Subgraph
Subgraph

Links

  • GitHub: https://github.com/euler-xyz/euler-subgraph
  • Querying the subgraph: https://thegraph.com/docs/en/developer/query-the-graph/

Mainnet

  • The Graph: https://thegraph.com/hosted-service/subgraph/euler-xyz/euler-mainnet
  • API: https://api.thegraph.com/subgraphs/name/euler-xyz/euler-mainnet

Ropsten

  • The Graph: https://thegraph.com/hosted-service/subgraph/euler-xyz/euler-ropsten
  • API: https://api.thegraph.com/subgraphs/name/euler-xyz/euler-ropsten

About

  • All amounts have a fixed decimal precision of 1e18.
  • Are timestamps are represented as unix timestamps.
  • USD and ETH exchange rates of all assets are pulled through Euler directly

Entities

Asset

Contains information about all Euler markets, pulled from EulerGeneralView contract.
1
type Asset @entity {
2
"asset_address"
3
id: ID!
4
blockHash: Bytes!
5
blockNumber: Int!
6
timestamp: Int!
7
transactionHash: Bytes!
8
transactionOrigin: Bytes!
9
dTokenAddress: Bytes!
10
eTokenAddress: Bytes!
11
pTokenAddress: Bytes!
12
symbol: String!
13
name: String!
14
decimals: BigInt!
15
totalSupply: BigInt!
16
totalBalances: BigInt!
17
totalBalancesUsd: BigInt!
18
totalBalancesEth: BigInt!
19
totalBorrows: BigInt!
20
totalBorrowsUsd: BigInt!
21
totalBorrowsEth: BigInt!
22
reserveBalance: BigInt!
23
reserveBalanceEth: BigInt!
24
reserveBalanceUsd: BigInt!
25
reserveFee: BigInt!
26
borrowAPY: BigInt!
27
supplyAPY: BigInt!
28
twap: BigInt!
29
twapPeriod: BigInt!
30
currPrice: BigInt!
31
currPriceUsd: BigInt!
32
pricingType: Int!
33
pricingParameters: BigInt!
34
pricingForwarded: Bytes!
35
collateralValue: BigInt!
36
liabilityValue: BigInt!
37
numBorrows: BigInt!
38
borrowIsolated: Boolean!
39
poolSize: BigInt!
40
interestAccumulator: BigInt!
41
interestRate: BigInt!
42
twapPrice: BigDecimal!
43
config: AssetConfig
44
}
Copied!
Sometimes, gouvernance will manually set asset configuration, it is displayed in the AssetConfig entity. If an asset has a null AssetConfig, it is safe to assume that it was never explicitly set and is isolated.
For further tier information, refer to Tier Methodology.
borrowFactor and collateralFactor can be transformed in a decimal fraction by dividing by 4e9.
1
type AssetConfig @entity {
2
"asset_address"
3
id: ID!
4
twapWindowInSeconds: Int!
5
borrowFactor: BigInt!
6
borrowIsolated: Boolean!
7
collateralFactor: BigInt!
8
tier: String!
9
}
Copied!

Account

Account that transacts on Euler. Could be a sub-account or a main account.
1
type Account @entity {
2
"account_address"
3
id: ID!
4
createdTimestamp: Int!
5
topLevelAccount: TopLevelAccount!
6
balances: [Balance!]
7
balanceChanges: [BalanceChange!]
8
balanceChangesCount: Int!
9
}
Copied!
A Balance represents the current amount of each assets held by an account.
1
type Balance @entity {
2
"account_address:underlying"
3
id: ID!
4
account: Account!
5
amount: BigInt!
6
asset: Asset!
7
}
Copied!
A BalanceChange is a transaction within the platform. type can be one of the following values:
  • borrow
  • deposit
  • withdraw
  • repay
