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
@@ -0,0 +1,71 @@
1
+ // Code generated by protoc-gen-as. DO NOT EDIT.
2
+ // Versions:
3
+ // protoc-gen-as v1.3.0
4
+ // protoc v6.33.4
5
+
6
+ import { Writer, Reader } from "as-proto/assembly";
7
+
8
+ export class NftItemPb {
9
+ static encode(message: NftItemPb, writer: Writer): void {
10
+ writer.uint32(10);
11
+ writer.bytes(message.collectionIdBytes);
12
+
13
+ writer.uint32(18);
14
+ writer.bytes(message.contractIdBytes);
15
+
16
+ writer.uint32(26);
17
+ writer.bytes(message.tokenIdBytes);
18
+
19
+ writer.uint32(34);
20
+ writer.bytes(message.amountBytes);
21
+ }
22
+
23
+ static decode(reader: Reader, length: i32): NftItemPb {
24
+ const end: usize = length < 0 ? reader.end : reader.ptr + length;
25
+ const message = new NftItemPb();
26
+
27
+ while (reader.ptr < end) {
28
+ const tag = reader.uint32();
29
+ switch (tag >>> 3) {
30
+ case 1:
31
+ message.collectionIdBytes = reader.bytes();
32
+ break;
33
+
34
+ case 2:
35
+ message.contractIdBytes = reader.bytes();
36
+ break;
37
+
38
+ case 3:
39
+ message.tokenIdBytes = reader.bytes();
40
+ break;
41
+
42
+ case 4:
43
+ message.amountBytes = reader.bytes();
44
+ break;
45
+
46
+ default:
47
+ reader.skipType(tag & 7);
48
+ break;
49
+ }
50
+ }
51
+
52
+ return message;
53
+ }
54
+
55
+ collectionIdBytes: Uint8Array;
56
+ contractIdBytes: Uint8Array;
57
+ tokenIdBytes: Uint8Array;
58
+ amountBytes: Uint8Array;
59
+
60
+ constructor(
61
+ collectionIdBytes: Uint8Array = new Uint8Array(0),
62
+ contractIdBytes: Uint8Array = new Uint8Array(0),
63
+ tokenIdBytes: Uint8Array = new Uint8Array(0),
64
+ amountBytes: Uint8Array = new Uint8Array(0)
65
+ ) {
66
+ this.collectionIdBytes = collectionIdBytes;
67
+ this.contractIdBytes = contractIdBytes;
68
+ this.tokenIdBytes = tokenIdBytes;
69
+ this.amountBytes = amountBytes;
70
+ }
71
+ }
@@ -0,0 +1,142 @@
1
+ // Code generated by protoc-gen-as. DO NOT EDIT.
2
+ // Versions:
3
+ // protoc-gen-as v1.3.0
4
+ // protoc v6.33.4
5
+
6
+ import { Writer, Reader } from "as-proto/assembly";
7
+ import { PerpSide } from "./PerpSide";
8
+
9
+ export class PerpPositionPb {
10
+ static encode(message: PerpPositionPb, writer: Writer): void {
11
+ writer.uint32(10);
12
+ writer.string(message.baseToken);
13
+
14
+ writer.uint32(18);
15
+ writer.string(message.quoteToken);
16
+
17
+ writer.uint32(26);
18
+ writer.bytes(message.marginTokenAddressBytes);
19
+
20
+ writer.uint32(34);
21
+ writer.bytes(message.marginInitialAmountBytes);
22
+
23
+ writer.uint32(42);
24
+ writer.bytes(message.entryPriceBytes);
25
+
26
+ writer.uint32(50);
27
+ writer.bytes(message.markPriceBytes);
28
+
29
+ writer.uint32(58);
30
+ writer.bytes(message.baseSizeBytes);
31
+
32
+ writer.uint32(66);
33
+ writer.bytes(message.unrealizedPnlBytes);
34
+
35
+ writer.uint32(74);
36
+ writer.bytes(message.currentEquityBytes);
37
+
38
+ writer.uint32(82);
39
+ writer.bytes(message.leverageBytes);
40
+
41
+ writer.uint32(88);
42
+ writer.int32(message.side);
43
+ }
44
+
45
+ static decode(reader: Reader, length: i32): PerpPositionPb {
46
+ const end: usize = length < 0 ? reader.end : reader.ptr + length;
47
+ const message = new PerpPositionPb();
48
+
49
+ while (reader.ptr < end) {
50
+ const tag = reader.uint32();
51
+ switch (tag >>> 3) {
52
+ case 1:
53
+ message.baseToken = reader.string();
54
+ break;
55
+
56
+ case 2:
57
+ message.quoteToken = reader.string();
58
+ break;
59
+
60
+ case 3:
61
+ message.marginTokenAddressBytes = reader.bytes();
62
+ break;
63
+
64
+ case 4:
65
+ message.marginInitialAmountBytes = reader.bytes();
66
+ break;
67
+
68
+ case 5:
69
+ message.entryPriceBytes = reader.bytes();
70
+ break;
71
+
72
+ case 6:
73
+ message.markPriceBytes = reader.bytes();
74
+ break;
75
+
76
+ case 7:
77
+ message.baseSizeBytes = reader.bytes();
78
+ break;
79
+
80
+ case 8:
81
+ message.unrealizedPnlBytes = reader.bytes();
82
+ break;
83
+
84
+ case 9:
85
+ message.currentEquityBytes = reader.bytes();
86
+ break;
87
+
88
+ case 10:
89
+ message.leverageBytes = reader.bytes();
90
+ break;
91
+
92
+ case 11:
93
+ message.side = reader.int32();
94
+ break;
95
+
96
+ default:
97
+ reader.skipType(tag & 7);
98
+ break;
99
+ }
100
+ }
101
+
102
+ return message;
103
+ }
104
+
105
+ baseToken: string;
106
+ quoteToken: string;
107
+ marginTokenAddressBytes: Uint8Array;
108
+ marginInitialAmountBytes: Uint8Array;
109
+ entryPriceBytes: Uint8Array;
110
+ markPriceBytes: Uint8Array;
111
+ baseSizeBytes: Uint8Array;
112
+ unrealizedPnlBytes: Uint8Array;
113
+ currentEquityBytes: Uint8Array;
114
+ leverageBytes: Uint8Array;
115
+ side: PerpSide;
116
+
117
+ constructor(
118
+ baseToken: string = "",
119
+ quoteToken: string = "",
120
+ marginTokenAddressBytes: Uint8Array = new Uint8Array(0),
121
+ marginInitialAmountBytes: Uint8Array = new Uint8Array(0),
122
+ entryPriceBytes: Uint8Array = new Uint8Array(0),
123
+ markPriceBytes: Uint8Array = new Uint8Array(0),
124
+ baseSizeBytes: Uint8Array = new Uint8Array(0),
125
+ unrealizedPnlBytes: Uint8Array = new Uint8Array(0),
126
+ currentEquityBytes: Uint8Array = new Uint8Array(0),
127
+ leverageBytes: Uint8Array = new Uint8Array(0),
128
+ side: PerpSide = 0
129
+ ) {
130
+ this.baseToken = baseToken;
131
+ this.quoteToken = quoteToken;
132
+ this.marginTokenAddressBytes = marginTokenAddressBytes;
133
+ this.marginInitialAmountBytes = marginInitialAmountBytes;
134
+ this.entryPriceBytes = entryPriceBytes;
135
+ this.markPriceBytes = markPriceBytes;
136
+ this.baseSizeBytes = baseSizeBytes;
137
+ this.unrealizedPnlBytes = unrealizedPnlBytes;
138
+ this.currentEquityBytes = currentEquityBytes;
139
+ this.leverageBytes = leverageBytes;
140
+ this.side = side;
141
+ }
142
+ }
@@ -0,0 +1,10 @@
1
+ // Code generated by protoc-gen-as. DO NOT EDIT.
2
+ // Versions:
3
+ // protoc-gen-as v1.3.0
4
+ // protoc v6.33.4
5
+
6
+ export enum PerpSide {
7
+ PERP_SIDE_UNSPECIFIED = 0,
8
+ PERP_SIDE_LONG = 1,
9
+ PERP_SIDE_SHORT = 2,
10
+ }
@@ -0,0 +1,71 @@
1
+ // Code generated by protoc-gen-as. DO NOT EDIT.
2
+ // Versions:
3
+ // protoc-gen-as v1.3.0
4
+ // protoc v6.33.4
5
+
6
+ import { Writer, Reader } from "as-proto/assembly";
7
+
8
+ export class TokenBalancePb {
9
+ static encode(message: TokenBalancePb, writer: Writer): void {
10
+ writer.uint32(10);
11
+ writer.bytes(message.tokenAddressBytes);
12
+
13
+ writer.uint32(18);
14
+ writer.bytes(message.tokenIdBytes);
15
+
16
+ writer.uint32(26);
17
+ writer.bytes(message.balanceBytes);
18
+
19
+ writer.uint32(34);
20
+ writer.bytes(message.claimableAmountBytes);
21
+ }
22
+
23
+ static decode(reader: Reader, length: i32): TokenBalancePb {
24
+ const end: usize = length < 0 ? reader.end : reader.ptr + length;
25
+ const message = new TokenBalancePb();
26
+
27
+ while (reader.ptr < end) {
28
+ const tag = reader.uint32();
29
+ switch (tag >>> 3) {
30
+ case 1:
31
+ message.tokenAddressBytes = reader.bytes();
32
+ break;
33
+
34
+ case 2:
35
+ message.tokenIdBytes = reader.bytes();
36
+ break;
37
+
38
+ case 3:
39
+ message.balanceBytes = reader.bytes();
40
+ break;
41
+
42
+ case 4:
43
+ message.claimableAmountBytes = reader.bytes();
44
+ break;
45
+
46
+ default:
47
+ reader.skipType(tag & 7);
48
+ break;
49
+ }
50
+ }
51
+
52
+ return message;
53
+ }
54
+
55
+ tokenAddressBytes: Uint8Array;
56
+ tokenIdBytes: Uint8Array;
57
+ balanceBytes: Uint8Array;
58
+ claimableAmountBytes: Uint8Array;
59
+
60
+ constructor(
61
+ tokenAddressBytes: Uint8Array = new Uint8Array(0),
62
+ tokenIdBytes: Uint8Array = new Uint8Array(0),
63
+ balanceBytes: Uint8Array = new Uint8Array(0),
64
+ claimableAmountBytes: Uint8Array = new Uint8Array(0)
65
+ ) {
66
+ this.tokenAddressBytes = tokenAddressBytes;
67
+ this.tokenIdBytes = tokenIdBytes;
68
+ this.balanceBytes = balanceBytes;
69
+ this.claimableAmountBytes = claimableAmountBytes;
70
+ }
71
+ }
@@ -0,0 +1,48 @@
1
+ // Code generated by protoc-gen-as. DO NOT EDIT.
2
+ // Versions:
3
+ // protoc-gen-as v1.3.0
4
+ // protoc v6.33.4
5
+
6
+ import { Writer, Reader } from "as-proto/assembly";
7
+
8
+ export class Timestamp {
9
+ static encode(message: Timestamp, writer: Writer): void {
10
+ writer.uint32(8);
11
+ writer.int64(message.seconds);
12
+
13
+ writer.uint32(16);
14
+ writer.int32(message.nanos);
15
+ }
16
+
17
+ static decode(reader: Reader, length: i32): Timestamp {
18
+ const end: usize = length < 0 ? reader.end : reader.ptr + length;
19
+ const message = new Timestamp();
20
+
21
+ while (reader.ptr < end) {
22
+ const tag = reader.uint32();
23
+ switch (tag >>> 3) {
24
+ case 1:
25
+ message.seconds = reader.int64();
26
+ break;
27
+
28
+ case 2:
29
+ message.nanos = reader.int32();
30
+ break;
31
+
32
+ default:
33
+ reader.skipType(tag & 7);
34
+ break;
35
+ }
36
+ }
37
+
38
+ return message;
39
+ }
40
+
41
+ seconds: i64;
42
+ nanos: i32;
43
+
44
+ constructor(seconds: i64 = 0, nanos: i32 = 0) {
45
+ this.seconds = seconds;
46
+ this.nanos = nanos;
47
+ }
48
+ }
@@ -0,0 +1,121 @@
1
+ // Code generated by protoc-gen-as. MODIFIED to use graph-ts Entity.
2
+ // Versions:
3
+ // protoc-gen-as v1.3.0
4
+ // protoc v6.33.4
5
+
6
+ import { Writer, Reader, Protobuf } from "as-proto/assembly";
7
+ import { Entity } from "@graphprotocol/graph-ts";
8
+ import { EntityPb } from "../../store/EntityPb";
9
+
10
+ /**
11
+ * WatcherInputPb - Extended watcher input with external data support.
12
+ *
13
+ * This class wraps the user position (Entity) and optional external API data.
14
+ * The position field uses graph-ts Entity for compatibility with existing watchers.
15
+ */
16
+ export class WatcherInputPb {
17
+ static encode(message: WatcherInputPb, writer: Writer): void {
18
+ const position = message.position;
19
+ if (position !== null) {
20
+ writer.uint32(10);
21
+ writer.fork();
22
+ EntityPb.encode(position, writer);
23
+ writer.ldelim();
24
+ }
25
+
26
+ const externalData = message.externalData;
27
+ if (externalData !== null) {
28
+ const externalDataKeys = externalData.keys();
29
+ for (let i: i32 = 0; i < externalDataKeys.length; ++i) {
30
+ const externalDataKey = externalDataKeys[i];
31
+ writer.uint32(18);
32
+ writer.fork();
33
+ writer.uint32(10);
34
+ writer.string(externalDataKey);
35
+ writer.uint32(18);
36
+ writer.bytes(externalData.get(externalDataKey));
37
+ writer.ldelim();
38
+ }
39
+ }
40
+ }
41
+
42
+ static decode(reader: Reader, length: i32): WatcherInputPb {
43
+ const end: usize = length < 0 ? reader.end : reader.ptr + length;
44
+ const message = new WatcherInputPb();
45
+
46
+ while (reader.ptr < end) {
47
+ const tag = reader.uint32();
48
+ switch (tag >>> 3) {
49
+ case 1:
50
+ message.position = EntityPb.decode(reader, reader.uint32());
51
+ break;
52
+
53
+ case 2:
54
+ let externalDataKey: string = "";
55
+ let externalDataValue: Uint8Array = new Uint8Array(0);
56
+ let externalDataHasKey: bool = false;
57
+ let externalDataHasValue: bool = false;
58
+ for (
59
+ const end: usize = reader.ptr + reader.uint32();
60
+ reader.ptr < end;
61
+
62
+ ) {
63
+ const tag = reader.uint32();
64
+ switch (tag >>> 3) {
65
+ case 1:
66
+ externalDataKey = reader.string();
67
+ externalDataHasKey = true;
68
+ break;
69
+
70
+ case 2:
71
+ externalDataValue = reader.bytes();
72
+ externalDataHasValue = true;
73
+ break;
74
+
75
+ default:
76
+ reader.skipType(tag & 7);
77
+ break;
78
+ }
79
+ if (message.externalData === null) {
80
+ message.externalData = new Map<string, Uint8Array>();
81
+ }
82
+ const externalData = message.externalData;
83
+ if (
84
+ externalData !== null &&
85
+ externalDataHasKey &&
86
+ externalDataHasValue
87
+ ) {
88
+ externalData.set(externalDataKey, externalDataValue);
89
+ }
90
+ }
91
+ break;
92
+
93
+ default:
94
+ reader.skipType(tag & 7);
95
+ break;
96
+ }
97
+ }
98
+
99
+ return message;
100
+ }
101
+
102
+ // Position uses graph-ts Entity (decoded via custom EntityPb)
103
+ position: Entity | null;
104
+ externalData: Map<string, Uint8Array>;
105
+
106
+ constructor(
107
+ position: Entity | null = null,
108
+ externalData: Map<string, Uint8Array> = new Map()
109
+ ) {
110
+ this.position = position;
111
+ this.externalData = externalData;
112
+ }
113
+ }
114
+
115
+ export function encodeWatcherInputPb(message: WatcherInputPb): Uint8Array {
116
+ return Protobuf.encode(message, WatcherInputPb.encode);
117
+ }
118
+
119
+ export function decodeWatcherInputPb(buffer: Uint8Array): WatcherInputPb {
120
+ return Protobuf.decode<WatcherInputPb>(buffer, WatcherInputPb.decode);
121
+ }
@@ -1,9 +1,107 @@
1
- import { Entity } from '@graphprotocol/graph-ts'
1
+ import { Entity, Bytes } from '@graphprotocol/graph-ts'
2
2
 
