@reality.eth/graph 0.4.24 → 0.4.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reality.eth/graph",
3
- "version": "0.4.24",
3
+ "version": "0.4.25",
4
4
  "scripts": {
5
5
  "create-local": "graph create realityeth/realityeth --node http://127.0.0.1:8020",
6
6
  "remove-local": "graph remove realityeth/realityeth --node http://127.0.0.1:8020",
@@ -24,6 +24,21 @@
24
24
  "deploy:xdai": "yarn prepare:xdai && graph deploy $GRAPH_AUTH--ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ realityeth/realityeth-xdai",
25
25
  "deploy:zksync-goerli": "yarn prepare:zksync-goerli && graph deploy $GRAPH_AUTH --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ realityeth/realityeth-zksync-goerli-2",
26
26
  "deploy:all": "yarn deploy:arbitrum && yarn deploy:ava && yarn deploy:bsc && yarn deploy:kovan && yarn deploy:mainnet && yarn deploy:mainnet && yarn deploy:optimism && yarn deploy:polygon && yarn deploy:rinkeby && yarn deploy:sokol && yarn deploy:xdai",
27
+ "deploy-studio:arbitrum": "yarn prepare:arbitrum && graph deploy $GRAPH_AUTH --studio realityeth/realityeth-arbitrum",
28
+ "deploy-studio:ava": "yarn prepare:ava && graph deploy $GRAPH_AUTH --studio realityeth/realityeth-ava",
29
+ "deploy-studio:bsc": "yarn prepare:bsc && graph deploy $GRAPH_AUTH --studio realityeth/realityeth-bsc",
30
+ "deploy-studio:chapel": "yarn prepare:chapel && graph deploy $GRAPH_AUTH --studio realityeth/realityeth-chapel",
31
+ "deploy-studio:kovan": "yarn prepare:kovan && graph deploy $GRAPH_AUTH --studio realityeth/realityeth-kovan",
32
+ "deploy-studio:goerli": "yarn prepare:goerli && graph deploy $GRAPH_AUTH --studio realityeth/realityeth-goerli",
33
+ "deploy-studio:mainnet": "yarn prepare:mainnet && graph deploy $GRAPH_AUTH --studio realityeth/realityeth",
34
+ "deploy-studio:optimism": "yarn prepare:optimism && graph deploy $GRAPH_AUTH --studio realityeth/realityeth-optimism",
35
+ "deploy-studio:polygon": "yarn prepare:polygon && graph deploy $GRAPH_AUTH --studio realityeth/realityeth-polygon",
36
+ "deploy-studio:mumbai": "yarn prepare:mumbai && graph deploy $GRAPH_AUTH --studio realityeth/realityeth-mumbai",
37
+ "deploy-studio:rinkeby": "yarn prepare:rinkeby && graph deploy $GRAPH_AUTH --studio realityeth/realityeth-rinkeby",
38
+ "deploy-studio:sokol": "yarn prepare:sokol && graph deploy $GRAPH_AUTH --studio realityeth/realityeth-sokol",
39
+ "deploy-studio:xdai": "yarn prepare:xdai && graph deploy $GRAPH_AUTH --studio realityeth/realityeth-xdai",
40
+ "deploy-studio:zksync-goerli": "yarn prepare:zksync-goerli && graph deploy $GRAPH_AUTH realityeth/realityeth-zksync-goerli-2",
41
+ "deploy-studio:all": "yarn deploy-studio:arbitrum && yarn deploy-studio:ava && yarn deploy-studio:bsc && yarn deploy-studio:kovan && yarn deploy-studio:mainnet && yarn deploy-studio:mainnet && yarn deploy-studio:optimism && yarn deploy-studio:polygon && yarn deploy-studio:rinkeby && yarn deploy-studio:sokol && yarn deploy-studio:xdai",
27
42
  "prepare:arbitrum": "yarn clean && node render-templates.js 42161 && graph codegen",
28
43
  "prepare:ava": "yarn clean && node render-templates.js 43114 && graph codegen",
29
44
  "prepare:bsc": "yarn clean && node render-templates.js 56 && graph codegen",
@@ -45,7 +60,7 @@
45
60
  "prettier-write": "prettier --write '**/*.ts'"
46
61
  },
