Source Code
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Cross-Chain Transactions
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
CTokenFirstExtension
Compiler Version
v0.8.10+commit.fc410830
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;
import { DiamondExtension } from "../ionic/DiamondExtension.sol";
import { IFlashLoanReceiver } from "../ionic/IFlashLoanReceiver.sol";
import { CErc20FirstExtensionBase, CTokenFirstExtensionInterface, ICErc20 } from "./CTokenInterfaces.sol";
import { SFSRegister } from "./ComptrollerInterface.sol";
import { TokenErrorReporter } from "./ErrorReporter.sol";
import { Exponential } from "./Exponential.sol";
import { InterestRateModel } from "./InterestRateModel.sol";
import { IFeeDistributor } from "./IFeeDistributor.sol";
import { Multicall } from "../utils/Multicall.sol";
import { IERC20, SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { AddressesProvider } from "../ionic/AddressesProvider.sol";
contract CTokenFirstExtension is
CErc20FirstExtensionBase,
TokenErrorReporter,
Exponential,
DiamondExtension,
Multicall
{
modifier isAuthorized() {
require(
IFeeDistributor(ionicAdmin).canCall(address(comptroller), msg.sender, address(this), msg.sig),
"not authorized"
);
_;
}
function _getExtensionFunctions() external pure virtual override returns (bytes4[] memory) {
uint8 fnsCount = 25;
bytes4[] memory functionSelectors = new bytes4[](fnsCount);
functionSelectors[--fnsCount] = this.transfer.selector;
functionSelectors[--fnsCount] = this.transferFrom.selector;
functionSelectors[--fnsCount] = this.allowance.selector;
functionSelectors[--fnsCount] = this.approve.selector;
functionSelectors[--fnsCount] = this.balanceOf.selector;
functionSelectors[--fnsCount] = this._setAdminFee.selector;
functionSelectors[--fnsCount] = this._setInterestRateModel.selector;
functionSelectors[--fnsCount] = this._setNameAndSymbol.selector;
functionSelectors[--fnsCount] = this._setAddressesProvider.selector;
functionSelectors[--fnsCount] = this._setReserveFactor.selector;
functionSelectors[--fnsCount] = this.supplyRatePerBlock.selector;
functionSelectors[--fnsCount] = this.borrowRatePerBlock.selector;
functionSelectors[--fnsCount] = this.exchangeRateCurrent.selector;
functionSelectors[--fnsCount] = this.accrueInterest.selector;
functionSelectors[--fnsCount] = this.totalBorrowsCurrent.selector;
functionSelectors[--fnsCount] = this.balanceOfUnderlying.selector;
functionSelectors[--fnsCount] = this.multicall.selector;
functionSelectors[--fnsCount] = this.supplyRatePerBlockAfterDeposit.selector;
functionSelectors[--fnsCount] = this.supplyRatePerBlockAfterWithdraw.selector;
functionSelectors[--fnsCount] = this.borrowRatePerBlockAfterBorrow.selector;
functionSelectors[--fnsCount] = this.getTotalUnderlyingSupplied.selector;
functionSelectors[--fnsCount] = this.flash.selector;
functionSelectors[--fnsCount] = this.getAccountSnapshot.selector;
functionSelectors[--fnsCount] = this.borrowBalanceCurrent.selector;
functionSelectors[--fnsCount] = this.registerInSFS.selector;
require(fnsCount == 0, "use the correct array length");
return functionSelectors;
}
function getTotalUnderlyingSupplied() public view override returns (uint256) {
// (totalCash + totalBorrows - (totalReserves + totalIonicFees + totalAdminFees))
return asCToken().getCash() + totalBorrows - (totalReserves + totalIonicFees + totalAdminFees);
}
/* ERC20 fns */
/**
* @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);
if (allowed != 0) {
return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.TRANSFER_COMPTROLLER_REJECTION, allowed);
}
/* Do not allow self-transfers */
if (src == dst) {
return fail(Error.BAD_INPUT, FailureInfo.TRANSFER_NOT_ALLOWED);
}
/* Get the allowance, infinite for the account owner */
uint256 startingAllowance = 0;
if (spender == src) {
startingAllowance = 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);
if (mathErr != MathError.NO_ERROR) {
return fail(Error.MATH_ERROR, FailureInfo.TRANSFER_NOT_ALLOWED);
}
(mathErr, srcTokensNew) = subUInt(accountTokens[src], tokens);
if (mathErr != MathError.NO_ERROR) {
return fail(Error.MATH_ERROR, FailureInfo.TRANSFER_NOT_ENOUGH);
}
(mathErr, dstTokensNew) = addUInt(accountTokens[dst], tokens);
if (mathErr != MathError.NO_ERROR) {
return fail(Error.MATH_ERROR, FailureInfo.TRANSFER_TOO_MUCH);
}
/////////////////////////
// EFFECTS & INTERACTIONS
// (No safe failures beyond this point)
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);
/* We call the defense hook */
// 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) public override nonReentrant(false) isAuthorized 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
) public override nonReentrant(false) isAuthorized 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) public override isAuthorized 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) public 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) public view override returns (uint256) {
return accountTokens[owner];
}
/*** Admin Functions ***/
/**
* @notice updates the cToken ERC20 name and symbol
* @dev Admin function to update the cToken ERC20 name and symbol
* @param _name the new ERC20 token name to use
* @param _symbol the new ERC20 token symbol to use
*/
function _setNameAndSymbol(string calldata _name, string calldata _symbol) external {
// Check caller is admin
require(hasAdminRights(), "!admin");
// Set ERC20 name and symbol
name = _name;
symbol = _symbol;
}
function _setAddressesProvider(address _ap) external {
// Check caller is admin
require(hasAdminRights(), "!admin");
ap = AddressesProvider(_ap);
}
/**
* @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) public override nonReentrant(false) returns (uint256) {
accrueInterest();
// Check caller is admin
if (!hasAdminRights()) {
return fail(Error.UNAUTHORIZED, FailureInfo.SET_RESERVE_FACTOR_ADMIN_CHECK);
}
// Verify market's block number equals current block number
if (accrualBlockNumber != block.number) {
return fail(Error.MARKET_NOT_FRESH, FailureInfo.SET_RESERVE_FACTOR_FRESH_CHECK);
}
// Check newReserveFactor ≤ maxReserveFactor
if (newReserveFactorMantissa + adminFeeMantissa + ionicFeeMantissa > reserveFactorPlusFeesMaxMantissa) {
return fail(Error.BAD_INPUT, FailureInfo.SET_RESERVE_FACTOR_BOUNDS_CHECK);
}
uint256 oldReserveFactorMantissa = reserveFactorMantissa;
reserveFactorMantissa = newReserveFactorMantissa;
emit NewReserveFactor(oldReserveFactorMantissa, newReserveFactorMantissa);
return uint256(Error.NO_ERROR);
}
/**
* @notice accrues interest and sets a new admin fee for the protocol using _setAdminFeeFresh
* @dev Admin function to accrue interest and set a new admin fee
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
*/
function _setAdminFee(uint256 newAdminFeeMantissa) public override nonReentrant(false) returns (uint256) {
accrueInterest();
// Verify market's block number equals current block number
if (accrualBlockNumber != block.number) {
return fail(Error.MARKET_NOT_FRESH, FailureInfo.SET_ADMIN_FEE_FRESH_CHECK);
}
// Sanitize newAdminFeeMantissa
if (newAdminFeeMantissa == type(uint256).max) newAdminFeeMantissa = adminFeeMantissa;
// Get latest Ionic fee
uint256 newIonicFeeMantissa = IFeeDistributor(ionicAdmin).interestFeeRate();
// Check reserveFactorMantissa + newAdminFeeMantissa + newIonicFeeMantissa ≤ reserveFactorPlusFeesMaxMantissa
if (reserveFactorMantissa + newAdminFeeMantissa + newIonicFeeMantissa > reserveFactorPlusFeesMaxMantissa) {
return fail(Error.BAD_INPUT, FailureInfo.SET_ADMIN_FEE_BOUNDS_CHECK);
}
// If setting admin fee
if (adminFeeMantissa != newAdminFeeMantissa) {
// Check caller is admin
if (!hasAdminRights()) {
return fail(Error.UNAUTHORIZED, FailureInfo.SET_ADMIN_FEE_ADMIN_CHECK);
}
// Set admin fee
uint256 oldAdminFeeMantissa = adminFeeMantissa;
adminFeeMantissa = newAdminFeeMantissa;
// Emit event
emit NewAdminFee(oldAdminFeeMantissa, newAdminFeeMantissa);
}
// If setting Ionic fee
if (ionicFeeMantissa != newIonicFeeMantissa) {
// Set Ionic fee
uint256 oldIonicFeeMantissa = ionicFeeMantissa;
ionicFeeMantissa = newIonicFeeMantissa;
// Emit event
emit NewIonicFee(oldIonicFeeMantissa, newIonicFeeMantissa);
}
return uint256(Error.NO_ERROR);
}
/**
* @notice accrues interest and updates the interest rate model using _setInterestRateModelFresh
* @dev Admin function to accrue interest and update the interest rate model
* @param newInterestRateModel the new interest rate model to use
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
*/
function _setInterestRateModel(InterestRateModel newInterestRateModel)
public
override
nonReentrant(false)
returns (uint256)
{
accrueInterest();
if (!hasAdminRights()) {
return fail(Error.UNAUTHORIZED, FailureInfo.SET_INTEREST_RATE_MODEL_OWNER_CHECK);
}
if (accrualBlockNumber != block.number) {
return fail(Error.MARKET_NOT_FRESH, FailureInfo.SET_INTEREST_RATE_MODEL_FRESH_CHECK);
}
require(newInterestRateModel.isInterestRateModel(), "!notIrm");
InterestRateModel oldInterestRateModel = interestRateModel;
interestRateModel = newInterestRateModel;
emit NewMarketInterestRateModel(oldInterestRateModel, newInterestRateModel);
return uint256(Error.NO_ERROR);
}
/**
* @notice Returns the current per-block borrow interest rate for this cToken
* @return The borrow interest rate per block, scaled by 1e18
*/
function borrowRatePerBlock() public view override returns (uint256) {
return
interestRateModel.getBorrowRate(
asCToken().getCash(),
totalBorrows,
totalReserves + totalAdminFees + totalIonicFees
);
}
function borrowRatePerBlockAfterBorrow(uint256 borrowAmount) public view returns (uint256) {
uint256 cash = asCToken().getCash();
require(cash >= borrowAmount, "market cash not enough");
return
interestRateModel.getBorrowRate(
cash - borrowAmount,
totalBorrows + borrowAmount,
totalReserves + totalAdminFees + totalIonicFees
);
}
/**
* @notice Returns the current per-block supply interest rate for this cToken
* @return The supply interest rate per block, scaled by 1e18
*/
function supplyRatePerBlock() public view override returns (uint256) {
return
interestRateModel.getSupplyRate(
asCToken().getCash(),
totalBorrows,
totalReserves + totalAdminFees + totalIonicFees,
reserveFactorMantissa + ionicFeeMantissa + adminFeeMantissa
);
}
function supplyRatePerBlockAfterDeposit(uint256 mintAmount) external view returns (uint256) {
return
interestRateModel.getSupplyRate(
asCToken().getCash() + mintAmount,
totalBorrows,
totalReserves + totalAdminFees + totalIonicFees,
reserveFactorMantissa + ionicFeeMantissa + adminFeeMantissa
);
}
function supplyRatePerBlockAfterWithdraw(uint256 withdrawAmount) external view returns (uint256) {
uint256 cash = asCToken().getCash();
require(cash >= withdrawAmount, "market cash not enough");
return
interestRateModel.getSupplyRate(
cash - withdrawAmount,
totalBorrows,
totalReserves + totalAdminFees + totalIonicFees,
reserveFactorMantissa + ionicFeeMantissa + adminFeeMantissa
);
}
/**
* @notice Accrue interest then return the up-to-date exchange rate
* @return Calculated exchange rate scaled by 1e18
*/
function exchangeRateCurrent() public view override returns (uint256) {
if (block.number == accrualBlockNumber) {
return
_exchangeRateHypothetical(
totalSupply,
initialExchangeRateMantissa,
asCToken().getCash(),
totalBorrows,
totalReserves,
totalAdminFees,
totalIonicFees
);
} else {
uint256 cashPrior = asCToken().getCash();
InterestAccrual memory accrual = _accrueInterestHypothetical(block.number, cashPrior);
return
_exchangeRateHypothetical(
accrual.totalSupply,
initialExchangeRateMantissa,
cashPrior,
accrual.totalBorrows,
accrual.totalReserves,
accrual.totalAdminFees,
accrual.totalIonicFees
);
}
}
function _exchangeRateHypothetical(
uint256 _totalSupply,
uint256 _initialExchangeRateMantissa,
uint256 _totalCash,
uint256 _totalBorrows,
uint256 _totalReserves,
uint256 _totalAdminFees,
uint256 _totalIonicFees
) internal pure returns (uint256) {
if (_totalSupply == 0) {
/*
* If there are no tokens minted:
* exchangeRate = initialExchangeRate
*/
return _initialExchangeRateMantissa;
} else {
/*
* Otherwise:
* exchangeRate = (totalCash + totalBorrows - (totalReserves + totalIonicFees + totalAdminFees)) / totalSupply
*/
uint256 cashPlusBorrowsMinusReserves;
Exp memory exchangeRate;
MathError mathErr;
(mathErr, cashPlusBorrowsMinusReserves) = addThenSubUInt(
_totalCash,
_totalBorrows,
_totalReserves + _totalAdminFees + _totalIonicFees
);
require(mathErr == MathError.NO_ERROR, "!addThenSubUInt overflow check failed");
(mathErr, exchangeRate) = getExp(cashPlusBorrowsMinusReserves, _totalSupply);
require(mathErr == MathError.NO_ERROR, "!getExp overflow check failed");
return exchangeRate.mantissa;
}
}
struct InterestAccrual {
uint256 accrualBlockNumber;
uint256 borrowIndex;
uint256 totalSupply;
uint256 totalBorrows;
uint256 totalReserves;
uint256 totalIonicFees;
uint256 totalAdminFees;
uint256 interestAccumulated;
}
function _accrueInterestHypothetical(uint256 blockNumber, uint256 cashPrior)
internal
view
returns (InterestAccrual memory accrual)
{
uint256 totalFees = totalAdminFees + totalIonicFees;
uint256 borrowRateMantissa = interestRateModel.getBorrowRate(cashPrior, totalBorrows, totalReserves + totalFees);
if (borrowRateMantissa > borrowRateMaxMantissa) {
if (cashPrior > totalFees) revert("!borrowRate");
else borrowRateMantissa = borrowRateMaxMantissa;
}
(MathError mathErr, uint256 blockDelta) = subUInt(blockNumber, accrualBlockNumber);
require(mathErr == MathError.NO_ERROR, "!blockDelta");
/*
* 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
* totalIonicFeesNew = interestAccumulated * ionicFee + totalIonicFees
* totalAdminFeesNew = interestAccumulated * adminFee + totalAdminFees
* borrowIndexNew = simpleInterestFactor * borrowIndex + borrowIndex
*/
accrual.accrualBlockNumber = blockNumber;
accrual.totalSupply = totalSupply;
Exp memory simpleInterestFactor = mul_(Exp({ mantissa: borrowRateMantissa }), blockDelta);
accrual.interestAccumulated = mul_ScalarTruncate(simpleInterestFactor, totalBorrows);
accrual.totalBorrows = accrual.interestAccumulated + totalBorrows;
accrual.totalReserves = mul_ScalarTruncateAddUInt(
Exp({ mantissa: reserveFactorMantissa }),
accrual.interestAccumulated,
totalReserves
);
accrual.totalIonicFees = mul_ScalarTruncateAddUInt(
Exp({ mantissa: ionicFeeMantissa }),
accrual.interestAccumulated,
totalIonicFees
);
accrual.totalAdminFees = mul_ScalarTruncateAddUInt(
Exp({ mantissa: adminFeeMantissa }),
accrual.interestAccumulated,
totalAdminFees
);
accrual.borrowIndex = mul_ScalarTruncateAddUInt(simpleInterestFactor, borrowIndex, borrowIndex);
}
/**
* @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 number */
uint256 currentBlockNumber = block.number;
/* Short-circuit accumulating 0 interest */
if (accrualBlockNumber == currentBlockNumber) {
return uint256(Error.NO_ERROR);
}
uint256 cashPrior = asCToken().getCash();
InterestAccrual memory accrual = _accrueInterestHypothetical(currentBlockNumber, cashPrior);
/////////////////////////
// EFFECTS & INTERACTIONS
// (No safe failures beyond this point)
accrualBlockNumber = currentBlockNumber;
borrowIndex = accrual.borrowIndex;
totalBorrows = accrual.totalBorrows;
totalReserves = accrual.totalReserves;
totalIonicFees = accrual.totalIonicFees;
totalAdminFees = accrual.totalAdminFees;
emit AccrueInterest(cashPrior, accrual.interestAccumulated, borrowIndex, totalBorrows);
return uint256(Error.NO_ERROR);
}
/**
* @notice Returns the current total borrows plus accrued interest
* @return The total borrows with interest
*/
function totalBorrowsCurrent() external view override returns (uint256) {
if (accrualBlockNumber == block.number) {
return totalBorrows;
} else {
uint256 cashPrior = asCToken().getCash();
InterestAccrual memory accrual = _accrueInterestHypothetical(block.number, cashPrior);
return accrual.totalBorrows;
}
}
/**
* @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 cTokenBalance = accountTokens[account];
uint256 borrowBalance;
uint256 exchangeRateMantissa;
borrowBalance = borrowBalanceCurrent(account);
exchangeRateMantissa = exchangeRateCurrent();
return (uint256(Error.NO_ERROR), cTokenBalance, borrowBalance, exchangeRateMantissa);
}
/**
* @notice calculate the borrowIndex and the account's borrow balance using the fresh borrowIndex
* @param account The address whose balance should be calculated after recalculating the borrowIndex
* @return The calculated balance
*/
function borrowBalanceCurrent(address account) public view override returns (uint256) {
uint256 _borrowIndex;
if (accrualBlockNumber == block.number) {
_borrowIndex = borrowIndex;
} else {
uint256 cashPrior = asCToken().getCash();
InterestAccrual memory accrual = _accrueInterestHypothetical(block.number, cashPrior);
_borrowIndex = accrual.borrowIndex;
}
/* 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 0;
}
/* Calculate new borrow balance using the interest index:
* recentBorrowBalance = borrower.borrowBalance * market.borrowIndex / borrower.borrowIndex
*/
(mathErr, principalTimesIndex) = mulUInt(borrowSnapshot.principal, _borrowIndex);
require(mathErr == MathError.NO_ERROR, "!mulUInt overflow check failed");
(mathErr, result) = divUInt(principalTimesIndex, borrowSnapshot.interestIndex);
require(mathErr == MathError.NO_ERROR, "!divUInt overflow check failed");
return result;
}
/**
* @notice Get the underlying balance of the `owner`
* @param owner The address of the account to query
* @return The amount of underlying owned by `owner`
*/
function balanceOfUnderlying(address owner) external view override returns (uint256) {
Exp memory exchangeRate = Exp({ mantissa: exchangeRateCurrent() });
(MathError mErr, uint256 balance) = mulScalarTruncate(exchangeRate, accountTokens[owner]);
require(mErr == MathError.NO_ERROR, "!balance");
return balance;
}
function flash(uint256 amount, bytes calldata data) public override isAuthorized {
accrueInterest();
totalBorrows += amount;
asCToken().selfTransferOut(msg.sender, amount);
IFlashLoanReceiver(msg.sender).receiveFlashLoan(underlying, amount, data);
asCToken().selfTransferIn(msg.sender, amount);
totalBorrows -= amount;
emit Flash(msg.sender, amount);
}
/*** Reentrancy Guard ***/
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
*/
modifier nonReentrant(bool localOnly) {
_beforeNonReentrant(localOnly);
_;
_afterNonReentrant(localOnly);
}
/**
* @dev Split off from `nonReentrant` to keep contract below the 24 KB size limit.
* Saves space because function modifier code is "inlined" into every function with the modifier).
* In this specific case, the optimization saves around 1500 bytes of that valuable 24 KB limit.
*/
function _beforeNonReentrant(bool localOnly) private {
require(_notEntered, "re-entered");
if (!localOnly) comptroller._beforeNonReentrant();
_notEntered = false;
}
/**
* @dev Split off from `nonReentrant` to keep contract below the 24 KB size limit.
* Saves space because function modifier code is "inlined" into every function with the modifier).
* In this specific case, the optimization saves around 150 bytes of that valuable 24 KB limit.
*/
function _afterNonReentrant(bool localOnly) private {
_notEntered = true; // get a gas-refund post-Istanbul
if (!localOnly) comptroller._afterNonReentrant();
}
function asCToken() internal view returns (ICErc20) {
return ICErc20(address(this));
}
function multicall(bytes[] calldata data)
public
payable
override(CTokenFirstExtensionInterface, Multicall)
returns (bytes[] memory results)
{
return Multicall.multicall(data);
}
function registerInSFS() external returns (uint256) {
require(hasAdminRights() || msg.sender == address(comptroller), "!admin");
SFSRegister sfsContract = SFSRegister(0x8680CEaBcb9b56913c519c069Add6Bc3494B7020);
return sfsContract.register(0x8Fba84867Ba458E7c6E2c024D2DE3d0b5C3ea1C2);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)
pragma solidity ^0.8.0;
/**
* @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface IERC1822Proxiable {
/**
* @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
* address.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy.
*/
function proxiableUUID() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (proxy/ERC1967/ERC1967Proxy.sol)
pragma solidity ^0.8.0;
import "../Proxy.sol";
import "./ERC1967Upgrade.sol";
/**
* @dev This contract implements an upgradeable proxy. It is upgradeable because calls are delegated to an
* implementation address that can be changed. This address is stored in storage in the location specified by
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967], so that it doesn't conflict with the storage layout of the
* implementation behind the proxy.
*/
contract ERC1967Proxy is Proxy, ERC1967Upgrade {
/**
* @dev Initializes the upgradeable proxy with an initial implementation specified by `_logic`.
*
* If `_data` is nonempty, it's used as data in a delegate call to `_logic`. This will typically be an encoded
* function call, and allows initializing the storage of the proxy like a Solidity constructor.
*/
constructor(address _logic, bytes memory _data) payable {
_upgradeToAndCall(_logic, _data, false);
}
/**
* @dev Returns the current implementation address.
*/
function _implementation() internal view virtual override returns (address impl) {
return ERC1967Upgrade._getImplementation();
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (proxy/ERC1967/ERC1967Upgrade.sol)
pragma solidity ^0.8.2;
import "../beacon/IBeacon.sol";
import "../../interfaces/draft-IERC1822.sol";
import "../../utils/Address.sol";
import "../../utils/StorageSlot.sol";
/**
* @dev This abstract contract provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
*
* _Available since v4.1._
*
* @custom:oz-upgrades-unsafe-allow delegatecall
*/
abstract contract ERC1967Upgrade {
// This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev Emitted when the implementation is upgraded.
*/
event Upgraded(address indexed implementation);
/**
* @dev Returns the current implementation address.
*/
function _getImplementation() internal view returns (address) {
return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Perform implementation upgrade
*
* Emits an {Upgraded} event.
*/
function _upgradeTo(address newImplementation) internal {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
}
/**
* @dev Perform implementation upgrade with additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCall(
address newImplementation,
bytes memory data,
bool forceCall
) internal {
_upgradeTo(newImplementation);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(newImplementation, data);
}
}
/**
* @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCallUUPS(
address newImplementation,
bytes memory data,
bool forceCall
) internal {
// Upgrades from old implementations will perform a rollback test. This test requires the new
// implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing
// this special case will break upgrade paths from old UUPS implementation to new ones.
if (StorageSlot.getBooleanSlot(_ROLLBACK_SLOT).value) {
_setImplementation(newImplementation);
} else {
try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID");
} catch {
revert("ERC1967Upgrade: new implementation is not UUPS");
}
_upgradeToAndCall(newImplementation, data, forceCall);
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Emitted when the admin account has changed.
*/
event AdminChanged(address previousAdmin, address newAdmin);
/**
* @dev Returns the current admin.
*/
function _getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(_ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
require(newAdmin != address(0), "ERC1967: new admin is the zero address");
StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {AdminChanged} event.
*/
function _changeAdmin(address newAdmin) internal {
emit AdminChanged(_getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
*/
bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Emitted when the beacon is upgraded.
*/
event BeaconUpgraded(address indexed beacon);
/**
* @dev Returns the current beacon.
*/
function _getBeacon() internal view returns (address) {
return StorageSlot.getAddressSlot(_BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the EIP1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
require(Address.isContract(newBeacon), "ERC1967: new beacon is not a contract");
require(
Address.isContract(IBeacon(newBeacon).implementation()),
"ERC1967: beacon implementation is not a contract"
);
StorageSlot.getAddressSlot(_BEACON_SLOT).value = newBeacon;
}
/**
* @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
* not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
*
* Emits a {BeaconUpgraded} event.
*/
function _upgradeBeaconToAndCall(
address newBeacon,
bytes memory data,
bool forceCall
) internal {
_setBeacon(newBeacon);
emit BeaconUpgraded(newBeacon);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (proxy/Proxy.sol)
pragma solidity ^0.8.0;
/**
* @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
* instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to
* be specified by overriding the virtual {_implementation} function.
*
* Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
* different contract through the {_delegate} function.
*
* The success and return data of the delegated call will be returned back to the caller of the proxy.
*/
abstract contract Proxy {
/**
* @dev Delegates the current call to `implementation`.
*
* This function does not return to its internal call site, it will return directly to the external caller.
*/
function _delegate(address implementation) internal virtual {
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize())
// Call the implementation.
// out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// delegatecall returns 0 on error.
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
/**
* @dev This is a virtual function that should be overridden so it returns the address to which the fallback function
* and {_fallback} should delegate.
*/
function _implementation() internal view virtual returns (address);
/**
* @dev Delegates the current call to the address returned by `_implementation()`.
*
* This function does not return to its internal call site, it will return directly to the external caller.
*/
function _fallback() internal virtual {
_beforeFallback();
_delegate(_implementation());
}
/**
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
* function in the contract matches the call data.
*/
fallback() external payable virtual {
_fallback();
}
/**
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data
* is empty.
*/
receive() external payable virtual {
_fallback();
}
/**
* @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback`
* call, or as part of the Solidity `fallback` or `receive` functions.
*
* If overridden should call `super._beforeFallback()`.
*/
function _beforeFallback() internal virtual {}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)
pragma solidity ^0.8.0;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeacon {
/**
* @dev Must return an address that can be used as a delegate call target.
*
* {BeaconProxy} will check that this address is a contract.
*/
function implementation() external view returns (address);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (proxy/transparent/TransparentUpgradeableProxy.sol)
pragma solidity ^0.8.0;
import "../ERC1967/ERC1967Proxy.sol";
/**
* @dev This contract implements a proxy that is upgradeable by an admin.
*
* To avoid https://medium.com/nomic-labs-blog/malicious-backdoors-in-ethereum-proxies-62629adf3357[proxy selector
* clashing], which can potentially be used in an attack, this contract uses the
* https://blog.openzeppelin.com/the-transparent-proxy-pattern/[transparent proxy pattern]. This pattern implies two
* things that go hand in hand:
*
* 1. If any account other than the admin calls the proxy, the call will be forwarded to the implementation, even if
* that call matches one of the admin functions exposed by the proxy itself.
* 2. If the admin calls the proxy, it can access the admin functions, but its calls will never be forwarded to the
* implementation. If the admin tries to call a function on the implementation it will fail with an error that says
* "admin cannot fallback to proxy target".
*
* These properties mean that the admin account can only be used for admin actions like upgrading the proxy or changing
* the admin, so it's best if it's a dedicated account that is not used for anything else. This will avoid headaches due
* to sudden errors when trying to call a function from the proxy implementation.
*
* Our recommendation is for the dedicated account to be an instance of the {ProxyAdmin} contract. If set up this way,
* you should think of the `ProxyAdmin` instance as the real administrative interface of your proxy.
*/
contract TransparentUpgradeableProxy is ERC1967Proxy {
/**
* @dev Initializes an upgradeable proxy managed by `_admin`, backed by the implementation at `_logic`, and
* optionally initialized with `_data` as explained in {ERC1967Proxy-constructor}.
*/
constructor(
address _logic,
address admin_,
bytes memory _data
) payable ERC1967Proxy(_logic, _data) {
_changeAdmin(admin_);
}
/**
* @dev Modifier used internally that will delegate the call to the implementation unless the sender is the admin.
*/
modifier ifAdmin() {
if (msg.sender == _getAdmin()) {
_;
} else {
_fallback();
}
}
/**
* @dev Returns the current admin.
*
* NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyAdmin}.
*
* TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the
* https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
* `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
*/
function admin() external ifAdmin returns (address admin_) {
admin_ = _getAdmin();
}
/**
* @dev Returns the current implementation.
*
* NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyImplementation}.
*
* TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the
* https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
* `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc`
*/
function implementation() external ifAdmin returns (address implementation_) {
implementation_ = _implementation();
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {AdminChanged} event.
*
* NOTE: Only the admin can call this function. See {ProxyAdmin-changeProxyAdmin}.
*/
function changeAdmin(address newAdmin) external virtual ifAdmin {
_changeAdmin(newAdmin);
}
/**
* @dev Upgrade the implementation of the proxy.
*
* NOTE: Only the admin can call this function. See {ProxyAdmin-upgrade}.
*/
function upgradeTo(address newImplementation) external ifAdmin {
_upgradeToAndCall(newImplementation, bytes(""), false);
}
/**
* @dev Upgrade the implementation of the proxy, and then call a function from the new implementation as specified
* by `data`, which should be an encoded function call. This is useful to initialize new storage variables in the
* proxied contract.
*
* NOTE: Only the admin can call this function. See {ProxyAdmin-upgradeAndCall}.
*/
function upgradeToAndCall(address newImplementation, bytes calldata data) external payable ifAdmin {
_upgradeToAndCall(newImplementation, data, true);
}
/**
* @dev Returns the current admin.
*/
function _admin() internal view virtual returns (address) {
return _getAdmin();
}
/**
* @dev Makes sure the admin cannot access the fallback function. See {Proxy-_beforeFallback}.
*/
function _beforeFallback() internal virtual override {
require(msg.sender != _getAdmin(), "TransparentUpgradeableProxy: admin cannot fallback to proxy target");
super._beforeFallback();
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol)
pragma solidity ^0.8.0;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.0;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping(bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastValue;
// Update the index for the moved value
set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;
import { IonicComptroller } from "./ComptrollerInterface.sol";
import { InterestRateModel } from "./InterestRateModel.sol";
import { ComptrollerV3Storage } from "./ComptrollerStorage.sol";
import { AddressesProvider } from "../ionic/AddressesProvider.sol";
abstract contract CTokenAdminStorage {
/*
* Administrator for Ionic
*/
address payable public ionicAdmin;
}
abstract contract CErc20Storage is CTokenAdminStorage {
/**
* @dev Guard variable for re-entrancy checks
*/
bool internal _notEntered;
/**
* @notice EIP-20 token name for this token
*/
string public name;
/**
* @notice EIP-20 token symbol for this token
*/
string public symbol;
/**
* @notice EIP-20 token decimals for this token
*/
uint8 public decimals;
/*
* Maximum borrow rate that can ever be applied (.0005% / block)
*/
uint256 internal constant borrowRateMaxMantissa = 0.0005e16;
/*
* Maximum fraction of interest that can be set aside for reserves + fees
*/
uint256 internal constant reserveFactorPlusFeesMaxMantissa = 1e18;
/**
* @notice Contract which oversees inter-cToken operations
*/
IonicComptroller public comptroller;
/**
* @notice Model which tells what the current interest rate should be
*/
InterestRateModel public interestRateModel;
/*
* Initial exchange rate used when minting the first CTokens (used when totalSupply = 0)
*/
uint256 internal initialExchangeRateMantissa;
/**
* @notice Fraction of interest currently set aside for admin fees
*/
uint256 public adminFeeMantissa;
/**
* @notice Fraction of interest currently set aside for Ionic fees
*/
uint256 public ionicFeeMantissa;
/**
* @notice Fraction of interest currently set aside for reserves
*/
uint256 public reserveFactorMantissa;
/**
* @notice Block number that interest was last accrued at
*/
uint256 public accrualBlockNumber;
/**
* @notice Accumulator of the total earned interest rate since the opening of the market
*/
uint256 public borrowIndex;
/**
* @notice Total amount of outstanding borrows of the underlying in this market
*/
uint256 public totalBorrows;
/**
* @notice Total amount of reserves of the underlying held in this market
*/
uint256 public totalReserves;
/**
* @notice Total amount of admin fees of the underlying held in this market
*/
uint256 public totalAdminFees;
/**
* @notice Total amount of Ionic fees of the underlying held in this market
*/
uint256 public totalIonicFees;
/**
* @notice Total number of tokens in circulation
*/
uint256 public totalSupply;
/*
* Official record of token balances for each account
*/
mapping(address => uint256) internal accountTokens;
/*
* Approved token transfer amounts on behalf of others
*/
mapping(address => mapping(address => uint256)) internal transferAllowances;
/**
* @notice Container for borrow balance information
* @member principal Total balance (with accrued interest), after applying the most recent balance-changing action
* @member interestIndex Global borrowIndex as of the most recent balance-changing action
*/
struct BorrowSnapshot {
uint256 principal;
uint256 interestIndex;
}
/*
* Mapping of account addresses to outstanding borrow balances
*/
mapping(address => BorrowSnapshot) internal accountBorrows;
/*
* Share of seized collateral that is added to reserves
*/
uint256 public constant protocolSeizeShareMantissa = 2.8e16; //2.8%
/*
* Share of seized collateral taken as fees
*/
uint256 public constant feeSeizeShareMantissa = 1e17; //10%
/**
* @notice Underlying asset for this CToken
*/
address public underlying;
/**
* @notice Addresses Provider
*/
AddressesProvider public ap;
}
abstract contract CTokenBaseEvents {
/* ERC20 */
/**
* @notice EIP20 Transfer event
*/
event Transfer(address indexed from, address indexed to, uint256 amount);
/*** Admin Events ***/
/**
* @notice Event emitted when interestRateModel is changed
*/
event NewMarketInterestRateModel(InterestRateModel oldInterestRateModel, InterestRateModel newInterestRateModel);
/**
* @notice Event emitted when the reserve factor is changed
*/
event NewReserveFactor(uint256 oldReserveFactorMantissa, uint256 newReserveFactorMantissa);
/**
* @notice Event emitted when the admin fee is changed
*/
event NewAdminFee(uint256 oldAdminFeeMantissa, uint256 newAdminFeeMantissa);
/**
* @notice Event emitted when the Ionic fee is changed
*/
event NewIonicFee(uint256 oldIonicFeeMantissa, uint256 newIonicFeeMantissa);
/**
* @notice EIP20 Approval event
*/
event Approval(address indexed owner, address indexed spender, uint256 amount);
/**
* @notice Event emitted when interest is accrued
*/
event AccrueInterest(uint256 cashPrior, uint256 interestAccumulated, uint256 borrowIndex, uint256 totalBorrows);
}
abstract contract CTokenFirstExtensionEvents is CTokenBaseEvents {
event Flash(address receiver, uint256 amount);
}
abstract contract CTokenSecondExtensionEvents is CTokenBaseEvents {
/*** Market Events ***/
/**
* @notice Event emitted when tokens are minted
*/
event Mint(address minter, uint256 mintAmount, uint256 mintTokens);
/**
* @notice Event emitted when tokens are redeemed
*/
event Redeem(address redeemer, uint256 redeemAmount, uint256 redeemTokens);
/**
* @notice Event emitted when underlying is borrowed
*/
event Borrow(address borrower, uint256 borrowAmount, uint256 accountBorrows, uint256 totalBorrows);
/**
* @notice Event emitted when a borrow is repaid
*/
event RepayBorrow(address payer, address borrower, uint256 repayAmount, uint256 accountBorrows, uint256 totalBorrows);
/**
* @notice Event emitted when a borrow is liquidated
*/
event LiquidateBorrow(
address liquidator,
address borrower,
uint256 repayAmount,
address cTokenCollateral,
uint256 seizeTokens
);
/**
* @notice Event emitted when the reserves are added
*/
event ReservesAdded(address benefactor, uint256 addAmount, uint256 newTotalReserves);
/**
* @notice Event emitted when the reserves are reduced
*/
event ReservesReduced(address admin, uint256 reduceAmount, uint256 newTotalReserves);
}
interface CTokenFirstExtensionInterface {
/*** User Interface ***/
function transfer(address dst, uint256 amount) external returns (bool);
function transferFrom(
address src,
address dst,
uint256 amount
) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function balanceOf(address owner) external view returns (uint256);
/*** Admin Functions ***/
function _setReserveFactor(uint256 newReserveFactorMantissa) external returns (uint256);
function _setAdminFee(uint256 newAdminFeeMantissa) external returns (uint256);
function _setInterestRateModel(InterestRateModel newInterestRateModel) external returns (uint256);
function getAccountSnapshot(address account)
external
view
returns (
uint256,
uint256,
uint256,
uint256
);
function borrowRatePerBlock() external view returns (uint256);
function supplyRatePerBlock() external view returns (uint256);
function exchangeRateCurrent() external view returns (uint256);
function accrueInterest() external returns (uint256);
function totalBorrowsCurrent() external view returns (uint256);
function borrowBalanceCurrent(address account) external view returns (uint256);
function getTotalUnderlyingSupplied() external view returns (uint256);
function balanceOfUnderlying(address owner) external view returns (uint256);
function multicall(bytes[] calldata data) external payable returns (bytes[] memory results);
function flash(uint256 amount, bytes calldata data) external;
function supplyRatePerBlockAfterDeposit(uint256 mintAmount) external view returns (uint256);
function supplyRatePerBlockAfterWithdraw(uint256 withdrawAmount) external view returns (uint256);
function borrowRatePerBlockAfterBorrow(uint256 borrowAmount) external view returns (uint256);
function registerInSFS() external returns (uint256);
}
interface CTokenSecondExtensionInterface {
function mint(uint256 mintAmount) external returns (uint256);
function redeem(uint256 redeemTokens) external returns (uint256);
function redeemUnderlying(uint256 redeemAmount) external returns (uint256);
function borrow(uint256 borrowAmount) external returns (uint256);
function repayBorrow(uint256 repayAmount) external returns (uint256);
function repayBorrowBehalf(address borrower, uint256 repayAmount) external returns (uint256);
function liquidateBorrow(
address borrower,
uint256 repayAmount,
address cTokenCollateral
) external returns (uint256);
function getCash() external view returns (uint256);
function seize(
address liquidator,
address borrower,
uint256 seizeTokens
) external returns (uint256);
/*** Admin Functions ***/
function _withdrawAdminFees(uint256 withdrawAmount) external returns (uint256);
function _withdrawIonicFees(uint256 withdrawAmount) external returns (uint256);
function selfTransferOut(address to, uint256 amount) external;
function selfTransferIn(address from, uint256 amount) external returns (uint256);
}
interface CDelegatorInterface {
function implementation() external view returns (address);
/**
* @notice Called by the admin to update the implementation of the delegator
* @param implementation_ The address of the new implementation for delegation
* @param becomeImplementationData The encoded bytes data to be passed to _becomeImplementation
*/
function _setImplementationSafe(address implementation_, bytes calldata becomeImplementationData) external;
/**
* @dev upgrades the implementation if necessary
*/
function _upgrade() external;
}
interface CDelegateInterface {
/**
* @notice Called by the delegator on a delegate to initialize it for duty
* @dev Should revert if any issues arise which make it unfit for delegation
* @param data The encoded bytes data for any initialization
*/
function _becomeImplementation(bytes calldata data) external;
function delegateType() external pure returns (uint8);
function contractType() external pure returns (string memory);
}
abstract contract CErc20AdminBase is CErc20Storage {
/**
* @notice Returns a boolean indicating if the sender has admin rights
*/
function hasAdminRights() internal view returns (bool) {
ComptrollerV3Storage comptrollerStorage = ComptrollerV3Storage(address(comptroller));
return
(msg.sender == comptrollerStorage.admin() && comptrollerStorage.adminHasRights()) ||
(msg.sender == address(ionicAdmin) && comptrollerStorage.ionicAdminHasRights());
}
}
abstract contract CErc20FirstExtensionBase is
CErc20AdminBase,
CTokenFirstExtensionEvents,
CTokenFirstExtensionInterface
{}
abstract contract CTokenSecondExtensionBase is
CErc20AdminBase,
CTokenSecondExtensionEvents,
CTokenSecondExtensionInterface,
CDelegateInterface
{}
abstract contract CErc20DelegatorBase is CErc20AdminBase, CTokenSecondExtensionEvents, CDelegatorInterface {}
interface CErc20StorageInterface {
function admin() external view returns (address);
function adminHasRights() external view returns (bool);
function ionicAdmin() external view returns (address);
function ionicAdminHasRights() external view returns (bool);
function comptroller() external view returns (IonicComptroller);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint256);
function adminFeeMantissa() external view returns (uint256);
function ionicFeeMantissa() external view returns (uint256);
function reserveFactorMantissa() external view returns (uint256);
function protocolSeizeShareMantissa() external view returns (uint256);
function feeSeizeShareMantissa() external view returns (uint256);
function totalReserves() external view returns (uint256);
function totalAdminFees() external view returns (uint256);
function totalIonicFees() external view returns (uint256);
function totalBorrows() external view returns (uint256);
function accrualBlockNumber() external view returns (uint256);
function underlying() external view returns (address);
function borrowIndex() external view returns (uint256);
function interestRateModel() external view returns (address);
}
interface CErc20PluginStorageInterface is CErc20StorageInterface {
function plugin() external view returns (address);
}
interface CErc20PluginRewardsInterface is CErc20PluginStorageInterface {
function approve(address, address) external;
}
interface ICErc20 is
CErc20StorageInterface,
CTokenSecondExtensionInterface,
CTokenFirstExtensionInterface,
CDelegatorInterface,
CDelegateInterface
{}
interface ICErc20Plugin is CErc20PluginStorageInterface, ICErc20 {
function _updatePlugin(address _plugin) external;
}
interface ICErc20PluginRewards is CErc20PluginRewardsInterface, ICErc20 {}// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;
/**
* @title Careful Math
* @author Compound
* @notice Derived from OpenZeppelin's SafeMath library
* https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/math/SafeMath.sol
*/
contract CarefulMath {
/**
* @dev Possible error codes that we can return
*/
enum MathError {
NO_ERROR,
DIVISION_BY_ZERO,
INTEGER_OVERFLOW,
INTEGER_UNDERFLOW
}
/**
* @dev Multiplies two numbers, returns an error on overflow.
*/
function mulUInt(uint256 a, uint256 b) internal pure returns (MathError, uint256) {
if (a == 0) {
return (MathError.NO_ERROR, 0);
}
uint256 c;
unchecked {
c = a * b;
}
if (c / a != b) {
return (MathError.INTEGER_OVERFLOW, 0);
} else {
return (MathError.NO_ERROR, c);
}
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function divUInt(uint256 a, uint256 b) internal pure returns (MathError, uint256) {
if (b == 0) {
return (MathError.DIVISION_BY_ZERO, 0);
}
return (MathError.NO_ERROR, a / b);
}
/**
* @dev Subtracts two numbers, returns an error on overflow (i.e. if subtrahend is greater than minuend).
*/
function subUInt(uint256 a, uint256 b) internal pure returns (MathError, uint256) {
if (b <= a) {
return (MathError.NO_ERROR, a - b);
} else {
return (MathError.INTEGER_UNDERFLOW, 0);
}
}
/**
* @dev Adds two numbers, returns an error on overflow.
*/
function addUInt(uint256 a, uint256 b) internal pure returns (MathError, uint256) {
uint256 c;
unchecked {
c = a + b;
}
if (c >= a) {
return (MathError.NO_ERROR, c);
} else {
return (MathError.INTEGER_OVERFLOW, 0);
}
}
/**
* @dev add a and b and then subtract c
*/
function addThenSubUInt(
uint256 a,
uint256 b,
uint256 c
) internal pure returns (MathError, uint256) {
(MathError err0, uint256 sum) = addUInt(a, b);
if (err0 != MathError.NO_ERROR) {
return (err0, 0);
}
return subUInt(sum, c);
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;
import { BasePriceOracle } from "../oracles/BasePriceOracle.sol";
import { ICErc20 } from "./CTokenInterfaces.sol";
import { ComptrollerV3Storage } from "../compound/ComptrollerStorage.sol";
interface ComptrollerInterface {
function isDeprecated(ICErc20 cToken) external view returns (bool);
function _becomeImplementation() external;
function _deployMarket(
uint8 delegateType,
bytes memory constructorData,
bytes calldata becomeImplData,
uint256 collateralFactorMantissa
) external returns (uint256);
function getAssetsIn(address account) external view returns (ICErc20[] memory);
function checkMembership(address account, ICErc20 cToken) external view returns (bool);
function _setPriceOracle(BasePriceOracle newOracle) external returns (uint256);
function _setCloseFactor(uint256 newCloseFactorMantissa) external returns (uint256);
function _setCollateralFactor(ICErc20 market, uint256 newCollateralFactorMantissa) external returns (uint256);
function _setLiquidationIncentive(uint256 newLiquidationIncentiveMantissa) external returns (uint256);
function _setWhitelistEnforcement(bool enforce) external returns (uint256);
function _setWhitelistStatuses(address[] calldata _suppliers, bool[] calldata statuses) external returns (uint256);
function _addRewardsDistributor(address distributor) external returns (uint256);
function getHypotheticalAccountLiquidity(
address account,
address cTokenModify,
uint256 redeemTokens,
uint256 borrowAmount,
uint256 repayAmount
)
external
view
returns (
uint256,
uint256,
uint256,
uint256
);
function getMaxRedeemOrBorrow(
address account,
ICErc20 cToken,
bool isBorrow
) external view returns (uint256);
/*** Assets You Are In ***/
function enterMarkets(address[] calldata cTokens) external returns (uint256[] memory);
function exitMarket(address cToken) external returns (uint256);
/*** Policy Hooks ***/
function mintAllowed(
address cToken,
address minter,
uint256 mintAmount
) external returns (uint256);
function redeemAllowed(
address cToken,
address redeemer,
uint256 redeemTokens
) external returns (uint256);
function redeemVerify(
address cToken,
address redeemer,
uint256 redeemAmount,
uint256 redeemTokens
) external;
function borrowAllowed(
address cToken,
address borrower,
uint256 borrowAmount
) external returns (uint256);
function borrowWithinLimits(address cToken, uint256 accountBorrowsNew) external view returns (uint256);
function repayBorrowAllowed(
address cToken,
address payer,
address borrower,
uint256 repayAmount
) external returns (uint256);
function liquidateBorrowAllowed(
address cTokenBorrowed,
address cTokenCollateral,
address liquidator,
address borrower,
uint256 repayAmount
) external returns (uint256);
function seizeAllowed(
address cTokenCollateral,
address cTokenBorrowed,
address liquidator,
address borrower,
uint256 seizeTokens
) external returns (uint256);
function transferAllowed(
address cToken,
address src,
address dst,
uint256 transferTokens
) external returns (uint256);
function mintVerify(
address cToken,
address minter,
uint256 actualMintAmount,
uint256 mintTokens
) external;
/*** Liquidity/Liquidation Calculations ***/
function getAccountLiquidity(address account)
external
view
returns (
uint256 error,
uint256 collateralValue,
uint256 liquidity,
uint256 shortfall
);
function liquidateCalculateSeizeTokens(
address cTokenBorrowed,
address cTokenCollateral,
uint256 repayAmount
) external view returns (uint256, uint256);
/*** Pool-Wide/Cross-Asset Reentrancy Prevention ***/
function _beforeNonReentrant() external;
function _afterNonReentrant() external;
}
interface ComptrollerStorageInterface {
function admin() external view returns (address);
function adminHasRights() external view returns (bool);
function ionicAdmin() external view returns (address);
function ionicAdminHasRights() external view returns (bool);
function pendingAdmin() external view returns (address);
function oracle() external view returns (BasePriceOracle);
function pauseGuardian() external view returns (address);
function closeFactorMantissa() external view returns (uint256);
function liquidationIncentiveMantissa() external view returns (uint256);
function isUserOfPool(address user) external view returns (bool);
function whitelist(address account) external view returns (bool);
function enforceWhitelist() external view returns (bool);
function borrowCapForCollateral(address borrowed, address collateral) external view returns (uint256);
function borrowingAgainstCollateralBlacklist(address borrowed, address collateral) external view returns (bool);
function suppliers(address account) external view returns (bool);
function cTokensByUnderlying(address) external view returns (address);
function supplyCaps(address cToken) external view returns (uint256);
function borrowCaps(address cToken) external view returns (uint256);
function markets(address cToken) external view returns (bool, uint256);
function accountAssets(address, uint256) external view returns (address);
function borrowGuardianPaused(address cToken) external view returns (bool);
function mintGuardianPaused(address cToken) external view returns (bool);
function rewardsDistributors(uint256) external view returns (address);
}
interface SFSRegister {
function register(address _recipient) external returns (uint256 tokenId);
}
interface ComptrollerExtensionInterface {
function getWhitelistedSuppliersSupply(address cToken) external view returns (uint256 supplied);
function getWhitelistedBorrowersBorrows(address cToken) external view returns (uint256 borrowed);
function getAllMarkets() external view returns (ICErc20[] memory);
function getAllBorrowers() external view returns (address[] memory);
function getAllBorrowersCount() external view returns (uint256);
function getPaginatedBorrowers(uint256 page, uint256 pageSize)
external
view
returns (uint256 _totalPages, address[] memory _pageOfBorrowers);
function getRewardsDistributors() external view returns (address[] memory);
function getAccruingFlywheels() external view returns (address[] memory);
function _supplyCapWhitelist(
address cToken,
address account,
bool whitelisted
) external;
function _setBorrowCapForCollateral(
address cTokenBorrow,
address cTokenCollateral,
uint256 borrowCap
) external;
function _setBorrowCapForCollateralWhitelist(
address cTokenBorrow,
address cTokenCollateral,
address account,
bool whitelisted
) external;
function isBorrowCapForCollateralWhitelisted(
address cTokenBorrow,
address cTokenCollateral,
address account
) external view returns (bool);
function _blacklistBorrowingAgainstCollateral(
address cTokenBorrow,
address cTokenCollateral,
bool blacklisted
) external;
function _blacklistBorrowingAgainstCollateralWhitelist(
address cTokenBorrow,
address cTokenCollateral,
address account,
bool whitelisted
) external;
function isBlacklistBorrowingAgainstCollateralWhitelisted(
address cTokenBorrow,
address cTokenCollateral,
address account
) external view returns (bool);
function isSupplyCapWhitelisted(address cToken, address account) external view returns (bool);
function _borrowCapWhitelist(
address cToken,
address account,
bool whitelisted
) external;
function isBorrowCapWhitelisted(address cToken, address account) external view returns (bool);
function _removeFlywheel(address flywheelAddress) external returns (bool);
function getWhitelist() external view returns (address[] memory);
function addNonAccruingFlywheel(address flywheelAddress) external returns (bool);
function _setMarketSupplyCaps(ICErc20[] calldata cTokens, uint256[] calldata newSupplyCaps) external;
function _setMarketBorrowCaps(ICErc20[] calldata cTokens, uint256[] calldata newBorrowCaps) external;
function _setBorrowCapGuardian(address newBorrowCapGuardian) external;
function _setPauseGuardian(address newPauseGuardian) external returns (uint256);
function _setMintPaused(ICErc20 cToken, bool state) external returns (bool);
function _setBorrowPaused(ICErc20 cToken, bool state) external returns (bool);
function _setTransferPaused(bool state) external returns (bool);
function _setSeizePaused(bool state) external returns (bool);
function _unsupportMarket(ICErc20 cToken) external returns (uint256);
function getAssetAsCollateralValueCap(
ICErc20 collateral,
ICErc20 cTokenModify,
bool redeeming,
address account
) external view returns (uint256);
function registerInSFS() external returns (uint256);
}
interface UnitrollerInterface {
function comptrollerImplementation() external view returns (address);
function _upgrade() external;
function _acceptAdmin() external returns (uint256);
function _setPendingAdmin(address newPendingAdmin) external returns (uint256);
function _toggleAdminRights(bool hasRights) external returns (uint256);
}
interface IComptrollerExtension is ComptrollerExtensionInterface, ComptrollerStorageInterface {}
//interface IComptrollerBase is ComptrollerInterface, ComptrollerStorageInterface {}
interface IonicComptroller is
ComptrollerInterface,
ComptrollerExtensionInterface,
UnitrollerInterface,
ComptrollerStorageInterface
{
}
abstract contract ComptrollerBase is ComptrollerV3Storage {
/// @notice Indicator that this is a Comptroller contract (for inspection)
bool public constant isComptroller = true;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;
import "./IFeeDistributor.sol";
import "../oracles/BasePriceOracle.sol";
import { ICErc20 } from "./CTokenInterfaces.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
contract UnitrollerAdminStorage {
/*
* Administrator for Ionic
*/
address payable public ionicAdmin;
/**
* @notice Administrator for this contract
*/
address public admin;
/**
* @notice Pending administrator for this contract
*/
address public pendingAdmin;
/**
* @notice Whether or not the Ionic admin has admin rights
*/
bool public ionicAdminHasRights = true;
/**
* @notice Whether or not the admin has admin rights
*/
bool public adminHasRights = true;
/**
* @notice Returns a boolean indicating if the sender has admin rights
*/
function hasAdminRights() internal view returns (bool) {
return (msg.sender == admin && adminHasRights) || (msg.sender == address(ionicAdmin) && ionicAdminHasRights);
}
}
contract ComptrollerV1Storage is UnitrollerAdminStorage {
/**
* @notice Oracle which gives the price of any given asset
*/
BasePriceOracle public oracle;
/**
* @notice Multiplier used to calculate the maximum repayAmount when liquidating a borrow
*/
uint256 public closeFactorMantissa;
/**
* @notice Multiplier representing the discount on collateral that a liquidator receives
*/
uint256 public liquidationIncentiveMantissa;
/*
* UNUSED AFTER UPGRADE: Max number of assets a single account can participate in (borrow or use as collateral)
*/
uint256 internal maxAssets;
/**
* @notice Per-account mapping of "assets you are in", capped by maxAssets
*/
mapping(address => ICErc20[]) public accountAssets;
}
contract ComptrollerV2Storage is ComptrollerV1Storage {
struct Market {
// Whether or not this market is listed
bool isListed;
// Multiplier representing the most one can borrow against their collateral in this market.
// For instance, 0.9 to allow borrowing 90% of collateral value.
// Must be between 0 and 1, and stored as a mantissa.
uint256 collateralFactorMantissa;
// Per-market mapping of "accounts in this asset"
mapping(address => bool) accountMembership;
}
/**
* @notice Official mapping of cTokens -> Market metadata
* @dev Used e.g. to determine if a market is supported
*/
mapping(address => Market) public markets;
/// @notice A list of all markets
ICErc20[] public allMarkets;
/**
* @dev Maps borrowers to booleans indicating if they have entered any markets
*/
mapping(address => bool) internal borrowers;
/// @notice A list of all borrowers who have entered markets
address[] public allBorrowers;
// Indexes of borrower account addresses in the `allBorrowers` array
mapping(address => uint256) internal borrowerIndexes;
/**
* @dev Maps suppliers to booleans indicating if they have ever supplied to any markets
*/
mapping(address => bool) public suppliers;
/// @notice All cTokens addresses mapped by their underlying token addresses
mapping(address => ICErc20) public cTokensByUnderlying;
/// @notice Whether or not the supplier whitelist is enforced
bool public enforceWhitelist;
/// @notice Maps addresses to booleans indicating if they are allowed to supply assets (i.e., mint cTokens)
mapping(address => bool) public whitelist;
/// @notice An array of all whitelisted accounts
address[] public whitelistArray;
// Indexes of account addresses in the `whitelistArray` array
mapping(address => uint256) internal whitelistIndexes;
/**
* @notice The Pause Guardian can pause certain actions as a safety mechanism.
* Actions which allow users to remove their own assets cannot be paused.
* Liquidation / seizing / transfer can only be paused globally, not by market.
*/
address public pauseGuardian;
bool public _mintGuardianPaused;
bool public _borrowGuardianPaused;
bool public transferGuardianPaused;
bool public seizeGuardianPaused;
mapping(address => bool) public mintGuardianPaused;
mapping(address => bool) public borrowGuardianPaused;
}
contract ComptrollerV3Storage is ComptrollerV2Storage {
/// @notice The borrowCapGuardian can set borrowCaps to any number for any market. Lowering the borrow cap could disable borrowing on the given market.
address public borrowCapGuardian;
/// @notice Borrow caps enforced by borrowAllowed for each cToken address. Defaults to zero which corresponds to unlimited borrowing.
mapping(address => uint256) public borrowCaps;
/// @notice Supply caps enforced by mintAllowed for each cToken address. Defaults to zero which corresponds to unlimited supplying.
mapping(address => uint256) public supplyCaps;
/// @notice RewardsDistributor contracts to notify of flywheel changes.
address[] public rewardsDistributors;
/// @dev Guard variable for pool-wide/cross-asset re-entrancy checks
bool internal _notEntered;
/// @dev Whether or not _notEntered has been initialized
bool internal _notEnteredInitialized;
/// @notice RewardsDistributor to list for claiming, but not to notify of flywheel changes.
address[] public nonAccruingRewardsDistributors;
/// @dev cap for each user's borrows against specific assets - denominated in the borrowed asset
mapping(address => mapping(address => uint256)) public borrowCapForCollateral;
/// @dev blacklist to disallow the borrowing of an asset against specific collateral
mapping(address => mapping(address => bool)) public borrowingAgainstCollateralBlacklist;
/// @dev set of whitelisted accounts that are allowed to bypass the borrowing against specific collateral cap
mapping(address => mapping(address => EnumerableSet.AddressSet)) internal borrowCapForCollateralWhitelist;
/// @dev set of whitelisted accounts that are allowed to bypass the borrow cap
mapping(address => mapping(address => EnumerableSet.AddressSet))
internal borrowingAgainstCollateralBlacklistWhitelist;
/// @dev set of whitelisted accounts that are allowed to bypass the supply cap
mapping(address => EnumerableSet.AddressSet) internal supplyCapWhitelist;
/// @dev set of whitelisted accounts that are allowed to bypass the borrow cap
mapping(address => EnumerableSet.AddressSet) internal borrowCapWhitelist;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;
contract ComptrollerErrorReporter {
enum Error {
NO_ERROR,
UNAUTHORIZED,
COMPTROLLER_MISMATCH,
INSUFFICIENT_SHORTFALL,
INSUFFICIENT_LIQUIDITY,
INVALID_CLOSE_FACTOR,
INVALID_COLLATERAL_FACTOR,
INVALID_LIQUIDATION_INCENTIVE,
MARKET_NOT_LISTED,
MARKET_ALREADY_LISTED,
MATH_ERROR,
NONZERO_BORROW_BALANCE,
PRICE_ERROR,
REJECTION,
SNAPSHOT_ERROR,
TOO_MANY_ASSETS,
TOO_MUCH_REPAY,
SUPPLIER_NOT_WHITELISTED,
BORROW_BELOW_MIN,
SUPPLY_ABOVE_MAX,
NONZERO_TOTAL_SUPPLY
}
enum FailureInfo {
ACCEPT_ADMIN_PENDING_ADMIN_CHECK,
ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK,
ADD_REWARDS_DISTRIBUTOR_OWNER_CHECK,
EXIT_MARKET_BALANCE_OWED,
EXIT_MARKET_REJECTION,
TOGGLE_ADMIN_RIGHTS_OWNER_CHECK,
TOGGLE_AUTO_IMPLEMENTATIONS_ENABLED_OWNER_CHECK,
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_LIQUIDATION_INCENTIVE_OWNER_CHECK,
SET_LIQUIDATION_INCENTIVE_VALIDATION,
SET_PENDING_ADMIN_OWNER_CHECK,
SET_PENDING_IMPLEMENTATION_CONTRACT_CHECK,
SET_PENDING_IMPLEMENTATION_OWNER_CHECK,
SET_PRICE_ORACLE_OWNER_CHECK,
SET_WHITELIST_ENFORCEMENT_OWNER_CHECK,
SET_WHITELIST_STATUS_OWNER_CHECK,
SUPPORT_MARKET_EXISTS,
SUPPORT_MARKET_OWNER_CHECK,
SET_PAUSE_GUARDIAN_OWNER_CHECK,
UNSUPPORT_MARKET_OWNER_CHECK,
UNSUPPORT_MARKET_DOES_NOT_EXIST,
UNSUPPORT_MARKET_IN_USE
}
/**
* @dev `error` corresponds to enum Error; `info` corresponds to enum FailureInfo, and `detail` is an arbitrary
* contract-specific code that enables us to report opaque error codes from upgradeable contracts.
**/
event Failure(uint256 error, uint256 info, uint256 detail);
/**
* @dev use this when reporting a known error from the money market or a non-upgradeable collaborator
*/
function fail(Error err, FailureInfo info) internal returns (uint256) {
emit Failure(uint256(err), uint256(info), 0);
return uint256(err);
}
/**
* @dev use this when reporting an opaque error from an upgradeable collaborator contract
*/
function failOpaque(
Error err,
FailureInfo info,
uint256 opaqueError
) internal returns (uint256) {
emit Failure(uint256(err), uint256(info), opaqueError);
return uint256(err);
}
}
contract TokenErrorReporter {
enum Error {
NO_ERROR,
UNAUTHORIZED,
BAD_INPUT,
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,
UTILIZATION_ABOVE_MAX
}
/*
* 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_NEW_TOTAL_IONIC_FEES_CALCULATION_FAILED,
ACCRUE_INTEREST_NEW_TOTAL_ADMIN_FEES_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,
NEW_UTILIZATION_RATE_ABOVE_MAX,
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,
WITHDRAW_IONIC_FEES_ACCRUE_INTEREST_FAILED,
WITHDRAW_IONIC_FEES_CASH_NOT_AVAILABLE,
WITHDRAW_IONIC_FEES_FRESH_CHECK,
WITHDRAW_IONIC_FEES_VALIDATION,
WITHDRAW_ADMIN_FEES_ACCRUE_INTEREST_FAILED,
WITHDRAW_ADMIN_FEES_CASH_NOT_AVAILABLE,
WITHDRAW_ADMIN_FEES_FRESH_CHECK,
WITHDRAW_ADMIN_FEES_VALIDATION,
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,
TOGGLE_ADMIN_RIGHTS_OWNER_CHECK,
SET_PENDING_ADMIN_OWNER_CHECK,
SET_ADMIN_FEE_ACCRUE_INTEREST_FAILED,
SET_ADMIN_FEE_ADMIN_CHECK,
SET_ADMIN_FEE_FRESH_CHECK,
SET_ADMIN_FEE_BOUNDS_CHECK,
SET_IONIC_FEE_ACCRUE_INTEREST_FAILED,
SET_IONIC_FEE_FRESH_CHECK,
SET_IONIC_FEE_BOUNDS_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
}
/**
* @dev `error` corresponds to enum Error; `info` corresponds to enum FailureInfo, and `detail` is an arbitrary
* contract-specific code that enables us to report opaque error codes from upgradeable contracts.
**/
event Failure(uint256 error, uint256 info, uint256 detail);
/**
* @dev use this when reporting a known error from the money market or a non-upgradeable collaborator
*/
function fail(Error err, FailureInfo info) internal returns (uint256) {
emit Failure(uint256(err), uint256(info), 0);
return uint256(err);
}
/**
* @dev use this when reporting an opaque error from an upgradeable collaborator contract
*/
function failOpaque(
Error err,
FailureInfo info,
uint256 opaqueError
) internal returns (uint256) {
emit Failure(uint256(err), uint256(info), opaqueError);
return err == Error.COMPTROLLER_REJECTION ? 1000 + opaqueError : uint256(err);
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;
import "./CarefulMath.sol";
import "./ExponentialNoError.sol";
/**
* @title Exponential module for storing fixed-precision decimals
* @author Compound
* @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(uint256 num, uint256 denom) internal pure returns (MathError, Exp memory) {
(MathError err0, uint256 scaledNumerator) = mulUInt(num, expScale);
if (err0 != MathError.NO_ERROR) {
return (err0, Exp({ mantissa: 0 }));
}
(MathError err1, uint256 rational) = divUInt(scaledNumerator, denom);
if (err1 != MathError.NO_ERROR) {
return (err1, Exp({ mantissa: 0 }));
}
return (MathError.NO_ERROR, Exp({ mantissa: rational }));
}
/**
* @dev Adds two exponentials, returning a new exponential.
*/
function addExp(Exp memory a, Exp memory b) internal pure returns (MathError, Exp memory) {
(MathError error, uint256 result) = addUInt(a.mantissa, b.mantissa);
return (error, Exp({ mantissa: result }));
}
/**
* @dev Subtracts two exponentials, returning a new exponential.
*/
function subExp(Exp memory a, Exp memory b) internal pure returns (MathError, Exp memory) {
(MathError error, uint256 result) = subUInt(a.mantissa, b.mantissa);
return (error, Exp({ mantissa: result }));
}
/**
* @dev Multiply an Exp by a scalar, returning a new Exp.
*/
function mulScalar(Exp memory a, uint256 scalar) internal pure returns (MathError, Exp memory) {
(MathError err0, uint256 scaledMantissa) = mulUInt(a.mantissa, scalar);
if (err0 != MathError.NO_ERROR) {
return (err0, Exp({ mantissa: 0 }));
}
return (MathError.NO_ERROR, Exp({ mantissa: scaledMantissa }));
}
/**
* @dev Multiply an Exp by a scalar, then truncate to return an unsigned integer.
*/
function mulScalarTruncate(Exp memory a, uint256 scalar) internal pure returns (MathError, uint256) {
(MathError err, Exp memory product) = mulScalar(a, scalar);
if (err != MathError.NO_ERROR) {
return (err, 0);
}
return (MathError.NO_ERROR, truncate(product));
}
/**
* @dev Divide an Exp by a scalar, returning a new Exp.
*/
function divScalar(Exp memory a, uint256 scalar) internal pure returns (MathError, Exp memory) {
(MathError err0, uint256 descaledMantissa) = divUInt(a.mantissa, scalar);
if (err0 != MathError.NO_ERROR) {
return (err0, Exp({ mantissa: 0 }));
}
return (MathError.NO_ERROR, Exp({ mantissa: descaledMantissa }));
}
/**
* @dev Divide a scalar by an Exp, returning a new Exp.
*/
function divScalarByExp(uint256 scalar, Exp memory divisor) internal pure returns (MathError, Exp memory) {
/*
We are doing this as:
getExp(mulUInt(expScale, scalar), divisor.mantissa)
How it works:
Exp = a / b;
Scalar = s;
`s / (a / b)` = `b * s / a` and since for an Exp `a = mantissa, b = expScale`
*/
(MathError err0, uint256 numerator) = mulUInt(expScale, scalar);
if (err0 != MathError.NO_ERROR) {
return (err0, Exp({ mantissa: 0 }));
}
return getExp(numerator, divisor.mantissa);
}
/**
* @dev Divide a scalar by an Exp, then truncate to return an unsigned integer.
*/
function divScalarByExpTruncate(uint256 scalar, Exp memory divisor) internal pure returns (MathError, uint256) {
(MathError err, Exp memory fraction) = divScalarByExp(scalar, divisor);
if (err != MathError.NO_ERROR) {
return (err, 0);
}
return (MathError.NO_ERROR, truncate(fraction));
}
/**
* @dev Multiplies two exponentials, returning a new exponential.
*/
function mulExp(Exp memory a, Exp memory b) internal pure returns (MathError, Exp memory) {
(MathError err0, uint256 doubleScaledProduct) = mulUInt(a.mantissa, b.mantissa);
if (err0 != MathError.NO_ERROR) {
return (err0, Exp({ mantissa: 0 }));
}
// We add half the scale before dividing so that we get rounding instead of truncation.
// See "Listing 6" and text above it at https://accu.org/index.php/journals/1717
// Without this change, a result like 6.6...e-19 will be truncated to 0 instead of being rounded to 1e-18.
(MathError err1, uint256 doubleScaledProductWithHalfScale) = addUInt(halfExpScale, doubleScaledProduct);
if (err1 != MathError.NO_ERROR) {
return (err1, Exp({ mantissa: 0 }));
}
(MathError err2, uint256 product) = divUInt(doubleScaledProductWithHalfScale, expScale);
// The only error `div` can return is MathError.DIVISION_BY_ZERO but we control `expScale` and it is not zero.
assert(err2 == MathError.NO_ERROR);
return (MathError.NO_ERROR, Exp({ mantissa: product }));
}
/**
* @dev Multiplies two exponentials given their mantissas, returning a new exponential.
*/
function mulExp(uint256 a, uint256 b) internal pure returns (MathError, Exp memory) {
return mulExp(Exp({ mantissa: a }), Exp({ mantissa: b }));
}
/**
* @dev Multiplies three exponentials, returning a new exponential.
*/
function mulExp3(
Exp memory a,
Exp memory b,
Exp memory c
) internal pure returns (MathError, Exp memory) {
(MathError err, Exp memory ab) = mulExp(a, b);
if (err != MathError.NO_ERROR) {
return (err, ab);
}
return mulExp(ab, c);
}
/**
* @dev Divides two exponentials, returning a new exponential.
* (a/scale) / (b/scale) = (a/scale) * (scale/b) = a/b,
* which we can scale as an Exp by calling getExp(a.mantissa, b.mantissa)
*/
function divExp(Exp memory a, Exp memory b) internal pure returns (MathError, Exp memory) {
return getExp(a.mantissa, b.mantissa);
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;
/**
* @title Exponential module for storing fixed-precision decimals
* @author Compound
* @notice Exp is a struct which stores decimals with a fixed precision of 18 decimal places.
* Thus, if we wanted to store the 5.1, mantissa would store 5.1e18. That is:
* `Exp({mantissa: 5100000000000000000})`.
*/
contract ExponentialNoError {
uint256 constant expScale = 1e18;
uint256 constant doubleScale = 1e36;
uint256 constant halfExpScale = expScale / 2;
uint256 constant mantissaOne = expScale;
struct Exp {
uint256 mantissa;
}
struct Double {
uint256 mantissa;
}
/**
* @dev Truncates the given exp to a whole number value.
* For example, truncate(Exp{mantissa: 15 * expScale}) = 15
*/
function truncate(Exp memory exp) internal pure returns (uint256) {
// Note: We are not using careful math here as we're performing a division that cannot fail
return exp.mantissa / expScale;
}
/**
* @dev Multiply an Exp by a scalar, then truncate to return an unsigned integer.
*/
function mul_ScalarTruncate(Exp memory a, uint256 scalar) internal pure returns (uint256) {
Exp memory product = mul_(a, scalar);
return truncate(product);
}
/**
* @dev Multiply an Exp by a scalar, truncate, then add an to an unsigned integer, returning an unsigned integer.
*/
function mul_ScalarTruncateAddUInt(
Exp memory a,
uint256 scalar,
uint256 addend
) internal pure returns (uint256) {
Exp memory product = mul_(a, scalar);
return add_(truncate(product), addend);
}
/**
* @dev Checks if first Exp is less than second Exp.
*/
function lessThanExp(Exp memory left, Exp memory right) internal pure returns (bool) {
return left.mantissa < right.mantissa;
}
/**
* @dev Checks if left Exp <= right Exp.
*/
function lessThanOrEqualExp(Exp memory left, Exp memory right) internal pure returns (bool) {
return left.mantissa <= right.mantissa;
}
/**
* @dev Checks if left Exp > right Exp.
*/
function greaterThanExp(Exp memory left, Exp memory right) internal pure returns (bool) {
return left.mantissa > right.mantissa;
}
/**
* @dev returns true if Exp is exactly zero
*/
function isZeroExp(Exp memory value) internal pure returns (bool) {
return value.mantissa == 0;
}
function safe224(uint256 n, string memory errorMessage) internal pure returns (uint224) {
require(n < 2**224, errorMessage);
return uint224(n);
}
function safe32(uint256 n, string memory errorMessage) internal pure returns (uint32) {
require(n < 2**32, errorMessage);
return uint32(n);
}
function add_(Exp memory a, Exp memory b) internal pure returns (Exp memory) {
return Exp({ mantissa: add_(a.mantissa, b.mantissa) });
}
function add_(Double memory a, Double memory b) internal pure returns (Double memory) {
return Double({ mantissa: add_(a.mantissa, b.mantissa) });
}
function add_(uint256 a, uint256 b) internal pure returns (uint256) {
return add_(a, b, "addition overflow");
}
function add_(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, errorMessage);
return c;
}
function sub_(Exp memory a, Exp memory b) internal pure returns (Exp memory) {
return Exp({ mantissa: sub_(a.mantissa, b.mantissa) });
}
function sub_(Double memory a, Double memory b) internal pure returns (Double memory) {
return Double({ mantissa: sub_(a.mantissa, b.mantissa) });
}
function sub_(uint256 a, uint256 b) internal pure returns (uint256) {
return sub_(a, b, "subtraction underflow");
}
function sub_(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
function mul_(Exp memory a, Exp memory b) internal pure returns (Exp memory) {
return Exp({ mantissa: mul_(a.mantissa, b.mantissa) / expScale });
}
function mul_(Exp memory a, uint256 b) internal pure returns (Exp memory) {
return Exp({ mantissa: mul_(a.mantissa, b) });
}
function mul_(uint256 a, Exp memory b) internal pure returns (uint256) {
return mul_(a, b.mantissa) / expScale;
}
function mul_(Double memory a, Double memory b) internal pure returns (Double memory) {
return Double({ mantissa: mul_(a.mantissa, b.mantissa) / doubleScale });
}
function mul_(Double memory a, uint256 b) internal pure returns (Double memory) {
return Double({ mantissa: mul_(a.mantissa, b) });
}
function mul_(uint256 a, Double memory b) internal pure returns (uint256) {
return mul_(a, b.mantissa) / doubleScale;
}
function mul_(uint256 a, uint256 b) internal pure returns (uint256) {
return mul_(a, b, "multiplication overflow");
}
function mul_(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
if (a == 0 || b == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, errorMessage);
return c;
}
function div_(Exp memory a, Exp memory b) internal pure returns (Exp memory) {
return Exp({ mantissa: div_(mul_(a.mantissa, expScale), b.mantissa) });
}
function div_(Exp memory a, uint256 b) internal pure returns (Exp memory) {
return Exp({ mantissa: div_(a.mantissa, b) });
}
function div_(uint256 a, Exp memory b) internal pure returns (uint256) {
return div_(mul_(a, expScale), b.mantissa);
}
function div_(Double memory a, Double memory b) internal pure returns (Double memory) {
return Double({ mantissa: div_(mul_(a.mantissa, doubleScale), b.mantissa) });
}
function div_(Double memory a, uint256 b) internal pure returns (Double memory) {
return Double({ mantissa: div_(a.mantissa, b) });
}
function div_(uint256 a, Double memory b) internal pure returns (uint256) {
return div_(mul_(a, doubleScale), b.mantissa);
}
function div_(uint256 a, uint256 b) internal pure returns (uint256) {
return div_(a, b, "divide by zero");
}
function div_(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
function fraction(uint256 a, uint256 b) internal pure returns (Double memory) {
return Double({ mantissa: div_(mul_(a, doubleScale), b) });
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;
import "../ionic/AuthoritiesRegistry.sol";
interface IFeeDistributor {
function minBorrowEth() external view returns (uint256);
function maxUtilizationRate() external view returns (uint256);
function interestFeeRate() external view returns (uint256);
function latestComptrollerImplementation(address oldImplementation) external view returns (address);
function latestCErc20Delegate(uint8 delegateType)
external
view
returns (address cErc20Delegate, bytes memory becomeImplementationData);
function latestPluginImplementation(address oldImplementation) external view returns (address);
function getComptrollerExtensions(address comptroller) external view returns (address[] memory);
function getCErc20DelegateExtensions(address cErc20Delegate) external view returns (address[] memory);
function deployCErc20(
uint8 delegateType,
bytes calldata constructorData,
bytes calldata becomeImplData
) external returns (address);
function canCall(
address pool,
address user,
address target,
bytes4 functionSig
) external view returns (bool);
function authoritiesRegistry() external view returns (AuthoritiesRegistry);
fallback() external payable;
receive() external payable;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;
/**
* @title Compound's InterestRateModel Interface
* @author Compound
*/
abstract contract InterestRateModel {
/// @notice Indicator that this is an InterestRateModel contract (for inspection)
bool public constant isInterestRateModel = true;
/**
* @notice Calculates the current borrow interest rate per block
* @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 block (as a percentage, and scaled by 1e18)
*/
function getBorrowRate(
uint256 cash,
uint256 borrows,
uint256 reserves
) public view virtual returns (uint256);
/**
* @notice Calculates the current supply interest rate per block
* @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 block (as a percentage, and scaled by 1e18)
*/
function getSupplyRate(
uint256 cash,
uint256 borrows,
uint256 reserves,
uint256 reserveFactorMantissa
) public view virtual returns (uint256);
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
import { SafeOwnableUpgradeable } from "../ionic/SafeOwnableUpgradeable.sol";
/**
* @title AddressesProvider
* @notice The Addresses Provider serves as a central storage of system internal and external
* contract addresses that change between deploys and across chains
* @author Veliko Minkov <[email protected]>
*/
contract AddressesProvider is SafeOwnableUpgradeable {
mapping(string => address) private _addresses;
mapping(address => Contract) public plugins;
mapping(address => Contract) public flywheelRewards;
mapping(address => RedemptionStrategy) public redemptionStrategiesConfig;
mapping(address => FundingStrategy) public fundingStrategiesConfig;
JarvisPool[] public jarvisPoolsConfig;
CurveSwapPool[] public curveSwapPoolsConfig;
mapping(address => mapping(address => address)) public balancerPoolForTokens;
/// @dev Initializer to set the admin that can set and change contracts addresses
function initialize(address owner) public initializer {
__SafeOwnable_init(owner);
}
/**
* @dev The contract address and a string that uniquely identifies the contract's interface
*/
struct Contract {
address addr;
string contractInterface;
}
struct RedemptionStrategy {
address addr;
string contractInterface;
address outputToken;
}
struct FundingStrategy {
address addr;
string contractInterface;
address inputToken;
}
struct JarvisPool {
address syntheticToken;
address collateralToken;
address liquidityPool;
uint256 expirationTime;
}
struct CurveSwapPool {
address poolAddress;
address[] coins;
}
/**
* @dev sets the address and contract interface ID of the flywheel for the reward token
* @param rewardToken the reward token address
* @param flywheelRewardsModule the flywheel rewards module address
* @param contractInterface a string that uniquely identifies the contract's interface
*/
function setFlywheelRewards(
address rewardToken,
address flywheelRewardsModule,
string calldata contractInterface
) public onlyOwner {
flywheelRewards[rewardToken] = Contract(flywheelRewardsModule, contractInterface);
}
/**
* @dev sets the address and contract interface ID of the ERC4626 plugin for the asset
* @param asset the asset address
* @param plugin the ERC4626 plugin address
* @param contractInterface a string that uniquely identifies the contract's interface
*/
function setPlugin(
address asset,
address plugin,
string calldata contractInterface
) public onlyOwner {
plugins[asset] = Contract(plugin, contractInterface);
}
/**
* @dev sets the address and contract interface ID of the redemption strategy for the asset
* @param asset the asset address
* @param strategy redemption strategy address
* @param contractInterface a string that uniquely identifies the contract's interface
*/
function setRedemptionStrategy(
address asset,
address strategy,
string calldata contractInterface,
address outputToken
) public onlyOwner {
redemptionStrategiesConfig[asset] = RedemptionStrategy(strategy, contractInterface, outputToken);
}
function getRedemptionStrategy(address asset) public view returns (RedemptionStrategy memory) {
return redemptionStrategiesConfig[asset];
}
/**
* @dev sets the address and contract interface ID of the funding strategy for the asset
* @param asset the asset address
* @param strategy funding strategy address
* @param contractInterface a string that uniquely identifies the contract's interface
*/
function setFundingStrategy(
address asset,
address strategy,
string calldata contractInterface,
address inputToken
) public onlyOwner {
fundingStrategiesConfig[asset] = FundingStrategy(strategy, contractInterface, inputToken);
}
function getFundingStrategy(address asset) public view returns (FundingStrategy memory) {
return fundingStrategiesConfig[asset];
}
/**
* @dev configures the Jarvis pool of a Jarvis synthetic token
* @param syntheticToken the synthetic token address
* @param collateralToken the collateral token address
* @param liquidityPool the liquidity pool address
* @param expirationTime the operation expiration time
*/
function setJarvisPool(
address syntheticToken,
address collateralToken,
address liquidityPool,
uint256 expirationTime
) public onlyOwner {
jarvisPoolsConfig.push(JarvisPool(syntheticToken, collateralToken, liquidityPool, expirationTime));
}
function setCurveSwapPool(address poolAddress, address[] calldata coins) public onlyOwner {
curveSwapPoolsConfig.push(CurveSwapPool(poolAddress, coins));
}
/**
* @dev Sets an address for an id replacing the address saved in the addresses map
* @param id The id
* @param newAddress The address to set
*/
function setAddress(string calldata id, address newAddress) external onlyOwner {
_addresses[id] = newAddress;
}
/**
* @dev Returns an address by id
* @return The address
*/
function getAddress(string calldata id) public view returns (address) {
return _addresses[id];
}
function getCurveSwapPools() public view returns (CurveSwapPool[] memory) {
return curveSwapPoolsConfig;
}
function getJarvisPools() public view returns (JarvisPool[] memory) {
return jarvisPoolsConfig;
}
function setBalancerPoolForTokens(
address inputToken,
address outputToken,
address pool
) external onlyOwner {
balancerPoolForTokens[inputToken][outputToken] = pool;
}
function getBalancerPoolForTokens(address inputToken, address outputToken) external view returns (address) {
return balancerPoolForTokens[inputToken][outputToken];
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;
import { PoolRolesAuthority } from "../ionic/PoolRolesAuthority.sol";
import { SafeOwnableUpgradeable } from "../ionic/SafeOwnableUpgradeable.sol";
import { IonicComptroller } from "../compound/ComptrollerInterface.sol";
import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
contract AuthoritiesRegistry is SafeOwnableUpgradeable {
mapping(address => PoolRolesAuthority) public poolsAuthorities;
PoolRolesAuthority public poolAuthLogic;
address public leveredPositionsFactory;
bool public noAuthRequired;
function initialize(address _leveredPositionsFactory) public initializer {
__SafeOwnable_init(msg.sender);
leveredPositionsFactory = _leveredPositionsFactory;
poolAuthLogic = new PoolRolesAuthority();
}
function reinitialize(address _leveredPositionsFactory) public onlyOwnerOrAdmin {
leveredPositionsFactory = _leveredPositionsFactory;
poolAuthLogic = new PoolRolesAuthority();
// for Neon the auth is not required
noAuthRequired = block.chainid == 245022934;
}
function createPoolAuthority(address pool) public onlyOwner returns (PoolRolesAuthority auth) {
require(address(poolsAuthorities[pool]) == address(0), "already created");
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(address(poolAuthLogic), _getProxyAdmin(), "");
auth = PoolRolesAuthority(address(proxy));
auth.initialize(address(this));
poolsAuthorities[pool] = auth;
auth.openPoolSupplierCapabilities(IonicComptroller(pool));
auth.setUserRole(address(this), auth.REGISTRY_ROLE(), true);
// sets the registry owner as the auth owner
reconfigureAuthority(pool);
}
function reconfigureAuthority(address poolAddress) public {
IonicComptroller pool = IonicComptroller(poolAddress);
PoolRolesAuthority auth = poolsAuthorities[address(pool)];
if (msg.sender != poolAddress || address(auth) != address(0)) {
require(address(auth) != address(0), "no such authority");
require(msg.sender == owner() || msg.sender == poolAddress, "not owner or pool");
auth.configureRegistryCapabilities();
auth.configurePoolSupplierCapabilities(pool);
auth.configurePoolBorrowerCapabilities(pool);
// everyone can be a liquidator
auth.configureOpenPoolLiquidatorCapabilities(pool);
auth.configureLeveredPositionCapabilities(pool);
if (auth.owner() != owner()) {
auth.setOwner(owner());
}
}
}
function canCall(
address pool,
address user,
address target,
bytes4 functionSig
) external view returns (bool) {
PoolRolesAuthority authorityForPool = poolsAuthorities[pool];
if (address(authorityForPool) == address(0)) {
return noAuthRequired;
} else {
// allow only if an auth exists and it allows the action
return authorityForPool.canCall(user, target, functionSig);
}
}
function setUserRole(
address pool,
address user,
uint8 role,
bool enabled
) external {
PoolRolesAuthority poolAuth = poolsAuthorities[pool];
require(address(poolAuth) != address(0), "auth does not exist");
require(msg.sender == owner() || msg.sender == leveredPositionsFactory, "not owner or factory");
require(msg.sender != leveredPositionsFactory || role == poolAuth.LEVERED_POSITION_ROLE(), "only lev pos role");
poolAuth.setUserRole(user, role, enabled);
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;
/**
* @notice a base contract for logic extensions that use the diamond pattern storage
* to map the functions when looking up the extension contract to delegate to.
*/
abstract contract DiamondExtension {
/**
* @return a list of all the function selectors that this logic extension exposes
*/
function _getExtensionFunctions() external pure virtual returns (bytes4[] memory);
}
// When no function exists for function called
error FunctionNotFound(bytes4 _functionSelector);
// When no extension exists for function called
error ExtensionNotFound(bytes4 _functionSelector);
// When the function is already added
error FunctionAlreadyAdded(bytes4 _functionSelector, address _currentImpl);
abstract contract DiamondBase {
/**
* @dev register a logic extension
* @param extensionToAdd the extension whose functions are to be added
* @param extensionToReplace the extension whose functions are to be removed/replaced
*/
function _registerExtension(DiamondExtension extensionToAdd, DiamondExtension extensionToReplace) external virtual;
function _listExtensions() public view returns (address[] memory) {
return LibDiamond.listExtensions();
}
fallback() external {
address extension = LibDiamond.getExtensionForFunction(msg.sig);
if (extension == address(0)) revert FunctionNotFound(msg.sig);
// Execute external function from extension using delegatecall and return any value.
assembly {
// copy function selector and any arguments
calldatacopy(0, 0, calldatasize())
// execute function call using the extension
let result := delegatecall(gas(), extension, 0, calldatasize(), 0, 0)
// get any return value
returndatacopy(0, 0, returndatasize())
// return any return value or error back to the caller
switch result
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
}
/**
* @notice a library to use in a contract, whose logic is extended with diamond extension
*/
library LibDiamond {
bytes32 constant DIAMOND_STORAGE_POSITION = keccak256("diamond.extensions.diamond.storage");
struct Function {
address extension;
bytes4 selector;
}
struct LogicStorage {
Function[] functions;
address[] extensions;
}
function getExtensionForFunction(bytes4 msgSig) internal view returns (address) {
return getExtensionForSelector(msgSig, diamondStorage());
}
function diamondStorage() internal pure returns (LogicStorage storage ds) {
bytes32 position = DIAMOND_STORAGE_POSITION;
assembly {
ds.slot := position
}
}
function listExtensions() internal view returns (address[] memory) {
return diamondStorage().extensions;
}
function registerExtension(DiamondExtension extensionToAdd, DiamondExtension extensionToReplace) internal {
if (address(extensionToReplace) != address(0)) {
removeExtension(extensionToReplace);
}
addExtension(extensionToAdd);
}
function removeExtension(DiamondExtension extension) internal {
LogicStorage storage ds = diamondStorage();
// remove all functions of the extension to replace
removeExtensionFunctions(extension);
for (uint8 i = 0; i < ds.extensions.length; i++) {
if (ds.extensions[i] == address(extension)) {
ds.extensions[i] = ds.extensions[ds.extensions.length - 1];
ds.extensions.pop();
}
}
}
function addExtension(DiamondExtension extension) internal {
LogicStorage storage ds = diamondStorage();
for (uint8 i = 0; i < ds.extensions.length; i++) {
require(ds.extensions[i] != address(extension), "extension already added");
}
addExtensionFunctions(extension);
ds.extensions.push(address(extension));
}
function removeExtensionFunctions(DiamondExtension extension) internal {
bytes4[] memory fnsToRemove = extension._getExtensionFunctions();
LogicStorage storage ds = diamondStorage();
for (uint16 i = 0; i < fnsToRemove.length; i++) {
bytes4 selectorToRemove = fnsToRemove[i];
// must never fail
assert(address(extension) == getExtensionForSelector(selectorToRemove, ds));
// swap with the last element in the selectorAtIndex array and remove the last element
uint16 indexToKeep = getIndexForSelector(selectorToRemove, ds);
ds.functions[indexToKeep] = ds.functions[ds.functions.length - 1];
ds.functions.pop();
}
}
function addExtensionFunctions(DiamondExtension extension) internal {
bytes4[] memory fnsToAdd = extension._getExtensionFunctions();
LogicStorage storage ds = diamondStorage();
uint16 functionsCount = uint16(ds.functions.length);
for (uint256 functionsIndex = 0; functionsIndex < fnsToAdd.length; functionsIndex++) {
bytes4 selector = fnsToAdd[functionsIndex];
address oldImplementation = getExtensionForSelector(selector, ds);
if (oldImplementation != address(0)) revert FunctionAlreadyAdded(selector, oldImplementation);
ds.functions.push(Function(address(extension), selector));
functionsCount++;
}
}
function getExtensionForSelector(bytes4 selector, LogicStorage storage ds) internal view returns (address) {
uint256 fnsLen = ds.functions.length;
for (uint256 i = 0; i < fnsLen; i++) {
if (ds.functions[i].selector == selector) return ds.functions[i].extension;
}
return address(0);
}
function getIndexForSelector(bytes4 selector, LogicStorage storage ds) internal view returns (uint16) {
uint16 fnsLen = uint16(ds.functions.length);
for (uint16 i = 0; i < fnsLen; i++) {
if (ds.functions[i].selector == selector) return i;
}
return type(uint16).max;
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;
interface IFlashLoanReceiver {
function receiveFlashLoan(
address borrowedAsset,
uint256 borrowedAmount,
bytes calldata data
) external;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;
import { IonicComptroller, ComptrollerInterface } from "../compound/ComptrollerInterface.sol";
import { ICErc20, CTokenSecondExtensionInterface, CTokenFirstExtensionInterface } from "../compound/CTokenInterfaces.sol";
import { RolesAuthority, Authority } from "solmate/auth/authorities/RolesAuthority.sol";
import "openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
contract PoolRolesAuthority is RolesAuthority, Initializable {
constructor() RolesAuthority(address(0), Authority(address(0))) {
_disableInitializers();
}
function initialize(address _owner) public initializer {
owner = _owner;
authority = this;
}
// up to 256 roles
uint8 public constant REGISTRY_ROLE = 0;
uint8 public constant SUPPLIER_ROLE = 1;
uint8 public constant BORROWER_ROLE = 2;
uint8 public constant LIQUIDATOR_ROLE = 3;
uint8 public constant LEVERED_POSITION_ROLE = 4;
function configureRegistryCapabilities() external requiresAuth {
setRoleCapability(REGISTRY_ROLE, address(this), PoolRolesAuthority.configureRegistryCapabilities.selector, true);
setRoleCapability(
REGISTRY_ROLE,
address(this),
PoolRolesAuthority.configurePoolSupplierCapabilities.selector,
true
);
setRoleCapability(
REGISTRY_ROLE,
address(this),
PoolRolesAuthority.configurePoolBorrowerCapabilities.selector,
true
);
setRoleCapability(
REGISTRY_ROLE,
address(this),
PoolRolesAuthority.configureClosedPoolLiquidatorCapabilities.selector,
true
);
setRoleCapability(
REGISTRY_ROLE,
address(this),
PoolRolesAuthority.configureOpenPoolLiquidatorCapabilities.selector,
true
);
setRoleCapability(
REGISTRY_ROLE,
address(this),
PoolRolesAuthority.configureLeveredPositionCapabilities.selector,
true
);
setRoleCapability(REGISTRY_ROLE, address(this), RolesAuthority.setUserRole.selector, true);
}
function openPoolSupplierCapabilities(IonicComptroller pool) external requiresAuth {
_setPublicPoolSupplierCapabilities(pool, true);
}
function closePoolSupplierCapabilities(IonicComptroller pool) external requiresAuth {
_setPublicPoolSupplierCapabilities(pool, false);
}
function _setPublicPoolSupplierCapabilities(IonicComptroller pool, bool setPublic) internal {
setPublicCapability(address(pool), pool.enterMarkets.selector, setPublic);
setPublicCapability(address(pool), pool.exitMarket.selector, setPublic);
ICErc20[] memory allMarkets = pool.getAllMarkets();
for (uint256 i = 0; i < allMarkets.length; i++) {
bytes4[] memory selectors = getSupplierMarketSelectors();
for (uint256 j = 0; j < selectors.length; j++) {
setPublicCapability(address(allMarkets[i]), selectors[j], setPublic);
}
}
}
function configurePoolSupplierCapabilities(IonicComptroller pool) external requiresAuth {
_configurePoolSupplierCapabilities(pool, SUPPLIER_ROLE);
}
function getSupplierMarketSelectors() internal pure returns (bytes4[] memory selectors) {
uint8 fnsCount = 6;
selectors = new bytes4[](fnsCount);
selectors[--fnsCount] = CTokenSecondExtensionInterface.mint.selector;
selectors[--fnsCount] = CTokenSecondExtensionInterface.redeem.selector;
selectors[--fnsCount] = CTokenSecondExtensionInterface.redeemUnderlying.selector;
selectors[--fnsCount] = CTokenFirstExtensionInterface.transfer.selector;
selectors[--fnsCount] = CTokenFirstExtensionInterface.transferFrom.selector;
selectors[--fnsCount] = CTokenFirstExtensionInterface.approve.selector;
require(fnsCount == 0, "use the correct array length");
return selectors;
}
function _configurePoolSupplierCapabilities(IonicComptroller pool, uint8 role) internal {
setRoleCapability(role, address(pool), pool.enterMarkets.selector, true);
setRoleCapability(role, address(pool), pool.exitMarket.selector, true);
ICErc20[] memory allMarkets = pool.getAllMarkets();
for (uint256 i = 0; i < allMarkets.length; i++) {
bytes4[] memory selectors = getSupplierMarketSelectors();
for (uint256 j = 0; j < selectors.length; j++) {
setRoleCapability(role, address(allMarkets[i]), selectors[j], true);
}
}
}
function openPoolBorrowerCapabilities(IonicComptroller pool) external requiresAuth {
_setPublicPoolBorrowerCapabilities(pool, true);
}
function closePoolBorrowerCapabilities(IonicComptroller pool) external requiresAuth {
_setPublicPoolBorrowerCapabilities(pool, false);
}
function _setPublicPoolBorrowerCapabilities(IonicComptroller pool, bool setPublic) internal {
ICErc20[] memory allMarkets = pool.getAllMarkets();
for (uint256 i = 0; i < allMarkets.length; i++) {
setPublicCapability(address(allMarkets[i]), allMarkets[i].borrow.selector, setPublic);
setPublicCapability(address(allMarkets[i]), allMarkets[i].repayBorrow.selector, setPublic);
setPublicCapability(address(allMarkets[i]), allMarkets[i].repayBorrowBehalf.selector, setPublic);
setPublicCapability(address(allMarkets[i]), allMarkets[i].flash.selector, setPublic);
}
}
function configurePoolBorrowerCapabilities(IonicComptroller pool) external requiresAuth {
// borrowers have the SUPPLIER_ROLE capabilities by default
_configurePoolSupplierCapabilities(pool, BORROWER_ROLE);
ICErc20[] memory allMarkets = pool.getAllMarkets();
for (uint256 i = 0; i < allMarkets.length; i++) {
setRoleCapability(BORROWER_ROLE, address(allMarkets[i]), allMarkets[i].borrow.selector, true);
setRoleCapability(BORROWER_ROLE, address(allMarkets[i]), allMarkets[i].repayBorrow.selector, true);
setRoleCapability(BORROWER_ROLE, address(allMarkets[i]), allMarkets[i].repayBorrowBehalf.selector, true);
setRoleCapability(BORROWER_ROLE, address(allMarkets[i]), allMarkets[i].flash.selector, true);
}
}
function configureClosedPoolLiquidatorCapabilities(IonicComptroller pool) external requiresAuth {
ICErc20[] memory allMarkets = pool.getAllMarkets();
for (uint256 i = 0; i < allMarkets.length; i++) {
setPublicCapability(address(allMarkets[i]), allMarkets[i].liquidateBorrow.selector, false);
setRoleCapability(LIQUIDATOR_ROLE, address(allMarkets[i]), allMarkets[i].liquidateBorrow.selector, true);
setRoleCapability(LIQUIDATOR_ROLE, address(allMarkets[i]), allMarkets[i].redeem.selector, true);
}
}
function configureOpenPoolLiquidatorCapabilities(IonicComptroller pool) external requiresAuth {
ICErc20[] memory allMarkets = pool.getAllMarkets();
for (uint256 i = 0; i < allMarkets.length; i++) {
setPublicCapability(address(allMarkets[i]), allMarkets[i].liquidateBorrow.selector, true);
// TODO this leaves redeeming open for everyone
setPublicCapability(address(allMarkets[i]), allMarkets[i].redeem.selector, true);
}
}
function configureLeveredPositionCapabilities(IonicComptroller pool) external requiresAuth {
setRoleCapability(LEVERED_POSITION_ROLE, address(pool), pool.enterMarkets.selector, true);
setRoleCapability(LEVERED_POSITION_ROLE, address(pool), pool.exitMarket.selector, true);
ICErc20[] memory allMarkets = pool.getAllMarkets();
for (uint256 i = 0; i < allMarkets.length; i++) {
setRoleCapability(LEVERED_POSITION_ROLE, address(allMarkets[i]), allMarkets[i].mint.selector, true);
setRoleCapability(LEVERED_POSITION_ROLE, address(allMarkets[i]), allMarkets[i].redeem.selector, true);
setRoleCapability(LEVERED_POSITION_ROLE, address(allMarkets[i]), allMarkets[i].redeemUnderlying.selector, true);
setRoleCapability(LEVERED_POSITION_ROLE, address(allMarkets[i]), allMarkets[i].borrow.selector, true);
setRoleCapability(LEVERED_POSITION_ROLE, address(allMarkets[i]), allMarkets[i].repayBorrow.selector, true);
setRoleCapability(LEVERED_POSITION_ROLE, address(allMarkets[i]), allMarkets[i].flash.selector, true);
}
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;
import "openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol";
/**
* @dev Ownable extension that requires a two-step process of setting the pending owner and the owner accepting it.
* @notice Existing OwnableUpgradeable contracts cannot be upgraded due to the extra storage variable
* that will shift the other.
*/
abstract contract SafeOwnableUpgradeable is OwnableUpgradeable {
/**
* @notice Pending owner of this contract
*/
address public pendingOwner;
function __SafeOwnable_init(address owner_) internal onlyInitializing {
__Ownable_init();
_transferOwnership(owner_);
}
struct AddressSlot {
address value;
}
modifier onlyOwnerOrAdmin() {
bool isOwner = owner() == _msgSender();
if (!isOwner) {
address admin = _getProxyAdmin();
bool isAdmin = admin == _msgSender();
require(isAdmin, "Ownable: caller is neither the owner nor the admin");
}
_;
}
/**
* @notice Emitted when pendingOwner is changed
*/
event NewPendingOwner(address oldPendingOwner, address newPendingOwner);
/**
* @notice Emitted when pendingOwner is accepted, which means owner is updated
*/
event NewOwner(address oldOwner, address newOwner);
/**
* @notice Begins transfer of owner rights. The newPendingOwner must call `_acceptOwner` to finalize the transfer.
* @dev Owner function to begin change of owner. The newPendingOwner must call `_acceptOwner` to finalize the transfer.
* @param newPendingOwner New pending owner.
*/
function _setPendingOwner(address newPendingOwner) public onlyOwner {
// Save current value, if any, for inclusion in log
address oldPendingOwner = pendingOwner;
// Store pendingOwner with value newPendingOwner
pendingOwner = newPendingOwner;
// Emit NewPendingOwner(oldPendingOwner, newPendingOwner)
emit NewPendingOwner(oldPendingOwner, newPendingOwner);
}
/**
* @notice Accepts transfer of owner rights. msg.sender must be pendingOwner
* @dev Owner function for pending owner to accept role and update owner
*/
function _acceptOwner() public {
// Check caller is pendingOwner and pendingOwner ≠ address(0)
require(msg.sender == pendingOwner, "not the pending owner");
// Save current values for inclusion in log
address oldOwner = owner();
address oldPendingOwner = pendingOwner;
// Store owner with value pendingOwner
_transferOwnership(pendingOwner);
// Clear the pending value
pendingOwner = address(0);
emit NewOwner(oldOwner, pendingOwner);
emit NewPendingOwner(oldPendingOwner, pendingOwner);
}
function renounceOwnership() public override onlyOwner {
// do not remove this overriding fn
revert("not used anymore");
}
function transferOwnership(address newOwner) public override onlyOwner {
emit NewPendingOwner(pendingOwner, newOwner);
pendingOwner = newOwner;
}
function _getProxyAdmin() internal view returns (address admin) {
bytes32 _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
AddressSlot storage adminSlot;
assembly {
adminSlot.slot := _ADMIN_SLOT
}
admin = adminSlot.value;
}
}// SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.0; import "../compound/CTokenInterfaces.sol"; /** * @title BasePriceOracle * @notice Returns prices of underlying tokens directly without the caller having to specify a cToken address. * @dev Implements the `PriceOracle` interface. * @author David Lucid <[email protected]> (https://github.com/davidlucid) */ interface BasePriceOracle { /** * @notice Get the price of an underlying asset. * @param underlying The underlying asset to get the price of. * @return The underlying asset price in ETH as a mantissa (scaled by 1e18). * Zero means the price is unavailable. */ function price(address underlying) external view returns (uint256); /** * @notice Get the underlying price of a cToken asset * @param cToken The cToken to get the underlying price of * @return The underlying asset price mantissa (scaled by 1e18). * Zero means the price is unavailable. */ function getUnderlyingPrice(ICErc20 cToken) external view returns (uint256); }
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.0;
/// @title Multicall interface
/// @notice Enables calling multiple methods in a single call to the contract
interface IMulticall {
/// @notice Call multiple functions in the current contract and return the data from all of them if they all succeed
/// @dev The `msg.value` should not be trusted for any method callable from multicall.
/// @param data The encoded function data for each of the calls to make to this contract
/// @return results The results from each of the calls passed in via data
function multicall(bytes[] calldata data) external payable returns (bytes[] memory results);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.0;
import "./IMulticall.sol";
/// @title Multicall
/// @notice Enables calling multiple methods in a single call to the contract
abstract contract Multicall is IMulticall {
/// @inheritdoc IMulticall
function multicall(bytes[] calldata data) public payable virtual override returns (bytes[] memory results) {
results = new bytes[](data.length);
for (uint256 i = 0; i < data.length; i++) {
(bool success, bytes memory result) = address(this).delegatecall(data[i]);
if (!success) {
// Next 5 lines from https://ethereum.stackexchange.com/a/83577
if (result.length < 68) revert();
assembly {
result := add(result, 0x04)
}
revert(abi.decode(result, (string)));
}
results[i] = result;
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";
/**
* @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 OwnableUpgradeable is Initializable, ContextUpgradeable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
function __Ownable_init() internal onlyInitializing {
__Ownable_init_unchained();
}
function __Ownable_init_unchained() internal onlyInitializing {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: setting the version to 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized < type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Internal function that returns the initialized version. Returns `_initialized`
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Internal function that returns the initialized version. Returns `_initializing`
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.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 ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Provides a flexible and updatable auth pattern which is completely separate from application logic.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Auth.sol)
/// @author Modified from Dappsys (https://github.com/dapphub/ds-auth/blob/master/src/auth.sol)
abstract contract Auth {
event OwnerUpdated(address indexed user, address indexed newOwner);
event AuthorityUpdated(address indexed user, Authority indexed newAuthority);
address public owner;
Authority public authority;
constructor(address _owner, Authority _authority) {
owner = _owner;
authority = _authority;
emit OwnerUpdated(msg.sender, _owner);
emit AuthorityUpdated(msg.sender, _authority);
}
modifier requiresAuth() virtual {
require(isAuthorized(msg.sender, msg.sig), "UNAUTHORIZED");
_;
}
function isAuthorized(address user, bytes4 functionSig) internal view virtual returns (bool) {
Authority auth = authority; // Memoizing authority saves us a warm SLOAD, around 100 gas.
// Checking if the caller is the owner only after calling the authority saves gas in most cases, but be
// aware that this makes protected functions uncallable even to the owner if the authority is out of order.
return (address(auth) != address(0) && auth.canCall(user, address(this), functionSig)) || user == owner;
}
function setAuthority(Authority newAuthority) public virtual {
// We check if the caller is the owner first because we want to ensure they can
// always swap out the authority even if it's reverting or using up a lot of gas.
require(msg.sender == owner || authority.canCall(msg.sender, address(this), msg.sig));
authority = newAuthority;
emit AuthorityUpdated(msg.sender, newAuthority);
}
function setOwner(address newOwner) public virtual requiresAuth {
owner = newOwner;
emit OwnerUpdated(msg.sender, newOwner);
}
}
/// @notice A generic interface for a contract which provides authorization data to an Auth instance.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Auth.sol)
/// @author Modified from Dappsys (https://github.com/dapphub/ds-auth/blob/master/src/auth.sol)
interface Authority {
function canCall(
address user,
address target,
bytes4 functionSig
) external view returns (bool);
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
import {Auth, Authority} from "../Auth.sol";
/// @notice Role based Authority that supports up to 256 roles.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/authorities/RolesAuthority.sol)
/// @author Modified from Dappsys (https://github.com/dapphub/ds-roles/blob/master/src/roles.sol)
contract RolesAuthority is Auth, Authority {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event UserRoleUpdated(address indexed user, uint8 indexed role, bool enabled);
event PublicCapabilityUpdated(address indexed target, bytes4 indexed functionSig, bool enabled);
event RoleCapabilityUpdated(uint8 indexed role, address indexed target, bytes4 indexed functionSig, bool enabled);
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor(address _owner, Authority _authority) Auth(_owner, _authority) {}
/*//////////////////////////////////////////////////////////////
ROLE/USER STORAGE
//////////////////////////////////////////////////////////////*/
mapping(address => bytes32) public getUserRoles;
mapping(address => mapping(bytes4 => bool)) public isCapabilityPublic;
mapping(address => mapping(bytes4 => bytes32)) public getRolesWithCapability;
function doesUserHaveRole(address user, uint8 role) public view virtual returns (bool) {
return (uint256(getUserRoles[user]) >> role) & 1 != 0;
}
function doesRoleHaveCapability(
uint8 role,
address target,
bytes4 functionSig
) public view virtual returns (bool) {
return (uint256(getRolesWithCapability[target][functionSig]) >> role) & 1 != 0;
}
/*//////////////////////////////////////////////////////////////
AUTHORIZATION LOGIC
//////////////////////////////////////////////////////////////*/
function canCall(
address user,
address target,
bytes4 functionSig
) public view virtual override returns (bool) {
return
isCapabilityPublic[target][functionSig] ||
bytes32(0) != getUserRoles[user] & getRolesWithCapability[target][functionSig];
}
/*//////////////////////////////////////////////////////////////
ROLE CAPABILITY CONFIGURATION LOGIC
//////////////////////////////////////////////////////////////*/
function setPublicCapability(
address target,
bytes4 functionSig,
bool enabled
) public virtual requiresAuth {
isCapabilityPublic[target][functionSig] = enabled;
emit PublicCapabilityUpdated(target, functionSig, enabled);
}
function setRoleCapability(
uint8 role,
address target,
bytes4 functionSig,
bool enabled
) public virtual requiresAuth {
if (enabled) {
getRolesWithCapability[target][functionSig] |= bytes32(1 << role);
} else {
getRolesWithCapability[target][functionSig] &= ~bytes32(1 << role);
}
emit RoleCapabilityUpdated(role, target, functionSig, enabled);
}
/*//////////////////////////////////////////////////////////////
USER ROLE ASSIGNMENT LOGIC
//////////////////////////////////////////////////////////////*/
function setUserRole(
address user,
uint8 role,
bool enabled
) public virtual requiresAuth {
if (enabled) {
getUserRoles[user] |= bytes32(1 << role);
} else {
getUserRoles[user] &= ~bytes32(1 << role);
}
emit UserRoleUpdated(user, role, enabled);
}
}{
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": [],
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"cashPrior","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"interestAccumulated","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"borrowIndex","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalBorrows","type":"uint256"}],"name":"AccrueInterest","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"error","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"info","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"detail","type":"uint256"}],"name":"Failure","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Flash","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldAdminFeeMantissa","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newAdminFeeMantissa","type":"uint256"}],"name":"NewAdminFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldIonicFeeMantissa","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newIonicFeeMantissa","type":"uint256"}],"name":"NewIonicFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract InterestRateModel","name":"oldInterestRateModel","type":"address"},{"indexed":false,"internalType":"contract InterestRateModel","name":"newInterestRateModel","type":"address"}],"name":"NewMarketInterestRateModel","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldReserveFactorMantissa","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newReserveFactorMantissa","type":"uint256"}],"name":"NewReserveFactor","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"_getExtensionFunctions","outputs":[{"internalType":"bytes4[]","name":"","type":"bytes4[]"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_ap","type":"address"}],"name":"_setAddressesProvider","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newAdminFeeMantissa","type":"uint256"}],"name":"_setAdminFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract InterestRateModel","name":"newInterestRateModel","type":"address"}],"name":"_setInterestRateModel","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"}],"name":"_setNameAndSymbol","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newReserveFactorMantissa","type":"uint256"}],"name":"_setReserveFactor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"accrualBlockNumber","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"accrueInterest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"adminFeeMantissa","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ap","outputs":[{"internalType":"contract AddressesProvider","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOfUnderlying","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"borrowBalanceCurrent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"borrowIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"borrowRatePerBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"borrowAmount","type":"uint256"}],"name":"borrowRatePerBlockAfterBorrow","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"comptroller","outputs":[{"internalType":"contract IonicComptroller","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"exchangeRateCurrent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeSeizeShareMantissa","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"flash","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getAccountSnapshot","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTotalUnderlyingSupplied","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"interestRateModel","outputs":[{"internalType":"contract InterestRateModel","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ionicAdmin","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ionicFeeMantissa","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"protocolSeizeShareMantissa","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"registerInSFS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"reserveFactorMantissa","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"supplyRatePerBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"mintAmount","type":"uint256"}],"name":"supplyRatePerBlockAfterDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"withdrawAmount","type":"uint256"}],"name":"supplyRatePerBlockAfterWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAdminFees","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalBorrows","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalBorrowsCurrent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalIonicFees","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalReserves","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"dst","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"src","type":"address"},{"internalType":"address","name":"dst","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"underlying","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]Contract Creation Code
608060405234801561001057600080fd5b50613d23806100206000396000f3fe60806040526004361061027d5760003560e01c80638d02d9a11161014f578063b1e23dbb116100c1578063cfcd4c071161007a578063cfcd4c0714610754578063dd62ed3e14610774578063f2b3abbd146107ba578063f3fdb15a146107da578063f8f9da28146107fa578063fca7820b1461080f57600080fd5b8063b1e23dbb1461068d578063bd6d894d146106ad578063be99f119146106c2578063c37f68e2146106de578063c3bf11cd1461071e578063c91a424f1461073457600080fd5b8063a6afed9511610113578063a6afed95146105ed578063a9059cbb14610602578063aa5af0fd14610622578063ac9650d814610638578063ae9d70b014610658578063b0a190761461066d57600080fd5b80638d02d9a1146105765780638f840ddd1461058c57806391dd36c6146105a257806395d89b41146105c25780639826394b146105d757600080fd5b80633c4f743c116101f35780636c540baf116101ac5780636c540baf146104be5780636f307dc3146104d457806370a08231146104f457806373acee981461052a5780637f15e2161461053f57806389f8132e1461055457600080fd5b80633c4f743c1461040557806347bd37181461043d5780634aeb3d9a146104535780635fe3b5671461046857806361feacff1461048d5780636752e702146104a357600080fd5b806323b872dd1161024557806323b872dd14610337578063313ce5671461035757806334154d4c1461038357806335daea64146103a55780633af9e669146103c55780633c3b4b89146103e557600080fd5b806306fdde0314610282578063095ea7b3146102ad578063173b9904146102dd57806317bfdfbc1461030157806318160ddd14610321575b600080fd5b34801561028e57600080fd5b5061029761082f565b6040516102a49190613681565b60405180910390f35b3480156102b957600080fd5b506102cd6102c83660046136a9565b6108bd565b60405190151581526020016102a4565b3480156102e957600080fd5b506102f360085481565b6040519081526020016102a4565b34801561030d57600080fd5b506102f361031c3660046136d5565b6109d4565b34801561032d57600080fd5b506102f3600f5481565b34801561034357600080fd5b506102cd6103523660046136f2565b610b84565b34801561036357600080fd5b506003546103719060ff1681565b60405160ff90911681526020016102a4565b34801561038f57600080fd5b506103a361039e366004613775565b610c59565b005b3480156103b157600080fd5b506102f36103c03660046137e1565b610c9d565b3480156103d157600080fd5b506102f36103e03660046136d5565b610e1f565b3480156103f157600080fd5b506103a36104003660046137fa565b610eba565b34801561041157600080fd5b50601454610425906001600160a01b031681565b6040516001600160a01b0390911681526020016102a4565b34801561044957600080fd5b506102f3600b5481565b34801561045f57600080fd5b506102f361111b565b34801561047457600080fd5b506003546104259061010090046001600160a01b031681565b34801561049957600080fd5b506102f3600d5481565b3480156104af57600080fd5b506102f3666379da05b6000081565b3480156104ca57600080fd5b506102f360095481565b3480156104e057600080fd5b50601354610425906001600160a01b031681565b34801561050057600080fd5b506102f361050f3660046136d5565b6001600160a01b031660009081526010602052604090205490565b34801561053657600080fd5b506102f36111b8565b34801561054b57600080fd5b506102f3611248565b34801561056057600080fd5b50610569611319565b6040516102a49190613846565b34801561058257600080fd5b506102f360065481565b34801561059857600080fd5b506102f3600c5481565b3480156105ae57600080fd5b506102f36105bd3660046137e1565b6119f3565b3480156105ce57600080fd5b50610297611bb0565b3480156105e357600080fd5b506102f3600e5481565b3480156105f957600080fd5b506102f3611bbd565b34801561060e57600080fd5b506102cd61061d3660046136a9565b611cce565b34801561062e57600080fd5b506102f3600a5481565b61064b610646366004613894565b611da2565b6040516102a49190613909565b34801561066457600080fd5b506102f3611dae565b34801561067957600080fd5b506103a36106883660046136d5565b611ed4565b34801561069957600080fd5b506102f36106a83660046137e1565b611f1a565b3480156106b957600080fd5b506102f361204a565b3480156106ce57600080fd5b506102f367016345785d8a000081565b3480156106ea57600080fd5b506106fe6106f93660046136d5565b612178565b6040805194855260208501939093529183015260608201526080016102a4565b34801561072a57600080fd5b506102f360075481565b34801561074057600080fd5b50600054610425906001600160a01b031681565b34801561076057600080fd5b506102f361076f3660046137e1565b6121be565b34801561078057600080fd5b506102f361078f36600461396b565b6001600160a01b03918216600090815260116020908152604080832093909416825291909152205490565b3480156107c657600080fd5b506102f36107d53660046136d5565b6122e5565b3480156107e657600080fd5b50600454610425906001600160a01b031681565b34801561080657600080fd5b506102f3612424565b34801561081b57600080fd5b506102f361082a3660046137e1565b6124eb565b6001805461083c906139a4565b80601f0160208091040260200160405190810160405280929190818152602001828054610868906139a4565b80156108b55780601f1061088a576101008083540402835291602001916108b5565b820191906000526020600020905b81548152906001019060200180831161089857829003601f168201915b505050505081565b60008054600354604051631beb2b9760e31b81526001600160a01b039283169263df595cb89261090a9261010090910490911690339030906001600160e01b0319883516906004016139d9565b602060405180830381865afa158015610927573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061094b9190613a0c565b6109705760405162461bcd60e51b815260040161096790613a2e565b60405180910390fd5b3360008181526011602090815260408083206001600160a01b038816808552908352928190208690555185815283917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a35060019392505050565b6000804360095414156109ea5750600a54610a65565b6000306001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a2a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a4e9190613a56565b90506000610a5c43836125a1565b60200151925050505b6001600160a01b0383166000908152601260205260408120805482918291610a94575060009695505050505050565b8054610aa09086612836565b90945092506000846003811115610ab957610ab9613a6f565b14610b065760405162461bcd60e51b815260206004820152601e60248201527f216d756c55496e74206f766572666c6f7720636865636b206661696c656400006044820152606401610967565b610b14838260010154612878565b90945091506000846003811115610b2d57610b2d613a6f565b14610b7a5760405162461bcd60e51b815260206004820152601e60248201527f2164697655496e74206f766572666c6f7720636865636b206661696c656400006044820152606401610967565b5095945050505050565b600080610b90816128a3565b60008054600354604051631beb2b9760e31b81526001600160a01b039283169363df595cb893610bda93610100900416913391309190356001600160e01b031916906004016139d9565b602060405180830381865afa158015610bf7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c1b9190613a0c565b610c375760405162461bcd60e51b815260040161096790613a2e565b6000610c4533878787612967565b149150610c5181612c1e565b509392505050565b610c61612c9d565b610c7d5760405162461bcd60e51b815260040161096790613a85565b610c896001858561358c565b50610c966002838361358c565b5050505050565b600080306001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa158015610cde573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d029190613a56565b905082811015610d4d5760405162461bcd60e51b81526020600482015260166024820152750dac2e4d6cae840c6c2e6d040dcdee840cadcdeeaced60531b6044820152606401610967565b6004546001600160a01b031663b8168816610d688584613abb565b600b54600e54600d54600c54610d7e9190613ad2565b610d889190613ad2565b600654600754600854610d9b9190613ad2565b610da59190613ad2565b6040516001600160e01b031960e087901b16815260048101949094526024840192909252604483015260648201526084015b602060405180830381865afa158015610df4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e189190613a56565b9392505050565b6000806040518060200160405280610e3561204a565b90526001600160a01b038416600090815260106020526040812054919250908190610e61908490612e14565b90925090506000826003811115610e7a57610e7a613a6f565b14610eb25760405162461bcd60e51b81526020600482015260086024820152672162616c616e636560c01b6044820152606401610967565b949350505050565b60008054600354604051631beb2b9760e31b81526001600160a01b039283169363df595cb893610f0493610100900416913391309190356001600160e01b031916906004016139d9565b602060405180830381865afa158015610f21573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f459190613a0c565b610f615760405162461bcd60e51b815260040161096790613a2e565b610f69611bbd565b5082600b6000828254610f7c9190613ad2565b9091555030905060405163067db1b360e01b8152336004820152602481018590526001600160a01b03919091169063067db1b390604401600060405180830381600087803b158015610fcd57600080fd5b505af1158015610fe1573d6000803e3d6000fd5b505060135460405163012b1f4560e71b815233935063958fa2809250611019916001600160a01b031690879087908790600401613aea565b600060405180830381600087803b15801561103357600080fd5b505af1158015611047573d6000803e3d6000fd5b505050506110523090565b6040516304d7c4cd60e21b8152336004820152602481018590526001600160a01b03919091169063135f1334906044016020604051808303816000875af11580156110a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110c59190613a56565b5082600b60008282546110d89190613abb565b909155505060408051338152602081018590527fe756d016d0e956882a6de9c72a2fe06d7d488ecbe6d76628713077ea7930cff8910160405180910390a1505050565b6000600d54600e54600c546111309190613ad2565b61113a9190613ad2565b600b54306001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa15801561117b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061119f9190613a56565b6111a99190613ad2565b6111b39190613abb565b905090565b60004360095414156111cb5750600b5490565b6000306001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa15801561120b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061122f9190613a56565b9050600061123d43836125a1565b606001519392505050565b6000611252612c9d565b8061126c575060035461010090046001600160a01b031633145b6112885760405162461bcd60e51b815260040161096790613a85565b604051632210724360e11b8152738fba84867ba458e7c6e2c024d2de3d0b5c3ea1c26004820152738680ceabcb9b56913c519c069add6bc3494b7020908190634420e486906024016020604051808303816000875af11580156112ef573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113139190613a56565b91505090565b60408051601980825261034082019092526060919060009082602082016103208036833701905050905063a9059cbb60e01b8161135584613b48565b93508360ff168151811061136b5761136b613b65565b6001600160e01b0319909216602092830291909101909101526323b872dd60e01b8161139684613b48565b93508360ff16815181106113ac576113ac613b65565b6001600160e01b031990921660209283029190910190910152636eb1769f60e11b816113d784613b48565b93508360ff16815181106113ed576113ed613b65565b6001600160e01b03199092166020928302919091019091015263095ea7b360e01b8161141884613b48565b93508360ff168151811061142e5761142e613b65565b6001600160e01b0319909216602092830291909101909101526370a0823160e01b8161145984613b48565b93508360ff168151811061146f5761146f613b65565b6001600160e01b0319909216602092830291909101909101526348ee9b6360e11b8161149a84613b48565b93508360ff16815181106114b0576114b0613b65565b6001600160e01b03199092166020928302919091019091015263f2b3abbd60e01b816114db84613b48565b93508360ff16815181106114f1576114f1613b65565b6001600160e01b031990921660209283029190910190910152630d05535360e21b8161151c84613b48565b93508360ff168151811061153257611532613b65565b6001600160e01b031990921660209283029190910190910152635850c83b60e11b8161155d84613b48565b93508360ff168151811061157357611573613b65565b6001600160e01b03199092166020928302919091019091015263fca7820b60e01b8161159e84613b48565b93508360ff16815181106115b4576115b4613b65565b6001600160e01b031990921660209283029190910190910152630ae9d70b60e41b816115df84613b48565b93508360ff16815181106115f5576115f5613b65565b6001600160e01b031990921660209283029190910190910152631f1f3b4560e31b8161162084613b48565b93508360ff168151811061163657611636613b65565b6001600160e01b03199092166020928302919091019091015263bd6d894d60e01b8161166184613b48565b93508360ff168151811061167757611677613b65565b6001600160e01b03199092166020928302919091019091015263a6afed9560e01b816116a284613b48565b93508360ff16815181106116b8576116b8613b65565b6001600160e01b031990921660209283029190910190910152630e759dd360e31b816116e384613b48565b93508360ff16815181106116f9576116f9613b65565b6001600160e01b031990921660209283029190910190910152633af9e66960e01b8161172484613b48565b93508360ff168151811061173a5761173a613b65565b6001600160e01b031990921660209283029190910190910152631592ca1b60e31b8161176584613b48565b93508360ff168151811061177b5761177b613b65565b6001600160e01b03199092166020928302919091019091015263b1e23dbb60e01b816117a684613b48565b93508360ff16815181106117bc576117bc613b65565b6001600160e01b031990921660209283029190910190910152630d76ba9960e21b816117e784613b48565b93508360ff16815181106117fd576117fd613b65565b6001600160e01b03199092166020928302919091019091015263cfcd4c0760e01b8161182884613b48565b93508360ff168151811061183e5761183e613b65565b6001600160e01b0319909216602092830291909101909101526325759ecd60e11b8161186984613b48565b93508360ff168151811061187f5761187f613b65565b6001600160e01b031990921660209283029190910190910152633c3b4b8960e01b816118aa84613b48565b93508360ff16815181106118c0576118c0613b65565b6001600160e01b0319909216602092830291909101909101526361bfb47160e11b816118eb84613b48565b93508360ff168151811061190157611901613b65565b6001600160e01b0319909216602092830291909101909101526305eff7ef60e21b8161192c84613b48565b93508360ff168151811061194257611942613b65565b6001600160e01b031990921660209283029190910190910152633f8af10b60e11b8161196d84613b48565b93508360ff168151811061198357611983613b65565b6001600160e01b03199092166020928302919091019091015260ff8216156119ed5760405162461bcd60e51b815260206004820152601c60248201527f7573652074686520636f7272656374206172726179206c656e677468000000006044820152606401610967565b92915050565b6000806119ff816128a3565b611a07611bbd565b504360095414611a2457611a1d600a6052612e66565b9150611ba1565b600019831415611a345760065492505b60008060009054906101000a90046001600160a01b03166001600160a01b031663dd86fea16040518163ffffffff1660e01b8152600401602060405180830381865afa158015611a88573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611aac9190613a56565b9050670de0b6b3a76400008185600854611ac69190613ad2565b611ad09190613ad2565b1115611aea57611ae260026053612e66565b925050611ba1565b8360065414611b4e57611afb612c9d565b611b0b57611ae260016051612e66565b600680549085905560408051828152602081018790527fcdd0b588250e1398549f79cfdb8217c186688822905d6715b0834ea1c865594a910160405180910390a1505b8060075414611b9a57600780549082905560408051828152602081018490527fedec4b9c99c2cdb231e7fd036f861e0445b015916700f41b9835f984cb9be4cb910160405180910390a1505b60005b9250505b611baa81612c1e565b50919050565b6002805461083c906139a4565b6009546000904390811415611bd3576000611313565b6000306001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa158015611c13573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c379190613a56565b90506000611c4583836125a1565b6009849055602081810151600a819055606080840151600b819055608080860151600c5560a0860151600e5560c0860151600d5560e0860151604080518a815296870191909152850193909352908301529192507f4dec04e750ca11537cabcd8a9eab06494de08da3735bc8871cd41250e190bc04910160405180910390a16000935050505090565b600080611cda816128a3565b60008054600354604051631beb2b9760e31b81526001600160a01b039283169363df595cb893611d2493610100900416913391309190356001600160e01b031916906004016139d9565b602060405180830381865afa158015611d41573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d659190613a0c565b611d815760405162461bcd60e51b815260040161096790613a2e565b6000611d8f33338787612967565b149150611d9b81612c1e565b5092915050565b6060610e188383612edf565b6004546000906001600160a01b031663b8168816306001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa158015611e00573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e249190613a56565b600b54600e54600d54600c54611e3a9190613ad2565b611e449190613ad2565b600654600754600854611e579190613ad2565b611e619190613ad2565b6040516001600160e01b031960e087901b16815260048101949094526024840192909252604483015260648201526084015b602060405180830381865afa158015611eb0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111b39190613a56565b611edc612c9d565b611ef85760405162461bcd60e51b815260040161096790613a85565b601480546001600160a01b0319166001600160a01b0392909216919091179055565b6004546000906001600160a01b031663b816881683306001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f6d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f919190613a56565b611f9b9190613ad2565b600b54600e54600d54600c54611fb19190613ad2565b611fbb9190613ad2565b600654600754600854611fce9190613ad2565b611fd89190613ad2565b6040516001600160e01b031960e087901b1681526004810194909452602484019290925260448301526064820152608401602060405180830381865afa158015612026573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119ed9190613a56565b60006009544314156120d8576111b3600f546005546120663090565b6001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa1580156120a3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120c79190613a56565b600b54600c54600d54600e54613030565b6000306001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa158015612118573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061213c9190613a56565b9050600061214a43836125a1565b9050612171816040015160055484846060015185608001518660c001518760a00151613030565b9250505090565b6001600160a01b03811660009081526010602052604081205481908190819081806121a2886109d4565b91506121ac61204a565b90506000989297509095509350915050565b600080306001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa1580156121ff573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122239190613a56565b90508281101561226e5760405162461bcd60e51b81526020600482015260166024820152750dac2e4d6cae840c6c2e6d040dcdee840cadcdeeaced60531b6044820152606401610967565b6004546001600160a01b03166315f240536122898584613abb565b85600b546122979190613ad2565b600e54600d54600c546122aa9190613ad2565b6122b49190613ad2565b6040516001600160e01b031960e086901b168152600481019390935260248301919091526044820152606401610dd7565b6000806122f1816128a3565b6122f9611bbd565b50612302612c9d565b61231257611a1d6001604d612e66565b436009541461232757611a1d600a604c612e66565b826001600160a01b0316632191f92a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612365573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123899190613a0c565b6123bf5760405162461bcd60e51b8152602060048201526007602482015266216e6f7449726d60c81b6044820152606401610967565b600480546001600160a01b038581166001600160a01b031983168117909355604080519190921680825260208201939093527fedffc32e068c7c95dfd4bdfd5c4d939a084d6b11c4199eac8436ed234d72f92691015b60405180910390a16000611b9d565b6004546000906001600160a01b03166315f24053306001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa158015612476573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061249a9190613a56565b600b54600e54600d54600c546124b09190613ad2565b6124ba9190613ad2565b6040516001600160e01b031960e086901b168152600481019390935260248301919091526044820152606401611e93565b6000806124f7816128a3565b6124ff611bbd565b50612508612c9d565b61251857611a1d60016058612e66565b436009541461252d57611a1d600a6059612e66565b670de0b6b3a7640000600754600654856125479190613ad2565b6125519190613ad2565b111561256357611a1d6002605a612e66565b600880549084905560408051828152602081018690527faaa68312e2ea9d50e16af5068410ab56e1a1fd06037b1a35664812c30f8214609101612415565b6125e960405180610100016040528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b6000600e54600d546125fb9190613ad2565b600454600b54600c549293506000926001600160a01b03909216916315f24053918791612629908790613ad2565b6040516001600160e01b031960e086901b168152600481019390935260248301919091526044820152606401602060405180830381865afa158015612672573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126969190613a56565b905065048c273950008111156126ed57818411156126e45760405162461bcd60e51b815260206004820152600b60248201526a21626f72726f775261746560a81b6044820152606401610967565b5065048c273950005b6000806126fc8760095461316f565b9092509050600082600381111561271557612715613a6f565b146127505760405162461bcd60e51b815260206004820152600b60248201526a21626c6f636b44656c746160a81b6044820152606401610967565b868552600f54604080870191909152805160208101909152838152600090612778908361319a565b905061278681600b546131cb565b60e08701819052600b5461279991613ad2565b60608701526040805160208101909152600854815260e0870151600c546127c19291906131e3565b60808701526040805160208101909152600754815260e0870151600e546127e99291906131e3565b60a08701526040805160208101909152600654815260e0870151600d546128119291906131e3565b60c0870152600a54612825908290806131e3565b602087015250939695505050505050565b6000808361284957506000905080612871565b838302836128578683613b7b565b1461286a57600260009250925050612871565b6000925090505b9250929050565b6000808261288c5750600190506000612871565b60006128988486613b7b565b915091509250929050565b600054600160a01b900460ff166128e95760405162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b6044820152606401610967565b8061295757600360019054906101000a90046001600160a01b03166001600160a01b031663c90c20b16040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561293e57600080fd5b505af1158015612952573d6000803e3d6000fd5b505050505b506000805460ff60a01b19169055565b6003546040516317b9b84b60e31b81523060048201526001600160a01b03858116602483015284811660448301526064820184905260009283926101009091049091169063bdcdc258906084016020604051808303816000875af11580156129d3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129f79190613a56565b90508015612a1457612a0c6003605b8361320d565b915050610eb2565b836001600160a01b0316856001600160a01b03161415612a3a57612a0c6002605c612e66565b6000856001600160a01b0316876001600160a01b03161415612a5f5750600019612a87565b506001600160a01b038086166000908152601160209081526040808320938a16835292905220545b600080600080612a97858961316f565b90945092506000846003811115612ab057612ab0613a6f565b14612ace57612ac16009605c612e66565b9650505050505050610eb2565b6001600160a01b038a16600090815260106020526040902054612af1908961316f565b90945091506000846003811115612b0a57612b0a613a6f565b14612b1b57612ac16009605d612e66565b6001600160a01b038916600090815260106020526040902054612b3e90896132af565b90945090506000846003811115612b5757612b57613a6f565b14612b6857612ac16009605e612e66565b6001600160a01b03808b16600090815260106020526040808220859055918b168152208190556000198514612bc0576001600160a01b03808b166000908152601160209081526040808320938f168352929052208390555b886001600160a01b03168a6001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8a604051612c0591815260200190565b60405180910390a35060009a9950505050505050505050565b6000805460ff60a01b1916600160a01b17905580612c9a57600360019054906101000a90046001600160a01b03166001600160a01b031663632e51426040518163ffffffff1660e01b8152600401600060405180830381600087803b158015612c8657600080fd5b505af1158015610c96573d6000803e3d6000fd5b50565b600080600360019054906101000a90046001600160a01b03169050806001600160a01b031663f851a4406040518163ffffffff1660e01b8152600401602060405180830381865afa158015612cf6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d1a9190613b9d565b6001600160a01b0316336001600160a01b0316148015612d975750806001600160a01b0316630a755ec26040518163ffffffff1660e01b8152600401602060405180830381865afa158015612d73573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d979190613a0c565b8061131357506000546001600160a01b0316331480156113135750806001600160a01b031663cf6bfd2d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612df0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113139190613a0c565b600080600080612e2486866132d5565b90925090506000826003811115612e3d57612e3d613a6f565b14612e4e5750915060009050612871565b6000612e5982613351565b9350935050509250929050565b60007f45b96fe442630264581b197e84bbada861235052c5a1aadfff9ea4e40a969aa0836011811115612e9b57612e9b613a6f565b836061811115612ead57612ead613a6f565b60408051928352602083019190915260009082015260600160405180910390a1826011811115610e1857610e18613a6f565b60608167ffffffffffffffff811115612efa57612efa613b32565b604051908082528060200260200182016040528015612f2d57816020015b6060815260200190600190039081612f185790505b50905060005b82811015611d9b5760008030868685818110612f5157612f51613b65565b9050602002810190612f639190613bba565b604051612f71929190613c01565b600060405180830381855af49150503d8060008114612fac576040519150601f19603f3d011682016040523d82523d6000602084013e612fb1565b606091505b509150915081612ffd57604481511015612fca57600080fd5b60048101905080806020019051810190612fe49190613c11565b60405162461bcd60e51b81526004016109679190613681565b8084848151811061301057613010613b65565b60200260200101819052505050808061302890613cb3565b915050612f33565b60008761303e575085613164565b60006130566040518060200160405280600081525090565b60006130778989876130688a8c613ad2565b6130729190613ad2565b613369565b93509050600081600381111561308f5761308f613a6f565b146130ea5760405162461bcd60e51b815260206004820152602560248201527f216164645468656e53756255496e74206f766572666c6f7720636865636b2066604482015264185a5b195960da1b6064820152608401610967565b6130f4838c6133bc565b92509050600081600381111561310c5761310c613a6f565b146131595760405162461bcd60e51b815260206004820152601d60248201527f21676574457870206f766572666c6f7720636865636b206661696c65640000006044820152606401610967565b505191506131649050565b979650505050505050565b60008083831161318e5760006131858486613abb565b91509150612871565b50600390506000612871565b60408051602081019091526000815260405180602001604052806131c2856000015185613487565b90529392505050565b6000806131d8848461319a565b9050610eb281613351565b6000806131f0858561319a565b90506132046131fe82613351565b846134c9565b95945050505050565b60007f45b96fe442630264581b197e84bbada861235052c5a1aadfff9ea4e40a969aa084601181111561324257613242613a6f565b84606181111561325457613254613a6f565b604080519283526020830191909152810184905260600160405180910390a1600384601181111561328757613287613a6f565b146132a35783601181111561329e5761329e613a6f565b610eb2565b610eb2826103e8613ad2565b6000808383018481106132c757600092509050612871565b600260009250925050612871565b60006132ed6040518060200160405280600081525090565b6000806132fe866000015186612836565b9092509050600082600381111561331757613317613a6f565b1461333657506040805160208101909152600081529092509050612871565b60408051602081019091529081526000969095509350505050565b80516000906119ed90670de0b6b3a764000090613b7b565b60008060008061337987876132af565b9092509050600082600381111561339257613392613a6f565b146133a357509150600090506133b4565b6133ad818661316f565b9350935050505b935093915050565b60006133d46040518060200160405280600081525090565b6000806133e986670de0b6b3a7640000612836565b9092509050600082600381111561340257613402613a6f565b1461342157506040805160208101909152600081529092509050612871565b60008061342e8388612878565b9092509050600082600381111561344757613447613a6f565b1461346a5781604051806020016040528060008152509550955050505050612871565b604080516020810190915290815260009890975095505050505050565b6000610e1883836040518060400160405280601781526020017f6d756c7469706c69636174696f6e206f766572666c6f770000000000000000008152506134ff565b6000610e188383604051806040016040528060118152602001706164646974696f6e206f766572666c6f7760781b81525061355b565b600083158061350c575082155b1561351957506000610e18565b60006135258486613cce565b9050836135328683613b7b565b1483906135525760405162461bcd60e51b81526004016109679190613681565b50949350505050565b6000806135688486613ad2565b905082858210156135525760405162461bcd60e51b81526004016109679190613681565b828054613598906139a4565b90600052602060002090601f0160209004810192826135ba5760008555613600565b82601f106135d35782800160ff19823516178555613600565b82800160010185558215613600579182015b828111156136005782358255916020019190600101906135e5565b5061360c929150613610565b5090565b5b8082111561360c5760008155600101613611565b60005b83811015613640578181015183820152602001613628565b8381111561364f576000848401525b50505050565b6000815180845261366d816020860160208601613625565b601f01601f19169290920160200192915050565b602081526000610e186020830184613655565b6001600160a01b0381168114612c9a57600080fd5b600080604083850312156136bc57600080fd5b82356136c781613694565b946020939093013593505050565b6000602082840312156136e757600080fd5b8135610e1881613694565b60008060006060848603121561370757600080fd5b833561371281613694565b9250602084013561372281613694565b929592945050506040919091013590565b60008083601f84011261374557600080fd5b50813567ffffffffffffffff81111561375d57600080fd5b60208301915083602082850101111561287157600080fd5b6000806000806040858703121561378b57600080fd5b843567ffffffffffffffff808211156137a357600080fd5b6137af88838901613733565b909650945060208701359150808211156137c857600080fd5b506137d587828801613733565b95989497509550505050565b6000602082840312156137f357600080fd5b5035919050565b60008060006040848603121561380f57600080fd5b83359250602084013567ffffffffffffffff81111561382d57600080fd5b61383986828701613733565b9497909650939450505050565b6020808252825182820181905260009190848201906040850190845b818110156138885783516001600160e01b03191683529284019291840191600101613862565b50909695505050505050565b600080602083850312156138a757600080fd5b823567ffffffffffffffff808211156138bf57600080fd5b818501915085601f8301126138d357600080fd5b8135818111156138e257600080fd5b8660208260051b85010111156138f757600080fd5b60209290920196919550909350505050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b8281101561395e57603f1988860301845261394c858351613655565b94509285019290850190600101613930565b5092979650505050505050565b6000806040838503121561397e57600080fd5b823561398981613694565b9150602083013561399981613694565b809150509250929050565b600181811c908216806139b857607f821691505b60208210811415611baa57634e487b7160e01b600052602260045260246000fd5b6001600160a01b0394851681529284166020840152921660408201526001600160e01b0319909116606082015260800190565b600060208284031215613a1e57600080fd5b81518015158114610e1857600080fd5b6020808252600e908201526d1b9bdd08185d5d1a1bdc9a5e995960921b604082015260600190565b600060208284031215613a6857600080fd5b5051919050565b634e487b7160e01b600052602160045260246000fd5b60208082526006908201526510b0b236b4b760d11b604082015260600190565b634e487b7160e01b600052601160045260246000fd5b600082821015613acd57613acd613aa5565b500390565b60008219821115613ae557613ae5613aa5565b500190565b6001600160a01b0385168152602081018490526060604082018190528101829052818360808301376000818301608090810191909152601f909201601f191601019392505050565b634e487b7160e01b600052604160045260246000fd5b600060ff821680613b5b57613b5b613aa5565b6000190192915050565b634e487b7160e01b600052603260045260246000fd5b600082613b9857634e487b7160e01b600052601260045260246000fd5b500490565b600060208284031215613baf57600080fd5b8151610e1881613694565b6000808335601e19843603018112613bd157600080fd5b83018035915067ffffffffffffffff821115613bec57600080fd5b60200191503681900382131561287157600080fd5b8183823760009101908152919050565b600060208284031215613c2357600080fd5b815167ffffffffffffffff80821115613c3b57600080fd5b818401915084601f830112613c4f57600080fd5b815181811115613c6157613c61613b32565b604051601f8201601f19908116603f01168101908382118183101715613c8957613c89613b32565b81604052828152876020848701011115613ca257600080fd5b613164836020830160208801613625565b6000600019821415613cc757613cc7613aa5565b5060010190565b6000816000190483118215151615613ce857613ce8613aa5565b50029056fea2646970667358221220baf8e95b13105502451f59762ba110f707d784ebf5504db0cf9ad97cbb65962164736f6c634300080a0033
Deployed Bytecode
0x60806040526004361061027d5760003560e01c80638d02d9a11161014f578063b1e23dbb116100c1578063cfcd4c071161007a578063cfcd4c0714610754578063dd62ed3e14610774578063f2b3abbd146107ba578063f3fdb15a146107da578063f8f9da28146107fa578063fca7820b1461080f57600080fd5b8063b1e23dbb1461068d578063bd6d894d146106ad578063be99f119146106c2578063c37f68e2146106de578063c3bf11cd1461071e578063c91a424f1461073457600080fd5b8063a6afed9511610113578063a6afed95146105ed578063a9059cbb14610602578063aa5af0fd14610622578063ac9650d814610638578063ae9d70b014610658578063b0a190761461066d57600080fd5b80638d02d9a1146105765780638f840ddd1461058c57806391dd36c6146105a257806395d89b41146105c25780639826394b146105d757600080fd5b80633c4f743c116101f35780636c540baf116101ac5780636c540baf146104be5780636f307dc3146104d457806370a08231146104f457806373acee981461052a5780637f15e2161461053f57806389f8132e1461055457600080fd5b80633c4f743c1461040557806347bd37181461043d5780634aeb3d9a146104535780635fe3b5671461046857806361feacff1461048d5780636752e702146104a357600080fd5b806323b872dd1161024557806323b872dd14610337578063313ce5671461035757806334154d4c1461038357806335daea64146103a55780633af9e669146103c55780633c3b4b89146103e557600080fd5b806306fdde0314610282578063095ea7b3146102ad578063173b9904146102dd57806317bfdfbc1461030157806318160ddd14610321575b600080fd5b34801561028e57600080fd5b5061029761082f565b6040516102a49190613681565b60405180910390f35b3480156102b957600080fd5b506102cd6102c83660046136a9565b6108bd565b60405190151581526020016102a4565b3480156102e957600080fd5b506102f360085481565b6040519081526020016102a4565b34801561030d57600080fd5b506102f361031c3660046136d5565b6109d4565b34801561032d57600080fd5b506102f3600f5481565b34801561034357600080fd5b506102cd6103523660046136f2565b610b84565b34801561036357600080fd5b506003546103719060ff1681565b60405160ff90911681526020016102a4565b34801561038f57600080fd5b506103a361039e366004613775565b610c59565b005b3480156103b157600080fd5b506102f36103c03660046137e1565b610c9d565b3480156103d157600080fd5b506102f36103e03660046136d5565b610e1f565b3480156103f157600080fd5b506103a36104003660046137fa565b610eba565b34801561041157600080fd5b50601454610425906001600160a01b031681565b6040516001600160a01b0390911681526020016102a4565b34801561044957600080fd5b506102f3600b5481565b34801561045f57600080fd5b506102f361111b565b34801561047457600080fd5b506003546104259061010090046001600160a01b031681565b34801561049957600080fd5b506102f3600d5481565b3480156104af57600080fd5b506102f3666379da05b6000081565b3480156104ca57600080fd5b506102f360095481565b3480156104e057600080fd5b50601354610425906001600160a01b031681565b34801561050057600080fd5b506102f361050f3660046136d5565b6001600160a01b031660009081526010602052604090205490565b34801561053657600080fd5b506102f36111b8565b34801561054b57600080fd5b506102f3611248565b34801561056057600080fd5b50610569611319565b6040516102a49190613846565b34801561058257600080fd5b506102f360065481565b34801561059857600080fd5b506102f3600c5481565b3480156105ae57600080fd5b506102f36105bd3660046137e1565b6119f3565b3480156105ce57600080fd5b50610297611bb0565b3480156105e357600080fd5b506102f3600e5481565b3480156105f957600080fd5b506102f3611bbd565b34801561060e57600080fd5b506102cd61061d3660046136a9565b611cce565b34801561062e57600080fd5b506102f3600a5481565b61064b610646366004613894565b611da2565b6040516102a49190613909565b34801561066457600080fd5b506102f3611dae565b34801561067957600080fd5b506103a36106883660046136d5565b611ed4565b34801561069957600080fd5b506102f36106a83660046137e1565b611f1a565b3480156106b957600080fd5b506102f361204a565b3480156106ce57600080fd5b506102f367016345785d8a000081565b3480156106ea57600080fd5b506106fe6106f93660046136d5565b612178565b6040805194855260208501939093529183015260608201526080016102a4565b34801561072a57600080fd5b506102f360075481565b34801561074057600080fd5b50600054610425906001600160a01b031681565b34801561076057600080fd5b506102f361076f3660046137e1565b6121be565b34801561078057600080fd5b506102f361078f36600461396b565b6001600160a01b03918216600090815260116020908152604080832093909416825291909152205490565b3480156107c657600080fd5b506102f36107d53660046136d5565b6122e5565b3480156107e657600080fd5b50600454610425906001600160a01b031681565b34801561080657600080fd5b506102f3612424565b34801561081b57600080fd5b506102f361082a3660046137e1565b6124eb565b6001805461083c906139a4565b80601f0160208091040260200160405190810160405280929190818152602001828054610868906139a4565b80156108b55780601f1061088a576101008083540402835291602001916108b5565b820191906000526020600020905b81548152906001019060200180831161089857829003601f168201915b505050505081565b60008054600354604051631beb2b9760e31b81526001600160a01b039283169263df595cb89261090a9261010090910490911690339030906001600160e01b0319883516906004016139d9565b602060405180830381865afa158015610927573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061094b9190613a0c565b6109705760405162461bcd60e51b815260040161096790613a2e565b60405180910390fd5b3360008181526011602090815260408083206001600160a01b038816808552908352928190208690555185815283917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a35060019392505050565b6000804360095414156109ea5750600a54610a65565b6000306001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a2a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a4e9190613a56565b90506000610a5c43836125a1565b60200151925050505b6001600160a01b0383166000908152601260205260408120805482918291610a94575060009695505050505050565b8054610aa09086612836565b90945092506000846003811115610ab957610ab9613a6f565b14610b065760405162461bcd60e51b815260206004820152601e60248201527f216d756c55496e74206f766572666c6f7720636865636b206661696c656400006044820152606401610967565b610b14838260010154612878565b90945091506000846003811115610b2d57610b2d613a6f565b14610b7a5760405162461bcd60e51b815260206004820152601e60248201527f2164697655496e74206f766572666c6f7720636865636b206661696c656400006044820152606401610967565b5095945050505050565b600080610b90816128a3565b60008054600354604051631beb2b9760e31b81526001600160a01b039283169363df595cb893610bda93610100900416913391309190356001600160e01b031916906004016139d9565b602060405180830381865afa158015610bf7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c1b9190613a0c565b610c375760405162461bcd60e51b815260040161096790613a2e565b6000610c4533878787612967565b149150610c5181612c1e565b509392505050565b610c61612c9d565b610c7d5760405162461bcd60e51b815260040161096790613a85565b610c896001858561358c565b50610c966002838361358c565b5050505050565b600080306001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa158015610cde573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d029190613a56565b905082811015610d4d5760405162461bcd60e51b81526020600482015260166024820152750dac2e4d6cae840c6c2e6d040dcdee840cadcdeeaced60531b6044820152606401610967565b6004546001600160a01b031663b8168816610d688584613abb565b600b54600e54600d54600c54610d7e9190613ad2565b610d889190613ad2565b600654600754600854610d9b9190613ad2565b610da59190613ad2565b6040516001600160e01b031960e087901b16815260048101949094526024840192909252604483015260648201526084015b602060405180830381865afa158015610df4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e189190613a56565b9392505050565b6000806040518060200160405280610e3561204a565b90526001600160a01b038416600090815260106020526040812054919250908190610e61908490612e14565b90925090506000826003811115610e7a57610e7a613a6f565b14610eb25760405162461bcd60e51b81526020600482015260086024820152672162616c616e636560c01b6044820152606401610967565b949350505050565b60008054600354604051631beb2b9760e31b81526001600160a01b039283169363df595cb893610f0493610100900416913391309190356001600160e01b031916906004016139d9565b602060405180830381865afa158015610f21573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f459190613a0c565b610f615760405162461bcd60e51b815260040161096790613a2e565b610f69611bbd565b5082600b6000828254610f7c9190613ad2565b9091555030905060405163067db1b360e01b8152336004820152602481018590526001600160a01b03919091169063067db1b390604401600060405180830381600087803b158015610fcd57600080fd5b505af1158015610fe1573d6000803e3d6000fd5b505060135460405163012b1f4560e71b815233935063958fa2809250611019916001600160a01b031690879087908790600401613aea565b600060405180830381600087803b15801561103357600080fd5b505af1158015611047573d6000803e3d6000fd5b505050506110523090565b6040516304d7c4cd60e21b8152336004820152602481018590526001600160a01b03919091169063135f1334906044016020604051808303816000875af11580156110a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110c59190613a56565b5082600b60008282546110d89190613abb565b909155505060408051338152602081018590527fe756d016d0e956882a6de9c72a2fe06d7d488ecbe6d76628713077ea7930cff8910160405180910390a1505050565b6000600d54600e54600c546111309190613ad2565b61113a9190613ad2565b600b54306001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa15801561117b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061119f9190613a56565b6111a99190613ad2565b6111b39190613abb565b905090565b60004360095414156111cb5750600b5490565b6000306001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa15801561120b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061122f9190613a56565b9050600061123d43836125a1565b606001519392505050565b6000611252612c9d565b8061126c575060035461010090046001600160a01b031633145b6112885760405162461bcd60e51b815260040161096790613a85565b604051632210724360e11b8152738fba84867ba458e7c6e2c024d2de3d0b5c3ea1c26004820152738680ceabcb9b56913c519c069add6bc3494b7020908190634420e486906024016020604051808303816000875af11580156112ef573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113139190613a56565b91505090565b60408051601980825261034082019092526060919060009082602082016103208036833701905050905063a9059cbb60e01b8161135584613b48565b93508360ff168151811061136b5761136b613b65565b6001600160e01b0319909216602092830291909101909101526323b872dd60e01b8161139684613b48565b93508360ff16815181106113ac576113ac613b65565b6001600160e01b031990921660209283029190910190910152636eb1769f60e11b816113d784613b48565b93508360ff16815181106113ed576113ed613b65565b6001600160e01b03199092166020928302919091019091015263095ea7b360e01b8161141884613b48565b93508360ff168151811061142e5761142e613b65565b6001600160e01b0319909216602092830291909101909101526370a0823160e01b8161145984613b48565b93508360ff168151811061146f5761146f613b65565b6001600160e01b0319909216602092830291909101909101526348ee9b6360e11b8161149a84613b48565b93508360ff16815181106114b0576114b0613b65565b6001600160e01b03199092166020928302919091019091015263f2b3abbd60e01b816114db84613b48565b93508360ff16815181106114f1576114f1613b65565b6001600160e01b031990921660209283029190910190910152630d05535360e21b8161151c84613b48565b93508360ff168151811061153257611532613b65565b6001600160e01b031990921660209283029190910190910152635850c83b60e11b8161155d84613b48565b93508360ff168151811061157357611573613b65565b6001600160e01b03199092166020928302919091019091015263fca7820b60e01b8161159e84613b48565b93508360ff16815181106115b4576115b4613b65565b6001600160e01b031990921660209283029190910190910152630ae9d70b60e41b816115df84613b48565b93508360ff16815181106115f5576115f5613b65565b6001600160e01b031990921660209283029190910190910152631f1f3b4560e31b8161162084613b48565b93508360ff168151811061163657611636613b65565b6001600160e01b03199092166020928302919091019091015263bd6d894d60e01b8161166184613b48565b93508360ff168151811061167757611677613b65565b6001600160e01b03199092166020928302919091019091015263a6afed9560e01b816116a284613b48565b93508360ff16815181106116b8576116b8613b65565b6001600160e01b031990921660209283029190910190910152630e759dd360e31b816116e384613b48565b93508360ff16815181106116f9576116f9613b65565b6001600160e01b031990921660209283029190910190910152633af9e66960e01b8161172484613b48565b93508360ff168151811061173a5761173a613b65565b6001600160e01b031990921660209283029190910190910152631592ca1b60e31b8161176584613b48565b93508360ff168151811061177b5761177b613b65565b6001600160e01b03199092166020928302919091019091015263b1e23dbb60e01b816117a684613b48565b93508360ff16815181106117bc576117bc613b65565b6001600160e01b031990921660209283029190910190910152630d76ba9960e21b816117e784613b48565b93508360ff16815181106117fd576117fd613b65565b6001600160e01b03199092166020928302919091019091015263cfcd4c0760e01b8161182884613b48565b93508360ff168151811061183e5761183e613b65565b6001600160e01b0319909216602092830291909101909101526325759ecd60e11b8161186984613b48565b93508360ff168151811061187f5761187f613b65565b6001600160e01b031990921660209283029190910190910152633c3b4b8960e01b816118aa84613b48565b93508360ff16815181106118c0576118c0613b65565b6001600160e01b0319909216602092830291909101909101526361bfb47160e11b816118eb84613b48565b93508360ff168151811061190157611901613b65565b6001600160e01b0319909216602092830291909101909101526305eff7ef60e21b8161192c84613b48565b93508360ff168151811061194257611942613b65565b6001600160e01b031990921660209283029190910190910152633f8af10b60e11b8161196d84613b48565b93508360ff168151811061198357611983613b65565b6001600160e01b03199092166020928302919091019091015260ff8216156119ed5760405162461bcd60e51b815260206004820152601c60248201527f7573652074686520636f7272656374206172726179206c656e677468000000006044820152606401610967565b92915050565b6000806119ff816128a3565b611a07611bbd565b504360095414611a2457611a1d600a6052612e66565b9150611ba1565b600019831415611a345760065492505b60008060009054906101000a90046001600160a01b03166001600160a01b031663dd86fea16040518163ffffffff1660e01b8152600401602060405180830381865afa158015611a88573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611aac9190613a56565b9050670de0b6b3a76400008185600854611ac69190613ad2565b611ad09190613ad2565b1115611aea57611ae260026053612e66565b925050611ba1565b8360065414611b4e57611afb612c9d565b611b0b57611ae260016051612e66565b600680549085905560408051828152602081018790527fcdd0b588250e1398549f79cfdb8217c186688822905d6715b0834ea1c865594a910160405180910390a1505b8060075414611b9a57600780549082905560408051828152602081018490527fedec4b9c99c2cdb231e7fd036f861e0445b015916700f41b9835f984cb9be4cb910160405180910390a1505b60005b9250505b611baa81612c1e565b50919050565b6002805461083c906139a4565b6009546000904390811415611bd3576000611313565b6000306001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa158015611c13573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c379190613a56565b90506000611c4583836125a1565b6009849055602081810151600a819055606080840151600b819055608080860151600c5560a0860151600e5560c0860151600d5560e0860151604080518a815296870191909152850193909352908301529192507f4dec04e750ca11537cabcd8a9eab06494de08da3735bc8871cd41250e190bc04910160405180910390a16000935050505090565b600080611cda816128a3565b60008054600354604051631beb2b9760e31b81526001600160a01b039283169363df595cb893611d2493610100900416913391309190356001600160e01b031916906004016139d9565b602060405180830381865afa158015611d41573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d659190613a0c565b611d815760405162461bcd60e51b815260040161096790613a2e565b6000611d8f33338787612967565b149150611d9b81612c1e565b5092915050565b6060610e188383612edf565b6004546000906001600160a01b031663b8168816306001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa158015611e00573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e249190613a56565b600b54600e54600d54600c54611e3a9190613ad2565b611e449190613ad2565b600654600754600854611e579190613ad2565b611e619190613ad2565b6040516001600160e01b031960e087901b16815260048101949094526024840192909252604483015260648201526084015b602060405180830381865afa158015611eb0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111b39190613a56565b611edc612c9d565b611ef85760405162461bcd60e51b815260040161096790613a85565b601480546001600160a01b0319166001600160a01b0392909216919091179055565b6004546000906001600160a01b031663b816881683306001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f6d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f919190613a56565b611f9b9190613ad2565b600b54600e54600d54600c54611fb19190613ad2565b611fbb9190613ad2565b600654600754600854611fce9190613ad2565b611fd89190613ad2565b6040516001600160e01b031960e087901b1681526004810194909452602484019290925260448301526064820152608401602060405180830381865afa158015612026573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119ed9190613a56565b60006009544314156120d8576111b3600f546005546120663090565b6001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa1580156120a3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120c79190613a56565b600b54600c54600d54600e54613030565b6000306001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa158015612118573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061213c9190613a56565b9050600061214a43836125a1565b9050612171816040015160055484846060015185608001518660c001518760a00151613030565b9250505090565b6001600160a01b03811660009081526010602052604081205481908190819081806121a2886109d4565b91506121ac61204a565b90506000989297509095509350915050565b600080306001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa1580156121ff573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122239190613a56565b90508281101561226e5760405162461bcd60e51b81526020600482015260166024820152750dac2e4d6cae840c6c2e6d040dcdee840cadcdeeaced60531b6044820152606401610967565b6004546001600160a01b03166315f240536122898584613abb565b85600b546122979190613ad2565b600e54600d54600c546122aa9190613ad2565b6122b49190613ad2565b6040516001600160e01b031960e086901b168152600481019390935260248301919091526044820152606401610dd7565b6000806122f1816128a3565b6122f9611bbd565b50612302612c9d565b61231257611a1d6001604d612e66565b436009541461232757611a1d600a604c612e66565b826001600160a01b0316632191f92a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612365573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123899190613a0c565b6123bf5760405162461bcd60e51b8152602060048201526007602482015266216e6f7449726d60c81b6044820152606401610967565b600480546001600160a01b038581166001600160a01b031983168117909355604080519190921680825260208201939093527fedffc32e068c7c95dfd4bdfd5c4d939a084d6b11c4199eac8436ed234d72f92691015b60405180910390a16000611b9d565b6004546000906001600160a01b03166315f24053306001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa158015612476573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061249a9190613a56565b600b54600e54600d54600c546124b09190613ad2565b6124ba9190613ad2565b6040516001600160e01b031960e086901b168152600481019390935260248301919091526044820152606401611e93565b6000806124f7816128a3565b6124ff611bbd565b50612508612c9d565b61251857611a1d60016058612e66565b436009541461252d57611a1d600a6059612e66565b670de0b6b3a7640000600754600654856125479190613ad2565b6125519190613ad2565b111561256357611a1d6002605a612e66565b600880549084905560408051828152602081018690527faaa68312e2ea9d50e16af5068410ab56e1a1fd06037b1a35664812c30f8214609101612415565b6125e960405180610100016040528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b6000600e54600d546125fb9190613ad2565b600454600b54600c549293506000926001600160a01b03909216916315f24053918791612629908790613ad2565b6040516001600160e01b031960e086901b168152600481019390935260248301919091526044820152606401602060405180830381865afa158015612672573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126969190613a56565b905065048c273950008111156126ed57818411156126e45760405162461bcd60e51b815260206004820152600b60248201526a21626f72726f775261746560a81b6044820152606401610967565b5065048c273950005b6000806126fc8760095461316f565b9092509050600082600381111561271557612715613a6f565b146127505760405162461bcd60e51b815260206004820152600b60248201526a21626c6f636b44656c746160a81b6044820152606401610967565b868552600f54604080870191909152805160208101909152838152600090612778908361319a565b905061278681600b546131cb565b60e08701819052600b5461279991613ad2565b60608701526040805160208101909152600854815260e0870151600c546127c19291906131e3565b60808701526040805160208101909152600754815260e0870151600e546127e99291906131e3565b60a08701526040805160208101909152600654815260e0870151600d546128119291906131e3565b60c0870152600a54612825908290806131e3565b602087015250939695505050505050565b6000808361284957506000905080612871565b838302836128578683613b7b565b1461286a57600260009250925050612871565b6000925090505b9250929050565b6000808261288c5750600190506000612871565b60006128988486613b7b565b915091509250929050565b600054600160a01b900460ff166128e95760405162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b6044820152606401610967565b8061295757600360019054906101000a90046001600160a01b03166001600160a01b031663c90c20b16040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561293e57600080fd5b505af1158015612952573d6000803e3d6000fd5b505050505b506000805460ff60a01b19169055565b6003546040516317b9b84b60e31b81523060048201526001600160a01b03858116602483015284811660448301526064820184905260009283926101009091049091169063bdcdc258906084016020604051808303816000875af11580156129d3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129f79190613a56565b90508015612a1457612a0c6003605b8361320d565b915050610eb2565b836001600160a01b0316856001600160a01b03161415612a3a57612a0c6002605c612e66565b6000856001600160a01b0316876001600160a01b03161415612a5f5750600019612a87565b506001600160a01b038086166000908152601160209081526040808320938a16835292905220545b600080600080612a97858961316f565b90945092506000846003811115612ab057612ab0613a6f565b14612ace57612ac16009605c612e66565b9650505050505050610eb2565b6001600160a01b038a16600090815260106020526040902054612af1908961316f565b90945091506000846003811115612b0a57612b0a613a6f565b14612b1b57612ac16009605d612e66565b6001600160a01b038916600090815260106020526040902054612b3e90896132af565b90945090506000846003811115612b5757612b57613a6f565b14612b6857612ac16009605e612e66565b6001600160a01b03808b16600090815260106020526040808220859055918b168152208190556000198514612bc0576001600160a01b03808b166000908152601160209081526040808320938f168352929052208390555b886001600160a01b03168a6001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8a604051612c0591815260200190565b60405180910390a35060009a9950505050505050505050565b6000805460ff60a01b1916600160a01b17905580612c9a57600360019054906101000a90046001600160a01b03166001600160a01b031663632e51426040518163ffffffff1660e01b8152600401600060405180830381600087803b158015612c8657600080fd5b505af1158015610c96573d6000803e3d6000fd5b50565b600080600360019054906101000a90046001600160a01b03169050806001600160a01b031663f851a4406040518163ffffffff1660e01b8152600401602060405180830381865afa158015612cf6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d1a9190613b9d565b6001600160a01b0316336001600160a01b0316148015612d975750806001600160a01b0316630a755ec26040518163ffffffff1660e01b8152600401602060405180830381865afa158015612d73573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d979190613a0c565b8061131357506000546001600160a01b0316331480156113135750806001600160a01b031663cf6bfd2d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612df0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113139190613a0c565b600080600080612e2486866132d5565b90925090506000826003811115612e3d57612e3d613a6f565b14612e4e5750915060009050612871565b6000612e5982613351565b9350935050509250929050565b60007f45b96fe442630264581b197e84bbada861235052c5a1aadfff9ea4e40a969aa0836011811115612e9b57612e9b613a6f565b836061811115612ead57612ead613a6f565b60408051928352602083019190915260009082015260600160405180910390a1826011811115610e1857610e18613a6f565b60608167ffffffffffffffff811115612efa57612efa613b32565b604051908082528060200260200182016040528015612f2d57816020015b6060815260200190600190039081612f185790505b50905060005b82811015611d9b5760008030868685818110612f5157612f51613b65565b9050602002810190612f639190613bba565b604051612f71929190613c01565b600060405180830381855af49150503d8060008114612fac576040519150601f19603f3d011682016040523d82523d6000602084013e612fb1565b606091505b509150915081612ffd57604481511015612fca57600080fd5b60048101905080806020019051810190612fe49190613c11565b60405162461bcd60e51b81526004016109679190613681565b8084848151811061301057613010613b65565b60200260200101819052505050808061302890613cb3565b915050612f33565b60008761303e575085613164565b60006130566040518060200160405280600081525090565b60006130778989876130688a8c613ad2565b6130729190613ad2565b613369565b93509050600081600381111561308f5761308f613a6f565b146130ea5760405162461bcd60e51b815260206004820152602560248201527f216164645468656e53756255496e74206f766572666c6f7720636865636b2066604482015264185a5b195960da1b6064820152608401610967565b6130f4838c6133bc565b92509050600081600381111561310c5761310c613a6f565b146131595760405162461bcd60e51b815260206004820152601d60248201527f21676574457870206f766572666c6f7720636865636b206661696c65640000006044820152606401610967565b505191506131649050565b979650505050505050565b60008083831161318e5760006131858486613abb565b91509150612871565b50600390506000612871565b60408051602081019091526000815260405180602001604052806131c2856000015185613487565b90529392505050565b6000806131d8848461319a565b9050610eb281613351565b6000806131f0858561319a565b90506132046131fe82613351565b846134c9565b95945050505050565b60007f45b96fe442630264581b197e84bbada861235052c5a1aadfff9ea4e40a969aa084601181111561324257613242613a6f565b84606181111561325457613254613a6f565b604080519283526020830191909152810184905260600160405180910390a1600384601181111561328757613287613a6f565b146132a35783601181111561329e5761329e613a6f565b610eb2565b610eb2826103e8613ad2565b6000808383018481106132c757600092509050612871565b600260009250925050612871565b60006132ed6040518060200160405280600081525090565b6000806132fe866000015186612836565b9092509050600082600381111561331757613317613a6f565b1461333657506040805160208101909152600081529092509050612871565b60408051602081019091529081526000969095509350505050565b80516000906119ed90670de0b6b3a764000090613b7b565b60008060008061337987876132af565b9092509050600082600381111561339257613392613a6f565b146133a357509150600090506133b4565b6133ad818661316f565b9350935050505b935093915050565b60006133d46040518060200160405280600081525090565b6000806133e986670de0b6b3a7640000612836565b9092509050600082600381111561340257613402613a6f565b1461342157506040805160208101909152600081529092509050612871565b60008061342e8388612878565b9092509050600082600381111561344757613447613a6f565b1461346a5781604051806020016040528060008152509550955050505050612871565b604080516020810190915290815260009890975095505050505050565b6000610e1883836040518060400160405280601781526020017f6d756c7469706c69636174696f6e206f766572666c6f770000000000000000008152506134ff565b6000610e188383604051806040016040528060118152602001706164646974696f6e206f766572666c6f7760781b81525061355b565b600083158061350c575082155b1561351957506000610e18565b60006135258486613cce565b9050836135328683613b7b565b1483906135525760405162461bcd60e51b81526004016109679190613681565b50949350505050565b6000806135688486613ad2565b905082858210156135525760405162461bcd60e51b81526004016109679190613681565b828054613598906139a4565b90600052602060002090601f0160209004810192826135ba5760008555613600565b82601f106135d35782800160ff19823516178555613600565b82800160010185558215613600579182015b828111156136005782358255916020019190600101906135e5565b5061360c929150613610565b5090565b5b8082111561360c5760008155600101613611565b60005b83811015613640578181015183820152602001613628565b8381111561364f576000848401525b50505050565b6000815180845261366d816020860160208601613625565b601f01601f19169290920160200192915050565b602081526000610e186020830184613655565b6001600160a01b0381168114612c9a57600080fd5b600080604083850312156136bc57600080fd5b82356136c781613694565b946020939093013593505050565b6000602082840312156136e757600080fd5b8135610e1881613694565b60008060006060848603121561370757600080fd5b833561371281613694565b9250602084013561372281613694565b929592945050506040919091013590565b60008083601f84011261374557600080fd5b50813567ffffffffffffffff81111561375d57600080fd5b60208301915083602082850101111561287157600080fd5b6000806000806040858703121561378b57600080fd5b843567ffffffffffffffff808211156137a357600080fd5b6137af88838901613733565b909650945060208701359150808211156137c857600080fd5b506137d587828801613733565b95989497509550505050565b6000602082840312156137f357600080fd5b5035919050565b60008060006040848603121561380f57600080fd5b83359250602084013567ffffffffffffffff81111561382d57600080fd5b61383986828701613733565b9497909650939450505050565b6020808252825182820181905260009190848201906040850190845b818110156138885783516001600160e01b03191683529284019291840191600101613862565b50909695505050505050565b600080602083850312156138a757600080fd5b823567ffffffffffffffff808211156138bf57600080fd5b818501915085601f8301126138d357600080fd5b8135818111156138e257600080fd5b8660208260051b85010111156138f757600080fd5b60209290920196919550909350505050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b8281101561395e57603f1988860301845261394c858351613655565b94509285019290850190600101613930565b5092979650505050505050565b6000806040838503121561397e57600080fd5b823561398981613694565b9150602083013561399981613694565b809150509250929050565b600181811c908216806139b857607f821691505b60208210811415611baa57634e487b7160e01b600052602260045260246000fd5b6001600160a01b0394851681529284166020840152921660408201526001600160e01b0319909116606082015260800190565b600060208284031215613a1e57600080fd5b81518015158114610e1857600080fd5b6020808252600e908201526d1b9bdd08185d5d1a1bdc9a5e995960921b604082015260600190565b600060208284031215613a6857600080fd5b5051919050565b634e487b7160e01b600052602160045260246000fd5b60208082526006908201526510b0b236b4b760d11b604082015260600190565b634e487b7160e01b600052601160045260246000fd5b600082821015613acd57613acd613aa5565b500390565b60008219821115613ae557613ae5613aa5565b500190565b6001600160a01b0385168152602081018490526060604082018190528101829052818360808301376000818301608090810191909152601f909201601f191601019392505050565b634e487b7160e01b600052604160045260246000fd5b600060ff821680613b5b57613b5b613aa5565b6000190192915050565b634e487b7160e01b600052603260045260246000fd5b600082613b9857634e487b7160e01b600052601260045260246000fd5b500490565b600060208284031215613baf57600080fd5b8151610e1881613694565b6000808335601e19843603018112613bd157600080fd5b83018035915067ffffffffffffffff821115613bec57600080fd5b60200191503681900382131561287157600080fd5b8183823760009101908152919050565b600060208284031215613c2357600080fd5b815167ffffffffffffffff80821115613c3b57600080fd5b818401915084601f830112613c4f57600080fd5b815181811115613c6157613c61613b32565b604051601f8201601f19908116603f01168101908382118183101715613c8957613c89613b32565b81604052828152876020848701011115613ca257600080fd5b613164836020830160208801613625565b6000600019821415613cc757613cc7613aa5565b5060010190565b6000816000190483118215151615613ce857613ce8613aa5565b50029056fea2646970667358221220baf8e95b13105502451f59762ba110f707d784ebf5504db0cf9ad97cbb65962164736f6c634300080a0033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in FRAX
0
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
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.