Get all user vault positions

To get all Fluid vault user positions, follow these steps:

Get the user positions from the VaultResolver

The VaultResolver periphery contract provides a method positionsByUser (also see docs) which returns all user positions together with the vault data. The contract address is listed here.

This method returns an array of UserPositions (userPositions_, see struct docs), and a corresponding array of VaultEntireData (vaultsData_, see struct docs).

Retrieve the position amounts and position tokens

For each UserPosition element, there are the supply and borrow amounts as struct params which have the total user deposit and borrow amounts for one position.

To get the supply and borrow tokens for each UserPosition, use the VaultEntireData array element at the same index. Under the property constantVariables there are the properties supplyToken and borrowToken, see struct docs.

Note: A user can create multiple positions on the same vault, so there can be multiple UserPosition with the same supply & borrow token. To get the total user amounts, iterate over all UserPositions and sum up supply & borrow amounts for each token on all positions.

Health factors: Collateral factor, Liquidation threshold, penalty etc.

The VaultEntireData array element also includes the vault config data. Under the property configs (see struct docs) there are the following properties:

  • collateralFactor: maximum ratio that can be borrowed
  • liquidationThreshold: ratio above which liquidation happens
  • liquidationPenalty: penalty when liquidation happens
  • liquidationMaxLimit: limit above which 100% could be liquidated

All of these values are percent values in 1e2 precision, so 1% = 100, 80% = 8000 etc.

Summary

To summarize the steps:

  1. VaultResolver.positionsByUser(address user)
  2. Iterate through returned UserPositions array
  3. In each iteration:
    • userPositions[i].supply refers to the user deposit amount of token vaultsData[i].constantVariables.supplyToken
    • userPositions[i].borrow refers to the user borrow amount of token vaultsData[i].constantVariables.borrowToken
  4. More data is available in the UserPosition and VaultEntireData structs if needed, see contract docs.