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
| Name | Type | Description |
|---|---|---|
| amount_ | uint256 | Amount to input to the Reinvest |
| data_ | bytes | Encoded Reinvest data |
Returns
| Name | Type | Description |
|---|---|---|
| amount | uint256 | Amount of liquidety token retunred |
| success | bool | If 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
| Name | Type | Description |
|---|---|---|
| amount_ | uint256 | Amount of the liqidety token to unwind |
| data_ | bytes | Encoded Reinvest data |
Returns
| Name | Type | Description |
|---|---|---|
| amount | uint256 | Amount of token returned |
| success | bool | If 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
| Name | Type | Description |
|---|---|---|
| data_ | bytes | Encoded Reinvest data |
Returns
| Name | Type | Description |
|---|---|---|
| _0 | ReinvestDataStruct | The Reinvest data |
function _decodeData(
bytes memory data_
) private pure returns (ReinvestDataStruct memory) {
return abi.decode(data_, (ReinvestDataStruct));
}
}