From 2324d385b4f4549d4f3625e3f2ae8b715ea85ac1 Mon Sep 17 00:00:00 2001 From: Kerber0x Date: Mon, 20 May 2024 17:08:28 +0100 Subject: [PATCH] docs(vault-manager): add readme for vault manager --- .../liquidity_hub/vault-manager/README.md | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/contracts/liquidity_hub/vault-manager/README.md b/contracts/liquidity_hub/vault-manager/README.md index 6460cda1f..e8d88fffe 100644 --- a/contracts/liquidity_hub/vault-manager/README.md +++ b/contracts/liquidity_hub/vault-manager/README.md @@ -1,4 +1,42 @@ # Vault Manager -The Vault Manager is the V2 iteration of the original WW vault network. This is a monolithic contract that handles all -the vaults and flashloans in the White Whale DEX. \ No newline at end of file +The Vault Manager is the V2 iteration of the original White Whale vault network. This is a monolithic contract that +handles all the vaults and flashloans on the Migaloo DEX. + +Vaults are single collateral pools used primarily by bots to take arbitrage opportunities across different AMMs via +flashloans. Flashloans have fees that are distributed among the users that have deposited into the vault where the +flashloan originated, and the users who bond assets on the Bonding Manager. + +## How it works + +The following is a high-level overview of how the Vault Manager works. It touches on some technical details, assisting +developers in understanding the contract's inner workings, while also providing a general understanding of the contract's +functionality, so a regular user can understand how to interact with it. + +### Vault Creation + +Creating vaults is a simple and permissionless process. A user can call the `CreateVault` message, with the desired vault +parameters together with the vault creation fee. The vault creation fee is a protocol fee that is sent to the Bonding +Manager. There can be multiple vaults for the same asset, but each vault must have a unique identifier. Vaults cannot be +removed or updated once created, so it is important to get the parameters right from the start. + +### Deposits and Withdrawals + +Users can deposit and withdraw assets from the vaults at any time. The assets are stored in the vault's balance, and they +are used to provide liquidity to the arbitrage bots. + +### Flashloans + +Flashloans are a powerful tool that allows bots and users to borrow assets from the vault without any collateral, with +the condition that the assets plus the flashloan fees are returned within the same transaction, otherwise the transaction +is reverted as if nothing had happened. + +A flashloan can be taken by calling the `FlashLoan` message, with the desired amount, vault identifier and the payload. +The payload is a list of messages that will be executed in the same transaction, and it doesn't need to include the "payback" +transaction as it is handled by the contract. + +When a flashloan is taken, a boolean in the state is set to true on `ONGOING_FLASHLOAN`, so the funds can't be used to +be deposited back into a vault or to take another flashloan. After the payload is executed, the `CallbackMsg::AfterFlashloan` +is called. This makes sure the funds are back in the vault plus the fees. The profit made from the payload operations is +sent back to the originator of the flashloan. The Bonding Manager receives the protocol fees via the `FillRewards` message +and the users that have deposited into the vault where the flashloan was taken from receive the flashloan fees.