{"id":30064528,"url":"https://github.com/morpho-org/vault-v2","last_synced_at":"2025-08-30T07:15:36.419Z","repository":{"id":304843314,"uuid":"865872571","full_name":"morpho-org/vault-v2","owner":"morpho-org","description":null,"archived":false,"fork":false,"pushed_at":"2025-08-26T10:15:31.000Z","size":3345,"stargazers_count":22,"open_issues_count":24,"forks_count":8,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-08-26T10:37:22.095Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/morpho-org.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-10-01T09:26:45.000Z","updated_at":"2025-08-19T17:28:53.000Z","dependencies_parsed_at":"2025-07-16T12:32:19.281Z","dependency_job_id":"5dcb97a3-e624-4441-8556-b93b9f8e2c80","html_url":"https://github.com/morpho-org/vault-v2","commit_stats":null,"previous_names":["morpho-org/vault-v2"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/morpho-org/vault-v2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morpho-org%2Fvault-v2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morpho-org%2Fvault-v2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morpho-org%2Fvault-v2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morpho-org%2Fvault-v2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/morpho-org","download_url":"https://codeload.github.com/morpho-org/vault-v2/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morpho-org%2Fvault-v2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272817705,"owners_count":24998038,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-30T02:00:09.474Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-08-08T05:03:08.527Z","updated_at":"2025-08-30T07:15:36.409Z","avatar_url":"https://github.com/morpho-org.png","language":"Solidity","funding_links":[],"categories":["Solidity"],"sub_categories":[],"readme":"# Vault v2\n\nMorpho Vault v2 enables anyone to create [non-custodial](#non-custodial-guarantees) vaults that allocate assets to any protocols, including but not limited to Morpho Market v1, Morpho Market v2, and Morpho Vault v1.\nDepositors of Morpho Vault v2 earn from the underlying protocols without having to actively manage the risk of their position.\nManagement of deposited assets is the responsibility of a set of different roles (owner, curator and allocators).\nThe active management of invested positions involves enabling and allocating liquidity to protocols.\n\n[Morpho Vault v2](./src/VaultV2.sol) is [ERC-4626](https://eips.ethereum.org/EIPS/eip-4626) and [ERC-2612](https://eips.ethereum.org/EIPS/eip-2612) compliant.\nThe [VaultV2Factory](./src/VaultV2Factory.sol) deploys instances of Vaults v2.\nAll the contracts are immutable.\n\n## Overview\n\n### Adapters\n\nVaults can allocate assets to arbitrary protocols and markets via adapters, or use an adapter registry to add restrictions to allowed adapters.\nThe curator enables adapters to hold positions on behalf of the vault.\nAdapters are also used to know how much these investments are worth (interest and loss realization).\nBecause adapters hold positions in protocols where assets are allocated, they are susceptible to accrue rewards for those protocols.\nTo ensure that those rewards can be retrieved, each adapter has a skim function that can be called by the vault's owner.\n\nAdapters for the following protocols are currently available:\n\n- [Morpho Market v1](./src/adapters/MorphoMarketV1Adapter.sol).\n  This adapter allocates to any Morpho Market v1, constrained by the allocation caps (see [Id system](#id-system) below).\n  The adapter holds a position on each respective market, on behalf of the vault v2.\n- [Morpho Vault v1](./src/adapters/MorphoVaultV1Adapter.sol).\n  This adapter allocates to a fixed Morpho Vault v1 (v1.0 and v1.1).\n  The adapter holds shares of the corresponding Morpho Vault v1 (v1.0 and v1.1) on behalf of the vault v2.\n\nA Morpho Market v2 adapter will be released together with Market v2.\n\n### Id system\n\nThe funds allocation of the vault is constrained by an id system.\nAn id is an abstract identifier for a common risk factor of some markets (a collateral, an oracle, a protocol, etc.).\nAllocation on markets with a common id is limited by absolute caps and relative caps.\nNote that relative caps are \"soft\" because they are not checked on withdrawals, they only constrain new allocations.\nThe curator ensures the consistency of the id system by:\n\n- setting caps for the ids according to an estimation of risk;\n- setting adapters that return consistent ids.\n\nThe ids of Morpho v1 lending markets could be for example the market parameters `(LoanToken, CollateralToken, Oracle, IRM, LLTV)` and `CollateralToken` alone.\nA vault could be set up to enforce the following caps:\n\n- `(loanToken, stEth, chainlink, irm, 86%)`: 10M\n- `(loanToken, stETH, redstone, irm, 86%)`: 10M\n- `stETH`: 15M\n\nThis would ensure that the vault never has more than 15M exposure to markets with stETH as collateral, and never more than 10M exposure to an individual market.\n\n### Liquidity\n\nThe allocator is responsible for ensuring that users can withdraw their assets at any time.\nThis is done by managing the available idle liquidity and an optional liquidity adapter.\n\nWhen users withdraw assets, the idle assets are taken in priority.\nIf there is not enough idle liquidity, liquidity is taken from the liquidity adapter.\nWhen defined, the liquidity adapter is also used to forward deposited funds.\n\nA typical liquidity adapter would allow deposits/withdrawals to go through a very liquid Market v1.\n\n### Non-custodial guarantees\n\nNon-custodial guarantees come from [in-kind redemptions](#in-kind-redemptions-with-forcedeallocate) and [timelocks](#curator-timelocks).\nThese mechanisms allow users to withdraw their assets before any critical configuration change takes effect.\n\n### In-kind redemptions with `forceDeallocate`\n\nTo guarantee exits even in the absence of assets immediately available for withdrawal, the permissionless `forceDeallocate` function allows anyone to move assets from an adapter to the vault's idle assets.\n\nUsers can redeem in-kind thanks to the `forceDeallocate` function: flashloan liquidity, supply it to an adapter's market, and withdraw the liquidity through `forceDeallocate` before repaying the flashloan.\nThis reduces their position in the vault and increases their position in the underlying market.\n\nA penalty for using forceDeallocate can be set per adapter, of up to 2%.\nThis disincentivizes the manipulation of allocations, in particular of relative caps which are not checked on withdrawals.\nNote that the only friction to deallocating an adapter with a 0% penalty is the associated gas cost.\n\n### Gates\n\nVaults v2 can use external gate contracts to control share transfer, vault asset deposit, and vault asset withdrawal.\n\nIf a gate is not set, its corresponding operations are not restricted.\n\nGate changes can be timelocked.\nBy setting the timelock to `type(uint256).max`, a curator can commit to an irreversible gate setup.\n\nFour gates are defined:\n\n**Receive shares gate** (`receiveSharesGate`): Controls the permission to receive shares.\n\nUpon `deposit`/`mint`, `transfer`/`transferFrom`, and interest accrual (for both fee recipients), `canReceiveShares` must return `true` for the shares recipient if the gate is set.\n\nThis gate is critical because it can prevent depositors from getting back their shares deposited on other contracts. Also, if it reverts and there is a non-zero fee, interest accrual reverts.\n\n**Send shares gate** (`sendShareGate`): Controls the permission to send shares.\n\nUpon `withdraw`/`redeem` and `transfer`/`transferFrom`, `canSendShares` must return `true` for the shares sender if the gate is set.\n\nThis gate is critical because it can prevent people from withdrawing their shares, or prevent depositors from getting back their shares deposited on other contract.\n\n**Receive Assets Gate** (`receiveAssetsGate`): Controls permissions related to receiving assets.\n\nUpon `withdraw`/`redeem`, `canReceiveAssets` must return true for the `receiver` if the gate is set.\n\nThis gate is critical because it can prevent people from receiving their assets upon withdrawals.\n\n**Send Assets Gate** (`sendAssetsGate`): Controls permissions related to sending assets.\n\nUpon `deposit`/`mint`, `canSendAssets` must return true for  `msg.sender` must pass the `canSendAssets` check.\n\n### Roles\n\n#### Owner\n\nThe owner's role is to set the curator and sentinels.\nOnly one address can have this role.\n\nIt can:\n\n- Set the owner.\n- Set the curator.\n- Set sentinels.\n- Set the name.\n- Set the symbol.\n\n#### Curator\n\nThe curator's role is to curate the vault, meaning setting risk limits, gates, allocators, fees.\nOnly one address can have this role.\n\nCurator actions are timelockable, except decreaseAbsoluteCap and decreaseRelativeCap.\nOnce the timelock has passed, the action can be executed by anyone.\n\nIt can:\n\n\u003ca id=\"curator-timelocks\"\u003e\u003c/a\u003e\n\n- [Timelockable] Increase absolute caps.\n- Decrease absolute caps.\n- [Timelockable] Increase relative caps.\n- Decrease relative caps.\n- [Timelockable] Set the adapter registry.\n- [Timelockable] Set adapters.\n- [Timelockable] Set allocators.\n- [Timelockable] Increase timelocks.\n- [Timelocked by the timelock being decreased] Decrease timelocks.\n- [Timelockable] Set the `performanceFee`.\n  The performance fee is capped at 50% of generated interest.\n- [Timelockable] Set the `managementFee`.\n  The management fee is capped at 5% of assets under management annually.\n- [Timelockable] Set the `performanceFeeRecipient`.\n- [Timelockable] Set the `managementFeeRecipient`.\n  increaseTimelock should be used carefully, because decreaseTimelock is timelocked with the timelock itself. In particular it is possible to make an action irreversible (which is a feature in itself). A timelock of `type(uint256).max` is a recommended convention for making an action irreversible.\n\n#### Allocator\n\nThe allocators' role is to handle the allocation of the liquidity (inside the caps set by the curator).\nThey are notably responsible for the vault's liquidity.\nMultiple addresses can have this role.\n\nIt can:\n\n- Allocate funds from the “idle market” to enabled markets.\n- Deallocate funds from enabled markets to the “idle market”.\n- Set the `liquidityAdapter` and the `liquidityData`.\n- Set the `maxRate`.\n\n#### Sentinel\n\nMultiple addresses can have this role.\n\nIt can:\n\n- Deallocate funds from enabled markets to the “idle market”.\n- Decrease absolute caps.\n- Decrease relative caps.\n- Revoke timelocked actions.\n\n## Getting started\n\n### Package installation\n\nInstall [Foundry](https://book.getfoundry.sh/getting-started/installation).\n\n### Run tests\n\nRun `forge test`.\n\n## License\n\nFiles in this repository are publicly available under license `GPL-2.0-or-later`, see [`LICENSE`](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorpho-org%2Fvault-v2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorpho-org%2Fvault-v2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorpho-org%2Fvault-v2/lists"}