From 4e644f3e86c59f344c54c71f043d9e8856195df7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Nicol=C3=A1s=20Gonz=C3=A1lez?= Date: Wed, 17 Aug 2022 17:24:24 -0300 Subject: [PATCH 1/3] Added volume decimals --- schema.graphql | 12 ++++++++++++ src/modules/pairs.ts | 31 +++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/schema.graphql b/schema.graphql index 2174168..ae4f436 100644 --- a/schema.graphql +++ b/schema.graphql @@ -346,6 +346,10 @@ type Pair @entity { volumeToken0: BigInt! "Total volume of token 1 traded" volumeToken1: BigInt! + "Total volume of token 0 expressed on token 0 decimals" + volumeToken0Decimals: BigDecimal! + "Total volume of token 1 expressed on token 1 decimals" + volumeToken1Decimals: BigDecimal! "Total volume in Eth" volumeTradedEth: BigDecimal "Total volume in Usd" @@ -373,6 +377,10 @@ type PairDaily @entity { volumeToken0: BigInt! "Total volume of token 1 traded" volumeToken1: BigInt! + "Total volume of token 0 expressed on token 0 decimals" + volumeToken0Decimals: BigDecimal! + "Total volume of token 1 expressed on token 1 decimals" + volumeToken1Decimals: BigDecimal! "Total volume in Eth" volumeTradedEth: BigDecimal "Total volume in Usd" @@ -400,6 +408,10 @@ type PairHourly @entity { volumeToken0: BigInt! "Total volume of token 1 traded" volumeToken1: BigInt! + "Total volume of token 0 expressed on token 0 decimals" + volumeToken0Decimals: BigDecimal! + "Total volume of token 1 expressed on token 1 decimals" + volumeToken1Decimals: BigDecimal! "Total volume in Eth" volumeTradedEth: BigDecimal "Total volume in Usd" diff --git a/src/modules/pairs.ts b/src/modules/pairs.ts index 68e6f15..7bbe20c 100644 --- a/src/modules/pairs.ts +++ b/src/modules/pairs.ts @@ -9,16 +9,19 @@ export namespace pairs { token: string volume: BigInt price: BigDecimal | null + priceInDecimals: BigDecimal relativePrice: BigDecimal constructor( _token: string, _volume: BigInt, _price: BigDecimal | null, + _priceInDecimals: BigDecimal, _relativePrice: BigDecimal ) { this.token = _token this.volume = _volume this.price = _price + this.priceInDecimals = _priceInDecimals this.relativePrice = _relativePrice } } @@ -32,12 +35,14 @@ export namespace pairs { let token0 = token0Props.token let volumeToken0 = token0Props.volume let priceToken0 = token0Props.price + let token0Decimals = token0Props.priceInDecimals let token0RelativePrice = token0Props.relativePrice let token1Props = canonicalMarket.get("token1") let token1 = token1Props.token let volumeToken1 = token1Props.volume let priceToken1 = token1Props.price + let token1Decimals = token1Props.priceInDecimals let token1RelativePrice = token1Props.relativePrice let pairTotal = getOrCreatePair(token0, token1) @@ -46,7 +51,7 @@ export namespace pairs { totalsUpdate(timestamp, pairTotal, pairDailyTotal, pairHourlyTotal, volumeToken0, volumeToken1, priceToken0, priceToken1, - token0RelativePrice, token1RelativePrice, + token0RelativePrice, token1RelativePrice, token0Decimals, token1Decimals, sellAmountEth, sellAmountUsd) } @@ -70,8 +75,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, buyAmount, buyTokenPriceUsd, buyAmountDecimals, buyTokenExpressedOnSellToken) + let sellTokenProps = new TokenProps(sellTokenId, sellAmount, sellTokenPriceUsd, sellAmountDecimals, sellTokenExpressedOnBuyToken) if (buyTokenNumber.lt(sellTokenNumber)) { value.set("token0", buyTokenProps) @@ -86,20 +91,26 @@ export namespace pairs { function totalsUpdate(timestamp: i32, pair: Pair, pairDaily: PairDaily, pairHourly: PairHourly, volumeToken0: BigInt, volumeToken1: BigInt, priceToken0: BigDecimal | null, priceToken1: BigDecimal | null, token0RelativePrice: BigDecimal, token1RelativePrice: BigDecimal, - sellAmountEth: BigDecimal | null, sellAmountUsd: BigDecimal | null): void { + token0PriceDecimals: BigDecimal, token1PriceDecimals: BigDecimal, sellAmountEth: BigDecimal | null, sellAmountUsd: BigDecimal | null): void { let prevPairTotalVolume0 = pair.volumeToken0 let prevPairTotalVolume1 = pair.volumeToken1 + let prevPairTotalVolume0Decimals = pair.volumeToken0Decimals + let prevPairTotalVolume1Decimals = pair.volumeToken1Decimals let prevPairTotalEth = pair.volumeTradedEth let prevPairTotalUsd = pair.volumeTradedUsd let prevPairDailyVolume0 = pairDaily.volumeToken0 let prevPairDailyVolume1 = pairDaily.volumeToken1 + let prevPairDailyVolume0Decimals = pairDaily.volumeToken0Decimals + let prevPairDailyVolume1Decimals = pairDaily.volumeToken1Decimals let prevPairDailyEth = pairDaily.volumeTradedEth let prevPairDailyUsd = pairDaily.volumeTradedUsd let prevPairHourlyVolume0 = pairHourly.volumeToken0 let prevPairHourlyVolume1 = pairHourly.volumeToken1 + let prevPairHourlyVolume0Decimals = pairHourly.volumeToken0Decimals + let prevPairHourlyVolume1Decimals = pairHourly.volumeToken1Decimals let prevPairHourlyEth = pairHourly.volumeTradedEth let prevPairHourlyUsd = pairHourly.volumeTradedUsd @@ -107,6 +118,8 @@ export namespace pairs { // Updates volumes for a pair pair.volumeToken0 = prevPairTotalVolume0.plus(volumeToken0) pair.volumeToken1 = prevPairTotalVolume1.plus(volumeToken1) + pair.volumeToken0Decimals = prevPairTotalVolume0Decimals.plus(token0PriceDecimals) + pair.volumeToken1Decimals = prevPairTotalVolume1Decimals.plus(token1PriceDecimals) if (prevPairTotalEth !== null && sellAmountEth) { pair.volumeTradedEth = prevPairTotalEth.plus(sellAmountEth) } @@ -123,6 +136,8 @@ export namespace pairs { // update volumes for a pair daily totals pairDaily.volumeToken0 = prevPairDailyVolume0.plus(volumeToken0) pairDaily.volumeToken1 = prevPairDailyVolume1.plus(volumeToken1) + pairDaily.volumeToken0Decimals = prevPairDailyVolume0Decimals.plus(token0PriceDecimals) + pairDaily.volumeToken1Decimals = prevPairDailyVolume1Decimals.plus(token1PriceDecimals) pairDaily.volumeTradedEth = sellAmountEth && prevPairDailyEth ? prevPairDailyEth.plus(sellAmountEth) : prevPairDailyEth pairDaily.volumeTradedUsd = sellAmountUsd && prevPairDailyUsd ? prevPairDailyUsd.plus(sellAmountUsd) : prevPairDailyUsd pairDaily.token0Usd = priceToken0 @@ -134,6 +149,8 @@ export namespace pairs { // update volumes for a pair hourly totals pairHourly.volumeToken0 = prevPairHourlyVolume0.plus(volumeToken0) pairHourly.volumeToken1 = prevPairHourlyVolume1.plus(volumeToken1) + pairHourly.volumeToken0Decimals = prevPairHourlyVolume0Decimals.plus(token0PriceDecimals) + pairHourly.volumeToken1Decimals = prevPairHourlyVolume1Decimals.plus(token1PriceDecimals) pairHourly.volumeTradedEth = sellAmountEth && prevPairHourlyEth ? prevPairHourlyEth.plus(sellAmountEth) : prevPairHourlyEth pairHourly.volumeTradedUsd = sellAmountUsd && prevPairHourlyUsd ? prevPairHourlyUsd.plus(sellAmountUsd) : prevPairHourlyUsd pairHourly.token0Usd = priceToken0 @@ -154,6 +171,8 @@ export namespace pairs { pairTotal.token1 = token1 pairTotal.volumeToken0 = ZERO_BI pairTotal.volumeToken1 = ZERO_BI + pairTotal.volumeToken0Decimals = ZERO_BD + pairTotal.volumeToken1Decimals = ZERO_BD pairTotal.volumeTradedEth = ZERO_BD pairTotal.volumeTradedUsd = ZERO_BD } @@ -173,6 +192,8 @@ export namespace pairs { pairDailyTotal.timestamp = timestamp pairDailyTotal.volumeToken0 = ZERO_BI pairDailyTotal.volumeToken1 = ZERO_BI + pairDailyTotal.volumeToken0Decimals = ZERO_BD + pairDailyTotal.volumeToken1Decimals = ZERO_BD pairDailyTotal.volumeTradedEth = ZERO_BD pairDailyTotal.volumeTradedUsd = ZERO_BD } @@ -193,6 +214,8 @@ export namespace pairs { pairHourlyTotal.timestamp = timestamp pairHourlyTotal.volumeToken0 = ZERO_BI pairHourlyTotal.volumeToken1 = ZERO_BI + pairHourlyTotal.volumeToken0Decimals = ZERO_BD + pairHourlyTotal.volumeToken1Decimals = ZERO_BD pairHourlyTotal.volumeTradedEth = ZERO_BD pairHourlyTotal.volumeTradedUsd = ZERO_BD } From cac6b34591e8db60581a570b90c10a690a691f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Nicol=C3=A1s=20Gonz=C3=A1lez?= Date: Fri, 19 Aug 2022 12:36:42 -0300 Subject: [PATCH 2/3] updated documentation --- model.md | 91 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 46 insertions(+), 45 deletions(-) diff --git a/model.md b/model.md index 515f985..92cbca4 100644 --- a/model.md +++ b/model.md @@ -8,7 +8,7 @@ classDiagram class User { id: ID! address: Bytes! - firstTradeTimestamp: BigInt + firstTradeTimestamp: Int! ordersPlaced: [Order!]! @derivedFrom(field: "owner") isSolver: Boolean! numberOfTrades: Int! @@ -23,11 +23,11 @@ User --o Order : ordersPlaced class Token { id: ID! address: Bytes! - firstTradeTimestamp: BigInt + firstTradeTimestamp: Int! name: String! symbol: String! decimals: Int! - totalVolume: BigInt + totalVolume: BigInt! priceEth: BigDecimal priceUsd: BigDecimal allowedPools: [BigInt!]! @@ -35,8 +35,8 @@ class Token { hourlyTotals: [TokenHourlyTotal!]! @derivedFrom(field: "token") dailyTotals: [TokenDailyTotal!]! @derivedFrom(field: "token") numberOfTrades: Int! - totalVolumeUsd: BigDecimal - totalVolumeEth: BigDecimal + totalVolumeUsd: BigDecimal! + totalVolumeEth: BigDecimal! } Token --o TokenTradingEvent : History @@ -46,9 +46,9 @@ Token --o TokenHourlyTotal : hourlyTotals class Order { id: ID! owner: User - tradesTimestamp: BigInt - invalidateTimestamp: BigInt - presignTimestamp: BigInt + tradesTimestamp: Int + invalidateTimestamp: Int + presignTimestamp: Int trades: [Trade!] @derivedFrom(field: "order") isSigned: Boolean isValid: Boolean @@ -58,7 +58,7 @@ Order --o Trade : trades class Trade { id: ID! - timestamp: BigInt! + timestamp: Int! gasPrice: BigInt! feeAmount: BigInt! feeAmountUsd: BigDecimal @@ -84,11 +84,11 @@ Trade --o Settlement : settlement class Settlement { id: ID! txHash: Bytes! - firstTradeTimestamp: BigInt! + firstTradeTimestamp: Int! trades: [Trade!] @derivedFrom(field: "settlement") solver: User txCostUsd: BigDecimal! - aggregatedFeeAmountUsd: BigDecimal + aggregatedFeeAmountUsd: BigDecimal! profitability: BigDecimal! } @@ -110,8 +110,7 @@ class Total { class DailyTotal { id: ID! - timestamp: BigInt! - totalTokens: BigInt! + timestamp: Int! numberOfTrades: BigInt! orders: BigInt! settlements: BigInt! @@ -119,15 +118,11 @@ class DailyTotal { volumeEth: BigDecimal feesUsd: BigDecimal feesEth: BigDecimal - tokens: [Token!]! } -DailyTotal --o Token : tokens - class HourlyTotal { id: ID! - timestamp: BigInt! - totalTokens: BigInt! + timestamp: Int! numberOfTrades: BigInt! orders: BigInt! settlements: BigInt! @@ -135,15 +130,13 @@ class HourlyTotal { volumeEth: BigDecimal feesUsd: BigDecimal feesEth: BigDecimal - tokens: [Token!]! } -HourlyTotal --o Token : tokens class TokenDailyTotal { id: ID! token: Token! - timestamp: BigInt! + timestamp: Int! totalVolume: BigInt! totalVolumeUsd: BigDecimal! totalVolumeEth: BigDecimal! @@ -158,7 +151,7 @@ class TokenDailyTotal { class TokenHourlyTotal { id: ID! token: Token! - timestamp: BigInt! + timestamp: Int! totalVolume: BigInt! totalVolumeUsd: BigDecimal! totalVolumeEth: BigDecimal! @@ -174,23 +167,27 @@ class TokenTradingEvent { id: ID! token: Token! trade: Trade! - timestamp: BigInt! - amountEth: BigDecimal! - amountUsd: BigDecimal! + timestamp: Int! + amountEth: BigDecimal + amountUsd: BigDecimal } TokenTradingEvent --o Token : token +TokenTradingEvent --o Trade : trade class Pair { id: ID! token0: Token! token1: Token! - token0Price: BigDecimal - token1Price: BigDecimal - token0relativePrice: BigDecimal - token1relativePrice: BigDecimal - volumeToken0: BigInt - volumeToken1: BigInt + lastTradeTimestamp: Int! + token0Usd: BigDecimal + token1Usd: BigDecimal + token0PriceInToken1: BigDecimal + token1PriceInToken0: BigDecimal + volumeToken0: BigInt! + volumeToken1: BigInt! + volumeToken0Deciomals: BigDecimal! + volumeToken1Deciomals: BigDecimal! volumeTradedEth: BigDecimal volumeTradedUsd: BigDecimal } @@ -202,13 +199,15 @@ class PairDaily { id: ID! token0: Token! token1: Token! - token0Price: BigDecimal - token1Price: BigDecimal - token0relativePrice: BigDecimal - token1relativePrice: BigDecimal - timestamp: BigInt - volumeToken0: BigInt - volumeToken1: BigInt + token0Usd: BigDecimal + token1Usd: BigDecimal + token0PriceInToken0: BigDecimal + token1PriceInToken1: BigDecimal + timestamp: Int + volumeToken0: BigInt! + volumeToken1: BigInt! + volumeToken0Deciomals: BigDecimal! + volumeToken1Deciomals: BigDecimal! volumeTradedEth: BigDecimal volumeTradedUsd: BigDecimal } @@ -220,13 +219,15 @@ class PairHourly { id: ID! token0: Token! token1: Token! - token0Price: BigDecimal - token1Price: BigDecimal - token0relativePrice: BigDecimal - token1relativePrice: BigDecimal - timestamp: BigInt - volumeToken0: BigInt - volumeToken1: BigInt + token0Usd: BigDecimal + token1Usd: BigDecimal + token0PriceInToken0: BigDecimal + token1PriceInToken1: BigDecimal + timestamp: Int + volumeToken0: BigInt! + volumeToken1: BigInt! + volumeToken0Deciomals: BigDecimal! + volumeToken1Deciomals: BigDecimal! volumeTradedEth: BigDecimal volumeTradedUsd: BigDecimal } From b02b8e02301f515ba14ad9be77e4a7bd6dcfbf80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Nicol=C3=A1s=20Gonz=C3=A1lez?= Date: Fri, 19 Aug 2022 12:45:04 -0300 Subject: [PATCH 3/3] fixed models docs --- model.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/model.md b/model.md index 92cbca4..ca5bed7 100644 --- a/model.md +++ b/model.md @@ -203,7 +203,7 @@ class PairDaily { token1Usd: BigDecimal token0PriceInToken0: BigDecimal token1PriceInToken1: BigDecimal - timestamp: Int + timestamp: Int! volumeToken0: BigInt! volumeToken1: BigInt! volumeToken0Deciomals: BigDecimal! @@ -223,7 +223,7 @@ class PairHourly { token1Usd: BigDecimal token0PriceInToken0: BigDecimal token1PriceInToken1: BigDecimal - timestamp: Int + timestamp: Int! volumeToken0: BigInt! volumeToken1: BigInt! volumeToken0Deciomals: BigDecimal!