ETH Price: $2,742.92 (-0.82%)

Contract

0x27B3b0CF354769d3caCADe98f4dcE083B22c00F3

Overview

ETH Balance

0 ETH

ETH Value

$0.00

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

View more zero value Internal Transactions in Advanced View mode

Advanced mode:

Cross-Chain Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
AvKatStrategy

Compiler Version
v0.8.28+commit.7893614a

Optimization Enabled:
Yes with 50 runs

Other Settings:
cancun EvmVersion
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.28;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IERC4626 } from "@openzeppelin/contracts/interfaces/IERC4626.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import { IBaseStrategy } from "../../interfaces/optimizer/IBaseStrategy.sol";
import { IAvKatStrategy } from "../../interfaces/optimizer/strategies/IAvKatStrategy.sol";
import { IRagaEpochVault } from "../../interfaces/IRagaEpochVault.sol";

import { BaseStrategy } from "./BaseStrategy.sol";

import { Constants } from "../../optimizer/utils/Constants.sol";
import { NotImplemented, ZeroAddress } from "../../utils/Helpers.sol";
import { RagaEpochVaultStorageLibrary } from "../../libraries/RagaEpochVaultStorageLibrary.sol";

contract AvKatStrategy is BaseStrategy, IAvKatStrategy {
    bytes32 private constant STRATEGY_STORAGE_SLOT = keccak256("AvKatStrategy.strategy.storage");
    bytes32 private constant STRATEGY_CONFIG_SLOT = keccak256("AvKatStrategy.config.storage");

    constructor(address optimizerVault, address avKatVault, address katToken) BaseStrategy(optimizerVault) {
        if (avKatVault == address(0)) revert ZeroAddress();
        _getConfig().avKatVault = avKatVault;
        _getConfig().katToken = katToken;
    }

    function processHook(
        address strategy,
        uint32 transactionType,
        bytes calldata cmd
    )
        external
        override
        onlyDelegateCall(strategy)
        onlyEpochProcessingDelegate
    {
        IAvKatStrategy conn = IAvKatStrategy(strategy);
        IBaseStrategy baseStrategy = IBaseStrategy(strategy);
        BaseStrategyStorage memory cfg = baseStrategy.getBaseStrategyConfig();
        AvKatStrategyConfig memory avKatConfig = conn.getConfig();
        IERC4626 avKatVault = IERC4626(avKatConfig.avKatVault);
        IERC20 katToken = IERC20(avKatConfig.katToken);

        if (transactionType == Constants.AVKAT_TRANSACTION_CODE_DEPOSIT) {
            uint256 assets = _decodeCmdForDeposit(cmd);
            _deposit(avKatVault, katToken, cfg.optimizerVault, assets);
        } else if (transactionType == Constants.AVKAT_TRANSACTION_CODE_RESERVE_FOR_WITHDRAWAL) {
            (uint256 avKATReservedForWithdrawal) = _decodeAvKATReservedForWithdrawal(cmd);
            _reserveForWithdrawalEntryPoint(conn, avKATReservedForWithdrawal);
        } else {
            revert InvalidTransactionType(transactionType);
        }
    }

    function finalizeHook(
        address strategy,
        uint32 transactionType,
        bytes calldata /*cmd*/
    )
        external
        override
        onlyDelegateCall(strategy)
        onlyEpochProcessingDelegate
    {
        IAvKatStrategy conn = IAvKatStrategy(strategy);
        if (transactionType != Constants.AVKAT_TRANSACTION_CODE_FINALIZE) {
            revert InvalidTransactionType(transactionType);
        }

        _finalizeForWithdrawalEntryPoint(conn);
    }

    function claimWithdrawalHook(
        uint256 totalSharesForWithdrawal,
        uint256 totalAssetsForWithdrawalInWithdrawalToken
    )
        external
        override
        onlyOptimizerVault
    {
        AvKatStrategyStorage storage s = _getStorage();

        s.totalSharesToBeClaimed -= totalSharesForWithdrawal;
        s.avKATFinalizedForWithdrawal -= totalAssetsForWithdrawalInWithdrawalToken;
    }

    function reserveForWithdrawal(uint256 avKATReservedForWithdrawal) external onlyOptimizerVault onlyEpochProcessing {
        _reserveAvKATForWithdrawal(avKATReservedForWithdrawal);
    }

    function finalizeForWithdrawal(uint256 totalSharesToBeClaimed)
        external
        onlyOptimizerVault
        onlyEpochProcessing
        returns (uint256)
    {
        return _finalizeAvKATForWithdrawal(totalSharesToBeClaimed);
    }

    function _deposit(IERC4626 avKatVault, IERC20 katToken, address optimizerVault, uint256 assets) internal {
        SafeERC20.forceApprove(katToken, address(avKatVault), assets);
        uint256 shares = avKatVault.deposit(assets, optimizerVault);
        emit KATDeposited(assets, shares);
    }

    function _reserveForWithdrawalEntryPoint(IAvKatStrategy conn, uint256 avKATReservedForWithdrawal) internal {
        conn.reserveForWithdrawal(avKATReservedForWithdrawal);
        emit AvKATReservedForWithdrawal(avKATReservedForWithdrawal);
    }

    function _finalizeForWithdrawalEntryPoint(IAvKatStrategy conn) internal {
        RagaEpochVaultStorageLibrary.RagaEpochVaultStorage storage ds = RagaEpochVaultStorageLibrary._getStorage();
        IRagaEpochVault.EpochData storage epochData = RagaEpochVaultStorageLibrary._getProcessingEpochData(ds);
        uint256 sharesBurned = epochData.sharesBurned;

        uint256 avKATFinalized = conn.finalizeForWithdrawal(sharesBurned);
        RagaEpochVaultStorageLibrary._updateEpochWithdrawalInfo(ds, epochData.epoch, avKATFinalized);

        emit AvKATFinalizedForWithdrawal(avKATFinalized, sharesBurned);
    }

    function _reserveAvKATForWithdrawal(uint256 avKATReservedForWithdrawal) internal {
        AvKatStrategyStorage storage s = _getStorage();
        s.avKATReservedForWithdrawal += avKATReservedForWithdrawal;
    }

    function _finalizeAvKATForWithdrawal(uint256 totalSharesToBeClaimed) internal returns (uint256 avKATReserved) {
        AvKatStrategyStorage storage s = _getStorage();

        avKATReserved = s.avKATReservedForWithdrawal;
        (uint256 avKatPresent, bool isNegative) = balance();

        if (isNegative || avKatPresent < avKATReserved) revert InSufficientAvKAT();

        s.avKATFinalizedForWithdrawal += s.avKATReservedForWithdrawal;
        s.totalSharesToBeClaimed += totalSharesToBeClaimed;
        s.avKATReservedForWithdrawal = 0;
    }

    function balance() public view override returns (uint256 delta, bool isNegative) {
        BaseStrategyStorage storage s = _getBaseStrategyStorage();
        AvKatStrategyConfig storage c = _getConfig();

        IERC4626 avKatVault = IERC4626(c.avKatVault);

        uint256 avKATBalance = avKatVault.balanceOf(s.optimizerVault);
        uint256 avKATFinalized = _getStorage().avKATFinalizedForWithdrawal;

        if (avKATBalance < avKATFinalized) {
            delta = avKATFinalized - avKATBalance;
            isNegative = true;
        } else {
            delta = avKATBalance - avKATFinalized;
            isNegative = false;
        }

        delta = avKatVault.convertToAssets(delta);
    }

    function token() external view override returns (address) {
        return _getConfig().avKatVault;
    }

    function isDepositEnabled() external pure override returns (bool) {
        return true;
    }

    function getConfig() external pure returns (AvKatStrategyConfig memory) {
        return _getConfig();
    }

    function avKATFinalizedForWithdrawal() external view returns (uint256) {
        return _getStorage().avKATFinalizedForWithdrawal;
    }

    function encodeCmdForDeposit(uint256 assets) external pure returns (bytes memory) {
        return abi.encode(assets);
    }

    function encodeCmdForReserveForWithdrawal(uint256 avKATReservedForWithdrawal) external pure returns (bytes memory) {
        return abi.encode(avKATReservedForWithdrawal);
    }

    function encodeCmdForFinalizeForWithdrawal(uint256 totalSharesToBeClaimed) external pure returns (bytes memory) {
        return abi.encode(totalSharesToBeClaimed);
    }

    function _decodeCmdForDeposit(bytes calldata cmd) internal pure returns (uint256) {
        return abi.decode(cmd, (uint256));
    }

    function _decodeAvKATReservedForWithdrawal(bytes calldata cmd) internal pure returns (uint256) {
        return abi.decode(cmd, (uint256));
    }

    function _getConfig() internal pure returns (AvKatStrategyConfig storage s) {
        bytes32 slot = STRATEGY_CONFIG_SLOT;
        assembly {
            s.slot := slot
        }
    }

    function _getStorage() internal pure returns (AvKatStrategyStorage storage s) {
        bytes32 slot = STRATEGY_STORAGE_SLOT;
        assembly {
            s.slot := slot
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-20 standard as defined in the ERC.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 value) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC4626.sol)

pragma solidity >=0.6.2;

import {IERC20} from "../token/ERC20/IERC20.sol";
import {IERC20Metadata} from "../token/ERC20/extensions/IERC20Metadata.sol";

/**
 * @dev Interface of the ERC-4626 "Tokenized Vault Standard", as defined in
 * https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
 */
interface IERC4626 is IERC20, IERC20Metadata {
    event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);

    event Withdraw(
        address indexed sender,
        address indexed receiver,
        address indexed owner,
        uint256 assets,
        uint256 shares
    );

    /**
     * @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
     *
     * - MUST be an ERC-20 token contract.
     * - MUST NOT revert.
     */
    function asset() external view returns (address assetTokenAddress);

    /**
     * @dev Returns the total amount of the underlying asset that is “managed” by Vault.
     *
     * - SHOULD include any compounding that occurs from yield.
     * - MUST be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT revert.
     */
    function totalAssets() external view returns (uint256 totalManagedAssets);

    /**
     * @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal
     * scenario where all the conditions are met.
     *
     * - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT show any variations depending on the caller.
     * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
     * - MUST NOT revert.
     *
     * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
     * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
     * from.
     */
    function convertToShares(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal
     * scenario where all the conditions are met.
     *
     * - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT show any variations depending on the caller.
     * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
     * - MUST NOT revert.
     *
     * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
     * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
     * from.
     */
    function convertToAssets(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver,
     * through a deposit call.
     *
     * - MUST return a limited value if receiver is subject to some deposit limit.
     * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
     * - MUST NOT revert.
     */
    function maxDeposit(address receiver) external view returns (uint256 maxAssets);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given
     * current on-chain conditions.
     *
     * - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit
     *   call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called
     *   in the same transaction.
     * - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the
     *   deposit would be accepted, regardless if the user has enough tokens approved, etc.
     * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by depositing.
     */
    function previewDeposit(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
     *
     * - MUST emit the Deposit event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   deposit execution, and are accounted for during deposit.
     * - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not
     *   approving enough underlying tokens to the Vault contract, etc).
     *
     * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
     */
    function deposit(uint256 assets, address receiver) external returns (uint256 shares);

    /**
     * @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
     * - MUST return a limited value if receiver is subject to some mint limit.
     * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
     * - MUST NOT revert.
     */
    function maxMint(address receiver) external view returns (uint256 maxShares);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given
     * current on-chain conditions.
     *
     * - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call
     *   in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the
     *   same transaction.
     * - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint
     *   would be accepted, regardless if the user has enough tokens approved, etc.
     * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by minting.
     */
    function previewMint(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.
     *
     * - MUST emit the Deposit event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint
     *   execution, and are accounted for during mint.
     * - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not
     *   approving enough underlying tokens to the Vault contract, etc).
     *
     * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
     */
    function mint(uint256 shares, address receiver) external returns (uint256 assets);

    /**
     * @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the
     * Vault, through a withdraw call.
     *
     * - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
     * - MUST NOT revert.
     */
    function maxWithdraw(address owner) external view returns (uint256 maxAssets);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block,
     * given current on-chain conditions.
     *
     * - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw
     *   call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if
     *   called
     *   in the same transaction.
     * - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though
     *   the withdrawal would be accepted, regardless if the user has enough shares, etc.
     * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by depositing.
     */
    function previewWithdraw(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver.
     *
     * - MUST emit the Withdraw event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   withdraw execution, and are accounted for during withdraw.
     * - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner
     *   not having enough shares, etc).
     *
     * Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
     * Those methods should be performed separately.
     */
    function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);

    /**
     * @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault,
     * through a redeem call.
     *
     * - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
     * - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
     * - MUST NOT revert.
     */
    function maxRedeem(address owner) external view returns (uint256 maxShares);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their redemption at the current block,
     * given current on-chain conditions.
     *
     * - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
     *   in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the
     *   same transaction.
     * - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
     *   redemption would be accepted, regardless if the user has enough shares, etc.
     * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by redeeming.
     */
    function previewRedeem(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver.
     *
     * - MUST emit the Withdraw event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   redeem execution, and are accounted for during redeem.
     * - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
     *   not having enough shares, etc).
     *
     * NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
     * Those methods should be performed separately.
     */
    function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC-20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    /**
     * @dev An operation with an ERC-20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
        return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
        return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     *
     * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
     * only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
     * set here.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            safeTransfer(token, to, value);
        } else if (!token.transferAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
     * has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferFromAndCallRelaxed(
        IERC1363 token,
        address from,
        address to,
        uint256 value,
        bytes memory data
    ) internal {
        if (to.code.length == 0) {
            safeTransferFrom(token, from, to, value);
        } else if (!token.transferFromAndCall(from, to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
     * Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
     * once without retrying, and relies on the returned value to be true.
     *
     * Reverts if the returned value is other than `true`.
     */
    function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            forceApprove(token, to, value);
        } else if (!token.approveAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            // bubble errors
            if iszero(success) {
                let ptr := mload(0x40)
                returndatacopy(ptr, 0, returndatasize())
                revert(ptr, returndatasize())
            }
            returnSize := returndatasize()
            returnValue := mload(0)
        }

        if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        bool success;
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            returnSize := returndatasize()
            returnValue := mload(0)
        }
        return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
    }
}

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.28;

