Developer Docs
Smart Contracts
Reinvest Library
Reinvest Modules
Aave V3

Aave V3 Reinvest Modual

Allows users to instantly deposit accepted tokens into the Aave V3 protocol after the strategy swap execution.

Functions

_execute

 function _execute(
        uint256 amount_,
        bytes memory data_
    ) internal returns (uint256 amount, bool success)

Executes the the Aave V3 reinvest logic

Parameters

NameTypeDescription
amount_uint256Amount to input to the Reinvest
data_bytesEncoded Reinvest data

Returns

NameTypeDescription
amountuint256Amount of liquidety token retunred
successboolIf the reinvest was successfull
   function _execute(
        uint256 amount_,
        bytes memory data_
    ) internal returns (uint256 amount, bool success) {
        ReinvestDataStruct memory investData = _decodeData(data_);
 
        uint256 oldBalance = IERC20(investData.aToken).balanceOf(address(this));
 
        bool approvalSuccess = IERC20(investData.token).approve(
            address(AAVE_POOL),
            amount_
        );
 
        if (approvalSuccess) {
            AAVE_POOL.supply(investData.token, amount_, address(this), 0);
 
            uint256 newBalance = IERC20(investData.aToken).balanceOf(
                address(this)
            );
 
            amount = newBalance - oldBalance;
            success = amount > 0;
        }
 
        return (amount, success);
    }

_unwind

 function _unwind(
        uint256 amount_,
        bytes memory data_
    ) internal returns (uint256 amount, bool success)

Executes the the Aave V3 unwind logic

Parameters

NameTypeDescription
amount_uint256Amount of the liqidety token to unwind
data_bytesEncoded Reinvest data

Returns

NameTypeDescription
amountuint256Amount of token returned
successboolIf the unwind was successfull
   function _unwind(
        uint256 amount_,
        bytes memory data_
    ) internal returns (uint256 amount, bool success) {
        ReinvestDataStruct memory investData = _decodeData(data_);
        amount = AAVE_POOL.withdraw(investData.token, amount_, address(this));
 
        success = amount > 0;
        return (amount, success);
    }

_decodeData

  function _decodeData(
        bytes memory data_
    ) private pure returns (ReinvestDataStruct memory) 

Decode the reinvest data

Parameters

NameTypeDescription
data_bytesEncoded Reinvest data

Returns

NameTypeDescription
_0ReinvestDataStructThe Reinvest data
    function _decodeData(
        bytes memory data_
    ) private pure returns (ReinvestDataStruct memory) {
        return abi.decode(data_, (ReinvestDataStruct));
    }
}