3
+ /**
4
+ * Input data provided to a watcher by the host.
5
+ *
6
+ * For watchers using the extended format (WatcherInputPb), this includes:
7
+ * - position: The user position entity from the subgraph
8
+ * - externalData: Optional map of pre-fetched external API data
9
+ *
10
+ * For legacy watchers, only position is populated and externalData is empty.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const input = watcher.input()
15
+ * const position = input.position
16
+ *
17
+ * // Check for external data
18
+ * if (input.hasExternalData('merkl_amount:0x...')) {
19
+ * const data = input.getExternalData('merkl_amount:0x...')!
20
+ * // Process data...
21
+ * }
22
+ * ```
23
+ */
3
24
  export class WatcherInput {
25
+ /**
26
+ * The user position entity from the subgraph.
27
+ * Contains the on-chain position data indexed by the subgraph.
28
+ */
4
29
  position: Entity
30
+
31
+ /**
32
+ * Optional map of pre-fetched external API data.
33
+ * Keys follow the convention: "{provider}_{dataType}:{identifier}"
34
+ * Values are raw bytes that the watcher must decode.
35
+ *
36
+ * Examples of keys:
37
+ * - "merkl_amount:0xUserAddr:0xTokenAddr" - Merkl claimable amount
38
+ * - "merkl_proof:0xUserAddr:0xTokenAddr" - Merkl Merkle proof
39
+ * - "aster_pnl:0xUserAddr" - Aster unrealized PnL
40
+ */
41
+ externalData: Map<string, Bytes>
5
42
 
6
- constructor(position: Entity) {
43
+ constructor(
44
+ position: Entity,
45
+ externalData: Map<string, Bytes> = new Map<string, Bytes>()
46
+ ) {
7
47
  this.position = position
48
+ this.externalData = externalData
49
+ }
50
+
51
+ /**
52
+ * Check if external data is available for a given key.
53
+ *
54
+ * @param key - The external data key to check
55
+ * @returns true if data exists for the key, false otherwise
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * if (input.hasExternalData('merkl_amount:0xUser:0xToken')) {
60
+ * // Data is available
61
+ * }
62
+ * ```
63
+ */
64
+ hasExternalData(key: string): bool {
65
+ return this.externalData.has(key)
66
+ }
67
+
68
+ /**
69
+ * Get external data by key.
70
+ *
71
+ * @param key - The external data key to retrieve
72
+ * @returns The data as Bytes if present, null otherwise
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * const data = input.getExternalData('merkl_amount:0xUser:0xToken')
77
+ * if (data !== null) {
78
+ * const amount = BigInt.fromUnsignedBytes(data)
79
+ * }
80
+ * ```
81
+ */
82
+ getExternalData(key: string): Bytes | null {
83
+ if (this.externalData.has(key)) {
84
+ return changetype<Bytes>(this.externalData.get(key))
85
+ }
86
+ return null
87
+ }
88
+
89
+ /**
90
+ * Get all external data keys available.
91
+ * Useful for debugging or iterating over all external data.
92
+ *
93
+ * @returns Array of all external data keys
94
+ */
95
+ getExternalDataKeys(): string[] {
96
+ return this.externalData.keys()
97
+ }
98
+
99
+ /**
100
+ * Check if any external data was provided.
101
+ *
102
+ * @returns true if at least one external data entry exists
103
+ */
104
+ hasAnyExternalData(): bool {
105
+ return this.externalData.size > 0
8
106
  }
9
107
  }