interface IBaseStrategy {
    struct BaseStrategyStorage {
        address optimizerVault;
    }

    // To be called via delegate
    function processHook(address strategy, uint32 transactionType, bytes calldata cmd) external;

    // To be called via delegate
    function finalizeHook(address strategy, uint32 transactionType, bytes calldata cmd) external;

    // To be called directly. How much asset to be deducted from reserve when claiming withdrawal
    function claimWithdrawalHook(
        uint256 totalSharesForWithdrawal,
        uint256 totalAssetsForWithdrawalInWithdrawalToken
    )
        external;

    function getBaseStrategyConfig() external view returns (BaseStrategyStorage memory);

    // Returns balance for vault accounted by the strategy in terms of underlying token
    function balance() external view returns (uint256, bool);

    // Token whitelisted to be deposited in the strategy
    function token() external view returns (address);

    // Whether user can directly deposits token linked to this strategy
    function isDepositEnabled() external view returns (bool);
}

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.28;

interface IAvKatStrategy {
    struct AvKatStrategyStorage {
        uint256 avKATFinalizedForWithdrawal;
        uint256 avKATReservedForWithdrawal;
        uint256 totalSharesToBeClaimed;
    }

    struct AvKatStrategyConfig {
        address katToken;
        address avKatVault;
    }

    error InSufficientAvKAT();

    event KATDeposited(uint256 assets, uint256 shares);
    event AvKATReservedForWithdrawal(uint256 avKATReservedForWithdrawal);
    event AvKATFinalizedForWithdrawal(uint256 avKATFinalizedForWithdrawal, uint256 totalSharesToBeClaimed);

    function reserveForWithdrawal(uint256 avKATReservedForWithdrawal) external;
    function finalizeForWithdrawal(uint256 totalSharesToBeClaimed) external returns (uint256);

    function avKATFinalizedForWithdrawal() external view returns (uint256);
    function getConfig() external view returns (AvKatStrategyConfig memory);
}

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.28;

interface IRagaEpochVault {
    // Enums
    enum EpochStatus {
        ACTIVE,
        PROCESSING,
        FINALIZED
    }

