Token prices

Description of Sentry's pricing algorithm

Tokens are traded across various markets, leading to multiple prices determined by individual rates on each market. In Sentry, we require a higher-level abstraction to effectively track token prices. To address this, we aggregate prices from diverse markets, allowing us to establish a resilient price that mitigates local variations. This aggregated price serves as a foundation for price notifications within Sentry, ensuring consistency and reliability across the platform.

For those seeking finer granularity, subscribing to a pool rate metric enables alerts for the rates of specific pools.

Preamble

All token prices within our system are denoted in WETH (Wrapped Ether). For standardization, native ETH pools, such as those in Curve Finance, are treated as equivalent to WETH.

For pools lacking a pair in ETH or WETH, we facilitate a one-step conversion using rates of whitelisted tokens such as DAI, USDC, stETH, rETH, and others.

Additionally, we compute a bundle price to monitor an on-chain equivalent of the ETH/USD pair, akin to the Uniswap V3 subgraph algorithm. This USD price is determined by averaging the swap rates of the three largest WETH/DAI, WETH/USDC, and WETH/USDT pool rates.

This approach enables us to track any pair in both WETH or USD terms by quoting all rates per token in WETH and converting WETH to USD as needed.

Token price computation

Upon receiving a new rate for a pool, the corresponding token price is recomputed as the weighted average of rates from all pools containing that token, quoted in WETH or whitelisted tokens. Weights are determined based on the TVL (Total Value Locked) of the token in each pool relative to the overall total TVL.

The formula for calculating the weighted average price is as follows:

P=i=1n(TVLi×Ri)i=1nTVLiP = \frac {​ ∑_{i=1}^n ​ (TVL i ​ ×R i ​ ) } {∑_{i=1}^n ​ TVL i}

  • nn is the number of pools for the token.

  • TokenTVLiToken TVL_i is the TVL of the token in the ithi^{th} pool.

  • RiR_i​ is the rate of the pool.

NOTE: For non whitelisted token, we calculate the price by weighting (using the percentage of total TVL of the token and the rates of whitelisted tokens versus WETH).

Condition for rate consideration

For each token, we only consider a pool's rate if it fulfill the following conditions:

For Whitelisted Tokens:

  • The token must have WETH pair rates.

  • Quantity of WETH must be greater than or equal to a minimum threshold (MIN_WETH_AMOUNT).

  • TVL of the token in the pool must be greater than or equal to a certain percentage (MIN_PERCENT_TVL) of the total TVL of the token.

For Non-Whitelisted Tokens:

  • The token must have whitelisted pair rates.

  • Quantity of WETH must be greater than or equal to a minimum threshold (MIN_WETH_AMOUNT). If it's a pool of token X versus a whitelisted token that is not WETH, we use the rate of the whitelisted token versus WETH.

  • TVL of the token in the pool must be greater than or equal to a certain percentage (MIN_PERCENT_TVL) of the total TVL of the token.

Calculation Order

Upon receipt of a new block, the calculation order is as follows:

  1. Update the WETH price for all whitelisted tokens.

  2. Update the WETH price for all non-whitelisted tokens.

  3. Update the USD price for all tokens using the bundle price

Last updated