CMPVault
Initialization
constructor
Description
The constructor initializes the CMPVault contract, setting up the initial parameters required.
Parameters
asset_
: Instance of the ERC20 token (Tether Gold - XAUT) used as collateral to mint aUSDT.data
: Encoded data containing essential parameters required for the contract initialization.
Functionality
Asset Initialization: Sets the
asset
variable to the specified ERC20 token instance.Decoding Parameters: Decodes the input
data
to extract the following parameters:collateral
: Instance of the collateral token (Tether Gold - XAUT) used.oracle
: Oracle contract address.LIQUIDATION_MULTIPLIER
: Multiplier used in determining the liquidation threshold.COLLATERALIZATION_RATE
: Rate at which collateralization must be maintained.MINT_OPENING_RETURN_FEE
: Fee charged for mint and return.
Usage
The constructor is called during the deployment of the CMPVault contract. It initializes the necessary parameters for the functioning of the contract and disables further initializers by calling _disableInitializers()
.
initialize
Description
The initialize
function further initializes the contract after deployment, setting additional parameters and executing specific actions required for functionality.
Parameters
oracleData_
: Empty memory bytes.interest
: The chosen interest rate.
Functionality
Ownership Initialization: Initializes ownership through the
__Ownable_init()
function.Interest: Updates the
accrueInfo.interest
variable.Mint Limit Setup: Sets the
mintLimit
to the maximum allowed value.Blacklist Callees: Adds the contract's own address, collateral token address, and asset token address to the
blacklistedCallees
to prevent recursive calls.Fetching Exchange Rate: Retrieves the current exchange rate from the Oracle contract.
Accrue Function Call: Executes the
accrue()
function to initialize certain internal values.
Usage
This function is called after the contract deployment to set up additional parameters and perform initial actions required for the contract's functionality.
Write Methods
accrue
Description
This function is responsible for calculating and accruing interest on outstanding mintings.
Emits
updateExchangeRate
Description
Updates the exchange rate (see oracle).
Returns
Name | Type | Description |
---|---|---|
updated |
| A boolean indicating whether the exchange rate update was successful. |
rate |
| The latest exchange rate fetched from the oracle smart contract. |
Emits
addCollateral
Description
Adds a share
amount of collateral token to to
.
Your smart contract must approveaddress(this)
to transfer the shares:
Parameters
Name | Type | Description |
---|---|---|
to |
| The receiver of the collateral tokens. |
share |
| The amount of tokens to add. |
Emits
removeCollateral
Description
Removes a share
amount of collateral token from msg.sender
.
Parameters
Name | Type | Description |
---|---|---|
to |
| The receiver of the collateral tokens. |
share |
| The amount of tokens to remove. |
Emits
mint
Description
Mints an amount
of asset tokens.
Parameters
Name | Type | Description |
---|---|---|
to |
| The receiver of the asset tokens. |
amount |
| The amount of asset tokens to mint. |
Returns
Name | Type | Description |
---|---|---|
part |
| The mint part held by the user. |
share |
| Warning: this value is always set to 0. |
Emits
returning
Description
Returns a loan.
Parameters
Name | Type | Description |
---|---|---|
to |
| The address for which to return the loan. |
part |
| The amount to return (see userMintPart). |
Returns
Name | Type | Description |
---|---|---|
amount |
| The amount of asset tokens that has been returned. |
Emits
manage
Description
Executes a set of actions and allows composability (contract calls) to other contracts.
The manage 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 values
array the ether value of a call may be defined.
Whereas calling functions like mint that have the solvent modifier requires solvency at the end of the function, solvency only needs to be guaranteed at the end of the manage 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 USEVALUE1 (-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 manage call.
The call data for the actions is ABI encoded as listed below.
Action | ID | Parameters | ABI encoding | value1 | value2 |
---|---|---|---|---|---|
Update exchange rate | 11 | must_update, minRate, maxRate | bool, uint256, uint256 | - | - |
Add collateral | 10 | share, to | int256, address | - | - |
Remove collateral | 4 | share, to | int256, address | - | - |
Mint | 5 | amount, to | int256, address | part | share |
Return | 2 | part, to | int256, address | - | - |
Get return amount | 6 | part | int256 | amount | - |
Get return part | 7 | amount | int256 | part | - |
Liquidate | 31 | users, maxMintParts, to, swapper, swapperData | address[], uint256[], address, ISwapperV2, bytes | - | - |
Call | 30 | callee, callData, useValue1, useValue2, returnValues | address, bytes, bool, bool, uint8 | Depends on the contract call. | Depends on the contract call. |
Parameters
Name | Type | Description |
---|---|---|
actions |
| An array containing the sequence of actions to execute (IDs) |
values |
| The ETH amount to send along with each action (one-to-one mapping). |
data |
| The ABI encoding containing the function arguments for each action (one-to-one mapping). |
Returns
Name | Type | Description |
---|---|---|
value1 |
| The first return value (may be unset depending on the last action). |
value2 |
| The second return value (may be unset depending on the last action). |
liquidate
Description
Handles the liquidation of users' balances, once the users' amount of collateral is too low.
Parameters
Name | Type | Description |
---|---|---|
users |
| An array of user addresses. |
maxMintParts |
| A one-to-one mapping to |
to |
| Address of the receiver in open liquidations if |
swapper |
| Contract address of the |
swapperData |
| The ABI encoding to pass to the swap function |
Emits
withdrawFees
Description
Transfers all available fees to feeTo.
Emits
setFeeTo
Description
Allows owner to change the recipient of the fees.
Parameters
Name | Type | Description |
---|---|---|
newFeeTo |
| The new recipient (see feeTo). |
Emits
reduceSupply
Description
Reduce the available supply of asset tokens.
Parameters
Name | Type | Description |
---|---|---|
amount |
| The amount of asset tokens to remove from the contract's supply. |
changeInterestRate
Description
Allows owner to change the interest rate.
Parameters
Name | Type | Description |
---|---|---|
newInterestRate |
| The new interest rate. |
Emits
changeMintLimit
Description
Allows owner to change the mint limit.
Parameters
Name | Type | Description |
---|---|---|
newMintLimit |
| The mint limit. |
perAddressPart |
| The mint limit per user address. |
Emits
changePermissionControl
Description
Allows owner to change the permission control contract.
Parameters
Name | Type | Description |
---|---|---|
newPermissionControl |
| The new permission control contract (see permissionControl). |
Emits
setBlacklistedCallee
Description
Allows owner to:
add a callee to the blacklist.
remove a callee from the blacklist.
Parameters
Name | Type | Description |
---|---|---|
callee |
| The callee's address. |
blacklisted |
| The status to set to |
Emits
View Methods
asset
Description
The ERC20 token the users can mint.
collateral
Description
The ERC20 token that acts as collateral to mint asset tokens.
userMintPart
Description
Maps each user to its total debt (i.e. its mint part).
You can convert this number into a numerical amount of asset tokens with:
userCollateralAmount
Description
Maps each user to its amount of collateral tokens.
totalMint
Description
Represents the total loan held by minters.
Properties
Name | Type | Description |
---|---|---|
elastic |
| The total amount of asset tokens held by minters. |
base |
| The total amount of mint parts held by minters. |
totalCollateralAmount
Description
The total amount of collateral tokens.
feeTo
Description
The recipient that will receive the fees.
oracle
Description
The oracle from which to fetch the exchange rate.
oracleData
Description
The ABI encoding to pass to the oracle get function.
blacklistedCallees
Description
If an address maps to true all manageCall
actions to its functions are forbidden.
accrueInfo
Description
Some data about the accrue function.
Properties
Name | Type | Description |
---|---|---|
lastAccrued |
| The timestamp of the last accrue call. |
feesEarned |
| The fees earned between the last withdrawal and the last accrue call. |
interest |
| The accrued interest. |
permissionControl
Description
See PermissionControl.
mintLimit
Description
The current mint limit (in mint parts).
Properties
Name | Type | Description |
---|---|---|
total |
| The mint limit on the total amount of asset tokens in the contract's balance. |
mintPartPerAddress |
| The mint limit per user address. |
COLLATERALIZATION_RATE
Description
The collateralization rate (i.e. maximum % mintable with current collateral).
LIQUIDATION_MULTIPLIER
Description
The liquidation multiplier.
MINT_OPENING_RETURN_FEE
Description
The mint/return fee.
Modifiers
onlyWhitelisted
Description
Checks if user
is present in the whitelist.
Parameters
Name | Type | Description |
---|---|---|
user |
| The address to check. |
onlyLiquidators
Description
Checks if liquidator
is a liquidator.
Parameters
Name | Type | Description |
---|---|---|
liquidator |
| The address to check. |
solvent
Description
Checks if msg.sender
is solvent after executing the function body.
Events
LogAccrue
Parameters
Name | Type | Index? |
---|---|---|
accruedAmount |
| No |
LogExchangeRate
Parameters
Name | Type | Index? |
---|---|---|
rate |
| No |
LogAddCollateral
Parameters
Name | Type | Index? |
---|---|---|
from |
| Yes |
to |
| Yes |
share |
| No |
LogRemoveCollateral
Parameters
Name | Type | Index? |
---|---|---|
from |
| Yes |
to |
| Yes |
share |
| No |
LogMint
Parameters
Name | Type | Index? |
---|---|---|
from |
| Yes |
to |
| Yes |
amount |
| No |
part |
| No |
LogReturn
Parameters
Name | Type | Index? |
---|---|---|
from |
| Yes |
to |
| Yes |
amount |
| No |
part |
| No |
LogLiquidation
Parameters
Name | Type | Index? |
---|---|---|
from |
| Yes |
user |
| Yes |
to |
| Yes |
collateralAmount |
| No |
mintAmount |
| No |
mintPart |
| No |
LogWithdrawFees
Parameters
Name | Type | Index? |
---|---|---|
feeTo |
| Yes |
feesEarnedFraction |
| No |
LogFeeTo
Parameters
Name | Type | Index? |
---|---|---|
newFeeTo |
| Yes |
LogInterestChange
Parameters
Name | Type | Index? |
---|---|---|
oldInterestRate |
| No |
newInterestRate |
| No |
LogChangeMintLimit
Parameters
Name | Type | Index? |
---|---|---|
newLimit |
| No |
perAddressPart |
| No |
LogChangeBlacklistedCallee
Parameters
Name | Type | Index? |
---|---|---|
account |
| Yes |
blacklisted |
| No |
LogChangePermissionControl
Parameters
Name | Type | Index? |
---|---|---|
newPermissionControl | PermissionControl | Yes |
Last updated