pricing.ts
path: /src/utils/pricing.ts
WETH_ADDRESS
- Eth Mainnet
- Polygon
- Arbitrum-One
- Optimism
- type: string
- value: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
- type: string
- value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619'
- type: string
- value: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1'
- type: string
- value: '0x4200000000000000000000000000000000000006'
Referenced at:
USDC_WETH_03_POOL
- Eth Mainnet
- Polygon
- Arbitrum-One
- Optimism
- type: string
- value: '0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8'
Address of Uniswap V3 pool contract between USDC
and WETH
ERC-20
tokens on the specific chain.
Referenced at:
- type: string
- value: '0x0e44ceb592acfc5d3f09d996302eb4c499ff8c10'
- type: string
- value: '0x17c14d2c404d167802b16c450d3c99f88f2c4f4d'
- Not present. Instead refer DAI_WETH_03_POOL
DAI_WETH_03_POOL
- Optimism
- Other-Chains
- type: string
- value: '0x03af20bdaaffb4cc0a521796a223f7d85e2aac31'
Address of Uniswap V3 pool contract between DAI
and WETH
ERC-20
tokens on optimsim mainnet.
Referenced at:
- Not present. Instead refer USDC_WETH_03_POOL
WHITELIST_TOKENS
A list of tokens which have considerable usage and are likely to have pool pairing with other tokens. These can be used for calculating liquidity in USD by using the tokens price in USD.
The following token addresses are present in the list:
- Eth Mainnet
- Polygon
- Arbitrum-One
- Optimism
Dependencies:
Referenced at:
Symbol | Address |
---|---|
WETH | WETH_ADDRESS * |
WMATIC | 0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270 |
USDC | 0x2791bca1f2de4661ed88a30c99a7a9449aa84174 |
DAI | 0x8f3cf7ad23cd3cadbd9735aff958023239c6a063 |
Symbol | Address |
---|---|
WETH | WETH_ADDRESS * |
USDC | 0xff970a61a04b1ca14834a43f5de4533ebddb5cc8 |
DAI | 0xda10009cbd5d07dd0cecc66161fc93d7c9000da1 |
USDT | 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9 |
Additional Referenced at:
* -> The value is imported from a variable and listed directly in the list declaration.
STABLE_COINS
A list of ERC20 token contract addresses which have stable coin prices, i.e., 1 token expected to be valued at 1 USD.
- Eth Mainnet
- Polygon
- Arbitrum-One
- Optimism
Referenced at:
Address | |
---|---|
USDC | 0x2791bca1f2de4661ed88a30c99a7a9449aa84174 |
STABLE_COINS
is not defined for arbitrum-one subgraph.
STABLE_COINS
is not defined for optimism subgraph.
MINIMUM_ETH_LOCKED
- Eth Mainnet
- Polygon
- Arbitrum-One
- Optimism
- type: BigDecimal
- value: 60
While calculating token price in USD, the value of other token locked in the pool in terms of eth has to be greated than MINIMUM_ETH_LOCKED
.
Referenced at:
- type: BigDecimal
- value: 5
- type: BigDecimal
- value: 10
sqrtPriceX96ToTokenPrices()
Params:
- sqrtPriceX96 (BigInt): The square root of the price of token1 in terms of token0 in Q64.96 format. Formula: sqrt(token0.price/token1.price)*(2^96)
- token0 (Token): The first token in the pool pair to calculate the relative price for
- token1 (Token): The second token in the pool pair to calculate the relative price for
ReturnType: BigDecimal[]
Find the price of token0
and token1
in the pool relative to each other and returns the two prices.
Formula:
num = (sqrtPriceX96^2) # Squaring the root to get the price
denom = 2^192 # To divide price by 96^2 to convert the Q64.96 number to BigDecimal
price1 = ((num/denom) * (10^token0.decimals))/ (10^token1.decimals) # Calculating price1
price0 = 1/price1
Dependencies:
Invoked at:
getEthPriceInUSD()
Params: none
ReturnType: BigDecimal
- Other Chains
- Arbitrum-One
- Optimism
Returns the Price of ETH in terms of USD, based on the stable coin pools.
Currently, the token0Price
for the pool
represented by USDC_WETH_03_POOL
. When pool
entity is not found, returns ZERO_BD
.
Entites:
- Pool - Read Entity
Dependencies:
Invoked at:
- Logic same as mainnet, except returns
ZERO_BD
if eth locked is not greated thanMINIMUM_ETH_LOCKED
.
Additional Dependencies:
findEthPerToken()
Params:
- token (Token): Token entity to find the price in terms of ETH
ReturnType: BigDecimal
- Eth Mainnet, Polygon
- Arbitrum-One
If token is weth, returns 1. If token in STABLE_COINS
, returns 1/bundle.ethPriceUSD
.
Else, iterates over all the whitelisted pools for the token using token.whitelistPools
. Finds the pool with largest liquidity value in terms of ETH, as long as the value is atleast MINIMUM_ETH_LOCKED
. Uses the eth value of the paired token and relative token price between the token pair to find the token
's' value in terms of eth.
If there's no whitelisted pool with MINIMUM_ETH_LOCKED
, returns ZERO_BD
.
Entites:
Dependencies:
Invoked at:
getTrackedAmountUSD()
Params:
- tokenAmount0 (BigDecimal):
- token0 (Token0):
- tokenAmount1 (BigDecimal):
- token1 (Token):
ReturnType: BigDecimal
Returns the USD value equivalent to tokenAmoun0
and tokenAmount1
together. Calculates the USD price using token.derviedEth*bundle.ethPriceUSD
as the multiplier if the token is present in WHITELIST_TOKENS
. If both the tokens are present, it adds their individual USD prices. If only one is present, it uses 2X the value of that token. If neither are in the WHITELIST_TOKENS
list, returns ZERO_BD
.
Entites:
- Bundle - Read Entity