envio 3.6.0 → 3.6.1-subgraph
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/package.json +6 -6
- package/src/ChainState.res +10 -4
- package/src/ChainState.res.mjs +5 -1
- package/src/Config.res +12 -0
- package/src/Config.res.mjs +8 -2
- package/src/Core.res +15 -0
- package/src/Core.res.mjs +11 -0
- package/src/EventProcessing.res +6 -6
- package/src/EventProcessing.res.mjs +8 -6
- package/src/HandlerLoader.res +20 -8
- package/src/HandlerLoader.res.mjs +11 -2
- package/src/Metrics.res +5 -5
- package/src/Metrics.res.mjs +5 -1
- package/src/UserContext.res +358 -51
- package/src/UserContext.res.mjs +271 -35
- package/src/sources/SourceManager.res +6 -12
- package/src/sources/SourceManager.res.mjs +8 -5
- package/src/subgraph/blocks.ts +176 -0
- package/src/subgraph/calls.ts +213 -0
- package/src/subgraph/conformance.ts +99 -0
- package/src/subgraph/division.ts +100 -0
- package/src/subgraph/errors.ts +90 -0
- package/src/subgraph/graph-ts-types/VERSION +2 -0
- package/src/subgraph/graph-ts-types/chain/arweave.d.ts +70 -0
- package/src/subgraph/graph-ts-types/chain/cosmos.d.ts +327 -0
- package/src/subgraph/graph-ts-types/chain/ethereum.d.ts +233 -0
- package/src/subgraph/graph-ts-types/chain/near.d.ts +253 -0
- package/src/subgraph/graph-ts-types/chain/starknet.d.ts +32 -0
- package/src/subgraph/graph-ts-types/common/collections.d.ts +136 -0
- package/src/subgraph/graph-ts-types/common/conversion.d.ts +11 -0
- package/src/subgraph/graph-ts-types/common/datasource.d.ts +30 -0
- package/src/subgraph/graph-ts-types/common/eager-offset.d.ts +0 -0
- package/src/subgraph/graph-ts-types/common/json.d.ts +17 -0
- package/src/subgraph/graph-ts-types/common/numbers.d.ts +120 -0
- package/src/subgraph/graph-ts-types/common/value.d.ts +120 -0
- package/src/subgraph/graph-ts-types/common/yaml.d.ts +90 -0
- package/src/subgraph/graph-ts-types/global/global.d.ts +194 -0
- package/src/subgraph/graph-ts-types/helper-functions.d.ts +22 -0
- package/src/subgraph/graph-ts-types/index.d.ts +102 -0
- package/src/subgraph/graph-ts.ts +1695 -0
- package/src/subgraph/hosts.ts +148 -0
- package/src/subgraph/runtime.ts +827 -0
- package/src/subgraph/scope.ts +63 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The graph-node host ops that reach outside the chain data envio already has:
|
|
3
|
+
* IPFS, Arweave, ENS, `eth_getBalance`/`eth_getCode`, and a block handler's
|
|
4
|
+
* timestamp. Each is an envio effect, so preload batches and dedupes them and
|
|
5
|
+
* the sync bridge suspends the mapping until the answer lands.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { createPublicClient, fallback, http } from "viem";
|
|
9
|
+
import * as Sury from "rescript-schema";
|
|
10
|
+
import { createEffect } from "../Envio.res.mjs";
|
|
11
|
+
import { configureBlockTimestamps, requestBlockTimestamp } from "./blocks.ts";
|
|
12
|
+
import { missingRpcMessage } from "./errors.ts";
|
|
13
|
+
|
|
14
|
+
const IPFS_GATEWAY = "https://ipfs.io/ipfs/";
|
|
15
|
+
const ARWEAVE_GATEWAY = "https://arweave.net/";
|
|
16
|
+
/** graph-node heals a hash from its rainbow table; this is the public one. */
|
|
17
|
+
const ENS_RAINBOW = "https://api.ensrainbow.io/v1/heal/";
|
|
18
|
+
|
|
19
|
+
const nullableString = Sury.union([Sury.string, null]);
|
|
20
|
+
|
|
21
|
+
async function fetchBase64(url: string): Promise<string | null> {
|
|
22
|
+
const response = await fetch(url);
|
|
23
|
+
if (!response.ok) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const buffer = new Uint8Array(await response.arrayBuffer());
|
|
27
|
+
return Buffer.from(buffer).toString("base64");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type HostEffects = ReturnType<typeof makeHostEffects>;
|
|
31
|
+
|
|
32
|
+
export function makeHostEffects(rpcUrls: string[]) {
|
|
33
|
+
configureBlockTimestamps(rpcUrls);
|
|
34
|
+
|
|
35
|
+
let client: ReturnType<typeof createPublicClient> | null = null;
|
|
36
|
+
const clientOrThrow = (callSite: string) => {
|
|
37
|
+
if (rpcUrls.length === 0) {
|
|
38
|
+
throw new Error(missingRpcMessage(callSite));
|
|
39
|
+
}
|
|
40
|
+
client ??= createPublicClient({
|
|
41
|
+
transport: fallback(rpcUrls.map((url) => http(url, { retryCount: 0 }))),
|
|
42
|
+
});
|
|
43
|
+
return client;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const ipfsCat = createEffect(
|
|
47
|
+
{
|
|
48
|
+
name: "envio_subgraph_ipfs_cat",
|
|
49
|
+
input: Sury.string,
|
|
50
|
+
output: nullableString,
|
|
51
|
+
rateLimit: false,
|
|
52
|
+
cache: true,
|
|
53
|
+
},
|
|
54
|
+
async ({ input }: { input: string }) => fetchBase64(IPFS_GATEWAY + input),
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const arweaveData = createEffect(
|
|
58
|
+
{
|
|
59
|
+
name: "envio_subgraph_arweave",
|
|
60
|
+
input: Sury.string,
|
|
61
|
+
output: nullableString,
|
|
62
|
+
rateLimit: false,
|
|
63
|
+
cache: true,
|
|
64
|
+
},
|
|
65
|
+
async ({ input }: { input: string }) => fetchBase64(ARWEAVE_GATEWAY + input),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
// Best-effort, as graph-node is: it returns null when its rainbow table
|
|
69
|
+
// doesn't hold the hash, so a lookup failure is a miss, not an error.
|
|
70
|
+
const ensName = createEffect(
|
|
71
|
+
{
|
|
72
|
+
name: "envio_subgraph_ens_name",
|
|
73
|
+
input: Sury.string,
|
|
74
|
+
output: nullableString,
|
|
75
|
+
rateLimit: false,
|
|
76
|
+
cache: true,
|
|
77
|
+
},
|
|
78
|
+
async ({ input }: { input: string }) => {
|
|
79
|
+
try {
|
|
80
|
+
const response = await fetch(ENS_RAINBOW + input);
|
|
81
|
+
if (!response.ok) return null;
|
|
82
|
+
const body = (await response.json()) as { label?: string };
|
|
83
|
+
return body.label ?? null;
|
|
84
|
+
} catch {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const getBalance = createEffect(
|
|
91
|
+
{
|
|
92
|
+
name: "envio_subgraph_eth_balance",
|
|
93
|
+
input: Sury.string,
|
|
94
|
+
output: Sury.string,
|
|
95
|
+
rateLimit: false,
|
|
96
|
+
cache: true,
|
|
97
|
+
crossChain: false,
|
|
98
|
+
},
|
|
99
|
+
async ({ input }: { input: string }) => {
|
|
100
|
+
const { address, blockNumber } = JSON.parse(input);
|
|
101
|
+
const balance = await clientOrThrow("ethereum.getBalance").getBalance({
|
|
102
|
+
address,
|
|
103
|
+
blockNumber: BigInt(blockNumber),
|
|
104
|
+
});
|
|
105
|
+
return balance.toString();
|
|
106
|
+
},
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const hasCode = createEffect(
|
|
110
|
+
{
|
|
111
|
+
name: "envio_subgraph_has_code",
|
|
112
|
+
input: Sury.string,
|
|
113
|
+
output: Sury.boolean,
|
|
114
|
+
rateLimit: false,
|
|
115
|
+
cache: true,
|
|
116
|
+
crossChain: false,
|
|
117
|
+
},
|
|
118
|
+
async ({ input }: { input: string }) => {
|
|
119
|
+
const { address, blockNumber } = JSON.parse(input);
|
|
120
|
+
const code = await clientOrThrow("ethereum.hasCode").getCode({
|
|
121
|
+
address,
|
|
122
|
+
blockNumber: BigInt(blockNumber),
|
|
123
|
+
});
|
|
124
|
+
return code !== undefined && code !== "0x";
|
|
125
|
+
},
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
// Uncached on purpose: a block's timestamp is read exactly once, by that
|
|
129
|
+
// block's own handler invocation, so a persisted row per indexed block would
|
|
130
|
+
// be bloat with no reuse. The in-memory memo still covers replay rounds and
|
|
131
|
+
// the preload -> execute transition.
|
|
132
|
+
const blockTimestamp = createEffect(
|
|
133
|
+
{
|
|
134
|
+
name: "envio_subgraph_block_timestamp",
|
|
135
|
+
input: Sury.number,
|
|
136
|
+
output: Sury.string,
|
|
137
|
+
rateLimit: false,
|
|
138
|
+
cache: false,
|
|
139
|
+
crossChain: false,
|
|
140
|
+
},
|
|
141
|
+
async ({ input, context }: { input: number; context: { chain: { id: number } } }) => {
|
|
142
|
+
const timestamp = await requestBlockTimestamp(context.chain.id, input);
|
|
143
|
+
return timestamp.toString();
|
|
144
|
+
},
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
return { ipfsCat, arweaveData, ensName, getBalance, hasCode, blockTimestamp };
|
|
148
|
+
}
|