ctoken-interface-sonne

Created Diff never expires
1 removal
Lines
Total
Removed
Words
Total
Removed
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
294 lines
0 additions
Lines
Total
Added
Words
Total
Added
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
293 lines
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.10;
pragma solidity ^0.8.10;


import "./ComptrollerInterface.sol";
import "./ComptrollerInterface.sol";
import "./InterestRateModel.sol";
import "./InterestRateModel.sol";
import "./EIP20NonStandardInterface.sol";
import "./EIP20NonStandardInterface.sol";
import "./ErrorReporter.sol";
import "./ErrorReporter.sol";


contract CTokenStorage {
contract CTokenStorage {
/**
/**
* @dev Guard variable for re-entrancy checks
* @dev Guard variable for re-entrancy checks
*/
*/
bool internal _notEntered;
bool internal _notEntered;


/**
/**
* @notice EIP-20 token name for this token
* @notice EIP-20 token name for this token
*/
*/
string public name;
string public name;


/**
/**
* @notice EIP-20 token symbol for this token
* @notice EIP-20 token symbol for this token
*/
*/
string public symbol;
string public symbol;


/**
/**
* @notice EIP-20 token decimals for this token
* @notice EIP-20 token decimals for this token
*/
*/
uint8 public decimals;
uint8 public decimals;


// Maximum borrow rate that can ever be applied (.0005% / block)
// Maximum borrow rate that can ever be applied (.0005% / block)
uint internal constant borrowRateMaxMantissa = 0.0005e16;
uint internal constant borrowRateMaxMantissa = 0.0005e16;


// Maximum fraction of interest that can be set aside for reserves
// Maximum fraction of interest that can be set aside for reserves
uint internal constant reserveFactorMaxMantissa = 1e18;
uint internal constant reserveFactorMaxMantissa = 1e18;


/**
/**
* @notice Administrator for this contract
* @notice Administrator for this contract
*/
*/
address payable public admin;
address payable public admin;


/**
/**
* @notice Pending administrator for this contract
* @notice Pending administrator for this contract
*/
*/
address payable public pendingAdmin;
address payable public pendingAdmin;


/**
/**
* @notice Contract which oversees inter-cToken operations
* @notice Contract which oversees inter-cToken operations
*/
*/
ComptrollerInterface public comptroller;
ComptrollerInterface public comptroller;


/**
/**
* @notice Model which tells what the current interest rate should be
* @notice Model which tells what the current interest rate should be
*/
*/
InterestRateModel public interestRateModel;
InterestRateModel public interestRateModel;


// Initial exchange rate used when minting the first CTokens (used when totalSupply = 0)
// Initial exchange rate used when minting the first CTokens (used when totalSupply = 0)
uint internal initialExchangeRateMantissa;
uint internal initialExchangeRateMantissa;


/**
/**
* @notice Fraction of interest currently set aside for reserves
* @notice Fraction of interest currently set aside for reserves
*/
*/
uint public reserveFactorMantissa;
uint public reserveFactorMantissa;


/**
/**
* @notice Block number that interest was last accrued at
* @notice Block number that interest was last accrued at
*/
*/
uint public accrualBlockNumber;
uint public accrualBlockNumber;


/**
/**
* @notice Accumulator of the total earned interest rate since the opening of the market
* @notice Accumulator of the total earned interest rate since the opening of the market
*/
*/
uint public borrowIndex;
uint public borrowIndex;


/**
/**
* @notice Total amount of outstanding borrows of the underlying in this market
* @notice Total amount of outstanding borrows of the underlying in this market
*/
*/
uint public totalBorrows;
uint public totalBorrows;


/**
/**
* @notice Total amount of reserves of the underlying held in this market
* @notice Total amount of reserves of the underlying held in this market
*/
*/
uint public totalReserves;
uint public totalReserves;


/**
/**
* @notice Total number of tokens in circulation
* @notice Total number of tokens in circulation
*/
*/
uint public totalSupply;
uint public totalSupply;


// Official record of token balances for each account
// Official record of token balances for each account
mapping (address => uint) internal accountTokens;
mapping (address => uint) internal accountTokens;


// Approved token transfer amounts on behalf of others
// Approved token transfer amounts on behalf of others
mapping (address => mapping (address => uint)) internal transferAllowances;
mapping (address => mapping (address => uint)) internal transferAllowances;


/**
/**
* @notice Container for borrow balance information
* @notice Container for borrow balance information
* @member principal Total balance (with accrued interest), after applying the most recent balance-changing action
* @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
* @member interestIndex Global borrowIndex as of the most recent balance-changing action
*/
*/
struct BorrowSnapshot {
struct BorrowSnapshot {
uint principal;
uint principal;
uint interestIndex;
uint interestIndex;
}
}


// Mapping of account addresses to outstanding borrow balances
// Mapping of account addresses to outstanding borrow balances
mapping(address => BorrowSnapshot) internal accountBorrows;
mapping(address => BorrowSnapshot) internal accountBorrows;


/**
/**
* @notice Share of seized collateral that is added to reserves
* @notice Share of seized collateral that is added to reserves
*/
*/
uint public constant protocolSeizeShareMantissa = 2.8e16; //2.8%
uint public constant protocolSeizeShareMantissa = 2.8e16; //2.8%
}
}