47
62
  "dependencies": {
48
- "@reality.eth/contracts": "^3.0.22",
63
+ "@reality.eth/contracts": "^3.0.23",
49
64
  "babel-polyfill": "^6.26.0",
50
65
  "babel-register": "^6.26.0",
51
66
  "mustache": "^4.2.0",
@@ -55,5 +70,5 @@
55
70
  "@graphprotocol/graph-cli": "^0.30.2",
56
71
  "@graphprotocol/graph-ts": "^0.27.0"
57
72
  },
58
- "gitHead": "f5f4349ac42ad43c41c012eb187e33869aa69fd5"
73
+ "gitHead": "d115d0f9e969993975ef156c559d6f247c783b81"
59
74
  }
@@ -1,38 +1,9 @@
1
1
  import { crypto, log, BigInt, Bytes, ByteArray } from '@graphprotocol/graph-ts'
2
- import { json, JSONValueKind } from '@graphprotocol/graph-ts'
3
-
4
- import { unescape } from './utils/unescape'
5
- import { sprintf } from './utils/sprintf'
6
2
 
7
3
  import {
8
- Question,
9
- Outcome,
10
- Response,
11
- Answer,
12
- Category,
13
- Template,
14
- Claim,
15
- Withdrawal,
16
- Fund,
17
- UserAction,
18
4
  FactoryDeployment,
19
5
  } from '../generated/schema'
20
6
 
21
- import {
22
- RealityETH,
23
- LogNewTemplate,
24
- LogNewQuestion,
25
- LogNewAnswer,
26
- LogNotifyOfArbitrationRequest,
27
- LogFinalize,
28
- LogAnswerReveal,
29
- LogFundAnswerBounty,
30
- LogClaim,
31
- LogWithdraw,
32
- LogMinimumBond,
33
- LogReopenQuestion
34
- } from '../generated/RealityETH-3.0-ETH/RealityETH'
35
-
36
7
  import {
37
8
  RealityETH_ERC20_deployed
38
9
  } from '../generated/RealityETH_ERC20_Factory/RealityETH_ERC20_Factory'
@@ -41,398 +12,6 @@ import {
41
12
  FactoryCreatedRealityETH,
42
13
  } from '../generated/templates'
43
14
 
