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

Reproduce Jesse's original subgraph #1

Closed
wants to merge 5 commits into from
Closed
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"deploy": "graph deploy ianlapham/uniswap-v3-subgraph --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --debug",
"deploy-dev": "graph deploy sommelier/uniswap-v3 --ipfs http://35.197.14.14:5000/ --node http://35.197.14.14:8020/ --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 ianlapham/uniswap-v3 --watch --debug --node http://127.0.0.1:8020/ --ipfs http://localhost:5001"
"watch-local": "graph deploy ianlapham/uniswap-v3 --watch --debug --node http://127.0.0.1:8020/ --ipfs http://localhost:5001",
"deploy-celo": "graph deploy --product hosted-service --access-token ${ACCESS_KEY} jesse-sawa/uniswap-celo --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --debug"
},
"devDependencies": {
"@graphprotocol/graph-cli": "^0.64.1",
Expand Down
6 changes: 4 additions & 2 deletions src/mappings/position-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,13 @@ export function handleCollect(event: Collect): void {
}

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

if (token0) {
if (token0 && token1) {
let amount0 = convertTokenToDecimal(event.params.amount0, token0.decimals)
let amount1 = convertTokenToDecimal(event.params.amount1, token1.decimals)
position.collectedFeesToken0 = position.collectedFeesToken0.plus(amount0)
position.collectedFeesToken1 = position.collectedFeesToken1.plus(amount0)
position.collectedFeesToken1 = position.collectedFeesToken1.plus(amount1)
}

position = updateFeeVars(position, event, event.params.tokenId)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BigInt, BigDecimal, Address } from '@graphprotocol/graph-ts'
import { Factory as FactoryContract } from '../types/templates/Pool/Factory'

export const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000'
export const FACTORY_ADDRESS = '0x1F98431c8aD98523631AE4a59f267346ea31F984'
export const FACTORY_ADDRESS = '0xAfE208a311B21f13EF87E33A90049fC17A7acDEc'

export let ZERO_BI = BigInt.fromI32(0)
export let ONE_BI = BigInt.fromI32(1)
Expand Down
54 changes: 20 additions & 34 deletions src/utils/pricing.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,29 @@
/* eslint-disable prefer-const */
import { ONE_BD, ZERO_BD, ZERO_BI } from './constants'
import { Bundle, Pool, Token } from './../types/schema'
import { Bundle, Pool, Token } from '../types/schema'
import { BigDecimal, BigInt } from '@graphprotocol/graph-ts'
import { exponentToBigDecimal, safeDiv } from '../utils/index'

const WETH_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
const USDC_WETH_03_POOL = '0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8'
const CELO_PREVWETH_ADDRESS = '0x471ece3750da237f93b8e339c536989b8978a438'
const CUSD_CELO_POOL_ADDRESS = '0x05efb437e4e97efea6450321eca8d7585a731369'

// token where amounts should contribute to tracked volume and liquidity
// usually tokens that many tokens are paired with s
// usually tokens that many tokens are paired with
export let WHITELIST_TOKENS: string[] = [
WETH_ADDRESS, // WETH
'0x6b175474e89094c44da98b954eedeac495271d0f', // DAI
'0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // USDC
'0xdac17f958d2ee523a2206206994597c13d831ec7', // USDT
'0x0000000000085d4780b73119b644ae5ecd22b376', // TUSD
'0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', // WBTC
'0x5d3a536e4d6dbd6114cc1ead35777bab948e3643', // cDAI
'0x39aa39c021dfbae8fac545936693ac917d5e7563', // cUSDC
'0x86fadb80d8d2cff3c3680819e4da99c10232ba0f', // EBASE
'0x57ab1ec28d129707052df4df418d58a2d46d5f51', // sUSD
'0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2', // MKR
'0xc00e94cb662c3520282e6f5717214004a7f26888', // COMP
'0x514910771af9ca656af840dff83e8264ecf986ca', // LINK
'0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f', // SNX
'0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e', // YFI
'0x111111111117dc0aa78b770fa6a738034120c302', // 1INCH
'0xdf5e0e81dff6faf3a7e52ba697820c5e32d806a8', // yCurv
'0x956f47f50a910163d8bf957cf5846d573e7f87ca', // FEI
'0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0', // MATIC
'0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9', // AAVE
'0xfe2e637202056d30016725477c5da089ab0a043a' // sETH2
'0x765de816845861e75a25fca122bb6898b8b1282a', // CUSD
'0xef4229c8c3250c675f21bcefa42f58efbff6002a', // USDC
'0x471ece3750da237f93b8e339c536989b8978a438', // CELO
'0xd8763cba276a3738e6de85b4b3bf5fded6d6ca73', // CEUR
'0xe8537a3d056da446677b9e9d6c5db704eaab4787', // CREAL
'0x46c9757c5497c5b1f2eb73ae79b6b67d119b0b58', // PACT
'0x17700282592d6917f6a73d0bf8accf4d578c131e', // MOO
'0x66803fb87abd4aac3cbb3fad7c3aa01f6f3fb207', // Portal Eth
'0xbaab46e28388d2779e6e31fd00cf0e5ad95e327b', // WBTC
]

let STABLE_COINS: string[] = [
'0x6b175474e89094c44da98b954eedeac495271d0f',
'0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
'0xdac17f958d2ee523a2206206994597c13d831ec7',
'0x0000000000085d4780b73119b644ae5ecd22b376',
'0x956f47f50a910163d8bf957cf5846d573e7f87ca',
'0x4dd28568d05f09b02220b09c2cb307bfd837cb95'
'0x765de816845861e75a25fca122bb6898b8b1282a', // CUSD
'0xef4229c8c3250c675f21bcefa42f58efbff6002a', //USDC
]

let MINIMUM_ETH_LOCKED = BigDecimal.fromString('60')
Expand All @@ -59,9 +43,11 @@ export function sqrtPriceX96ToTokenPrices(sqrtPriceX96: BigInt, token0: Token, t

export function getEthPriceInUSD(): BigDecimal {
// fetch eth prices for each stablecoin
let usdcPool = Pool.load(USDC_WETH_03_POOL) // dai is token0
let usdcPool = Pool.load(CUSD_CELO_POOL_ADDRESS) // dai is token0
if (usdcPool !== null) {
return usdcPool.token0Price
// if (usdcPool.token0.toString().toLowerCase() == CELO_PREVWETH_ADDRESS.toString().toLowerCase()) {
// return usdcPool.token0Price
return usdcPool.token1Price
} else {
return ZERO_BD
}
Expand All @@ -72,7 +58,7 @@ export function getEthPriceInUSD(): BigDecimal {
* @todo update to be derived ETH (add stablecoin estimates)
**/
export function findEthPerToken(token: Token): BigDecimal {
if (token.id == WETH_ADDRESS) {
if (token.id == CELO_PREVWETH_ADDRESS) {
return ONE_BD
}
let whiteList = token.whitelistPools
Expand Down
20 changes: 10 additions & 10 deletions subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ description: Uniswap is a decentralized protocol for automated token exchange on
repository: https://github.com/Uniswap/uniswap-v3-subgraph
schema:
file: ./schema.graphql
graft:
base: QmZeCuoZeadgHkGwLwMeguyqUKz1WPWQYKcKyMCeQqGhsF
block: 19470000
# graft:
# base: QmZeCuoZeadgHkGwLwMeguyqUKz1WPWQYKcKyMCeQqGhsF
# block: 19470000
features:
- nonFatalErrors
- grafting
dataSources:
- kind: ethereum/contract
name: Factory
network: mainnet
network: celo
source:
address: '0x1F98431c8aD98523631AE4a59f267346ea31F984'
address: '0xAfE208a311B21f13EF87E33A90049fC17A7acDEc'
abi: Factory
startBlock: 12369621
startBlock: 13750000
mapping:
kind: ethereum/events
apiVersion: 0.0.7
Expand All @@ -41,11 +41,11 @@ dataSources:
handler: handlePoolCreated
- kind: ethereum/contract
name: NonfungiblePositionManager
network: mainnet
network: celo
source:
address: '0xC36442b4a4522E871399CD717aBDD847Ab11FE88'
address: '0x3d79EdAaBC0EaB6F08ED885C05Fc0B014290D95A'
abi: NonfungiblePositionManager
startBlock: 12369651
startBlock: 13750000
mapping:
kind: ethereum/events
apiVersion: 0.0.7
Expand Down Expand Up @@ -75,7 +75,7 @@ dataSources:
templates:
- kind: ethereum/contract
name: Pool
network: mainnet
network: celo
source:
abi: Pool
mapping:
Expand Down