Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: update with latest change for overflow issues #143

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/mappings/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,14 @@ export function handleTransfer(event: Transfer): void {

export function handleSync(event: Sync): void {
let pair = Pair.load(event.address.toHex())

if (!pair) return

let token0 = Token.load(pair.token0)
let token1 = Token.load(pair.token1)

if (!token0 || !token1) return

let uniswap = UniswapFactory.load(FACTORY_ADDRESS)

// reset factory liquidity by subtracting onluy tarcked liquidity
Expand Down Expand Up @@ -281,11 +287,15 @@ export function handleMint(event: Mint): void {
let mint = MintEvent.load(mints[mints.length - 1])

let pair = Pair.load(event.address.toHex())
if (!pair) return

let uniswap = UniswapFactory.load(FACTORY_ADDRESS)

let token0 = Token.load(pair.token0)
let token1 = Token.load(pair.token1)

if (!token0 || !token1) return

// update exchange info (except balances, sync will cover that)
let token0Amount = convertTokenToDecimal(event.params.amount0, token0.decimals)
let token1Amount = convertTokenToDecimal(event.params.amount1, token1.decimals)
Expand Down Expand Up @@ -342,11 +352,16 @@ export function handleBurn(event: Burn): void {
let burn = BurnEvent.load(burns[burns.length - 1])

let pair = Pair.load(event.address.toHex())
if (!pair) return

let uniswap = UniswapFactory.load(FACTORY_ADDRESS)

//update token info
let token0 = Token.load(pair.token0)
let token1 = Token.load(pair.token1)

if (!token0 || !token1) return

let token0Amount = convertTokenToDecimal(event.params.amount0, token0.decimals)
let token1Amount = convertTokenToDecimal(event.params.amount1, token1.decimals)

Expand Down Expand Up @@ -394,8 +409,12 @@ export function handleBurn(event: Burn): void {

export function handleSwap(event: Swap): void {
let pair = Pair.load(event.address.toHexString())
if (!pair) return

let token0 = Token.load(pair.token0)
let token1 = Token.load(pair.token1)
if (!token0 || !token1) return

let amount0In = convertTokenToDecimal(event.params.amount0In, token0.decimals)
let amount1In = convertTokenToDecimal(event.params.amount1In, token1.decimals)
let amount0Out = convertTokenToDecimal(event.params.amount0Out, token0.decimals)
Expand Down
13 changes: 12 additions & 1 deletion src/mappings/factory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable prefer-const */
import { log } from '@graphprotocol/graph-ts'
import { BigInt, log } from '@graphprotocol/graph-ts'
import { PairCreated } from '../types/Factory/Factory'
import { Bundle, Pair, Token, UniswapFactory } from '../types/schema'
import { Pair as PairTemplate } from '../types/templates'
Expand All @@ -13,6 +13,9 @@ import {
ZERO_BI
} from './helpers'


let SKIP_BLOCKS: string[] = ["17308596", "18746374"]

export function handleNewPair(event: PairCreated): void {
// load factory (create if first exchange)
let factory = UniswapFactory.load(FACTORY_ADDRESS)
Expand All @@ -38,6 +41,14 @@ export function handleNewPair(event: PairCreated): void {
let token0 = Token.load(event.params.token0.toHexString())
let token1 = Token.load(event.params.token1.toHexString())

// hot fix for overflow error - need better solution for this but urgent as subgraph is down
for (let i = 0; i < SKIP_BLOCKS.length; ++i) {
let skipBlock = BigInt.fromI32(parseInt(SKIP_BLOCKS[i]) as i32)
if (event.block.number == skipBlock) {
return
}
}

// fetch info if null
if (token0 === null) {
token0 = new Token(event.params.token0.toHexString())
Expand Down
10 changes: 9 additions & 1 deletion src/mappings/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ export function fetchTokenName(tokenAddress: Address): string {
// HOT FIX: we cant implement try catch for overflow catching so skip total supply parsing on these tokens that overflow
// TODO: find better way to handle overflow
let SKIP_TOTAL_SUPPLY: string[] = [
"0x0000000000bf2686748e1c0255036e7617e7e8a5"
"0x0000000000bf2686748e1c0255036e7617e7e8a5",
"0x000000000000b91b6956fead1dda24c66aa6b972",
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
]

export function fetchTokenTotalSupply(tokenAddress: Address): BigInt {
Expand All @@ -134,6 +136,12 @@ export function fetchTokenTotalSupply(tokenAddress: Address): BigInt {
}

export function fetchTokenDecimals(tokenAddress: Address): BigInt {

if (SKIP_TOTAL_SUPPLY.includes(tokenAddress.toHexString())) {
return BigInt.fromI32(0)
}


// static definitions overrides
let staticDefinition = TokenDefinition.fromAddress(tokenAddress)
if (staticDefinition != null) {
Expand Down
4 changes: 2 additions & 2 deletions subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ repository: https://github.com/Uniswap/uniswap-v2-subgraph
schema:
file: ./schema.graphql
graft:
base: Qmc7K8dKoadu1VcHfAV45pN4sPnwZcU2okV6cuU4B7qQp1
block: 17308000
base: QmXYAmabbEmnSDNR5GWJhmm2NQKXnPkSJEBC3EsMwjXr4e
block: 18746198
dataSources:
- kind: ethereum/contract
name: Factory
Expand Down
Loading