Skip to content

Commit

Permalink
Merge pull request #94 from Uniswap/dev
Browse files Browse the repository at this point in the history
Multiple small changes - need github to reflect current subgraph
  • Loading branch information
ianlapham authored May 26, 2021
2 parents 8798be5 + 11c85d1 commit 537e539
Showing 6 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
"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/uniswapv2 --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --debug",
"deploy": "graph deploy ianlapham/uniswap-v2-rinkeby --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"
},
4 changes: 3 additions & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
@@ -68,7 +68,9 @@ type Pair @entity {
# derived liquidity
reserveETH: BigDecimal!
reserveUSD: BigDecimal!
trackedReserveETH: BigDecimal! # used for separating per pair reserves and global
# used for separating per pair reserves and global
trackedReserveETH: BigDecimal!

# Price in terms of the asset pair
token0Price: BigDecimal!
token1Price: BigDecimal!
1 change: 1 addition & 0 deletions src/mappings/factory.ts
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@ export function handleNewPair(event: PairCreated): void {
token0.name = fetchTokenName(event.params.token0)
token0.totalSupply = fetchTokenTotalSupply(event.params.token0)
let decimals = fetchTokenDecimals(event.params.token0)

// bail if we couldn't figure out the decimals
if (decimals === null) {
log.debug('mybug the decimal on token 0 was null', [])
3 changes: 3 additions & 0 deletions src/mappings/helpers.ts
Original file line number Diff line number Diff line change
@@ -18,6 +18,9 @@ export let BI_18 = BigInt.fromI32(18)

export let factoryContract = FactoryContract.bind(Address.fromString(FACTORY_ADDRESS))

// rebass tokens, dont count in tracked volume
export let UNTRACKED_PAIRS: string[] = ['0x9ea3b5b4ec044b70375236a281986106457b20ef']

export function exponentToBigDecimal(decimals: BigInt): BigDecimal {
let bd = BigDecimal.fromString('1')
for (let i = ZERO_BI; i.lt(decimals as BigInt); i = i.plus(ONE_BI)) {
13 changes: 11 additions & 2 deletions src/mappings/pricing.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable prefer-const */
import { Pair, Token, Bundle } from '../types/schema'
import { BigDecimal, Address, BigInt } from '@graphprotocol/graph-ts/index'
import { ZERO_BD, factoryContract, ADDRESS_ZERO, ONE_BD } from './helpers'
import { ZERO_BD, factoryContract, ADDRESS_ZERO, ONE_BD, UNTRACKED_PAIRS } from './helpers'

const WETH_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
const USDC_WETH_PAIR = '0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc' // created 10008355
@@ -55,7 +55,11 @@ let WHITELIST: string[] = [
'0x960b236a07cf122663c4303350609a66a7b288c0', //ANT
'0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f', //SNX
'0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e', //YFI
'0xdf5e0e81dff6faf3a7e52ba697820c5e32d806a8' // yCurv
'0xdf5e0e81dff6faf3a7e52ba697820c5e32d806a8', // yCurv
'0x853d955acef822db058eb8505911ed77f175b99e', // FRAX
'0xa47c8bf37f92abed4a126bda807a7b7498661acd', // WUST
'0x1f9840a85d5af5bf1d1762f925bdaddc4201f984', // UNI
'0x2260fac5e5542a773aa44fbcfedf7c193bc2c599' // WBTC
]

// minimum liquidity required to count towards tracked volume for pairs with small # of Lps
@@ -107,6 +111,11 @@ export function getTrackedVolumeUSD(
let price0 = token0.derivedETH.times(bundle.ethPrice)
let price1 = token1.derivedETH.times(bundle.ethPrice)

// dont count tracked volume on these pairs - usually rebass tokens
if (UNTRACKED_PAIRS.includes(pair.id)) {
return ZERO_BD
}

// if less than 5 LPs, require high minimum reserve amount amount or return 0
if (pair.liquidityProviderCount.lt(BigInt.fromI32(5))) {
let reserve0USD = pair.reserve0.times(price0)
2 changes: 1 addition & 1 deletion subgraph.yaml
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ dataSources:
templates:
- kind: ethereum/contract
name: Pair
network: mainnet
network: rinkeby
source:
abi: Pair
mapping:

0 comments on commit 537e539

Please sign in to comment.