44
- export function handleNewTemplate(event: LogNewTemplate): void {
45
- let contractTemplateId = event.address.toHexString() + '-' + event.params.template_id.toHexString();
46
- let tmpl = new Template(contractTemplateId);
47
- tmpl.templateId = event.params.template_id;
48
- tmpl.contract = event.address;
49
- tmpl.user = event.params.user;
50
- tmpl.questionText = event.params.question_text;
51
- tmpl.createdBlock = event.block.number;
52
- tmpl.save()
53
-
54
- let ua = new UserAction(event.transaction.hash.toHex() + "-" + event.logIndex.toString());
55
- ua.actionType = 'CreateTemplate';
56
- ua.user = event.params.user;
57
- ua.template = contractTemplateId;
58
- ua.createdBlock = event.block.number;
59
- ua.createdTimestamp = event.block.timestamp;
60
- ua.save();
61
- }
62
-
63
- export function handleNewQuestion(event: LogNewQuestion): void {
64
- let contractQuestionId = event.address.toHexString() + '-' + event.params.question_id.toHexString();
65
- let contract = event.address;
66
- let question = new Question(contractQuestionId);
67
- question.questionId = event.params.question_id;
68
-
69
- let contractTemplateId = event.address.toHexString() + '-' + event.params.template_id.toHexString();
70
- let tmpl = Template.load(contractTemplateId);
71
- question.template = contractTemplateId;
72
-
73
- let questionText = tmpl.questionText;
74
-
75
- let data = event.params.question;
76
- let fields = data.split('\u241f');
77
-
78
- let qJsonStr = sprintf(questionText, fields)
79
-
80
- let tryData = json.try_fromBytes(ByteArray.fromUTF8(qJsonStr) as Bytes)
81
- if (tryData.isOk) {
82
- let json_dict = tryData.value.toObject()
83
-
84
- let qTitle = json_dict.get('title')
85
- if (qTitle != null && qTitle.kind === JSONValueKind.STRING) {
86
- question.qTitle = qTitle.toString()
87
- }
88
-
89
- let qCategory = json_dict.get('category')
90
- if (qCategory != null && qCategory.kind == JSONValueKind.STRING) {
91
- question.qCategory = qCategory.toString();
92
- }
93
-
94
- let qLang = json_dict.get('lang')
95
- if (qLang != null && qLang.kind == JSONValueKind.STRING) {
96
- question.qLang = qLang.toString();
97
- }
98
-
99
- let qType = json_dict.get('type')
100
- if (qType != null && qType.kind == JSONValueKind.STRING) {
101
- question.qType = qType.toString();
102
- }
103
-
104
- let q_outcomes_val = json_dict.get('outcomes')
105
- if (q_outcomes_val != null && q_outcomes_val.kind === JSONValueKind.ARRAY) {
106
- let q_outcomes = q_outcomes_val.toArray()
107
- for(let i = 0; i < q_outcomes.length; i++) {
108
- let outcomeID = contractQuestionId + '-' + i.toString();
109
- let outcome = new Outcome(outcomeID);
110
- if (q_outcomes[i].kind === JSONValueKind.STRING) {
111
- outcome.answer = q_outcomes[i].toString()
112
- } else {
113
- outcome.answer = "[FORMATTING ERROR]";
114
- }
115
- outcome.question = contractQuestionId;
116
- outcome.save()
117
- }
118
- }
119
- } else {
120
- log.info('Could not parse json for question {}', [contractQuestionId]);
121
- }
122
-
123
- question.contract = contract;
124
-
125
- question.data = data
126
- question.contentHash = event.params.content_hash;
127
-
128
- question.qJsonStr = qJsonStr
129
-
130
- question.createdBlock = event.block.number;
131
- question.createdTimestamp = event.params.created;
132
- question.updatedBlock = event.block.number;
133
- question.updatedTimestamp = event.block.timestamp;
134
-
135
- question.user = event.params.user;
136
- question.arbitrator = event.params.arbitrator;
137
- question.openingTimestamp = event.params.opening_ts;
138
- question.timeout = event.params.timeout;
139
-
140
- question.isPendingArbitration = false;
141
- question.arbitrationOccurred = false;
142
-
143
- question.currentAnswerBond = new BigInt(0);
144
- question.lastBond = new BigInt(0);
145
- question.cumulativeBonds = new BigInt(0);
146
-
147
- question.minBond = new BigInt(0);
148
-
149
- question.currentScheduledFinalizationTimestamp = BigInt.fromI32(I32.MAX_VALUE);
150
-
151
- // In version 3 and above the bounty should be picked up by the LogFundAnswerBounty event.
152
- // In version 2 this isn't fired on question create.
153
- // We could handle this with a call but this would mean we'd need an archive node to index.
154
- // Instead, make sure we do a call in the UI for the current bounty when using the v2 contract.
155
- // This shouldn't matter much as neither v2 nor the bounty feature is used much.
156
- question.bounty = new BigInt(0);
157
-
158
- question.save();
159
-
160
- let ua = new UserAction(event.transaction.hash.toHex() + "-" + event.logIndex.toString());
161
- ua.actionType = 'AskQuestion';
162
- ua.user = event.params.user;
163
- ua.question = contractQuestionId;
164
- ua.createdBlock = event.block.number;
165
- ua.createdTimestamp = event.block.timestamp;
166
- ua.save();
167
-
168
- }
169
-
170
- export function handleNewAnswer(event: LogNewAnswer): void {
171
-
172
- let contractQuestionId = event.address.toHexString() + '-' + event.params.question_id.toHexString();
173
- let question = Question.load(contractQuestionId);
174
- if (question == null) {
175
- log.info('cannot find question {} to answer', [contractQuestionId]);
176
- return;
177
- }
178
-
179
- let ts = event.params.ts
180
- let isCommitment = event.params.is_commitment;
181
-
182
- let responseId = contractQuestionId + '-' + event.params.bond.toHexString();
183
- let response = new Response(responseId);
184
- response.question = contractQuestionId;
185
- response.createdBlock = event.block.number;
186
- if (isCommitment) {
187
- response.commitmentId = event.params.answer;
188
- response.isUnrevealed = true;
189
- } else {
190
- response.answer = event.params.answer;
191
- response.isUnrevealed = false;
192
- }
193
- response.bond = event.params.bond;
194
- response.user = event.params.user;
195
- response.timestamp = event.params.ts;
196
- response.isCommitment = isCommitment;
197
- response.historyHash = event.params.history_hash;
198
- response.save();
199
-
200
- if (!isCommitment) {
201
- saveAnswer(contractQuestionId, event.params.answer, event.params.bond, event.params.ts, event.block.number);
202
- if (event.params.bond > question.lastBond) {
203
- question.currentAnswer = event.params.answer;
204
- question.currentAnswerBond = event.params.bond;
205
- question.currentAnswerTimestamp = event.params.ts;
206
- }
207
- }
208
- // response.bondAggregate = response.bondAggregate.plus(bond);
209
-
210
- /*
211
- response.bondAggregate = response.bondAggregate.plus(bond);
212
- response.timestamp = ts;
213
- */
214
-
215
- question.answerFinalizedTimestamp = question.arbitrationOccurred ? ts : ts.plus(question.timeout);
216
- question.currentScheduledFinalizationTimestamp = question.arbitrationOccurred ? ts : ts.plus(question.timeout);
217
-
218
- question.historyHash = event.params.history_hash;
219
- question.lastBond = event.params.bond;
220
- question.cumulativeBonds = question.cumulativeBonds.plus(event.params.bond);
221
-
222
- question.updatedBlock = event.block.number;
223
- question.updatedTimestamp = event.block.timestamp;
224
-
225
- question.save();
226
-
227
- let ua = new UserAction(event.transaction.hash.toHex() + "-" + event.logIndex.toString());
228
- ua.actionType = 'AnswerQuestion';
229
- ua.user = event.params.user;
230
- ua.question = contractQuestionId;
231
- ua.response = responseId;
232
- ua.createdBlock = event.block.number;
233
- ua.createdTimestamp = event.block.timestamp;
234
- ua.save();
235
-
236
- }
237
-
238
- export function handleAnswerReveal(event: LogAnswerReveal): void {
239
- let contractQuestionId = event.address.toHexString() + '-' + event.params.question_id.toHexString();
240
- let responseId = contractQuestionId + '-' + event.params.bond.toHexString();
241
-
242
- let response = Response.load(responseId);
243
- if (response == null) {
244
- //log.info('cannot find answer {} for reveal', [event.params.answer]);
245
- return;
246
- }
247
- response.answer = event.params.answer;
248
- response.isUnrevealed = false;
249
- response.revealedBlock = event.block.number;
250
- response.save()
251
-
252
- let question = Question.load(contractQuestionId);
253
- if (question == null) {
254
- log.info('cannot find question {} to answer', [contractQuestionId]);
255
- return;
256
- }
257
- saveAnswer(contractQuestionId, event.params.answer, event.params.bond, response.timestamp, event.block.number);
258
-
259
- question.updatedBlock = event.block.number;
260
- question.updatedTimestamp = event.block.timestamp;
261
-
262
- // Update the question to the current answer, unless someone has posted a higher bond since you made the commitment
263
- if (event.params.bond == question.lastBond) {
264
- question.currentAnswer = event.params.answer;
265
- }
266
- question.save()
267
-
268
- let ua = new UserAction(event.transaction.hash.toHex() + "-" + event.logIndex.toString());
269
- ua.actionType = 'RevealAnswer';
270
- ua.user = event.params.user;
271
- ua.question = contractQuestionId;
272
- ua.response = responseId;
273
- ua.createdBlock = event.block.number;
274
- ua.createdTimestamp = event.block.timestamp;
275
- ua.save();
276
-
277
- //saveAnswer(question, questionId, event.params.answer, event.params.bond, event.params.ts);
278
-
279
- }
280
-
281
- export function handleArbitrationRequest(event: LogNotifyOfArbitrationRequest): void {
282
- let contractQuestionId = event.address.toHexString() + '-' + event.params.question_id.toHexString();
283
- let question = Question.load(contractQuestionId);
284
- if (question == null) {
285
- log.info('cannot find question {} to begin arbitration', [contractQuestionId]);
286
- return;
287
- }
288
-
289
- question.isPendingArbitration = true;
290
- question.answerFinalizedTimestamp = null;
291
- question.arbitrationRequestedTimestamp = event.block.timestamp;
292
- question.arbitrationRequestedBy = event.params.user.toHexString();
293
-
294
- question.currentScheduledFinalizationTimestamp = BigInt.fromI32(I32.MAX_VALUE);
295
-
296
- question.updatedBlock = event.block.number;
297
- question.updatedTimestamp = event.block.timestamp;
298
- question.save();
299
-
300
- let ua = new UserAction(event.transaction.hash.toHex() + "-" + event.logIndex.toString());
301
- ua.actionType = 'RequestArbitration';
302
- ua.user = event.params.user;
303
- ua.question = contractQuestionId;
304
- ua.createdBlock = event.block.number;
305
- ua.createdTimestamp = event.block.timestamp;
306
- ua.save();
307
-
308
- }
309
-
310
- export function handleFinalize(event: LogFinalize): void {
311
- let contractQuestionId = event.address.toHexString() + '-' + event.params.question_id.toHexString();
312
- let question = Question.load(contractQuestionId);
313
- if (question == null) {
314
- log.info('cannot find question {} to finalize', [contractQuestionId]);
315
- return;
316
- }
317
-
318
- question.isPendingArbitration = false;
319
- question.arbitrationOccurred = true;
320
- question.currentAnswer = event.params.answer;
321
-
322
- question.updatedBlock = event.block.number;
323
- question.updatedTimestamp = event.block.timestamp;
324
- question.save();
325
-
326
- }
327
-
328
- export function handleFundAnswerBounty(event: LogFundAnswerBounty): void {
329
- let contractQuestionId = event.address.toHexString() + '-' + event.params.question_id.toHexString();
330
- let question = Question.load(contractQuestionId);
331
- if (question == null) {
332
- log.info('cannot find question {} to finalize', [contractQuestionId]);
333
- return;
334
- }
335
- question.bounty = event.params.bounty;
336
- question.updatedBlock = event.block.number;
337
- question.updatedTimestamp = event.block.timestamp;
338
- question.save()
339
-
340
- let fundId = event.transaction.hash.toHex() + "-" + event.logIndex.toString()
341
- let fund = new Fund(fundId);
342
- fund.question = contractQuestionId;
343
- fund.user = event.params.user;
344
- fund.amount = event.params.bounty_added;
345
- fund.createdBlock = event.block.number;
346
- fund.save()
347
-
348
- let ua = new UserAction(event.transaction.hash.toHex() + "-" + event.logIndex.toString());
349
- ua.actionType = 'FundAnswerBounty';
350
- ua.user = event.params.user;
351
- ua.createdBlock = event.block.number;
352
- ua.createdTimestamp = event.block.timestamp;
353
- ua.fund = fundId;
354
- ua.question = contractQuestionId;
355
- ua.save();
356
- }
357
-
358
- export function handleLogClaim(event: LogClaim): void {
359
- let claimId = event.transaction.hash.toHex() + "-" + event.logIndex.toString()
360
- let claim = new Claim(claimId)
361
-
362
- let contractQuestionId = event.address.toHexString() + '-' + event.params.question_id.toHexString();
363
- claim.question = contractQuestionId;
364
- claim.user = event.params.user;
365
- claim.amount = event.params.amount;
366
- claim.createdBlock = event.block.number;
367
- claim.save();
368
-
369
- let question = Question.load(contractQuestionId);
370
- let contract = RealityETH.bind(event.address)
371
- question.historyHash = contract.getHistoryHash(event.params.question_id);
372
-
373
- question.updatedBlock = event.block.number;
374
- question.updatedTimestamp = event.block.timestamp;
375
- question.save();
376
- }
377
-
378
- export function handleLogWithdraw(event: LogWithdraw): void {
379
- let withdrawalId = event.transaction.hash.toHex() + "-" + event.logIndex.toString();
380
- let withdrawal = new Withdrawal(withdrawalId);
381
- withdrawal.user = event.params.user;
382
- withdrawal.amount = event.params.amount;
383
- withdrawal.createdBlock = event.block.number;
384
- withdrawal.save();
385
- }
386
-
387
- // This is done on question creation.
388
- // To preserve the old event signatures it adds a new event
389
- export function handleLogMinimumBond(event: LogMinimumBond): void {
390
- let contractQuestionId = event.address.toHexString() + '-' + event.params.question_id.toHexString();
391
- let question = Question.load(contractQuestionId);
392
- question.minBond = event.params.min_bond;
393
- question.save();
394
- }
395
-
396
- export function handleLogReopenQuestion(event: LogReopenQuestion): void {
397
- // We'll save this in both directions for easy querying
398
- let contractQuestionId = event.address.toHexString() + '-' + event.params.question_id.toHexString();
399
- let reopenedContractQuestionId = event.address.toHexString() + '-' + event.params.reopened_question_id.toHexString();
400
- let question = Question.load(contractQuestionId);
401
- let reopenedQuestion = Question.load(reopenedContractQuestionId);
402
- question.reopens = reopenedContractQuestionId;
403
- question.updatedBlock = event.block.number;
404
- question.updatedTimestamp = event.block.timestamp;
405
- question.save();
406
- reopenedQuestion.reopenedBy = contractQuestionId;
407
- reopenedQuestion.updatedBlock = event.block.number;
408
- reopenedQuestion.updatedTimestamp = event.block.timestamp;
409
- reopenedQuestion.save();
410
- }
411
-
412
- function saveAnswer(contractQuestionId: string, answer: Bytes, bond: BigInt, ts: BigInt, createdBlock: BigInt): void {
413
- let question = Question.load(contractQuestionId);
414
-
415
- let answerId = contractQuestionId + '-' + answer.toHexString();
416
- let answerEntity = Answer.load(answerId);
417
- if(answerEntity == null) {
418
- answerEntity = new Answer(answerId);
419
- answerEntity.question = contractQuestionId;
420
- answerEntity.answer = answer;
421
- answerEntity.bondAggregate = bond;
422
- answerEntity.lastBond = bond;
423
- answerEntity.timestamp = ts;
424
- answerEntity.createdBlock = createdBlock;
425
- answerEntity.save();
426
- } else {
427
- answerEntity.bondAggregate = answerEntity.bondAggregate.plus(bond);
428
- answerEntity.timestamp = ts;
429
- if (bond > answerEntity.lastBond) {
430
- answerEntity.lastBond = bond;
431
- }
432
- answerEntity.save();
433
- }
434
- }
435
-
436
15
  export function handleFactoryRealityETHDeploy(event: RealityETH_ERC20_deployed): void {
437
16
  FactoryCreatedRealityETH.create(event.params.reality_eth)
438
17