forked from perpetual-protocol/perp-position-subgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.graphql
140 lines (130 loc) · 4.44 KB
/
schema.graphql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
type Position @entity {
id: ID!
trader: Bytes! # address
margin: BigInt! # uint256
openNotional: BigInt! # total position notional values at open
tradingVolume: BigInt! # trading volume in notional value
leverage: BigInt! # openNotional / margin
realizedPnl: BigInt! # int256
unrealizedPnl: BigInt! # int256
fundingPayment: BigInt! # int256
fee: BigInt! # uint256
badDebt: BigInt! # uint256
liquidationPenalty: BigInt! # uint256
totalPnlAmount: BigInt! # accumulated total PnL (realizedPnl - fundingPayment - fee - liquidationPenalty)
ammPositions: [AmmPosition!]! @derivedFrom(field: "position") # breakdown for each Amm
blockNumber: BigInt # last updated block number
timestamp: BigInt # last updated timestamp
}
type AmmPosition @entity {
id: ID!
amm: Bytes! # address
trader: Bytes! # address
margin: BigInt! # uint256
positionSize: BigInt! # int256
openNotional: BigInt! # position notional value at open
tradingVolume: BigInt! # trading volume in notional value
leverage: BigInt! # openNotional / margin
entryPrice: BigInt! # openNotional / positionSize
realizedPnl: BigInt! # int256
unrealizedPnl: BigInt! # int256
fundingPayment: BigInt! # int256
fee: BigInt! # uint256
badDebt: BigInt! # uint256
liquidationPenalty: BigInt! # uint256
totalPnlAmount: BigInt! # accumulated total PnL (realizedPnl - fundingPayment - fee - liquidationPenalty)
position: Position!
blockNumber: BigInt # last updated block number
timestamp: BigInt # last updated timestamp
}
type Amm @entity {
id: ID!
address: Bytes! # address
positionBalance: BigInt! # int256
openInterestSize: BigInt! # uint256
openInterestNotional: BigInt! # uint256
tradingVolume: BigInt! # trading volume in notional value
quoteAssetReserve: BigInt! # uint256
baseAssetReserve: BigInt! # uint256
blockNumber: BigInt # last updated block number
timestamp: BigInt # last updated timestamp
}
type PositionChangedEvent @entity {
id: ID!
trader: Bytes! # address
amm: Bytes! # address
margin: BigInt! # uint256
positionNotional: BigInt! # uint256
exchangedPositionSize: BigInt! # uint256
fee: BigInt! # uint256
positionSizeAfter: BigInt! # int256
realizedPnl: BigInt! # int256
unrealizedPnlAfter: BigInt! # int256
badDebt: BigInt! # uint256
liquidationPenalty: BigInt! # uint256
spotPrice: BigInt! # uint256
fundingPayment: BigInt! # int256
blockNumber: BigInt! # last updated block number
timestamp: BigInt! # last updated timestamp
}
type PositionLiquidatedEvent @entity {
id: ID!
trader: Bytes! # address
amm: Bytes! # address
positionNotional: BigInt! # uint256
positionSize: BigInt! # uint256
liquidationFee: BigInt! # uint256
liquidator: Bytes! # address
badDebt: BigInt! # uint256
blockNumber: BigInt! # last updated block number
timestamp: BigInt! # last updated timestamp
}
type FundingRateUpdatedEvent @entity {
id: ID!
amm: Bytes! # address
rate: BigInt! # int256
underlyingPrice: BigInt! # int256
blockNumber: BigInt! # last updated block number
timestamp: BigInt! # last updated timestamp
}
type MarginChangedEvent @entity {
id: ID!
sender: Bytes! # address
amm: Bytes! # address
amount: BigInt! #int256
fundingPayment: BigInt! # int256
blockNumber: BigInt! # last updated block number
timestamp: BigInt! # last updated timestamp
}
type Trader @entity {
id: ID!
position: Position!
dayData: [TraderDayData!] @derivedFrom(field: "trader")
referrerCode: ReferralCode # the referral code the trade owners
refereeCode: ReferralCode # the referral code the trader entered
}
type TraderDayData @entity {
id: ID!
trader: Trader!
date: BigInt!
tradingVolume: BigInt! # trading volume aggregated per day for trader
fee: BigInt! # trading fee aggregated per day for trader
fundingPayment: BigInt! # funding payment aggregated per day for trader
realizedPnl: BigInt! # total pnl aggregated per day for trader
}
type ReferralCodeDayData @entity {
id: ID!
referralCode: ReferralCode!
date: BigInt!
tradingVolume: BigInt! # trading volume in notional value
fees: BigInt! # fees paid during day
newReferees: [Trader!]! # a list of new referees added today
activeReferees: [Trader!]! # a list of referees which have traded on the day
}
type ReferralCode @entity {
id: ID!
referrer: Trader! # referrer address
referees: [Trader!]! @derivedFrom(field: "refereeCode")
createdAt: BigInt! # created at
dayData: [ReferralCodeDayData!] @derivedFrom(field: "referralCode")
}