datai-sdk 1.0.0
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/@graphprotocol/graph-ts/README.md +13 -0
- package/@graphprotocol/graph-ts/chain/arweave.ts +82 -0
- package/@graphprotocol/graph-ts/chain/cosmos.ts +426 -0
- package/@graphprotocol/graph-ts/chain/ethereum.ts +727 -0
- package/@graphprotocol/graph-ts/chain/near.ts +420 -0
- package/@graphprotocol/graph-ts/chain/starknet.ts +39 -0
- package/@graphprotocol/graph-ts/common/collections.ts +495 -0
- package/@graphprotocol/graph-ts/common/conversion.ts +3 -0
- package/@graphprotocol/graph-ts/common/datasource.ts +41 -0
- package/@graphprotocol/graph-ts/common/eager_offset.ts +42 -0
- package/@graphprotocol/graph-ts/common/json.ts +28 -0
- package/@graphprotocol/graph-ts/common/numbers.ts +407 -0
- package/@graphprotocol/graph-ts/common/value.ts +585 -0
- package/@graphprotocol/graph-ts/global/global.ts +4 -0
- package/@graphprotocol/graph-ts/helper-functions.ts +79 -0
- package/@graphprotocol/graph-ts/index.ts +156 -0
- package/@graphprotocol/graph-ts/package.json +3 -0
- package/@graphprotocol/graph-ts/tsconfig.json +4 -0
- package/@graphprotocol/graph-ts/types/tsconfig.base.json +3 -0
- package/API/index.ts +1 -0
- package/API/v1/activePositions/ActivePositionsResult.ts +147 -0
- package/API/v1/activePositions/TokenBalance.ts +25 -0
- package/API/v1/activePositions/activePositions.ts +37 -0
- package/API/v1/bigDecimal/BigDecimalPb.ts +40 -0
- package/API/v1/bigDecimal/bigDecimal.ts +75 -0
- package/API/v1/bigInt/bigInt.ts +123 -0
- package/API/v1/crypto/crypto.ts +16 -0
- package/API/v1/ethereum/SmartContractCallPb.ts +84 -0
- package/API/v1/ethereum/ValuePb.ts +113 -0
- package/API/v1/ethereum/ValuesPb.ts +39 -0
- package/API/v1/ethereum/ethereum.ts +76 -0
- package/API/v1/index.ts +10 -0
- package/API/v1/log/log.ts +18 -0
- package/API/v1/proto/activePositions/ActivePositionsResultPb.ts +139 -0
- package/API/v1/proto/activePositions/TokenBalancePb.ts +69 -0
- package/API/v1/proto/bigDecimal/BigDecimalPb.ts +56 -0
- package/API/v1/proto/ethereum/SmartContractCallPb.ts +102 -0
- package/API/v1/proto/ethereum/ValueKindPb.ts +17 -0
- package/API/v1/proto/ethereum/ValuePb.ts +96 -0
- package/API/v1/proto/ethereum/ValuesPb.ts +53 -0
- package/API/v1/proto/google/protobuf/Any.ts +56 -0
- package/API/v1/proto/google/protobuf/Timestamp.ts +56 -0
- package/API/v1/proto/store/EntitiesPb.ts +53 -0
- package/API/v1/proto/store/EntityPb.ts +99 -0
- package/API/v1/proto/store/EntityWithMetaPb.ts +75 -0
- package/API/v1/proto/store/ValueKindPb.ts +17 -0
- package/API/v1/proto/store/ValuePb.ts +132 -0
- package/API/v1/proto/store/ValuesPb.ts +53 -0
- package/API/v1/proto/watcher/WatcherResultPb.ts +62 -0
- package/API/v1/store/EntitiesPb.ts +39 -0
- package/API/v1/store/EntityPb.ts +75 -0
- package/API/v1/store/ValuePb.ts +154 -0
- package/API/v1/store/ValuesPb.ts +39 -0
- package/API/v1/store/store.ts +78 -0
- package/API/v1/typeConversion/typeConversion.ts +57 -0
- package/API/v1/watcher/WatcherInput.ts +9 -0
- package/API/v1/watcher/watcher.ts +33 -0
- package/index.ts +5 -0
- package/package.json +11 -0
- package/utils/constants.ts +16 -0
- package/utils/mathUtils.ts +77 -0
- package/utils/pdk.ts +171 -0
- package/utils/subgraphUtils.ts +27 -0
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
import './eager_offset';
|
|
2
|
+
import { ByteArray, Bytes } from './collections';
|
|
3
|
+
import { typeConversion } from './conversion';
|
|
4
|
+
import { bigInt, bigDecimal } from '../../../API'
|
|
5
|
+
|
|
6
|
+
export type Int8 = i64;
|
|
7
|
+
export type Timestamp = i64;
|
|
8
|
+
|
|
9
|
+
/** An Ethereum address (20 bytes). */
|
|
10
|
+
export class Address extends Bytes {
|
|
11
|
+
static fromString(s: string): Address {
|
|
12
|
+
return changetype<Address>(typeConversion.stringToH160(s));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Convert `Bytes` that must be exactly 20 bytes long to an address.
|
|
16
|
+
* Passing in a value with fewer or more bytes will result in an error */
|
|
17
|
+
static fromBytes(b: Bytes): Address {
|
|
18
|
+
if (b.length != 20) {
|
|
19
|
+
throw new Error(`Bytes of length ${b.length} can not be converted to 20 byte addresses`);
|
|
20
|
+
}
|
|
21
|
+
return changetype<Address>(b);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static zero(): Address {
|
|
25
|
+
const self = new ByteArray(20);
|
|
26
|
+
|
|
27
|
+
for (let i = 0; i < 20; i++) {
|
|
28
|
+
self[i] = 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return changetype<Address>(self);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** An arbitrary size integer represented as an array of bytes. */
|
|
36
|
+
export class BigInt extends Uint8Array {
|
|
37
|
+
static fromI32(x: i32): BigInt {
|
|
38
|
+
const byteArray = ByteArray.fromI32(x);
|
|
39
|
+
return BigInt.fromByteArray(byteArray);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static fromU32(x: u32): BigInt {
|
|
43
|
+
const byteArray = ByteArray.fromU32(x);
|
|
44
|
+
return BigInt.fromUnsignedBytes(byteArray);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static fromI64(x: i64): BigInt {
|
|
48
|
+
const byteArray = ByteArray.fromI64(x);
|
|
49
|
+
return BigInt.fromByteArray(byteArray);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static fromU64(x: u64): BigInt {
|
|
53
|
+
const byteArray = ByteArray.fromU64(x);
|
|
54
|
+
return BigInt.fromUnsignedBytes(byteArray);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static zero(): BigInt {
|
|
58
|
+
return BigInt.fromI32(0);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* `bytes` assumed to be little-endian. If your input is big-endian, call `.reverse()` first.
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
static fromSignedBytes(bytes: Bytes): BigInt {
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
67
|
+
const byteArray = <ByteArray>bytes;
|
|
68
|
+
return BigInt.fromByteArray(byteArray);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static fromByteArray(byteArray: ByteArray): BigInt {
|
|
72
|
+
return changetype<BigInt>(byteArray);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* `bytes` assumed to be little-endian. If your input is big-endian, call `.reverse()` first.
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
static fromUnsignedBytes(bytes: ByteArray): BigInt {
|
|
80
|
+
const signedBytes = new BigInt(bytes.length + 1);
|
|
81
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
82
|
+
signedBytes[i] = bytes[i];
|
|
83
|
+
}
|
|
84
|
+
signedBytes[bytes.length] = 0;
|
|
85
|
+
return signedBytes;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
toHex(): string {
|
|
89
|
+
return typeConversion.bigIntToHex(this);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
toHexString(): string {
|
|
93
|
+
return typeConversion.bigIntToHex(this);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
toString(): string {
|
|
97
|
+
return typeConversion.bigIntToString(this);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
static fromString(s: string): BigInt {
|
|
101
|
+
return bigInt.fromString(s);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
toI32(): i32 {
|
|
105
|
+
const uint8Array = changetype<Uint8Array>(this);
|
|
106
|
+
const byteArray = changetype<ByteArray>(uint8Array);
|
|
107
|
+
return byteArray.toI32();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
toU32(): u32 {
|
|
111
|
+
const uint8Array = changetype<Uint8Array>(this);
|
|
112
|
+
const byteArray = changetype<ByteArray>(uint8Array);
|
|
113
|
+
return byteArray.toU32();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
toI64(): i64 {
|
|
117
|
+
const uint8Array = changetype<Uint8Array>(this);
|
|
118
|
+
const byteArray = changetype<ByteArray>(uint8Array);
|
|
119
|
+
return byteArray.toI64();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
toU64(): u64 {
|
|
123
|
+
const uint8Array = changetype<Uint8Array>(this);
|
|
124
|
+
const byteArray = changetype<ByteArray>(uint8Array);
|
|
125
|
+
return byteArray.toU64();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
toBigDecimal(): BigDecimal {
|
|
129
|
+
return new BigDecimal(this);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
isZero(): boolean {
|
|
133
|
+
return this == BigInt.fromI32(0);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
isI32(): boolean {
|
|
137
|
+
return BigInt.fromI32(i32.MIN_VALUE) <= this && this <= BigInt.fromI32(i32.MAX_VALUE);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
abs(): BigInt {
|
|
141
|
+
return this < BigInt.fromI32(0) ? this.neg() : this;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
sqrt(): BigInt {
|
|
145
|
+
return bigInt.sqrt(this)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Operators
|
|
149
|
+
|
|
150
|
+
@operator('+')
|
|
151
|
+
plus(other: BigInt): BigInt {
|
|
152
|
+
return bigInt.plus(this, other);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
@operator('-')
|
|
156
|
+
minus(other: BigInt): BigInt {
|
|
157
|
+
return bigInt.minus(this, other);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
@operator('*')
|
|
161
|
+
times(other: BigInt): BigInt {
|
|
162
|
+
return bigInt.times(this, other);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
@operator('/')
|
|
166
|
+
div(other: BigInt): BigInt {
|
|
167
|
+
return bigInt.dividedBy(this, other);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
divDecimal(other: BigDecimal): BigDecimal {
|
|
171
|
+
return bigInt.dividedByDecimal(this, other);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
@operator('%')
|
|
175
|
+
mod(other: BigInt): BigInt {
|
|
176
|
+
return bigInt.mod(this, other);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
@operator('==')
|
|
180
|
+
equals(other: BigInt): boolean {
|
|
181
|
+
return BigInt.compare(this, other) == 0;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
@operator('!=')
|
|
185
|
+
notEqual(other: BigInt): boolean {
|
|
186
|
+
return !(this == other);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
@operator('<')
|
|
190
|
+
lt(other: BigInt): boolean {
|
|
191
|
+
return BigInt.compare(this, other) == -1;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
@operator('>')
|
|
195
|
+
gt(other: BigInt): boolean {
|
|
196
|
+
return BigInt.compare(this, other) == 1;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
@operator('<=')
|
|
200
|
+
le(other: BigInt): boolean {
|
|
201
|
+
return !(this > other);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
@operator('>=')
|
|
205
|
+
ge(other: BigInt): boolean {
|
|
206
|
+
return !(this < other);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
@operator.prefix('-')
|
|
210
|
+
neg(): BigInt {
|
|
211
|
+
return BigInt.fromI32(0).minus(this);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
@operator('|')
|
|
215
|
+
bitOr(other: BigInt): BigInt {
|
|
216
|
+
return bigInt.bitOr(this, other);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
@operator('&')
|
|
220
|
+
bitAnd(other: BigInt): BigInt {
|
|
221
|
+
return bigInt.bitAnd(this, other);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
@operator('<<')
|
|
225
|
+
leftShift(bits: u8): BigInt {
|
|
226
|
+
return bigInt.leftShift(this, bits);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
@operator('>>')
|
|
230
|
+
rightShift(bits: u8): BigInt {
|
|
231
|
+
return bigInt.rightShift(this, bits);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/// Limited to a low exponent to discourage creating a huge BigInt.
|
|
235
|
+
pow(exp: u8): BigInt {
|
|
236
|
+
return bigInt.pow(this, exp);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Returns −1 if a < b, 1 if a > b, and 0 if A == B
|
|
241
|
+
*/
|
|
242
|
+
static compare(a: BigInt, b: BigInt): i32 {
|
|
243
|
+
// Check if a and b have the same sign.
|
|
244
|
+
const aIsNeg = a.length > 0 && a[a.length - 1] >> 7 == 1;
|
|
245
|
+
const bIsNeg = b.length > 0 && b[b.length - 1] >> 7 == 1;
|
|
246
|
+
|
|
247
|
+
if (!aIsNeg && bIsNeg) {
|
|
248
|
+
return 1;
|
|
249
|
+
}
|
|
250
|
+
if (aIsNeg && !bIsNeg) {
|
|
251
|
+
return -1;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Check how many bytes of a and b are relevant to the magnitude.
|
|
255
|
+
let aRelevantBytes = a.length;
|
|
256
|
+
while (
|
|
257
|
+
aRelevantBytes > 0 &&
|
|
258
|
+
((!aIsNeg && a[aRelevantBytes - 1] == 0) || (aIsNeg && a[aRelevantBytes - 1] == 255))
|
|
259
|
+
) {
|
|
260
|
+
aRelevantBytes -= 1;
|
|
261
|
+
}
|
|
262
|
+
let bRelevantBytes = b.length;
|
|
263
|
+
while (
|
|
264
|
+
bRelevantBytes > 0 &&
|
|
265
|
+
((!bIsNeg && b[bRelevantBytes - 1] == 0) || (bIsNeg && b[bRelevantBytes - 1] == 255))
|
|
266
|
+
) {
|
|
267
|
+
bRelevantBytes -= 1;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// If a and b are positive then the one with more relevant bytes is larger.
|
|
271
|
+
// Otherwise the one with less relevant bytes is larger.
|
|
272
|
+
if (aRelevantBytes > bRelevantBytes) {
|
|
273
|
+
return aIsNeg ? -1 : 1;
|
|
274
|
+
}
|
|
275
|
+
if (bRelevantBytes > aRelevantBytes) {
|
|
276
|
+
return aIsNeg ? 1 : -1;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// We now know that a and b have the same sign and number of relevant bytes.
|
|
280
|
+
// If a and b are both negative then the one of lesser magnitude is the
|
|
281
|
+
// largest, however since in two's complement the magnitude is flipped, we
|
|
282
|
+
// may use the same logic as if a and b are positive.
|
|
283
|
+
const relevantBytes = aRelevantBytes;
|
|
284
|
+
for (let i = 1; i <= relevantBytes; i++) {
|
|
285
|
+
if (a[relevantBytes - i] < b[relevantBytes - i]) {
|
|
286
|
+
return -1;
|
|
287
|
+
}
|
|
288
|
+
if (a[relevantBytes - i] > b[relevantBytes - i]) {
|
|
289
|
+
return 1;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return 0;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export class BigDecimal {
|
|
298
|
+
digits: BigInt;
|
|
299
|
+
exp: BigInt;
|
|
300
|
+
|
|
301
|
+
constructor(bigInt: BigInt) {
|
|
302
|
+
this.digits = bigInt;
|
|
303
|
+
this.exp = BigInt.fromI32(0);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
static fromString(s: string): BigDecimal {
|
|
307
|
+
return bigDecimal.fromString(s);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
static zero(): BigDecimal {
|
|
311
|
+
return new BigDecimal(BigInt.zero());
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
toString(): string {
|
|
315
|
+
return bigDecimal.toString(this);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
truncate(decimals: i32): BigDecimal {
|
|
319
|
+
const digitsRightOfZero = this.digits.toString().length + this.exp.toI32();
|
|
320
|
+
const newDigitLength = decimals + digitsRightOfZero;
|
|
321
|
+
const truncateLength = this.digits.toString().length - newDigitLength;
|
|
322
|
+
if (truncateLength < 0) {
|
|
323
|
+
return this;
|
|
324
|
+
}
|
|
325
|
+
for (let i = 0; i < truncateLength; i++) {
|
|
326
|
+
this.digits = this.digits.div(BigInt.fromI32(10));
|
|
327
|
+
}
|
|
328
|
+
this.exp = BigInt.fromI32(decimals * -1);
|
|
329
|
+
return this;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
@operator('+')
|
|
333
|
+
plus(other: BigDecimal): BigDecimal {
|
|
334
|
+
return bigDecimal.plus(this, other);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
@operator('-')
|
|
338
|
+
minus(other: BigDecimal): BigDecimal {
|
|
339
|
+
return bigDecimal.minus(this, other);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
@operator('*')
|
|
343
|
+
times(other: BigDecimal): BigDecimal {
|
|
344
|
+
return bigDecimal.times(this, other);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
@operator('/')
|
|
348
|
+
div(other: BigDecimal): BigDecimal {
|
|
349
|
+
return bigDecimal.dividedBy(this, other);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
@operator('==')
|
|
353
|
+
equals(other: BigDecimal): boolean {
|
|
354
|
+
return BigDecimal.compare(this, other) == 0;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
@operator('!=')
|
|
358
|
+
notEqual(other: BigDecimal): boolean {
|
|
359
|
+
return !(this == other);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
@operator('<')
|
|
363
|
+
lt(other: BigDecimal): boolean {
|
|
364
|
+
return BigDecimal.compare(this, other) == -1;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
@operator('>')
|
|
368
|
+
gt(other: BigDecimal): boolean {
|
|
369
|
+
return BigDecimal.compare(this, other) == 1;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
@operator('<=')
|
|
373
|
+
le(other: BigDecimal): boolean {
|
|
374
|
+
return !(this > other);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
@operator('>=')
|
|
378
|
+
ge(other: BigDecimal): boolean {
|
|
379
|
+
return !(this < other);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
@operator.prefix('-')
|
|
383
|
+
neg(): BigDecimal {
|
|
384
|
+
return new BigDecimal(new BigInt(0)).minus(this);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Returns −1 if a < b, 1 if a > b, and 0 if A == B
|
|
389
|
+
*/
|
|
390
|
+
static compare(a: BigDecimal, b: BigDecimal): i32 {
|
|
391
|
+
const diff = a.minus(b);
|
|
392
|
+
if (diff.digits.isZero()) {
|
|
393
|
+
return 0;
|
|
394
|
+
}
|
|
395
|
+
return diff.digits > BigInt.fromI32(0) ? 1 : -1;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/** A type representing Starknet's field element type. */
|
|
400
|
+
export class Felt extends Bytes {
|
|
401
|
+
/**
|
|
402
|
+
* Modifies and transforms the object IN-PLACE into `BigInt`.
|
|
403
|
+
*/
|
|
404
|
+
intoBigInt(): BigInt {
|
|
405
|
+
return BigInt.fromUnsignedBytes(changetype<ByteArray>(this.reverse()));
|
|
406
|
+
}
|
|
407
|
+
}
|