datai-sdk 1.0.6 → 1.1.1

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.
Files changed (36) hide show
  1. package/API/v1/activePositions/ActivePositionsResult.ts +221 -3
  2. package/API/v1/activePositions/NftItem.ts +63 -0
  3. package/API/v1/activePositions/PerpPosition.ts +129 -0
  4. package/API/v1/activePositions/TokenBalance.ts +32 -1
  5. package/API/v1/activePositions/activePositions.ts +8 -1
  6. package/API/v1/index.ts +6 -0
  7. package/API/v1/proto/activePositions/activePositions/ActivePositionsResultPb.ts +159 -0
  8. package/API/v1/proto/activePositions/activePositions/NftItemPb.ts +71 -0
  9. package/API/v1/proto/activePositions/activePositions/PerpPositionPb.ts +142 -0
  10. package/API/v1/proto/activePositions/activePositions/PerpSide.ts +10 -0
  11. package/API/v1/proto/activePositions/activePositions/TokenBalancePb.ts +71 -0
  12. package/API/v1/proto/activePositions/google/protobuf/Timestamp.ts +48 -0
  13. package/API/v1/proto/watcher/WatcherInputPb.ts +121 -0
  14. package/API/v1/watcher/WatcherInput.ts +100 -2
  15. package/API/v1/watcher/watcher.ts +154 -4
  16. package/package.json +5 -2
  17. package/postinstall-script.js +4 -2
  18. package/@graphprotocol/graph-ts/README.md +0 -13
  19. package/@graphprotocol/graph-ts/chain/arweave.ts +0 -82
  20. package/@graphprotocol/graph-ts/chain/cosmos.ts +0 -426
  21. package/@graphprotocol/graph-ts/chain/ethereum.ts +0 -727
  22. package/@graphprotocol/graph-ts/chain/near.ts +0 -420
  23. package/@graphprotocol/graph-ts/chain/starknet.ts +0 -39
  24. package/@graphprotocol/graph-ts/common/collections.ts +0 -495
  25. package/@graphprotocol/graph-ts/common/conversion.ts +0 -3
  26. package/@graphprotocol/graph-ts/common/datasource.ts +0 -41
  27. package/@graphprotocol/graph-ts/common/eager_offset.ts +0 -42
  28. package/@graphprotocol/graph-ts/common/json.ts +0 -28
  29. package/@graphprotocol/graph-ts/common/numbers.ts +0 -407
  30. package/@graphprotocol/graph-ts/common/value.ts +0 -585
  31. package/@graphprotocol/graph-ts/global/global.ts +0 -4
  32. package/@graphprotocol/graph-ts/helper-functions.ts +0 -79
  33. package/@graphprotocol/graph-ts/index.ts +0 -156
  34. package/@graphprotocol/graph-ts/package.json +0 -3
  35. package/@graphprotocol/graph-ts/tsconfig.json +0 -4
  36. package/@graphprotocol/graph-ts/types/tsconfig.base.json +0 -3
