StrategAaveV3PositionManager
This contract manages positions within the Aave V3 protocol, enabling strategies that involve leveraging, unleveraging, and rebalancing of assets. It interacts with Aave's lending pool to supply collateral, borrow assets, and manage debt positions, while also utilizing a portal for asset swaps necessary for strategy execution. The contract supports operations such as initializing a position with specific parameters, leveraging up or down a position, and rebalancing based on health factor thresholds.
Methods
blockIndex
The index of the block at which the position was created.
Returns
_0
uint256
undefined
borrow
Initiates a borrowing operation to adjust the position's health factor.
This function allows for borrowing additional debt based on the provided collateral amount. It ensures that the operation adheres to the position's desired health factor constraints.
Parameters
_addCollateralAmount
uint256
The amount of additional collateral to be deposited before borrowing.
borrowAmountFor
Calculates the amount that can be borrowed for a given collateral amount.
This function computes the borrow amount based on the collateral's value, loan-to-value ratio, and the desired health factor.
Parameters
_collateral
uint256
The amount of collateral to be deposited.
Returns
_0
uint256
borrowAmount The maximum amount that can be borrowed.
borrowStatus
Retrieves the borrowing status of the current position.
Parameters
_withSpecificAvailableTokenForRepay
bool
Indicates if a specific token amount is available for repayment.
_availableTokenForRepay
uint256
The amount of token available for repayment if _withSpecificAvailableTokenForRepay
is true.
Returns
status
IStrategAaveV3PositionManager.BorrowStatus
The borrowing status of the current position as a BorrowStatus
struct.
executeOperation
Handles the callback from Aave's flashloan operation.
This function is called by Aave's lending pool contract after a flashloan is executed. It processes the flashloan based on the callback type specified in the flashloan parameters.
Parameters
_0
address[]
undefined
_amounts
uint256[]
The amounts of the assets borrowed in the flashloan.
_premiums
uint256[]
The fees associated with the flashloan.
_initiator
address
The initiator of the flashloan.
_params
bytes
Encoded flashloan parameters including the callback type and any additional data required for processing the flashloan.
Returns
_0
bool
Returns true if the flashloan callback was executed successfully.
initialize
Initializes the position manager with the specified parameters.
This function sets the initial state of the position manager, including owner, block index, and position details. It can only be called once.
Parameters
_owner
address
The address of the owner of the position.
_blockIndex
uint256
The index of the block at which the position is created.
_params
bytes
Encoded initialization parameters for the position.
initialized
Indicates whether the contract has been initialized.
Returns
_0
bool
undefined
leverage
Leverages the position by adding collateral and borrowing more debt to increase the position size.
This function transfers the specified amount of collateral from the caller, leverages it by borrowing more debt, and then deposits the collateral back into the pool. It ensures that the health factor of the position remains within the desired range after leveraging.
Parameters
_addCollateralAmount
uint256
The amount of additional collateral to add to the position.
_dynamicParams
bytes
Encoded dynamic parameters for the leverage operation, including the amount to borrow.
leverageStatus
Retrieves the current leverage status of the position.
This function returns the leverage status including the health factor, desired health factor, whether rebalancing is needed, the collateral amount, and the debt amount.
Returns
status
IStrategAaveV3PositionManager.LeverageStatus
The current leverage status of the position.
operator
The address of the operator.
Returns
_0
address
undefined
oracle
The Aave protocol's oracle contract.
Returns
_0
contract IAaveOracle
undefined
owner
The owner of the position.
Returns
_0
address
undefined
pool
The Aave protocol's pool contract.
Returns
_0
contract IPool
undefined
portal
The portal contract to execute swap
Returns
_0
contract IStrategPortal
undefined
position
Returns the current position of the strategy.
This function provides a view into the current state of the strategy's position, including leverage mode, eMode category, oracle, collateral, debt, and health factor details.
Returns
_0
IStrategAaveV3PositionManager.Position
The current position of the strategy as a Position
struct.
rebalance
Parameters
params
IStrategPositionManager.RebalanceData
undefined
refreshAaveData
Updates the Aave data for the current position.
This function refreshes the loan-to-value (LTV) and liquidation threshold (LTS) of the collateral based on whether eMode is enabled or disabled for the position. If eMode is enabled, it also updates the oracle address used for price information. This is necessary to keep the position's parameters in sync with the latest data from the Aave protocol.
repay
Repays the borrowed asset to close the position.
This function repays the debt of the position, potentially using a dynamic swap if the debt token balance is insufficient. It ensures the position's health factor is adjusted appropriately.
Parameters
_dynamicParams
bytes
Encoded dynamic parameters for swap operations, if needed.
_percent
uint256
undefined
returnedAmountAfterRepay
Calculates the collateral amount returned after a specified debt amount is repaid.
This function computes the returned collateral amount after repaying a portion of the debt, taking into account the current prices of the collateral and debt assets.
Parameters
_repay
uint256
The amount of debt to be repaid.
_percent
uint256
undefined
Returns
_0
uint256
collateralAmount The amount of collateral returned after the debt repayment.
returnedAmountAfterUnleverage
Calculates the collateral amount returned after unleveraging the position.
This function computes the returned collateral amount after completely unleveraging the position, taking into account the current price of the collateral asset.
Parameters
_percent
uint256
undefined
Returns
_0
uint256
collateralAmount The amount of collateral returned after the position is completely unleveraged.
unleverage
Initiates the process to unleverage the current position.
This function calls the internal _unleverage function with the dynamic parameters provided.
Parameters
_dynamicParams
bytes
Encoded dynamic parameters for the unleverage operation.
_percent
uint256
undefined
Errors
AddressEmptyCode
There's no code at target
(it is not a contract).
Parameters
target
address
undefined
AddressInsufficientBalance
The ETH balance of the account is not enough to perform the operation.
Parameters
account
address
undefined
AlreadyInitialized
Error thrown when the contract has already been initialized.
BorrowOnly
Error thrown when the operation is not a borrow operation.
FailedInnerCall
A call to an address target failed. The target may have reverted.
LeverageHealthfactorNotMatch
Error thrown when the leverage operation does not match the desired health factor.
LeverageOnly
Error thrown when the operation is not a leverage operation.
NotAavePool
Error thrown when the caller is not the Aave pool.
NotOperator
Error thrown when the caller is not an operator.
NotOwner
Error thrown when the caller is not the owner.
RepayNotCoveredWithSwap
Error thrown when a repay operation is not covered by a swap.
SafeERC20FailedOperation
An operation with an ERC20 token failed.
Parameters
token
address
undefined
UnleverageNotComplete
Error thrown when the unleverage operation is not complete.
WrongInitiator
Error thrown when the initiator of the operation is wrong.
Last updated