abstract contract CTokenInterface is CTokenStorage {
abstract contract CTokenInterface is CTokenStorage {
/**
/**
* @notice Indicator that this is a CToken contract (for inspection)
* @notice Indicator that this is a CToken contract (for inspection)
*/
*/
bool public constant isCToken = true;
bool public constant isCToken = true;




/*** Market Events ***/
/*** Market Events ***/


/**
/**
* @notice Event emitted when interest is accrued
* @notice Event emitted when interest is accrued
*/
*/
event AccrueInterest(uint cashPrior, uint interestAccumulated, uint borrowIndex, uint totalBorrows);
event AccrueInterest(uint cashPrior, uint interestAccumulated, uint borrowIndex, uint totalBorrows);


/**
/**
* @notice Event emitted when tokens are minted
* @notice Event emitted when tokens are minted
*/
*/
event Mint(address minter, uint mintAmount, uint mintTokens);
event Mint(address minter, uint mintAmount, uint mintTokens);


/**
/**
* @notice Event emitted when tokens are redeemed
* @notice Event emitted when tokens are redeemed
*/
*/
event Redeem(address redeemer, uint redeemAmount, uint redeemTokens);
event Redeem(address redeemer, uint redeemAmount, uint redeemTokens);


/**
/**
* @notice Event emitted when underlying is borrowed
* @notice Event emitted when underlying is borrowed
*/
*/
event Borrow(address borrower, uint borrowAmount, uint accountBorrows, uint totalBorrows);
event Borrow(address borrower, uint borrowAmount, uint accountBorrows, uint totalBorrows);


/**
/**
* @notice Event emitted when a borrow is repaid
* @notice Event emitted when a borrow is repaid
*/
*/
event RepayBorrow(address payer, address borrower, uint repayAmount, uint accountBorrows, uint totalBorrows);
event RepayBorrow(address payer, address borrower, uint repayAmount, uint accountBorrows, uint totalBorrows);


/**
/**
* @notice Event emitted when a borrow is liquidated
* @notice Event emitted when a borrow is liquidated
*/
*/
event LiquidateBorrow(address liquidator, address borrower, uint repayAmount, address cTokenCollateral, uint seizeTokens);
event LiquidateBorrow(address liquidator, address borrower, uint repayAmount, address cTokenCollateral, uint seizeTokens);




/*** Admin Events ***/
/*** Admin Events ***/


/**
/**
* @notice Event emitted when pendingAdmin is changed
* @notice Event emitted when pendingAdmin is changed
*/
*/
event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin);
event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin);


/**
/**
* @notice Event emitted when pendingAdmin is accepted, which means admin is updated
* @notice Event emitted when pendingAdmin is accepted, which means admin is updated
*/
*/
event NewAdmin(address oldAdmin, address newAdmin);
event NewAdmin(address oldAdmin, address newAdmin);


/**
/**
* @notice Event emitted when comptroller is changed
* @notice Event emitted when comptroller is changed
*/
*/
event NewComptroller(ComptrollerInterface oldComptroller, ComptrollerInterface newComptroller);
event NewComptroller(ComptrollerInterface oldComptroller, ComptrollerInterface newComptroller);


