Compute vault share valuation
There are two independent ways to get the value of a vault share. Pick one:
On-chain — call the vault contract directly over RPC and convert to dollars with your own asset price.
Lagoon API (GraphQL) — one query returns the price per share in assets and in USD.
The method described below is identical to that used for an ERC4626 vault.
To calculate the value of a single share, first determine the price per share of the vault in terms of assets. To achieve this, call the function convertToAssets(uint256 sharers) returns (uint256 assets); with the argument set to 10 ** vault.decimals().
The price per share is given with a scaling factor of 10 ** underlyingAsset.decimals. To obtain a standard value, you have to divide the price by this scaling factor.
To calculate the value of a share in dollars, multiply the price per share by the price of the underlying asset in dollars:
pricePerShare / 10 ** underlyingAsset.decimals * underlyingAssetPriceInDollar = shareValueInDollar.
Send this query to https://api.lagoon.finance/query:
query GetSharePrice {
vaultByAddress(
address: "0x936facdf10c8c36294e7b9d28345255539d81bc7"
chainId: 1
) {
asset { decimals }
state {
pricePerShare
pricePerShareUsd
}
}
}curl -sS -X POST https://api.lagoon.finance/query \
-H "Content-Type: application/json" \
-d '{"query":"query GetSharePrice { vaultByAddress(address: \"0x936facdf10c8c36294e7b9d28345255539d81bc7\", chainId: 1) { asset { decimals } state { pricePerShare pricePerShareUsd } } }"}'pricePerShare
Price of one share in asset base units, scaled by 10 ** asset.decimals
convertToAssets(10 ** vault.decimals())
pricePerShareUsd
Price of one share in USD, already converted
pricePerShare / 10 ** asset.decimals * assetPriceInDollar
For the price per share at a past date, use stateAt(timestamp) or stateHistory — see Historical data.
Last updated