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.
Files changed (63) hide show
  1. package/@graphprotocol/graph-ts/README.md +13 -0
  2. package/@graphprotocol/graph-ts/chain/arweave.ts +82 -0
  3. package/@graphprotocol/graph-ts/chain/cosmos.ts +426 -0
  4. package/@graphprotocol/graph-ts/chain/ethereum.ts +727 -0
  5. package/@graphprotocol/graph-ts/chain/near.ts +420 -0
  6. package/@graphprotocol/graph-ts/chain/starknet.ts +39 -0
  7. package/@graphprotocol/graph-ts/common/collections.ts +495 -0
  8. package/@graphprotocol/graph-ts/common/conversion.ts +3 -0
  9. package/@graphprotocol/graph-ts/common/datasource.ts +41 -0
  10. package/@graphprotocol/graph-ts/common/eager_offset.ts +42 -0
  11. package/@graphprotocol/graph-ts/common/json.ts +28 -0
  12. package/@graphprotocol/graph-ts/common/numbers.ts +407 -0
  13. package/@graphprotocol/graph-ts/common/value.ts +585 -0
  14. package/@graphprotocol/graph-ts/global/global.ts +4 -0
  15. package/@graphprotocol/graph-ts/helper-functions.ts +79 -0
  16. package/@graphprotocol/graph-ts/index.ts +156 -0
  17. package/@graphprotocol/graph-ts/package.json +3 -0
  18. package/@graphprotocol/graph-ts/tsconfig.json +4 -0
  19. package/@graphprotocol/graph-ts/types/tsconfig.base.json +3 -0
  20. package/API/index.ts +1 -0
  21. package/API/v1/activePositions/ActivePositionsResult.ts +147 -0
  22. package/API/v1/activePositions/TokenBalance.ts +25 -0
  23. package/API/v1/activePositions/activePositions.ts +37 -0
  24. package/API/v1/bigDecimal/BigDecimalPb.ts +40 -0
  25. package/API/v1/bigDecimal/bigDecimal.ts +75 -0
  26. package/API/v1/bigInt/bigInt.ts +123 -0
  27. package/API/v1/crypto/crypto.ts +16 -0
  28. package/API/v1/ethereum/SmartContractCallPb.ts +84 -0
  29. package/API/v1/ethereum/ValuePb.ts +113 -0
  30. package/API/v1/ethereum/ValuesPb.ts +39 -0
  31. package/API/v1/ethereum/ethereum.ts +76 -0
  32. package/API/v1/index.ts +10 -0
  33. package/API/v1/log/log.ts +18 -0
  34. package/API/v1/proto/activePositions/ActivePositionsResultPb.ts +139 -0
  35. package/API/v1/proto/activePositions/TokenBalancePb.ts +69 -0
  36. package/API/v1/proto/bigDecimal/BigDecimalPb.ts +56 -0
  37. package/API/v1/proto/ethereum/SmartContractCallPb.ts +102 -0
  38. package/API/v1/proto/ethereum/ValueKindPb.ts +17 -0
  39. package/API/v1/proto/ethereum/ValuePb.ts +96 -0
  40. package/API/v1/proto/ethereum/ValuesPb.ts +53 -0
  41. package/API/v1/proto/google/protobuf/Any.ts +56 -0
  42. package/API/v1/proto/google/protobuf/Timestamp.ts +56 -0
  43. package/API/v1/proto/store/EntitiesPb.ts +53 -0
  44. package/API/v1/proto/store/EntityPb.ts +99 -0
  45. package/API/v1/proto/store/EntityWithMetaPb.ts +75 -0
  46. package/API/v1/proto/store/ValueKindPb.ts +17 -0
  47. package/API/v1/proto/store/ValuePb.ts +132 -0
  48. package/API/v1/proto/store/ValuesPb.ts +53 -0
  49. package/API/v1/proto/watcher/WatcherResultPb.ts +62 -0
  50. package/API/v1/store/EntitiesPb.ts +39 -0
  51. package/API/v1/store/EntityPb.ts +75 -0
  52. package/API/v1/store/ValuePb.ts +154 -0
  53. package/API/v1/store/ValuesPb.ts +39 -0
  54. package/API/v1/store/store.ts +78 -0
  55. package/API/v1/typeConversion/typeConversion.ts +57 -0
  56. package/API/v1/watcher/WatcherInput.ts +9 -0
  57. package/API/v1/watcher/watcher.ts +33 -0
  58. package/index.ts +5 -0
  59. package/package.json +11 -0
  60. package/utils/constants.ts +16 -0
  61. package/utils/mathUtils.ts +77 -0
  62. package/utils/pdk.ts +171 -0
  63. package/utils/subgraphUtils.ts +27 -0
