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

feat(#major); abracadabra; subgraph optimizations #2446

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
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"
}
}
118 changes: 89 additions & 29 deletions subgraphs/abracadabra/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum ProtocolType {

type Token @entity @regularPolling {
" Smart contract address of the token "
id: ID!
id: Bytes!
melotik marked this conversation as resolved.
Show resolved Hide resolved

" Name of the token, mirrored from the smart contract "
name: String!
Expand Down Expand Up @@ -65,7 +65,7 @@ enum RewardTokenType {

type RewardToken @entity @regularPolling {
" { Reward token type }-{ Smart contract address of the reward token } "
id: ID!
id: Bytes!

" Reference to the actual token "
token: Token!
Expand Down Expand Up @@ -123,7 +123,7 @@ enum PositionSide {
# to the IDs to differentiate.
type InterestRate @entity @regularPolling {
" { Interest rate side }-{ Interest rate type }-{ Market ID } "
id: ID!
id: Bytes!

" Interest rate in percentage APY. E.g. 5.21% should be stored as 5.21 "
rate: BigDecimal!
Expand All @@ -147,7 +147,7 @@ type InterestRate @entity @regularPolling {

interface Protocol {
" Smart contract address of the protocol's main contract (Factory, Registry, etc) "
id: ID!
id: Bytes!

" Name of the protocol, including version. e.g. Uniswap v3 "
name: String!
Expand Down Expand Up @@ -209,7 +209,7 @@ interface Protocol {

type LendingProtocol implements Protocol @entity @regularPolling {
" Smart contract address of the protocol's main contract (Factory, Registry, etc) "
id: ID!
id: Bytes!

" Name of the protocol, including version. e.g. Aave v2 "
name: String!
Expand Down 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 @@ -320,16 +326,22 @@ type LendingProtocol implements Protocol @entity @regularPolling {

##### Add ons #####

marketIDList: [String!]!
marketIDList: [Bytes!]!

" 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!
id: Bytes!

" Protocol this snapshot is associated with "
protocol: LendingProtocol!
Expand Down Expand Up @@ -392,9 +404,9 @@ type UsageMetricsDailySnapshot @entity @dailySnapshot {
timestamp: BigInt!
}

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

" Protocol this snapshot is associated with "
protocol: LendingProtocol!
Expand Down Expand Up @@ -430,9 +442,9 @@ 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!
id: Bytes!

" Protocol this snapshot is associated with "
protocol: LendingProtocol!
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 All @@ -511,7 +529,7 @@ type FinancialsDailySnapshot @entity @dailySnapshot {

type Market @entity @regularPolling {
" Smart contract address of the market "
id: ID!
id: Bytes!

" The protocol this pool belongs to "
protocol: LendingProtocol!
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,15 +680,21 @@ 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!
id: Bytes!

" The protocol this snapshot belongs to "
protocol: LendingProtocol!
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,9 +794,9 @@ 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!
id: Bytes!

" The protocol this snapshot belongs to "
protocol: LendingProtocol!
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 @@ -860,7 +902,7 @@ type MarketHourlySnapshot @entity @hourlySnapshot {

type Account @entity @regularPolling {
" { Account address } "
id: ID!
id: Bytes!

" Number of positions this account has "
positionCount: Int!
Expand Down Expand Up @@ -913,7 +955,7 @@ type Account @entity @regularPolling {

type Position @entity @regularPolling {
" { Account address }-{ Market address }-{ Position Side }-{ Counter } "
id: ID!
id: Bytes!

count: Int

Expand Down Expand Up @@ -992,7 +1034,7 @@ type Position @entity @regularPolling {
# Note that we only take snapshot for open positions
type PositionSnapshot @entity @hourlySnapshot {
" { Position ID }-{ Transaction hash }-{ Log index } "
id: ID!
id: Bytes!

" Transaction hash of the transaction that triggered this snapshot "
hash: String!
Expand Down Expand Up @@ -1030,7 +1072,7 @@ contracts.
"""
type Deposit @entity(immutable: true) @transaction {
" { Transaction hash }-{ Log index } "
id: ID!
id: Bytes!

" Transaction hash of the transaction that emitted this event "
hash: String!
Expand Down Expand Up @@ -1068,7 +1110,7 @@ type Deposit @entity(immutable: true) @transaction {

type Withdraw @entity(immutable: true) @transaction {
" { Transaction hash }-{ Log index }"
id: ID!
id: Bytes!

" Transaction hash of the transaction that emitted this event "
hash: String!
Expand Down Expand Up @@ -1111,7 +1153,7 @@ type Withdraw @entity(immutable: true) @transaction {
# For CDPs, use this for mint events
type Borrow @entity(immutable: true) @transaction {
" { Transaction hash }-{ Log index } "
id: ID!
id: Bytes!

" Transaction hash of the transaction that emitted this event "
hash: String!
Expand Down Expand Up @@ -1150,7 +1192,7 @@ type Borrow @entity(immutable: true) @transaction {
# For CDPs, use this for burn events
type Repay @entity(immutable: true) @transaction {
" { Transaction hash }-{ Log index } "
id: ID!
id: Bytes!

" Transaction hash of the transaction that emitted this event "
hash: String!
Expand Down Expand Up @@ -1188,7 +1230,7 @@ type Repay @entity(immutable: true) @transaction {

type Liquidate @entity(immutable: true) @transaction {
" { Transaction hash }-{ Log index } "
id: ID!
id: Bytes!

" Transaction hash of the transaction that emitted this event "
hash: String!
Expand Down Expand Up @@ -1233,18 +1275,18 @@ type Liquidate @entity(immutable: true) @transaction {
# Helper entity for calculating daily/hourly active users
type ActiveAccount @entity {
" { daily/hourly }-{ Address of the account }-{ Days/hours since Unix epoch } "
id: ID!
id: Bytes!
}

type LiquidateProxy @entity {
" { Transaction hash }-{ Log index } "
id: ID!
id: Bytes!
amount: BigInt!
}

type PositionCounter @entity {
" { Account address }-{ Market address }-{ Position Side } "
id: ID!
id: Bytes!

" Next count "
nextCount: Int!
Expand All @@ -1253,5 +1295,23 @@ type PositionCounter @entity {
# Helper entity for calculating daily/hourly active users
type ActiveEventAccount @entity {
"{ daily/hourly }-{ Address of the account }-{ Days/hours since Unix epoch }-{ EventType: Optional }"
id: ID!
id: Bytes!
}

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

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
Loading