Skip to content

Commit

Permalink
fix(#patch); pancakeswap-v2-swap; check if tokenContract.decimals ret…
Browse files Browse the repository at this point in the history
…urn i32 (#2394)

Co-authored-by: Dhruv Chauhan <[email protected]>
  • Loading branch information
dhruv-chauhan and Dhruv Chauhan authored Oct 3, 2023
1 parent 9b812ba commit 26c7f43
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
8 changes: 4 additions & 4 deletions deployment/deployment.json
Original file line number Diff line number Diff line change
Expand Up @@ -4884,7 +4884,7 @@
"status": "prod",
"versions": {
"schema": "1.3.2",
"subgraph": "1.0.1",
"subgraph": "1.1.0",
"methodology": "1.0.0"
},
"files": {
Expand Down Expand Up @@ -5462,7 +5462,7 @@
"status": "prod",
"versions": {
"schema": "1.3.2",
"subgraph": "1.0.2",
"subgraph": "1.1.0",
"methodology": "1.0.0"
},
"files": {
Expand Down Expand Up @@ -5526,7 +5526,7 @@
"status": "prod",
"versions": {
"schema": "1.3.2",
"subgraph": "1.0.1",
"subgraph": "1.1.0",
"methodology": "1.0.0"
},
"files": {
Expand Down Expand Up @@ -5556,7 +5556,7 @@
"status": "prod",
"versions": {
"schema": "1.3.2",
"subgraph": "1.0.0",
"subgraph": "1.1.0",
"methodology": "1.0.0"
},
"files": {
Expand Down
3 changes: 3 additions & 0 deletions subgraphs/uniswap-forks-swap/src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ export const BIGDECIMAL_TEN = new BigDecimal(BIGINT_TEN);
export const BIGDECIMAL_HUNDRED = new BigDecimal(BIGINT_HUNDRED);

export const BIGDECIMAL_FIFTY_PERCENT = new BigDecimal(BIGINT_FIFTY);
export const MAX_INT32 = BigInt.fromI32(2)
.times(BigInt.fromI32(31))
.minus(BIGINT_ONE);
export const MAX_UINT = BigInt.fromI32(2).times(BigInt.fromI32(255));
export const DAYS_PER_YEAR = new BigDecimal(BigInt.fromI32(365));
export const SECONDS_PER_DAY = 60 * 60 * 24;
Expand Down
30 changes: 15 additions & 15 deletions subgraphs/uniswap-forks-swap/src/common/creators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ export function createLiquidityPool(
// create the tokens and tokentracker
const token0 = getOrCreateToken(token0Address);
const token1 = getOrCreateToken(token1Address);
if (
token0.decimals < EXPONENT_MIN ||
token0.decimals > EXPONENT_MAX ||
token0.decimals < EXPONENT_MIN ||
token1.decimals > EXPONENT_MAX
) {
// If decimals for any of the input tokens are not in range [-6143, 6144]. Ignore it.
// https://github.com/messari/subgraphs/issues/2375
log.error(
"Decimals for token(s) out of range - Ignore creating pair: token0: {} token1: {}",
[token0.id, token1.id]
);
return;
}

const LPtoken = getOrCreateLPToken(poolAddress, token0, token1);

const pool = new LiquidityPool(poolAddress);
Expand Down Expand Up @@ -97,21 +112,6 @@ export function createSwap(
const token0 = getOrCreateToken(pool.inputTokens[0]);
const token1 = getOrCreateToken(pool.inputTokens[1]);

if (
token0.decimals < EXPONENT_MIN ||
token0.decimals > EXPONENT_MAX ||
token0.decimals < EXPONENT_MIN ||
token1.decimals > EXPONENT_MAX
) {
// If decimals for any of the input tokens are not in range [-6143, 6144]. Ignore it.
// https://github.com/messari/subgraphs/issues/2375
log.error(
"Decimals for token(s) out of range - Invalid Swap: token0: {} token1: {}",
[token0.id, token1.id]
);
return;
}

// totals for volume updates
const amount0 = amount0In.minus(amount0Out);
const amount1 = amount1In.minus(amount1Out);
Expand Down
8 changes: 6 additions & 2 deletions subgraphs/uniswap-forks-swap/src/common/getters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address } from "@graphprotocol/graph-ts";
import { Address, BigInt } from "@graphprotocol/graph-ts";

import { NetworkConfigs } from "../../configurations/configure";
import { Versions } from "../versions";
Expand All @@ -7,6 +7,7 @@ import {
BIGINT_ZERO,
DEFAULT_DECIMALS,
INT_ZERO,
MAX_INT32,
ProtocolType,
} from "./constants";

Expand Down Expand Up @@ -62,7 +63,10 @@ export function getOrCreateToken(address: string): Token {
const symbolCall = erc20Contract.try_symbol();
if (!symbolCall.reverted) symbol = symbolCall.value;
const decimalsCall = erc20Contract.try_decimals();
if (!decimalsCall.reverted) decimals = decimalsCall.value;
if (!decimalsCall.reverted)
decimals = BigInt.fromString(decimalsCall.value.toString()).isI32()
? decimalsCall.value
: MAX_INT32.toI32();
}

token.name = name;
Expand Down

0 comments on commit 26c7f43

Please sign in to comment.