    // Structs
    struct EpochData {
        uint32 epoch;
        uint48 startTime;
        uint48 endTime;
        // Updated whenever a deposit is made
        uint256 assetsDeposited;
        uint256 sharesMinted;
        // Updated whenever epoch is finalized and withdrawals are processed
        // Asset in terms of withdrawal token
        uint256 assetsWithdrawnInWithdrawalToken;
        // Updated on withdrawal request
        uint256 sharesBurned;
        EpochStatus status;
    }

    struct WithdrawalRequest {
        uint256 shares;
        uint32 epoch;
    }

    // Errors
    error NoEpochProcessing();
    error EpochNotFinalized();
    error EpochNotProcessing();
    error PreviousEpochNotFinalized();

    // Events
    event WithdrawalRequested(address indexed user, uint256 shares, uint256 epoch);
    event WithdrawalClaimed(
        address indexed user, address withdrawalToken, uint256 shares, uint256 assetsInWithdrawalToken
    );

    event EpochStarted(uint256 indexed epoch, uint256 startTime);
    event EpochProcessing(uint256 indexed epoch, uint256 startTime, uint256 endTime, bytes executionData);

    event EpochFinalized(
        uint256 indexed epoch,
        uint256 sharesMinted,
        uint256 assetDeposited,
        uint256 sharesBurned,
        uint256 assetsWithdrawnInWithdrawalToken
    );

    // read-only functions
    function getExecutor() external view returns (address);
    function getCurrentEpoch() external view returns (uint32);
    function getEpochData(uint32 epoch) external view returns (EpochData memory);
    function getWithdrawalToken() external view returns (address);
}

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.28;

import { IERC4626 } from "@openzeppelin/contracts/interfaces/IERC4626.sol";

import { IRagaEpochVault } from "../../interfaces/IRagaEpochVault.sol";
import { IBaseStrategy } from "../../interfaces/optimizer/IBaseStrategy.sol";
import { IOptimizerVault } from "../../interfaces/optimizer/IOptimizerVault.sol";

import { RagaEpochVaultStorageLibrary } from "../../libraries/RagaEpochVaultStorageLibrary.sol";
import { PermissionDenied, ZeroAddress } from "../../utils/Helpers.sol";

abstract contract BaseStrategy is IBaseStrategy {
    bytes32 private constant BASE_STRATEGY_STORAGE_SLOT = keccak256("BaseStrategy.storage") & ~bytes32(uint256(0xff));

    error NoPrimaryDepositToken();
    error NotWithdrawableByUser();
    error InvalidTransactionType(uint32 transactionType);

    modifier onlyOptimizerVault() {
        BaseStrategyStorage storage s = _getBaseStrategyStorage();
        if (msg.sender != s.optimizerVault) revert PermissionDenied();
        _;
    }

    modifier onlyExecutor() {
        BaseStrategyStorage storage s = _getBaseStrategyStorage();
        if (msg.sender != IRagaEpochVault(s.optimizerVault).getExecutor()) revert PermissionDenied();
        _;
    }

    modifier onlyDelegateCall(address strategy) {
        BaseStrategyStorage memory s = IBaseStrategy(strategy).getBaseStrategyConfig();
        if (address(this) != s.optimizerVault) revert PermissionDenied();
        _;
    }

    modifier onlyEpochProcessingDelegate() {
        require(_isEpochProccessingDelegate(), IRagaEpochVault.NoEpochProcessing());
        _;
    }

    modifier onlyEpochProcessing() {
        BaseStrategyStorage storage s = _getBaseStrategyStorage();
        IRagaEpochVault epochVault = IRagaEpochVault(s.optimizerVault);
        require(_isEpochProcessing(epochVault), IRagaEpochVault.NoEpochProcessing());
        _;
    }

    constructor(address optimizerVault) {
        if (optimizerVault == address(0)) revert ZeroAddress();
        BaseStrategyStorage storage s = _getBaseStrategyStorage();
        s.optimizerVault = optimizerVault;
    }

    function getBaseStrategyConfig() external pure override returns (BaseStrategyStorage memory) {
        return _getBaseStrategyStorage();
    }

    function _isEpochProcessing(IRagaEpochVault epochVault) internal view returns (bool) {
        uint32 currentEpoch = epochVault.getCurrentEpoch();
        if (currentEpoch == 0) return false;
        IRagaEpochVault.EpochData memory epochData = epochVault.getEpochData(currentEpoch - 1);
        return epochData.status == IRagaEpochVault.EpochStatus.PROCESSING;
    }

    function _isEpochProccessingDelegate() internal view returns (bool) {
        RagaEpochVaultStorageLibrary.RagaEpochVaultStorage storage s = RagaEpochVaultStorageLibrary._getStorage();
        uint32 currentEpoch = RagaEpochVaultStorageLibrary._getCurrentEpoch(s);
        if (currentEpoch == 0) return false;
        IRagaEpochVault.EpochData storage epochData = RagaEpochVaultStorageLibrary._getEpochData(s, currentEpoch - 1);
        return epochData.status == IRagaEpochVault.EpochStatus.PROCESSING;
    }

    function _getBaseStrategyStorage() internal pure returns (BaseStrategyStorage storage s) {
        bytes32 slot = BASE_STRATEGY_STORAGE_SLOT;
        assembly {
            s.slot := slot
        }
    }
}

File 9 of 18 : Constants.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.28;

library Constants {
    uint256 constant WAD = 1e18;

    uint32 constant FEE_TYPE_DEPOSIT = 1;
    uint32 constant FEE_TYPE_WITHDRAWAL = 2;
    uint32 constant FEE_TYPE_MANAGEMENT = 3;
    uint32 constant FEE_TYPE_PERFORMANCE = 4;

    uint32 constant MORPHO_SUPPLY_TRANSACTION_CODE_SUPPLY = 1001;
    uint32 constant MORPHO_SUPPLY_TRANSACTION_CODE_WITHDRAW = 1002;
    uint32 constant MORPHO_SUPPLY_TRANSACTION_CODE_MAX_WITHDRAWABLE = 1003;
    uint32 constant MORPHO_SUPPLY_TRANSACTION_CODE_WITHDRAW_ALL = 1004;
    uint32 constant MORPHO_SUPPLY_TRANSACTION_CODE_RESET = 1005;
    uint32 constant MORPHO_SUPPLY_TRANASCTION_CODE_RESERVE_FOR_WITHDRAWAL = 1006;
    uint32 constant MORPHO_SUPPLY_TRANSACTION_CODE_FINALIZE = 1007;

    uint32 constant AVKAT_TRANSACTION_CODE_DEPOSIT = 2001;
    uint32 constant AVKAT_TRANSACTION_CODE_RESERVE_FOR_WITHDRAWAL = 2002;
    uint32 constant AVKAT_TRANSACTION_CODE_FINALIZE = 2003;

    uint32 constant KAT_TRANSACTION_CODE_RESERVE_FOR_WITHDRAWAL = 3001;
    uint32 constant KAT_TRANSACTION_CODE_RESET = 3002;
    uint32 constant KAT_TRANSACTION_CODE_FINALIZE = 3003;

    uint32 constant MORPHO_LOOPING_TRANSACTION_CODE_OPEN_POSITION = 4001;
    uint32 constant MORPHO_LOOPING_TRANSACTION_CODE_DEPOSIT_POSITION = 4002;
    uint32 constant MORPHO_LOOPING_TRANSACTION_CODE_WITHDRAW_POSITION = 4003;
    uint32 constant MORPHO_LOOPING_TRANSACTION_CODE_WITHDRAW_ALL_POSITION = 4004;
    uint32 constant MORPHO_LOOPING_TRANSACTION_CODE_RESERVE_FOR_WITHDRAWAL = 4005;
    uint32 constant MORPHO_LOOPING_TRANSACTION_CODE_RESET = 4006;
    uint32 constant MORPHO_LOOPING_TRANSACTION_CODE_FINALIZE = 4007;
}

File 10 of 18 : Helpers.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.28;

// common errors
error IncorrectTypeID(uint256 _typeId, address _sender);
error NegativePriceError();
error PriceStaleError();
error CallFailed();
error NotDepositContract(address _address);
error NotExecutor(address _address);
error NotStrategyContract(address _address);
error IncorrectTokenAddress(address _tokenAddress);
error IncorrectValue();
error IncorrectMessageAddress(address _sender);
error ZeroAddress();
error ZeroAmount();
error ZeroValue();
error MinimumDustAmountError();
error NonPayableFunction();
error DivideByZeroError();
error PermissionDenied();
error InvalidLendingThreshold();

