|
| 1 | +# FCM Architecture |
| 2 | + |
| 3 | +This repo implements an [ERC4626](https://eips.ethereum.org/EIPS/eip-4626)-compliant vault which implements a levered investment with automated rebalancing. |
| 4 | + |
| 5 | +## Terminology |
| 6 | +- **Asset** - ERC4626 term meaning "the unit of account of this vault". Deposits, withdrawals, and NAV for a vault are denominated in the vault's asset. The asset must be an ERC20 token. |
| 7 | + - **InnerAsset/OuterAsset** - The asset of the inner vault or outer vault, respective (see below) |
| 8 | +- **Share** - ERC4626 term meaning "a portion of the total assets in this vault". Shares are fungible and are represented as ERC20 tokens. Vault users deposit assets and receive shares. |
| 9 | + - **InnerShare/OuterShare** - The share of the inner vault or outer vault, respective (see below) |
| 10 | +- **Outer Vault** - The ERC4626 vault implemented in this repository, which borrows against deposits to invest in an inner vault. |
| 11 | +- **Inner Vault** - The ERC4626 vault which the outer vault invests borrowing proceeds in. |
| 12 | + |
| 13 | +## Dependencies |
| 14 | +### Lending Protocol |
| 15 | +[Morpho Blue](https://github.com/morpho-org/morpho-blue) |
| 16 | + |
| 17 | +### Automated Market Maker |
| 18 | +[FlowSwap (Uniswap v3)](https://flowswap.io/) |
| 19 | + |
| 20 | +### Inner Vault |
| 21 | +[Morpho Vault v2](https://docs.morpho.org/build/earn/concepts/vault-mechanics) |
| 22 | + |
| 23 | +NOTE: Morpho Vault v2 has [unconventional behaviour on some ERC4626 view functions](https://github.com/morpho-org/vault-v2#erc-4626-compliance): |
| 24 | +> The vault has a non-conventional behaviour on max functions (maxDeposit, maxMint, maxWithdraw, maxRedeem): they always return zero. |
| 25 | +
|
| 26 | +**Liquidity:** Morpho Vault v2 does not guarantee that withdrawals can be satisfied, depending on liquidity conditions. However, it provides a [`forceDeallocate`](https://docs.morpho.org/get-started/resources/contracts/morpho-vaults-v2/#forcedeallocate) method which can be used in conjunction with a flash loan to perform a withdrawal regardless of liquidity. This path has a configurable penalty, which is [set to zero](https://dapperlabs.slack.com/archives/C0AT1TSDFAL/p1779231421973099) in our specific Inner Vault instance. |
| 27 | + |
| 28 | +**NAV Reporting:** Share price (derived from [`totalAssets`](https://docs.morpho.org/get-started/resources/contracts/morpho-vaults-v2/#totalassets)) is updated lazily on each write path. Read paths use [`accrueInterestView`](https://github.com/morpho-org/vault-v2/blob/main/src/VaultV2.sol#L658-L664), which returns an up-to-date share price. |
| 29 | + |
| 30 | +## Deposit Flow |
| 31 | +```mermaid |
| 32 | +sequenceDiagram |
| 33 | + autonumber |
| 34 | + actor User |
| 35 | + participant Outer as Outer ERC4626 Vault |
| 36 | + participant Lender as Lending Protocol |
| 37 | + participant Inner as Inner ERC4626 Vault |
| 38 | +
|
| 39 | + User->>Outer: deposit(outerAsset) |
| 40 | + activate Outer |
| 41 | +
|
| 42 | + Outer->>Lender: supply (outerAsset) |
| 43 | + Lender-->>Outer: borrow (innerAsset) |
| 44 | +
|
| 45 | + Outer->>Inner: deposit (innerAsset) |
| 46 | + activate Inner |
| 47 | + Inner-->>Outer: innerShare |
| 48 | + deactivate Inner |
| 49 | +
|
| 50 | + Outer-->>User: outerShare |
| 51 | + deactivate Outer |
| 52 | +``` |
| 53 | + |
| 54 | +In Step 2/3 above: |
| 55 | +- We always supply all deposited collateral, regardless of LTV |
| 56 | +- We choose the amount of debt to borrow based on LTV after supply |
| 57 | + |
| 58 | +## Withdrawal Flow (TODO) |
| 59 | +- [Schlagonia always withdraws from inner vault, does not use flash loans](https://github.com/Schlagonia/lender-borrower/blob/morpho/src/BaseLenderBorrower.sol#L660-L666) |
| 60 | +- Patrick's PoC uses flash loans |
| 61 | + |
| 62 | +## Rebalancing |
| 63 | +See **TODO LINK TO REBALANCING SPEC** |
| 64 | + |
| 65 | +## Security |
| 66 | +### Donation/Inflation Attack |
| 67 | +See [explanation from OpenZeppelin](https://docs.openzeppelin.com/contracts/5.x/erc4626#security-concern-inflation-attack). |
| 68 | +### ... |
| 69 | + |
| 70 | +## References / Prior Art |
| 71 | + |
| 72 | +- [Patrick's Vault PoC](https://github.com/holyfuchs/fcm-sol-poc) |
| 73 | +- [Schlagonia Morpho Lender Vault](https://github.com/Schlagonia/lender-borrower/blob/morpho/src/MorphoBlueLenderBorrower.sol) |
0 commit comments