@@ -0,0 +1,132 @@
1
+ // Code generated by protoc-gen-as. DO NOT EDIT.
2
+ // Versions:
3
+ // protoc-gen-as v1.3.0
4
+ // protoc v3.21.12
5
+
6
+ import { Writer, Reader, Protobuf } from 'as-proto/assembly'
7
+ import { BigDecimalPb } from '../bigDecimal/BigDecimalPb'
8
+ import { ValuesPb } from './ValuesPb'
9
+ import { ValueKindPb } from './ValueKindPb'
10
+
11
+ export class ValuePb {
12
+ static encode(message: ValuePb, writer: Writer): void {
13
+ writer.uint32(8)
14
+ writer.int32(message.kind)
15
+
16
+ writer.uint32(802)
17
+ writer.string(message.stringData)
18
+
19
+ writer.uint32(808)
20
+ writer.int32(message.intData)
21
+
22
+ const bigdecimalData = message.bigdecimalData
23
+ if (bigdecimalData !== null) {
24
+ writer.uint32(818)
25
+ writer.fork()
26
+ BigDecimalPb.encode(bigdecimalData, writer)
27
+ writer.ldelim()
28
+ }
29
+
30
+ writer.uint32(824)
31
+ writer.bool(message.boolData)
32
+
33
+ const arrayData = message.arrayData
34
+ if (arrayData !== null) {
35
+ writer.uint32(834)
36
+ writer.fork()
37
+ ValuesPb.encode(arrayData, writer)
38
+ writer.ldelim()
39
+ }
40
+
41
+ writer.uint32(850)
42
+ writer.bytes(message.bytesData)
43
+
44
+ writer.uint32(864)
45
+ writer.int64(message.int8Data)
46
+ }
47
+
48
+ static decode(reader: Reader, length: i32): ValuePb {
49
+ const end: usize = length < 0 ? reader.end : reader.ptr + length
50
+ const message = new ValuePb()
51
+
52
+ while (reader.ptr < end) {
53
+ const tag = reader.uint32()
54
+ switch (tag >>> 3) {
55
+ case 1:
56
+ message.kind = reader.int32()
57
+ break
58
+
59
+ case 100:
60
+ message.stringData = reader.string()
61
+ break
62
+
63
+ case 101:
64
+ message.intData = reader.int32()
65
+ break
66
+
67
+ case 102:
68
+ message.bigdecimalData = BigDecimalPb.decode(reader, reader.uint32())
69
+ break
70
+
71
+ case 103:
72
+ message.boolData = reader.bool()
73
+ break
74
+
75
+ case 104:
76
+ message.arrayData = ValuesPb.decode(reader, reader.uint32())
77
+ break
78
+
79
+ case 106:
80
+ message.bytesData = reader.bytes()
81
+ break
82
+
83
+ case 108:
84
+ message.int8Data = reader.int64()
85
+ break
86
+
87
+ default:
88
+ reader.skipType(tag & 7)
89
+ break
90
+ }
91
+ }
92
+
93
+ return message
94
+ }
95
+
96
+ kind: ValueKindPb
97
+ stringData: string
98
+ intData: i32
99
+ bigdecimalData: BigDecimalPb | null
100
+ boolData: bool
101
+ arrayData: ValuesPb | null
102
+ bytesData: Uint8Array
103
+ int8Data: i64
104
+
105
+ constructor(
106
+ kind: ValueKindPb = 0,
107
+ stringData: string = '',
108
+ intData: i32 = 0,
109
+ bigdecimalData: BigDecimalPb | null = null,
110
+ boolData: bool = false,
111
+ arrayData: ValuesPb | null = null,
112
+ bytesData: Uint8Array = new Uint8Array(0),
113
+ int8Data: i64 = 0
114
+ ) {
115
+ this.kind = kind
116
+ this.stringData = stringData
117
+ this.intData = intData
118
+ this.bigdecimalData = bigdecimalData
119
+ this.boolData = boolData
120
+ this.arrayData = arrayData
121
+ this.bytesData = bytesData
122
+ this.int8Data = int8Data
123
+ }
124
+ }
125
+
126
+ export function encodeValuePb(message: ValuePb): Uint8Array {
127
+ return Protobuf.encode(message, ValuePb.encode)
128
+ }
129
+
130
+ export function decodeValuePb(buffer: Uint8Array): ValuePb {
131
+ return Protobuf.decode<ValuePb>(buffer, ValuePb.decode)
132
+ }
@@ -0,0 +1,53 @@
1
+ // Code generated by protoc-gen-as. DO NOT EDIT.
2
+ // Versions:
3
+ // protoc-gen-as v1.3.0
4
+ // protoc v3.21.12
5
+
6
+ import { Writer, Reader, Protobuf } from 'as-proto/assembly'
7
+ import { ValuePb } from './ValuePb'
8
+
9
+ export class ValuesPb {
10
+ static encode(message: ValuesPb, writer: Writer): void {
11
+ const values = message.values
12
+ for (let i: i32 = 0; i < values.length; ++i) {
13
+ writer.uint32(10)
14
+ writer.fork()
15
+ ValuePb.encode(values[i], writer)
16
+ writer.ldelim()
17
+ }
18
+ }
19
+
20
+ static decode(reader: Reader, length: i32): ValuesPb {
21
+ const end: usize = length < 0 ? reader.end : reader.ptr + length
22
+ const message = new ValuesPb()
23
+
24
+ while (reader.ptr < end) {
25
+ const tag = reader.uint32()
26
+ switch (tag >>> 3) {
27
+ case 1:
28
+ message.values.push(ValuePb.decode(reader, reader.uint32()))
29
+ break
30
+
31
+ default:
32
+ reader.skipType(tag & 7)
33
+ break
34
+ }
35
+ }
36
+
37
+ return message
38
+ }
39
+
40
+ values: Array<ValuePb>
41
+
42
+ constructor(values: Array<ValuePb> = []) {
43
+ this.values = values
44
+ }
45
+ }
46
+
47
+ export function encodeValuesPb(message: ValuesPb): Uint8Array {
48
+ return Protobuf.encode(message, ValuesPb.encode)
49
+ }
50
+
51
+ export function decodeValuesPb(buffer: Uint8Array): ValuesPb {
52
+ return Protobuf.decode<ValuesPb>(buffer, ValuesPb.decode)
53
+ }
@@ -0,0 +1,62 @@
1
+ // Code generated by protoc-gen-as. DO NOT EDIT.
2
+ // Versions:
3
+ // protoc-gen-as v1.3.0
4
+ // protoc v3.21.12
5
+
6
+ import { Writer, Reader, Protobuf } from 'as-proto/assembly'
7
+ import { Any } from '../google/protobuf/Any'
8
+
9
+ export class WatcherResultPb {
10
+ static encode(message: WatcherResultPb, writer: Writer): void {
11
+ writer.uint32(10)
12
+ writer.string(message.updateTrigger)
13
+
14
+ const payload = message.payload
15
+ if (payload !== null) {
16
+ writer.uint32(18)
17
+ writer.fork()
18
+ Any.encode(payload, writer)
19
+ writer.ldelim()
20
+ }
21
+ }
22
+
23
+ static decode(reader: Reader, length: i32): WatcherResultPb {
24
+ const end: usize = length < 0 ? reader.end : reader.ptr + length
25
+ const message = new WatcherResultPb()
26
+
27
+ while (reader.ptr < end) {
28
+ const tag = reader.uint32()
29
+ switch (tag >>> 3) {
30
+ case 1:
31
+ message.updateTrigger = reader.string()
32
+ break
33
+
34
+ case 2:
35
+ message.payload = Any.decode(reader, reader.uint32())
36
+ break
37
+
38
+ default:
39
+ reader.skipType(tag & 7)
40
+ break
41
+ }
42
+ }
43
+
44
+ return message
45
+ }
46
+
47
+ updateTrigger: string
48
+ payload: Any | null
49
+
50
+ constructor(updateTrigger: string = '', payload: Any | null = null) {
51
+ this.updateTrigger = updateTrigger
52
+ this.payload = payload
53
+ }
54
+ }
55
+
56
+ export function encodeWatcherResultPb(message: WatcherResultPb): Uint8Array {
57
+ return Protobuf.encode(message, WatcherResultPb.encode)
58
+ }
59
+
60
+ export function decodeWatcherResultPb(buffer: Uint8Array): WatcherResultPb {
61
+ return Protobuf.decode<WatcherResultPb>(buffer, WatcherResultPb.decode)
62
+ }
@@ -0,0 +1,39 @@
1
+ // Code is NOT generated
2
+ // but the generated code from proto folder was used as reference
3
+ // it is done this way to directly encode/decode into graph-ts types
4
+
5
+ import { Writer, Reader } from 'as-proto/assembly'
6
+ import { EntityPb } from './EntityPb'
7
+ import { Entity } from '@graphprotocol/graph-ts/'
8
+
9
+ export namespace EntitiesPb {
10
+ export function encode(message: Array<Entity>, writer: Writer): void {
11
+ const items = message
12
+ for (let i: i32 = 0; i < items.length; ++i) {
13
+ writer.uint32(10)
14
+ writer.fork()
15
+ EntityPb.encode(items[i], writer)
16
+ writer.ldelim()
17
+ }
18
+ }
19
+
20
+ export function decode(reader: Reader, length: i32): Array<Entity> {
21
+ const end: usize = length < 0 ? reader.end : reader.ptr + length
22
+ const message = new Array<Entity>()
23
+
24
+ while (reader.ptr < end) {
25
+ const tag = reader.uint32()
26
+ switch (tag >>> 3) {
27
+ case 1:
28
+ message.push(EntityPb.decode(reader, reader.uint32()))
29
+ break
30
+
31
+ default:
32
+ reader.skipType(tag & 7)
33
+ break
34
+ }
35
+ }
36
+
37
+ return message
38
+ }
39
+ }
@@ -0,0 +1,75 @@
1
+ // Code is NOT generated
2
+ // but the generated code from proto folder was used as reference
3
+ // it is done this way to directly encode/decode into graph-ts types
4
+
5
+ import { Writer, Reader } from 'as-proto/assembly'
6
+ import { ValuePb } from './ValuePb'
7
+ import { Value, Entity } from '@graphprotocol/graph-ts/'
8
+
9
+ export namespace EntityPb {
10
+ export function encode(message: Entity, writer: Writer): void {
11
+ const entries = message.entries
12
+ if (entries !== null) {
13
+ for (let i: i32 = 0; i < entries.length; ++i) {
14
+ writer.uint32(10)
15
+ writer.fork()
16
+ writer.uint32(10)
17
+ writer.string(entries[i].key)
18
+ writer.uint32(18)
19
+ writer.fork()
20
+ ValuePb.encode(entries[i].value, writer)
21
+ writer.ldelim()
22
+ writer.ldelim()
23
+ }
24
+ }
25
+ }
26
+
27
+ export function decode(reader: Reader, length: i32): Entity {
28
+ const end: usize = length < 0 ? reader.end : reader.ptr + length
29
+ const message = new Entity()
30
+
31
+ while (reader.ptr < end) {
32
+ const tag = reader.uint32()
33
+ switch (tag >>> 3) {
34
+ case 1:
35
+ let entriesKey: string = ''
36
+ let entriesValue: Value | null = null
37
+ let entriesHasKey: bool = false
38
+ let entriesHasValue: bool = false
39
+ for (
40
+ const end: usize = reader.ptr + reader.uint32();
41
+ reader.ptr < end;
42
+
43
+ ) {
44
+ const tag = reader.uint32()
45
+ switch (tag >>> 3) {
46
+ case 1:
47
+ entriesKey = reader.string()
48
+ entriesHasKey = true
49
+ break
50
+
51
+ case 2:
52
+ entriesValue = ValuePb.decode(reader, reader.uint32())
53
+ entriesHasValue = true
54
+ break
55
+
56
+ default:
57
+ reader.skipType(tag & 7)
58
+ break
59
+ }
60
+
61
+ if (entriesHasKey && entriesHasValue && entriesValue !== null) {
62
+ message.set(entriesKey, entriesValue)
63
+ }
64
+ }
65
+ break
66
+
67
+ default:
68
+ reader.skipType(tag & 7)
69
+ break
70
+ }
71
+ }
72
+
73
+ return message
74
+ }
75
+ }
@@ -0,0 +1,154 @@
1
+ // Code is NOT generated
2
+ // but the generated code from proto folder was used as reference
3
+ // it is done this way to directly encode/decode into graph-ts types
4
+
5
+ import { Writer, Reader } from 'as-proto/assembly'
6
+ import { BigDecimalPb } from '../bigDecimal/BigDecimalPb'
7
+ import { ValuesPb } from './ValuesPb'
8
+ import {
9
+ Value,
10
+ Bytes,
11
+ BigInt,
12
+ ValueKind,
13
+ BigDecimal,
14
+ ByteArray
15
+ } from '@graphprotocol/graph-ts/'
16
+
17
+ export namespace ValuePb {
18
+ export function encode(message: Value, writer: Writer): void {
19
+ writer.uint32(8)
20
+ writer.int32(message.kind)
21
+
22
+ switch (message.kind) {
23
+ case ValueKind.STRING:
24
+ writer.uint32(802)
25
+ writer.string(message.toString())
26
+ break
27
+
28
+ case ValueKind.INT:
29
+ writer.uint32(808)
30
+ writer.int32(message.toI32())
31
+ break
32
+
33
+ case ValueKind.BIGDECIMAL:
34
+ const bigdecimalData = message.toBigDecimal()
35
+ writer.uint32(818)
36
+ writer.fork()
37
+ BigDecimalPb.encode(bigdecimalData, writer)
38
+ writer.ldelim()
39
+ break
40
+
41
+ case ValueKind.BOOL:
42
+ writer.uint32(824)
43
+ writer.bool(message.toBoolean())
44
+ break
45
+
46
+ case ValueKind.ARRAY:
47
+ const arrayData = message.toArray()
48
+ if (arrayData !== null) {
49
+ writer.uint32(834)
50
+ writer.fork()
51
+ ValuesPb.encode(arrayData, writer)
52
+ writer.ldelim()
53
+ }
54
+ break
55
+
56
+ case ValueKind.NULL:
57
+ // write nothing
58
+ break
59
+
60
+ case ValueKind.BYTES:
61
+ case ValueKind.BIGINT:
62
+ writer.uint32(850)
63
+ writer.bytes(changetype<Bytes>(message.data as u32))
64
+ break
65
+
66
+ case ValueKind.INT8:
67
+ case ValueKind.TIMESTAMP:
68
+ writer.uint32(864)
69
+ writer.int64(message.data as i64)
70
+ break
71
+
72
+ default:
73
+ throw new Error('Encoding unsupported common value kind')
74
+ }
75
+ }
76
+
77
+ export function decode(reader: Reader, length: i32): Value {
78
+ const end: usize = length < 0 ? reader.end : reader.ptr + length
79
+ let kind: ValueKind = 0
80
+ let stringData: string = ''
81
+ let intData: i32 = 0
82
+ let bigdecimalData: BigDecimal | null = null
83
+ let boolData: bool = false
84
+ let arrayData: Value[] | null = null
85
+ let bytesData: Uint8Array = new Uint8Array(0)
86
+ let int8Data: i64 = 0
87
+
88
+ while (reader.ptr < end) {
89
+ const tag = reader.uint32()
90
+ switch (tag >>> 3) {
91
+ case 1:
92
+ kind = reader.int32()
93
+ break
94
+
95
+ case 100:
96
+ stringData = reader.string()
97
+ break
98
+
99
+ case 101:
100
+ intData = reader.int32()
101
+ break
102
+
103
+ case 102:
104
+ bigdecimalData = BigDecimalPb.decode(reader, reader.uint32())
105
+ break
106
+
107
+ case 103:
108
+ boolData = reader.bool()
109
+ break
110
+
111
+ case 104:
112
+ arrayData = ValuesPb.decode(reader, reader.uint32())
113
+ break
114
+
115
+ case 106:
116
+ bytesData = reader.bytes()
117
+ break
118
+
119
+ case 108:
120
+ int8Data = reader.int64()
121
+ break
122
+
123
+ default:
124
+ reader.skipType(tag & 7)
125
+ break
126
+ }
127
+ }
128
+
129
+ switch (kind) {
130
+ case ValueKind.STRING:
131
+ return Value.fromString(stringData)
132
+ case ValueKind.INT:
133
+ return Value.fromI32(intData)
134
+ case ValueKind.BIGDECIMAL:
135
+ return Value.fromBigDecimal(bigdecimalData!)
136
+ case ValueKind.BOOL:
137
+ return Value.fromBoolean(boolData)
138
+ case ValueKind.ARRAY:
139
+ return Value.fromArray(arrayData!)
140
+ case ValueKind.NULL:
141
+ return Value.fromNull()
142
+ case ValueKind.BYTES:
143
+ return Value.fromBytes(changetype<Bytes>(bytesData))
144
+ case ValueKind.BIGINT:
145
+ return Value.fromBigInt(changetype<BigInt>(bytesData))
146
+ case ValueKind.INT8:
147
+ return Value.fromI64(int8Data)
148
+ case ValueKind.TIMESTAMP:
149
+ return Value.fromTimestamp(int8Data)
150
+ default:
151
+ throw new Error(`Unsupported kind ${kind}`)
152
+ }
153
+ }
154
+ }
@@ -0,0 +1,39 @@
1
+ // Code is NOT generated
2
+ // but the generated code from proto folder was used as reference
3
+ // it is done this way to directly encode/decode into graph-ts types
4
+
5
+ import { Writer, Reader } from 'as-proto/assembly'
6
+ import { ValuePb } from './ValuePb'
7
+ import { Value } from '@graphprotocol/graph-ts/'
8
+
9
+ export namespace ValuesPb {
10
+ export function encode(message: Array<Value>, writer: Writer): void {
11
+ const values = message
12
+ for (let i: i32 = 0; i < values.length; ++i) {
13
+ writer.uint32(10)
14
+ writer.fork()
15
+ ValuePb.encode(values[i], writer)
16
+ writer.ldelim()
17
+ }
18
+ }
19
+
20
+ export function decode(reader: Reader, length: i32): Array<Value> {
21
+ const end: usize = length < 0 ? reader.end : reader.ptr + length
22
+ const message = new Array<Value>()
23
+
24
+ while (reader.ptr < end) {
25
+ const tag = reader.uint32()
26
+ switch (tag >>> 3) {
27
+ case 1:
28
+ message.push(ValuePb.decode(reader, reader.uint32()))
29
+ break
30
+
31
+ default:
32
+ reader.skipType(tag & 7)
33
+ break
34
+ }
35
+ }
36
+
37
+ return message
38
+ }
39
+ }
@@ -0,0 +1,78 @@
1
+ import { EntityPb } from './EntityPb'
2
+ import { EntitiesPb } from './EntitiesPb'
3
+ import { Entity } from '@graphprotocol/graph-ts/'
4
+ import {
5
+ findProtobuOrNull,
6
+ storeString,
7
+ storeProtobuf
8
+ } from '../../../utils/pdk'
9
+
10
+ /**
11
+ * Host store interface.
12
+ */
13
+ export declare namespace store {
14
+ function hostGet(entity: u64, id: u64): u64
15
+ function hostGet_in_block(entity: u64, id: u64): u64
16
+ function hostLoadRelated(entity: u64, id: u64, field: u64): u64
17
+ function hostSet(entity: u64, id: u64, data: u64): void
18
+ function hostRemove(entity: u64, id: u64): void
19
+ }
20
+
21
+ export namespace store {
22
+ export function get(entity: string, id: string): Entity | null {
23
+ const entityMem = storeString(entity)
24
+ const idMem = storeString(id)
25
+ const resultOffset = store.hostGet(entityMem.offset, idMem.offset)
26
+ entityMem.free()
27
+ idMem.free()
28
+ return findProtobuOrNull<Entity>(resultOffset, EntityPb.decode)
29
+ }
30
+
31
+ export function get_in_block(entity: string, id: string): Entity | null {
32
+ const entityMem = storeString(entity)
33
+ const idMem = storeString(id)
34
+ const resultOffset = store.hostGet_in_block(entityMem.offset, idMem.offset)
35
+ entityMem.free()
36
+ idMem.free()
37
+ return findProtobuOrNull<Entity>(resultOffset, EntityPb.decode)
38
+ }
39
+
40
+ export function loadRelated(
41
+ entity: string,
42
+ id: string,
43
+ field: string
44
+ ): Array<Entity> {
45
+ const entityMem = storeString(entity)
46
+ const idMem = storeString(id)
47
+ const fieldMem = storeString(field)
48
+
49
+ const resultOffset = store.hostLoadRelated(
50
+ entityMem.offset,
51
+ idMem.offset,
52
+ fieldMem.offset
53
+ )
54
+
55
+ entityMem.free()
56
+ idMem.free()
57
+ fieldMem.free()
58
+ return findProtobuOrNull(resultOffset, EntitiesPb.decode) || []
59
+ }
60
+
61
+ export function set(entity: string, id: string, data: Entity): void {
62
+ const entityMem = storeString(entity)
63
+ const idMem = storeString(id)
64
+ const dataMem = storeProtobuf(data, EntityPb.encode)
65
+ store.hostSet(entityMem.offset, idMem.offset, dataMem.offset)
66
+ entityMem.free()
67
+ idMem.free()
68
+ dataMem.free()
69
+ }
70
+
71
+ export function remove(entity: string, id: string): void {
72
+ const entityMem = storeString(entity)
73
+ const idMem = storeString(id)
74
+ store.hostRemove(entityMem.offset, idMem.offset)
75
+ entityMem.free()
76
+ idMem.free()
77
+ }
78
+ }
@@ -0,0 +1,57 @@
1
+ import { Bytes } from '@graphprotocol/graph-ts/'
2
+ import {
3
+ findUint8Array,
4
+ findString,
5
+ storeString,
6
+ storeUint8Array,
7
+ findStringOrNull
8
+ } from '../../../utils/pdk'
9
+
10
+ /** Host type conversion interface */
11
+ export declare namespace typeConversion {
12
+ function hostBytesToString(bytes: u64): u64
13
+ function hostBytesToHex(bytes: u64): u64
14
+ function hostBigIntToString(bigInt: u64): u64
15
+ function hostBigIntToHex(bigInt: u64): u64
16
+ function hostStringToH160(s: u64): u64
17
+ function hostBytesToBase58(n: u64): u64
18
+ }
19
+
20
+ export namespace typeConversion {
21
+ export function bytesToString(bytes: Uint8Array): string {
22
+ const bytesMem = storeUint8Array(bytes)
23
+ const resultOffset = typeConversion.hostBytesToString(bytesMem.offset)
24
+ bytesMem.free()
25
+ return findStringOrNull(resultOffset) || ''
26
+ }
27
+ export function bytesToHex(bytes: Uint8Array): string {
28
+ const bytesMem = storeUint8Array(bytes)
29
+ const resultOffset = typeConversion.hostBytesToHex(bytesMem.offset)
30
+ bytesMem.free()
31
+ return findString(resultOffset)
32
+ }
33
+ export function bigIntToString(bigInt: Uint8Array): string {
34
+ const bigIntMem = storeUint8Array(bigInt)
35
+ const resultOffset = typeConversion.hostBigIntToString(bigIntMem.offset)
36
+ bigIntMem.free()
37
+ return findString(resultOffset)
38
+ }
39
+ export function bigIntToHex(bigInt: Uint8Array): string {
40
+ const bigIntMem = storeUint8Array(bigInt)
41
+ const resultOffset = typeConversion.hostBigIntToHex(bigIntMem.offset)
42
+ bigIntMem.free()
43
+ return findString(resultOffset)
44
+ }
45
+ export function stringToH160(s: string): Bytes {
46
+ const sMem = storeString(s)
47
+ const resultOffset = typeConversion.hostStringToH160(sMem.offset)
48
+ sMem.free()
49
+ return changetype<Bytes>(findUint8Array(resultOffset))
50
+ }
51
+ export function bytesToBase58(n: Uint8Array): string {
52
+ const nMem = storeUint8Array(n)
53
+ const resultOffset = typeConversion.hostBytesToBase58(nMem.offset)
54
+ nMem.free()
55
+ return findStringOrNull(resultOffset) || ''
56
+ }
57
+ }
@@ -0,0 +1,9 @@
1
+ import { Entity } from '../../../@graphprotocol/graph-ts'
2
+
3
+ export class WatcherInput {
4
+ position: Entity
5
+
6
+ constructor(position: Entity) {
7
+ this.position = position
8
+ }
9
+ }