Address Contract Verified
Address
0x0568F6cb5A0E84FACa107D02f81ddEB1803f3B50
Balance
0 ETH
Nonce
1
Code Size
7362 bytes
Creator
0x6A138bd6...D04C at tx 0x7229ff3c...d0776f
Indexed Transactions
0
Contract Bytecode
7362 bytes
0x6080604052600436106103355760003560e01c806373acee98116101ab578063bd6d894d116100f7578063f3fdb15a11610095578063f8f9da281161006f578063f8f9da2814610a44578063fca7820b14610a59578063fe881bda14610a79578063fe9c44ae14610a9957610335565b8063f3fdb15a146109df578063f5e3c462146109ff578063f851a44014610a1f57610335565b8063db006a75116100d1578063db006a751461096a578063dd62ed3e1461098a578063e9c714f2146109aa578063f2b3abbd146109bf57610335565b8063bd6d894d146108f5578063c37f68e21461090a578063c5ebeaec1461094a57610335565b8063a0712d6811610164578063aa5af0fd1161013e578063aa5af0fd1461088a578063ae9d70b0146108a0578063b2a02ff1146108b5578063b71d1a0c146108d557610335565b8063a0712d6814610835578063a6afed9514610855578063a9059cbb1461086a57610335565b806373acee9814610795578063852a12e3146107aa5780638f840ddd146107ca57806393e59dc1146107e057806395d89b411461080057806395dd91931461081557610335565b80633af9e669116102855780635c60da1b116102235780636752e702116101fd5780636752e702146107245780636c540baf1461073f5780636f307dc31461075557806370a082311461077557610335565b80635c60da1b146106c45780635fe3b567146106e4578063601a0bf11461070457610335565b80634487152f1161025f5780634487152f1461064e5780634576b5db1461066e57806347bd37181461068e578063555bcc40146106a457610335565b80633af9e669146105f95780633b1d21a2146106195780633e9410101461062e57610335565b806318160ddd116102f257806323b872dd116102cc57806323b872dd146105555780632608f818146105755780632678224714610595578063313ce567146105cd57610335565b806318160ddd14610508578063182df0f51461051e5780631be195601461053357610335565b806306fdde03146104295780630933c1ed14610454578063095ea7b3146104745780630e752702146104a4578063173b9904146104d257806317bfdfbc146104e8575b34156103ae5760405162461bcd60e51b815260206004820152603760248201527f43457263323044656c656761746f723a66616c6c6261636b3a2063616e6e6f7460448201527f2073656e642076616c756520746f2066616c6c6261636b00000000000000000060648201526084015b60405180910390fd5b6013546040516000916001600160a01b0316906103ce908390369061183c565b600060405180830381855af49150503d8060008114610409576040519150601f19603f3d011682016040523d82523d6000602084013e61040e565b606091505b505090506040513d6000823e818015610425573d82f35b3d82fd5b34801561043557600080fd5b5061043e610aae565b60405161044b91906118a8565b60405180910390f35b34801561046057600080fd5b5061043e61046f366004611980565b610b3c565b34801561048057600080fd5b5061049461048f3660046119cd565b610b5b565b604051901515815260200161044b565b3480156104b057600080fd5b506104c46104bf3660046119f9565b610bcd565b60405190815260200161044b565b3480156104de57600080fd5b506104c460085481565b3480156104f457600080fd5b506104c4610503366004611a12565b610c32565b34801561051457600080fd5b506104c4600d5481565b34801561052a57600080fd5b506104c4610c7f565b34801561053f57600080fd5b5061055361054e366004611a12565b610cd2565b005b34801561056157600080fd5b50610494610570366004611a2f565b610d1d565b34801561058157600080fd5b506104c46105903660046119cd565b610d98565b3480156105a157600080fd5b506004546105b5906001600160a01b031681565b6040516001600160a01b03909116815260200161044b565b3480156105d957600080fd5b506003546105e79060ff1681565b60405160ff909116815260200161044b565b34801561060557600080fd5b506104c4610614366004611a12565b610e02565b34801561062557600080fd5b506104c4610e4f565b34801561063a57600080fd5b506104c46106493660046119f9565b610e86565b34801561065a57600080fd5b5061043e610669366004611980565b610ece565b34801561067a57600080fd5b506104c4610689366004611a12565b610f8c565b34801561069a57600080fd5b506104c4600b5481565b3480156106b057600080fd5b506105536106bf366004611a7e565b610fd9565b3480156106d057600080fd5b506013546105b5906001600160a01b031681565b3480156106f057600080fd5b506005546105b5906001600160a01b031681565b34801561071057600080fd5b506104c461071f3660046119f9565b61114b565b34801561073057600080fd5b506104c4666379da05b6000081565b34801561074b57600080fd5b506104c460095481565b34801561076157600080fd5b506012546105b5906001600160a01b031681565b34801561078157600080fd5b506104c4610790366004611a12565b611193565b3480156107a157600080fd5b506104c46111e0565b3480156107b657600080fd5b506104c46107c53660046119f9565b611217565b3480156107d657600080fd5b506104c4600c5481565b3480156107ec57600080fd5b506011546105b5906001600160a01b031681565b34801561080c57600080fd5b5061043e61125f565b34801561082157600080fd5b506104c4610830366004611a12565b61126c565b34801561084157600080fd5b506104c46108503660046119f9565b6112b9565b34801561086157600080fd5b506104c4611301565b34801561087657600080fd5b506104946108853660046119cd565b611338565b34801561089657600080fd5b506104c4600a5481565b3480156108ac57600080fd5b506104c461138c565b3480156108c157600080fd5b506104c46108d0366004611a2f565b6113c3565b3480156108e157600080fd5b506104c46108f0366004611a12565b611435565b34801561090157600080fd5b506104c4611482565b34801561091657600080fd5b5061092a610925366004611a12565b6114b9565b60408051948552602085019390935291830152606082015260800161044b565b34801561095657600080fd5b506104c46109653660046119f9565b611539565b34801561097657600080fd5b506104c46109853660046119f9565b611581565b34801561099657600080fd5b506104c46109a5366004611ae0565b6115c9565b3480156109b657600080fd5b506104c461161e565b3480156109cb57600080fd5b506104c46109da366004611a12565b611655565b3480156109eb57600080fd5b506006546105b5906001600160a01b031681565b348015610a0b57600080fd5b506104c4610a1a366004611b19565b6116a2565b348015610a2b57600080fd5b506003546105b59061010090046001600160a01b031681565b348015610a5057600080fd5b506104c46116fe565b348015610a6557600080fd5b506104c4610a743660046119f9565b611735565b348015610a8557600080fd5b506104c4610a94366004611a12565b61177d565b348015610aa557600080fd5b50610494600181565b60018054610abb90611b5b565b80601f0160208091040260200160405190810160405280929190818152602001828054610ae790611b5b565b8015610b345780601f10610b0957610100808354040283529160200191610b34565b820191906000526020600020905b815481529060010190602001808311610b1757829003601f168201915b505050505081565b601354606090610b55906001600160a01b0316836117ca565b92915050565b6040516001600160a01b0383166024820152604481018290526000908190610baf9060640160408051601f198184030181529190526020810180516001600160e01b031663095ea7b360e01b179052610b3c565b905080806020019051810190610bc59190611b96565b949350505050565b600080610c1583604051602401610be691815260200190565b60408051601f198184030181529190526020810180516001600160e01b031663073a938160e11b179052610b3c565b905080806020019051810190610c2b9190611bb3565b9392505050565b6040516001600160a01b03821660248201526000908190610c159060440160408051601f198184030181529190526020810180516001600160e01b03166305eff7ef60e21b179052610b3c565b6040805160048152602481019091526020810180516001600160e01b031663182df0f560e01b1790526000908190610cb690610ece565b905080806020019051810190610ccc9190611bb3565b91505090565b6040516001600160a01b0382166024820152610d199060440160408051601f198184030181529190526020810180516001600160e01b031662df0cab60e51b179052610b3c565b5050565b6040516001600160a01b03808516602483015283166044820152606481018290526000908190610d799060840160408051601f198184030181529190526020810180516001600160e01b03166323b872dd60e01b179052610b3c565b905080806020019051810190610d8f9190611b96565b95945050505050565b6040516001600160a01b0383166024820152604481018290526000908190610dec9060640160408051601f198184030181529190526020810180516001600160e01b03166304c11f0360e31b179052610b3c565b905080806020019051810190610bc59190611bb3565b6040516001600160a01b03821660248201526000908190610c159060440160408051601f198184030181529190526020810180516001600160e01b0316633af9e66960e01b179052610b3c565b6040805160048152602481019091526020810180516001600160e01b0316631d8e90d160e11b1790526000908190610cb690610ece565b600080610c1583604051602401610e9f91815260200190565b60408051601f198184030181529190526020810180516001600160e01b03166303e9410160e41b179052610b3c565b6060600080306001600160a01b031684604051602401610eee91906118a8565b60408051601f198184030181529181526020820180516001600160e01b0316630933c1ed60e01b17905251610f239190611bcc565b600060405180830381855afa9150503d8060008114610f5e576040519150601f19603f3d011682016040523d82523d6000602084013e610f63565b606091505b50915091506000821415610f78573d60208201fd5b80806020019051810190610bc59190611be8565b6040516001600160a01b03821660248201526000908190610c159060440160408051601f198184030181529190526020810180516001600160e01b0316634576b5db60e01b179052610b3c565b60035461010090046001600160a01b0316331461105e5760405162461bcd60e51b815260206004820152603960248201527f43457263323044656c656761746f723a3a5f736574496d706c656d656e74617460448201527f696f6e3a2043616c6c6572206d7573742062652061646d696e0000000000000060648201526084016103a5565b8115611098576040805160048152602481019091526020810180516001600160e01b031663153ab50560e01b17905261109690610b3c565b505b601380546001600160a01b038581166001600160a01b03198316179092556040519116906110fd906110ce9084906024016118a8565b60408051601f198184030181529190526020810180516001600160e01b0316630adccee560e31b179052610b3c565b50601354604080516001600160a01b03808516825290921660208301527fd604de94d45953f9138079ec1b82d533cb2160c906d1076d1f7ed54befbca97a910160405180910390a150505050565b600080610c158360405160240161116491815260200190565b60408051601f198184030181529190526020810180516001600160e01b031663601a0bf160e01b179052610b3c565b6040516001600160a01b03821660248201526000908190610c159060440160408051601f198184030181529190526020810180516001600160e01b03166370a0823160e01b179052610ece565b6040805160048152602481019091526020810180516001600160e01b0316630e759dd360e31b1790526000908190610cb690610b3c565b600080610c158360405160240161123091815260200190565b60408051601f198184030181529190526020810180516001600160e01b031663852a12e360e01b179052610b3c565b60028054610abb90611b5b565b6040516001600160a01b03821660248201526000908190610c159060440160408051601f198184030181529190526020810180516001600160e01b03166395dd919360e01b179052610ece565b600080610c15836040516024016112d291815260200190565b60408051601f198184030181529190526020810180516001600160e01b031663140e25ad60e31b179052610b3c565b6040805160048152602481019091526020810180516001600160e01b031663a6afed9560e01b1790526000908190610cb690610b3c565b6040516001600160a01b0383166024820152604481018290526000908190610baf9060640160408051601f198184030181529190526020810180516001600160e01b031663a9059cbb60e01b179052610b3c565b6040805160048152602481019091526020810180516001600160e01b0316630ae9d70b60e41b1790526000908190610cb690610ece565b6040516001600160a01b0380851660248301528316604482015260648101829052600090819061141f9060840160408051601f198184030181529190526020810180516001600160e01b031663b2a02ff160e01b179052610b3c565b905080806020019051810190610d8f9190611bb3565b6040516001600160a01b03821660248201526000908190610c159060440160408051601f198184030181529190526020810180516001600160e01b0316632dc7468360e21b179052610b3c565b6040805160048152602481019091526020810180516001600160e01b031663bd6d894d60e01b1790526000908190610cb690610b3c565b6000806000806000611513866040516024016114e491906001600160a01b0391909116815260200190565b60408051601f198184030181529190526020810180516001600160e01b03166361bfb47160e11b179052610ece565b9050808060200190518101906115299190611c56565b9450945094509450509193509193565b600080610c158360405160240161155291815260200190565b60408051601f198184030181529190526020810180516001600160e01b031663317afabb60e21b179052610b3c565b600080610c158360405160240161159a91815260200190565b60408051601f198184030181529190526020810180516001600160e01b031663db006a7560e01b179052610b3c565b6040516001600160a01b038084166024830152821660448201526000908190610dec9060640160408051601f198184030181529190526020810180516001600160e01b0316636eb1769f60e11b179052610ece565b6040805160048152602481019091526020810180516001600160e01b03166374e38a7960e11b1790526000908190610cb690610b3c565b6040516001600160a01b03821660248201526000908190610c159060440160408051601f198184030181529190526020810180516001600160e01b031663f2b3abbd60e01b179052610b3c565b6040516001600160a01b0380851660248301526044820184905282166064820152600090819061141f9060840160408051601f198184030181529190526020810180516001600160e01b0316637af1e23160e11b179052610b3c565b6040805160048152602481019091526020810180516001600160e01b0316631f1f3b4560e31b1790526000908190610cb690610ece565b600080610c158360405160240161174e91815260200190565b60408051601f198184030181529190526020810180516001600160e01b031663fca7820b60e01b179052610b3c565b6040516001600160a01b03821660248201526000908190610c159060440160408051601f198184030181529190526020810180516001600160e01b0316637f440ded60e11b179052610b3c565b6060600080846001600160a01b0316846040516117e79190611bcc565b600060405180830381855af49150503d8060008114611822576040519150601f19603f3d011682016040523d82523d6000602084013e611827565b606091505b50915091506000821415610bc5573d60208201fd5b8183823760009101908152919050565b60005b8381101561186757818101518382015260200161184f565b83811115611876576000848401525b50505050565b6000815180845261189481602086016020860161184c565b601f01601f19169290920160200192915050565b602081526000610c2b602083018461187c565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156118fa576118fa6118bb565b604052919050565b600067ffffffffffffffff82111561191c5761191c6118bb565b50601f01601f191660200190565b600082601f83011261193b57600080fd5b813561194e61194982611902565b6118d1565b81815284602083860101111561196357600080fd5b816020850160208301376000918101602001919091529392505050565b60006020828403121561199257600080fd5b813567ffffffffffffffff8111156119a957600080fd5b610bc58482850161192a565b6001600160a01b03811681146119ca57600080fd5b50565b600080604083850312156119e057600080fd5b82356119eb816119b5565b946020939093013593505050565b600060208284031215611a0b57600080fd5b5035919050565b600060208284031215611a2457600080fd5b8135610c2b816119b5565b600080600060608486031215611a4457600080fd5b8335611a4f816119b5565b92506020840135611a5f816119b5565b929592945050506040919091013590565b80151581146119ca57600080fd5b600080600060608486031215611a9357600080fd5b8335611a9e816119b5565b92506020840135611aae81611a70565b9150604084013567ffffffffffffffff811115611aca57600080fd5b611ad68682870161192a565b9150509250925092565b60008060408385031215611af357600080fd5b8235611afe816119b5565b91506020830135611b0e816119b5565b809150509250929050565b600080600060608486031215611b2e57600080fd5b8335611b39816119b5565b9250602084013591506040840135611b50816119b5565b809150509250925092565b600181811c90821680611b6f57607f821691505b60208210811415611b9057634e487b7160e01b600052602260045260246000fd5b50919050565b600060208284031215611ba857600080fd5b8151610c2b81611a70565b600060208284031215611bc557600080fd5b5051919050565b60008251611bde81846020870161184c565b9190910192915050565b600060208284031215611bfa57600080fd5b815167ffffffffffffffff811115611c1157600080fd5b8201601f81018413611c2257600080fd5b8051611c3061194982611902565b818152856020838501011115611c4557600080fd5b610d8f82602083016020860161184c565b60008060008060808587031215611c6c57600080fd5b50508251602084015160408501516060909501519196909550909250905056fea26469706673582212207d8557ed32e2afa80157eb722e83784a244cc72ae0e2dd3bb363453f3178d73164736f6c634300080a0033
Verified Source Code Full Match
Compiler: v0.8.10+commit.fc410830
EVM: london
Optimization: Yes (200 runs)
WhitelistAccess.sol 23 lines
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.10;
/**
* @title Capyfi Whitelist Interface
*/
abstract contract WhitelistAccess {
/// @notice Indicator that this is a WhitelistAccess contract (for inspection)
bool public constant isWhitelistAccess = true;
/**
* @notice function to check if an account is whitelisted
* @param account The address to check
* @return Boolean indicating if the address is whitelisted
*/
function isWhitelisted(address account) external view virtual returns (bool);
/**
* @notice function to check if the whitelist is active
* @return Boolean indicating if the whitelist is active and should be enforced
*/
function isActive() external view virtual returns (bool);
}
CErc20Delegator.sol 488 lines
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.10;
import "./CTokenInterfaces.sol";
/**
* @title Compound's CErc20Delegator Contract
* @notice CTokens which wrap an EIP-20 underlying and delegate to an implementation
* @author Compound
*/
contract CErc20Delegator is CTokenInterface, CErc20Interface, CDelegatorInterface {
/**
* @notice Construct a new money market
* @param underlying_ The address of the underlying asset
* @param comptroller_ The address of the Comptroller
* @param interestRateModel_ The address of the interest rate model
* @param initialExchangeRateMantissa_ The initial exchange rate, scaled by 1e18
* @param name_ ERC-20 name of this token
* @param symbol_ ERC-20 symbol of this token
* @param decimals_ ERC-20 decimal precision of this token
* @param admin_ Address of the administrator of this token
* @param implementation_ The address of the implementation the contract delegates to
* @param becomeImplementationData The encoded args for becomeImplementation
*/
constructor(address underlying_,
ComptrollerInterface comptroller_,
InterestRateModel interestRateModel_,
uint initialExchangeRateMantissa_,
string memory name_,
string memory symbol_,
uint8 decimals_,
address payable admin_,
address implementation_,
bytes memory becomeImplementationData) {
// Creator of the contract is admin during initialization
admin = payable(msg.sender);
// First delegate gets to initialize the delegator (i.e. storage contract)
delegateTo(implementation_, abi.encodeWithSignature("initialize(address,address,address,uint256,string,string,uint8)",
underlying_,
comptroller_,
interestRateModel_,
initialExchangeRateMantissa_,
name_,
symbol_,
decimals_));
// New implementations always get set via the settor (post-initialize)
_setImplementation(implementation_, false, becomeImplementationData);
// Set the proper admin now that initialization is done
admin = admin_;
}
/**
* @notice Called by the admin to update the implementation of the delegator
* @param implementation_ The address of the new implementation for delegation
* @param allowResign Flag to indicate whether to call _resignImplementation on the old implementation
* @param becomeImplementationData The encoded bytes data to be passed to _becomeImplementation
*/
function _setImplementation(address implementation_, bool allowResign, bytes memory becomeImplementationData)override public {
require(msg.sender == admin, "CErc20Delegator::_setImplementation: Caller must be admin");
if (allowResign) {
delegateToImplementation(abi.encodeWithSignature("_resignImplementation()"));
}
address oldImplementation = implementation;
implementation = implementation_;
delegateToImplementation(abi.encodeWithSignature("_becomeImplementation(bytes)", becomeImplementationData));
emit NewImplementation(oldImplementation, implementation);
}
/**
* @notice Sender supplies assets into the market and receives cTokens in exchange
* @dev Accrues interest whether or not the operation succeeds, unless reverted
* @param mintAmount The amount of the underlying asset to supply
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
*/
function mint(uint mintAmount) override external returns (uint) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("mint(uint256)", mintAmount));
return abi.decode(data, (uint));
}
/**
* @notice Sender redeems cTokens in exchange for the underlying asset
* @dev Accrues interest whether or not the operation succeeds, unless reverted
* @param redeemTokens The number of cTokens to redeem into underlying
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
*/
function redeem(uint redeemTokens) override external returns (uint) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("redeem(uint256)", redeemTokens));
return abi.decode(data, (uint));
}
/**
* @notice Sender redeems cTokens in exchange for a specified amount of underlying asset
* @dev Accrues interest whether or not the operation succeeds, unless reverted
* @param redeemAmount The amount of underlying to redeem
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
*/
function redeemUnderlying(uint redeemAmount) override external returns (uint) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("redeemUnderlying(uint256)", redeemAmount));
return abi.decode(data, (uint));
}
/**
* @notice Sender borrows assets from the protocol to their own address
* @param borrowAmount The amount of the underlying asset to borrow
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
*/
function borrow(uint borrowAmount) override external returns (uint) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("borrow(uint256)", borrowAmount));
return abi.decode(data, (uint));
}
/**
* @notice Sender repays their own borrow
* @param repayAmount The amount to repay, or -1 for the full outstanding amount
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
*/
function repayBorrow(uint repayAmount) override external returns (uint) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("repayBorrow(uint256)", repayAmount));
return abi.decode(data, (uint));
}
/**
* @notice Sender repays a borrow belonging to borrower
* @param borrower the account with the debt being payed off
* @param repayAmount The amount to repay, or -1 for the full outstanding amount
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
*/
function repayBorrowBehalf(address borrower, uint repayAmount) override external returns (uint) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("repayBorrowBehalf(address,uint256)", borrower, repayAmount));
return abi.decode(data, (uint));
}
/**
* @notice The sender liquidates the borrowers collateral.
* The collateral seized is transferred to the liquidator.
* @param borrower The borrower of this cToken to be liquidated
* @param cTokenCollateral The market in which to seize collateral from the borrower
* @param repayAmount The amount of the underlying borrowed asset to repay
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
*/
function liquidateBorrow(address borrower, uint repayAmount, CTokenInterface cTokenCollateral) override external returns (uint) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("liquidateBorrow(address,uint256,address)", borrower, repayAmount, cTokenCollateral));
return abi.decode(data, (uint));
}
/**
* @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, uint amount) override external returns (bool) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("transfer(address,uint256)", dst, amount));
return abi.decode(data, (bool));
}
/**
* @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) override external returns (bool) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("transferFrom(address,address,uint256)", src, dst, amount));
return abi.decode(data, (bool));
}
/**
* @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) override external returns (bool) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("approve(address,uint256)", spender, amount));
return abi.decode(data, (bool));
}
/**
* @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) override external view returns (uint) {
bytes memory data = delegateToViewImplementation(abi.encodeWithSignature("allowance(address,address)", owner, spender));
return abi.decode(data, (uint));
}
/**
* @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) override external view returns (uint) {
bytes memory data = delegateToViewImplementation(abi.encodeWithSignature("balanceOf(address)", owner));
return abi.decode(data, (uint));
}
/**
* @notice Get the underlying balance of the `owner`
* @dev This also accrues interest in a transaction
* @param owner The address of the account to query
* @return The amount of underlying owned by `owner`
*/
function balanceOfUnderlying(address owner) override external returns (uint) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("balanceOfUnderlying(address)", owner));
return abi.decode(data, (uint));
}
/**
* @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) override external view returns (uint, uint, uint, uint) {
bytes memory data = delegateToViewImplementation(abi.encodeWithSignature("getAccountSnapshot(address)", account));
return abi.decode(data, (uint, uint, uint, uint));
}
/**
* @notice Returns the current per-block borrow interest rate for this cToken
* @return The borrow interest rate per block, scaled by 1e18
*/
function borrowRatePerBlock() override external view returns (uint) {
bytes memory data = delegateToViewImplementation(abi.encodeWithSignature("borrowRatePerBlock()"));
return abi.decode(data, (uint));
}
/**
* @notice Returns the current per-block supply interest rate for this cToken
* @return The supply interest rate per block, scaled by 1e18
*/
function supplyRatePerBlock() override external view returns (uint) {
bytes memory data = delegateToViewImplementation(abi.encodeWithSignature("supplyRatePerBlock()"));
return abi.decode(data, (uint));
}
/**
* @notice Returns the current total borrows plus accrued interest
* @return The total borrows with interest
*/
function totalBorrowsCurrent() override external returns (uint) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("totalBorrowsCurrent()"));
return abi.decode(data, (uint));
}
/**
* @notice Accrue interest to updated borrowIndex and then calculate account's borrow balance using the updated borrowIndex
* @param account The address whose balance should be calculated after updating borrowIndex
* @return The calculated balance
*/
function borrowBalanceCurrent(address account) override external returns (uint) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("borrowBalanceCurrent(address)", account));
return abi.decode(data, (uint));
}
/**
* @notice Return the borrow balance of account based on stored data
* @param account The address whose balance should be calculated
* @return The calculated balance
*/
function borrowBalanceStored(address account) override public view returns (uint) {
bytes memory data = delegateToViewImplementation(abi.encodeWithSignature("borrowBalanceStored(address)", account));
return abi.decode(data, (uint));
}
/**
* @notice Accrue interest then return the up-to-date exchange rate
* @return Calculated exchange rate scaled by 1e18
*/
function exchangeRateCurrent() override public returns (uint) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("exchangeRateCurrent()"));
return abi.decode(data, (uint));
}
/**
* @notice Calculates the exchange rate from the underlying to the CToken
* @dev This function does not accrue interest before calculating the exchange rate
* @return Calculated exchange rate scaled by 1e18
*/
function exchangeRateStored() override public view returns (uint) {
bytes memory data = delegateToViewImplementation(abi.encodeWithSignature("exchangeRateStored()"));
return abi.decode(data, (uint));
}
/**
* @notice Get cash balance of this cToken in the underlying asset
* @return The quantity of underlying asset owned by this contract
*/
function getCash() override external view returns (uint) {
bytes memory data = delegateToViewImplementation(abi.encodeWithSignature("getCash()"));
return abi.decode(data, (uint));
}
/**
* @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() override public returns (uint) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("accrueInterest()"));
return abi.decode(data, (uint));
}
/**
* @notice Transfers collateral tokens (this market) to the liquidator.
* @dev Will fail unless called by another cToken during the process of liquidation.
* Its absolutely critical to use msg.sender as the borrowed cToken and not a parameter.
* @param liquidator The account receiving seized collateral
* @param borrower The account having collateral seized
* @param seizeTokens The number of cTokens to seize
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
*/
function seize(address liquidator, address borrower, uint seizeTokens) override external returns (uint) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("seize(address,address,uint256)", liquidator, borrower, seizeTokens));
return abi.decode(data, (uint));
}
/**
* @notice A public function to sweep accidental ERC-20 transfers to this contract. Tokens are sent to admin (timelock)
* @param token The address of the ERC-20 token to sweep
*/
function sweepToken(EIP20NonStandardInterface token) override external {
delegateToImplementation(abi.encodeWithSignature("sweepToken(address)", token));
}
/*** Admin Functions ***/
/**
* @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer.
* @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer.
* @param newPendingAdmin New pending admin.
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
*/
function _setPendingAdmin(address payable newPendingAdmin) override external returns (uint) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("_setPendingAdmin(address)", newPendingAdmin));
return abi.decode(data, (uint));
}
/**
* @notice Sets a new comptroller for the market
* @dev Admin function to set a new comptroller
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
*/
function _setComptroller(ComptrollerInterface newComptroller) override public returns (uint) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("_setComptroller(address)", newComptroller));
return abi.decode(data, (uint));
}
/**
* @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(uint newReserveFactorMantissa) override external returns (uint) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("_setReserveFactor(uint256)", newReserveFactorMantissa));
return abi.decode(data, (uint));
}
/**
* @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin
* @dev Admin function for pending admin to accept role and update admin
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
*/
function _acceptAdmin() override external returns (uint) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("_acceptAdmin()"));
return abi.decode(data, (uint));
}
/**
* @notice Accrues interest and adds reserves by transferring from admin
* @param addAmount Amount of reserves to add
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
*/
function _addReserves(uint addAmount) override external returns (uint) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("_addReserves(uint256)", addAmount));
return abi.decode(data, (uint));
}
/**
* @notice Accrues interest and reduces reserves by transferring to admin
* @param reduceAmount Amount of reduction to reserves
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
*/
function _reduceReserves(uint reduceAmount) override external returns (uint) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("_reduceReserves(uint256)", reduceAmount));
return abi.decode(data, (uint));
}
/**
* @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) override public returns (uint) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("_setInterestRateModel(address)", newInterestRateModel));
return abi.decode(data, (uint));
}
/**
* @notice Sets a new whitelist for the market
* @dev Admin function to set a new whitelist
* @param newWhitelist The address of the new whitelist
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
*/
function _setWhitelist(WhitelistAccess newWhitelist) override public returns (uint) {
bytes memory data = delegateToImplementation(abi.encodeWithSignature("_setWhitelist(address)", newWhitelist));
return abi.decode(data, (uint));
}
/**
* @notice Internal method to delegate execution to another contract
* @dev It returns to the external caller whatever the implementation returns or forwards reverts
* @param callee The contract to delegatecall
* @param data The raw data to delegatecall
* @return The returned bytes from the delegatecall
*/
function delegateTo(address callee, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returnData) = callee.delegatecall(data);
assembly {
if eq(success, 0) {
revert(add(returnData, 0x20), returndatasize())
}
}
return returnData;
}
/**
* @notice Delegates execution to the implementation contract
* @dev It returns to the external caller whatever the implementation returns or forwards reverts
* @param data The raw data to delegatecall
* @return The returned bytes from the delegatecall
*/
function delegateToImplementation(bytes memory data) public returns (bytes memory) {
return delegateTo(implementation, data);
}
/**
* @notice Delegates execution to an implementation contract
* @dev It returns to the external caller whatever the implementation returns or forwards reverts
* There are an additional 2 prefix uints from the wrapper returndata, which we ignore since we make an extra hop.
* @param data The raw data to delegatecall
* @return The returned bytes from the delegatecall
*/
function delegateToViewImplementation(bytes memory data) public view returns (bytes memory) {
(bool success, bytes memory returnData) = address(this).staticcall(abi.encodeWithSignature("delegateToImplementation(bytes)", data));
assembly {
if eq(success, 0) {
revert(add(returnData, 0x20), returndatasize())
}
}
return abi.decode(returnData, (bytes));
}
/**
* @notice Delegates execution to an implementation contract
* @dev It returns to the external caller whatever the implementation returns or forwards reverts
*/
fallback() external payable {
require(msg.value == 0,"CErc20Delegator:fallback: cannot send value to fallback");
// delegate all other functions to current implementation
(bool success, ) = implementation.delegatecall(msg.data);
assembly {
let free_mem_ptr := mload(0x40)
returndatacopy(free_mem_ptr, 0, returndatasize())
switch success
case 0 { revert(free_mem_ptr, returndatasize()) }
default { return(free_mem_ptr, returndatasize()) }
}
}
}
CTokenInterfaces.sol 304 lines
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.10;
import "./ComptrollerInterface.sol";
import "./InterestRateModel.sol";
import "./EIP20NonStandardInterface.sol";
import "./ErrorReporter.sol";
import "./Access/WhitelistAccess.sol";
contract CTokenStorage {
/**
* @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)
uint internal constant borrowRateMaxMantissa = 0.0005e16;
// Maximum fraction of interest that can be set aside for reserves
uint internal constant reserveFactorMaxMantissa = 1e18;
/**
* @notice Administrator for this contract
*/
address payable public admin;
/**
* @notice Pending administrator for this contract
*/
address payable public pendingAdmin;
/**
* @notice Contract which oversees inter-cToken operations
*/
ComptrollerInterface 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)
uint internal initialExchangeRateMantissa;
/**
* @notice Fraction of interest currently set aside for reserves
*/
uint public reserveFactorMantissa;
/**
* @notice Block number that interest was last accrued at
*/
uint public accrualBlockNumber;
/**
* @notice Accumulator of the total earned interest rate since the opening of the market
*/
uint public borrowIndex;
/**
* @notice Total amount of outstanding borrows of the underlying in this market
*/
uint public totalBorrows;
/**
* @notice Total amount of reserves of the underlying held in this market
*/
uint public totalReserves;
/**
* @notice Total number of tokens in circulation
*/
uint public totalSupply;
// Official record of token balances for each account
mapping (address => uint) internal accountTokens;
// Approved token transfer amounts on behalf of others
mapping (address => mapping (address => uint)) internal transferAllowances;
/**
* @notice Container for borrow balance information
* @member principal Total balance (with accrued interest), after applying the most recent balance-changing action
* @member interestIndex Global borrowIndex as of the most recent balance-changing action
*/
struct BorrowSnapshot {
uint principal;
uint interestIndex;
}
// Mapping of account addresses to outstanding borrow balances
mapping(address => BorrowSnapshot) internal accountBorrows;
/**
* @notice Share of seized collateral that is added to reserves
*/
uint public constant protocolSeizeShareMantissa = 2.8e16; //2.8%
/**
* @notice Whitelist contract
*/
WhitelistAccess public whitelist;
}
abstract contract CTokenInterface is CTokenStorage {
/**
* @notice Indicator that this is a CToken contract (for inspection)
*/
bool public constant isCToken = true;
/*** Market Events ***/
/**
* @notice Event emitted when interest is accrued
*/
event AccrueInterest(uint cashPrior, uint interestAccumulated, uint borrowIndex, uint totalBorrows);
/**
* @notice Event emitted when tokens are minted
*/
event Mint(address minter, uint mintAmount, uint mintTokens);
/**
* @notice Event emitted when tokens are redeemed
*/
event Redeem(address redeemer, uint redeemAmount, uint redeemTokens);
/**
* @notice Event emitted when underlying is borrowed
*/
event Borrow(address borrower, uint borrowAmount, uint accountBorrows, uint totalBorrows);
/**
* @notice Event emitted when a borrow is repaid
*/
event RepayBorrow(address payer, address borrower, uint repayAmount, uint accountBorrows, uint totalBorrows);
/**
* @notice Event emitted when a borrow is liquidated
*/
event LiquidateBorrow(address liquidator, address borrower, uint repayAmount, address cTokenCollateral, uint seizeTokens);
/*** Admin Events ***/
/**
* @notice Event emitted when pendingAdmin is changed
*/
event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin);
/**
* @notice Event emitted when pendingAdmin is accepted, which means admin is updated
*/
event NewAdmin(address oldAdmin, address newAdmin);
/**
* @notice Event emitted when comptroller is changed
*/
event NewComptroller(ComptrollerInterface oldComptroller, ComptrollerInterface newComptroller);
/**
* @notice Event emitted when interestRateModel is changed
*/
event NewMarketInterestRateModel(InterestRateModel oldInterestRateModel, InterestRateModel newInterestRateModel);
/**
* @notice Event emitted when the reserve factor is changed
*/
event NewReserveFactor(uint oldReserveFactorMantissa, uint newReserveFactorMantissa);
/**
* @notice Event emitted when the reserves are added
*/
event ReservesAdded(address benefactor, uint addAmount, uint newTotalReserves);
/**
* @notice Event emitted when the reserves are reduced
*/
event ReservesReduced(address admin, uint reduceAmount, uint newTotalReserves);
/**
* @notice EIP20 Transfer event
*/
event Transfer(address indexed from, address indexed to, uint amount);
/**
* @notice EIP20 Approval event
*/
event Approval(address indexed owner, address indexed spender, uint amount);
/**
* @notice Event emitted when whitelist is changed
*/
event NewWhitelist(WhitelistAccess oldWhitelist, WhitelistAccess newWhitelist);
/*** User Interface ***/
function transfer(address dst, uint amount) virtual external returns (bool);
function transferFrom(address src, address dst, uint amount) virtual external returns (bool);
function approve(address spender, uint amount) virtual external returns (bool);
function allowance(address owner, address spender) virtual external view returns (uint);
function balanceOf(address owner) virtual external view returns (uint);
function balanceOfUnderlying(address owner) virtual external returns (uint);
function getAccountSnapshot(address account) virtual external view returns (uint, uint, uint, uint);
function borrowRatePerBlock() virtual external view returns (uint);
function supplyRatePerBlock() virtual external view returns (uint);
function totalBorrowsCurrent() virtual external returns (uint);
function borrowBalanceCurrent(address account) virtual external returns (uint);
function borrowBalanceStored(address account) virtual external view returns (uint);
function exchangeRateCurrent() virtual external returns (uint);
function exchangeRateStored() virtual external view returns (uint);
function getCash() virtual external view returns (uint);
function accrueInterest() virtual external returns (uint);
function seize(address liquidator, address borrower, uint seizeTokens) virtual external returns (uint);
/*** Admin Functions ***/
function _setPendingAdmin(address payable newPendingAdmin) virtual external returns (uint);
function _acceptAdmin() virtual external returns (uint);
function _setComptroller(ComptrollerInterface newComptroller) virtual external returns (uint);
function _setReserveFactor(uint newReserveFactorMantissa) virtual external returns (uint);
function _reduceReserves(uint reduceAmount) virtual external returns (uint);
function _setInterestRateModel(InterestRateModel newInterestRateModel) virtual external returns (uint);
function _setWhitelist(WhitelistAccess newWhitelist) virtual external returns (uint);
}
contract CErc20Storage {
/**
* @notice Underlying asset for this CToken
*/
address public underlying;
}
abstract contract CErc20Interface is CErc20Storage {
/*** User Interface ***/
function mint(uint mintAmount) virtual external returns (uint);
function redeem(uint redeemTokens) virtual external returns (uint);
function redeemUnderlying(uint redeemAmount) virtual external returns (uint);
function borrow(uint borrowAmount) virtual external returns (uint);
function repayBorrow(uint repayAmount) virtual external returns (uint);
function repayBorrowBehalf(address borrower, uint repayAmount) virtual external returns (uint);
function liquidateBorrow(address borrower, uint repayAmount, CTokenInterface cTokenCollateral) virtual external returns (uint);
function sweepToken(EIP20NonStandardInterface token) virtual external;
/*** Admin Functions ***/
function _addReserves(uint addAmount) virtual external returns (uint);
}
contract CDelegationStorage {
/**
* @notice Implementation address for this contract
*/
address public implementation;
}
abstract contract CDelegatorInterface is CDelegationStorage {
/**
* @notice Emitted when implementation is changed
*/
event NewImplementation(address oldImplementation, address newImplementation);
/**
* @notice Called by the admin to update the implementation of the delegator
* @param implementation_ The address of the new implementation for delegation
* @param allowResign Flag to indicate whether to call _resignImplementation on the old implementation
* @param becomeImplementationData The encoded bytes data to be passed to _becomeImplementation
*/
function _setImplementation(address implementation_, bool allowResign, bytes memory becomeImplementationData) virtual external;
}
abstract contract CDelegateInterface is CDelegationStorage {
/**
* @notice Called by the delegator on a delegate to initialize it for duty
* @dev Should revert if any issues arise which make it unfit for delegation
* @param data The encoded bytes data for any initialization
*/
function _becomeImplementation(bytes memory data) virtual external;
/**
* @notice Called by the delegator on a delegate to forfeit its responsibility
*/
function _resignImplementation() virtual external;
}
ComptrollerInterface.sol 72 lines
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.10;
abstract contract ComptrollerInterface {
/// @notice Indicator that this is a Comptroller contract (for inspection)
bool public constant isComptroller = true;
/*** Assets You Are In ***/
function enterMarkets(address[] calldata cTokens) virtual external returns (uint[] memory);
function exitMarket(address cToken) virtual external returns (uint);
/*** Policy Hooks ***/
function mintAllowed(address cToken, address minter, uint mintAmount) virtual external returns (uint);
function mintVerify(address cToken, address minter, uint mintAmount, uint mintTokens) virtual external;
function redeemAllowed(address cToken, address redeemer, uint redeemTokens) virtual external returns (uint);
function redeemVerify(address cToken, address redeemer, uint redeemAmount, uint redeemTokens) virtual external;
function borrowAllowed(address cToken, address borrower, uint borrowAmount) virtual external returns (uint);
function borrowVerify(address cToken, address borrower, uint borrowAmount) virtual external;
function repayBorrowAllowed(
address cToken,
address payer,
address borrower,
uint repayAmount) virtual external returns (uint);
function repayBorrowVerify(
address cToken,
address payer,
address borrower,
uint repayAmount,
uint borrowerIndex) virtual external;
function liquidateBorrowAllowed(
address cTokenBorrowed,
address cTokenCollateral,
address liquidator,
address borrower,
uint repayAmount) virtual external returns (uint);
function liquidateBorrowVerify(
address cTokenBorrowed,
address cTokenCollateral,
address liquidator,
address borrower,
uint repayAmount,
uint seizeTokens) virtual external;
function seizeAllowed(
address cTokenCollateral,
address cTokenBorrowed,
address liquidator,
address borrower,
uint seizeTokens) virtual external returns (uint);
function seizeVerify(
address cTokenCollateral,
address cTokenBorrowed,
address liquidator,
address borrower,
uint seizeTokens) virtual external;
function transferAllowed(address cToken, address src, address dst, uint transferTokens) virtual external returns (uint);
function transferVerify(address cToken, address src, address dst, uint transferTokens) virtual external;
/*** Liquidity/Liquidation Calculations ***/
function liquidateCalculateSeizeTokens(
address cTokenBorrowed,
address cTokenCollateral,
uint repayAmount) virtual external view returns (uint, uint);
}
EIP20NonStandardInterface.sol 71 lines
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.10;
/**
* @title EIP20NonStandardInterface
* @dev Version of ERC20 with no return values for `transfer` and `transferFrom`
* See https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca
*/
interface EIP20NonStandardInterface {
/**
* @notice Get the total number of tokens in circulation
* @return The supply of tokens
*/
function totalSupply() external view returns (uint256);
/**
* @notice Gets the balance of the specified address
* @param owner The address from which the balance will be retrieved
* @return balance The balance
*/
function balanceOf(address owner) external view returns (uint256 balance);
///
/// !!!!!!!!!!!!!!
/// !!! NOTICE !!! `transfer` does not return a value, in violation of the ERC-20 specification
/// !!!!!!!!!!!!!!
///
/**
* @notice Transfer `amount` tokens from `msg.sender` to `dst`
* @param dst The address of the destination account
* @param amount The number of tokens to transfer
*/
function transfer(address dst, uint256 amount) external;
///
/// !!!!!!!!!!!!!!
/// !!! NOTICE !!! `transferFrom` does not return a value, in violation of the ERC-20 specification
/// !!!!!!!!!!!!!!
///
/**
* @notice Transfer `amount` tokens from `src` to `dst`
* @param src The address of the source account
* @param dst The address of the destination account
* @param amount The number of tokens to transfer
*/
function transferFrom(address src, address dst, uint256 amount) external;
/**
* @notice Approve `spender` to transfer up to `amount` from `src`
* @dev This will overwrite the approval amount for `spender`
* and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)
* @param spender The address of the account which may transfer tokens
* @param amount The number of tokens that are approved
* @return success Whether or not the approval succeeded
*/
function approve(address spender, uint256 amount) external returns (bool success);
/**
* @notice Get the current allowance from `owner` for `spender`
* @param owner The address of the account which owns the tokens to be spent
* @param spender The address of the account which may transfer tokens
* @return remaining The number of tokens allowed to be spent
*/
function allowance(address owner, address spender) external view returns (uint256 remaining);
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
}
ErrorReporter.sol 129 lines
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.10;
contract ComptrollerErrorReporter {
enum Error {
NO_ERROR,
UNAUTHORIZED,
COMPTROLLER_MISMATCH,
INSUFFICIENT_SHORTFALL,
INSUFFICIENT_LIQUIDITY,
INVALID_CLOSE_FACTOR,
INVALID_COLLATERAL_FACTOR,
INVALID_LIQUIDATION_INCENTIVE,
MARKET_NOT_ENTERED, // no longer possible
MARKET_NOT_LISTED,
MARKET_ALREADY_LISTED,
MATH_ERROR,
NONZERO_BORROW_BALANCE,
PRICE_ERROR,
REJECTION,
SNAPSHOT_ERROR,
TOO_MANY_ASSETS,
TOO_MUCH_REPAY
}
enum FailureInfo {
ACCEPT_ADMIN_PENDING_ADMIN_CHECK,
ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK,
EXIT_MARKET_BALANCE_OWED,
EXIT_MARKET_REJECTION,
SET_CLOSE_FACTOR_OWNER_CHECK,
SET_CLOSE_FACTOR_VALIDATION,
SET_COLLATERAL_FACTOR_OWNER_CHECK,
SET_COLLATERAL_FACTOR_NO_EXISTS,
SET_COLLATERAL_FACTOR_VALIDATION,
SET_COLLATERAL_FACTOR_WITHOUT_PRICE,
SET_IMPLEMENTATION_OWNER_CHECK,
SET_LIQUIDATION_INCENTIVE_OWNER_CHECK,
SET_LIQUIDATION_INCENTIVE_VALIDATION,
SET_MAX_ASSETS_OWNER_CHECK,
SET_PENDING_ADMIN_OWNER_CHECK,
SET_PENDING_IMPLEMENTATION_OWNER_CHECK,
SET_PRICE_ORACLE_OWNER_CHECK,
SUPPORT_MARKET_EXISTS,
SUPPORT_MARKET_OWNER_CHECK,
SET_PAUSE_GUARDIAN_OWNER_CHECK
}
/**
* @dev `error` corresponds to enum Error; `info` corresponds to enum FailureInfo, and `detail` is an arbitrary
* contract-specific code that enables us to report opaque error codes from upgradeable contracts.
**/
event Failure(uint error, uint info, uint detail);
/**
* @dev use this when reporting a known error from the money market or a non-upgradeable collaborator
*/
function fail(Error err, FailureInfo info) internal returns (uint) {
emit Failure(uint(err), uint(info), 0);
return uint(err);
}
/**
* @dev use this when reporting an opaque error from an upgradeable collaborator contract
*/
function failOpaque(Error err, FailureInfo info, uint opaqueError) internal returns (uint) {
emit Failure(uint(err), uint(info), opaqueError);
return uint(err);
}
}
contract TokenErrorReporter {
uint public constant NO_ERROR = 0; // support legacy return codes
error TransferComptrollerRejection(uint256 errorCode);
error TransferNotAllowed();
error TransferNotEnough();
error TransferTooMuch();
error MintComptrollerRejection(uint256 errorCode);
error MintFreshnessCheck();
error RedeemComptrollerRejection(uint256 errorCode);
error RedeemFreshnessCheck();
error RedeemTransferOutNotPossible();
error BorrowComptrollerRejection(uint256 errorCode);
error BorrowFreshnessCheck();
error BorrowCashNotAvailable();
error RepayBorrowComptrollerRejection(uint256 errorCode);
error RepayBorrowFreshnessCheck();
error LiquidateComptrollerRejection(uint256 errorCode);
error LiquidateFreshnessCheck();
error LiquidateCollateralFreshnessCheck();
error LiquidateAccrueBorrowInterestFailed(uint256 errorCode);
error LiquidateAccrueCollateralInterestFailed(uint256 errorCode);
error LiquidateLiquidatorIsBorrower();
error LiquidateCloseAmountIsZero();
error LiquidateCloseAmountIsUintMax();
error LiquidateRepayBorrowFreshFailed(uint256 errorCode);
error LiquidateSeizeComptrollerRejection(uint256 errorCode);
error LiquidateSeizeLiquidatorIsBorrower();
error AcceptAdminPendingAdminCheck();
error SetComptrollerOwnerCheck();
error SetPendingAdminOwnerCheck();
error SetReserveFactorAdminCheck();
error SetReserveFactorFreshCheck();
error SetReserveFactorBoundsCheck();
error AddReservesFactorFreshCheck(uint256 actualAddAmount);
error ReduceReservesAdminCheck();
error ReduceReservesFreshCheck();
error ReduceReservesCashNotAvailable();
error ReduceReservesCashValidation();
error SetInterestRateModelOwnerCheck();
error SetInterestRateModelFreshCheck();
error SetWhitelistAdminOwnerCheck();
}
InterestRateModel.sol 30 lines
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.10;
/**
* @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(uint cash, uint borrows, uint reserves) virtual external view returns (uint);
/**
* @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(uint cash, uint borrows, uint reserves, uint reserveFactorMantissa) virtual external view returns (uint);
}
Read Contract
accrualBlockNumber 0x6c540baf → uint256
admin 0xf851a440 → address
allowance 0xdd62ed3e → uint256
balanceOf 0x70a08231 → uint256
borrowBalanceStored 0x95dd9193 → uint256
borrowIndex 0xaa5af0fd → uint256
borrowRatePerBlock 0xf8f9da28 → uint256
comptroller 0x5fe3b567 → address
decimals 0x313ce567 → uint8
delegateToViewImplementation 0x4487152f → bytes
exchangeRateStored 0x182df0f5 → uint256
getAccountSnapshot 0xc37f68e2 → uint256, uint256, uint256, uint256
getCash 0x3b1d21a2 → uint256
implementation 0x5c60da1b → address
interestRateModel 0xf3fdb15a → address
isCToken 0xfe9c44ae → bool
name 0x06fdde03 → string
pendingAdmin 0x26782247 → address
protocolSeizeShareMantissa 0x6752e702 → uint256
reserveFactorMantissa 0x173b9904 → uint256
supplyRatePerBlock 0xae9d70b0 → uint256
symbol 0x95d89b41 → string
totalBorrows 0x47bd3718 → uint256
totalReserves 0x8f840ddd → uint256
totalSupply 0x18160ddd → uint256
underlying 0x6f307dc3 → address
whitelist 0x93e59dc1 → address
Write Contract 27 functions
These functions modify contract state and require a wallet transaction to execute.
_acceptAdmin 0xe9c714f2
No parameters
returns: uint256
_addReserves 0x3e941010
uint256 addAmount
returns: uint256
_reduceReserves 0x601a0bf1
uint256 reduceAmount
returns: uint256
_setComptroller 0x4576b5db
address newComptroller
returns: uint256
_setImplementation 0x555bcc40
address implementation_
bool allowResign
bytes becomeImplementationData
_setInterestRateModel 0xf2b3abbd
address newInterestRateModel
returns: uint256
_setPendingAdmin 0xb71d1a0c
address newPendingAdmin
returns: uint256
_setReserveFactor 0xfca7820b
uint256 newReserveFactorMantissa
returns: uint256
_setWhitelist 0xfe881bda
address newWhitelist
returns: uint256
accrueInterest 0xa6afed95
No parameters
returns: uint256
approve 0x095ea7b3
address spender
uint256 amount
returns: bool
balanceOfUnderlying 0x3af9e669
address owner
returns: uint256
borrow 0xc5ebeaec
uint256 borrowAmount
returns: uint256
borrowBalanceCurrent 0x17bfdfbc
address account
returns: uint256
delegateToImplementation 0x0933c1ed
bytes data
returns: bytes
exchangeRateCurrent 0xbd6d894d
No parameters
returns: uint256
liquidateBorrow 0xf5e3c462
address borrower
uint256 repayAmount
address cTokenCollateral
returns: uint256
mint 0xa0712d68
uint256 mintAmount
returns: uint256
redeem 0xdb006a75
uint256 redeemTokens
returns: uint256
redeemUnderlying 0x852a12e3
uint256 redeemAmount
returns: uint256
repayBorrow 0x0e752702
uint256 repayAmount
returns: uint256
repayBorrowBehalf 0x2608f818
address borrower
uint256 repayAmount
returns: uint256
seize 0xb2a02ff1
address liquidator
address borrower
uint256 seizeTokens
returns: uint256
sweepToken 0x1be19560
address token
totalBorrowsCurrent 0x73acee98
No parameters
returns: uint256
transfer 0xa9059cbb
address dst
uint256 amount
returns: bool
transferFrom 0x23b872dd
address src
address dst
uint256 amount
returns: bool
Recent Transactions
No transactions found for this address