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

Changed type on Pairs entities property volumeToken[x] #62

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions model.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ class Pair {
token1Price: BigDecimal
token0relativePrice: BigDecimal
token1relativePrice: BigDecimal
volumeToken0: BigInt
volumeToken1: BigInt
volumeToken0: BigDecimal!
volumeToken1: BigDecimal!
volumeTradedEth: BigDecimal
volumeTradedUsd: BigDecimal
}
Expand All @@ -207,8 +207,8 @@ class PairDaily {
token0relativePrice: BigDecimal
token1relativePrice: BigDecimal
timestamp: BigInt
volumeToken0: BigInt
volumeToken1: BigInt
volumeToken0: BigDecimal!
volumeToken1: BigDecimal!
volumeTradedEth: BigDecimal
volumeTradedUsd: BigDecimal
}
Expand All @@ -225,8 +225,8 @@ class PairHourly {
token0relativePrice: BigDecimal
token1relativePrice: BigDecimal
timestamp: BigInt
volumeToken0: BigInt
volumeToken1: BigInt
volumeToken0: BigDecimal!
volumeToken1: BigDecimal!
volumeTradedEth: BigDecimal
volumeTradedUsd: BigDecimal
}
Expand Down
12 changes: 6 additions & 6 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ type Pair @entity {
"Token 1 price expressed in token1 in the last trade"
token1PriceInToken0: BigDecimal
"Total volume of token 0 traded"
volumeToken0: BigInt!
volumeToken0: BigDecimal!
"Total volume of token 1 traded"
volumeToken1: BigInt!
volumeToken1: BigDecimal!
"Total volume in Eth"
volumeTradedEth: BigDecimal
"Total volume in Usd"
Expand All @@ -370,9 +370,9 @@ type PairDaily @entity {
"Start day timestamp"
timestamp: Int!
"Total volume of token 0 traded"
volumeToken0: BigInt!
volumeToken0: BigDecimal!
"Total volume of token 1 traded"
volumeToken1: BigInt!
volumeToken1: BigDecimal!
"Total volume in Eth"
volumeTradedEth: BigDecimal
"Total volume in Usd"
Expand All @@ -397,9 +397,9 @@ type PairHourly @entity {
"Start hour timestamp"
timestamp: Int!
"Total volume of token 0 traded"
volumeToken0: BigInt!
volumeToken0: BigDecimal!
"Total volume of token 1 traded"
volumeToken1: BigInt!
volumeToken1: BigDecimal!
"Total volume in Eth"
volumeTradedEth: BigDecimal
"Total volume in Usd"
Expand Down
28 changes: 14 additions & 14 deletions src/modules/pairs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ export namespace pairs {

export class TokenProps {
token: string
volume: BigInt
volume: BigDecimal
price: BigDecimal | null
relativePrice: BigDecimal
constructor(
_token: string,
_volume: BigInt,
_volume: BigDecimal,
_price: BigDecimal | null,
_relativePrice: BigDecimal
) {
Expand All @@ -23,10 +23,10 @@ export namespace pairs {
}
}

export function createOrUpdatePair(timestamp: i32, buyTokenId: string, sellTokenId: string, buyAmount: BigInt, sellAmount: BigInt,
export function createOrUpdatePair(timestamp: i32, buyTokenId: string, sellTokenId: string,
sellAmountEth: BigDecimal | null, sellAmountUsd: BigDecimal | null, buyTokenPriceUsd: BigDecimal | null, sellTokenPriceUsd: BigDecimal | null,
buyAmountDecimals: BigDecimal, sellAmountDecimals: BigDecimal): void {
let canonicalMarket = getCanonicalMarket(buyTokenId, sellTokenId, buyAmount, sellAmount, buyTokenPriceUsd, sellTokenPriceUsd, buyAmountDecimals, sellAmountDecimals)
let canonicalMarket = getCanonicalMarket(buyTokenId, sellTokenId, buyTokenPriceUsd, sellTokenPriceUsd, buyAmountDecimals, sellAmountDecimals)

let token0Props = canonicalMarket.get("token0")
let token0 = token0Props.token
Expand All @@ -50,7 +50,7 @@ export namespace pairs {
sellAmountEth, sellAmountUsd)
}

function getCanonicalMarket(buyTokenId: string, sellTokenId: string, buyAmount: BigInt, sellAmount: BigInt,
function getCanonicalMarket(buyTokenId: string, sellTokenId: string,
buyTokenPriceUsd: BigDecimal | null, sellTokenPriceUsd: BigDecimal | null,
buyAmountDecimals: BigDecimal, sellAmountDecimals: BigDecimal): Map<string, TokenProps> {
let buyTokenAddress = Address.fromString(buyTokenId)
Expand All @@ -70,8 +70,8 @@ export namespace pairs {
sellTokenExpressedOnBuyToken = sellAmountDecimals.div(buyAmountDecimals)
}

let buyTokenProps = new TokenProps(buyTokenId, buyAmount, buyTokenPriceUsd, buyTokenExpressedOnSellToken)
let sellTokenProps = new TokenProps(sellTokenId, sellAmount, sellTokenPriceUsd, sellTokenExpressedOnBuyToken)
let buyTokenProps = new TokenProps(buyTokenId, buyAmountDecimals, buyTokenPriceUsd, buyTokenExpressedOnSellToken)
let sellTokenProps = new TokenProps(sellTokenId, sellAmountDecimals, sellTokenPriceUsd, sellTokenExpressedOnBuyToken)

if (buyTokenNumber.lt(sellTokenNumber)) {
value.set("token0", buyTokenProps)
Expand All @@ -84,7 +84,7 @@ export namespace pairs {
return value
}

function totalsUpdate(timestamp: i32, pair: Pair, pairDaily: PairDaily, pairHourly: PairHourly, volumeToken0: BigInt, volumeToken1: BigInt,
function totalsUpdate(timestamp: i32, pair: Pair, pairDaily: PairDaily, pairHourly: PairHourly, volumeToken0: BigDecimal, volumeToken1: BigDecimal,
priceToken0: BigDecimal | null, priceToken1: BigDecimal | null, token0RelativePrice: BigDecimal, token1RelativePrice: BigDecimal,
sellAmountEth: BigDecimal | null, sellAmountUsd: BigDecimal | null): void {

Expand Down Expand Up @@ -152,8 +152,8 @@ export namespace pairs {
pairTotal = new Pair(id)
pairTotal.token0 = token0
pairTotal.token1 = token1
pairTotal.volumeToken0 = ZERO_BI
pairTotal.volumeToken1 = ZERO_BI
pairTotal.volumeToken0 = ZERO_BD
pairTotal.volumeToken1 = ZERO_BD
pairTotal.volumeTradedEth = ZERO_BD
pairTotal.volumeTradedUsd = ZERO_BD
}
Expand All @@ -171,8 +171,8 @@ export namespace pairs {
pairDailyTotal.token0 = token0
pairDailyTotal.token1 = token1
pairDailyTotal.timestamp = timestamp
pairDailyTotal.volumeToken0 = ZERO_BI
pairDailyTotal.volumeToken1 = ZERO_BI
pairDailyTotal.volumeToken0 = ZERO_BD
pairDailyTotal.volumeToken1 = ZERO_BD
pairDailyTotal.volumeTradedEth = ZERO_BD
pairDailyTotal.volumeTradedUsd = ZERO_BD
}
Expand All @@ -191,8 +191,8 @@ export namespace pairs {
pairHourlyTotal.token0 = token0
pairHourlyTotal.token1 = token1
pairHourlyTotal.timestamp = timestamp
pairHourlyTotal.volumeToken0 = ZERO_BI
pairHourlyTotal.volumeToken1 = ZERO_BI
pairHourlyTotal.volumeToken0 = ZERO_BD
pairHourlyTotal.volumeToken1 = ZERO_BD
pairHourlyTotal.volumeTradedEth = ZERO_BD
pairHourlyTotal.volumeTradedUsd = ZERO_BD
}
Expand Down
8 changes: 5 additions & 3 deletions src/modules/settlements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getEthPriceInUSD } from "../utils/pricing"

export namespace settlements {

export function getOrCreateSettlement(txHash: Bytes, tradeTimestamp: i32, solver: Address, txGasPrice: BigInt, feeAmountUsd: BigDecimal): void {
export function getOrCreateSettlement(txHash: Bytes, tradeTimestamp: i32, solver: Address, txGasPrice: BigInt, feeAmountUsd: BigDecimal | null): void {

let settlementId = txHash.toHexString()
let network = dataSource.network()
Expand Down Expand Up @@ -36,8 +36,10 @@ export namespace settlements {
settlement.profitability = ZERO_BD
totals.addSettlementCount(tradeTimestamp)
}
let prevFeeAmountUsd = settlement.aggregatedFeeAmountUsd
settlement.aggregatedFeeAmountUsd = prevFeeAmountUsd.plus(feeAmountUsd)
if(feeAmountUsd) {
let prevFeeAmountUsd = settlement.aggregatedFeeAmountUsd
settlement.aggregatedFeeAmountUsd = prevFeeAmountUsd.plus(feeAmountUsd)
}
settlement.profitability = settlement.aggregatedFeeAmountUsd.minus(settlement.txCostUsd)
settlement.save()
}
Expand Down
6 changes: 3 additions & 3 deletions src/modules/trades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export namespace trades {
let buyTokenId = buyToken.id
let sellTokenId = sellToken.id

let buyTokenPriceUsd = buyToken.priceUsd as BigDecimal
let sellTokenPriceUsd = sellToken.priceUsd as BigDecimal
let buyTokenPriceUsd = _buyTokenPriceUsd ? _buyTokenPriceUsd as BigDecimal : null
let sellTokenPriceUsd = _sellTokenPriceUsd ? _sellTokenPriceUsd as BigDecimal : null

tokens.createTokenTradingEvent(timestamp, buyTokenId, tradeId, buyAmount, buyAmountEth, buyAmountUsd, buyTokenPriceUsd)
tokens.createTokenTradingEvent(timestamp, sellTokenId, tradeId, sellAmount, sellAmountEth, sellAmountUsd, sellTokenPriceUsd)
Expand Down Expand Up @@ -92,7 +92,7 @@ export namespace trades {

totals.addVolumesAndFees(ethAmountForVolumes, usdAmountForVolumes, feeAmountEth, feeAmountUsd, timestamp)

pairs.createOrUpdatePair(timestamp, buyTokenId, sellTokenId, buyAmount, sellAmount,
pairs.createOrUpdatePair(timestamp, buyTokenId, sellTokenId,
sellAmountEth, sellAmountUsd, buyTokenPriceUsd, sellTokenPriceUsd, buyAmountDecimals, sellAmountDecimals)
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/getPrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ function getUniswapPricesForPair(token0: Address, token1: Address, isEthPriceCal
let reservesTry = pair.try_getReserves()
let reserves = reservesTry.reverted ? EMPTY_RESERVES_RESULT : reservesTry.value
let pairToken0Try = pair.try_token0()
let pairToken0 = pairToken0Try.reverted ? ZERO_ADDRESS as Address : pairToken0Try.value
let pairToken0 = pairToken0Try.reverted ? changetype<Address>(ZERO_ADDRESS) : pairToken0Try.value
let pairToken1Try = pair.try_token1()
let pairToken1 = pairToken1Try.reverted ? ZERO_ADDRESS as Address : pairToken1Try.value
let pairToken1 = pairToken1Try.reverted ? changetype<Address>(ZERO_ADDRESS) : pairToken1Try.value

if (reserves.value0 == ZERO_BI ||
reserves.value1 == ZERO_BI ||
Expand Down