Skip to content

Commit

Permalink
Merge pull request #53 from cowprotocol/0xeeeePricesDebug
Browse files Browse the repository at this point in the history
0xeeee prices fix.
  • Loading branch information
GabrielCamba authored Aug 3, 2022
2 parents 5b4a309 + 0711f5c commit ebab4ae
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ type User @entity {
"Owner's address"
address: Bytes!
"First trade block timestamp"
firstTradeTimestamp: Int
firstTradeTimestamp: Int!
"List of orders placed by this user"
ordersPlaced: [Order!]! @derivedFrom(field: "owner")
"Determine if user has solved a settlement"
Expand All @@ -27,7 +27,7 @@ type Token @entity {
"Token address"
address: Bytes!
"First token trade block timestamp"
firstTradeTimestamp: Int
firstTradeTimestamp: Int!
"Token name fetched by ERC20 contract call"
name: String!
"Token symbol fetched by contract call"
Expand Down
22 changes: 17 additions & 5 deletions src/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import {
Settlement,
Trade
} from "../generated/GPV2Settlement/GPV2Settlement"
import { WETH_ADDRESS } from "./utils/pricing"
import { tokens, trades, orders, users } from "./modules"
import { getPrices } from "./utils/getPrices"
import { MINUS_ONE_BD, ZERO_BI } from "./utils/constants"
import { BigDecimal, BigInt, dataSource, log } from "@graphprotocol/graph-ts"
import { MINUS_ONE_BD, ZERO_BD } from "./utils/constants"
import { Address, BigDecimal, BigInt, dataSource, log } from "@graphprotocol/graph-ts"
import { convertTokenToDecimal } from "./utils"
import { UniswapToken } from "../generated/schema"

Expand Down Expand Up @@ -63,9 +64,18 @@ export function handleTrade(event: Trade): void {
sellToken.totalVolume = tokenCurrentSellAmount.plus(sellAmount)
buyToken.totalVolume = tokenCurrentBuyAmount.plus(buyAmount)

let buyTokenAddressHexString = buyTokenAddress.toHexString()
let isBuyTokenTheNativeOne = buyTokenAddressHexString == "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"

if (network == 'xdai') {
let sellTokenPrices = getPrices(sellTokenAddress)
let buyTokenPrices = getPrices(buyTokenAddress)
let buyTokenPrices = new Map<string, BigDecimal>()
if (isBuyTokenTheNativeOne) {
let XDAI_ADDRESS = Address.fromString("0xe91d153e0b41518a2ce8dd3d7944fa863463a97d")
buyTokenPrices = getPrices(XDAI_ADDRESS)
} else {
buyTokenPrices = getPrices(buyTokenAddress)
}
if (sellTokenPrices.get("usd") != MINUS_ONE_BD &&
sellTokenPrices.get("eth") != MINUS_ONE_BD) {
sellToken.priceUsd = sellTokenPrices.get("usd")
Expand All @@ -77,8 +87,11 @@ export function handleTrade(event: Trade): void {
buyToken.priceEth = buyTokenPrices.get("eth")
}
} else {
if (isBuyTokenTheNativeOne){
buyTokenAddressHexString = WETH_ADDRESS
}
let sellUniToken = UniswapToken.load(sellTokenAddress.toHexString())
let buyUniToken = UniswapToken.load(buyTokenAddress.toHexString())
let buyUniToken = UniswapToken.load(buyTokenAddressHexString)
if (sellUniToken) {
sellToken.priceUsd = sellUniToken.priceUsd ? sellUniToken.priceUsd : null
sellToken.priceEth = sellUniToken.priceEth ? sellUniToken.priceEth : null
Expand Down Expand Up @@ -136,5 +149,4 @@ export function handleTrade(event: Trade): void {
sellToken.save()
buyToken.save()
order.save()

}
1 change: 1 addition & 0 deletions src/modules/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export namespace users {
user.solvedAmountUsd = ZERO_BD
user.tradedAmountEth = ZERO_BD
user.tradedAmountUsd = ZERO_BD
user.firstTradeTimestamp = 0
}

return user as User
Expand Down
2 changes: 1 addition & 1 deletion src/utils/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Bundle, UniswapPool, UniswapToken } from './../../generated/schema'
import { BigDecimal, BigInt } from '@graphprotocol/graph-ts'
import { exponentToBigDecimal, safeDiv } from '../utils/index'

const WETH_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
export const WETH_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
const USDC_WETH_03_POOL = '0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8'

// token where amounts should contribute to tracked volume and liquidity
Expand Down

0 comments on commit ebab4ae

Please sign in to comment.