ConcreteEncoderPlainV1

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) {
        // use multistrategy encode 
        EncodePlainAllocateParams[] memory allocates = new EncodePlainAllocateParams[](1);
        allocates[0] = EncodePlainAllocateParams({strategy: strategy, amount: amount});
        return encodePlainMultiStrategyAllocate(allocates);
    }

    /**
     * @dev Encodes a plain allocate parameter for 2 strategies
     * @param strategy1 The address of the strategy 1
     * @param amount1 The amount of funds to allocate to strategy 1
     * @param strategy2 The address of the strategy 2
     * @param amount2 The amount of funds to allocate to strategy 2
     * @return The encoded allocate parameter
     */
    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);
    }

    /**
     * @dev Encodes a plain allocate parameter for arbitrarily many strategies
     * @param allocates An array of tuples with strategy address and allocation amount
     * @return The encoded allocate parameter
     */
    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);
    }

    /**
     * @dev Encodes a plain deallocate parameter
     * @param strategy The address of the strategy contract
     * @param amount The amount of funds to deallocate
     * @return The encoded deallocate parameter
     */
    function encodePlainDeallocate(address strategy, uint256 amount) public pure returns (bytes memory) {
        EncodePlainAllocateParams[] memory deallocates = new EncodePlainAllocateParams[](1);
        deallocates[0] = EncodePlainAllocateParams({strategy: strategy, amount: amount});
        return encodePlainMultiStrategyDeallocate(deallocates);
    }

    /**
     * @dev Encodes a plain deallocate parameter for 2 strategies
     * @param strategy1 The address of the strategy 1
     * @param amount1 The amount of funds to deallocate from strategy 1
     * @param strategy2 The address of the strategy 2
     * @param amount2 The amount of funds to deallocate from strategy 2
     * @return The encoded deallocate parameter
     */
    function encodePlainDeallocateFromTwoStrategies(address strategy1, uint256 amount1, address strategy2, uint256 amount2) public pure returns (bytes memory) {
        EncodePlainAllocateParams[] memory deallocates = new EncodePlainAllocateParams[](2);
        deallocates[0] = EncodePlainAllocateParams({strategy: strategy1, amount: amount1});
        deallocates[1] = EncodePlainAllocateParams({strategy: strategy2, amount: amount2});
        return encodePlainMultiStrategyDeallocate(deallocates);
    }

    /**
     * @dev Encodes a plain deallocate parameter for arbitrarily many strategies
     * @param deallocates An array of tuples with strategy address and deallocation amount
     * @return The encoded deallocate parameter
     */
    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
  }
}}

Tags:
DeFi, Yield, Factory|addr:0xa90179d73c1bb6fbd149a7b1e04cc625f075840a|verified:true|block:23684182|tx:0x00ff1d06bc6e0a7ff9ca4aca97cb8a233b00dc2ef72f066375cdae867b2f2725|first_check:1761758205

Submitted on: 2025-10-29 18:16:45

Comments

Log in to comment.

No comments yet.