datai-sdk 1.1.2 → 1.1.3
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/package.json +1 -1
- package/patch-graph-ts.js +4 -2
- package/postinstall-script.js +27 -70
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// Side-effect to evaluate eagerly the offset of stub AS runtime
|
|
2
|
+
import './common/eager_offset';
|
|
3
|
+
import { ByteArray, Bytes, Entity } from './common/collections';
|
|
4
|
+
import { Value } from './common/value';
|
|
5
|
+
|
|
6
|
+
// Arweave support
|
|
7
|
+
export * from './chain/arweave';
|
|
8
|
+
// Ethereum support
|
|
9
|
+
export * from './chain/ethereum';
|
|
10
|
+
// NEAR support
|
|
11
|
+
export * from './chain/near';
|
|
12
|
+
// Cosmos support
|
|
13
|
+
export * from './chain/cosmos';
|
|
14
|
+
// Starknet support
|
|
15
|
+
export * from './chain/starknet';
|
|
16
|
+
// Regular re-exports
|
|
17
|
+
export * from './common/collections';
|
|
18
|
+
export * from './common/conversion';
|
|
19
|
+
export * from './common/datasource';
|
|
20
|
+
export * from './common/json';
|
|
21
|
+
export * from './common/numbers';
|
|
22
|
+
export * from './common/value';
|
|
23
|
+
import * as API from '../../../API'
|
|
24
|
+
export { store, crypto } from '../../../API';
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// /** Host IPFS interface */
|
|
28
|
+
// export declare namespace ipfs {
|
|
29
|
+
// function cat(hash: string): Bytes | null;
|
|
30
|
+
// function map(hash: string, callback: string, userData: Value, flags: string[]): void;
|
|
31
|
+
// }
|
|
32
|
+
|
|
33
|
+
// export namespace ipfs {
|
|
34
|
+
// export function mapJSON(hash: string, callback: string, userData: Value): void {
|
|
35
|
+
// ipfs.map(hash, callback, userData, ['json']);
|
|
36
|
+
// }
|
|
37
|
+
// }
|
|
38
|
+
|
|
39
|
+
// /**
|
|
40
|
+
// * Special function for ENS name lookups, not meant for general purpose use.
|
|
41
|
+
// * This function will only be useful if the graph-node instance has additional
|
|
42
|
+
// * data loaded **
|
|
43
|
+
// */
|
|
44
|
+
// export declare namespace ens {
|
|
45
|
+
// function nameByHash(hash: string): string | null;
|
|
46
|
+
// }
|
|
47
|
+
|
|
48
|
+
function format(fmt: string, args: string[]): string {
|
|
49
|
+
let out = '';
|
|
50
|
+
let argIndex = 0;
|
|
51
|
+
for (let i: i32 = 0, len: i32 = fmt.length; i < len; i++) {
|
|
52
|
+
if (
|
|
53
|
+
i < len - 1 &&
|
|
54
|
+
fmt.charCodeAt(i) == 0x7b /* '{' */ &&
|
|
55
|
+
fmt.charCodeAt(i + 1) == 0x7d /* '}' */
|
|
56
|
+
) {
|
|
57
|
+
if (argIndex >= args.length) {
|
|
58
|
+
throw new Error('Too few arguments for format string: ' + fmt);
|
|
59
|
+
} else {
|
|
60
|
+
out += args[argIndex++];
|
|
61
|
+
i++;
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
out += fmt.charAt(i);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export namespace log {
|
|
71
|
+
export const log = API.log.log;
|
|
72
|
+
|
|
73
|
+
export enum Level {
|
|
74
|
+
CRITICAL = 0,
|
|
75
|
+
ERROR = 1,
|
|
76
|
+
WARNING = 2,
|
|
77
|
+
INFO = 3,
|
|
78
|
+
DEBUG = 4,
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Logs a critical message that terminates the subgraph.
|
|
83
|
+
*
|
|
84
|
+
* @param msg Format string a la "Value = {}, other = {}".
|
|
85
|
+
* @param args Format string arguments.
|
|
86
|
+
*/
|
|
87
|
+
export function critical(msg: string, args: Array<string>): void {
|
|
88
|
+
log(Level.CRITICAL, format(msg, args));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Logs an error message.
|
|
93
|
+
*
|
|
94
|
+
* @param msg Format string a la "Value = {}, other = {}".
|
|
95
|
+
* @param args Format string arguments.
|
|
96
|
+
*/
|
|
97
|
+
export function error(msg: string, args: Array<string>): void {
|
|
98
|
+
log(Level.ERROR, format(msg, args));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Logs a warning message.
|
|
102
|
+
*
|
|
103
|
+
* @param msg Format string a la "Value = {}, other = {}".
|
|
104
|
+
* @param args Format string arguments.
|
|
105
|
+
*/
|
|
106
|
+
export function warning(msg: string, args: Array<string>): void {
|
|
107
|
+
log(Level.WARNING, format(msg, args));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Logs an info message.
|
|
111
|
+
*
|
|
112
|
+
* @param msg Format string a la "Value = {}, other = {}".
|
|
113
|
+
* @param args Format string arguments.
|
|
114
|
+
*/
|
|
115
|
+
export function info(msg: string, args: Array<string>): void {
|
|
116
|
+
log(Level.INFO, format(msg, args));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Logs a debug message.
|
|
120
|
+
*
|
|
121
|
+
* @param msg Format string a la "Value = {}, other = {}".
|
|
122
|
+
* @param args Format string arguments.
|
|
123
|
+
*/
|
|
124
|
+
export function debug(msg: string, args: Array<string>): void {
|
|
125
|
+
log(Level.DEBUG, format(msg, args));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Helper functions for Ethereum.
|
|
131
|
+
*/
|
|
132
|
+
export namespace EthereumUtils {
|
|
133
|
+
/**
|
|
134
|
+
* Returns the contract address that would result from the given CREATE2 call.
|
|
135
|
+
* @param from The Ethereum address of the account that is initiating the contract creation.
|
|
136
|
+
* @param salt A 32-byte value that is used to create a deterministic address for the contract. This can be any arbitrary value, but it should be unique to the contract being created.
|
|
137
|
+
* @param initCodeHash he compiled code that will be executed when the contract is created. This should be a hex-encoded string that represents the compiled bytecode.
|
|
138
|
+
* @returns Address of the contract that would be created.
|
|
139
|
+
*/
|
|
140
|
+
export function getCreate2Address(from: Bytes, salt: Bytes, initCodeHash: Bytes): Bytes {
|
|
141
|
+
return Bytes.fromHexString(
|
|
142
|
+
Bytes.fromByteArray(
|
|
143
|
+
API.crypto.keccak256(
|
|
144
|
+
Bytes.fromHexString(
|
|
145
|
+
'0xff' +
|
|
146
|
+
from.toHexString().slice(2) +
|
|
147
|
+
salt.toHexString().slice(2) +
|
|
148
|
+
initCodeHash.toHexString().slice(2),
|
|
149
|
+
),
|
|
150
|
+
),
|
|
151
|
+
)
|
|
152
|
+
.toHexString()
|
|
153
|
+
.slice(26),
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
}
|
package/package.json
CHANGED
package/patch-graph-ts.js
CHANGED
|
@@ -41,7 +41,9 @@ let content = fs.readFileSync(numbersPath, 'utf8');
|
|
|
41
41
|
// Pattern to match assertions like:
|
|
42
42
|
// assert(this !== null, "Failed to ... because left hand side is 'null'");
|
|
43
43
|
// or "... value of it is 'null'"
|
|
44
|
-
|
|
44
|
+
// We match the entire line including leading whitespace and newline
|
|
45
|
+
// Handles optional whitespace after the semicolon
|
|
46
|
+
const assertPattern = /^\s*assert\(this !== null, "Failed to [^"]+"\);\s*\n/gm;
|
|
45
47
|
|
|
46
48
|
// Count matches
|
|
47
49
|
const matches = content.match(assertPattern);
|
|
@@ -52,7 +54,7 @@ if (!matches || matches.length === 0) {
|
|
|
52
54
|
|
|
53
55
|
console.log(`Found ${matches.length} assertions to remove.`);
|
|
54
56
|
|
|
55
|
-
// Remove the problematic assertions
|
|
57
|
+
// Remove the problematic assertions (replace with empty string to preserve next line's indentation)
|
|
56
58
|
const patched = content.replace(assertPattern, '');
|
|
57
59
|
|
|
58
60
|
// Backup original
|
package/postinstall-script.js
CHANGED
|
@@ -9,77 +9,34 @@ const destinationFolder = path.resolve(
|
|
|
9
9
|
);
|
|
10
10
|
|
|
11
11
|
// Check if the source folder exists
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const nodeModulesPath = path.resolve(__dirname, "node_modules");
|
|
21
|
-
if (!fs.existsSync(nodeModulesPath)) {
|
|
22
|
-
fs.mkdirSync(nodeModulesPath);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Check if the destination folder already exists
|
|
26
|
-
if (fs.existsSync(destinationFolder)) {
|
|
27
|
-
console.log(
|
|
28
|
-
`Destination folder "${destinationFolder}" already exists. Removing it...`
|
|
29
|
-
);
|
|
30
|
-
fs.rmSync(destinationFolder, { recursive: true, force: true });
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Move the source folder to node_modules
|
|
34
|
-
fs.renameSync(sourceFolder, destinationFolder);
|
|
35
|
-
|
|
36
|
-
console.log(`Folder "${sourceFolder}" moved to "${destinationFolder}".`);
|
|
37
|
-
|
|
38
|
-
// ============================================================
|
|
39
|
-
// Apply graph-ts patch to fix AssemblyScript type inference bug
|
|
40
|
-
// ============================================================
|
|
41
|
-
// The issue: `assert(this !== null, ...)` in BigInt/BigDecimal methods causes
|
|
42
|
-
// AssemblyScript to infer `this` as `T | null`, which breaks type checking.
|
|
43
|
-
// We remove these assertions as `this` can never be null in normal class method calls.
|
|
44
|
-
|
|
45
|
-
const graphTsPaths = [
|
|
46
|
-
// When installed as dependency (looks in parent's node_modules)
|
|
47
|
-
path.resolve(__dirname, "../node_modules/@graphprotocol/graph-ts/common/numbers.ts"),
|
|
48
|
-
// When running from project root
|
|
49
|
-
path.resolve(process.cwd(), "node_modules/@graphprotocol/graph-ts/common/numbers.ts"),
|
|
50
|
-
];
|
|
12
|
+
// The @graphprotocol folder contains a custom fork of graph-ts that integrates
|
|
13
|
+
// with the SDK's host functions (bigInt, bigDecimal, ethereum.call, etc.)
|
|
14
|
+
if (fs.existsSync(sourceFolder)) {
|
|
15
|
+
// Create node_modules folder if it doesn't exist
|
|
16
|
+
const nodeModulesPath = path.resolve(__dirname, "node_modules");
|
|
17
|
+
if (!fs.existsSync(nodeModulesPath)) {
|
|
18
|
+
fs.mkdirSync(nodeModulesPath);
|
|
19
|
+
}
|
|
51
20
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const matches = content.match(assertPattern);
|
|
59
|
-
|
|
60
|
-
if (matches && matches.length > 0) {
|
|
61
|
-
console.log(`Patching ${numbersPath}...`);
|
|
62
|
-
console.log(`Found ${matches.length} assertions to remove.`);
|
|
63
|
-
|
|
64
|
-
// Backup original
|
|
65
|
-
const backupPath = numbersPath + ".bak";
|
|
66
|
-
if (!fs.existsSync(backupPath)) {
|
|
67
|
-
fs.writeFileSync(backupPath, content);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Remove assertions
|
|
71
|
-
const patched = content.replace(assertPattern, "");
|
|
72
|
-
fs.writeFileSync(numbersPath, patched);
|
|
73
|
-
console.log("graph-ts patch applied successfully!");
|
|
74
|
-
patchApplied = true;
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
} catch (e) {
|
|
78
|
-
console.log(`Warning: Could not patch ${numbersPath}: ${e.message}`);
|
|
79
|
-
}
|
|
21
|
+
// Check if the destination folder already exists
|
|
22
|
+
if (fs.existsSync(destinationFolder)) {
|
|
23
|
+
console.log(
|
|
24
|
+
`Destination folder "${destinationFolder}" already exists. Removing it...`
|
|
25
|
+
);
|
|
26
|
+
fs.rmSync(destinationFolder, { recursive: true, force: true });
|
|
80
27
|
}
|
|
81
|
-
}
|
|
82
28
|
|
|
83
|
-
|
|
84
|
-
|
|
29
|
+
// Move the source folder to node_modules
|
|
30
|
+
// This makes the custom graph-ts available to watchers that use the SDK
|
|
31
|
+
fs.renameSync(sourceFolder, destinationFolder);
|
|
32
|
+
|
|
33
|
+
console.log(`Folder "${sourceFolder}" moved to "${destinationFolder}".`);
|
|
34
|
+
console.log("Custom graph-ts (integrated with SDK host functions) is now available.");
|
|
35
|
+
} else if (fs.existsSync(destinationFolder)) {
|
|
36
|
+
// Folder already moved in a previous install - this is fine
|
|
37
|
+
console.log("Custom graph-ts already installed in node_modules.");
|
|
38
|
+
} else {
|
|
39
|
+
// This shouldn't happen in normal usage, but warn instead of error
|
|
40
|
+
console.warn(`Warning: Source folder "${sourceFolder}" does not exist.`);
|
|
41
|
+
console.warn("If this is an npm install, the @graphprotocol folder should be included in the package.");
|
|
85
42
|
}
|