Skip to main content

index.ts

path: /src/utils/index.ts

exponentToBigDecimal()

Params:
- decimals (BigInt): The power of ten to return.

ReturnType: BigDecimal

Returns the number 1 followed by decimals number of 0s with type BigDecimal.
It uses a for loop to iterate between 0 and decimals and multiplies the previous result by 10. Thus, only positive values are possible.

Dependencies:

  1. ZERO_BI
  2. ONE_BI

Invoked at:

  1. tokenAmountToDecimal()
  2. priceToDecimal()
  3. convertTokenToDecimal()
  4. convertEthToDecimal
  5. sqrtPriceX96ToTokenPrices

safeDiv()

Params:
- amount0 (BigDecimal): Numerator for the division
- amount1 (BigDecimal): Denominator for the division

ReturnType: BigDecimal

Return 0 if parameter amount1 is equal to ZERO_BD.
Else returns the result of dividing amount0 by amount1 using BigDecimal's div() method.

Dependencies:

  1. ZERO_BD

Invoked at:

  1. bigDecimalExponated()
  2. priceToDecimal()
  3. createTick()

bigDecimalExponated()

Params:
- value (BigDecimal): value to be raised to a certain power
- power (BigInt): the exponent of the value to be calculated

ReturnType: BigDecimal

If power is ZERO_BI, ONE_BD is returned. value is multipled by itself in a simple for loop executed abs(power) number of times. If the power is negative, uses safeDiv to divide ONE_BD with the result of the previous calculation. Returns the result in BigDecimal.

Dependencies:

  1. ZERO_BI
  2. ZERO_BD
  3. ONE_BI
  4. ONE_BD
  5. safeDiv()

Invoked at:

  1. createTick()

tokenAmountToDecimal()

Params:
- tokenAmount (BigDecimal): The amount of tokens to be divided (numerator)
- exchangeDecimals (BigInt): The power of 10 to divide the amount with

ReturnType: BigDecimal

If exchangeDecimals is ZERO_BI, returns tokenAmount after converting to BigDecimal. Else divides the BigDecimal tokenAmount using 10 raised to exchangeDecimals as the denominator.

Dependencies:

  1. ZERO_BI
  2. exponentToBigDecimal()

Invoked at:

  1. []

priceToDecimal()

Params:
- amount (BigDecimal): The amount to be divided (numerator)
- exchangeDecimals (BigInt): The power of 10 to divide the amount with

ReturnType: BigDecimal

If exchangeDecimals is equal to ZERO_BI returns the amount as it is. Otherwise uses safeDiv to divide amount with 10^exchangeDecimals in BigDecimals type.

Dependencies:

  1. ZERO_BI
  2. safeDiv()
  3. exponentToBigDecimal()

Invoked at:

equalToZero()

Params:
- value (BigDecimal): Value to check whether zero

ReturnType: boolean

Converts value to string and then to float. Compares it against ZERO_BD after converting to String and then parsing as float. Returns boolean value from comparing the equality of the two float values.

Dependencies:

  1. ZERO_BD

Invoked at:

isNullEthValue()

Params:
- value (String) - Hex String to check for Null Eth value

ReturnType: boolean

Returns boolean value. True is value == '0x0000000000000000000000000000000000000000000000000000000000000001', else false.

Invoked at:

  1. fetchTokenSymbol()
  2. fetchTokenName()

bigDecimalExp18()

ReturnType: BigDecimal
Value: 10^18

Invoked at:

convertTokenToDecimal()

Params:
- tokenAmount (BigInt) - The amount of token value to be converted
- exchangeDecimals (BigInt) - The positive power of the exponent to divide the tokenAmount with

ReturnType: BigDecimal

If exchangeDecimals is ZERO_BI, returns tokenAmount after converting to BigDecimal. Else divides the BigDecimal tokenAmount using 10 raised to exchangeDecimals as the denominator.

Dependencies:

  1. ZERO_BI
  2. exponentToBigDecimal

Invoked at:

  1. handleMint()
  2. handleBurn()
  3. handleSwap()
  4. handleIncreaseLiquidity()
  5. handleDecreaseLiquidity()
  6. handleCollect()

convertEthToDecimal()

Params:
- eth (BigInt) - Int value representing ether amount in wei

ReturnType: BigDecimal

Converts the value of ether in wei from integer to big decimal representing amount in ether. It converts the eth parameter to BigDecimal and then divides it with 10^18 BigDecimal value.

Dependencies:

  1. exponentToBigDecimal

Invoked at:

loadTransaction()

Params:
- event (ethereum.Event) - Ethereum event emitted from the transaction to return.

ReturnType: Transaction

Returns a Transaction instance for the specified event. If a transaction instance doesn't already exit for the event, it's created and then returned. Uses event.transaction.hash.toHexString() to find the relevant transaction or to create a new transaction instance. Uses event parameters block.blockNumber, block.timestamp, transaction.gasUsed and transaction.gasPrice to populate transaction's fields.

Entites:

  1. Transaction - Read/Create & Write

Invoked at:

  1. getPosition()
  2. savePositionSnapshot()
  3. handleMint()
  4. handleBurn()
  5. handleSwap()