-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.graphql
182 lines (164 loc) · 3.95 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
type SystemState @entity {
id: ID!
totalDebt: BigDecimal!
totalCollateral: BigDecimal!
totalRepaid: BigDecimal!
totalDefaulted: BigDecimal!
totalFees: BigDecimal!
lastUpdateTimestamp: BigInt!
lastUpdateBlocknumber: BigInt!
}
type Collateral @entity {
id: ID!
symbol: String!
decimals: Int!
priceUSD: BigDecimal!
minColRatio: BigDecimal
}
type PairedToken @entity {
id: ID!
symbol: String!
decimals: Int!
}
type Market @entity {
id: ID!
collateral: Collateral!
pairedToken: PairedToken!
expiry: BigInt!
mintRatio: BigDecimal!
fees: BigDecimal!
feeRate: BigDecimal!
rcToken: Bytes
rrToken: Bytes
totalCollateral: BigDecimal!
totalBorrowers: BigInt!
totalLenders: BigInt!
premiumPerCollateralLent: BigDecimal!
lastUpdateTimestamp: BigInt!
lastUpdateBlocknumber: BigInt!
borrowAPY: BigDecimal!
lendingAPY: BigDecimal!
}
type User @entity {
id: ID!
totalPnL: BigDecimal!
positions: [UserPosition!]! @derivedFrom(field: "user")
flashloans: [FlashloanEvent!]! @derivedFrom(field: "user")
mmDeposits: [MarketMakeDepositEvent!]! @derivedFrom(field: "user")
deposits: [DepositEvent!]! @derivedFrom(field: "user")
repays: [RepayEvent!]! @derivedFrom(field: "user")
redeems: [RedeemEvent!]! @derivedFrom(field: "user")
collects: [CollectEvent!]! @derivedFrom(field: "user")
}
type UserPosition @entity {
id: ID!
user: User!
amountCollateral: BigDecimal
amountBorrowed: BigDecimal
amountLent: BigDecimal
market: Market!
lastUpdateBlocknumber: BigInt!
lastUpdateTimestamp: BigInt!
isExpired: Boolean!
rrTokenAmount: BigDecimal!
rcTokenAmount: BigDecimal!
borrowAPY: BigDecimal
lendingAPY: BigDecimal
currentPnL: BigDecimal!
initialCollateralPrice: BigDecimal!
}
type FlashloanEvent @entity {
id: ID!
user: User!
token: Bytes!
amount: BigDecimal!
loanTokenPriceUsd: BigDecimal!
fees: BigDecimal!
timestamp:BigInt!
blocknumber:BigInt!
}
type MarketMakeDepositEvent @entity {
"""
Market make deposit paired Token to received rcTokens
Considered as an immediately repaid loan
"""
id: ID!
user: User!
market: Market!
collateralAmountDeposited: BigDecimal!
"Fees collected on rcToken"
fees: BigDecimal!
mintAmount: BigDecimal!
timestamp:BigInt!
blocknumber:BigInt!
}
type DepositEvent @entity {
"""
Deposit collateral to a Ruler Pair
Sender receives rcTokens and rrTokens
"""
id: ID!
user: User!
market: Market!
collateralAmountDeposited: BigDecimal!
mintAmount: BigDecimal!
timestamp:BigInt!
blocknumber:BigInt!
}
type RedeemEvent @entity {
"""
Redeem with rrTokens and rcTokens before expiry only, sender receives collateral
Fees charged on collateral
Before expiry only
"""
id: ID!
user: User!
market: Market!
"Collateral amount redeemed before subtracting fees"
collateralAmountRedeemed: BigDecimal!
"fees in collateral"
fees: BigDecimal!
rTokenAmount: BigDecimal!
timestamp: BigInt!
blocknumber: BigInt!
}
type RepayEvent @entity {
"""
Repay with equal amounts of rrTokens and paired token amount
Sender receives collateral, no fees charged on collateral
Before expiry, else collateral forfeitted
"""
id: ID!
user: User!
market: Market!
collateralAmountReceived: BigDecimal!
"fees in rrToken"
fees: BigDecimal!
rrTokenAmountRepaid: BigDecimal!
timestamp: BigInt!
blocknumber: BigInt!
}
type CollectEvent @entity {
"""
Sender collect paired tokens by returning same amount of rcTokens to Ruler
Post Expiry
"""
id: ID!
user: User!
market: Market!
collateralAmountReceived: BigDecimal!
rcTokenAmountRepaid: BigDecimal!
defaultedLoanAmount: BigDecimal!
"paired token amount to pay = rcToken amount * (1 - default ratio), no fees"
pairedTokenAmtCollected: BigDecimal!
"collateral amount to collect before subtracting fees"
colAmountToCollect: BigDecimal!
"fees = colAmountToCollect * _feeRate / 1e18"
fees: BigDecimal!
timestamp: BigInt!
blocknumber: BigInt!
}
type Metapool @entity {
id: ID!
market: Market!
}