Description:
Decentralized Finance (DeFi) protocol contract providing Yield, Factory functionality.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"src/ConcreteEncoder.sol": {
"content": "// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.24;
/**
* @title ConcreteEncoderPlainV1
* @dev Utility contract for encoding concrete allocate and deallocate parameters
*/
import {IAllocateModule} from "./interface/IAllocateModule.sol";
struct EncodePlainAllocateParams {
address strategy;
uint256 amount;
}
contract ConcreteEncoderPlainV1 {
/**
* @dev Encodes a plain allocate parameter
* @param strategy The address of the strategy contract
* @param amount The amount of funds to allocate
* @return The encoded allocate parameter
*/
function encodePlainAllocate(address strategy, uint256 amount) public pure returns (bytes memory) {
bytes memory extraData = abi.encode(amount);
return abi.encode(IAllocateModule.AllocateParams({isDeposit: true, strategy: strategy, extraData: extraData}));
}
function encodePlainAllocateToTwoStrategies(address strategy1, uint256 amount1, address strategy2, uint256 amount2) public pure returns (bytes memory) {
EncodePlainAllocateParams[] memory allocates = new EncodePlainAllocateParams[](2);
allocates[0] = EncodePlainAllocateParams({strategy: strategy1, amount: amount1});
allocates[1] = EncodePlainAllocateParams({strategy: strategy2, amount: amount2});
return encodePlainMultiStrategyAllocate(allocates);
}
function encodePlainMultiStrategyAllocate(EncodePlainAllocateParams[] memory allocates) public pure returns (bytes memory) {
IAllocateModule.AllocateParams[] memory params = new IAllocateModule.AllocateParams[](allocates.length);
for (uint256 i = 0; i < allocates.length; i++) {
params[i] = IAllocateModule.AllocateParams({isDeposit: true, strategy: allocates[i].strategy, extraData: abi.encode(allocates[i].amount)});
}
return abi.encode(params);
}
function encodePlainDeallocate(address strategy, uint256 amount) public pure returns (bytes memory) {
return abi.encode(IAllocateModule.AllocateParams({isDeposit: false, strategy: strategy, extraData: abi.encode(amount)}));
}
function encodePlainDeallocateFromTwoStrategies(address strategy1, uint256 amount1, address strategy2, uint256 amount2) public pure returns (bytes memory) {
EncodePlainAllocateParams[] memory allocates = new EncodePlainAllocateParams[](2);
allocates[0] = EncodePlainAllocateParams({strategy: strategy1, amount: amount1});
allocates[1] = EncodePlainAllocateParams({strategy: strategy2, amount: amount2});
return encodePlainMultiStrategyDeallocate(allocates);
}
function encodePlainMultiStrategyDeallocate(EncodePlainAllocateParams[] memory deallocates) public pure returns (bytes memory) {
IAllocateModule.AllocateParams[] memory params = new IAllocateModule.AllocateParams[](deallocates.length);
for (uint256 i = 0; i < deallocates.length; i++) {
params[i] = IAllocateModule.AllocateParams({isDeposit: false, strategy: deallocates[i].strategy, extraData: abi.encode(deallocates[i].amount)});
}
return abi.encode(params);
}
}"
},
"src/interface/IAllocateModule.sol": {
"content": "// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;
/**
* @title IAllocateModule
* @dev Interface for the AllocateModule contract that handles fund allocation and deallocation across multiple strategies.
* @dev This module enables the vault to efficiently manage funds across different yield-generating strategies
* by batching multiple allocation/deallocation operations in a single transaction.
*
* @notice The AllocateModule serves as a coordinator for strategy operations, allowing the vault to:
* - Allocate funds to multiple strategies in a single call
* - Deallocate funds from multiple strategies in a single call
* - Maintain accurate accounting of allocated amounts per strategy
*
* @notice This module is typically used during rebalancing operations where the vault needs to
* adjust allocations across multiple strategies based on current market conditions,
* strategy performance, or allocation targets.
*/
interface IAllocateModule {
/**
* @dev Emitted when funds are allocated or deallocated from a strategy.
*
* @param strategy The address of the strategy contract.
* @param isDeposit True if this is an allocation (deposit) operation, false if it's a deallocation (withdrawal).
* @param amount The amount of funds allocated or deallocated.
* @param extraData Arbitrary calldata passed to the strategy's allocateFunds or deallocateFunds function.
*/
event AllocatedFunds(address indexed strategy, bool indexed isDeposit, uint256 amount, bytes extraData);
/**
* @dev Structure containing parameters for a single allocation or deallocation operation.
*
* @param isDeposit True if this is an allocation (deposit) operation, false if it's a deallocation (withdrawal).
* @param strategy The address of the strategy contract to interact with.
* @param extraData Arbitrary calldata to pass to the strategy's allocateFunds or deallocateFunds function.
* This allows for strategy-specific parameters like slippage tolerance, routing info, etc.
*/
struct AllocateParams {
bool isDeposit;
address strategy;
bytes extraData;
}
/**
* @dev Executes multiple allocation and deallocation operations across different strategies in a single transaction.
* @dev This function processes an array of allocation parameters, calling the appropriate strategy functions
* and updating the vault's internal accounting for each strategy.
*
* @param data ABI-encoded array of AllocateParams structures containing the operations to execute.
* Each AllocateParams specifies whether to allocate or deallocate funds, which strategy to use,
* and any additional data required by the strategy.
*
* @notice The function iterates through all provided parameters and:
* - For deposits (isDeposit = true): Calls strategy.allocateFunds() and increases allocated amount
* - For withdrawals (isDeposit = false): Calls strategy.deallocateFunds() and decreases allocated amount
*
* @notice All operations are executed atomically - if any single operation fails, the entire transaction reverts.
*
* @notice The function updates the vault's internal strategy accounting to track the total amount
* allocated to each strategy, which is used for yield calculation and strategy limits.
*/
function allocateFunds(bytes calldata data) external;
}
"
}
},
"settings": {
"remappings": [
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
"@openzeppelin-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable/",
"@openzeppelin-contracts/=node_modules/@openzeppelin/contracts/",
"@openzeppelin/=node_modules/@openzeppelin/"
],
"optimizer": {
"enabled": true,
"runs": 200
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "prague",
"viaIR": false
}
}}
Submitted on: 2025-10-29 18:01:43
Comments
Log in to comment.
No comments yet.