Request form
Cookbook may introduce a token in the future. Share and contribute to be eligible for future airdrops.
close icon
relevant tag icon
Compound Comptroller
copy icon
compound
• version 1.0.0
Compound
Finance
Risk
Audited

Compound Comptroller

Audited

The risk model contract, which validates permissible user actions and disallows actions if they do not fit certain risk parameters. For instance, the Comptroller enforces that each borrowing user must maintain a sufficient collateral balance across all cTokens.

*Visit desktop site to download or deploy

Version

1.0.0

Creator

compound

Recent Use

🍞 0x0759 downloaded

Last Publish

10/26/2022
Any contract you deploy is yours.
Fully owned and controlled by your wallet.
Documentation
Source Code
getAssetsIn(address) :
This function is used to retrieve an array of CToken assets that are held in a given address. It takes in an address as an argument and returns an array of CToken assets that are held in that address. The function works by accessing the accountAssets mapping, which stores the address of the account as the key and an array of CToken assets as the value. The function then returns the array of CToken assets associated with the given address. (autogenerated documentation)
checkMembership(address) :
This function checks whether a given account is a member of a given cToken. It does this by accessing the markets mapping, which stores the address of the cToken and a mapping of accounts to their membership status. The function then returns a boolean value indicating whether the account is a member or not. (autogenerated documentation)
enterMarkets() :
This function allows a user to enter multiple markets at once. It takes an array of cTokens as an argument and loops through each one, calling the addToMarketInternal function for each one. The addToMarketInternal function adds the cToken to the market and returns a uint indicating the result of the operation. The results of each operation are stored in an array and returned to the user. (autogenerated documentation)
addToMarketInternal(address) :
This function adds a borrower to a given cToken market. It first checks if the market is listed, and if the borrower is already a member of the market. If the borrower is not already a member, it sets the borrower's membership to true and adds the cToken to the borrower's account assets. Finally, it emits a MarketEntered event. (autogenerated documentation)
exitMarket(address) :
This function allows a user to exit a market by redeeming all of their tokens and removing their membership from the market. It first checks to make sure that the user does not have any outstanding borrow balance, and then checks to see if the user is a member of the market. If they are, it removes them from the market and emits an event to signal that the user has exited the market. Finally, it returns an error code to indicate whether the exit was successful or not. (autogenerated documentation)
mintAllowed(address,address) :
This function allows a minter to mint a given amount of a given cToken. It first checks if the minting of the cToken is paused, and if the cToken is listed. If both of these conditions are met, it updates the cToken's supply index and distributes the supplier's compensation. Finally, it returns a status code indicating that the minting was successful. (autogenerated documentation)
mintVerify(address,address) :
This function is an override of the mintVerify function in the Compound protocol. It is used to verify that a given minter is authorized to mint a given amount of cTokens. It takes in four parameters: the address of the cToken, the address of the minter, the actual mint amount, and the amount of tokens to be minted. The function then checks to make sure that the minter is authorized to mint the given amount of cTokens, and if not, it will throw an error. Finally, it checks to make sure that the total amount of cTokens minted does not exceed the maximum amount of assets allowed. (autogenerated documentation)
redeemAllowed(address,address) :
This function allows a redeemer to redeem a specified amount of cTokens from a given cToken address. It first checks if the redeemer is allowed to redeem the tokens, and if so, it updates the cToken's supply index and distributes the supplier's compensation. The function returns an error code if the redeemer is not allowed to redeem the tokens. (autogenerated documentation)
redeemAllowedInternal(address,address) :
This function checks if a given address is allowed to redeem a given amount of tokens from a given cToken contract. It does this by first checking if the cToken is listed, then checking if the redeemer is a member of the cToken's account membership, and finally checking if the redeemer has sufficient liquidity to cover the redemption. If all of these conditions are met, the function returns Error.NO_ERROR, otherwise it returns an error code. (autogenerated documentation)
redeemVerify(address,address) :
This function is used to verify a redeem transaction on a cToken contract. It checks that the redeemer address, the amount of cToken to be redeemed, and the amount of tokens to be received are all valid. If the redeemTokens value is zero and the redeemAmount is greater than zero, the transaction will be reverted. (autogenerated documentation)
borrowAllowed(address,address) :
This function checks if a borrower is allowed to borrow a certain amount of a cToken. It first checks if the borrow is paused, if the market is listed, and if the borrower is a member of the market. It then checks if the oracle price is valid and if the borrow cap has been reached. It then checks if the borrower has enough liquidity to cover the borrow amount and if not, returns an error. Finally, it updates the borrow index and distributes the borrower's compensation. (autogenerated documentation)
borrowVerify(address,address) :
This function is used to verify a borrower's request to borrow a certain amount of a cToken. It checks the address of the cToken, the address of the borrower, and the amount of the borrow request. If all of these parameters are valid, the function will allow the borrower to borrow the requested amount. (autogenerated documentation)
repayBorrowAllowed(address,address,address) :
This function allows a borrower to repay a loan taken out from a cToken. It first checks if the cToken is listed, then updates the borrow index and distributes the borrower's compensation accordingly. Finally, it returns an error code indicating whether the repayment was successful or not. (autogenerated documentation)
repayBorrowVerify(address,address,address) :
This function is used to verify a repayment of a loan taken out from a cToken contract. It takes in the address of the cToken, the address of the payer, the address of the borrower, the amount of the repayment, and the borrower's index. It then checks if the repayment is valid and if it is, it updates the cToken contract accordingly. (autogenerated documentation)
liquidateBorrowAllowed(address,address,address,address) :
This function is used to check if a liquidation of a borrower's position is allowed. It takes in the address of the cToken being borrowed, the address of the cToken being used as collateral, the address of the liquidator, the address of the borrower, and the amount to be repaid. It first checks if the markets for the cTokens are listed. It then checks the borrower's borrow balance stored in the cToken contract. If the cToken is deprecated, it checks if the amount to be repaid is less than or equal to the total borrow. If the cToken is not deprecated, it checks the borrower's account liquidity and if there is a shortfall. If there is a shortfall, it checks if the amount to (autogenerated documentation)
liquidateBorrowVerify(address,address,address,address) :
This function is used to verify a liquidation of a borrower's debt. It takes in the addresses of the cTokenBorrowed, cTokenCollateral, liquidator, and borrower, as well as the actualRepayAmount and seizeTokens. It then checks to make sure that the maxAssets variable is false, and if it is, the liquidation is verified. (autogenerated documentation)
seizeAllowed(address,address,address,address) :
This function is used to seize tokens from a borrower in order to repay a loan. It requires the addresses of the cTokenCollateral, cTokenBorrowed, liquidator, and borrower, as well as the amount of tokens to be seized. It first checks that the markets for the cTokens are listed, and that the comptroller for both cTokens is the same. It then updates the comptroller's supply index and distributes the supplier compensation to the borrower and liquidator. Finally, it returns an error code indicating whether or not the seizure was successful. (autogenerated documentation)
seizeVerify(address,address,address,address) :
This function is used to verify a seizure of tokens from a borrower by a liquidator. It takes in the addresses of the cToken collateral, cToken borrowed, liquidator, and borrower, as well as the amount of tokens to be seized. It then checks to make sure that the seizure is valid and that the maximum amount of assets is not exceeded. If the seizure is valid, the tokens are seized from the borrower and transferred to the liquidator. (autogenerated documentation)
transferAllowed(address,address,address) :
This function is used to transfer tokens from one address to another. It first checks if the transfer is allowed by calling the redeemAllowedInternal function. If the transfer is allowed, it then updates the supply index and distributes the supplier compensation to both the source and destination addresses. (autogenerated documentation)
transferVerify(address,address,address) :
This function is an override of the transferVerify function in the cToken contract. It is used to verify a transfer of tokens from one address (src) to another (dst). It checks that the amount of tokens being transferred (transferTokens) does not exceed the maximum amount of assets allowed (maxAssets). If the transfer is valid, the function will return true, otherwise it will return false. (autogenerated documentation)
getAccountLiquidity(address) :
This function calculates the liquidity of a given Ethereum account. It does this by calling the getHypotheticalAccountLiquidityInternal function, which takes the address of the account, the address of a cToken, the amount of cToken to borrow, and the amount of cToken to supply as parameters. The function then returns a tuple containing an error code, the liquidity of the account, and the shortfall of the account. (autogenerated documentation)
getAccountLiquidityInternal(address) :
This function is an internal view function that returns the liquidity of a given account. It does this by calling the getHypotheticalAccountLiquidityInternal function, which takes the address of the account, the address of a cToken, the amount of cToken held by the account, and the amount of cToken borrowed by the account. The function then returns an Error, the amount of cToken held by the account, and the amount of cToken borrowed by the account. (autogenerated documentation)
getHypotheticalAccountLiquidity(address,address) :
This function calculates the hypothetical liquidity of an account given a certain set of parameters. It takes an account address, a cToken address, the amount of tokens to redeem, and the amount to borrow as parameters. It then calls the internal function getHypotheticalAccountLiquidityInternal, which returns an error code, the liquidity of the account, and the shortfall. The function then returns the error code, liquidity, and shortfall as a tuple. (autogenerated documentation)
getHypotheticalAccountLiquidityInternal(address) :
This function calculates the hypothetical liquidity of an account given a certain set of parameters. It does this by looping through all of the assets held by the account, calculating the exchange rate, collateral factor, and oracle price for each asset, and then summing up the collateral and borrow balances for each asset. It then adjusts the borrow balance for the cTokenModify asset based on the redeemTokens and borrowAmount parameters, and finally returns the difference between the sum of the collateral balances and the sum of the borrow balances plus effects. (autogenerated documentation)
liquidateCalculateSeizeTokens(address,address) :
This function calculates the amount of tokens that should be seized from a borrower in a liquidation event. It takes in the addresses of the cToken borrowed and the cToken collateral, as well as the actual repay amount, and returns a tuple containing an error code and the amount of tokens to be seized. The function first retrieves the underlying prices of the cTokens from the oracle. If either of the prices is 0, it returns an error code. Otherwise, it calculates the exchange rate mantissa from the cToken collateral and then calculates the ratio of liquidation incentive mantissa to the product of the underlying prices and exchange rate mantissa. Finally, it multiplies this ratio with the actual repay amount to get the (autogenerated documentation)
_setPriceOracle() :
This function allows the admin to set a new PriceOracle. It first checks that the sender is the admin, and then sets the new PriceOracle. Finally, it emits an event to notify that the PriceOracle has been changed. (autogenerated documentation)
_setCloseFactor() :
This function allows the admin to set the close factor of the contract. The close factor is a value used to calculate the closing price of a position. The function takes in a new close factor mantissa as an argument and requires that the sender of the transaction is the admin. It then sets the close factor mantissa to the new value and emits an event with the old and new close factor mantissa values. The function returns an error code indicating that the operation was successful. (autogenerated documentation)
_setCollateralFactor() :
This function allows the admin to set the collateral factor for a given cToken. The collateral factor is a number that represents the amount of collateral held in the cToken contract. The function checks that the admin is authorized to make the change, that the cToken is listed, that the new collateral factor is within the allowed range, and that the cToken has a valid price. If all checks pass, the function updates the collateral factor and emits an event to notify other contracts of the change. (autogenerated documentation)
_setLiquidationIncentive() :
This function allows the admin to set the liquidation incentive mantissa for the contract. The liquidation incentive mantissa is a value that determines the amount of incentive that is given to users who liquidate their positions. The function checks that the caller is the admin, then sets the liquidation incentive mantissa to the new value and emits an event to notify other contracts of the change. (autogenerated documentation)
_supportMarket() :
This function is used to support a new market on the platform. It is called by the admin and takes a CToken as an argument. It checks to make sure that the sender is the admin and that the market is not already listed. It then checks to make sure that the CToken is valid and adds the market to the platform. Finally, it initializes the market and emits an event to signal that the market has been listed. (autogenerated documentation)
_addMarketInternal(address) :
This function adds a given cToken address to the list of allMarkets. It does this by looping through the existing list of allMarkets and ensuring that the given cToken address is not already present. If it is not, the cToken address is added to the list. (autogenerated documentation)
_initializeMarket(address) :
This function initializes the market for a given cToken address. It sets the supplyState and borrowState indices to the compInitialIndex, and sets the block number for both states to the current block number. This ensures that the market is properly initialized and ready to be used. (autogenerated documentation)
_setMarketBorrowCaps() :
This function allows the admin or borrowCapGuardian to set the borrow caps for a given array of cTokens. It requires that the length of the cTokens array and the newBorrowCaps array are the same, and that they are both not empty. It then loops through the cTokens array and sets the borrowCaps mapping to the corresponding newBorrowCaps value. Finally, it emits an event to signal that the borrow caps have been updated. (autogenerated documentation)
_setBorrowCapGuardian(address) :
This function allows the admin to set a new Borrow Cap Guardian. It requires that the msg.sender is the admin, and then sets the new Borrow Cap Guardian address to the one provided as an argument. It then emits an event to signal that the Borrow Cap Guardian has been changed. (autogenerated documentation)
_setPauseGuardian(address) :
This function allows the admin to set a new pause guardian. It first checks that the sender is the admin, and then sets the new pause guardian. Finally, it emits an event to notify of the change. (autogenerated documentation)
_setMintPaused(bool) :
This function allows the pause guardian or the admin to pause or unpause the minting of a cToken. If the cToken is not listed, the function will not execute. If the msg.sender is the pause guardian, the state of the minting will be set to the value of the state parameter. If the msg.sender is the admin, the state of the minting will be set to true (unpaused). The function will then emit an ActionPaused event with the cToken address, the action type ("Mint"), and the state of the minting. Finally, the function will return the state of the minting. (autogenerated documentation)
_setBorrowPaused(bool) :
This function sets the borrow paused state of a given cToken. It requires that the cToken is listed, that the sender is either the pauseGuardian or the admin, and that the sender is the admin if they are attempting to unpause. If these conditions are met, the borrow paused state of the cToken is set to the given state and an ActionPaused event is emitted. The function then returns the given state. (autogenerated documentation)
_setTransferPaused(bool) :
This function sets the transferGuardianPaused state to either true or false. It can only be called by the pauseGuardian or the admin. If the pauseGuardian calls it, the state will be set to true. If the admin calls it, the state can be set to either true or false. If the state is set to true, an ActionPaused event is emitted. The function returns the state that was set. (autogenerated documentation)
_setSeizePaused(bool) :
This function allows the pauseGuardian or the admin to pause or unpause the Seize function. If the pauseGuardian or the admin calls the function with a state of true, the Seize function will be paused. If the admin calls the function with a state of false, the Seize function will be unpaused. The function will emit an ActionPaused event with the name of the function and the state of the pause. The function will then return the state of the pause. (autogenerated documentation)
_become() :
This function is used to change the brains of a Unitroller. It requires that the sender of the message is the admin of the Unitroller and that the Unitroller has authorized the change. If these conditions are met, the brains of the Unitroller will be changed. (autogenerated documentation)
fixBadAccruals() :
This function is used to fix bad accruals for a given set of users. It takes in an array of affected users and an array of amounts to subtract from their accruals. It then loops through the arrays, subtracting the amount from the user's accrual. If the amount to subtract is greater than the user's current accrual, the difference is added to the user's account receivable. Finally, the function sets a boolean to indicate that the fix has been executed. (autogenerated documentation)
() :
This function is used to adjust the accrued compensation of a group of users. It takes in two arrays, one containing the addresses of the affected users and the other containing the amounts to subtract from each user's accrued compensation. It then iterates through the arrays, subtracting the amount from each user's accrued compensation. If the amount to subtract is greater than the user's accrued compensation, the difference is added to the user's account receivable. Finally, an event is emitted for each user to indicate that their accrued compensation has been adjusted. (autogenerated documentation)
adminOrInitializing() :
This function is used to check if the sender of a message is either the admin or the comptrollerImplementation. It returns a boolean value of true if the sender is either the admin or the comptrollerImplementation, and false otherwise. This function is used to ensure that only the admin or the comptrollerImplementation can perform certain actions. (autogenerated documentation)
setCompSpeedInternal() :
This function sets the supply and borrow speeds for a given cToken. It first checks if the cToken is listed in the markets, and then updates the compSupplyIndex and compBorrowIndex accordingly. Finally, it updates the compSupplySpeeds and compBorrowSpeeds and emits the CompSupplySpeedUpdated and CompBorrowSpeedUpdated events. (autogenerated documentation)
updateCompSupplyIndex(address) :
This function updates the Compound Supply Index for a given cToken. It does this by calculating the amount of cToken supply accrued since the last update, based on the cToken's supply speed and the number of blocks that have passed since the last update. This accrued amount is then added to the existing Compound Supply Index, and the block number is updated to the current block number. (autogenerated documentation)
updateCompBorrowIndex(address) :
This function updates the Compound Borrow Index for a given cToken. It takes in the address of the cToken and the current market borrow index as parameters. It first retrieves the Compound Market State for the cToken from the compBorrowState mapping. It then calculates the delta blocks since the last update, and if the delta blocks is greater than 0 and the borrow speed is greater than 0, it calculates the borrow amount, compAccrued, and ratio. It then updates the borrowState index with the new ratio and updates the block number. If the delta blocks is greater than 0 but the borrow speed is 0, it only updates the block number. (autogenerated documentation)
distributeSupplierComp(address,address) :
This function distributes comp tokens to a supplier based on the amount of cTokens they hold. It works by first retrieving the current supply index and the supplier's index from the compSupplyState and compSupplierIndex mappings respectively. It then calculates the difference between the two indices and uses this to calculate the amount of comp tokens the supplier should receive. Finally, it updates the compAccrued mapping with the new amount of comp tokens the supplier has accrued and emits an event to log the distribution. (autogenerated documentation)
distributeBorrowerComp(address,address) :
This function distributes borrower compensation for a given cToken. It takes in the address of the cToken, the address of the borrower, and an Exp memory marketBorrowIndex. It first looks up the CompMarketState storage borrowState for the cToken, and then looks up the borrowerIndex for the borrower. It then calculates the deltaIndex, which is the difference between the borrowIndex and the borrowerIndex. It then calculates the borrowerAmount by dividing the borrowBalanceStored of the borrower by the marketBorrowIndex. It then calculates the borrowerDelta by multiplying the borrowerAmount by the deltaIndex. Finally, it adds the borrowerDelta to the compAccrued of the borrower and emits a DistributedBorrowerComp event (autogenerated documentation)
updateContributorRewards(address) :
This function updates the rewards for a given contributor. It takes the address of the contributor as an argument and then calculates the amount of rewards they should receive based on the number of blocks since their last reward and their contribution speed. It then adds this amount to the total amount of rewards they have accrued and updates the last block number for the contributor. (autogenerated documentation)
claimComp(address) :
This function allows a user to claim a company's shares from all markets. It takes an address of the holder as an argument and returns the claimComp function with the holder's address and allMarkets as arguments. The claimComp function will then check the holder's address against the list of markets and if it matches, the holder will be able to claim the company's shares. (autogenerated documentation)
claimComp(bool,bool) :
This function is used to distribute COMP tokens to holders of cTokens. It takes in an array of addresses (holders), an array of cTokens, and two boolean values (borrowers and suppliers). If the borrowers boolean is true, it will update the borrow index for each cToken and distribute COMP tokens to each holder based on the borrow index. If the suppliers boolean is true, it will update the supply index for each cToken and distribute COMP tokens to each holder based on the supply index. Finally, it will grant COMP tokens to each holder based on the accrued COMP tokens. (autogenerated documentation)
grantCompInternal(address) :
This function grants a user a specified amount of Comp tokens from the contract's own balance. It takes in two parameters, an address of the user to receive the tokens and the amount of tokens to be granted. It first checks if the amount is greater than 0 and less than or equal to the contract's remaining balance of Comp tokens. If so, it transfers the specified amount of tokens to the user's address and returns 0. Otherwise, it returns the amount. (autogenerated documentation)
_grantComp(address) :
This function allows an admin to grant a specified amount of "comp" to a specified address. It first checks that the caller is an admin or is in the process of initializing the contract. It then calls the internal function grantCompInternal, which deducts the specified amount from the total comp available and adds it to the recipient's balance. If the amount of comp available is insufficient, the function will fail. Finally, it emits an event to notify that the comp has been granted. (autogenerated documentation)
_setCompSpeeds() :
This function allows an admin to set the supply and borrow speeds for a given array of cTokens. The function requires that the length of the cTokens array, the supplySpeeds array, and the borrowSpeeds array are all equal. It then iterates through each of the cTokens and sets the corresponding supply and borrow speeds for each one. (autogenerated documentation)
_setContributorCompSpeed(address) :
This function allows an admin to set the comp speed of a contributor. The comp speed is a measure of how quickly a contributor will receive rewards for their contributions. The function takes in an address of the contributor and a uint value for the comp speed. It first checks that the caller is an admin or is initializing. It then updates the rewards for the contributor and sets the comp speed. If the comp speed is set to 0, the last contributor block is deleted. Otherwise, the last contributor block is set to the current block number. Finally, the compContributorSpeeds mapping is updated with the new comp speed and an event is emitted. (autogenerated documentation)
getAllMarkets() :
This function is a public view function that returns an array of all the CTokens stored in the allMarkets array. It does not modify any state variables and does not require any input parameters. (autogenerated documentation)
isDeprecated() :
This function checks whether a given cToken is deprecated. It does this by checking three conditions: whether the collateral factor mantissa is 0, whether the borrow guardian is paused, and whether the reserve factor mantissa is equal to 1e18. If all three conditions are true, the function returns true, indicating that the cToken is deprecated. (autogenerated documentation)
getBlockNumber() :
This function returns the current block number of the Ethereum blockchain. It works by accessing the block object, which contains information about the current block, and then returning the block number. (autogenerated documentation)
getCompAddress() :
This function is a public view function that returns the address of a company. It works by returning the address of the company stored in the function. (autogenerated documentation)

Get Cookin'
share iconShare

copy iconDownload Source
copy iconnpx cookbookdev i comptroller
copy icon

Recent Use

🍞 0x0759 downloaded

Last Publish

10/26/2022

Version

1.0.0

Creator

compound

Cookbook is free.
Any contract you deploy is yours.
Your contract is owned and controlled by you.