Skip to content

Commit

Permalink
refactor: rename fastPow -> fastExponentiation
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanVergiliev committed Apr 1, 2024
1 parent f9033a9 commit 7217fe5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/tick.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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)

Expand Down

0 comments on commit 7217fe5

Please sign in to comment.