Skip to content

Commit

Permalink
Schema upgrade: 1.3.0 (messari#310)
Browse files Browse the repository at this point in the history
* Added pool-level revenue

* Fix markdown formatting issue in comments

* Updated constants

* Schema changes for Bancor v3

* Address code review comments
  • Loading branch information
this-username-is-taken authored and 0xbe1 committed Jun 27, 2022
1 parent ac356aa commit 5771617
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 31 deletions.
8 changes: 8 additions & 0 deletions docs/Schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ Entity IDs are usually defined by either an address, a transaction hash, a log i

Note that entity types that derive from the same interface cannot have the same IDs. For example, a `Withdraw` entity and a `Deposit` entity cannot have the same ID since they both implement the `Event` interface. In this case, we prefix the ID by `withdraw-` or `deposit-` in order to make them unique. You can use the helper function `prefixID(string, string)` in `common/utils/strings.ts` to make this easier.

Certain protocols may require adjustments to the ID of specific entities to handle edge cases (e.g. single-sided liquidity pools or single-sided staking). Feel free to make adjustments necessary to best fit the situation. Make sure these are documented in the README of the specific subgraphs.

Here are some examples:

- Convex doesn't have vault contracts for individual vaults. The Vault IDs for Convex is stored as { the Booster contract address }-{ pool ID }.
- Bancor v3 creates a reward program that has start and end date for a few tokens deposited (DAI, ETH, etc). The reward is always in BNT. So the ID is being stored as " { Reward token type }-{ Smart contract address of the deposited token }-{ start }-{ end } " such as `DEPOSIT-<DAI ADDRESS>-16xxxxxx-16xxxxxxx`.
- For pools that support single-sided staking, we can store each side as a separate pool, set `isSingleSided` as true, and differentiate with their ID (e.g. { Address of parent pool }- { Address/pid of staking pool }).

## Transaction vs. Event

The most granular data we index in the subgraphs are Event entities. They are very similar to the events in Ethereum event logs but not exactly the same. Conceptually, an Event entity uniquely represents a user action that has occurred in a protocol.
Expand Down
75 changes: 68 additions & 7 deletions schema-dex-amm.graphql
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
# Subgraph Schema: DEX AMM
# Version: 1.2.1
# Version: 1.3.0
# See https://github.com/messari/subgraphs/blob/master/docs/Schema.md for details

enum Network {
ARBITRUM_ONE
ARWEAVE_MAINNET
AURORA
AVALANCHE
BOBA
BSC # aka BNB Chain
CELO
COSMOS
CRONOS
MAINNET # Ethereum Mainnet
FANTOM
FUSE
HARMONY
JUNO
MOONBEAM
MOONRIVER
NEAR_MAINNET
OPTIMISM
OSMOSIS
MATIC # aka Polygon
XDAI # aka Gnosis Chain
}
Expand Down Expand Up @@ -92,6 +99,12 @@ enum LiquidityPoolFeeType {

" Some protocols use dynamic protocol fees (e.g., Bancor v2). Set `feePercentage` as 0 but handle the dynamic fees in the mapping code. "
DYNAMIC_PROTOCOL_FEE

" One-time fee charged by the protocol during deposit, in percentages of the deposit token "
DEPOSIT_FEE

" One-time fee charged by the protocol (e.g. Bancor v3) during withdrawal, in percentages of the withdrawal token "
WITHDRAWAL_FEE
}

type LiquidityPoolFee @entity {
Expand Down Expand Up @@ -151,7 +164,7 @@ interface Protocol {
" All revenue generated by the protocol. e.g. 0.30% of swap fee in Sushiswap, all yield generated by Yearn. "
cumulativeTotalRevenueUSD: BigDecimal!

" # of cumulative unique users "
" Number of cumulative unique users "
cumulativeUniqueUsers: Int!

##### Snapshots #####
Expand Down Expand Up @@ -211,7 +224,7 @@ type DexAmmProtocol implements Protocol @entity {
" All revenue generated by the protocol. e.g. 0.30% of swap fee in Sushiswap, all yield generated by Yearn. "
cumulativeTotalRevenueUSD: BigDecimal!

" # of cumulative unique users "
" Number of cumulative unique users "
cumulativeUniqueUsers: Int!

##### Snapshots #####
Expand Down Expand Up @@ -242,10 +255,10 @@ type UsageMetricsDailySnapshot @entity {
" Protocol this snapshot is associated with "
protocol: DexAmmProtocol!

" # of unique daily active users "
" Number of unique daily active users "
dailyActiveUsers: Int!

" # of cumulative unique users "
" Number of cumulative unique users "
cumulativeUniqueUsers: Int!

" Total number of transactions occurred in a day. Transactions include all entities that implement the Event interface. "
Expand Down Expand Up @@ -274,10 +287,10 @@ type UsageMetricsHourlySnapshot @entity {
" Protocol this snapshot is associated with "
protocol: DexAmmProtocol!

" # of unique hourly active users "
" Number of unique hourly active users "
hourlyActiveUsers: Int!

" # of cumulative unique users "
" Number of cumulative unique users "
cumulativeUniqueUsers: Int!

" Total number of transactions occurred in an hour. Transactions include all entities that implement the Event interface. "
Expand Down Expand Up @@ -372,6 +385,9 @@ type LiquidityPool @entity {
" Fees per trade incurred to the user. Should include all fees that apply to a pool (e.g. Curve has a trading fee AND an admin fee, which is a portion of the trading fee. Uniswap only has a trading fee and no protocol fee. ) "
fees: [LiquidityPoolFee!]!

" Whether this pool is single-sided (e.g. Bancor, Platypus's Alternative Pool). The specifics of the implementation depends on the protocol. "
isSingleSided: Boolean!

" Creation timestamp "
createdTimestamp: BigInt!

Expand All @@ -383,6 +399,15 @@ type LiquidityPool @entity {
" Current TVL (Total Value Locked) of this pool in USD "
totalValueLockedUSD: BigDecimal!

" All revenue generated by the liquidity pool, accrued to the supply side. "
cumulativeSupplySideRevenueUSD: BigDecimal!

" All revenue generated by the liquidity pool, accrued to the protocol. "
cumulativeProtocolSideRevenueUSD: BigDecimal!

" All revenue generated by the liquidity pool. "
cumulativeTotalRevenueUSD: BigDecimal!

" All historical trade volume occurred in this pool, in USD "
cumulativeVolumeUSD: BigDecimal!

Expand Down Expand Up @@ -452,6 +477,24 @@ type LiquidityPoolDailySnapshot @entity {
" Current TVL (Total Value Locked) of this pool "
totalValueLockedUSD: BigDecimal!

" All revenue generated by the liquidity pool, accrued to the supply side. "
cumulativeSupplySideRevenueUSD: BigDecimal!

" Daily revenue generated by the liquidity pool, accrued to the supply side. "
dailySupplySideRevenueUSD: BigDecimal!

" All revenue generated by the liquidity pool, accrued to the protocol. "
cumulativeProtocolSideRevenueUSD: BigDecimal!

" Daily revenue generated by the liquidity pool, accrued to the protocol. "
dailyProtocolSideRevenueUSD: BigDecimal!

" All revenue generated by the liquidity pool. "
cumulativeTotalRevenueUSD: BigDecimal!

" Daily revenue generated by the liquidity pool. "
dailyTotalRevenueUSD: BigDecimal!

" All trade volume occurred in a given day, in USD "
dailyVolumeUSD: BigDecimal!

Expand Down Expand Up @@ -507,6 +550,24 @@ type LiquidityPoolHourlySnapshot @entity {
" Current TVL (Total Value Locked) of this pool "
totalValueLockedUSD: BigDecimal!

" All revenue generated by the liquidity pool, accrued to the supply side. "
cumulativeSupplySideRevenueUSD: BigDecimal!

" Hourly revenue generated by the liquidity pool, accrued to the supply side. "
hourlySupplySideRevenueUSD: BigDecimal!

" All revenue generated by the liquidity pool, accrued to the protocol. "
cumulativeProtocolSideRevenueUSD: BigDecimal!

" Hourly revenue generated by the liquidity pool, accrued to the protocol. "
hourlyProtocolSideRevenueUSD: BigDecimal!

" All revenue generated by the liquidity pool. "
cumulativeTotalRevenueUSD: BigDecimal!

" Hourly revenue generated by the liquidity pool. "
hourlyTotalRevenueUSD: BigDecimal!

" All trade volume occurred in a given hour, in USD "
hourlyVolumeUSD: BigDecimal!

Expand Down
64 changes: 58 additions & 6 deletions schema-generic.graphql
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
# Subgraph Schema: Generic
# Version: 1.2.1
# Version: 1.3.0
# See https://github.com/messari/subgraphs/blob/master/docs/Schema.md for details

enum Network {
ARBITRUM_ONE
ARWEAVE_MAINNET
AURORA
AVALANCHE
BOBA
BSC # aka BNB Chain
CELO
COSMOS
CRONOS
MAINNET # Ethereum Mainnet
FANTOM
FUSE
HARMONY
JUNO
MOONBEAM
MOONRIVER
NEAR_MAINNET
OPTIMISM
OSMOSIS
MATIC # aka Polygon
XDAI # aka Gnosis Chain
}
Expand Down Expand Up @@ -113,7 +120,7 @@ type Protocol @entity {
" All revenue generated by the protocol. e.g. 0.30% of swap fee in Sushiswap, all yield generated by Yearn. "
cumulativeTotalRevenueUSD: BigDecimal!

" # of cumulative unique users "
" Number of cumulative unique users "
cumulativeUniqueUsers: Int!

##### Snapshots #####
Expand Down Expand Up @@ -144,10 +151,10 @@ type UsageMetricsDailySnapshot @entity {
" Protocol this snapshot is associated with "
protocol: Protocol!

" # of unique daily active users "
" Number of unique daily active users "
dailyActiveUsers: Int!

" # of cumulative unique users "
" Number of cumulative unique users "
cumulativeUniqueUsers: Int!

" Total number of transactions occurred in a day. Transactions include all entities that implement the Event interface. "
Expand All @@ -167,10 +174,10 @@ type UsageMetricsHourlySnapshot @entity {
" Protocol this snapshot is associated with "
protocol: Protocol!

" # of unique hourly active users "
" Number of unique hourly active users "
hourlyActiveUsers: Int!

" # of cumulative unique users "
" Number of cumulative unique users "
cumulativeUniqueUsers: Int!

" Total number of transactions occurred in an hour. Transactions include all entities that implement the Event interface. "
Expand Down Expand Up @@ -261,6 +268,15 @@ type Pool @entity {
" Current TVL (Total Value Locked) of this pool in USD "
totalValueLockedUSD: BigDecimal!

" All revenue generated by the pool, accrued to the supply side. "
cumulativeSupplySideRevenueUSD: BigDecimal!

" All revenue generated by the pool, accrued to the protocol. "
cumulativeProtocolSideRevenueUSD: BigDecimal!

" All revenue generated by the pool. "
cumulativeTotalRevenueUSD: BigDecimal!

" Amount of input tokens in the pool. The ordering should be the same as the pool's `inputTokens` field. "
inputTokenBalances: [BigInt!]!

Expand Down Expand Up @@ -309,6 +325,24 @@ type PoolDailySnapshot @entity {
" Current TVL (Total Value Locked) of this pool "
totalValueLockedUSD: BigDecimal!

" All revenue generated by the pool, accrued to the supply side. "
cumulativeSupplySideRevenueUSD: BigDecimal!

" Daily revenue generated by the pool, accrued to the supply side. "
dailySupplySideRevenueUSD: BigDecimal!

" All revenue generated by the pool, accrued to the protocol. "
cumulativeProtocolSideRevenueUSD: BigDecimal!

" Daily revenue generated by the pool, accrued to the protocol. "
dailyProtocolSideRevenueUSD: BigDecimal!

" All revenue generated by the pool. "
cumulativeTotalRevenueUSD: BigDecimal!

" Daily revenue generated by the pool. "
dailyTotalRevenueUSD: BigDecimal!

" Amount of input tokens in the pool. The ordering should be the same as the pool's `inputTokens` field. "
inputTokenBalances: [BigInt!]!

Expand Down Expand Up @@ -349,6 +383,24 @@ type PoolHourlySnapshot @entity {
" Current TVL (Total Value Locked) of this pool "
totalValueLockedUSD: BigDecimal!

" All revenue generated by the pool, accrued to the supply side. "
cumulativeSupplySideRevenueUSD: BigDecimal!

" Hourly revenue generated by the pool, accrued to the supply side. "
hourlySupplySideRevenueUSD: BigDecimal!

" All revenue generated by the pool, accrued to the protocol. "
cumulativeProtocolSideRevenueUSD: BigDecimal!

" Hourly revenue generated by the pool, accrued to the protocol. "
hourlyProtocolSideRevenueUSD: BigDecimal!

" All revenue generated by the pool. "
cumulativeTotalRevenueUSD: BigDecimal!

" Hourly revenue generated by the pool. "
hourlyTotalRevenueUSD: BigDecimal!

" Amount of input tokens in the pool. The ordering should be the same as the pool's `inputTokens` field. "
inputTokenBalances: [BigInt!]!

Expand Down
Loading

0 comments on commit 5771617

Please sign in to comment.