### Create VaultV2 Example Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/VaultV2Factory.md Example of how to call the createVaultV2 function to deploy a new vault. Ensure you have the factory interface and relevant addresses. ```solidity IVaultV2Factory factory = IVaultV2Factory(0x...); address usdc = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; address owner = msg.sender; bytes32 salt = bytes32(0); address vault = factory.createVaultV2(owner, usdc, salt); ``` -------------------------------- ### IAdapter Interface: allocate Example Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Adapters.md An example demonstrating how to call the allocate function within an adapter. It shows encoding market parameters, specifying the asset amount, and passing relevant context from the message. ```solidity // In allocate function (bytes32[] memory ids, int256 change) = adapter.allocate( abi.encode(marketParams), 1000e6, // 1000 USDC msg.sig, msg.sender ); // ids contains the market's cap IDs // change is the new net position value ``` -------------------------------- ### Example: DepositRouter Contract Implementing IIntermediary Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Gates.md A smart contract example demonstrating how to implement the IIntermediary interface to route deposits. The `initiator()` function dynamically returns the caller's address. ```solidity // Smart contract that routes deposits contract DepositRouter is IIntermediary { function initiator() external view returns (address) { return msg.sender; // Dynamically returns caller } function depositOnBehalf(IVaultV2 vault, uint256 amount) external { // Gate checks the msg.sender's whitelist status vault.deposit(amount, msg.sender); } } ``` -------------------------------- ### Vault V2 Initial Setup and Configuration Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/configuration.md Demonstrates the initial deployment and configuration steps for a Vault V2 instance, including setting up roles, adapters, fees, and timelocks. ```solidity // 1. Deploy vault vault = new VaultV2(owner, asset); // 2. Add curators and allocators vault.setCurator(curator); vault.setIsAllocator(allocator, true); // 3. Add adapters vault.addAdapter(adapter1); vault.addAdapter(adapter2); // 4. Configure fees (optional) vault.setPerformanceFeeRecipient(feeRecipient); vault.setPerformanceFee(0.2e18); // 20% // 5. Set initial timelocks vault.increaseTimelock(IVaultV2.addAdapter.selector, 1 days); vault.increaseTimelock(IVaultV2.setPerformanceFee.selector, 2 days); ``` -------------------------------- ### Share Price Calculation Example Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/ERC20-ERC4626.md Illustrates how the share price changes over time due to interest accrual and fee impacts. It shows the initial state, the effect of interest, and how performance fees alter the total assets and subsequently the share price. ```text Initial state: - 1000 USDC deposited, 1000 shares minted - sharePrice = 1.0 After interest accrual (100 USDC earned): - totalAssets = 1100, no fees - sharePrice = 1100 / 1000 = 1.1 With 20% performance fee: - performanceFeeAssets = 100 * 0.2 = 20 USDC - newTotalAssets = 1080 - performanceFeeShares minted - newSharePrice adjusts accordingly ``` -------------------------------- ### Checking Permissions on VaultV2 Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Gates.md Provides examples for checking deposit, transfer, and withdrawal permissions using VaultV2's permission checking functions. ```solidity // Check before deposit bool canDeposit = vault.canSendAssets(msg.sender); // Check before transfer bool canTransfer = vault.canSendShares(msg.sender) && vault.canReceiveShares(recipient); // Check before withdraw bool canWithdraw = vault.canSendShares(msg.sender) && vault.canReceiveAssets(receiver); ``` -------------------------------- ### Get Vault Allocation and Cap Information Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Adapters.md Retrieves current allocation amounts and defined capacity limits for a given cap ID from the vault. Used to monitor and enforce investment limits. ```solidity uint256 allocation = vault.allocation(capId); uint256 absoluteCap = vault.absoluteCap(capId); uint256 relativeCap = vault.relativeCap(capId); ``` -------------------------------- ### Get Underlying Asset Address Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/ERC20-ERC4626.md Returns the address of the underlying ERC-20 token managed by the vault. ```solidity address public immutable asset ``` -------------------------------- ### Deploying and Setting Gates for Whitelist-Only Vault Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Gates.md Illustrates the steps to set up a whitelist-only vault by deploying gates and then whitelisting specific users. ```solidity // 1. Deploy gates gate = new WhitelistReceiveSharesGate(curator); // 2. Set on vault vault.setReceiveSharesGate(gate); vault.setSendAssetsGate(new WhitelistSendAssetsGate(curator)); // 3. Whitelist users gate.setIsWhitelisted(userA, true); gate.setIsWhitelisted(userB, true); // Result: Only whitelisted users can deposit and hold shares ``` -------------------------------- ### Development Commands with Foundry Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/README.md Common commands for developing and testing smart contracts using the Foundry framework. Includes commands for running tests, building, and formatting code. ```bash forge test forge build forge fmt ``` -------------------------------- ### MorphoMarketV1AdapterV2.constructor Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Adapters.md Initializes the MorphoMarketV1AdapterV2, linking it to a specific Morpho Blue instance and its parent vault. ```APIDOC ## Constructor ### Description Creates adapter for a specific Morpho Blue and parent vault. ### Signature constructor(address _parentVault, address _morpho, address _adaptiveCurveIrm) ### Parameters #### Path Parameters - **_parentVault** (address) - Parent VaultV2 address - **_morpho** (address) - Morpho Blue contract address - **_adaptiveCurveIrm** (address) - Adaptive curve IRM address ``` -------------------------------- ### createVaultV2 Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/VaultV2Factory.md Deploys a new VaultV2 instance using CREATE2 for deterministic address generation. It requires the owner, the asset address, and a salt for determinism. ```APIDOC ## createVaultV2 ### Description Deploys a new VaultV2 instance with deterministic address via CREATE2. This function requires the owner's address, the ERC-20 asset address, and a salt for deterministic address generation. ### Method `external` ### Parameters #### Path Parameters - **owner** (address) - Required - Initial owner of the vault - **asset** (address) - Required - ERC-20 asset the vault manages - **salt** (bytes32) - Required - Salt for CREATE2 determinism ### Returns - **address** - Address of the deployed VaultV2 ### Emits - `CreateVaultV2(owner, asset, salt, newVaultV2)` ### Example ```solidity IVaultV2Factory factory = IVaultV2Factory(0x...); address usdc = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; address owner = msg.sender; bytes32 salt = bytes32(0); address vault = factory.createVaultV2(owner, usdc, salt); ``` ``` -------------------------------- ### Solidity Error: RelativeCapExceeded Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/errors.md This error occurs if an allocation would exceed the relative cap. The relative cap is a soft limit based on the total assets at the start of the transaction and is only enforced during allocation. ```solidity error RelativeCapExceeded(); ``` ```solidity uint256 relativeCap = vault.relativeCap(capId); uint256 firstTotalAssets = vault.firstTotalAssets(); // Relative cap only enforced on allocate, not deallocate // It's "soft" and relative to firstTotalAssets (transaction start) require( vault.allocation(capId) <= firstTotalAssets * relativeCap / WAD, "Would exceed relative cap" ); ``` -------------------------------- ### Constructor Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/VaultV2.md Initializes a new VaultV2 instance with an owner and the managed asset. ```APIDOC ## Constructor ### Description Initializes a new VaultV2 instance. ### Parameters #### Path Parameters - **_owner** (address) - Required - Initial owner of the vault - **_asset** (address) - Required - ERC-20 asset token that the vault manages ### Notes - The asset's decimals determine the vault's decimal offset for protection against inflation attacks - All timelocks default to zero, allowing immediate configuration changes initially - No gates are set, allowing unrestricted access initially ### Example ```solidity address owner = 0x1234...; address usdc = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; VaultV2 vault = new VaultV2(owner, usdc); ``` ``` -------------------------------- ### Get Total Assets in Vault Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/ERC20-ERC4626.md Returns the total amount of assets currently held within the vault, including both idle and allocated assets. This function internally calls accrueInterestView() and has no state changes. ```solidity function totalAssets() external view returns (uint256) ``` -------------------------------- ### Initialize MorphoMarketV1AdapterV2Factory Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Adapters.md Initializes the factory contract with the addresses of the Morpho Blue contract and the Adaptive Curve IRM. ```solidity constructor(address _morpho, address _adaptiveCurveIrm) ``` -------------------------------- ### Get Real Assets in Morpho Vault V1 Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Adapters.md Returns the current value of the adapter's balance within the Morpho Vault V1. Returns 0 if the allocation is zero to prevent unnecessary updates. ```solidity function realAssets() external view returns (uint256) ``` -------------------------------- ### Create MorphoMarketV1AdapterV2 Instance Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Adapters.md Creates and deploys a new MorphoMarketV1AdapterV2 instance associated with a specified parent vault. Returns the address of the newly deployed adapter. ```solidity function createMorphoMarketV1AdapterV2(address parentVault) external returns (address) ``` -------------------------------- ### Create and Configure a Vault V2 Instance Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/README.md Deploy a new VaultV2 contract, set its curator, assign allocator roles, add market adapters, configure fees, and establish timelocks for security. Note that setting the curator is timelocked unless the timelock is set to 0. ```solidity uint256 constant public days = 1 days; // 1. Deploy vault VaultV2 vault = new VaultV2(owner, usdc); // 2. Set curator (timelocked, but can be immediate if timelock=0) vault.setCurator(curator); // 3. Add allocators vault.setIsAllocator(allocator, true); // 4. Add adapters vault.addAdapter(morphoAdapter); // 5. Set fees vault.setPerformanceFeeRecipient(treasury); vault.setPerformanceFee(0.2e18); // 20% // 6. Set timelocks for security vault.increaseTimelock(IVaultV2.addAdapter.selector, 3 * days); ``` -------------------------------- ### Initialize VaultV2Factory Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/VaultV2Factory.md Initializes the factory contract. No parameters are required. ```solidity constructor() ``` -------------------------------- ### Deploy New VaultV2 Instance Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/VaultV2Factory.md Deploys a new VaultV2 instance using CREATE2 for deterministic addressing. Use this to create a new vault managed by a specific owner and asset. ```solidity function createVaultV2(address owner, address asset, bytes32 salt) external returns (address) ``` -------------------------------- ### Initialize MorphoVaultV1Adapter Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Adapters.md Initializes the adapter for a specific Morpho Vault V1 (MetaMorpho). The asset of the parent vault must match the asset of the Morpho Vault V1. ```solidity constructor(address _parentVault, address _morphoVaultV1) ``` -------------------------------- ### WhitelistReceiveSharesGate Constructor Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Gates.md Initializes the WhitelistReceiveSharesGate with a whitelister address. ```APIDOC ## constructor ### Description Initializes the gate with a whitelister address. ### Method CONSTRUCTOR ### Endpoint N/A (Smart Contract Constructor) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **_whitelister** (address) - Required - Address with permission to manage whitelist. ``` -------------------------------- ### MorphoMarketV1AdapterV2 Constructor Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Adapters.md Constructor for the MorphoMarketV1AdapterV2. It initializes the adapter with the parent vault address, the Morpho Blue contract address, and the adaptive curve IRM address. ```solidity constructor(address _parentVault, address _morpho, address _adaptiveCurveIrm) ``` -------------------------------- ### previewMint Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/ERC20-ERC4626.md Simulates the effect of minting a specific amount of shares at the current block, rounding up the required assets. ```APIDOC ## previewMint ### Description Simulates the effect of minting shares at current block (rounds up). ### Method `public view` ### Signature `previewMint(uint256 shares) returns (uint256 assets)` ``` -------------------------------- ### previewDeposit Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/ERC20-ERC4626.md Simulates the effect of a deposit at the current block, accounting for fee accrual and share dilution. ```APIDOC ## previewDeposit ### Description Simulates the effect of a deposit at current block. ### Method `public view` ### Signature `previewDeposit(uint256 assets) returns (uint256 shares)` ### Notes Accounts for fee accrual and share dilution. ``` -------------------------------- ### MorphoMarketV1AdapterV2Factory Constructor Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Adapters.md Initializes the MorphoMarketV1AdapterV2Factory with the addresses of the Morpho Blue contract and the Adaptive Curve IRM. ```APIDOC ## MorphoMarketV1AdapterV2Factory Constructor ### Description Initializes the factory with Morpho Blue and IRM addresses. ### Method CONSTRUCTOR ### Parameters #### Path Parameters - **_morpho** (address) - Required - Morpho Blue contract address - **_adaptiveCurveIrm** (address) - Required - Adaptive curve IRM address ``` -------------------------------- ### Adapter Allocation Flow Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Adapters.md Illustrates the standard process for an adapter to invest assets. It involves the vault transferring assets to the adapter, the adapter allocating them, and the vault updating its internal cap tracking. ```solidity // 1. Vault transfers assets to adapter SafeERC20.safeTransferFrom(asset, vault, adapter, amount) // 2. Adapter invests assets // Returns IDs and change (ids, change) = adapter.allocate(data, amount, sig, sender) // 3. Vault updates cap allocations for each ID for each id in ids: vault.allocation[id] += change // Check against caps require(vault.allocation[id] <= vault.absoluteCap[id]) ``` -------------------------------- ### Adding Access Control with Whitelist Gate Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/README.md Demonstrates how to deploy and configure a WhitelistReceiveSharesGate to control access for specific users. It involves submitting the gate to the vault and then setting it after the timelock expires. ```solidity // Deploy gate gate = new WhitelistReceiveSharesGate(curator); gate.setIsWhitelisted(user1, true); gate.setIsWhitelisted(user2, true); // Submit and execute (after timelock) vault.submit(abi.encodeWithSelector( IVaultV2.setReceiveSharesGate.selector, gate )); // After timelock expires... vault.setReceiveSharesGate(gate); ``` -------------------------------- ### Convert Assets to Shares Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/ERC20-ERC4626.md Converts a given amount of assets to their equivalent share value at the current exchange rate, rounded down. This is equivalent to calling previewDeposit. ```solidity function convertToShares(uint256 assets) external view returns (uint256 shares) ``` -------------------------------- ### VaultV2 Constructor Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/VaultV2.md Initializes a new VaultV2 instance with an owner and an asset address. The asset's decimals influence the vault's decimal offset. All timelocks and gates are initially unset. ```solidity constructor(address _owner, address _asset) ``` ```solidity address owner = 0x1234...; address usdc = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; VaultV2 vault = new VaultV2(owner, usdc); ``` -------------------------------- ### WhitelistReceiveSharesGate Constructor Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Gates.md Initializes the WhitelistReceiveSharesGate with a whitelister address. ```solidity constructor(address _whitelister) ``` -------------------------------- ### Setting a Gate on VaultV2 Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Gates.md Demonstrates how to set a gate on VaultV2. It involves submitting the call to the curator and then executing it after the timelock expires. ```solidity // Curator must submit and wait for timelock vault.submit( abi.encodeWithSelector( IVaultV2.setReceiveSharesGate.selector, gateAddress ) ); // After timelock expires vault.setReceiveSharesGate(gateAddress); ``` -------------------------------- ### Batch Whitelist and Deposit with Signature Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Gates.md Combines signature-based whitelisting with token approval and deposit in a single transaction. Requires user to sign whitelist data and then perform token approval and deposit. ```solidity // User signs whitelist + approve data uint256 deadline = block.timestamp + 1 hours; bytes32 permitData = getSignature(user, true, deadline, v, r, s); // In one transaction: // 1. Whitelist user via signature gate.setIsWhitelistedWithSig(user, true, deadline, v, r, s); // 2. Approve token token.approve(vault, amount); // 3. Deposit vault.deposit(amount, user); ``` -------------------------------- ### MorphoVaultV1Adapter Constructor Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Adapters.md Initializes the MorphoVaultV1Adapter for a specific Morpho Vault V1 (MetaMorpho). ```APIDOC ## MorphoVaultV1Adapter Constructor ### Description Creates adapter for a specific Morpho Vault V1. ### Method CONSTRUCTOR ### Parameters #### Path Parameters - **_parentVault** (address) - Required - Parent VaultV2 address - **_morphoVaultV1** (address) - Required - Morpho Vault V1 (MetaMorpho) address ### Requirements Asset of parent vault must match Morpho Vault V1 asset ``` -------------------------------- ### VaultV2 Constructor Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/configuration.md Initializes a new VaultV2 contract instance. The owner can be changed later, but the asset is immutable. ```solidity new VaultV2(address owner, address asset) ``` -------------------------------- ### Set Adapter Registry Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/configuration.md Configures an optional registry to whitelist allowed adapters. If set, all existing and new adapters must be present in the registry. Setting a new registry validates all current adapters. ```solidity function setAdapterRegistry(address newAdapterRegistry) external ``` -------------------------------- ### Basic Deposit and Withdraw Integration Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/ERC20-ERC4626.md Demonstrates the standard pattern for depositing assets into the vault and subsequently withdrawing them by redeeming shares. Ensure the asset contract is approved for the vault before depositing. ```solidity // Deposit IERC20(asset).approve(vault, amount); uint256 shares = IVaultV2(vault).deposit(amount, msg.sender); // Withdraw uint256 assetsBack = IVaultV2(vault).redeem(shares, msg.sender, msg.sender); ``` -------------------------------- ### Preview Deposit Calculation Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/ERC20-ERC4626.md Simulates the number of shares that would be minted for a given amount of assets deposited, accounting for current fee accrual and share dilution. ```solidity function previewDeposit(uint256 assets) public view returns (uint256 shares) ``` -------------------------------- ### previewDeposit Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/VaultV2.md Calculates and returns the estimated amount of shares that would be minted for a given deposit of assets. The result is rounded down. ```APIDOC ## previewDeposit ### Description Returns the amount of shares that would be minted for a deposit (rounded down). ### Method `public view` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - `assets` (uint256) - Required - Amount of assets to deposit ### Request Example ```solidity function previewDeposit(uint256 assets) ``` ### Response #### Success Response - Returns: Amount of shares to be minted (rounded down) #### Response Example ```solidity (uint256) ``` ``` -------------------------------- ### Set Liquidity Adapter and Data Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/configuration.md Configures an optional adapter for handling deposit and withdrawal liquidity, along with its specific parameters. This adapter is used for both entry and exit operations. ```solidity function setLiquidityAdapterAndData(address newLiquidityAdapter, bytes memory newLiquidityData) external ``` -------------------------------- ### Preview Redemption Amount Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/ERC20-ERC4626.md Simulates the amount of assets that would be received for a given share redemption amount at the current exchange rate, rounding down. ```solidity function previewRedeem(uint256 shares) public view returns (uint256 assets) ``` -------------------------------- ### Add Adapter Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/configuration.md Enables an adapter for use by allocators. This function checks against the adapter registry if one is set. ```solidity function addAdapter(address account) external ``` -------------------------------- ### previewWithdraw Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/ERC20-ERC4626.md Simulates the effect of a withdrawal at the current block, rounding up the number of shares. ```APIDOC ## previewWithdraw ### Description Simulates withdrawal effect at current block (rounds up). ### Method `public view` ### Parameters #### Path Parameters - `assets` (uint256) - Required - Amount of assets to preview withdrawal for ``` -------------------------------- ### Solidity Interface: IIntermediary Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Gates.md Defines the IIntermediary interface, which includes a single function `initiator()` to return the address of the true initiator. ```solidity interface IIntermediary { function initiator() external view returns (address); } ``` -------------------------------- ### Adapter Deallocation Flow Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Adapters.md Details the process for an adapter to return assets. The vault initiates deallocation, the adapter approves the vault for asset transfer, and the vault updates caps and receives the assets. ```solidity // 1. Vault calls deallocate (ids, change) = adapter.deallocate(data, amount, sig, sender) // 2. Adapter must approve vault for at least amount assets SafeERC20.safeApprove(asset, vault, amount) // 3. Vault updates caps and transfers assets for each id in ids: vault.allocation[id] += change SafeERC20.safeTransferFrom(asset, adapter, vault, amount) ``` -------------------------------- ### previewRedeem Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/ERC20-ERC4626.md Simulates the effect of a redemption at the current block, rounding down the number of assets. ```APIDOC ## previewRedeem ### Description Simulates redemption effect at current block (rounds down). ### Method `public view` ### Parameters #### Path Parameters - `shares` (uint256) - Required - Amount of shares to preview redemption for ``` -------------------------------- ### Convert Shares to Assets Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/ERC20-ERC4626.md Converts a given amount of shares to their equivalent asset value at the current exchange rate, rounded down. This is equivalent to calling previewRedeem. ```solidity function convertToAssets(uint256 shares) external view returns (uint256 assets) ``` ```solidity uint256 value = vault.convertToAssets(sharesHeld); ``` -------------------------------- ### MorphoMarketV1AdapterV2.allocate Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Adapters.md Supplies assets to a Morpho Blue market using the adapter. This is a specific implementation of the general `allocate` function. ```APIDOC ## allocate ### Description Supplies assets to a Morpho Blue market. ### Method external ### Signature function allocate(bytes memory data, uint256 assets, bytes4, address) returns (bytes32[] memory, int256) ### Parameters #### Path Parameters - **data** (bytes) - abi-encoded `MarketParams` struct - **assets** (uint256) - Amount to supply ### Returns #### Success Response - **ids** (bytes32[]) - Single-element array with market cap ID - **change** (int256) - Change in position value ### Requirements - MarketParams.loanToken must match vault's asset - MarketParams.irm must match adaptiveCurveIrm - Minted shares >= assets (share price >= 1.0) ``` -------------------------------- ### convertToShares Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/ERC20-ERC4626.md Converts assets to shares at the current exchange rate, rounded down. This is equivalent to calling `previewDeposit()`. ```APIDOC ## convertToShares ### Description Converts assets to shares at current exchange rate (rounded down). ### Method `external view` ### Parameters #### Path Parameters - `assets` (uint256) - Required - The number of assets to convert to shares ``` -------------------------------- ### Share Approval and Transfer Integration Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/ERC20-ERC4626.md Shows how to approve a spender for a specific amount of shares and then transfer those shares from one address to another using the vault's ERC20-like interface. ```solidity // Approve transfers IVaultV2(vault).approve(spender, amount); // Transfer IVaultV2(vault).transferFrom(from, to, shares); ``` -------------------------------- ### Submitting Data for Timelock Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/errors.md Shows the process of submitting function call data for a timelocked operation. This must be done before the actual execution of the timelocked function. ```solidity // Must submit first vault.submit(abi.encodeWithSelector( IVaultV2.addAdapter.selector, adapterAddress )); // Wait for timelock... // Then execute vault.addAdapter(adapterAddress); ``` -------------------------------- ### allocate Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/VaultV2.md Allocates assets to a specified adapter. This function is callable by allocators and accrues interest. It includes checks for authorization, adapter validity, and capacity limits. ```APIDOC ## allocate ### Description Allocates assets to an adapter. Callable by allocators. Accrues interest. ### Method external ### Parameters #### Path Parameters - **adapter** (address) - Address of adapter - **data** (bytes) - Encoded adapter-specific data - **assets** (uint256) - Amount of assets to allocate ### Reverts - ErrorsLib.Unauthorized() if not allocator - ErrorsLib.NotAdapter() if not an enabled adapter - ErrorsLib.ZeroAbsoluteCap() if any returned ID has zero absolute cap - ErrorsLib.AbsoluteCapExceeded() if allocation exceeds absolute cap - ErrorsLib.RelativeCapExceeded() if allocation exceeds relative cap ``` -------------------------------- ### WhitelistReceiveSharesGate setIsWhitelistedWithSig Function Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Gates.md Whitelists an account using an EIP-712 signature, allowing batching with deposits. Requires a valid signature and must be within the deadline. ```solidity function setIsWhitelistedWithSig( address account, bool newIsWhitelisted, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external ``` -------------------------------- ### Convert Assets to Shares in Vault V2 Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/VaultV2.md Converts assets to shares, rounded down. Equivalent to `previewDeposit`. Use for direct asset-to-share conversion calculations. ```solidity function convertToShares(uint256 assets) external view returns (uint256) ``` -------------------------------- ### MorphoVaultV1AdapterFactory Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Adapters.md Factory for creating MorphoVaultV1Adapter instances. ```APIDOC ## MorphoVaultV1AdapterFactory Factory for creating MorphoVaultV1Adapter instances. **Source**: `src/adapters/MorphoVaultV1AdapterFactory.sol` ``` -------------------------------- ### Handling DataAlreadyPending Error Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/errors.md Illustrates submitting data twice, showing how the second attempt reverts with DataAlreadyPending. It also shows how to successfully resubmit after execution. ```solidity bytes memory data = abi.encodeWithSelector( IVaultV2.addAdapter.selector, adapter ); // First submit succeeds vault.submit(data); // Second submit with same data fails // vault.submit(data); // Would revert with DataAlreadyPending // Can execute and resubmit vault.addAdapter(adapter); vault.submit(data); // Now succeeds again ``` -------------------------------- ### Emergency Deallocation Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/README.md Allows immediate deallocation of assets from a specific adapter. This is a critical function for emergency situations. ```solidity vault.deallocate(adapter, data, 500e6); ``` -------------------------------- ### Preview Mint Amount in Vault V2 Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/VaultV2.md Returns the amount of assets required to mint shares, rounded up. Use to estimate asset cost before minting new shares. ```solidity function previewMint(uint256 shares) public view returns (uint256) ``` -------------------------------- ### Preview Withdrawal Amount Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/ERC20-ERC4626.md Simulates the number of shares that would be burned for a given asset withdrawal amount at the current exchange rate, rounding up. ```solidity function previewWithdraw(uint256 assets) public view returns (uint256 shares) ``` -------------------------------- ### Solidity Error: NotAdapter Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/errors.md This error is raised when an attempt is made to allocate or deallocate using an address that is not in the enabled adapters list. Ensure the adapter is added and enabled before performing allocation operations. ```solidity error NotAdapter(); ``` ```solidity // First add adapter vault.submit(abi.encodeWithSelector(IVaultV2.addAdapter.selector, newAdapter)); // Wait for timelock... vault.addAdapter(newAdapter); // Then allocate vault.allocate(newAdapter, data, amount); ``` -------------------------------- ### MorphoVaultV1Adapter allocate Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Adapters.md Deposits assets into the Morpho Vault V1. The `data` parameter must be empty. ```APIDOC ## allocate ### Description Deposits assets to the Morpho Vault V1. ### Method EXTERNAL ### Endpoint N/A (Contract Method) ### Parameters #### Path Parameters - **data** (bytes) - Required - Must be empty (no parameters needed) - **assets** (uint256) - Required - Amount to deposit ### Returns - **bytes32[]** - ids: Single-element array with adapter ID - **int256** - change: Change in position value ### Reverts - `InvalidData()` if data is not empty ``` -------------------------------- ### convertToAssets Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/ERC20-ERC4626.md Converts shares to assets at the current exchange rate, rounded down. This is equivalent to calling `previewRedeem()`. ```APIDOC ## convertToAssets ### Description Converts shares to assets at current exchange rate (rounded down). ### Method `external view` ### Parameters #### Path Parameters - `shares` (uint256) - Required - The number of shares to convert to assets ### Example ```solidity uint256 value = vault.convertToAssets(sharesHeld); ``` ``` -------------------------------- ### VaultV2 Creation Event Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/VaultV2Factory.md Event emitted when a new VaultV2 is successfully created. It logs the owner, asset, salt, and the address of the newly deployed vault. ```solidity event CreateVaultV2(address indexed owner, address indexed asset, bytes32 salt, address newVaultV2) ``` -------------------------------- ### addAdapter Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/VaultV2.md Adds an adapter contract to the vault. This operation is timelocked. Duplicate additions are ignored. ```APIDOC ## addAdapter ### Description Adds an adapter to the vault. This operation is timelocked. Duplicate additions are no-ops. ### Method external ### Endpoint N/A (Smart Contract Function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response N/A #### Response Example N/A ### Reverts - `ErrorsLib.DataNotTimelocked()`: If the operation is not submitted and the timelock has expired. - `ErrorsLib.NotInAdapterRegistry()`: If the adapter registry is set and the adapter is not registered. ``` -------------------------------- ### Permit-Based Approval and Transfer Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/ERC20-ERC4626.md Sign an approval off-chain using `signPermit` and then execute the approval and transfer in a single on-chain transaction using the `vault.permit` and `vault.transferFrom` functions. ```solidity // Sign off-chain (v, r, s) = signPermit(owner, spender, shares, deadline); // Approve and transfer in one tx vault.permit(owner, spender, shares, deadline, v, r, s); vault.transferFrom(owner, recipient, shares); ``` -------------------------------- ### WhitelistReceiveSharesGate.setIsWhitelisted Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Gates.md Adds or removes an account from the whitelist. Only callable by the current whitelister. ```APIDOC ## setIsWhitelisted ### Description Adds or removes an account from the whitelist. Only callable by the current whitelister. ### Method EXTERNAL ### Endpoint N/A (Smart Contract Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **account** (address) - Required - Account to whitelist/delist. - **newIsWhitelisted** (bool) - Required - True to whitelist, false to remove. **Reverts**: `NotWhitelister()` if not called by whitelister. ``` -------------------------------- ### permit Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/ERC20-ERC4626.md Approves spending of shares via an EIP-712 signature. This allows for gasless approvals by submitting the signature on-chain. ```APIDOC ## permit ### Description Approves spending of shares via an EIP-712 signature. This allows for gasless approvals by submitting the signature on-chain. ### Method `external` ### Signature `permit( address _owner, address spender, uint256 shares, uint256 deadline, uint8 v, bytes32 r, bytes32 s )` ### Parameters #### Path Parameters - `_owner` (address) - Required - Account whose shares are approved - `spender` (address) - Required - Account approved to spend - `shares` (uint256) - Required - Amount approved - `deadline` (uint256) - Required - Signature expiration (block.timestamp) - `v` (uint8) - Required - Signature v component - `r` (bytes32) - Required - Signature r component - `s` (bytes32) - Required - Signature s component ### Reverts - `ErrorsLib.PermitDeadlineExpired()` if deadline < block.timestamp - `ErrorsLib.InvalidSigner()` if signature invalid ### Notes - No return value (doesn't return bool) - Signature nonce auto-incremented - Useful for gasless approvals ### Example ```solidity // Sign off-chain bytes32 digest = keccak256(abi.encodePacked( "\x19\x01", vault.DOMAIN_SEPARATOR(), keccak256(abi.encode( PERMIT_TYPEHASH, owner, spender, shares, nonce, deadline )) )); (uint8 v, bytes32 r, bytes32 s) = sign(digest, ownerPrivateKey); // Submit on-chain without separate approval tx vault.permit(owner, spender, shares, deadline, v, r, s); vault.transferFrom(owner, recipient, shares); ``` ``` -------------------------------- ### Allocate Assets to Adapter Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/VaultV2.md Allocates a specified amount of assets to an adapter. This function is callable by allocators and accrues interest. It includes checks for authorization, adapter status, and capacity limits. ```solidity function allocate(address adapter, bytes memory data, uint256 assets) external ``` -------------------------------- ### Solidity Error: MaxRateTooHigh Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/errors.md This error occurs when the maximum rate set exceeds 200% APR. Ensure the new maximum rate is within the acceptable limit. ```solidity error MaxRateTooHigh(); ``` ```solidity uint256 maxAllowed = 200e16 / uint256(365 days); vault.setMaxRate(maxAllowed); // OK - 200% APR // vault.setMaxRate(maxAllowed + 1); // Would fail ``` -------------------------------- ### WhitelistReceiveSharesGate DOMAIN_SEPARATOR Function Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Gates.md Returns the EIP-712 domain separator used for signature verification. ```solidity function DOMAIN_SEPARATOR() public view returns (bytes32) ``` -------------------------------- ### setIsWhitelisted Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Gates.md Adds or removes an account from the whitelist. This function can only be called by an authorized whitelister. ```APIDOC ## setIsWhitelisted ### Description Adds or removes an account from the whitelist. ### Method EXTERNAL ### Parameters #### Path Parameters - **account** (address) - Required - Account to whitelist/delist - **newIsWhitelisted** (bool) - Required - True to whitelist, false to remove ### Reverts - `NotWhitelister()` if not called by whitelister ``` -------------------------------- ### createMorphoVaultV1Adapter Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Adapters.md Creates a new adapter for a vault and Morpho Vault V1. This function deploys a new adapter contract that bridges a Vault V2 with a Morpho Vault V1. ```APIDOC ## createMorphoVaultV1Adapter ### Description Creates a new adapter for a vault and Morpho Vault V1. This function deploys a new adapter contract that bridges a Vault V2 with a Morpho Vault V1. ### Method External function call ### Signature `createMorphoVaultV1Adapter(address parentVault, address morphoVaultV1) returns (address)` ### Parameters #### Path Parameters - **parentVault** (address) - Required - Parent VaultV2 address - **morphoVaultV1** (address) - Required - Morpho Vault V1 (MetaMorpho) address ### Response #### Success Response - **adapterAddress** (address) - Address of deployed adapter ### Emits - `CreateMorphoVaultV1Adapter(address parentVault, address morphoVaultV1, address adapterAddress)` ``` -------------------------------- ### Convert Shares to Assets in Vault V2 Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/VaultV2.md Converts shares to assets, rounded down. Equivalent to `previewRedeem`. Use for direct share-to-asset conversion calculations. ```solidity function convertToAssets(uint256 shares) external view returns (uint256) ``` -------------------------------- ### Create Morpho Vault V1 Adapter Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Adapters.md Creates a new adapter instance for a vault and its associated Morpho Vault V1 contract. This function is part of the adapter factory pattern. ```solidity function createMorphoVaultV1Adapter(address parentVault, address morphoVaultV1) external returns (address) ``` -------------------------------- ### WhitelistReceiveSharesGate setIsWhitelisted Function Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Gates.md Adds or removes an account from the whitelist. Only callable by the current whitelister. ```solidity function setIsWhitelisted(address account, bool newIsWhitelisted) external ``` -------------------------------- ### setIsWhitelistedWithSig Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Gates.md Whitelists an account using an EIP-712 signature. This allows for off-chain signing of whitelist actions. ```APIDOC ## setIsWhitelistedWithSig ### Description Whitelists an account using an EIP-712 signature. ### Method EXTERNAL ### Parameters #### Path Parameters - **account** (address) - Required - Account to whitelist/delist - **newIsWhitelisted** (bool) - Required - True to whitelist, false to remove - **deadline** (uint256) - Required - Signature expiration - **v** (uint8) - Required - Signature v component - **r** (bytes32) - Required - Signature r component - **s** (bytes32) - Required - Signature s component ### Reverts - `DeadlineExpired()` if deadline < block.timestamp - `InvalidSigner()` if signature invalid ``` -------------------------------- ### IAdapter Interface: allocate Function Signature Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Adapters.md Defines the signature for the allocate function within the IAdapter interface. This function is used to allocate assets to market positions and is only callable by the parent vault. ```solidity function allocate(bytes memory data, uint256 assets, bytes4 selector, address sender) external returns (bytes32[] memory ids, int256 change) ``` -------------------------------- ### WhitelistReceiveSharesGate.DOMAIN_SEPARATOR Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Gates.md EIP-712 domain separator for signature verification. ```APIDOC ## DOMAIN_SEPARATOR ### Description EIP-712 domain separator for signature verification. ### Method VIEW ### Endpoint N/A (Smart Contract Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Response #### Success Response - **bytes32** - The EIP-712 domain separator. ``` -------------------------------- ### ERC-20 Account Balances Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/ERC20-ERC4626.md Details on how to check account balances and the total supply of shares. ```APIDOC ## balanceOf ```solidity mapping(address => uint256) public balanceOf ``` Tracks share balance of each account. **Example**: ```solidity uint256 shares = vault.balanceOf(user); ``` ## totalSupply ```solidity uint256 public totalSupply ``` Total shares in circulation. Note: does not include fee shares yet to be minted. **Notes**: - Updated only when shares are transferred, minted, or burned - Fee shares are minted on accrueInterest but not reflected until accrueInterest is called - Use `accrueInterestView()` to get the updated totalSupply ``` -------------------------------- ### NotInAdapterRegistry Error Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/errors.md This error is triggered when an adapter is not registered in the adapter registry. It is used during the setAdapterRegistry and addAdapter functions. ```solidity error NotInAdapterRegistry(); ``` ```solidity // Verify adapter in registry before adding address registry = vault.adapterRegistry(); require( registry == address(0) || IAdapterRegistry(registry).isInRegistry(adapter), "Not in registry" ); vault.addAdapter(adapter); ``` -------------------------------- ### maxDeposit Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/ERC20-ERC4626.md Returns the maximum deposit amount, which is always 0 due to gates and allocator requirements. ```APIDOC ## maxDeposit ### Description Returns maximum deposit amount: always 0. ### Method `external pure` ### Parameters #### Path Parameters - `_` (address) - Required - The address for which to check the maximum deposit amount (unused) ``` -------------------------------- ### WhitelistReceiveSharesGate.setIsWhitelistedWithSig Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Gates.md Whitelists an account using an EIP-712 signature, allowing batching with deposits. ```APIDOC ## setIsWhitelistedWithSig ### Description Whitelists an account using an EIP-712 signature, allowing batching with deposits. ### Method EXTERNAL ### Endpoint N/A (Smart Contract Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **account** (address) - Required - Account to whitelist/delist. - **newIsWhitelisted** (bool) - Required - True to whitelist, false to remove. - **deadline** (uint256) - Required - Signature expiration (block.timestamp). - **v** (uint8) - Required - Signature v component. - **r** (bytes32) - Required - Signature r component. - **s** (bytes32) - Required - Signature s component. **Reverts**: - `DeadlineExpired()` if deadline < block.timestamp - `InvalidSigner()` if signature invalid. **Example**: Deposit and whitelist in one transaction without prior whitelister approval. ``` -------------------------------- ### MorphoMarketV1AdapterV2Factory createMorphoMarketV1AdapterV2 Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Adapters.md Creates a new MorphoMarketV1AdapterV2 instance for a given parent vault. ```APIDOC ## createMorphoMarketV1AdapterV2 ### Description Creates a new adapter for a vault. ### Method EXTERNAL ### Endpoint N/A (Contract Method) ### Parameters #### Path Parameters - **parentVault** (address) - Required - Parent VaultV2 address ### Returns - **address** - Address of deployed adapter ### Emits - `CreateMorphoMarketV1AdapterV2(parentVault, adapterAddress)` ``` -------------------------------- ### Unauthorized Error Handling Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/errors.md Demonstrates how to catch and handle the Unauthorized error when calling a vault function. This is useful for providing user-friendly messages or alternative logic paths. ```solidity try vault.allocate(adapter, data, amount) { // Success } catch (bytes memory error) { if (bytes4(error) == ErrorsLib.Unauthorized.selector) { revert("Not an allocator"); } } ``` -------------------------------- ### ERC-20 Balance Of Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/ERC20-ERC4626.md Tracks the ERC-20 share balance for each account. This is a mapping from an address to its uint256 share balance. ```solidity mapping(address => uint256) public balanceOf ``` -------------------------------- ### Preview Withdraw Amount in Vault V2 Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/VaultV2.md Returns the amount of shares to burn to withdraw assets, rounded up. Use to estimate share burn before initiating a withdrawal. ```solidity function previewWithdraw(uint256 assets) public view returns (uint256) ``` -------------------------------- ### Checking for Abdicated Functions Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/errors.md Demonstrates how to check if a timelocked function has been permanently disabled (abdicated) before attempting to submit or execute it. Abdication is irreversible. ```solidity // Check if abdicated before submit bool isAbdicated = vault.abdicated(IVaultV2.addAdapter.selector); require(!isAbdicated, "Function abdicated"); // Note: Cannot be undone once abdicated // The vault is locked in that configuration forever ``` -------------------------------- ### Set Max Rate Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/configuration.md Configures the maximum rate of share price increase per second. Limits interest accrual and protects against excessive rates. Requires Allocator role. ```solidity function setMaxRate(uint256 newMaxRate) external ``` -------------------------------- ### Allocate Assets to a Market Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/README.md An allocator can deposit vault assets into a specified market using a configured adapter. This function requires the adapter address, encoded market parameters, and the amount of assets to allocate. ```solidity // Allocator allocates vault assets to a market vault.allocate( adapter, abi.encode(marketParams), 500e6 // 500 USDC ); ``` -------------------------------- ### Preview Deposit Amount in Vault V2 Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/VaultV2.md Returns the amount of shares that would be minted for a deposit, rounded down. Use to estimate share issuance before making a deposit. ```solidity function previewDeposit(uint256 assets) public view returns (uint256) ``` -------------------------------- ### Preview Mint Calculation Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/ERC20-ERC4626.md Simulates the amount of assets required to mint a specific number of shares, rounding up. This function accounts for current fee accrual and share dilution. ```solidity function previewMint(uint256 shares) public view returns (uint256 assets) ``` -------------------------------- ### IAdapter.allocate Source: https://github.com/morpho-org/vault-v2/blob/main/_autodocs/api-reference/Adapters.md Allocates assets to market positions. This function is intended for internal use by the parent vault and handles the logic for supplying assets to a market. ```APIDOC ## allocate ### Description Allocates assets to market positions. Only callable by parent vault. ### Method external ### Signature function allocate(bytes memory data, uint256 assets, bytes4 selector, address sender) returns (bytes32[] memory ids, int256 change) ### Parameters #### Path Parameters - **data** (bytes) - Encoded adapter-specific market parameters - **assets** (uint256) - Amount of assets to allocate - **selector** (bytes4) - Function selector that invoked the allocation - **sender** (address) - Address that triggered the allocation ### Returns #### Success Response - **ids** (bytes32[]) - Array of cap IDs affected by this allocation - **change** (int256) - Change in total allocation (positive for additions) ### Requirements - Only vault can call this - Must return non-zero IDs for known markets - Must approve vault to transfer at least `assets` after deallocation ### Example ```solidity // In allocate function (bytes32[] memory ids, int256 change) = adapter.allocate( abi.encode(marketParams), 1000e6, // 1000 USDC msg.sig, msg.sender ); // ids contains the market's cap IDs // change is the new net position value ``` ```