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.
- package/API/v1/activePositions/ActivePositionsResult.ts +221 -3
- package/API/v1/activePositions/NftItem.ts +63 -0
- package/API/v1/activePositions/PerpPosition.ts +129 -0
- package/API/v1/activePositions/TokenBalance.ts +32 -1
- package/API/v1/activePositions/activePositions.ts +8 -1
- package/API/v1/index.ts +6 -0
- package/API/v1/proto/activePositions/activePositions/ActivePositionsResultPb.ts +159 -0
- package/API/v1/proto/activePositions/activePositions/NftItemPb.ts +71 -0
- package/API/v1/proto/activePositions/activePositions/PerpPositionPb.ts +142 -0
- package/API/v1/proto/activePositions/activePositions/PerpSide.ts +10 -0
- package/API/v1/proto/activePositions/activePositions/TokenBalancePb.ts +71 -0
- package/API/v1/proto/activePositions/google/protobuf/Timestamp.ts +48 -0
- package/API/v1/proto/watcher/WatcherInputPb.ts +121 -0
- package/API/v1/watcher/WatcherInput.ts +100 -2
- package/API/v1/watcher/watcher.ts +154 -4
- package/package.json +5 -2
- package/postinstall-script.js +4 -2
- package/@graphprotocol/graph-ts/README.md +0 -13
- package/@graphprotocol/graph-ts/chain/arweave.ts +0 -82
- package/@graphprotocol/graph-ts/chain/cosmos.ts +0 -426
- package/@graphprotocol/graph-ts/chain/ethereum.ts +0 -727
- package/@graphprotocol/graph-ts/chain/near.ts +0 -420
- package/@graphprotocol/graph-ts/chain/starknet.ts +0 -39
- package/@graphprotocol/graph-ts/common/collections.ts +0 -495
- package/@graphprotocol/graph-ts/common/conversion.ts +0 -3
- package/@graphprotocol/graph-ts/common/datasource.ts +0 -41
- package/@graphprotocol/graph-ts/common/eager_offset.ts +0 -42
- package/@graphprotocol/graph-ts/common/json.ts +0 -28
- package/@graphprotocol/graph-ts/common/numbers.ts +0 -407
- package/@graphprotocol/graph-ts/common/value.ts +0 -585
- package/@graphprotocol/graph-ts/global/global.ts +0 -4
- package/@graphprotocol/graph-ts/helper-functions.ts +0 -79
- package/@graphprotocol/graph-ts/index.ts +0 -156
- package/@graphprotocol/graph-ts/package.json +0 -3
- package/@graphprotocol/graph-ts/tsconfig.json +0 -4
- package/@graphprotocol/graph-ts/types/tsconfig.base.json +0 -3
|
@@ -1,495 +0,0 @@
|
|
|
1
|
-
import { typeConversion } from './conversion';
|
|
2
|
-
import { BigDecimal, BigInt } from './numbers';
|
|
3
|
-
import { Value } from './value';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Byte array
|
|
7
|
-
*/
|
|
8
|
-
export class ByteArray extends Uint8Array {
|
|
9
|
-
/**
|
|
10
|
-
* Returns bytes in little-endian order.
|
|
11
|
-
*/
|
|
12
|
-
static fromI32(x: i32): ByteArray {
|
|
13
|
-
const self = new ByteArray(4);
|
|
14
|
-
self[0] = x as u8;
|
|
15
|
-
self[1] = (x >> 8) as u8;
|
|
16
|
-
self[2] = (x >> 16) as u8;
|
|
17
|
-
self[3] = (x >> 24) as u8;
|
|
18
|
-
return self;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Returns bytes in little-endian order.
|
|
23
|
-
*/
|
|
24
|
-
static fromU32(x: u32): ByteArray {
|
|
25
|
-
const self = new ByteArray(4);
|
|
26
|
-
self[0] = x as u8;
|
|
27
|
-
self[1] = (x >> 8) as u8;
|
|
28
|
-
self[2] = (x >> 16) as u8;
|
|
29
|
-
self[3] = (x >> 24) as u8;
|
|
30
|
-
return self;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Returns bytes in little-endian order.
|
|
35
|
-
*/
|
|
36
|
-
static fromI64(x: i64): ByteArray {
|
|
37
|
-
const self = new ByteArray(8);
|
|
38
|
-
self[0] = x as u8;
|
|
39
|
-
self[1] = (x >> 8) as u8;
|
|
40
|
-
self[2] = (x >> 16) as u8;
|
|
41
|
-
self[3] = (x >> 24) as u8;
|
|
42
|
-
self[4] = (x >> 32) as u8;
|
|
43
|
-
self[5] = (x >> 40) as u8;
|
|
44
|
-
self[6] = (x >> 48) as u8;
|
|
45
|
-
self[7] = (x >> 56) as u8;
|
|
46
|
-
return self;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Returns bytes in little-endian order.
|
|
51
|
-
*/
|
|
52
|
-
static fromU64(x: u64): ByteArray {
|
|
53
|
-
const self = new ByteArray(8);
|
|
54
|
-
self[0] = x as u8;
|
|
55
|
-
self[1] = (x >> 8) as u8;
|
|
56
|
-
self[2] = (x >> 16) as u8;
|
|
57
|
-
self[3] = (x >> 24) as u8;
|
|
58
|
-
self[4] = (x >> 32) as u8;
|
|
59
|
-
self[5] = (x >> 40) as u8;
|
|
60
|
-
self[6] = (x >> 48) as u8;
|
|
61
|
-
self[7] = (x >> 56) as u8;
|
|
62
|
-
return self;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
static empty(): ByteArray {
|
|
66
|
-
return ByteArray.fromI32(0);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Convert the string `hex` which must consist of an even number of
|
|
71
|
-
* hexadecimal digits to a `ByteArray`. The string `hex` can optionally
|
|
72
|
-
* start with '0x'
|
|
73
|
-
*/
|
|
74
|
-
static fromHexString(hex: string): ByteArray {
|
|
75
|
-
assert(hex.length % 2 == 0, 'input ' + hex + ' has odd length');
|
|
76
|
-
// Skip possible `0x` prefix.
|
|
77
|
-
if (hex.length >= 2 && hex.charAt(0) == '0' && hex.charAt(1) == 'x') {
|
|
78
|
-
hex = hex.substr(2);
|
|
79
|
-
}
|
|
80
|
-
const output = new Bytes(hex.length / 2);
|
|
81
|
-
for (let i = 0; i < hex.length; i += 2) {
|
|
82
|
-
output[i / 2] = I8.parseInt(hex.substr(i, 2), 16);
|
|
83
|
-
}
|
|
84
|
-
return output;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
static fromUTF8(str: string): ByteArray {
|
|
88
|
-
const utf8 = String.UTF8.encode(str);
|
|
89
|
-
return changetype<ByteArray>(ByteArray.wrap(utf8));
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
static fromBigInt(bigInt: BigInt): ByteArray {
|
|
93
|
-
return changetype<ByteArray>(bigInt);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
toHex(): string {
|
|
97
|
-
return typeConversion.bytesToHex(this);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
toHexString(): string {
|
|
101
|
-
return typeConversion.bytesToHex(this);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
toString(): string {
|
|
105
|
-
return typeConversion.bytesToString(this);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
toBase58(): string {
|
|
109
|
-
return typeConversion.bytesToBase58(this);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Interprets the byte array as a little-endian U32.
|
|
114
|
-
* Throws in case of overflow.
|
|
115
|
-
*/
|
|
116
|
-
|
|
117
|
-
toU32(): u32 {
|
|
118
|
-
for (let i = 4; i < this.length; i++) {
|
|
119
|
-
if (this[i] != 0) {
|
|
120
|
-
assert(false, 'overflow converting ' + this.toHexString() + ' to u32');
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
const paddedBytes = new Bytes(4);
|
|
124
|
-
paddedBytes[0] = 0;
|
|
125
|
-
paddedBytes[1] = 0;
|
|
126
|
-
paddedBytes[2] = 0;
|
|
127
|
-
paddedBytes[3] = 0;
|
|
128
|
-
const minLen = paddedBytes.length < this.length ? paddedBytes.length : this.length;
|
|
129
|
-
for (let i = 0; i < minLen; i++) {
|
|
130
|
-
paddedBytes[i] = this[i];
|
|
131
|
-
}
|
|
132
|
-
let x: u32 = 0;
|
|
133
|
-
x = (x | paddedBytes[3]) << 8;
|
|
134
|
-
x = (x | paddedBytes[2]) << 8;
|
|
135
|
-
x = (x | paddedBytes[1]) << 8;
|
|
136
|
-
x = x | paddedBytes[0];
|
|
137
|
-
return x;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Interprets the byte array as a little-endian I32.
|
|
142
|
-
* Throws in case of overflow.
|
|
143
|
-
*/
|
|
144
|
-
|
|
145
|
-
toI32(): i32 {
|
|
146
|
-
const isNeg = this.length > 0 && this[this.length - 1] >> 7 == 1;
|
|
147
|
-
const padding = isNeg ? 255 : 0;
|
|
148
|
-
for (let i = 4; i < this.length; i++) {
|
|
149
|
-
if (this[i] != padding) {
|
|
150
|
-
assert(false, 'overflow converting ' + this.toHexString() + ' to i32');
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
const paddedBytes = new Bytes(4);
|
|
154
|
-
paddedBytes[0] = padding;
|
|
155
|
-
paddedBytes[1] = padding;
|
|
156
|
-
paddedBytes[2] = padding;
|
|
157
|
-
paddedBytes[3] = padding;
|
|
158
|
-
const minLen = paddedBytes.length < this.length ? paddedBytes.length : this.length;
|
|
159
|
-
for (let i = 0; i < minLen; i++) {
|
|
160
|
-
paddedBytes[i] = this[i];
|
|
161
|
-
}
|
|
162
|
-
let x: i32 = 0;
|
|
163
|
-
x = (x | paddedBytes[3]) << 8;
|
|
164
|
-
x = (x | paddedBytes[2]) << 8;
|
|
165
|
-
x = (x | paddedBytes[1]) << 8;
|
|
166
|
-
x = x | paddedBytes[0];
|
|
167
|
-
return x;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/** Create a new `ByteArray` that consist of `this` directly followed by
|
|
171
|
-
* the bytes from `other` */
|
|
172
|
-
concat(other: ByteArray): ByteArray {
|
|
173
|
-
const newArray = new ByteArray(this.length + other.length);
|
|
174
|
-
newArray.set(this, 0);
|
|
175
|
-
newArray.set(other, this.length);
|
|
176
|
-
return newArray;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/** Create a new `ByteArray` that consists of `this` directly followed by
|
|
180
|
-
* the representation of `other` as bytes */
|
|
181
|
-
concatI32(other: i32): ByteArray {
|
|
182
|
-
return this.concat(ByteArray.fromI32(other));
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Interprets the byte array as a little-endian I64.
|
|
187
|
-
* Throws in case of overflow.
|
|
188
|
-
*/
|
|
189
|
-
|
|
190
|
-
toI64(): i64 {
|
|
191
|
-
const isNeg = this.length > 0 && this[this.length - 1] >> 7 == 1;
|
|
192
|
-
const padding = isNeg ? 255 : 0;
|
|
193
|
-
for (let i = 8; i < this.length; i++) {
|
|
194
|
-
if (this[i] != padding) {
|
|
195
|
-
assert(false, 'overflow converting ' + this.toHexString() + ' to i64');
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
const paddedBytes = new Bytes(8);
|
|
199
|
-
paddedBytes[0] = padding;
|
|
200
|
-
paddedBytes[1] = padding;
|
|
201
|
-
paddedBytes[2] = padding;
|
|
202
|
-
paddedBytes[3] = padding;
|
|
203
|
-
paddedBytes[4] = padding;
|
|
204
|
-
paddedBytes[5] = padding;
|
|
205
|
-
paddedBytes[6] = padding;
|
|
206
|
-
paddedBytes[7] = padding;
|
|
207
|
-
const minLen = paddedBytes.length < this.length ? paddedBytes.length : this.length;
|
|
208
|
-
for (let i = 0; i < minLen; i++) {
|
|
209
|
-
paddedBytes[i] = this[i];
|
|
210
|
-
}
|
|
211
|
-
let x: i64 = 0;
|
|
212
|
-
x = (x | paddedBytes[7]) << 8;
|
|
213
|
-
x = (x | paddedBytes[6]) << 8;
|
|
214
|
-
x = (x | paddedBytes[5]) << 8;
|
|
215
|
-
x = (x | paddedBytes[4]) << 8;
|
|
216
|
-
x = (x | paddedBytes[3]) << 8;
|
|
217
|
-
x = (x | paddedBytes[2]) << 8;
|
|
218
|
-
x = (x | paddedBytes[1]) << 8;
|
|
219
|
-
x = x | paddedBytes[0];
|
|
220
|
-
return x;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Interprets the byte array as a little-endian U64.
|
|
225
|
-
* Throws in case of overflow.
|
|
226
|
-
*/
|
|
227
|
-
|
|
228
|
-
toU64(): u64 {
|
|
229
|
-
for (let i = 8; i < this.length; i++) {
|
|
230
|
-
if (this[i] != 0) {
|
|
231
|
-
assert(false, 'overflow converting ' + this.toHexString() + ' to u64');
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
const paddedBytes = new Bytes(8);
|
|
235
|
-
paddedBytes[0] = 0;
|
|
236
|
-
paddedBytes[1] = 0;
|
|
237
|
-
paddedBytes[2] = 0;
|
|
238
|
-
paddedBytes[3] = 0;
|
|
239
|
-
paddedBytes[4] = 0;
|
|
240
|
-
paddedBytes[5] = 0;
|
|
241
|
-
paddedBytes[6] = 0;
|
|
242
|
-
paddedBytes[7] = 0;
|
|
243
|
-
const minLen = paddedBytes.length < this.length ? paddedBytes.length : this.length;
|
|
244
|
-
for (let i = 0; i < minLen; i++) {
|
|
245
|
-
paddedBytes[i] = this[i];
|
|
246
|
-
}
|
|
247
|
-
let x: u64 = 0;
|
|
248
|
-
x = (x | paddedBytes[7]) << 8;
|
|
249
|
-
x = (x | paddedBytes[6]) << 8;
|
|
250
|
-
x = (x | paddedBytes[5]) << 8;
|
|
251
|
-
x = (x | paddedBytes[4]) << 8;
|
|
252
|
-
x = (x | paddedBytes[3]) << 8;
|
|
253
|
-
x = (x | paddedBytes[2]) << 8;
|
|
254
|
-
x = (x | paddedBytes[1]) << 8;
|
|
255
|
-
x = x | paddedBytes[0];
|
|
256
|
-
return x;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
@operator('==')
|
|
260
|
-
equals(other: ByteArray): boolean {
|
|
261
|
-
if (this.length != other.length) {
|
|
262
|
-
return false;
|
|
263
|
-
}
|
|
264
|
-
for (let i = 0; i < this.length; i++) {
|
|
265
|
-
if (this[i] != other[i]) {
|
|
266
|
-
return false;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
return true;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
@operator('!=')
|
|
273
|
-
notEqual(other: ByteArray): boolean {
|
|
274
|
-
return !(this == other);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/** A dynamically-sized byte array. */
|
|
279
|
-
export class Bytes extends ByteArray {
|
|
280
|
-
static fromByteArray(byteArray: ByteArray): Bytes {
|
|
281
|
-
return changetype<Bytes>(byteArray);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
static fromUint8Array(uint8Array: Uint8Array): Bytes {
|
|
285
|
-
return changetype<Bytes>(uint8Array);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Convert the string `hex` which must consist of an even number of
|
|
290
|
-
* hexadecimal digits to a `ByteArray`. The string `hex` can optionally
|
|
291
|
-
* start with '0x'
|
|
292
|
-
*/
|
|
293
|
-
static fromHexString(str: string): Bytes {
|
|
294
|
-
return changetype<Bytes>(ByteArray.fromHexString(str));
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
static fromUTF8(str: string): Bytes {
|
|
298
|
-
return Bytes.fromByteArray(ByteArray.fromUTF8(str));
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
static fromI32(i: i32): Bytes {
|
|
302
|
-
return changetype<Bytes>(ByteArray.fromI32(i));
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
static empty(): Bytes {
|
|
306
|
-
return changetype<Bytes>(ByteArray.empty());
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
concat(other: Bytes): Bytes {
|
|
310
|
-
return changetype<Bytes>(super.concat(other));
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
concatI32(other: i32): Bytes {
|
|
314
|
-
return changetype<Bytes>(super.concat(ByteArray.fromI32(other)));
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* TypedMap entry.
|
|
320
|
-
*/
|
|
321
|
-
export class TypedMapEntry<K, V> {
|
|
322
|
-
key: K;
|
|
323
|
-
value: V;
|
|
324
|
-
|
|
325
|
-
constructor(key: K, value: V) {
|
|
326
|
-
this.key = key;
|
|
327
|
-
this.value = value;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
/** Typed map */
|
|
332
|
-
export class TypedMap<K, V> {
|
|
333
|
-
entries: Array<TypedMapEntry<K, V>>;
|
|
334
|
-
|
|
335
|
-
constructor() {
|
|
336
|
-
this.entries = new Array<TypedMapEntry<K, V>>(0);
|
|
337
|
-
// this.entries = []
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
set(key: K, value: V): void {
|
|
341
|
-
const entry = this.getEntry(key);
|
|
342
|
-
if (entry === null) {
|
|
343
|
-
const entry = new TypedMapEntry<K, V>(key, value);
|
|
344
|
-
this.entries.push(entry);
|
|
345
|
-
} else {
|
|
346
|
-
entry.value = value;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
getEntry(key: K): TypedMapEntry<K, V> | null {
|
|
351
|
-
for (let i: i32 = 0; i < this.entries.length; i++) {
|
|
352
|
-
if (this.entries[i].key == key) {
|
|
353
|
-
return this.entries[i];
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
return null;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
mustGetEntry(key: K): TypedMapEntry<K, V> {
|
|
360
|
-
const entry = this.getEntry(key);
|
|
361
|
-
assert(entry != null, `Entry for key ${key} does not exist in TypedMap`);
|
|
362
|
-
return entry!;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
get(key: K): V | null {
|
|
366
|
-
for (let i: i32 = 0; i < this.entries.length; i++) {
|
|
367
|
-
if (this.entries[i].key == key) {
|
|
368
|
-
return this.entries[i].value;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
return null;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
mustGet(key: K): V {
|
|
375
|
-
const value = this.get(key);
|
|
376
|
-
assert(value != null, `Value for key ${key} does not exist in TypedMap`);
|
|
377
|
-
return value!;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
isSet(key: K): bool {
|
|
381
|
-
for (let i: i32 = 0; i < this.entries.length; i++) {
|
|
382
|
-
if (this.entries[i].key == key) {
|
|
383
|
-
return true;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
return false;
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* Common representation for entity data, storing entity attributes
|
|
392
|
-
* as `string` keys and the attribute values as dynamically-typed
|
|
393
|
-
* `Value` objects.
|
|
394
|
-
*/
|
|
395
|
-
export class Entity extends TypedMap<string, Value> {
|
|
396
|
-
unset(key: string): void {
|
|
397
|
-
this.set(key, Value.fromNull());
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
/** Assigns properties from sources to this Entity in right-to-left order */
|
|
401
|
-
merge(sources: Array<Entity>): Entity {
|
|
402
|
-
const target = this;
|
|
403
|
-
for (let i = 0; i < sources.length; i++) {
|
|
404
|
-
const entries = sources[i].entries;
|
|
405
|
-
for (let j = 0; j < entries.length; j++) {
|
|
406
|
-
target.set(entries[j].key, entries[j].value);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
return target;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
setString(key: string, value: string): void {
|
|
413
|
-
this.set(key, Value.fromString(value));
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
setI32(key: string, value: i32): void {
|
|
417
|
-
this.set(key, Value.fromI32(value));
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
setBigInt(key: string, value: BigInt): void {
|
|
421
|
-
this.set(key, Value.fromBigInt(value));
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
setBytes(key: string, value: Bytes): void {
|
|
425
|
-
this.set(key, Value.fromBytes(value));
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
setBoolean(key: string, value: bool): void {
|
|
429
|
-
this.set(key, Value.fromBoolean(value));
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
setBigDecimal(key: string, value: BigDecimal): void {
|
|
433
|
-
this.set(key, Value.fromBigDecimal(value));
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
getString(key: string): string {
|
|
437
|
-
return this.get(key)!.toString();
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
getI32(key: string): i32 {
|
|
441
|
-
return this.get(key)!.toI32();
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
getBigInt(key: string): BigInt {
|
|
445
|
-
return this.get(key)!.toBigInt();
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
getBytes(key: string): Bytes {
|
|
449
|
-
return this.get(key)!.toBytes();
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
getBoolean(key: string): boolean {
|
|
453
|
-
return this.get(key)!.toBoolean();
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
getBigDecimal(key: string): BigDecimal {
|
|
457
|
-
return this.get(key)!.toBigDecimal();
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
* The result of an operation, with a corresponding value and error type.
|
|
463
|
-
*/
|
|
464
|
-
export class Result<V, E> {
|
|
465
|
-
_value: Wrapped<V> | null = null;
|
|
466
|
-
_error: Wrapped<E> | null = null;
|
|
467
|
-
|
|
468
|
-
get isOk(): boolean {
|
|
469
|
-
return this._value !== null;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
get isError(): boolean {
|
|
473
|
-
return this._error !== null;
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
get value(): V {
|
|
477
|
-
assert(this._value != null, 'Trying to get a value from an error result');
|
|
478
|
-
return changetype<Wrapped<V>>(this._value).inner;
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
get error(): E {
|
|
482
|
-
assert(this._error != null, 'Trying to get an error from a successful result');
|
|
483
|
-
return changetype<Wrapped<E>>(this._error).inner;
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
// This is used to wrap a generic so that it can be unioned with `null`, working around limitations
|
|
488
|
-
// with primitives.
|
|
489
|
-
export class Wrapped<T> {
|
|
490
|
-
inner: T;
|
|
491
|
-
|
|
492
|
-
constructor(inner: T) {
|
|
493
|
-
this.inner = inner;
|
|
494
|
-
}
|
|
495
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import './eager_offset';
|
|
2
|
-
import { Entity } from './collections';
|
|
3
|
-
import { Address } from './numbers';
|
|
4
|
-
|
|
5
|
-
/** Host interface for managing data sources */
|
|
6
|
-
export declare namespace dataSource {
|
|
7
|
-
function create(name: string, params: Array<string>): void;
|
|
8
|
-
function createWithContext(name: string, params: Array<string>, context: DataSourceContext): void;
|
|
9
|
-
|
|
10
|
-
// Properties of the data source that fired the event.
|
|
11
|
-
function address(): Address;
|
|
12
|
-
function network(): string;
|
|
13
|
-
function context(): DataSourceContext;
|
|
14
|
-
}
|
|
15
|
-
export namespace dataSource {
|
|
16
|
-
export function stringParam(): string {
|
|
17
|
-
return String.UTF8.decode(dataSource.address().buffer);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** Context for dynamic data sources */
|
|
22
|
-
export class DataSourceContext extends Entity {}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Base class for data source templates. Allows to dynamically create
|
|
26
|
-
* data sources from templates at runtime.
|
|
27
|
-
*/
|
|
28
|
-
export class DataSourceTemplate {
|
|
29
|
-
/**
|
|
30
|
-
* Dynamically creates a data source from the template with the
|
|
31
|
-
* given name, using the parameter strings to configure the new
|
|
32
|
-
* data source.
|
|
33
|
-
*/
|
|
34
|
-
static create(name: string, params: Array<string>): void {
|
|
35
|
-
dataSource.create(name, params);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
static createWithContext(name: string, params: Array<string>, context: DataSourceContext): void {
|
|
39
|
-
dataSource.createWithContext(name, params, context);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// # What is this file?
|
|
2
|
-
// This file is a "hack" to allow global variables in subgraphs and
|
|
3
|
-
// on this library (`graph-ts`).
|
|
4
|
-
//
|
|
5
|
-
// # Why is it needed?
|
|
6
|
-
// It's necessary because of one of the features of the AssemblyScript
|
|
7
|
-
// compiler we use, the stub runtime.
|
|
8
|
-
//
|
|
9
|
-
// The problem happens because we call the stub runtime allocation
|
|
10
|
-
// (`__alloc`) directly on Rust side (`graph-node`), and that doesn't
|
|
11
|
-
// trigger some AssemblyScript aspects of the code.
|
|
12
|
-
//
|
|
13
|
-
// If you take a look at the stub runtime's code, you'll see that the
|
|
14
|
-
// `__alloc` function uses a variable named `offset` tagged as `lazy`.
|
|
15
|
-
// Like said above, since we call it on Rust side, this variable is not
|
|
16
|
-
// "triggered" to be used, then it's declared below the `__alloc` call
|
|
17
|
-
// in the compiled WASM code.
|
|
18
|
-
//
|
|
19
|
-
// That makes the `graph-node` WASM runtime break because of this out
|
|
20
|
-
// of order variable usage.
|
|
21
|
-
//
|
|
22
|
-
// # How does this fix the issue?
|
|
23
|
-
// The way this workaround works is by calling the `__alloc` function
|
|
24
|
-
// before everything in the AssemblyScript side. This makes the `offset`
|
|
25
|
-
// `lazy` variable be eagerly evaluated when the mappings are compiled
|
|
26
|
-
// (since they always import `graph-ts`).
|
|
27
|
-
//
|
|
28
|
-
// So when we're on Rust side calling `__alloc` it will be fine, because
|
|
29
|
-
// the `offset` is declared before call (order fixed because of this file).
|
|
30
|
-
//
|
|
31
|
-
// The 0 argument to the function call is just because we need no memory
|
|
32
|
-
// to be allocated.
|
|
33
|
-
//
|
|
34
|
-
// # IMPORTANT
|
|
35
|
-
// This should be imported in EVERY file which uses external namespaces (`graph-node` host-exports code),
|
|
36
|
-
// just to make sure no one imports a file directly and gets an error on global variables.
|
|
37
|
-
//
|
|
38
|
-
// # Reference
|
|
39
|
-
// - Runtimes in AS: https://www.assemblyscript.org/garbage-collection.html#runtime-variants
|
|
40
|
-
// - `offset` variable in question: https://github.com/AssemblyScript/assemblyscript/blob/f4091b8f3b6b029d30cd917cf84d97421faadeeb/std/assembly/rt/stub.ts#L9
|
|
41
|
-
// @ts-expect-error We do not want to expose __alloc, hence why we just ignore the error
|
|
42
|
-
__alloc(0);
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import './eager_offset';
|
|
2
|
-
import { Bytes, Result } from './collections';
|
|
3
|
-
import { BigInt } from './numbers';
|
|
4
|
-
import { JSONValue } from './value';
|
|
5
|
-
|
|
6
|
-
/** Host JSON interface */
|
|
7
|
-
export declare namespace json {
|
|
8
|
-
function fromBytes(data: Bytes): JSONValue;
|
|
9
|
-
function try_fromBytes(data: Bytes): Result<JSONValue, boolean>;
|
|
10
|
-
function toI64(decimal: string): i64;
|
|
11
|
-
function toU64(decimal: string): u64;
|
|
12
|
-
function toF64(decimal: string): f64;
|
|
13
|
-
function toBigInt(decimal: string): BigInt;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export namespace json {
|
|
17
|
-
export function fromString(data: string): JSONValue {
|
|
18
|
-
const bytes = Bytes.fromUTF8(data);
|
|
19
|
-
|
|
20
|
-
return json.fromBytes(bytes);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function try_fromString(data: string): Result<JSONValue, boolean> {
|
|
24
|
-
const bytes = Bytes.fromUTF8(data);
|
|
25
|
-
|
|
26
|
-
return json.try_fromBytes(bytes);
|
|
27
|
-
}
|
|
28
|
-
}
|