Skip to content

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).

There are alternative methods on the VaultResolver to also fetch a position by the nft id.

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.

::alert{type="info"} 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. ::

Smart debt / smart col amounts ​

For smart vault and smart debt the amounts are in DEX shares. There are flags for isSmartCol and isSmartDebt when fetching getVaultEntireData(), if true then the respective amount is in shares.

Shares can be resolved to token amounts via either:

  • oracle price, in Configs struct of the VaultResolver
  • using token amounts per share from the DexResolver (fetch DexEntireData for the Dex linked as supply or borrow token returned by the VaultResolver)

For further info check the public github repo or the auto-generated docs.

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.