@@ -1,727 +0,0 @@
1
- import '../common/eager_offset';
2
- import { Bytes, Wrapped } from '../common/collections';
3
- import { Address, BigInt } from '../common/numbers';
4
- import * as API from '../../../../API'
5
-
6
- export namespace ethereum {
7
- export const call = API.ethereum.call
8
- export const getBalance = API.ethereum.getBalance
9
- export const encode = API.ethereum.encode
10
- export const decode = API.ethereum.decode
11
-
12
- /** Type hint for Ethereum values. */
13
- export enum ValueKind {
14
- ADDRESS = 0,
15
- FIXED_BYTES = 1,
16
- BYTES = 2,
17
- INT = 3,
18
- UINT = 4,
19
- BOOL = 5,
20
- STRING = 6,
21
- FIXED_ARRAY = 7,
22
- ARRAY = 8,
23
- TUPLE = 9,
24
- }
25
-
26
- /**
27
- * Pointer type for Ethereum value data.
28
- *
29
- * Big enough to fit any pointer or native `this.data`.
30
- */
31
- export type ValuePayload = u64;
32
-
33
- /**
34
- * A dynamically typed value used when accessing Ethereum data.
35
- */
36
- export class Value {
37
- constructor(
38
- public kind: ValueKind,
39
- public data: ValuePayload,
40
- ) {}
41
-
42
- @operator('<')
43
- lt(_: Value): boolean {
44
- abort("Less than operator isn't supported in Value");
45
- return false;
46
- }
47
-
48
- @operator('>')
49
- gt(_: Value): boolean {
50
- abort("Greater than operator isn't supported in Value");
51
- return false;
52
- }
53
-
54
- toAddress(): Address {
55
- assert(this.kind == ValueKind.ADDRESS, 'Ethereum value is not an address');
56
- return changetype<Address>(this.data as u32);
57
- }
58
-
59
- toBoolean(): boolean {
60
- assert(this.kind == ValueKind.BOOL, 'Ethereum value is not a boolean.');
61
- return this.data != 0;
62
- }
63
-
64
- toBytes(): Bytes {
65
- assert(
66
- this.kind == ValueKind.FIXED_BYTES || this.kind == ValueKind.BYTES,
67
- 'Ethereum value is not bytes.',
68
- );
69
- return changetype<Bytes>(this.data as u32);
70
- }
71
-
72
- toI32(): i32 {
73
- assert(
74
- this.kind == ValueKind.INT || this.kind == ValueKind.UINT,
75
- 'Ethereum value is not an int or uint.',
76
- );
77
- const bigInt = changetype<BigInt>(this.data as u32);
78
- return bigInt.toI32();
79
- }
80
-
81
- toBigInt(): BigInt {
82
- assert(
83
- this.kind == ValueKind.INT || this.kind == ValueKind.UINT,
84
- 'Ethereum value is not an int or uint.',
85
- );
86
- return changetype<BigInt>(this.data as u32);
87
- }
88
-
89
- toString(): string {
90
- assert(this.kind == ValueKind.STRING, 'Ethereum value is not a string.');
91
- return changetype<string>(this.data as u32);
92
- }
93
-
94
- toArray(): Array<Value> {
95
- assert(
96
- this.kind == ValueKind.ARRAY || this.kind == ValueKind.FIXED_ARRAY,
97
- 'Ethereum value is not an array.',
98
- );
99
- return changetype<Array<Value>>(this.data as u32);
100
- }
101
-
102
- toTuple(): Tuple {
103
- assert(this.kind == ValueKind.TUPLE, 'Ethereum value is not a tuple.');
104
- return changetype<Tuple>(this.data as u32);
105
- }
106
-
107
- toMatrix(): Array<Array<Value>> {
108
- const valueArray = this.toArray();
109
- const out = new Array<Array<Value>>(valueArray.length);
110
- for (let i: i32 = 0; i < valueArray.length; i++) {
111
- out[i] = valueArray[i].toArray();
112
- }
113
- return out;
114
- }
115
-
116
- toTupleArray<T extends Tuple>(): Array<T> {
117
- assert(
118
- this.kind == ValueKind.ARRAY || this.kind == ValueKind.FIXED_ARRAY,
119
- 'Ethereum value is not an array.',
120
- );
121
- const valueArray = this.toArray();
122
- const out = new Array<T>(valueArray.length);
123
- for (let i: i32 = 0; i < valueArray.length; i++) {
124
- out[i] = changetype<T>(valueArray[i].toTuple());
125
- }
126
- return out;
127
- }
128
-
129
- toTupleMatrix<T extends Tuple>(): Array<Array<T>> {
130
- const valueMatrix = this.toMatrix();
131
- const out = new Array<Array<T>>(valueMatrix.length);
132
- for (let i: i32 = 0; i < valueMatrix.length; i++) {
133
- out[i] = new Array<T>(valueMatrix[i].length);
134
- for (let j: i32 = 0; j < valueMatrix[i].length; j++) {
135
- out[i][j] = changetype<T>(valueMatrix[i][j].toTuple());
136
- }
137
- }
138
- return out;
139
- }
140
-
141
- toBooleanArray(): Array<boolean> {
142
- assert(
143
- this.kind == ValueKind.ARRAY || this.kind == ValueKind.FIXED_ARRAY,
144
- 'Ethereum value is not an array or fixed array.',
145
- );
146
- const valueArray = this.toArray();
147
- const out = new Array<boolean>(valueArray.length);
148
- for (let i: i32 = 0; i < valueArray.length; i++) {
149
- out[i] = valueArray[i].toBoolean();
150
- }
151
- return out;
152
- }
153
-
154
- toBytesArray(): Array<Bytes> {
155
- assert(
156
- this.kind == ValueKind.ARRAY || this.kind == ValueKind.FIXED_ARRAY,
157
- 'Ethereum value is not an array or fixed array.',
158
- );
159
- const valueArray = this.toArray();
160
- const out = new Array<Bytes>(valueArray.length);
161
- for (let i: i32 = 0; i < valueArray.length; i++) {
162
- out[i] = valueArray[i].toBytes();
163
- }
164
- return out;
165
- }
166
-
167
- toAddressArray(): Array<Address> {
168
- assert(
169
- this.kind == ValueKind.ARRAY || this.kind == ValueKind.FIXED_ARRAY,
170
- 'Ethereum value is not an array or fixed array.',
171
- );
172
- const valueArray = this.toArray();
173
- const out = new Array<Address>(valueArray.length);
174
- for (let i: i32 = 0; i < valueArray.length; i++) {
175
- out[i] = valueArray[i].toAddress();
176
- }
177
- return out;
178
- }
179
-
180
- toStringArray(): Array<string> {
181
- assert(
182
- this.kind == ValueKind.ARRAY || this.kind == ValueKind.FIXED_ARRAY,
183
- 'Ethereum value is not an array or fixed array.',
184
- );
185
- const valueArray = this.toArray();
186
- const out = new Array<string>(valueArray.length);
187
- for (let i: i32 = 0; i < valueArray.length; i++) {
188
- out[i] = valueArray[i].toString();
189
- }
190
- return out;
191
- }
192
-
193
- toI32Array(): Array<i32> {
194
- assert(
195
- this.kind == ValueKind.ARRAY || this.kind == ValueKind.FIXED_ARRAY,
196
- 'Ethereum value is not an array or fixed array.',
197
- );
198
- const valueArray = this.toArray();
199
- const out = new Array<i32>(valueArray.length);
200
- for (let i: i32 = 0; i < valueArray.length; i++) {
201
- out[i] = valueArray[i].toI32();
202
- }
203
- return out;
204
- }
205
-
206
- toBigIntArray(): Array<BigInt> {
207
- assert(
208
- this.kind == ValueKind.ARRAY || this.kind == ValueKind.FIXED_ARRAY,
209
- 'Ethereum value is not an array or fixed array.',
210
- );
211
- const valueArray = this.toArray();
212
- const out = new Array<BigInt>(valueArray.length);
213
- for (let i: i32 = 0; i < valueArray.length; i++) {
214
- out[i] = valueArray[i].toBigInt();
215
- }
216
- return out;
217
- }
218
-
219
- toBooleanMatrix(): Array<Array<boolean>> {
220
- const valueMatrix = this.toMatrix();
221
- const out = new Array<Array<boolean>>(valueMatrix.length);
222
- for (let i: i32 = 0; i < valueMatrix.length; i++) {
223
- out[i] = new Array<boolean>(valueMatrix[i].length);
224
- for (let j: i32 = 0; j < valueMatrix[i].length; j++) {
225
- out[i][j] = valueMatrix[i][j].toBoolean();
226
- }
227
- }
228
- return out;
229
- }
230
-
231
- toBytesMatrix(): Array<Array<Bytes>> {
232
- const valueMatrix = this.toMatrix();
233
- const out = new Array<Array<Bytes>>(valueMatrix.length);
234
- for (let i: i32 = 0; i < valueMatrix.length; i++) {
235
- out[i] = new Array<Bytes>(valueMatrix[i].length);
236
- for (let j: i32 = 0; j < valueMatrix[i].length; j++) {
237
- out[i][j] = valueMatrix[i][j].toBytes();
238
- }
239
- }
240
- return out;
241
- }
242
-
243
- toAddressMatrix(): Array<Array<Address>> {
244
- const valueMatrix = this.toMatrix();
245
- const out = new Array<Array<Address>>(valueMatrix.length);
246
- for (let i: i32 = 0; i < valueMatrix.length; i++) {
247
- out[i] = new Array<Address>(valueMatrix[i].length);
248
- for (let j: i32 = 0; j < valueMatrix[i].length; j++) {
249
- out[i][j] = valueMatrix[i][j].toAddress();
250
- }
251
- }
252
- return out;
253
- }
254
-
255
- toStringMatrix(): Array<Array<string>> {
256
- const valueMatrix = this.toMatrix();
257
- const out = new Array<Array<string>>(valueMatrix.length);
258
- for (let i: i32 = 0; i < valueMatrix.length; i++) {
259
- out[i] = new Array<string>(valueMatrix[i].length);
260
- for (let j: i32 = 0; j < valueMatrix[i].length; j++) {
261
- out[i][j] = valueMatrix[i][j].toString();
262
- }
263
- }
264
- return out;
265
- }
266
-
267
- toI32Matrix(): Array<Array<i32>> {
268
- const valueMatrix = this.toMatrix();
269
- const out = new Array<Array<i32>>(valueMatrix.length);
270
- for (let i: i32 = 0; i < valueMatrix.length; i++) {
271
- out[i] = new Array<i32>(valueMatrix[i].length);
272
- for (let j: i32 = 0; j < valueMatrix[i].length; j++) {
273
- out[i][j] = valueMatrix[i][j].toI32();
274
- }
275
- }
276
- return out;
277
- }
278
-
279
- toBigIntMatrix(): Array<Array<BigInt>> {
280
- const valueMatrix = this.toMatrix();
281
- const out = new Array<Array<BigInt>>(valueMatrix.length);
282
- for (let i: i32 = 0; i < valueMatrix.length; i++) {
283
- out[i] = new Array<BigInt>(valueMatrix[i].length);
284
- for (let j: i32 = 0; j < valueMatrix[i].length; j++) {
285
- out[i][j] = valueMatrix[i][j].toBigInt();
286
- }
287
- }
288
- return out;
289
- }
290
-
291
- static fromAddress(address: Address): Value {
292
- assert(address.length == 20, 'Address must contain exactly 20 bytes');
293
- return new Value(ValueKind.ADDRESS, changetype<u32>(address));
294
- }
295
-
296
- static fromBoolean(b: boolean): Value {
297
- return new Value(ValueKind.BOOL, b ? 1 : 0);
298
- }
299
-
300
- static fromBytes(bytes: Bytes): Value {
301
- return new Value(ValueKind.BYTES, changetype<u32>(bytes));
302
- }
303
-
304
- static fromFixedBytes(bytes: Bytes): Value {
305
- return new Value(ValueKind.FIXED_BYTES, changetype<u32>(bytes));
306
- }
307
-
308
- static fromI32(i: i32): Value {
309
- return new Value(ValueKind.INT, changetype<u32>(BigInt.fromI32(i)));
310
- }
311
-
312
- static fromSignedBigInt(i: BigInt): Value {
313
- return new Value(ValueKind.INT, changetype<u32>(i));
314
- }
315
-
316
- static fromUnsignedBigInt(i: BigInt): Value {
317
- return new Value(ValueKind.UINT, changetype<u32>(i));
318
- }
319
-
320
- static fromString(s: string): Value {
321
- return new Value(ValueKind.STRING, changetype<u32>(s));
322
- }
323
-
324
- static fromArray(values: Array<Value>): Value {
325
- return new Value(ValueKind.ARRAY, changetype<u32>(values));
326
- }
327
-
328
- static fromFixedSizedArray(values: Array<Value>): Value {
329
- return new Value(ValueKind.FIXED_ARRAY, changetype<u32>(values));
330
- }
331
-
332
- static fromTuple(values: Tuple): Value {
333
- return new Value(ValueKind.TUPLE, changetype<u32>(values));
334
- }
335
-
336
- static fromMatrix(values: Array<Array<Value>>): Value {
337
- const innerOut = new Array<Value>(values.length);
338
- for (let i: i32 = 0; i < innerOut.length; i++) {
339
- innerOut[i] = Value.fromArray(values[i]);
340
- }
341
- return Value.fromArray(innerOut);
342
- }
343
-
344
- static fromTupleArray(values: Array<Tuple>): Value {
345
- const out = new Array<Value>(values.length);
346
- for (let i: i32 = 0; i < values.length; i++) {
347
- out[i] = Value.fromTuple(values[i]);
348
- }
349
- return Value.fromArray(out);
350
- }
351
-
352
- static fromTupleMatrix(values: Array<Array<Tuple>>): Value {
353
- const out = new Array<Array<Value>>(values.length);
354
- for (let i: i32 = 0; i < values.length; i++) {
355
- out[i] = new Array<Value>(values[i].length);
356
- for (let j: i32 = 0; j < values[i].length; j++) {
357
- out[i][j] = Value.fromTuple(values[i][j]);
358
- }
359
- }
360
- return Value.fromMatrix(out);
361
- }
362
-
363
- static fromBooleanArray(values: Array<boolean>): Value {
364
- const out = new Array<Value>(values.length);
365
- for (let i: i32 = 0; i < values.length; i++) {
366
- out[i] = Value.fromBoolean(values[i]);
367
- }
368
- return Value.fromArray(out);
369
- }
370
-
371
- static fromBytesArray(values: Array<Bytes>): Value {
372
- const out = new Array<Value>(values.length);
373
- for (let i: i32 = 0; i < values.length; i++) {
374
- out[i] = Value.fromBytes(values[i]);
375
- }
376
- return Value.fromArray(out);
377
- }
378
-
379
- static fromFixedBytesArray(values: Array<Bytes>): Value {
380
- const out = new Array<Value>(values.length);
381
- for (let i: i32 = 0; i < values.length; i++) {
382
- out[i] = Value.fromFixedBytes(values[i]);
383
- }
384
- return Value.fromArray(out);
385
- }
386
-
387
- static fromAddressArray(values: Array<Address>): Value {
388
- const out = new Array<Value>(values.length);
389
- for (let i: i32 = 0; i < values.length; i++) {
390
- out[i] = Value.fromAddress(values[i]);
391
- }
392
- return Value.fromArray(out);
393
- }
394
-
395
- static fromStringArray(values: Array<string>): Value {
396
- const out = new Array<Value>(values.length);
397
- for (let i: i32 = 0; i < values.length; i++) {
398
- out[i] = Value.fromString(values[i]);
399
- }
400
- return Value.fromArray(out);
401
- }
402
-
403
- static fromI32Array(values: Array<i32>): Value {
404
- const out = new Array<Value>(values.length);
405
- for (let i: i32 = 0; i < values.length; i++) {
406
- out[i] = Value.fromI32(values[i]);
407
- }
408
- return Value.fromArray(out);
409
- }
410
-
411
- static fromSignedBigIntArray(values: Array<BigInt>): Value {
412
- const out = new Array<Value>(values.length);
413
- for (let i: i32 = 0; i < values.length; i++) {
414
- out[i] = Value.fromSignedBigInt(values[i]);
415
- }
416
- return Value.fromArray(out);
417
- }
418
-
419
- static fromUnsignedBigIntArray(values: Array<BigInt>): Value {
420
- const out = new Array<Value>(values.length);
421
- for (let i: i32 = 0; i < values.length; i++) {
422
- out[i] = Value.fromUnsignedBigInt(values[i]);
423
- }
424
- return Value.fromArray(out);
425
- }
426
-
427
- static fromBooleanMatrix(values: Array<Array<boolean>>): Value {
428
- const out = new Array<Array<Value>>(values.length);
429
- for (let i: i32 = 0; i < values.length; i++) {
430
- out[i] = new Array<Value>(values[i].length);
431
- for (let j: i32 = 0; j < values[i].length; j++) {
432
- out[i][j] = Value.fromBoolean(values[i][j]);
433
- }
434
- }
435
- return Value.fromMatrix(out);
436
- }
437
-
438
- static fromBytesMatrix(values: Array<Array<Bytes>>): Value {
439
- const out = new Array<Array<Value>>(values.length);
440
- for (let i: i32 = 0; i < values.length; i++) {
441
- out[i] = new Array<Value>(values[i].length);
442
- for (let j: i32 = 0; j < values[i].length; j++) {
443
- out[i][j] = Value.fromBytes(values[i][j]);
444
- }
445
- }
446
- return Value.fromMatrix(out);
447
- }
448
-
449
- static fromFixedBytesMatrix(values: Array<Array<Bytes>>): Value {
450
- const out = new Array<Array<Value>>(values.length);
451
- for (let i: i32 = 0; i < values.length; i++) {
452
- out[i] = new Array<Value>(values[i].length);
453
- for (let j: i32 = 0; j < values[i].length; j++) {
454
- out[i][j] = Value.fromFixedBytes(values[i][j]);
455
- }
456
- }
457
- return Value.fromMatrix(out);
458
- }
459
-
460
- static fromAddressMatrix(values: Array<Array<Address>>): Value {
461
- const out = new Array<Array<Value>>(values.length);
462
- for (let i: i32 = 0; i < values.length; i++) {
463
- out[i] = new Array<Value>(values[i].length);
464
- for (let j: i32 = 0; j < values[i].length; j++) {
465
- out[i][j] = Value.fromAddress(values[i][j]);
466
- }
467
- }
468
- return Value.fromMatrix(out);
469
- }
470
-
471
- static fromStringMatrix(values: Array<Array<string>>): Value {
472
- const out = new Array<Array<Value>>(values.length);
473
- for (let i: i32 = 0; i < values.length; i++) {
474
- out[i] = new Array<Value>(values[i].length);
475
- for (let j: i32 = 0; j < values[i].length; j++) {
476
- out[i][j] = Value.fromString(values[i][j]);
477
- }
478
- }
479
- return Value.fromMatrix(out);
480
- }
481
-
482
- static fromI32Matrix(values: Array<Array<i32>>): Value {
483
- const out = new Array<Array<Value>>(values.length);
484
- for (let i: i32 = 0; i < values.length; i++) {
485
- out[i] = new Array<Value>(values[i].length);
486
- for (let j: i32 = 0; j < values[i].length; j++) {
487
- out[i][j] = Value.fromI32(values[i][j]);
488
- }
489
- }
490
- return Value.fromMatrix(out);
491
- }
492
-
493
- static fromSignedBigIntMatrix(values: Array<Array<BigInt>>): Value {
494
- const out = new Array<Array<Value>>(values.length);
495
- for (let i: i32 = 0; i < values.length; i++) {
496
- out[i] = new Array<Value>(values[i].length);
497
- for (let j: i32 = 0; j < values[i].length; j++) {
498
- out[i][j] = Value.fromSignedBigInt(values[i][j]);
499
- }
500
- }
501
- return Value.fromMatrix(out);
502
- }
503
-
504
- static fromUnsignedBigIntMatrix(values: Array<Array<BigInt>>): Value {
505
- const out = new Array<Array<Value>>(values.length);
506
- for (let i: i32 = 0; i < values.length; i++) {
507
- out[i] = new Array<Value>(values[i].length);
508
- for (let j: i32 = 0; j < values[i].length; j++) {
509
- out[i][j] = Value.fromUnsignedBigInt(values[i][j]);
510
- }
511
- }
512
- return Value.fromMatrix(out);
513
- }
514
- }
515
-
516
- /**
517
- * Common representation for Ethereum tuples / Solidity structs.
518
- *
519
- * This base class stores the tuple/struct values in an array. The Graph CLI
520
- * code generation then creates subclasses that provide named getters to
521
- * access the members by name.
522
- */
523
- export class Tuple extends Array<Value> {}
524
-
525
- /**
526
- * An Ethereum block.
527
- */
528
- export class Block {
529
- constructor(
530
- public hash: Bytes,
531
- public parentHash: Bytes,
532
- public unclesHash: Bytes,
533
- public author: Address,
534
- public stateRoot: Bytes,
535
- public transactionsRoot: Bytes,
536
- public receiptsRoot: Bytes,
537
- public number: BigInt,
538
- public gasUsed: BigInt,
539
- public gasLimit: BigInt,
540
- public timestamp: BigInt,
541
- public difficulty: BigInt,
542
- public totalDifficulty: BigInt,
543
- public size: BigInt | null,
544
- public baseFeePerGas: BigInt | null,
545
- ) {}
546
- }
547
-
548
- /**
549
- * An Ethereum transaction.
550
- */
551
- export class Transaction {
552
- constructor(
553
- public hash: Bytes,
554
- public index: BigInt,
555
- public from: Address,
556
- public to: Address | null,
557
- public value: BigInt,
558
- public gasLimit: BigInt,
559
- public gasPrice: BigInt,
560
- public input: Bytes,
561
- public nonce: BigInt,
562
- ) {}
563
- }
564
-
565
- /**
566
- * An Ethereum transaction receipt.
567
- */
568
- export class TransactionReceipt {
569
- constructor(
570
- public transactionHash: Bytes,
571
- public transactionIndex: BigInt,
572
- public blockHash: Bytes,
573
- public blockNumber: BigInt,
574
- public cumulativeGasUsed: BigInt,
575
- public gasUsed: BigInt,
576
- public contractAddress: Address,
577
- public logs: Array<Log>,
578
- public status: BigInt,
579
- public root: Bytes,
580
- public logsBloom: Bytes,
581
- ) {}
582
- }
583
-
584
- /**
585
- * An Ethereum event log.
586
- */
587
- export class Log {
588
- constructor(
589
- public address: Address,
590
- public topics: Array<Bytes>,
591
- public data: Bytes,
592
- public blockHash: Bytes,
593
- public blockNumber: Bytes,
594
- public transactionHash: Bytes,
595
- public transactionIndex: BigInt,
596
- public logIndex: BigInt,
597
- public transactionLogIndex: BigInt,
598
- public logType: string,
599
- public removed: Wrapped<bool> | null,
600
- ) {}
601
- }
602
-
603
- /**
604
- * Common representation for Ethereum smart contract calls.
605
- */
606
- export class Call {
607
- constructor(
608
- public to: Address,
609
- public from: Address,
610
- public block: Block,
611
- public transaction: Transaction,
612
- public inputValues: Array<EventParam>,
613
- public outputValues: Array<EventParam>,
614
- ) {}
615
- }
616
-
617
- /**
618
- * Common representation for Ethereum smart contract events.
619
- */
620
- export class Event {
621
- constructor(
622
- public address: Address,
623
- public logIndex: BigInt,
624
- public transactionLogIndex: BigInt,
625
- public logType: string | null,
626
- public block: Block,
627
- public transaction: Transaction,
628
- public parameters: Array<EventParam>,
629
- public receipt: TransactionReceipt | null,
630
- ) {}
631
- }
632
-
633
- /**
634
- * A dynamically-typed Ethereum event parameter.
635
- */
636
- export class EventParam {
637
- constructor(
638
- public name: string,
639
- public value: Value,
640
- ) {}
641
- }
642
-
643
- export class SmartContractCall {
644
- contractName: string;
645
- contractAddress: Address;
646
- functionName: string;
647
- functionSignature: string;
648
- functionParams: Array<Value>;
649
-
650
- constructor(
651
- contractName: string,
652
- contractAddress: Address,
653
- functionName: string,
654
- functionSignature: string,
655
- functionParams: Array<Value>,
656
- ) {
657
- this.contractName = contractName;
658
- this.contractAddress = contractAddress;
659
- this.functionName = functionName;
660
- this.functionSignature = functionSignature;
661
- this.functionParams = functionParams;
662
- }
663
- }
664
-
665
- /**
666
- * Low-level interaction with Ethereum smart contracts
667
- */
668
- export class SmartContract {
669
- _name: string;
670
- _address: Address;
671
-
672
- protected constructor(name: string, address: Address) {
673
- this._name = name;
674
- this._address = address;
675
- }
676
-
677
- call(name: string, signature: string, params: Array<Value>): Array<Value> {
678
- const call = new SmartContractCall(this._name, this._address, name, signature, params);
679
- const result = ethereum.call(call);
680
- assert(
681
- result != null,
682
- 'Call reverted, probably because an `assert` or `require` in the contract failed, ' +
683
- 'consider using `try_' +
684
- name +
685
- '` to handle this in the mapping.',
686
- );
687
- return changetype<Array<Value>>(result);
688
- }
689
-
690
- tryCall(name: string, signature: string, params: Array<Value>): CallResult<Array<Value>> {
691
- const call = new SmartContractCall(this._name, this._address, name, signature, params);
692
- const result = ethereum.call(call);
693
- if (result == null) {
694
- return new CallResult();
695
- }
696
- return CallResult.fromValue(changetype<Array<Value>>(result));
697
- }
698
- }
699
-
700
- export class CallResult<T> {
701
- // `null` indicates a reverted call.
702
- private _value: Wrapped<T> | null;
703
-
704
- constructor() {
705
- this._value = null;
706
- }
707
-
708
- static fromValue<T>(value: T): CallResult<T> {
709
- const result = new CallResult<T>();
710
- result._value = new Wrapped(value);
711
- return result;
712
- }
713
-
714
- get reverted(): bool {
715
- return this._value == null;
716
- }
717
-
718
- get value(): T {
719
- assert(
720
- !this.reverted,
721
- 'accessed value of a reverted call, ' +
722
- 'please check the `reverted` field before accessing the `value` field',
723
- );
724
- return changetype<Wrapped<T>>(this._value).inner;
725
- }
726
- }
727
- }