diff --git a/src/utils/index.ts b/src/utils/index.ts index 9bc80147..00624094 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -25,9 +25,9 @@ export function safeDiv(amount0: BigDecimal, amount1: BigDecimal): BigDecimal { * (see https://en.wikipedia.org/wiki/Exponentiation_by_squaring ) * to minimize the number of BigDecimal operations and their impact on performance. */ -export function fastPow(value: BigDecimal, power: i32): BigDecimal { +export function fastExponentiation(value: BigDecimal, power: i32): BigDecimal { if (power < 0) { - let result = fastPow(value, -power); + let result = fastExponentiation(value, -power); return safeDiv(ONE_BD, result); } @@ -40,7 +40,7 @@ export function fastPow(value: BigDecimal, power: i32): BigDecimal { } let halfPower = power / 2; - let halfResult = fastPow(value, halfPower); + let halfResult = fastExponentiation(value, halfPower); // Use the fact that x ^ (2n) = (x ^ n) * (x ^ n) and we can compute (x ^ n) only once. let result = halfResult.times(halfResult); diff --git a/src/utils/tick.ts b/src/utils/tick.ts index a4f9399f..4d1ff61d 100644 --- a/src/utils/tick.ts +++ b/src/utils/tick.ts @@ -1,6 +1,6 @@ /* eslint-disable prefer-const */ import { BigDecimal, BigInt } from '@graphprotocol/graph-ts' -import { fastPow, safeDiv } from '.' +import { fastExponentiation, safeDiv } from '.' import { Tick } from '../types/schema' import { Mint as MintEvent } from '../types/templates/Pool/Pool' import { ONE_BD, ZERO_BD, ZERO_BI } from './constants' @@ -21,7 +21,7 @@ export function createTick(tickId: string, tickIdx: i32, poolId: string, event: tick.price1 = ONE_BD // 1.0001^tick is token1/token0. - let price0 = fastPow(BigDecimal.fromString('1.0001'), tickIdx); + let price0 = fastExponentiation(BigDecimal.fromString('1.0001'), tickIdx); tick.price0 = price0 tick.price1 = safeDiv(ONE_BD, price0)