/**
/**
* @notice Event emitted when interestRateModel is changed
* @notice Event emitted when interestRateModel is changed
*/
*/
event NewMarketInterestRateModel(InterestRateModel oldInterestRateModel, InterestRateModel newInterestRateModel);
event NewMarketInterestRateModel(InterestRateModel oldInterestRateModel, InterestRateModel newInterestRateModel);


/**
/**
* @notice Event emitted when the reserve factor is changed
* @notice Event emitted when the reserve factor is changed
*/
*/
event NewReserveFactor(uint oldReserveFactorMantissa, uint newReserveFactorMantissa);
event NewReserveFactor(uint oldReserveFactorMantissa, uint newReserveFactorMantissa);


/**
/**
* @notice Event emitted when the reserves are added
* @notice Event emitted when the reserves are added
*/
*/
event ReservesAdded(address benefactor, uint addAmount, uint newTotalReserves);
event ReservesAdded(address benefactor, uint addAmount, uint newTotalReserves);


/**
/**
* @notice Event emitted when the reserves are reduced
* @notice Event emitted when the reserves are reduced
*/
*/
event ReservesReduced(address admin, uint reduceAmount, uint newTotalReserves);
event ReservesReduced(address admin, uint reduceAmount, uint newTotalReserves);


/**
/**
* @notice EIP20 Transfer event
* @notice EIP20 Transfer event
*/
*/
event Transfer(address indexed from, address indexed to, uint amount);
event Transfer(address indexed from, address indexed to, uint amount);


/**
/**
* @notice EIP20 Approval event
* @notice EIP20 Approval event
*/
*/
event Approval(address indexed owner, address indexed spender, uint amount);
event Approval(address indexed owner, address indexed spender, uint amount);




/*** User Interface ***/
/*** User Interface ***/


function transfer(address dst, uint amount) virtual external returns (bool);
function transfer(address dst, uint amount) virtual external returns (bool);
function transferFrom(address src, 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 approve(address spender, uint amount) virtual external returns (bool);
function allowance(address owner, address spender) virtual external view returns (uint);
function allowance(address owner, address spender) virtual external view returns (uint);
function balanceOf(address owner) virtual external view returns (uint);
function balanceOf(address owner) virtual external view returns (uint);
function balanceOfUnderlying(address owner) virtual external returns (uint);
function balanceOfUnderlying(address owner) virtual external returns (uint);
function getAccountSnapshot(address account) virtual external view returns (uint, uint, uint, uint);
function getAccountSnapshot(address account) virtual external view returns (uint, uint, uint, uint);
function borrowRatePerBlock() virtual external view returns (uint);
function borrowRatePerBlock() virtual external view returns (uint);
function supplyRatePerBlock() virtual external view returns (uint);
function supplyRatePerBlock() virtual external view returns (uint);
function totalBorrowsCurrent() virtual external returns (uint);
function totalBorrowsCurrent() virtual external returns (uint);
function borrowBalanceCurrent(address account) virtual external returns (uint);
function borrowBalanceCurrent(address account) virtual external returns (uint);
function borrowBalanceStored(address account) virtual external view returns (uint);
function borrowBalanceStored(address account) virtual external view returns (uint);
function exchangeRateCurrent() virtual external returns (uint);
function exchangeRateCurrent() virtual external returns (uint);
function exchangeRateStored() virtual external view returns (uint);
function exchangeRateStored() virtual external view returns (uint);
function getCash() virtual external view returns (uint);
function getCash() virtual external view returns (uint);
function accrueInterest() virtual external returns (uint);
function accrueInterest() virtual external returns (uint);
function seize(address liquidator, address borrower, uint seizeTokens) virtual external returns (uint);
function seize(address liquidator, address borrower, uint seizeTokens) virtual external returns (uint);




/*** Admin Functions ***/
/*** Admin Functions ***/


function _setPendingAdmin(address payable newPendingAdmin) virtual external returns (uint);
function _setPendingAdmin(address payable newPendingAdmin) virtual external returns (uint);
function _acceptAdmin() virtual external returns (uint);
function _acceptAdmin() virtual external returns (uint);
function _setComptroller(ComptrollerInterface newComptroller) virtual external returns (uint);
function _setComptroller(ComptrollerInterface newComptroller) virtual external returns (uint);
function _setReserveFactor(uint newReserveFactorMantissa) virtual external returns (uint);
function _setReserveFactor(uint newReserveFactorMantissa) virtual external returns (uint);
function _reduceReserves(uint reduceAmount) virtual external returns (uint);
function _reduceReserves(uint reduceAmount) virtual external returns (uint);
function _setInterestRateModel(InterestRateModel newInterestRateModel) virtual external returns (uint);
function _setInterestRateModel(InterestRateModel newInterestRateModel) virtual external returns (uint);
}
}


