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

update network to arbitrum-one #173

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion src/mappings/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Factory as FactoryContract } from '../types/templates/Pair/Factory'
import { TokenDefinition } from './tokenDefinition'

export const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000'
export const FACTORY_ADDRESS = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f'
export const FACTORY_ADDRESS = '0xf1D7CC64Fb4452F05c498126312eBE29f30Fbcf9'

export let ZERO_BI = BigInt.fromI32(0)
export let ONE_BI = BigInt.fromI32(1)
Expand Down
79 changes: 28 additions & 51 deletions src/mappings/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,71 +4,42 @@ import { Address, BigDecimal, BigInt } from '@graphprotocol/graph-ts/index'
import { Bundle, Pair, Token } from '../types/schema'
import { ADDRESS_ZERO, factoryContract, ONE_BD, UNTRACKED_PAIRS, ZERO_BD } from './helpers'

const WETH_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
const USDC_WETH_PAIR = '0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc' // created 10008355
const DAI_WETH_PAIR = '0xa478c2975ab1ea89e8196811f51a7b7ade33eb11' // created block 10042267
const USDT_WETH_PAIR = '0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852' // created block 10093341
const WETH_ADDRESS = '0x82af49447d8a07e3bd95bd0d56f35241523fbab1'
const USDC_WETH_PAIR = '0xf64dfe17c8b87f012fcf50fbda1d62bfa148366a'