error NotImplemented();

// common events

//deposit events

//deposit

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.28;

import { IRagaEpochVault } from "../interfaces/IRagaEpochVault.sol";
import { WithrawalQueueLibrary } from "./WithrawalQueueLibrary.sol";

library RagaEpochVaultStorageLibrary {
    using WithrawalQueueLibrary for WithrawalQueueLibrary.WithdrawalQueue;

    bytes32 internal constant STORAGE_SLOT = keccak256("raga.epoch.vault.storage") & ~bytes32(uint256(0xff));

    struct RagaEpochVaultStorage {
        address executor;
        uint32 currentEpoch;
        // Token in which user will receive the withdrawal funds
        address withdrawalToken;
        mapping(uint32 => IRagaEpochVault.EpochData) epochs;
        mapping(address => WithrawalQueueLibrary.WithdrawalQueue) userWithdrawalQueue;
        // Shares scheduled for withdrawal, yet to be processed and claimed by the user
        uint256 scheduledWithdrawalShares;
        uint256 totalAssetsReservedForWithdrawalInWithdrawalToken;
    }

    function _getStorage() internal pure returns (RagaEpochVaultStorage storage ds) {
        bytes32 slot = STORAGE_SLOT;
        assembly {
            ds.slot := slot
        }
    }

    function _initStorage(RagaEpochVaultStorage storage ds, address withdrawalToken, address executor) internal {
        ds.withdrawalToken = withdrawalToken;
        ds.executor = executor;
    }

    function _updateEpochDepositInfo(RagaEpochVaultStorage storage ds, uint256 shares, uint256 assets) internal {
        uint32 epoch = ds.currentEpoch;
        IRagaEpochVault.EpochData storage epochData = ds.epochs[epoch];

        epochData.sharesMinted += shares;
        epochData.assetsDeposited += assets;
    }

    function _updateEpochWithdrawalInfo(RagaEpochVaultStorage storage ds, uint32 epoch, uint256 assets) internal {
        IRagaEpochVault.EpochData storage epochData = ds.epochs[epoch];
        if (epochData.status != IRagaEpochVault.EpochStatus.PROCESSING) {
            revert IRagaEpochVault.EpochNotProcessing();
        }

        epochData.assetsWithdrawnInWithdrawalToken += assets;
    }

    function _initializeFirstEpoch(RagaEpochVaultStorage storage ds) internal {
        ds.currentEpoch = 0;

        ds.epochs[0] = IRagaEpochVault.EpochData({
            epoch: 0,
            startTime: uint48(block.timestamp),
            endTime: 0,
            status: IRagaEpochVault.EpochStatus.ACTIVE,
            assetsDeposited: 0,
            assetsWithdrawnInWithdrawalToken: 0,
            sharesMinted: 0,
            sharesBurned: 0
        });
    }

    /**
     * @dev Increments the current epoch and creates a new epoch data entry.
     * @param ds The storage pointer to the RagaEpochVaultStorage struct.
     */
    function _incrementEpoch(RagaEpochVaultStorage storage ds)
        internal
        returns (uint32 newEpoch, uint32 processingEpoch)
    {
        if (ds.currentEpoch > 0) {
            uint32 previousEpoch = ds.currentEpoch - 1;
            if (ds.epochs[previousEpoch].status != IRagaEpochVault.EpochStatus.FINALIZED) {
                revert IRagaEpochVault.PreviousEpochNotFinalized();
            }
        }

        uint48 currentTs = uint48(block.timestamp);

        // Close the current epoch
        ds.epochs[ds.currentEpoch].endTime = currentTs;
        ds.epochs[ds.currentEpoch].status = IRagaEpochVault.EpochStatus.PROCESSING;
        processingEpoch = ds.currentEpoch;

        // Start a new epoch with relevant details
        ds.currentEpoch++;
        ds.epochs[ds.currentEpoch] = IRagaEpochVault.EpochData({
            epoch: ds.currentEpoch,
            startTime: currentTs,
            endTime: 0,
            status: IRagaEpochVault.EpochStatus.ACTIVE,
            assetsDeposited: 0,
            assetsWithdrawnInWithdrawalToken: 0,
            sharesMinted: 0,
            sharesBurned: 0
        });

        newEpoch = ds.currentEpoch;
    }

    function _finalizeEpoch(RagaEpochVaultStorage storage ds, uint32 epoch) internal {
        IRagaEpochVault.EpochData storage proccessingEpoch = ds.epochs[epoch];
        if (proccessingEpoch.status != IRagaEpochVault.EpochStatus.PROCESSING) {
            revert IRagaEpochVault.EpochNotProcessing();
        }

        // Update the status and assets for epoch finalized
        proccessingEpoch.status = IRagaEpochVault.EpochStatus.FINALIZED;

        // Remove the shares burned from the scheduled withdrawal shares as they have been processed
        ds.scheduledWithdrawalShares -= proccessingEpoch.sharesBurned;
    }

    function _createWithdrawalRequest(RagaEpochVaultStorage storage ds, address user, uint256 shares) internal {
        WithrawalQueueLibrary.WithdrawalQueue storage queue = ds.userWithdrawalQueue[user];

        ds.scheduledWithdrawalShares += shares;
        ds.epochs[ds.currentEpoch].sharesBurned += shares;

        if (queue._isEmpty()) {
            queue._enqueue(IRagaEpochVault.WithdrawalRequest({ shares: shares, epoch: ds.currentEpoch }));
            return;
        }

        IRagaEpochVault.WithdrawalRequest storage latestRequest = queue._backMut();
        if (latestRequest.epoch == ds.currentEpoch) {
            latestRequest.shares += shares;
            return;
        }

        queue._enqueue(IRagaEpochVault.WithdrawalRequest({ shares: shares, epoch: ds.currentEpoch }));
    }

    /**
     * @notice Clears the withdrawal queue for a user from all claimable requests
     * @dev Effect step which clears all the claimable requests from the withdrawal queue
     * @param ds The storage pointer to the RagaEpochVaultStorage struct.
     * @param user The address of the user whose withdrawal queue is to be cleared.
     */
    function _aggregateAndClearClaimableWithdrawalRequests(
        RagaEpochVaultStorage storage ds,
        address user
    )
        internal
        returns (uint256 totalShares, uint256 totalAssetsInWithdrawalToken)
    {
        WithrawalQueueLibrary.WithdrawalQueue storage queue = ds.userWithdrawalQueue[user];

        while (!queue._isEmpty()) {
            uint128 idx = queue._head();
            IRagaEpochVault.WithdrawalRequest memory request = queue._peek(idx);

            // Check
            if (ds.epochs[request.epoch].status != IRagaEpochVault.EpochStatus.FINALIZED) {
                break;
            }

            // Effect
            totalShares += request.shares;
            totalAssetsInWithdrawalToken += _calculateAssets(ds, request.epoch, request.shares);

            // Interaction
            queue._dequeueFront();
        }
    }

    function _getCurrentEpoch(RagaEpochVaultStorage storage ds) internal view returns (uint32) {
        return ds.currentEpoch;
    }

    function _getEpochData(
        RagaEpochVaultStorage storage ds,
        uint32 epoch
    )
        internal
        view
        returns (IRagaEpochVault.EpochData storage)
    {
        return ds.epochs[epoch];
    }

    function _getProcessingEpochData(RagaEpochVaultStorage storage ds)
        internal
        view
        returns (IRagaEpochVault.EpochData storage)
    {
        uint32 currentEpoch = _getCurrentEpoch(ds);
        if (currentEpoch == 0) revert IRagaEpochVault.NoEpochProcessing();

        IRagaEpochVault.EpochData storage epochData = _getEpochData(ds, currentEpoch - 1);
        if (epochData.status != IRagaEpochVault.EpochStatus.PROCESSING) revert IRagaEpochVault.NoEpochProcessing();

        return epochData;
    }

    function _aggregateClaimableRequests(
        RagaEpochVaultStorage storage ds,
        address user
    )
        internal
        view
        returns (uint256 totalShares, uint256 totalAssetsInWithdrawalToken)
    {
        WithrawalQueueLibrary.WithdrawalQueue storage queue = ds.userWithdrawalQueue[user];

        for (uint128 i = queue._head(); i < queue._tail(); i++) {
            IRagaEpochVault.WithdrawalRequest memory request = queue._peek(i);

            if (ds.epochs[request.epoch].status != IRagaEpochVault.EpochStatus.FINALIZED) {
                break;
            }

            totalShares += request.shares;
            totalAssetsInWithdrawalToken += _calculateAssets(ds, request.epoch, request.shares);
        }
    }

    function _calculateAssets(
        RagaEpochVaultStorage storage ds,
        uint32 epoch,
        uint256 shares
    )
        internal
        view
        returns (uint256)
    {
        IRagaEpochVault.EpochData storage epochData = ds.epochs[epoch];
        if (epochData.status != IRagaEpochVault.EpochStatus.FINALIZED) revert IRagaEpochVault.EpochNotFinalized();

        if (epochData.sharesBurned == 0) return 0;

        return shares * epochData.assetsWithdrawnInWithdrawalToken / epochData.sharesBurned;
    }

    function _getWithdrawalToken(RagaEpochVaultStorage storage ds) internal view returns (address) {
        return ds.withdrawalToken;
    }

    function _getExecutor(RagaEpochVaultStorage storage ds) internal view returns (address) {
        return ds.executor;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity >=0.6.2;

import {IERC20} from "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC-20 standard.
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)

pragma solidity >=0.6.2;

import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";

/**
 * @title IERC1363
 * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
 *
 * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
 * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
 */
interface IERC1363 is IERC20, IERC165 {
    /*
     * Note: the ERC-165 identifier for this interface is 0xb0202a11.
     * 0xb0202a11 ===
     *   bytes4(keccak256('transferAndCall(address,uint256)')) ^
     *   bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
     */

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @param data Additional data with no specified format, sent in call to `spender`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}

File 14 of 18 : IOptimizerVault.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.28;

interface IOptimizerVault {
    // errors
    error NegativeBalance();

    // structs

    // transactionType: Code to be defined in separately
    struct StrategyExecutionCallData {
        address strategy;
        uint32 transactionType;
        bytes cmd;
    }

    // events
    event DepositToken(address user, address token, uint256 assets, uint256 shares);
    event ClaimWithdrawalHookCalled(
        address strategy, uint256 totalSharesForWithdrawal, uint256 totalAssetsForWithdrawalInWithdrawalToken
    );
    event StrategyProcessHookCalled(address strategy, uint32 transactionType);
    event StrategyFinalizeHookCalled(address strategy, uint32 transactionType);

    event FeeTransferred(address sender, address receiver, address token, uint256 fee);
}

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.28;

import { IRagaEpochVault } from "../interfaces/IRagaEpochVault.sol";

library WithrawalQueueLibrary {
    struct WithdrawalQueue {
        uint128 head;
        uint128 tail;
        mapping(uint128 => IRagaEpochVault.WithdrawalRequest) requestMap;
    }

    function _head(WithdrawalQueue storage queue) internal view returns (uint128) {
        return queue.head;
    }

    function _tail(WithdrawalQueue storage queue) internal view returns (uint128) {
        return queue.tail;
    }

    function _length(WithdrawalQueue storage queue) internal view returns (uint128) {
        return queue.tail - queue.head;
    }

    function _isEmpty(WithdrawalQueue storage queue) internal view returns (bool) {
        return queue.tail == queue.head;
    }

    function _enqueue(WithdrawalQueue storage queue, IRagaEpochVault.WithdrawalRequest memory request) internal {
        uint128 idx = queue.tail;
        queue.requestMap[idx] = request;
        unchecked {
            queue.tail = idx + 1;
        }
    }

    function _dequeueFront(WithdrawalQueue storage queue) internal returns (IRagaEpochVault.WithdrawalRequest memory) {
        require(queue.tail > queue.head, "Queue: empty");

        uint128 idx = queue.head;
        IRagaEpochVault.WithdrawalRequest memory request = queue.requestMap[idx];

        delete queue.requestMap[idx];
        unchecked {
            queue.head = idx + 1;
        }

        return request;
    }

    function _dequeueBack(WithdrawalQueue storage queue) internal returns (IRagaEpochVault.WithdrawalRequest memory) {
        require(queue.tail > queue.head, "Queue: empty");

        uint128 idx = queue.tail - 1;
        IRagaEpochVault.WithdrawalRequest memory request = queue.requestMap[idx];

        delete queue.requestMap[idx];
        unchecked {
            queue.tail = idx;
        }

        return request;
    }

    /**
     * @notice Returns a mutable reference to the last element in the queue.
     */
    function _backMut(WithdrawalQueue storage queue) internal view returns (IRagaEpochVault.WithdrawalRequest storage) {
        require(queue.tail > queue.head, "Queue: empty");
        uint128 idx = queue.tail - 1;
        return queue.requestMap[idx];
    }

    function _peek(
        WithdrawalQueue storage queue,
        uint128 idx
    )
        internal
        view
        returns (IRagaEpochVault.WithdrawalRequest memory)
    {
        require(idx >= queue.head && idx < queue.tail, "Queue: index out of bounds");
        return queue.requestMap[idx];
    }
}

File 16 of 18 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)

