Developers Documentation
  • Overview
    • Contracts Overview
    • Public Repositories
    • Smart Contract Addresses
      • Polygon PoS
  • Core protocol
    • Architecture Overview
    • Blocks
    • Vault Strategy
    • Vault Configuration
    • Vault Deployment
    • Vault Operations
    • Access Manager
    • Contracts
      • StrategVault
      • StrategERC3525
      • StrategVaultFactory
      • StrategAssetBuffer
      • StrategBlockRegistry
      • StrategUserInteractions
      • StrategOperatorProxy
      • StrategOperatorDataAggregator
  • Borrow module
    • Architecture Overview
    • Aave V3 Position manager
    • Smart Contract Docs
      • StrategPositionManagerFactory
      • StrategAaveV3PositionManager
      • StrategAaveV3PositionManagerInfo
  • Portal Module
    • Architecture Overview
    • Swap
      • Features
      • Functions
    • Oracle
      • Architecture design
      • Functions
  • Tools
    • Developer kit
Powered by GitBook
On this page
  • Methods
  • blockIndex
  • borrow
  • borrowAmountFor
  • borrowStatus
  • executeOperation
  • initialize
  • initialized
  • leverage
  • leverageStatus
  • operator
  • oracle
  • owner
  • pool
  • portal
  • position
  • rebalance
  • refreshAaveData
  • repay
  • returnedAmountAfterRepay
  • returnedAmountAfterUnleverage
  • unleverage
  • Errors
  • AddressEmptyCode
  • AddressInsufficientBalance
  • AlreadyInitialized
  • BorrowOnly
  • FailedInnerCall
  • LeverageHealthfactorNotMatch
  • LeverageOnly
  • NotAavePool
  • NotOperator
  • NotOwner
  • RepayNotCoveredWithSwap
  • SafeERC20FailedOperation
  • UnleverageNotComplete
  • WrongInitiator
  1. Borrow module
  2. Smart Contract Docs

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

function blockIndex() external view returns (uint256)

The index of the block at which the position was created.

Returns

Name
Type
Description

_0

uint256

undefined

borrow

function borrow(uint256 _addCollateralAmount) external nonpayable

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

Name
Type
Description

_addCollateralAmount

uint256

The amount of additional collateral to be deposited before borrowing.

borrowAmountFor

function borrowAmountFor(uint256 _collateral) external view returns (uint256)

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

Name
Type
Description

_collateral

uint256

The amount of collateral to be deposited.

Returns

Name
Type
Description

_0

uint256

borrowAmount The maximum amount that can be borrowed.

borrowStatus

function borrowStatus(bool _withSpecificAvailableTokenForRepay, uint256 _availableTokenForRepay) external view returns (struct IStrategAaveV3PositionManager.BorrowStatus status)

Retrieves the borrowing status of the current position.

Parameters

Name
Type
Description

_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

Name
Type
Description

status

IStrategAaveV3PositionManager.BorrowStatus

The borrowing status of the current position as a BorrowStatus struct.

executeOperation

function executeOperation(address[], uint256[] _amounts, uint256[] _premiums, address _initiator, bytes _params) external nonpayable returns (bool)

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

Name
Type
Description

_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

Name
Type
Description

_0

bool

Returns true if the flashloan callback was executed successfully.

initialize

function initialize(address _owner, uint256 _blockIndex, bytes _params) external nonpayable

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

Name
Type
Description

_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

function initialized() external view returns (bool)

Indicates whether the contract has been initialized.

Returns

Name
Type
Description

_0

bool

undefined

leverage

function leverage(uint256 _addCollateralAmount, bytes _dynamicParams) external nonpayable

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

Name
Type
Description

_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

function leverageStatus() external view returns (struct IStrategAaveV3PositionManager.LeverageStatus status)

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

Name
Type
Description

status

IStrategAaveV3PositionManager.LeverageStatus

The current leverage status of the position.

operator

function operator() external view returns (address)

The address of the operator.

Returns

Name
Type
Description

_0

address

undefined