contract CErc20Storage {
contract CErc20Storage {
/**
/**
* @notice Underlying asset for this CToken
* @notice Underlying asset for this CToken
*/
*/
address public underlying;
address public underlying;
}
}


abstract contract CErc20Interface is CErc20Storage {
abstract contract CErc20Interface is CErc20Storage {


/*** User Interface ***/
/*** User Interface ***/


function mint(uint mintAmount) virtual external returns (uint);
function mint(uint mintAmount) virtual external returns (uint);
function redeem(uint redeemTokens) virtual external returns (uint);
function redeem(uint redeemTokens) virtual external returns (uint);
function redeemUnderlying(uint redeemAmount) virtual external returns (uint);
function redeemUnderlying(uint redeemAmount) virtual external returns (uint);
function borrow(uint borrowAmount) virtual external returns (uint);
function borrow(uint borrowAmount) virtual external returns (uint);
function repayBorrow(uint repayAmount) virtual external returns (uint);
function repayBorrow(uint repayAmount) virtual external returns (uint);
function repayBorrowBehalf(address borrower, 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 liquidateBorrow(address borrower, uint repayAmount, CTokenInterface cTokenCollateral) virtual external returns (uint);
function sweepToken(EIP20NonStandardInterface token) virtual external;
function sweepToken(EIP20NonStandardInterface token) virtual external;




/*** Admin Functions ***/
/*** Admin Functions ***/


function _addReserves(uint addAmount) virtual external returns (uint);
function _addReserves(uint addAmount) virtual external returns (uint);
}
}


contract CDelegationStorage {
contract CDelegationStorage {
/**
/**
* @notice Implementation address for this contract
* @notice Implementation address for this contract
*/
*/
address public implementation;
address public implementation;
}
}


abstract contract CDelegatorInterface is CDelegationStorage {
abstract contract CDelegatorInterface is CDelegationStorage {
/**
/**
* @notice Emitted when implementation is changed
* @notice Emitted when implementation is changed
*/
*/
event NewImplementation(address oldImplementation, address newImplementation);
event NewImplementation(address oldImplementation, address newImplementation);


/**
/**
* @notice Called by the admin to update the implementation of the delegator
* @notice Called by the admin to update the implementation of the delegator
* @param implementation_ The address of the new implementation for delegation
* @param implementation_ The address of the new implementation for delegation
* @param allowResign Flag to indicate whether to call _resignImplementation on the old implementation
* @param allowResign Flag to indicate whether to call _resignImplementation on the old implementation
* @param becomeImplementationData The encoded bytes data to be passed to _becomeImplementation
* @param becomeImplementationData The encoded bytes data to be passed to _becomeImplementation
*/
*/
function _setImplementation(address implementation_, bool allowResign, bytes memory becomeImplementationData) virtual external;
function _setImplementation(address implementation_, bool allowResign, bytes memory becomeImplementationData) virtual external;
}
}


abstract contract CDelegateInterface is CDelegationStorage {
abstract contract CDelegateInterface is CDelegationStorage {
/**
/**
* @notice Called by the delegator on a delegate to initialize it for duty
* @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
* @dev Should revert if any issues arise which make it unfit for delegation
* @param data The encoded bytes data for any initialization
* @param data The encoded bytes data for any initialization
*/
*/
function _becomeImplementation(bytes memory data) virtual external;
function _becomeImplementation(bytes memory data) virtual external;


/**
/**
* @notice Called by the delegator on a delegate to forfeit its responsibility
* @notice Called by the delegator on a delegate to forfeit its responsibility
*/
*/
function _resignImplementation() virtual external;
function _resignImplementation() virtual external;
}
}