pragma solidity >=0.4.16;

import {IERC20} from "../token/ERC20/IERC20.sol";

File 17 of 18 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)

pragma solidity >=0.4.16;

import {IERC165} from "../utils/introspection/IERC165.sol";

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[ERC].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

Settings
{
  "remappings": [
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "@spectra-core/src/=lib/spectra-core/src/",
    "@pythnetwork/pyth-sdk-solidity/=node_modules/@pythnetwork/pyth-sdk-solidity/",
    "hardhat/=node_modules/hardhat/",
    "@morpho-blue/=lib/morpho-blue/",
    "ds-test/=lib/openzeppelin-foundry-upgrades/lib/solidity-stringutils/lib/ds-test/src/",
    "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/",
    "morpho-blue/=lib/morpho-blue/",
    "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "openzeppelin-erc20-basic/=lib/spectra-core/lib/openzeppelin-contracts/contracts/token/ERC20/",
    "openzeppelin-erc20-extensions/=lib/spectra-core/lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/extensions/",
    "openzeppelin-erc20/=lib/spectra-core/lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/",
    "openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/",
    "openzeppelin-math/=lib/spectra-core/lib/openzeppelin-contracts/contracts/utils/math/",
    "openzeppelin-proxy/=lib/spectra-core/lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/",
    "openzeppelin-utils/=lib/spectra-core/lib/openzeppelin-contracts/contracts/utils/",
    "solidity-stringutils/=lib/openzeppelin-foundry-upgrades/lib/solidity-stringutils/",
    "spectra-core/=lib/spectra-core/",
    "v3-core/=lib/v3-core/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 50
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "cancun",
  "viaIR": false
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"address","name":"optimizerVault","type":"address"},{"internalType":"address","name":"avKatVault","type":"address"},{"internalType":"address","name":"katToken","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"EpochNotProcessing","type":"error"},{"inputs":[],"name":"InSufficientAvKAT","type":"error"},{"inputs":[{"internalType":"uint32","name":"transactionType","type":"uint32"}],"name":"InvalidTransactionType","type":"error"},{"inputs":[],"name":"NoEpochProcessing","type":"error"},{"inputs":[],"name":"NoPrimaryDepositToken","type":"error"},{"inputs":[],"name":"NotWithdrawableByUser","type":"error"},{"inputs":[],"name":"PermissionDenied","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"avKATFinalizedForWithdrawal","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalSharesToBeClaimed","type":"uint256"}],"name":"AvKATFinalizedForWithdrawal","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"avKATReservedForWithdrawal","type":"uint256"}],"name":"AvKATReservedForWithdrawal","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"KATDeposited","type":"event"},{"inputs":[],"name":"avKATFinalizedForWithdrawal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"balance","outputs":[{"internalType":"uint256","name":"delta","type":"uint256"},{"internalType":"bool","name":"isNegative","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"totalSharesForWithdrawal","type":"uint256"},{"internalType":"uint256","name":"totalAssetsForWithdrawalInWithdrawalToken","type":"uint256"}],"name":"claimWithdrawalHook","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"encodeCmdForDeposit","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"totalSharesToBeClaimed","type":"uint256"}],"name":"encodeCmdForFinalizeForWithdrawal","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"avKATReservedForWithdrawal","type":"uint256"}],"name":"encodeCmdForReserveForWithdrawal","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"totalSharesToBeClaimed","type":"uint256"}],"name":"finalizeForWithdrawal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"strategy","type":"address"},{"internalType":"uint32","name":"transactionType","type":"uint32"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"finalizeHook","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getBaseStrategyConfig","outputs":[{"components":[{"internalType":"address","name":"optimizerVault","type":"address"}],"internalType":"struct IBaseStrategy.BaseStrategyStorage","name":"","type":"tuple"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"getConfig","outputs":[{"components":[{"internalType":"address","name":"katToken","type":"address"},{"internalType":"address","name":"avKatVault","type":"address"}],"internalType":"struct IAvKatStrategy.AvKatStrategyConfig","name":"","type":"tuple"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"isDepositEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"strategy","type":"address"},{"internalType":"uint32","name":"transactionType","type":"uint32"},{"internalType":"bytes","name":"cmd","type":"bytes"}],"name":"processHook","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"avKATReservedForWithdrawal","type":"uint256"}],"name":"reserveForWithdrawal","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

