IVaultHandler
Abstract Contract in charge of handling the collateral and the minting of the TCAP Token.
Code
Address
Mainnet
Normal Mode Vault
Contract | Address |
---|---|
ETH VaultHandler | 0x717170b66654292dfbd89c39f5ae6753d2ac1381 |
DAI VaultHandler | 0x443366a7a5821619d8d57405511e4fadd9964771 |
Hard Mode Vaults
Contract | Address |
---|---|
ETH VaultHandler | 0xc2Ba6B8E0EE3cf48B045D966F1dCda767df74833 |
DAI VaultHandler | 0xA5b3Bb6e1f206624B3B8CE0c6A0f7614fd35Fa03 |
USDC VaultHandler | 0xa8CcA36A624215a39D5af6854ac24868559424d3 |
WBTC VaultHandler | 0x2364536F4891Ed560A6728f4B36871de8176eE5c |
Rinkeby
Contract | Address |
---|---|
ETH VaultHandler | 0x16Ab98d9B7753D6c5da7c29Db6E3d51Abc76BE35 |
DAI VaultHandler | 0x8eD3A1A6221c9B6DA1Af4F21dD98646137bCa5ad |
ERC165 Introspection
The computed interface ID according to ERC-165. The interface ID is a XOR of all interface method selectors.
Vault
Vault object created to manage the mint and burns of TCAP tokens with the following variables:
- Id: unique identifier of the vault.
- Collateral: current collateral on vault.
- Debt: current amount of TCAP tokens minted.
- Owner: owner of the vault.
Public Variables
Vault Id counter.
TCAP Token Address.
Total Market Cap/USD Oracle Address.
Collateral Token Address.
Collateral/USD Oracle Address.
ETH/USD Oracle Address.
Value used as divisor with the total market cap, just like the S&P 500 or any major financial index would to define the final tcap token price.
Minimun ratio required to prevent liquidation of vault.
Fee percentage of the total amount to burn charged on ETH when burning TCAP Tokens.
Penalty charged to vault owner when a vault is liquidated, this value goes to the liquidator.
Address of the contract that gives rewards to minters of TCAP, rewards are only given if address is set before minting.
Address of the treasury multisign contract that allows the multisign to control the rewards and funds generated by the protocol.
Owner address to Vault Id mapping.
Id To Vault mapping.
Value used to multiply chainlink oracle for handling decimals.
Minimum value that the ratio can be set to.
Maximum value that the burn fee can be set to.
Private Variables
The computed interface ID according to ERC-165. Indicates if this contract supports the vault handler functions.
The computed interface ID according to ERC-165. Indicates if this contract supports the timelock functions.
The computed interface ID according to ERC-165. Indicates if this contract supports the ERC165 interface.
Events
Events are called each time the state changes on the contract.
An event emitted when the ratio is updated.
An event emitted when the burn fee is updated.
An event emitted when the liquidation penalty is updated.
An event emitted when the treasury contract is updated.
An event emitted when a vault is created.
An event emitted when collateral is added to a vault.
An event emitted when collateral is removed from a vault.
An event emitted when tokens are minted.
An event emitted when tokens are burned.
An event emitted when a vault is liquidated.
An event emitted when a erc20 token is recovered.
Modifiers
vaultExists
Throws if vault hasn't been created.
notZero
Throws if value is 0.
Read-Only Functions
supportsInterface
ERC165 Standard for support of interfaces.
getVault
Returns the Vault information of specified _id
.
getOraclePrice
Returns the price of the chainlink oracle multiplied by the digits to get 18 decimals format.
TCAPPrice
Returns the price of the TCAP token in 18 decimals. The formula for calculating the price is:
=
Where
= TCAP Token Price
= Total Crypto Market Cap
= Divisor
The oracle Total Crypto Market Cap is in wei format.
requiredCollateral
Returns the minimal required collateral to mint TCAP token. The formula for calculating the required collateral is:
=
Where
= Required Collateral
= TCAP Token Price
= Amount to Mint
= Collateral Price
It's divided by 100 as eth price comes in wei to cancel the additional 0s
requiredLiquidationTCAP
Returns the minimal required TCAP to liquidate a Vault. The formula for calculating the required collateral is:
=
=
Where
= Required Liquidation Collateral
= Vault Debt
= Required Collateral
= TCAP Token Price
= Collateral Price
= Min Vault Ratio
= Liquidation Penalty
liquidationReward
Returns the reward for liquidating a vault, the reward is taken from the collateral staked on the liquidated vault. The formula for calculating the reward is:
=
Where
= Liquidation Reward
= Required Liquidation TCAP
= Liquidation Penalty
getVaultRatio
Returns the Collateral Ratio fo the Vault. The formula for calculating the ratio is:
=
Where
= Vault Ratio
= Vault Collateral
= Collateral Price
= Vault Debt
= TCAP Token Price
getFee
Returns the required fee of ETH to burn the TCAP tokens. The formula for calculating the burning fee is:
=
= Burn Fee Value
= TCAP Token Price
= Amount to Burn
= Burn Fee %
= ETH Price
State-Changing Functions
constructor
Called once the contract it's deployed, sets the orchestrator as owner. It also sets the vault counter to 1 as 0 is reserved for empty objects.
setRatio
Sets the collateral ratio needed to mint tokens. Only owner can call it.
setBurnFee
Sets the burn fee percentage an user pays when burning tcap tokens
setLiquidationPenalty
Sets the liquidation penalty % charged on liquidation. Only owner can call it. recommended value is between 1-15% and can't be above 100%.
setTreasury
Sets the treasury contract address where fees are transfered to. Only owner can call it
createVault
Allows sender to creates a Vault with an unique ID. Only one vault per address can be created.
addCollateral
Adds collateral to vault,_amount
should be higher than 0.
removeCollateral
Allows users to remove collateral currently not being used to generate TCAP tokens from their vaults. _amount
should be higher than 0. Reverts if the resulting ratio is less than the minimun ratio.
mint
Uses collateral to generate debt on TCAP Tokens which are minted and assigend to caller. _amount
should be higher than 0. Requires to have a vault ratio above the minimum ratio.
burn
Pays the debt of TCAP tokens resulting them on burn, this releases collateral up to minimun vault ratio._amount
should be higher than 0. A fee on ETH must be paid when executing a TCAP burn, the fee is a % defined by the contract burnFee
of the _amount
of TCAP tokens to burn. The fee goes to the treasury contract. if reward handler is set exit rewards.
liquidateVault
Allow users to burn TCAP tokens to liquidate vaults with current vault collateral ratio
under the minium ratio, the liquidator receives the staked collateral of the liquidated vault at a premium.Resulting ratio must be above or equal minimun ratio. The fee goes to the treasury contract.
pause
Allows the owner to Pause the Contract.
unpause
Allows owner to Unpause the Contract.
recoverERC20
Added to support recovering LP Rewards from other systems such as BAL to be distributed to holders.
safeTransferETH
Allows the safe transfer of ETH.
_burn
Internal function that burns the _amount
of TCAP Tokens, called by the burn and liquidateVault functions.