From ba1f6806c45d94b82167e5bca9605baff70b4fa9 Mon Sep 17 00:00:00 2001 From: Nabarun Gogoi <95nikass@gmail.com> Date: Mon, 13 Nov 2023 15:18:27 +0530 Subject: [PATCH] Use BigDecimal pow method for exponentiation (#2) --- pnpm-lock.yaml | 8 ++++---- subgraphs/v3/package.json | 2 +- subgraphs/v3/src/utils/index.ts | 16 +--------------- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 29b629f1..156efc01 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -329,8 +329,8 @@ importers: specifier: 0.32.0-watcher-ts-0.1.2 version: 0.32.0-watcher-ts-0.1.2 '@graphprotocol/graph-ts': - specifier: npm:@cerc-io/graph-ts@0.27.0-watcher-ts-0.1.2 - version: /@cerc-io/graph-ts@0.27.0-watcher-ts-0.1.2 + specifier: npm:@cerc-io/graph-ts@0.27.0-watcher-ts-0.1.3 + version: /@cerc-io/graph-ts@0.27.0-watcher-ts-0.1.3 abi: specifier: workspace:* version: link:../../packages/abi @@ -449,8 +449,8 @@ packages: - utf-8-validate dev: true - /@cerc-io/graph-ts@0.27.0-watcher-ts-0.1.2: - resolution: {integrity: sha512-tYEWXrbMXNhONqwe329KsS2UcCcYJQ22RhSMJUg+8zsA1RtkLVJR6imVFihsacbBLR8QDMCoVK/FACVguV+Iqw==, tarball: https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fgraph-ts/-/0.27.0-watcher-ts-0.1.2/graph-ts-0.27.0-watcher-ts-0.1.2.tgz} + /@cerc-io/graph-ts@0.27.0-watcher-ts-0.1.3: + resolution: {integrity: sha512-Ipyrx0Ltn/uTaPEgRYUk9MDlfQctoLegBHHmtbijsBJzj6EKNgnUg9plc3TTQS0tubwsjpBnRNi3Ohixsuj+Bw==, tarball: https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fgraph-ts/-/0.27.0-watcher-ts-0.1.3/graph-ts-0.27.0-watcher-ts-0.1.3.tgz} dependencies: assemblyscript: 0.19.10 dev: true diff --git a/subgraphs/v3/package.json b/subgraphs/v3/package.json index 0aece100..6a95bac2 100644 --- a/subgraphs/v3/package.json +++ b/subgraphs/v3/package.json @@ -19,7 +19,7 @@ "devDependencies": { "abi": "workspace:*", "@cerc-io/graph-cli": "0.32.0-watcher-ts-0.1.2", - "@graphprotocol/graph-ts": "npm:@cerc-io/graph-ts@0.27.0-watcher-ts-0.1.2", + "@graphprotocol/graph-ts": "npm:@cerc-io/graph-ts@0.27.0-watcher-ts-0.1.3", "assemblyscript": "^0.19.20", "matchstick-as": "0.5.0", "wabt": "1.0.24" diff --git a/subgraphs/v3/src/utils/index.ts b/subgraphs/v3/src/utils/index.ts index 594e6a7e..86fa956d 100644 --- a/subgraphs/v3/src/utils/index.ts +++ b/subgraphs/v3/src/utils/index.ts @@ -22,21 +22,7 @@ export function safeDiv(amount0: BigDecimal, amount1: BigDecimal): BigDecimal { } export function bigDecimalExponated(value: BigDecimal, power: BigInt): BigDecimal { - if (power.equals(ZERO_BI)) { - return ONE_BD - } - let negativePower = power.lt(ZERO_BI) - let result = ZERO_BD.plus(value) - let powerAbs = power.abs() - for (let i = ONE_BI; i.lt(powerAbs); i = i.plus(ONE_BI)) { - result = result.times(value) - } - - if (negativePower) { - result = safeDiv(ONE_BD, result) - } - - return result + return value.pow(power.toBigDecimal()); } export function tokenAmountToDecimal(tokenAmount: BigInt, exchangeDecimals: BigInt): BigDecimal {