Skip to content

Commit

Permalink
feat(#major); abracadabra; subgraph optimizations (#2446)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruv-chauhan authored Jan 6, 2024
1 parent d8e3560 commit 9ad3f98
Show file tree
Hide file tree
Showing 10 changed files with 3,525 additions and 4,273 deletions.
6,657 changes: 2,950 additions & 3,707 deletions subgraphs/abracadabra/package-lock.json

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions subgraphs/abracadabra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"format": "npx prettier --write ."
},
"dependencies": {
"@graphprotocol/graph-cli": "0.42.4",
"@graphprotocol/graph-ts": "0.29.3",
"prettier": "^2.7.1"
"@graphprotocol/graph-cli": "^0.64.0",
"@graphprotocol/graph-ts": "^0.32.0"
},
"devDependencies": {
"prettier": "^3.1.1"
}
}
70 changes: 65 additions & 5 deletions subgraphs/abracadabra/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ type LendingProtocol implements Protocol @entity @regularPolling {
" Sum of all historical liquidations in USD "
cumulativeLiquidateUSD: BigDecimal!

" Sum of all historical withdrawals in USD "
cumulativeWithdrawUSD: BigDecimal!

" Sum of all historical repayments in USD "
cumulativeRepayUSD: BigDecimal!

" Total supply of minted tokens in native amounts, with same ordering as mintedTokens. Only applies to CDP "
mintedTokenSupplies: [BigInt!]

Expand Down Expand Up @@ -321,13 +327,19 @@ type LendingProtocol implements Protocol @entity @regularPolling {
##### Add ons #####

marketIDList: [String!]!

" Helper field for taking daily snapshots "
_lastDailySnapshotTimestamp: BigInt!

" Helper field for taking hourly snapshots "
_lastHourlySnapshotTimestamp: BigInt!
}

###############################
##### Protocol Timeseries #####
###############################

type UsageMetricsDailySnapshot @entity @dailySnapshot {
type UsageMetricsDailySnapshot @entity(immutable: true) @dailySnapshot {
" ID is # of days since Unix epoch time "
id: ID!

Expand Down Expand Up @@ -392,7 +404,7 @@ type UsageMetricsDailySnapshot @entity @dailySnapshot {
timestamp: BigInt!
}

type UsageMetricsHourlySnapshot @entity @hourlySnapshot {
type UsageMetricsHourlySnapshot @entity(immutable: true) @hourlySnapshot {
" { # of hours since Unix epoch time } "
id: ID!

Expand Down Expand Up @@ -430,7 +442,7 @@ type UsageMetricsHourlySnapshot @entity @hourlySnapshot {
timestamp: BigInt!
}

type FinancialsDailySnapshot @entity @dailySnapshot {
type FinancialsDailySnapshot @entity(immutable: true) @dailySnapshot {
" ID is # of days since Unix epoch time "
id: ID!

Expand Down Expand Up @@ -501,8 +513,14 @@ type FinancialsDailySnapshot @entity @dailySnapshot {
" Total assets withdrawn on a given day, in USD. "
dailyWithdrawUSD: BigDecimal!

" Sum of all historical withdrawals in USD "
cumulativeWithdrawUSD: BigDecimal!

" Total assets repaid on a given day, in USD. "
dailyRepayUSD: BigDecimal!

" Sum of all historical repayments in USD "
cumulativeRepayUSD: BigDecimal!
}

###############################
Expand Down Expand Up @@ -578,6 +596,12 @@ type Market @entity @regularPolling {
" Sum of all historical liquidations in USD "
cumulativeLiquidateUSD: BigDecimal!

" Sum of all historical withdrawals in USD "
cumulativeWithdrawUSD: BigDecimal!

" Sum of all historical repayments in USD "
cumulativeRepayUSD: BigDecimal!

##### Token Balances #####

" Amount of input tokens in the market "
Expand Down Expand Up @@ -656,13 +680,19 @@ type Market @entity @regularPolling {

" Market's price oracle "
priceOracle: Bytes

" Helper field for taking daily snapshots "
_lastDailySnapshotTimestamp: BigInt!

" Helper field for taking hourly snapshots "
_lastHourlySnapshotTimestamp: BigInt!
}

#################################
##### Pool-Level Timeseries #####
#################################

type MarketDailySnapshot @entity @dailySnapshot {
type MarketDailySnapshot @entity(immutable: true) @dailySnapshot {
" { Smart contract address of the market }-{ # of days since Unix epoch time } "
id: ID!

Expand Down Expand Up @@ -731,9 +761,15 @@ type MarketDailySnapshot @entity @dailySnapshot {
" Total assets withdrawn on a given day, in USD. "
dailyWithdrawUSD: BigDecimal!

" Sum of all historical withdrawals in USD "
cumulativeWithdrawUSD: BigDecimal!

" Total assets repaid on a given day, in USD. "
dailyRepayUSD: BigDecimal!

" Sum of all historical repayments in USD "
cumulativeRepayUSD: BigDecimal!

##### Token Balances #####

" Amount of input token in the market. "
Expand All @@ -758,7 +794,7 @@ type MarketDailySnapshot @entity @dailySnapshot {
rewardTokenEmissionsUSD: [BigDecimal!]
}

type MarketHourlySnapshot @entity @hourlySnapshot {
type MarketHourlySnapshot @entity(immutable: true) @hourlySnapshot {
" { Smart contract address of the market }-{ # of hours since Unix epoch time } "
id: ID!

Expand Down Expand Up @@ -827,9 +863,15 @@ type MarketHourlySnapshot @entity @hourlySnapshot {
" Total assets withdrawn on a given hour, in USD. "
hourlyWithdrawUSD: BigDecimal!

" Sum of all historical withdrawals in USD "
cumulativeWithdrawUSD: BigDecimal!

" Total assets repaid on a given hour, in USD. "
hourlyRepayUSD: BigDecimal!

" Sum of all historical repayments in USD "
cumulativeRepayUSD: BigDecimal!

##### Token Balances #####

" Amount of input token in the market. "
Expand Down Expand Up @@ -1255,3 +1297,21 @@ type ActiveEventAccount @entity {
"{ daily/hourly }-{ Address of the account }-{ Days/hours since Unix epoch }-{ EventType: Optional }"
id: ID!
}

# Helper entity for calculating daily/hourly fields
type _ActivityHelper @entity {
id: ID!

activeUsers: Int!
activeDepositors: Int!
activeBorrowers: Int!
activeLiquidators: Int!
activeLiquidatees: Int!

transactionCount: Int!
depositCount: Int!
borrowCount: Int!
liquidateCount: Int!
withdrawCount: Int!
repayCount: Int!
}
5 changes: 5 additions & 0 deletions subgraphs/abracadabra/src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ export namespace PositionSide {
export const BORROWER = "BORROWER";
}

export namespace ActivityInterval {
export const HOURLY = "HOURLY";
export const DAILY = "DAILY";
}

//////////////////////////////
///// Ethereum Addresses /////
//////////////////////////////
Expand Down
Loading

0 comments on commit 9ad3f98

Please sign in to comment.