608060405234801561000f575f5ffd5b5060405161155938038061155983398101604081905261002e9161013d565b826001600160a01b0381166100565760405163d92e233d60e01b815260040160405180910390fd5b5f7feae00031c28a6f170099d0b3cb74122be9df00baf3745c5b377a885957a7070080546001600160a01b0319166001600160a01b039384161790555082166100b25760405163d92e233d60e01b815260040160405180910390fd5b7f80a741b826a3b8d305d3e2c221d2fd9edff4cb06215eccd65201aeaaa62acf2580546001600160a01b039384166001600160a01b0319918216179091557f80a741b826a3b8d305d3e2c221d2fd9edff4cb06215eccd65201aeaaa62acf2480549290931691161790555061017d565b80516001600160a01b0381168114610138575f5ffd5b919050565b5f5f5f6060848603121561014f575f5ffd5b61015884610122565b925061016660208501610122565b915061017460408501610122565b90509250925092565b6113cf8061018a5f395ff3fe608060405234801561000f575f5ffd5b50600436106100b8575f3560e01c806307619fdd146100bc5780634a867833146100d75780634ed106a2146100ec57806353836e8a1461010c5780635656fc781461011f578063583a53d81461012e57806384dca753146100ec578063b69ef8a814610141578063bae7a3461461015e578063c3f909d414610171578063c7b00266146100ec578063ec15946a146101a0578063faa6441b146101b3578063fc0c546a146101d3575b5f5ffd5b6100c46101e8565b6040519081526020015b60405180910390f35b6100ea6100e5366004611030565b6101f7565b005b6100ff6100fa3660046110bc565b6102f3565b6040516100ce91906110d3565b6100ea61011a366004611108565b61031e565b604051600181526020016100ce565b6100ea61013c3660046110bc565b610395565b610149610417565b604080519283529015156020830152016100ce565b6100ea61016c366004611030565b610556565b610179610768565b6040805182516001600160a01b0390811682526020938401511692810192909252016100ce565b6100c46101ae3660046110bc565b6107af565b6101bb610835565b60405190516001600160a01b031681526020016100ce565b6101db610868565b6040516100ce9190611128565b5f6101f1610883565b54919050565b835f816001600160a01b031663faa6441b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610235573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906102599190611171565b80519091506001600160a01b0316301461028657604051630782484160e21b815260040160405180910390fd5b61028e6108a7565b6102ab5760405163a5030a3f60e01b815260040160405180910390fd5b8563ffffffff86166107d3146102e15760405163d8d0a3fd60e01b815263ffffffff871660048201526024015b60405180910390fd5b6102ea81610924565b50505050505050565b60608160405160200161030891815260200190565b6040516020818303038152906040529050919050565b5f610327610a03565b80549091506001600160a01b0316331461035457604051630782484160e21b815260040160405180910390fd5b5f61035d610883565b905083816002015f82825461037291906111dc565b90915550508054839082905f9061038a9084906111dc565b909155505050505050565b5f61039e610a03565b80549091506001600160a01b031633146103cb57604051630782484160e21b815260040160405180910390fd5b5f6103d4610a03565b80549091506001600160a01b03166103eb81610a27565b6104085760405163a5030a3f60e01b815260040160405180910390fd5b61041184610b43565b50505050565b5f5f5f610422610a03565b90505f61042d610b6a565b600181015483546040516370a0823160e01b81529293506001600160a01b03918216925f9284926370a082319261046a9290911690600401611128565b602060405180830381865afa158015610485573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906104a991906111ef565b90505f6104b4610883565b549050808210156104d4576104c982826111dc565b9650600195506104e4565b6104de81836111dc565b96505f95505b6040516303d1689d60e11b8152600481018890526001600160a01b038416906307a2d13a90602401602060405180830381865afa158015610527573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061054b91906111ef565b965050505050509091565b835f816001600160a01b031663faa6441b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610594573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105b89190611171565b80519091506001600160a01b031630146105e557604051630782484160e21b815260040160405180910390fd5b6105ed6108a7565b61060a5760405163a5030a3f60e01b815260040160405180910390fd5b5f8690505f8790505f816001600160a01b031663faa6441b6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561064f573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106739190611171565b90505f836001600160a01b031663c3f909d46040518163ffffffff1660e01b81526004016040805180830381865afa1580156106b1573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106d59190611206565b60208101518151919250906107d01963ffffffff8c1601610712575f6106fb8b8b610b8e565b905061070c8383875f015184610ba4565b5061075a565b6107d11963ffffffff8c1601610739575f61072d8b8b610b8e565b905061070c8782610c5b565b60405163d8d0a3fd60e01b815263ffffffff8c1660048201526024016102d8565b505050505050505050505050565b604080518082019091525f8082526020820152610783610b6a565b6040805180820190915281546001600160a01b0390811682526001909201549091166020820152919050565b5f5f6107b9610a03565b80549091506001600160a01b031633146107e657604051630782484160e21b815260040160405180910390fd5b5f6107ef610a03565b80549091506001600160a01b031661080681610a27565b6108235760405163a5030a3f60e01b815260040160405180910390fd5b61082c85610ced565b95945050505050565b60408051602081019091525f815261084b610a03565b604080516020810190915290546001600160a01b03168152919050565b5f610871610b6a565b600101546001600160a01b0316919050565b7f3813c4bc1bdb04a115036bf293df8cfb179bb8d70bccc6ecb9dc1d8fc31972f590565b5f5f6108b1610d7e565b90505f6108bd82610da2565b90508063ffffffff165f036108d4575f9250505090565b5f6108fe836108e4600185611270565b63ffffffff165f9081526002919091016020526040902090565b90506001600582015460ff16600281111561091b5761091b61128c565b14935050505090565b5f61092d610d7e565b90505f61093982610db3565b60048181015460405163760aca3560e11b81529182018190529192505f906001600160a01b0386169063ec15946a906024016020604051808303815f875af1158015610987573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109ab91906111ef565b83549091506109c290859063ffffffff1683610e38565b60408051828152602081018490527fe33d76b12a4f6daa57c45901bedceb7f30a071f7801adf4b3220cfc37d2b7ef891015b60405180910390a15050505050565b7feae00031c28a6f170099d0b3cb74122be9df00baf3745c5b377a885957a7070090565b5f5f826001600160a01b031663b97dd9e26040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a65573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610a8991906112a0565b90508063ffffffff165f03610aa057505f92915050565b5f6001600160a01b03841663f2ae9d0b610abb600185611270565b6040516001600160e01b031960e084901b16815263ffffffff91909116600482015260240161010060405180830381865afa158015610afc573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610b2091906112e3565b905060018160e001516002811115610b3a57610b3a61128c565b14949350505050565b5f610b4c610883565b905081816001015f828254610b61919061136d565b90915550505050565b7f80a741b826a3b8d305d3e2c221d2fd9edff4cb06215eccd65201aeaaa62acf2490565b5f610b9b828401846110bc565b90505b92915050565b610baf838583610e9a565b604051636e553f6560e01b8152600481018290526001600160a01b0383811660248301525f9190861690636e553f65906044016020604051808303815f875af1158015610bfe573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c2291906111ef565b60408051848152602081018390529192507f6d302cb1bbe743fa2dc400c5831a385f4f8886539d42207f9ddf6f30023b2b4391016109f4565b604051630b074a7b60e31b8152600481018290526001600160a01b0383169063583a53d8906024015f604051808303815f87803b158015610c9a575f5ffd5b505af1158015610cac573d5f5f3e3d5ffd5b505050507f4d075d0b1dd23f7077e436c1e01c956544dc64b18c9a086f75a4796a1d0e79a981604051610ce191815260200190565b60405180910390a15050565b5f5f610cf7610883565b9050806001015491505f5f610d0a610417565b915091508080610d1957508382105b15610d37576040516305b22f7b60e41b815260040160405180910390fd5b8260010154835f015f828254610d4d919061136d565b9250508190555084836002015f828254610d67919061136d565b90915550505f600190930192909255509092915050565b7f09232bebc33d8ffa7aaa574d9b368412805f314ca7c9b8bb526f2051d6c1960090565b54600160a01b900463ffffffff1690565b5f5f610dbe83610da2565b90508063ffffffff165f03610de65760405163a5030a3f60e01b815260040160405180910390fd5b5f610df6846108e4600185611270565b90506001600582015460ff166002811115610e1357610e1361128c565b14610e315760405163a5030a3f60e01b815260040160405180910390fd5b9392505050565b63ffffffff82165f90815260028401602052604090206001600582015460ff166002811115610e6957610e6961128c565b14610e875760405163d09ff6c360e01b815260040160405180910390fd5b81816003015f82825461038a919061136d565b5f836001600160a01b031663095ea7b38484604051602401610ebd929190611380565b604051602081830303815290604052915060e01b6020820180516001600160e01b0383818316178352505050509050610ef68482610f5c565b61041157610f5284856001600160a01b031663095ea7b3865f604051602401610f20929190611380565b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050610fa5565b6104118482610fa5565b5f5f5f5f60205f8651602088015f8a5af192503d91505f519050828015610f9b57508115610f8d5780600114610f9b565b5f866001600160a01b03163b115b9695505050505050565b5f5f60205f8451602086015f885af180610fc4576040513d5f823e3d81fd5b50505f513d91508115610fdb578060011415610fe8565b6001600160a01b0384163b155b156104115783604051635274afe760e01b81526004016102d89190611128565b6001600160a01b038116811461101c575f5ffd5b50565b63ffffffff8116811461101c575f5ffd5b5f5f5f5f60608587031215611043575f5ffd5b843561104e81611008565b9350602085013561105e8161101f565b925060408501356001600160401b03811115611078575f5ffd5b8501601f81018713611088575f5ffd5b80356001600160401b0381111561109d575f5ffd5b8760208284010111156110ae575f5ffd5b949793965060200194505050565b5f602082840312156110cc575f5ffd5b5035919050565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b5f5f60408385031215611119575f5ffd5b50508035926020909101359150565b6001600160a01b0391909116815260200190565b60405161010081016001600160401b038111828210171561116b57634e487b7160e01b5f52604160045260245ffd5b60405290565b5f6020828403128015611182575f5ffd5b50604051602081016001600160401b03811182821017156111b157634e487b7160e01b5f52604160045260245ffd5b60405282516111bf81611008565b81529392505050565b634e487b7160e01b5f52601160045260245ffd5b81810381811115610b9e57610b9e6111c8565b5f602082840312156111ff575f5ffd5b5051919050565b5f6040828403128015611217575f5ffd5b50604080519081016001600160401b038111828210171561124657634e487b7160e01b5f52604160045260245ffd5b604052825161125481611008565b8152602083015161126481611008565b60208201529392505050565b63ffffffff8281168282160390811115610b9e57610b9e6111c8565b634e487b7160e01b5f52602160045260245ffd5b5f602082840312156112b0575f5ffd5b8151610e318161101f565b805165ffffffffffff811681146112d0575f5ffd5b919050565b8051600381106112d0575f5ffd5b5f6101008284031280156112f5575f5ffd5b506112fe61113c565b82516113098161101f565b8152611317602084016112bb565b6020820152611328604084016112bb565b6040820152606083810151908201526080808401519082015260a0808401519082015260c0808401519082015261136160e084016112d5565b60e08201529392505050565b80820180821115610b9e57610b9e6111c8565b6001600160a01b0392909216825260208201526040019056fea2646970667358221220dac2b43818b4aa134a712a0f88ff26d1772f4a57ff99a238ae154c47e6241b1564736f6c634300081c0033000000000000000000000000c385fee416dcd3731aa3abdccd36dd57dca01223000000000000000000000000297612c171fc8adce32ac333085a9ee1f2bcc1da000000000000000000000000cd6863bb697d7cee5b7ed8dea7d803374f7e4aa6