oracle

function oracle() external view returns (contract IAaveOracle)

The Aave protocol's oracle contract.

Returns

Name
Type
Description

_0

contract IAaveOracle

undefined

owner

function owner() external view returns (address)

The owner of the position.

Returns

Name
Type
Description

_0

address

undefined

pool

function pool() external view returns (contract IPool)

The Aave protocol's pool contract.

Returns

Name
Type
Description

_0

contract IPool

undefined

portal

function portal() external view returns (contract IStrategPortal)

The portal contract to execute swap

Returns

Name
Type
Description

_0

contract IStrategPortal

undefined

position

function position() external view returns (struct IStrategAaveV3PositionManager.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

Name
Type
Description

_0

IStrategAaveV3PositionManager.Position

The current position of the strategy as a Position struct.

rebalance

function rebalance(IStrategPositionManager.RebalanceData params) external nonpayable

Parameters

Name
Type
Description

params

IStrategPositionManager.RebalanceData

undefined

refreshAaveData

function refreshAaveData() external nonpayable

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

function repay(bytes _dynamicParams, uint256 _percent) external nonpayable

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

Name
Type
Description

_dynamicParams

bytes

Encoded dynamic parameters for swap operations, if needed.

_percent

uint256

undefined

returnedAmountAfterRepay

function returnedAmountAfterRepay(uint256 _repay, uint256 _percent) external view returns (uint256)

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

Name
Type
Description

_repay

uint256

The amount of debt to be repaid.

_percent

uint256

undefined

Returns

Name
Type
Description

_0

uint256

collateralAmount The amount of collateral returned after the debt repayment.

returnedAmountAfterUnleverage

function returnedAmountAfterUnleverage(uint256 _percent) external view returns (uint256)

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

Name
Type
Description

_percent

uint256

undefined

Returns

Name
Type
Description

_0

uint256

collateralAmount The amount of collateral returned after the position is completely unleveraged.

unleverage

function unleverage(bytes _dynamicParams, uint256 _percent) external nonpayable

Initiates the process to unleverage the current position.

This function calls the internal _unleverage function with the dynamic parameters provided.

Parameters

Name
Type
Description

_dynamicParams

bytes

Encoded dynamic parameters for the unleverage operation.

_percent

uint256

undefined

Errors

AddressEmptyCode

error AddressEmptyCode(address target)

There's no code at target (it is not a contract).

Parameters

Name
Type
Description

target

address

undefined

AddressInsufficientBalance

error AddressInsufficientBalance(address account)

The ETH balance of the account is not enough to perform the operation.

Parameters

Name
Type
Description

account

address

undefined

AlreadyInitialized

error AlreadyInitialized()

Error thrown when the contract has already been initialized.

BorrowOnly

error BorrowOnly()

Error thrown when the operation is not a borrow operation.

FailedInnerCall

error FailedInnerCall()

A call to an address target failed. The target may have reverted.

LeverageHealthfactorNotMatch

error LeverageHealthfactorNotMatch()

Error thrown when the leverage operation does not match the desired health factor.

LeverageOnly

error LeverageOnly()

Error thrown when the operation is not a leverage operation.

NotAavePool

error NotAavePool()

Error thrown when the caller is not the Aave pool.

NotOperator

error NotOperator()

Error thrown when the caller is not an operator.

NotOwner

error NotOwner()

Error thrown when the caller is not the owner.

RepayNotCoveredWithSwap

error RepayNotCoveredWithSwap()

Error thrown when a repay operation is not covered by a swap.

SafeERC20FailedOperation

error SafeERC20FailedOperation(address token)

An operation with an ERC20 token failed.

Parameters

Name
Type
Description

token

address

undefined

UnleverageNotComplete

error UnleverageNotComplete()

Error thrown when the unleverage operation is not complete.

WrongInitiator

error WrongInitiator()

Error thrown when the initiator of the operation is wrong.

PreviousStrategPositionManagerFactoryNextStrategAaveV3PositionManagerInfo

Last updated 1 year ago