export function getEthPriceInUSD(): BigDecimal {
// fetch eth prices for each stablecoin
let daiPair = Pair.load(DAI_WETH_PAIR) // dai is token0
let usdcPair = Pair.load(USDC_WETH_PAIR) // usdc is token0
let usdtPair = Pair.load(USDT_WETH_PAIR) // usdt is token1

// all 3 have been created
if (daiPair !== null && usdcPair !== null && usdtPair !== null) {
let totalLiquidityETH = daiPair.reserve1.plus(usdcPair.reserve1).plus(usdtPair.reserve0)
let daiWeight = daiPair.reserve1.div(totalLiquidityETH)
let usdcWeight = usdcPair.reserve1.div(totalLiquidityETH)
let usdtWeight = usdtPair.reserve0.div(totalLiquidityETH)
return daiPair.token0Price
.times(daiWeight)
.plus(usdcPair.token0Price.times(usdcWeight))
.plus(usdtPair.token1Price.times(usdtWeight))
// dai and USDC have been created
} else if (daiPair !== null && usdcPair !== null) {
let totalLiquidityETH = daiPair.reserve1.plus(usdcPair.reserve1)
let daiWeight = daiPair.reserve1.div(totalLiquidityETH)
let usdcWeight = usdcPair.reserve1.div(totalLiquidityETH)
return daiPair.token0Price.times(daiWeight).plus(usdcPair.token0Price.times(usdcWeight))
// USDC is the only pair so far
} else if (usdcPair !== null) {
return usdcPair.token0Price
let usdcPair = Pair.load(USDC_WETH_PAIR) // usdc is token1
if (usdcPair !== null) {
return usdcPair.token1Price
} else {
return ZERO_BD
}
}

// token where amounts should contribute to tracked volume and liquidity
let WHITELIST: string[] = [
'0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', // WETH
'0x6b175474e89094c44da98b954eedeac495271d0f', // DAI
'0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // USDC
'0xdac17f958d2ee523a2206206994597c13d831ec7', // USDT
'0x0000000000085d4780b73119b644ae5ecd22b376', // TUSD
'0x5d3a536e4d6dbd6114cc1ead35777bab948e3643', // cDAI
'0x39aa39c021dfbae8fac545936693ac917d5e7563', // cUSDC
'0x86fadb80d8d2cff3c3680819e4da99c10232ba0f', // EBASE
'0x57ab1ec28d129707052df4df418d58a2d46d5f51', // sUSD
'0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2', // MKR
'0xc00e94cb662c3520282e6f5717214004a7f26888', // COMP
'0x514910771af9ca656af840dff83e8264ecf986ca', //LINK
'0x960b236a07cf122663c4303350609a66a7b288c0', //ANT
'0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f', //SNX
'0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e', //YFI
'0xdf5e0e81dff6faf3a7e52ba697820c5e32d806a8', // yCurv
'0x853d955acef822db058eb8505911ed77f175b99e', // FRAX
'0xa47c8bf37f92abed4a126bda807a7b7498661acd', // WUST
'0x1f9840a85d5af5bf1d1762f925bdaddc4201f984', // UNI
'0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', // WBTC
'0x956f47f50a910163d8bf957cf5846d573e7f87ca', // FEI
'0x82af49447d8a07e3bd95bd0d56f35241523fbab1', // WETH
'0xaf88d065e77c8cc2239327c5edb3a432268e5831', // USDC
]

const STABLECOINS: string[] = [
'0xaf88d065e77c8cc2239327c5edb3a432268e5831', // USDC
]

// minimum liquidity required to count towards tracked volume for pairs with small # of Lps
let MINIMUM_USD_THRESHOLD_NEW_PAIRS = BigDecimal.fromString('400000')
let MINIMUM_USD_THRESHOLD_NEW_PAIRS = BigDecimal.fromString('10000')

// minimum liquidity for price to get tracked
let MINIMUM_LIQUIDITY_THRESHOLD_ETH = BigDecimal.fromString('2')
let MINIMUM_LIQUIDITY_THRESHOLD_ETH = BigDecimal.fromString('1')

// return 0 if denominator is 0 in division
export function safeDiv(amount0: BigDecimal, amount1: BigDecimal): BigDecimal {
if (amount1.equals(ZERO_BD)) {
return ZERO_BD
} else {
return amount0.div(amount1)
}
}

/**
* Search through graph to find derived Eth per token.
Expand All @@ -78,6 +49,12 @@ export function findEthPerToken(token: Token): BigDecimal {
if (token.id == WETH_ADDRESS) {
return ONE_BD
}

if (STABLECOINS.includes(token.id)) {
const bundle = Bundle.load('1')!
return safeDiv(ONE_BD, bundle.ethPrice)
}

// loop through whitelist and check if paired with any
for (let i = 0; i < WHITELIST.length; ++i) {
let pairAddress = factoryContract.getPair(Address.fromString(token.id), Address.fromString(WHITELIST[i]))
Expand Down
39 changes: 1 addition & 38 deletions src/mappings/tokenDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,7 @@ export class TokenDefinition {

// Get all tokens with a static defintion
static getStaticDefinitions(): Array<TokenDefinition> {
const staticDefinitions: Array<TokenDefinition> = [
{
address: Address.fromString('0xe0b7927c4af23765cb51314a0e0521a9645f0e2a'),
symbol: 'DGD',
name: 'DGD',
decimals: BigInt.fromI32(9),
},
{
address: Address.fromString('0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9'),
symbol: 'AAVE',
name: 'Aave Token',
decimals: BigInt.fromI32(18),
},
{
address: Address.fromString('0xeb9951021698b42e4399f9cbb6267aa35f82d59d'),
symbol: 'LIF',
name: 'Lif',
decimals: BigInt.fromI32(18),
},
{
address: Address.fromString('0xbdeb4b83251fb146687fa19d1c660f99411eefe3'),
symbol: 'SVD',
name: 'savedroid',
decimals: BigInt.fromI32(18),
},
{
address: Address.fromString('0xbb9bc244d798123fde783fcc1c72d3bb8c189413'),
symbol: 'TheDAO',
name: 'TheDAO',
decimals: BigInt.fromI32(16),
},
{
address: Address.fromString('0x38c6a68304cdefb9bec48bbfaaba5c5b47818bb2'),
symbol: 'HPB',
name: 'HPBCoin',
decimals: BigInt.fromI32(18),
},
]
const staticDefinitions: Array<TokenDefinition> = []
return staticDefinitions
}

Expand Down
8 changes: 4 additions & 4 deletions subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ schema:
dataSources:
- kind: ethereum/contract
name: Factory
network: mainnet
network: arbitrum-one
source:
address: '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f'
address: '0xf1D7CC64Fb4452F05c498126312eBE29f30Fbcf9'
abi: Factory
startBlock: 10000834
startBlock: 150442611
mapping:
kind: ethereum/events
apiVersion: 0.0.7
Expand All @@ -34,7 +34,7 @@ dataSources:
templates:
- kind: ethereum/contract
name: Pair
network: mainnet
network: arbitrum-one
source:
abi: Pair
mapping:
Expand Down
Loading