Deployed Bytecode

0x608060405234801561000f575f5ffd5b50600436106100b8575f3560e01c806307619fdd146100bc5780634a867833146100d75780634ed106a2146100ec57806353836e8a1461010c5780635656fc781461011f578063583a53d81461012e57806384dca753146100ec578063b69ef8a814610141578063bae7a3461461015e578063c3f909d414610171578063c7b00266146100ec578063ec15946a146101a0578063faa6441b146101b3578063fc0c546a146101d3575b5f5ffd5b6100c46101e8565b6040519081526020015b60405180910390f35b6100ea6100e5366004611030565b6101f7565b005b6100ff6100fa3660046110bc565b6102f3565b6040516100ce91906110d3565b6100ea61011a366004611108565b61031e565b604051600181526020016100ce565b6100ea61013c3660046110bc565b610395565b610149610417565b604080519283529015156020830152016100ce565b6100ea61016c366004611030565b610556565b610179610768565b6040805182516001600160a01b0390811682526020938401511692810192909252016100ce565b6100c46101ae3660046110bc565b6107af565b6101bb610835565b60405190516001600160a01b031681526020016100ce565b6101db610868565b6040516100ce9190611128565b5f6101f1610883565b54919050565b835f816001600160a01b031663faa6441b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610235573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906102599190611171565b80519091506001600160a01b0316301461028657604051630782484160e21b815260040160405180910390fd5b61028e6108a7565b6102ab5760405163a5030a3f60e01b815260040160405180910390fd5b8563ffffffff86166107d3146102e15760405163d8d0a3fd60e01b815263ffffffff871660048201526024015b60405180910390fd5b6102ea81610924565b50505050505050565b60608160405160200161030891815260200190565b6040516020818303038152906040529050919050565b5f610327610a03565b80549091506001600160a01b0316331461035457604051630782484160e21b815260040160405180910390fd5b5f61035d610883565b905083816002015f82825461037291906111dc565b90915550508054839082905f9061038a9084906111dc565b909155505050505050565b5f61039e610a03565b80549091506001600160a01b031633146103cb57604051630782484160e21b815260040160405180910390fd5b5f6103d4610a03565b80549091506001600160a01b03166103eb81610a27565b6104085760405163a5030a3f60e01b815260040160405180910390fd5b61041184610b43565b50505050565b5f5f5f610422610a03565b90505f61042d610b6a565b600181015483546040516370a0823160e01b81529293506001600160a01b03918216925f9284926370a082319261046a9290911690600401611128565b602060405180830381865afa158015610485573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906104a991906111ef565b90505f6104b4610883565b549050808210156104d4576104c982826111dc565b9650600195506104e4565b6104de81836111dc565b96505f95505b6040516303d1689d60e11b8152600481018890526001600160a01b038416906307a2d13a90602401602060405180830381865afa158015610527573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061054b91906111ef565b965050505050509091565b835f816001600160a01b031663faa6441b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610594573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105b89190611171565b80519091506001600160a01b031630146105e557604051630782484160e21b815260040160405180910390fd5b6105ed6108a7565b61060a5760405163a5030a3f60e01b815260040160405180910390fd5b5f8690505f8790505f816001600160a01b031663faa6441b6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561064f573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106739190611171565b90505f836001600160a01b031663c3f909d46040518163ffffffff1660e01b81526004016040805180830381865afa1580156106b1573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106d59190611206565b60208101518151919250906107d01963ffffffff8c1601610712575f6106fb8b8b610b8e565b905061070c8383875f015184610ba4565b5061075a565b6107d11963ffffffff8c1601610739575f61072d8b8b610b8e565b905061070c8782610c5b565b60405163d8d0a3fd60e01b815263ffffffff8c1660048201526024016102d8565b505050505050505050505050565b604080518082019091525f8082526020820152610783610b6a565b6040805180820190915281546001600160a01b0390811682526001909201549091166020820152919050565b5f5f6107b9610a03565b80549091506001600160a01b031633146107e657604051630782484160e21b815260040160405180910390fd5b5f6107ef610a03565b80549091506001600160a01b031661080681610a27565b6108235760405163a5030a3f60e01b815260040160405180910390fd5b61082c85610ced565b95945050505050565b60408051602081019091525f815261084b610a03565b604080516020810190915290546001600160a01b03168152919050565b5f610871610b6a565b600101546001600160a01b0316919050565b7f3813c4bc1bdb04a115036bf293df8cfb179bb8d70bccc6ecb9dc1d8fc31972f590565b5f5f6108b1610d7e565b90505f6108bd82610da2565b90508063ffffffff165f036108d4575f9250505090565b5f6108fe836108e4600185611270565b63ffffffff165f9081526002919091016020526040902090565b90506001600582015460ff16600281111561091b5761091b61128c565b14935050505090565b5f61092d610d7e565b90505f61093982610db3565b60048181015460405163760aca3560e11b81529182018190529192505f906001600160a01b0386169063ec15946a906024016020604051808303815f875af1158015610987573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109ab91906111ef565b83549091506109c290859063ffffffff1683610e38565b60408051828152602081018490527fe33d76b12a4f6daa57c45901bedceb7f30a071f7801adf4b3220cfc37d2b7ef891015b60405180910390a15050505050565b7feae00031c28a6f170099d0b3cb74122be9df00baf3745c5b377a885957a7070090565b5f5f826001600160a01b031663b97dd9e26040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a65573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610a8991906112a0565b90508063ffffffff165f03610aa057505f92915050565b5f6001600160a01b03841663f2ae9d0b610abb600185611270565b6040516001600160e01b031960e084901b16815263ffffffff91909116600482015260240161010060405180830381865afa158015610afc573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610b2091906112e3565b905060018160e001516002811115610b3a57610b3a61128c565b14949350505050565b5f610b4c610883565b905081816001015f828254610b61919061136d565b90915550505050565b7f80a741b826a3b8d305d3e2c221d2fd9edff4cb06215eccd65201aeaaa62acf2490565b5f610b9b828401846110bc565b90505b92915050565b610baf838583610e9a565b604051636e553f6560e01b8152600481018290526001600160a01b0383811660248301525f9190861690636e553f65906044016020604051808303815f875af1158015610bfe573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c2291906111ef565b60408051848152602081018390529192507f6d302cb1bbe743fa2dc400c5831a385f4f8886539d42207f9ddf6f30023b2b4391016109f4565b604051630b074a7b60e31b8152600481018290526001600160a01b0383169063583a53d8906024015f604051808303815f87803b158015610c9a575f5ffd5b505af1158015610cac573d5f5f3e3d5ffd5b505050507f4d075d0b1dd23f7077e436c1e01c956544dc64b18c9a086f75a4796a1d0e79a981604051610ce191815260200190565b60405180910390a15050565b5f5f610cf7610883565b9050806001015491505f5f610d0a610417565b915091508080610d1957508382105b15610d37576040516305b22f7b60e41b815260040160405180910390fd5b8260010154835f015f828254610d4d919061136d565b9250508190555084836002015f828254610d67919061136d565b90915550505f600190930192909255509092915050565b7f09232bebc33d8ffa7aaa574d9b368412805f314ca7c9b8bb526f2051d6c1960090565b54600160a01b900463ffffffff1690565b5f5f610dbe83610da2565b90508063ffffffff165f03610de65760405163a5030a3f60e01b815260040160405180910390fd5b5f610df6846108e4600185611270565b90506001600582015460ff166002811115610e1357610e1361128c565b14610e315760405163a5030a3f60e01b815260040160405180910390fd5b9392505050565b63ffffffff82165f90815260028401602052604090206001600582015460ff166002811115610e6957610e6961128c565b14610e875760405163d09ff6c360e01b815260040160405180910390fd5b81816003015f82825461038a919061136d565b5f836001600160a01b031663095ea7b38484604051602401610ebd929190611380565b604051602081830303815290604052915060e01b6020820180516001600160e01b0383818316178352505050509050610ef68482610f5c565b61041157610f5284856001600160a01b031663095ea7b3865f604051602401610f20929190611380565b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050610fa5565b6104118482610fa5565b5f5f5f5f60205f8651602088015f8a5af192503d91505f519050828015610f9b57508115610f8d5780600114610f9b565b5f866001600160a01b03163b115b9695505050505050565b5f5f60205f8451602086015f885af180610fc4576040513d5f823e3d81fd5b50505f513d91508115610fdb578060011415610fe8565b6001600160a01b0384163b155b156104115783604051635274afe760e01b81526004016102d89190611128565b6001600160a01b038116811461101c575f5ffd5b50565b63ffffffff8116811461101c575f5ffd5b5f5f5f5f60608587031215611043575f5ffd5b843561104e81611008565b9350602085013561105e8161101f565b925060408501356001600160401b03811115611078575f5ffd5b8501601f81018713611088575f5ffd5b80356001600160401b0381111561109d575f5ffd5b8760208284010111156110ae575f5ffd5b949793965060200194505050565b5f602082840312156110cc575f5ffd5b5035919050565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b5f5f60408385031215611119575f5ffd5b50508035926020909101359150565b6001600160a01b0391909116815260200190565b60405161010081016001600160401b038111828210171561116b57634e487b7160e01b5f52604160045260245ffd5b60405290565b5f6020828403128015611182575f5ffd5b50604051602081016001600160401b03811182821017156111b157634e487b7160e01b5f52604160045260245ffd5b60405282516111bf81611008565b81529392505050565b634e487b7160e01b5f52601160045260245ffd5b81810381811115610b9e57610b9e6111c8565b5f602082840312156111ff575f5ffd5b5051919050565b5f6040828403128015611217575f5ffd5b50604080519081016001600160401b038111828210171561124657634e487b7160e01b5f52604160045260245ffd5b604052825161125481611008565b8152602083015161126481611008565b60208201529392505050565b63ffffffff8281168282160390811115610b9e57610b9e6111c8565b634e487b7160e01b5f52602160045260245ffd5b5f602082840312156112b0575f5ffd5b8151610e318161101f565b805165ffffffffffff811681146112d0575f5ffd5b919050565b8051600381106112d0575f5ffd5b5f6101008284031280156112f5575f5ffd5b506112fe61113c565b82516113098161101f565b8152611317602084016112bb565b6020820152611328604084016112bb565b6040820152606083810151908201526080808401519082015260a0808401519082015260c0808401519082015261136160e084016112d5565b60e08201529392505050565b80820180821115610b9e57610b9e6111c8565b6001600160a01b0392909216825260208201526040019056fea2646970667358221220dac2b43818b4aa134a712a0f88ff26d1772f4a57ff99a238ae154c47e6241b1564736f6c634300081c0033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

000000000000000000000000c385fee416dcd3731aa3abdccd36dd57dca01223000000000000000000000000297612c171fc8adce32ac333085a9ee1f2bcc1da000000000000000000000000cd6863bb697d7cee5b7ed8dea7d803374f7e4aa6

-----Decoded View---------------
Arg [0] : optimizerVault (address): 0xC385FeE416DCd3731Aa3aBDCCd36dd57dca01223
Arg [1] : avKatVault (address): 0x297612c171fc8ADce32ac333085a9Ee1F2BCC1Da
Arg [2] : katToken (address): 0xCD6863bB697d7CEE5b7Ed8deA7D803374F7e4Aa6

-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 000000000000000000000000c385fee416dcd3731aa3abdccd36dd57dca01223
Arg [1] : 000000000000000000000000297612c171fc8adce32ac333085a9ee1f2bcc1da
Arg [2] : 000000000000000000000000cd6863bb697d7cee5b7ed8dea7d803374f7e4aa6


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.