Important
This repository contains smart contracts that have been developed for educational, experimental, or demonstration purposes only. By using or interacting with these smart contracts, you acknowledge and accept the following:
- The smart contracts in this repository have not been audited and are provided "as is" with no guarantees, warranties, or assurances of any kind. The authors and maintainers of this repository are not responsible for any damages, losses, or liabilities that may arise from the use or deployment of these smart contracts.
- The smart contracts in this repository are not intended for use in production environments or for the management of real-world assets, funds, or resources. Any use or deployment of these smart contracts for such purposes is done entirely at your own risk.
- The smart contracts are provided for reference and learning purposes, and you are solely responsible for understanding, modifying, and deploying them as needed.
One can use the logic provided in the following:
- Functions to get data:
supplyAPYborrowAPYsupplyAssetsUserborrowAssetsUsercollateralAssetsUsermarketTotalSupplymarketTotalBorrowuserHealthFactor
- Functions to modify state:
supplysupplyCollateralwithdrawCollateralwithdrawAmountwithdraw50PercentwithdrawAll
- Functions using callbacks:
leverageMedeLeverageMe
One can use the logic provided in the following:
- Functions to get data:
totalDepositVaultvaultAssetsInMarkettotalSharesUserVaultsupplyQueueVaultwithdrawQueueVaulttotalCapCollateralsupplyAPYMarketsupplyAPYVault
- Functions to modify state:
depositInVaultwithdrawFromVaultAmountredeemAllFromVault
One can use the logic provided in the following:
- Functions to get data:
totalDepositVaultV2totalSharesUserVaultV2sharePriceVaultV2adaptersListVaultV2allocationByIdabsoluteCapByIdrelativeCapByIdcapsByIdrealAssetsPerAdapteridleAssetsVaultV2feeInfoVaultV2liquidityAdapterVaultV2accrueInterestViewpreviewDepositVaultV2previewMintVaultV2previewWithdrawVaultV2previewRedeemVaultV2effectiveCapByIdvaultV2AssetsInMarketmarketsInVaultV2vaultV1AssetsInMarket(legacy helper for MetaMorpho V1)supplyAPYVaultV2
- Functions to modify state:
depositInVaultV2mintInVaultV2withdrawFromVaultV2redeemFromVaultV2redeemAllFromVaultV2accrueInterestVaultV2
Note
The VaultV2 snippets support MorphoMarketV1AdapterV2 and MorphoVaultV1Adapter. For MorphoVaultV1Adapter, nested VaultV2 wrappers are supported and MetaMorpho V1 handling is kept as a legacy fallback path.
VaultV2 intentionally returns 0 for default maxWithdraw and maxRedeem in many integrations, which can make
UI/analytics liquidity estimation harder.
VaultV2LiquidityLib and VaultV2LiquidityLens provide an alternative view-only way to recompute withdrawable
liquidity from current state:
availableLiquidity(vault): recomputes instant exit liquidity asidle assets + liquidity from the configured liquidity adaptermaxWithdraw(vault, owner): recomputesmin(owner assets, available liquidity)maxRedeem(vault, owner): recomputesmin(owner shares, shares implied by available liquidity)adapterLiquidity(adapter, liqData): exposes adapter-level liquidity computation
How liquidity is recomputed:
- Idle part: token balance held directly by the vault
- Adapter part: derived from the current
liquidityAdapter+liquidityDataconfiguration - For Morpho market adapter path, computation mirrors the single exit market encoded in
liquidityData
Note
This library is a demo/integration helper and currently supports only:
MorphoMarketV1AdapterV2MorphoVaultV1AdapterUnknown adapter families are ignored (contribute0), so new adapter types require explicit library updates.
FeeWrapperDeployer deploys and configures a VaultV2 "fee wrapper" on top of an existing Morpho Vault V2 in a single
atomic transaction. A fee wrapper is a VaultV2 that wraps a child vault via a MorphoVaultV1Adapter: users deposit into
the wrapper, funds are routed to the child vault, and the wrapper owner charges performance and/or management fees on
the yield.
The deployer handles all setup atomically:
- Creates the wrapper vault and adapter pointing to the child vault
- Permanently locks the adapter configuration (addAdapter and removeAdapter are abdicated)
- Sets caps, liquidity routing, max rate, and force-deallocate penalty to recommended defaults
- Optionally configures performance fee, management fee, and fee recipient
- Optionally abdicates gate setters for non-custodial guarantees
- Transfers ownership to the final owner (must be a safe wallet)
Configurable parameters via FeeWrapperConfig:
owner/salt/childVault(required)name/symbol(ERC20 metadata, settable later by owner)performanceFee/managementFee/feeRecipient(optional, configurable later by curator)abdicateNonCriticalGates(if true, permanently locks gates open for non-custodial operation)
Important
The child vault must be a Morpho Vault V2. The "MorphoVaultV1Adapter" name is a legacy artifact; the adapter is ERC4626-compatible but V2 is the only audited and recommended configuration.
Note
For compliance use cases (KYC/AML), leave abdicateNonCriticalGates = false and configure gates later via the
curator + timelock mechanism.
- Install Foundry
- Install yarn
- Run
foundryup - Run
forge install - Create a
.envfile according to the.env.examplefile.
You can run tests by running the command:
forge testIf you have any questions or need further assistance, please don't hesitate to reach out on Discord.
The code is under the MIT License. See LICENSE.