Skip to content

Commit

Permalink
Use BigDecimal pow method for exponentiation (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikugogoi committed Jun 6, 2024
1 parent 06e82d5 commit ba1f680
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 deletions.
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion subgraphs/v3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected].2",
"@graphprotocol/graph-ts": "npm:@cerc-io/[email protected].3",
"assemblyscript": "^0.19.20",
"matchstick-as": "0.5.0",
"wabt": "1.0.24"
Expand Down
16 changes: 1 addition & 15 deletions subgraphs/v3/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ba1f680

Please sign in to comment.