1
type BalanceChange @entity {
2
"transaction_hash:event_log_index"
3
id: ID!
4
transactionHash: Bytes!
5
type: String!
6
account: Account!
7
topLevelAccount: TopLevelAccount!
8
amount: BigInt!
9
amountUsd: BigDecimal!
10
timestamp: Int!
11
asset: Asset!
Copied!

TopLevelAccount

Aggregate of the sub-accounts associated with a wallet. TopLevelAccount id corresponds to main sub-account id.
1
type TopLevelAccount @entity {
2
"account_address"
3
id: ID!
4
createdTimestamp: Int!
5
accounts: [Account!]
6
balances: [TopLevelAccountBalance!]
7
balanceChanges: [BalanceChange!]
8
balanceChangesCount: Int!
9
}
Copied!
1
type TopLevelAccountBalance @entity {
2
"top_level_account_address:underlying"
3
id: ID!
4
topLevelAccount: TopLevelAccount!
5
amount: BigInt!
6
asset: Asset!
7
}
Copied!

EulerMarketStore

Contains list of all active markets on Euler.
1
type EulerMarketStore @entity {
2
id: ID!
3
markets: [Asset!]
4
}
Copied!

EulerOverview

Aggregated metrics for all markets as a whole.
1
type EulerOverview @entity {
2
id: ID!
3
reserveBalanceUsd: BigInt!
4
reserveBalanceEth: BigInt!
5
totalBalancesUsd: BigInt!
6
totalBalancesEth: BigInt!
7
totalBorrowsUsd: BigInt!
8
totalBorrowsEth: BigInt!
9
}
Copied!

Liquidation

Contains all liquidation transactions.
liquidator and violator fields correspond to account addresses.
1
type Liquidation @entity {
2
"transaction_hash:event_log_index"
3
id: ID!
4
timestamp: Int!
5
transactionHash: Bytes!
6
liquidator: Bytes!
7
violator: Bytes!
8
asset: Asset!
9
collateralAsset: Asset!
10
repay: BigInt!
11
repayUsd: BigDecimal!
12
harvest: BigInt!
13
yieldUsd: BigDecimal!
14
healthScore: BigInt!
15
discount: BigInt!
16
baseDiscount: BigInt!
17
}
Copied!

Governance

GovConvertReserve and GovSetReserveFee contain all on-chain information about governance.
1
type GovConvertReserve @entity {
2
"transaction_hash:event_log_index"
3
id: ID!
4
timestamp: Int!
5
blockNumber: Int!
6
transactionHash: Bytes!
7
amount: BigInt!
8
amountUsd: BigDecimal!
9
asset: Asset!
10
recipient: Bytes!
11
}
Copied!
1
type GovSetReserveFee @entity {
2
"transaction_hash:event_log_index"
3
id: ID!
4
timestamp: Int!
5
blockNumber: Int!
6
transactionHash: Bytes!
7
reserveFee: Int!
8
asset: Asset!
9
}
Copied!

Hourly/Daily/MonthlyAssetStatus

Aggregated metrics of a specific market over hourly, daily and monthly time period.
1
type HourlyAssetStatus @entity {
2
"start_of_hour_timestamp:asset_address"
3
id: ID!
4
timestamp: Int!
5
totalBalances: BigInt!
6
totalBorrows: BigInt!
7
reserveBalance: BigInt!
8
poolSize: BigInt!
9
interestAccumulator: BigInt!
10
interestRate: BigInt!
11
twapPrice: BigDecimal!
12
}
Copied!

Hourly/Daily/MonthlyRepay

Aggregated metrics for repay transactions over hourly, daily and monthly time period.
1
type HourlyRepay @entity {
2
"start_of_hour_timestamp"
3
id: ID!
4
timestamp: Int!
5
count: Int!
6
totalAmount: BigInt!
7
totalUsdAmount: BigDecimal!
8
}
Copied!

Hourly/Daily/MonthlyDeposit

Aggregated metrics for deposits over hourly, daily and monthly time period.
1
type HourlyDeposit @entity {
2
"start_of_hour_timestamp"
3
id: ID!
4
timestamp: Int!
5
count: Int!
6
totalAmount: BigInt!
7
totalUsdAmount: BigDecimal!
8
}
Copied!

Hourly/Daily/MonthlyWithdraw

Aggregated metrics for withdrawals over hourly, daily and monthly time period.
1
type HourlyWithdraw @entity {
2
"start_of_hour_timestamp"
3
id: ID!
4
timestamp: Int!
5
count: Int!
6
totalAmount: BigInt!
7
totalUsdAmount: BigDecimal!
8
}
Copied!

Hourly/Daily/MonthlyBorrow

Aggregated for borrow transactions over hourly, daily and monthly time period.
1
type HourlyBorrow @entity {
2
"start_of_hour_timestamp"
3
id: ID!
4
timestamp: Int!
5
count: Int!
6
totalAmount: BigInt!
7
totalUsdAmount: BigDecimal!
8
}
Copied!

Querying time based aggregates

Every entity that has hourly, daily or monthly in its name can be queried by its ID. The documentation for those is located within each entity. Below lies the rules used to create the required timestamps.
Parameter
Value
start_of_hour_timestamp
unix timestamp at minute 0
start_of_day_timestamp
unix timestamp at hour 0, minute 0
start_of_month_timestamp
unix timestamp at first day of the month, hour 0, minute 0

Examples

Fetch the 5 biggest markets by total borrowed in USD

1
{
2
assets(first: 5, orderBy: totalBorrowsUsd, orderDirection: desc) {
3
symbol
4
totalBorrows
5
totalBorrowsUsd
6
currPriceUsd
7
}
8
}
Copied!

Get the current balances of an account

1
{
2
account(id: "0x0000000002732779240fe05873611dc4203dfb71") {
3
balances {
4
amount
5
asset {
6
symbol
7
}
8
}
9
}
10
}
Copied!

Get the transaction history of an account

1
{
2
account(id: "0x0000000002732779240fe05873611dc4203dfb71") {
3
balanceChanges {
4
type
5
timestamp
6
amount
7
amountUsd
8
asset {
9
symbol
10
}
11
}
12
}
13
}
Copied!

Get USD amount borrowed on February 10th 2022

First we need to create our ID using the parameters define in the Querying time based aggregates section. In this case, February 10th 2020 = 1644451200.
1
{
2
dailyBorrow(id: "1644451200") {
3
count
4
totalUsdAmount
5
}
6
}
Copied!

Last 30 days of deposit amounts

1
{
2
dailyDeposits(first: 30, orderBy: timestamp, orderDirection: desc) {
3
id
4
timestamp
5
totalUsdAmount
6
}
7
}
Copied!

All transactions between February 1st 2022 and February 3rd 2022

1
{
2
balanceChanges(orderBy: timestamp, orderDirection: asc, where: {timestamp_gte: 1643673600, timestamp_lte: 1643932799}) {
3
timestamp
4
type
5
amount
6
amountUsd
7
account {
8
id
9
}
10
asset {
11
symbol
12
}
13
}
14
}
Copied!

Querying time based aggregates

Every entity that has hourly, daily or monthly in its name can be queried by its ID. The documentation for those is located within each entity. Below lies the rules used to create the required timestamps.
Parameter
Value
start_of_hour_timestamp
unix timestamp at minute 0
start_of_day_timestamp
unix timestamp at hour 0, minute 0
start_of_month_timestamp
unix timestamp at first day of the month, hour 0, minute 0

Examples

Fetch the 5 biggest markets by total borrowed in USD

1
{
2
assets(first: 5, orderBy: totalBorrowsUsd, orderDirection: desc) {
3
symbol
4
totalBorrows
5
totalBorrowsUsd
6
currPriceUsd
7
}
8
}
Copied!

Get the current balances of an account

1
{
2
account(id: "0x0000000002732779240fe05873611dc4203dfb71") {
3
balances {
4
amount
5
asset {
6
symbol
7
}
8
}
9
}
10
}
Copied!

Get the transaction history of an account

1
{
2
account(id: "0x0000000002732779240fe05873611dc4203dfb71") {
3
balanceChanges {
4
type
5
timestamp
6
amount
7
amountUsd
8
asset {
9
symbol
10
}
11
}
12
}
13
}
Copied!

Get USD amount borrowed on February 10th 2022

First we need to create our ID using the parameters define in the Querying time based aggregates section. In this case, February 10th 2020 = 1644451200.
1
{
2
dailyBorrow(id: "1644451200") {
3
count
4
totalUsdAmount
5
}
6
}
Copied!

Last 30 days of deposit amounts

1
{
2
dailyDeposits(first: 30, orderBy: timestamp, orderDirection: desc) {
3
id
4
timestamp
5
totalUsdAmount
6
}
7
}
Copied!

All transactions between February 1st 2022 and February 3rd 2022

1
{
2
balanceChanges(orderBy: timestamp, orderDirection: asc, where: {timestamp_gte: 1643673600, timestamp_lte: 1643932799}) {
3
timestamp
4
type
5
amount
6
amountUsd
7
account {
8
id
9
}
10
asset {
11
symbol
12
}
13
}
14
}
Copied!