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,20 +1,170 @@
|
|
|
1
1
|
import { Protobuf } from 'as-proto/assembly'
|
|
2
2
|
import { WatcherResultPb } from '../proto/watcher/WatcherResultPb'
|
|
3
|
+
import { WatcherInputPb } from '../proto/watcher/WatcherInputPb'
|
|
3
4
|
import { Any } from '../proto/google/protobuf/Any'
|
|
4
5
|
import { Host } from '@extism/as-pdk'
|
|
5
6
|
import { WatcherInput } from './WatcherInput'
|
|
6
|
-
import {
|
|
7
|
-
import { EntityPb } from '../store/EntityPb'
|
|
7
|
+
import { Bytes } from '@graphprotocol/graph-ts'
|
|
8
8
|
|
|
9
|
+
// Cached input to avoid re-decoding on multiple calls
|
|
10
|
+
let _cachedInput: WatcherInput | null = null
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Watcher namespace providing input/output functions for watcher implementations.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { watcher, activePositions, ActivePositionsResult } from 'datai-sdk'
|
|
18
|
+
*
|
|
19
|
+
* export function GetActivePositions(): void {
|
|
20
|
+
* const input = watcher.input()
|
|
21
|
+
* const position = activePositions.inputPosition<MyPosition>()
|
|
22
|
+
*
|
|
23
|
+
* // Check for external data
|
|
24
|
+
* if (watcher.hasExternalData('my_key')) {
|
|
25
|
+
* const data = watcher.getExternalData('my_key')!
|
|
26
|
+
* // Use the data...
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* const output = new ActivePositionsResult()
|
|
30
|
+
* // ... build output
|
|
31
|
+
* activePositions.output(output)
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
9
35
|
export namespace watcher {
|
|
36
|
+
/** Default update schedule */
|
|
10
37
|
export const SCHEDULE_DEFAULT = 'DEFAULT'
|
|
38
|
+
|
|
39
|
+
/** Low priority update schedule (less frequent updates) */
|
|
11
40
|
export const SCHEDULE_LOW_PRIORITY = 'LOW_PRIORITY'
|
|
12
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Get the watcher input (position + external data).
|
|
44
|
+
* Result is cached for the duration of the watcher call.
|
|
45
|
+
*
|
|
46
|
+
* NOTE: This function expects WatcherInputPb format.
|
|
47
|
+
* Watchers built with this SDK version MUST be configured in the host
|
|
48
|
+
* to receive the extended format.
|
|
49
|
+
*
|
|
50
|
+
* @returns WatcherInput containing position and optional external data
|
|
51
|
+
*/
|
|
13
52
|
export function input(): WatcherInput {
|
|
14
|
-
|
|
15
|
-
|
|
53
|
+
if (_cachedInput !== null) {
|
|
54
|
+
return _cachedInput!
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const rawInput = Host.input()
|
|
58
|
+
|
|
59
|
+
// Decode as WatcherInputPb (new format with external data support)
|
|
60
|
+
const inputPb = Protobuf.decode<WatcherInputPb>(rawInput, WatcherInputPb.decode)
|
|
61
|
+
|
|
62
|
+
// Convert external data map from Uint8Array to Bytes
|
|
63
|
+
const externalData = new Map<string, Bytes>()
|
|
64
|
+
const keys = inputPb.externalData.keys()
|
|
65
|
+
for (let i = 0; i < keys.length; i++) {
|
|
66
|
+
const key = keys[i]
|
|
67
|
+
const value = inputPb.externalData.get(key)
|
|
68
|
+
externalData.set(key, changetype<Bytes>(value))
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Create WatcherInput with position and external data
|
|
72
|
+
_cachedInput = new WatcherInput(inputPb.position!, externalData)
|
|
73
|
+
return _cachedInput!
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Helper: Get external data by key.
|
|
78
|
+
* Convenience method that calls input().getExternalData(key).
|
|
79
|
+
*
|
|
80
|
+
* @param key - The external data key to retrieve
|
|
81
|
+
* @returns The data as Bytes if present, null otherwise
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const amount = watcher.getExternalData('merkl_amount:0xUser:0xToken')
|
|
86
|
+
* if (amount !== null) {
|
|
87
|
+
* // Process amount...
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export function getExternalData(key: string): Bytes | null {
|
|
92
|
+
return input().getExternalData(key)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Helper: Check if external data exists for a key.
|
|
97
|
+
* Convenience method that calls input().hasExternalData(key).
|
|
98
|
+
*
|
|
99
|
+
* @param key - The external data key to check
|
|
100
|
+
* @returns true if data exists for the key, false otherwise
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* if (watcher.hasExternalData('merkl_proof:0xUser:0xToken')) {
|
|
105
|
+
* const proof = watcher.getExternalData('merkl_proof:0xUser:0xToken')!
|
|
106
|
+
* // Use proof...
|
|
107
|
+
* }
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export function hasExternalData(key: string): bool {
|
|
111
|
+
return input().hasExternalData(key)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Helper: Get all external data keys.
|
|
116
|
+
* Convenience method that calls input().getExternalDataKeys().
|
|
117
|
+
*
|
|
118
|
+
* @returns Array of all external data keys
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* const keys = watcher.getExternalDataKeys()
|
|
123
|
+
* for (let i = 0; i < keys.length; i++) {
|
|
124
|
+
* const data = watcher.getExternalData(keys[i])
|
|
125
|
+
* // Process data...
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export function getExternalDataKeys(): string[] {
|
|
130
|
+
return input().getExternalDataKeys()
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Helper: Check if any external data was provided.
|
|
135
|
+
* Convenience method that calls input().hasAnyExternalData().
|
|
136
|
+
*
|
|
137
|
+
* @returns true if at least one external data entry exists
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* if (watcher.hasAnyExternalData()) {
|
|
142
|
+
* // External data is available, process it
|
|
143
|
+
* const keys = watcher.getExternalDataKeys()
|
|
144
|
+
* // ...
|
|
145
|
+
* }
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export function hasAnyExternalData(): bool {
|
|
149
|
+
return input().hasAnyExternalData()
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Reset cached input.
|
|
154
|
+
* Called automatically by the host between watcher invocations.
|
|
155
|
+
* Watchers should not need to call this directly.
|
|
156
|
+
*/
|
|
157
|
+
export function resetInput(): void {
|
|
158
|
+
_cachedInput = null
|
|
16
159
|
}
|
|
17
160
|
|
|
161
|
+
/**
|
|
162
|
+
* Output the watcher result to the host.
|
|
163
|
+
*
|
|
164
|
+
* @param resultTypeUrl - The protobuf type URL for the result
|
|
165
|
+
* @param resultBytes - The serialized result bytes
|
|
166
|
+
* @param updateTrigger - The update trigger/schedule for next update
|
|
167
|
+
*/
|
|
18
168
|
export function output(
|
|
19
169
|
resultTypeUrl: string,
|
|
20
170
|
resultBytes: Uint8Array,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "datai-sdk",
|
|
3
3
|
"main": "index.ts",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.1.1",
|
|
5
5
|
"description": "Datai SDK which has useful libraries to help building projections",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"postinstall": "node postinstall-script.js"
|
|
@@ -9,5 +9,8 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@extism/as-pdk": "^1.0.0",
|
|
11
11
|
"as-proto": "^1.3.0"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"as-proto-gen": "^1.3.0"
|
|
12
15
|
}
|
|
13
|
-
}
|
|
16
|
+
}
|
package/postinstall-script.js
CHANGED
|
@@ -9,9 +9,11 @@ const destinationFolder = path.resolve(
|
|
|
9
9
|
);
|
|
10
10
|
|
|
11
11
|
// Check if the source folder exists
|
|
12
|
+
// If it doesn't exist, the script was likely already run or this is an npm install
|
|
13
|
+
// In either case, we can safely exit without error
|
|
12
14
|
if (!fs.existsSync(sourceFolder)) {
|
|
13
|
-
console.
|
|
14
|
-
process.exit(
|
|
15
|
+
console.log(`Source folder "${sourceFolder}" does not exist. Skipping postinstall (already configured or installed from npm).`);
|
|
16
|
+
process.exit(0);
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
// Create node_modules folder if it doesn't exist
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# The Graph TypeScript Library (graph-ts) adapted to Extism PDK
|
|
2
|
-
|
|
3
|
-
## License
|
|
4
|
-
|
|
5
|
-
Copyright © 2018 Graph Protocol, Inc. and contributors.
|
|
6
|
-
|
|
7
|
-
The Graph TypeScript library is dual-licensed under the [MIT license](LICENSE-MIT) and the
|
|
8
|
-
[Apache License, Version 2.0](LICENSE-APACHE).
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software distributed under the License is
|
|
11
|
-
distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
12
|
-
implied. See the License for the specific language governing permissions and limitations under the
|
|
13
|
-
License.
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import '../common/eager_offset';
|
|
2
|
-
import { Bytes } from '../common/collections';
|
|
3
|
-
|
|
4
|
-
// Most types from this namespace are direct mappings or adaptations from:
|
|
5
|
-
// https://github.com/ChainSafe/firehose-arweave/blob/master/proto/sf/arweave/type/v1/type.proto
|
|
6
|
-
export namespace arweave {
|
|
7
|
-
/**
|
|
8
|
-
* A key-value pair for arbitrary metadata
|
|
9
|
-
*/
|
|
10
|
-
export class Tag {
|
|
11
|
-
constructor(
|
|
12
|
-
public name: Bytes,
|
|
13
|
-
public value: Bytes,
|
|
14
|
-
) {}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class ProofOfAccess {
|
|
18
|
-
constructor(
|
|
19
|
-
public option: string,
|
|
20
|
-
public txPath: Bytes,
|
|
21
|
-
public dataPath: Bytes,
|
|
22
|
-
public chunk: Bytes,
|
|
23
|
-
) {}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* An Arweave block.
|
|
28
|
-
*/
|
|
29
|
-
export class Block {
|
|
30
|
-
constructor(
|
|
31
|
-
public timestamp: u64,
|
|
32
|
-
public lastRetarget: u64,
|
|
33
|
-
public height: u64,
|
|
34
|
-
public indepHash: Bytes,
|
|
35
|
-
public nonce: Bytes,
|
|
36
|
-
public previousBlock: Bytes,
|
|
37
|
-
public diff: Bytes,
|
|
38
|
-
public hash: Bytes,
|
|
39
|
-
public txRoot: Bytes,
|
|
40
|
-
public txs: Bytes[],
|
|
41
|
-
public walletList: Bytes,
|
|
42
|
-
public rewardAddr: Bytes,
|
|
43
|
-
public tags: Tag[],
|
|
44
|
-
public rewardPool: Bytes,
|
|
45
|
-
public weaveSize: Bytes,
|
|
46
|
-
public blockSize: Bytes,
|
|
47
|
-
public cumulativeDiff: Bytes,
|
|
48
|
-
public hashListMerkle: Bytes,
|
|
49
|
-
public poa: ProofOfAccess,
|
|
50
|
-
) {}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* An Arweave transaction
|
|
55
|
-
*/
|
|
56
|
-
export class Transaction {
|
|
57
|
-
constructor(
|
|
58
|
-
public format: u32,
|
|
59
|
-
public id: Bytes,
|
|
60
|
-
public lastTx: Bytes,
|
|
61
|
-
public owner: Bytes,
|
|
62
|
-
public tags: Tag[],
|
|
63
|
-
public target: Bytes,
|
|
64
|
-
public quantity: Bytes,
|
|
65
|
-
public data: Bytes,
|
|
66
|
-
public dataSize: Bytes,
|
|
67
|
-
public dataRoot: Bytes,
|
|
68
|
-
public signature: Bytes,
|
|
69
|
-
public reward: Bytes,
|
|
70
|
-
) {}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* An Arweave transaction with block ptr
|
|
75
|
-
*/
|
|
76
|
-
export class TransactionWithBlockPtr {
|
|
77
|
-
constructor(
|
|
78
|
-
public tx: Transaction,
|
|
79
|
-
public block: Block,
|
|
80
|
-
) {}
|
|
81
|
-
}
|
|
82
|
-
}
|