Skip to content

Commit

Permalink
Merge pull request #136 from Uniswap/ian/overflow-fix
Browse files Browse the repository at this point in the history
merge latest
  • Loading branch information
ianlapham authored Sep 13, 2023
2 parents 7c82235 + 0a1e0c8 commit b505875
Show file tree
Hide file tree
Showing 8 changed files with 563 additions and 297 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
"build": "graph build",
"create-local": "graph create davekaj/uniswap --node http://127.0.0.1:8020",
"deploy-local": "graph deploy davekaj/uniswap --debug --ipfs http://localhost:5001 --node http://127.0.0.1:8020",
"deploy": "graph deploy ianlapham/uniswap-v2-rinkeby --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --debug",
"deploy": "graph deploy ianlapham/uniswap-v2-dev --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --debug",
"deploy-staging": "graph deploy $THE_GRAPH_GITHUB_USER/$THE_GRAPH_SUBGRAPH_NAME /Uniswap --ipfs https://api.staging.thegraph.com/ipfs/ --node https://api.staging.thegraph.com/deploy/",
"watch-local": "graph deploy graphprotocol/Uniswap2 --watch --debug --node http://127.0.0.1:8020/ --ipfs http://localhost:5001"
},
"devDependencies": {
"@graphprotocol/graph-cli": "^0.16.0",
"@graphprotocol/graph-ts": "^0.16.0",
"@graphprotocol/graph-cli": "^0.20.0",
"@graphprotocol/graph-ts": "^0.20.0",
"@typescript-eslint/eslint-plugin": "^2.0.0",
"@typescript-eslint/parser": "^2.0.0",
"eslint": "^6.2.2",
Expand Down
4 changes: 2 additions & 2 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ type PairHourData @entity {
reserve1: BigDecimal!

# total supply for LP historical returns
totalSupply: BigDecimal!
totalSupply: BigDecimal

# derived liquidity
reserveUSD: BigDecimal!
Expand All @@ -268,7 +268,7 @@ type PairDayData @entity {
reserve1: BigDecimal!

# total supply for LP historical returns
totalSupply: BigDecimal!
totalSupply: BigDecimal

# derived liquidity
reserveUSD: BigDecimal!
Expand Down
10 changes: 5 additions & 5 deletions src/mappings/dayUpdates.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable prefer-const */
import { BigDecimal, BigInt, EthereumEvent } from '@graphprotocol/graph-ts'
import { BigDecimal, BigInt, ethereum } from '@graphprotocol/graph-ts'
import { Bundle, Pair, PairDayData, Token, TokenDayData, UniswapDayData, UniswapFactory } from '../types/schema'
import { PairHourData } from './../types/schema'
import { FACTORY_ADDRESS, ONE_BI, ZERO_BD, ZERO_BI } from './helpers'

export function updateUniswapDayData(event: EthereumEvent): UniswapDayData {
export function updateUniswapDayData(event: ethereum.Event): UniswapDayData {
let uniswap = UniswapFactory.load(FACTORY_ADDRESS)
let timestamp = event.block.timestamp.toI32()
let dayID = timestamp / 86400
Expand All @@ -28,7 +28,7 @@ export function updateUniswapDayData(event: EthereumEvent): UniswapDayData {
return uniswapDayData as UniswapDayData
}

export function updatePairDayData(event: EthereumEvent): PairDayData {
export function updatePairDayData(event: ethereum.Event): PairDayData {
let timestamp = event.block.timestamp.toI32()
let dayID = timestamp / 86400
let dayStartTimestamp = dayID * 86400
Expand Down Expand Up @@ -60,7 +60,7 @@ export function updatePairDayData(event: EthereumEvent): PairDayData {
return pairDayData as PairDayData
}

export function updatePairHourData(event: EthereumEvent): PairHourData {
export function updatePairHourData(event: ethereum.Event): PairHourData {
let timestamp = event.block.timestamp.toI32()
let hourIndex = timestamp / 3600 // get unique hour within unix history
let hourStartUnix = hourIndex * 3600 // want the rounded effect
Expand Down Expand Up @@ -90,7 +90,7 @@ export function updatePairHourData(event: EthereumEvent): PairHourData {
return pairHourData as PairHourData
}

export function updateTokenDayData(token: Token, event: EthereumEvent): TokenDayData {
export function updateTokenDayData(token: Token, event: ethereum.Event): TokenDayData {
let bundle = Bundle.load('1')
let timestamp = event.block.timestamp.toI32()
let dayID = timestamp / 86400
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
fetchTokenSymbol,
fetchTokenTotalSupply,
ZERO_BD,
ZERO_BI,
ZERO_BI
} from './helpers'

export function handleNewPair(event: PairCreated): void {
Expand Down
20 changes: 15 additions & 5 deletions src/mappings/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable prefer-const */
import { log, BigInt, BigDecimal, Address, EthereumEvent } from '@graphprotocol/graph-ts'
import { log, BigInt, BigDecimal, Address, ethereum } from '@graphprotocol/graph-ts'
import { ERC20 } from '../types/Factory/ERC20'
import { ERC20SymbolBytes } from '../types/Factory/ERC20SymbolBytes'
import { ERC20NameBytes } from '../types/Factory/ERC20NameBytes'
Expand Down Expand Up @@ -60,7 +60,7 @@ export function isNullEthValue(value: string): boolean {
export function fetchTokenSymbol(tokenAddress: Address): string {
// static definitions overrides
let staticDefinition = TokenDefinition.fromAddress(tokenAddress)
if(staticDefinition != null) {
if (staticDefinition != null) {
return (staticDefinition as TokenDefinition).symbol
}

Expand Down Expand Up @@ -88,7 +88,7 @@ export function fetchTokenSymbol(tokenAddress: Address): string {
export function fetchTokenName(tokenAddress: Address): string {
// static definitions overrides
let staticDefinition = TokenDefinition.fromAddress(tokenAddress)
if(staticDefinition != null) {
if (staticDefinition != null) {
return (staticDefinition as TokenDefinition).name
}

Expand All @@ -113,7 +113,17 @@ export function fetchTokenName(tokenAddress: Address): string {
return nameValue
}

// 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"
]

export function fetchTokenTotalSupply(tokenAddress: Address): BigInt {
if (SKIP_TOTAL_SUPPLY.includes(tokenAddress.toHexString())) {
return BigInt.fromI32(0)
}

let contract = ERC20.bind(tokenAddress)
let totalSupplyValue = null
let totalSupplyResult = contract.try_totalSupply()
Expand All @@ -126,7 +136,7 @@ export function fetchTokenTotalSupply(tokenAddress: Address): BigInt {
export function fetchTokenDecimals(tokenAddress: Address): BigInt {
// static definitions overrides
let staticDefinition = TokenDefinition.fromAddress(tokenAddress)
if(staticDefinition != null) {
if (staticDefinition != null) {
return (staticDefinition as TokenDefinition).decimals
}

Expand Down Expand Up @@ -169,7 +179,7 @@ export function createUser(address: Address): void {
}
}

export function createLiquiditySnapshot(position: LiquidityPosition, event: EthereumEvent): void {
export function createLiquiditySnapshot(position: LiquidityPosition, event: ethereum.Event): void {
let timestamp = event.block.timestamp.toI32()
let bundle = Bundle.load('1')
let pair = Pair.load(position.pair)
Expand Down
3 changes: 2 additions & 1 deletion src/mappings/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ let WHITELIST: string[] = [
'0x853d955acef822db058eb8505911ed77f175b99e', // FRAX
'0xa47c8bf37f92abed4a126bda807a7b7498661acd', // WUST
'0x1f9840a85d5af5bf1d1762f925bdaddc4201f984', // UNI
'0x2260fac5e5542a773aa44fbcfedf7c193bc2c599' // WBTC
'0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', // WBTC
'0x956f47f50a910163d8bf957cf5846d573e7f87ca' // FEI
]

// minimum liquidity required to count towards tracked volume for pairs with small # of Lps
Expand Down
7 changes: 5 additions & 2 deletions subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ description: Uniswap is a decentralized protocol for automated token exchange on
repository: https://github.com/Uniswap/uniswap-v2-subgraph
schema:
file: ./schema.graphql
graft:
base: Qmc7K8dKoadu1VcHfAV45pN4sPnwZcU2okV6cuU4B7qQp1
block: 17308000
dataSources:
- kind: ethereum/contract
name: Factory
Expand All @@ -13,7 +16,7 @@ dataSources:
startBlock: 10000834
mapping:
kind: ethereum/events
apiVersion: 0.0.3
apiVersion: 0.0.4
language: wasm/assemblyscript
file: ./src/mappings/factory.ts
entities:
Expand All @@ -39,7 +42,7 @@ templates:
abi: Pair
mapping:
kind: ethereum/events
apiVersion: 0.0.3
apiVersion: 0.0.4
language: wasm/assemblyscript
file: ./src/mappings/core.ts
entities:
Expand Down
Loading

0 comments on commit b505875

Please sign in to comment.