Cauldron V2
Second version of the cauldrons, which changed the way fees and liquidations are accounted. The way the user interacts with it hasn't changed and no new functions were introduced.
It is deployed directly and then used as a masterContract to deploy each market, as clones, following the minimal proxy pattern.
You can find the full contract here.
constructor nonpayable (address)
This will create the masterContract that will be used by all the clones (markets).
Parameter | Description |
---|---|
bentoBox_ | The address of the BentoBox |
magicInternetMoney_ | The address of MIM. |
Write Functions
accrue
Accrues the interest on the borrowed tokens and handles the accumulation of fees.
updateExchangeRate
Gets the exchange rate, ie how much collateral to buy 1e18 asset. Invoked if needed since Oracle queries can be expensive.
Returns
Name | Type | Description |
---|---|---|
| bool | boolean determining if the exchange rate has been updated yet or not |
| uint256 | the new exchange rate that was fetched |
addCollateral
Adds share
amount of collateral from msg.sender
to the account to
.
Parameters
Name | Type | Description |
---|---|---|
| address | receiver of the tokens |
| bool | True if the amount should be skimmed from the deposit balance of msg.sender.
False if tokens from msg.sender in |
| uint256 | amount of shares to add for |
removeCollateral
Calls _removeCollateral
, which removes the amount share
of collateral and transfers it to the account to
.
Parameters
Name | Type | Description |
---|---|---|
| address | receiver of the shares |
| uint256 | amount of shares to send |
borrow
Calls _borrow
, which allows the sender to borrow amount
and transfer to to
.
Parameters
Name | Type | Description |
---|---|---|
| address | receiver of the borrowed assets |
| uint256 | amount of assets to borrow |
Returns
Name | Type | Description |
---|---|---|
| uint256 | total part of debt held by borrowers |
| uint256 | total amount in shares borrowed |
repay
Calls _repay
, which repays a loan.
Parameters
Name | Type | Description |
---|---|---|
| address | address of user payment should go to |
| bool | true if amount should be skimmed from the deposit balance of msg.sender |
| uint256 | amount to repay |
Returns
Name | Type | Description |
---|---|---|
| uint256 | total amount repayed |
cook
Executes a set of actions and allows composability (contract calls) to other contracts.
The cook function allows to bundle functionality within one contract call while passing return values from one call to the next one. Actions are defined by a numeric identifier and can return two values, value1 and value2 to the next function. The input arrays actions, values and datas define the sequential actions. In the Value array the ether value of a call may be defined.
Whereas calling functions like borrow that have the solvent modifier requires solvency at the end of the function, solvency only needs to be guaranteed at the end of the cook function, thereby allowing more complicated operations such as leveraging within one call.
For certain parameters either an external value can be passed in or the identifier USE_VALUE1 (-1) or USE__VALUE2 (-2) to access either of the local variables. The following variables are marked in bold italic in the table below. If an action returns one value it is saved as value1, if two are returned they are saved as value1 and value2 respectively. Any action can access these values during the whole duration of the cook call.
The call data for the actions is ABI encoded as listed below.
Action Name | ID | parameter names | ABI encoding | returnValues |
---|---|---|---|---|
ACTION_REPAY | 2 | share, to, skim | int256, address, bool | |
ACTION_REMOVE_COLLATERAL | 4 | fraction, to | int256, address | |
ACTION_BORROW | 5 | amount, to | int256, address | part, share |
ACTION_GET_REPAY_SHARE | 6 | part | int256 | |
ACTION_GET_REPAY_PART | 7 | amount | int256 | |
ACTION_ACCRUE | 8 | |||
ACTION_ADD_COLLATERAL | 10 | share, to, skim | int256, address, bool | |
ACTION_UPDATE_EXCHANGE_RATE | 11 | must_update, minRate, maxRate | bool, uint256, uint256 | |
ACTION_BENTO_DEPOSIT | 20 | token, to, amount, share | IERC20, address, int256, int256 | amountOut, shareOut |
ACTION_BENTO_WITHDRAW | 21 | token, to, amount, share | IERC20, address, int256, int256 | amountOut, shareOut |
ACTION_BENTO_TRANSFER | 22 | token, to, share | IERC20, address, int256 | |
ACTION_BENTO_TRANSFER_MULTIPLE | 23 | token, tos, shares | IERC20, address[], uint256[] | |
ACTION_BENTO_SETAPPROVAL | 24 | user, _masterContract, approved, v, r, s | address, address, bool, uint8, bytes32, bytes32 | |
ACTION_CALL | 30 | callee, callData, useValue1, useValue2, returnValues | address, bytes, bool, bool, uint8 |
Parameters
Name | Type | Description |
---|---|---|
| uint8[] | array with sequence of actions to execute |
| uint256[] | one-to-one mapped array to |
| bytes[] | one-to-one mapped array to |
Returns
Name | Type | Description |
---|---|---|
| uint256 | may contain first positioned return value of last executed action (if applicable) |
| uint256 | may contain second positioned return value of last executed action which returns 2 values (if applicable) |
liquidate
Handles the liquidation of users' balances once the users' amount of collateral is too low.
Parameters
Name | Type | Description |
---|---|---|
| address[] | array of user addresses |
| uint256[] | one-to-one mapping to |
| address | address of the receiver in open liquidations if |
| ISwapper | contract address of the |
withdrawFees
Withdraw the fees accumulated to the feeTo address.
setFeeTo
Sets the beneficiary of fees accrued in liquidations. Can only be called by the owner of the contract.
Parameters
Name | Type | Description |
---|---|---|
| address | address of the beneficiary |
reduceSupply
Reduces the supply of MIM
Parameters
Name | Type | Description |
---|---|---|
amount | uint256 | amount to reduce supply by (in native representation) |
View Functions
BORROW_OPENING_FEE
Returns the opening fee (charged instantly, added to user debt upon borrowing) in Basis Points.
COLLATERIZATION_RATE
Returns the Collateralization Rate (maximum % borrowable with this collateral) in Basis Points. eg: 75000 = 75%
LIQUIDATION_MULTIPLIER
Returns the liquidation fee in Basis Points. eg: 112000 would add 12% (it's a multiplier, so the value is 112%)
accrueInfo
Return values
Name | Type | Description |
---|---|---|
lastAccrued |
| Timestamp of the last accrue() call. |
feesEarned |
| Fees accrue between the last withdrawal and the last accrue. |
INTEREST_PER_SECOND |
|
bentoBox
Return values
Name | Type | Description |
---|---|---|
/ |
| Address of the bentoBox the cauldron is deployed on. Set by constructor of masterContract |
collateral
Return values
Name | Type | Description |
---|---|---|
/ |
| Address of the collateral used by this cauldron. |
exchangeRate
Return values
Name | Type | Description |
---|---|---|
/ |
| Current cached exchange rate. |
feeTo
Return values
Name | Type | |
---|---|---|
/ |
| Recipient of the Fees (controlled by masterContract, which is why regular cauldrons have a feeTo zero address) |
magicInternetMoney
Return values
Name | Type | Description |
---|---|---|
/ |
| Address of MIM, set by constructor of masterContract |
masterContract
Return values
Name | Type | Description |
---|---|---|
/ |
| masterContract address. |
oracle
Return values
Name | Type | Description |
---|---|---|
/ |
| Oracle Address. |
oracleData
Return values
Name | Type | Description |
---|---|---|
/ |
| Oracle data used to query it. |
owner
Return values
Name | Type | |
---|---|---|
/ |
| Owner of the Cauldron (controlled by masterContract, which is why regular cauldrons have zeroAddress as an owner). |
pendingOwner
When transferring ownership, the future owner is pending until they claims ownership.
Return values
Name | Type | Description |
---|---|---|
/ |
| Address of the pending owner. |
totalBorrow
Returns the total amounts borrowed from the cauldron.
Return values
Name | Type | Description |
---|---|---|
elastic |
| Amount of MIM borrowed by users. |
base |
| Amount of borrowParts held by users. |
totalCollateralShare
Returns the amount (in shares) of the token collateral
used as collateral in this cauldron.
Return values
Name | Type | Description |
---|---|---|
/ |
| Amount of shares of collateral deposited into the Cauldron. |
userBorrowPart
Returns the amount of borrowParts held by a user. To convert that amount into a numerical MIM debt amount, you must do totalBorrow.elastic / totalBorrow.base * borrowParts.
Parameters
Name | Type | Description |
---|---|---|
/ |
| User address. |
Return values
Name | Type | Description |
---|---|---|
/ |
| Amount of borrowParts held. |
userCollateralShare
Amount (in shares) of the token collateral
used as collateral by the user.
Parameters
Name | Type | Description |
---|---|---|
/ |
| User address. |
Return values
Name | Type | Description |
---|---|---|
/ |
| Shares of collateral deposited. |
Last updated