Collateral Vault
This contract is the collateral vault contract that all borrowers on Twyne interact with. In Twyne v1, every collateral vault has a single owner. Many functions in the collateral vault can be called only by the vault owner. This limits the ability for anyone else to interact with the vault, enhancing the security of the user’s collateral assets.
It isn’t ERC20 or ERC4626 compliant, partially the current design requires a single owner of vault value, meaning the vault shares must be non-transferrable. Correctness is maintained through our invariants, explained in more detail in the mechanics section.
Function Calls
Borrowers can deposit and withdraw collateral, borrow and repay their debt from the external lending protocol.
Deposit collateral
Euler collateral vaults have assets like eWETH (yield bearing, Euler wrapped WETH) as collateral. To deposit these assets, use:
/// @notice Deposits a certain amount of assets for a receiver.
/// @param assets The assets to deposit.
function deposit(uint assets) external;To deposit the underlying asset (like WETH), use:
/// @notice Deposits a certain amount of underlying asset for a receiver.
/// @param underlying The underlying assets to deposit.
function depositUnderlying(uint underlying) external;This function first trasfers the underlying asset, converts it to the corresponding Euler wrapped asset and then registers it as collateral.
Withdraw collateral
To withdraw your collateral, use:
In case you want to receive the underlying asset, use:
Note that, you still specify the amount of collateral (which is eWETH in our running example). The contract will remove that amount as collateral, convert it to the underlying asset, and transfer all the redeemed underlying asset to receiver.
Borrow
Each collateral vault can only borrow a single asset called target asset. To borrow that target asset, use:
Repay
Liquidate
Liquidating a collateral vault is a multi-step process.
Call
liquidate()which sets the collateral vault’sborrowervariable to the caller:This essentially transfers the entire position from the borrower to the liquidator, hence liquidator becomes the new borrower.
In the same batch, the liquidator has to make the position healthy, either by depositing more collateral, repaying some debt, or both.
The liquidator will likely unwind the position completely for profit, but it isn’t mandated by the protocol.
Handle external liquidation
Collateral vault is a borrower w.r.t. external lending protocol. In case, the liquidation doesn’t happen on Twyne and the external debt position keeps deteriorating, the external lending protocol will liquidate the collateral vault.
Once this happens, the following function needs to be called to process this external liquidation on that collateral vault:
In a nutshell, this process unwinds the entire position, distributes the collateral asset balance of the collateral vault among relevant parties, and then shuts down.
In some cases, this process may be create some bad debt for the intermediate vault as described as the exception scenario in credit vault doc.
To settle the bad debt, call intermediateVault.liquidate(...) as follows:
Last updated

