@fangorn-network/sdk 2026.8.12-dev → 2026.9.22-dev
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/README.md +175 -62
- package/lib/cli/cli.d.ts +0 -0
- package/lib/cli/cli.js +348 -17
- package/lib/cli/index.d.ts +13 -13
- package/lib/config.d.ts +28 -352
- package/lib/config.js +11 -20
- package/lib/contracts/app-registry/abi.d.ts +509 -0
- package/lib/contracts/app-registry/abi.js +575 -0
- package/lib/contracts/app-registry/index.d.ts +120 -0
- package/lib/contracts/app-registry/index.js +266 -0
- package/lib/contracts/data-registry/abi.d.ts +124 -125
- package/lib/contracts/data-registry/abi.js +145 -142
- package/lib/contracts/data-registry/index.d.ts +20 -27
- package/lib/contracts/data-registry/index.js +32 -78
- package/lib/contracts/index.d.ts +8 -3
- package/lib/contracts/index.js +8 -3
- package/lib/contracts/logs.d.ts +18 -0
- package/lib/contracts/logs.js +25 -0
- package/lib/contracts/settlement-registry/abi.d.ts +430 -11
- package/lib/contracts/settlement-registry/abi.js +528 -41
- package/lib/contracts/settlement-registry/index.d.ts +148 -10
- package/lib/contracts/settlement-registry/index.js +233 -9
- package/lib/contracts/subscription-registry/abi.d.ts +179 -0
- package/lib/contracts/subscription-registry/abi.js +195 -0
- package/lib/contracts/subscription-registry/index.d.ts +59 -0
- package/lib/contracts/subscription-registry/index.js +116 -0
- package/lib/contracts/types.d.ts +8 -0
- package/lib/contracts/types.js +10 -0
- package/lib/contracts/write.d.ts +27 -0
- package/lib/contracts/write.js +55 -0
- package/lib/crypto/encryption.js +4 -4
- package/lib/engine/index.d.ts +14 -12
- package/lib/engine/index.js +13 -7
- package/lib/fangorn.d.ts +71 -6
- package/lib/fangorn.js +86 -7
- package/lib/index.d.ts +9 -4
- package/lib/index.js +9 -4
- package/lib/test/testbed.js +9 -3
- package/lib/types/index.d.ts +6 -0
- package/package.json +73 -85
|
@@ -7,17 +7,12 @@ const DATA_REGISTRY_ABI = [
|
|
|
7
7
|
},
|
|
8
8
|
{
|
|
9
9
|
"inputs": [],
|
|
10
|
-
"name": "
|
|
10
|
+
"name": "NotRegistered",
|
|
11
11
|
"type": "error"
|
|
12
12
|
},
|
|
13
13
|
{
|
|
14
14
|
"inputs": [],
|
|
15
|
-
"name": "
|
|
16
|
-
"type": "error"
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
"inputs": [],
|
|
20
|
-
"name": "NotRegistered",
|
|
15
|
+
"name": "NotRegisteredForApp",
|
|
21
16
|
"type": "error"
|
|
22
17
|
},
|
|
23
18
|
{
|
|
@@ -41,121 +36,19 @@ const DATA_REGISTRY_ABI = [
|
|
|
41
36
|
"type": "error"
|
|
42
37
|
},
|
|
43
38
|
{
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
"internalType": "bytes32",
|
|
48
|
-
"name": "app_id",
|
|
49
|
-
"type": "bytes32"
|
|
50
|
-
}, {
|
|
51
|
-
"indexed": true,
|
|
52
|
-
"internalType": "address",
|
|
53
|
-
"name": "owner",
|
|
54
|
-
"type": "address"
|
|
55
|
-
}],
|
|
56
|
-
"name": "AppRegistered",
|
|
57
|
-
"type": "event"
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
"anonymous": false,
|
|
61
|
-
"inputs": [{
|
|
62
|
-
"indexed": true,
|
|
63
|
-
"internalType": "address",
|
|
64
|
-
"name": "publisher",
|
|
65
|
-
"type": "address"
|
|
66
|
-
}, {
|
|
67
|
-
"indexed": false,
|
|
68
|
-
"internalType": "bytes32",
|
|
69
|
-
"name": "initial_root",
|
|
70
|
-
"type": "bytes32"
|
|
71
|
-
}],
|
|
72
|
-
"name": "PublisherRegistered",
|
|
73
|
-
"type": "event"
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
"anonymous": false,
|
|
77
|
-
"inputs": [{
|
|
78
|
-
"indexed": true,
|
|
79
|
-
"internalType": "address",
|
|
80
|
-
"name": "publisher",
|
|
81
|
-
"type": "address"
|
|
82
|
-
}, {
|
|
83
|
-
"indexed": false,
|
|
84
|
-
"internalType": "bytes32",
|
|
85
|
-
"name": "current_root",
|
|
86
|
-
"type": "bytes32"
|
|
87
|
-
}],
|
|
88
|
-
"name": "PublisherReactivated",
|
|
89
|
-
"type": "event"
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
"anonymous": false,
|
|
93
|
-
"inputs": [{
|
|
94
|
-
"indexed": true,
|
|
39
|
+
"inputs": [],
|
|
40
|
+
"name": "admin",
|
|
41
|
+
"outputs": [{
|
|
95
42
|
"internalType": "address",
|
|
96
|
-
"name": "
|
|
43
|
+
"name": "",
|
|
97
44
|
"type": "address"
|
|
98
45
|
}],
|
|
99
|
-
"
|
|
100
|
-
"type": "
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
"anonymous": false,
|
|
104
|
-
"inputs": [{
|
|
105
|
-
"indexed": false,
|
|
106
|
-
"internalType": "uint256",
|
|
107
|
-
"name": "fee",
|
|
108
|
-
"type": "uint256"
|
|
109
|
-
}],
|
|
110
|
-
"name": "RegistrationFeeChanged",
|
|
111
|
-
"type": "event"
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
"anonymous": false,
|
|
115
|
-
"inputs": [
|
|
116
|
-
{
|
|
117
|
-
"indexed": true,
|
|
118
|
-
"internalType": "bytes32",
|
|
119
|
-
"name": "namespace_key",
|
|
120
|
-
"type": "bytes32"
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
"indexed": true,
|
|
124
|
-
"internalType": "bytes32",
|
|
125
|
-
"name": "app_id",
|
|
126
|
-
"type": "bytes32"
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
"indexed": true,
|
|
130
|
-
"internalType": "address",
|
|
131
|
-
"name": "publisher",
|
|
132
|
-
"type": "address"
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
"indexed": false,
|
|
136
|
-
"internalType": "bytes32",
|
|
137
|
-
"name": "subspace_id",
|
|
138
|
-
"type": "bytes32"
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
"indexed": false,
|
|
142
|
-
"internalType": "bytes32",
|
|
143
|
-
"name": "old_root",
|
|
144
|
-
"type": "bytes32"
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
"indexed": false,
|
|
148
|
-
"internalType": "bytes32",
|
|
149
|
-
"name": "new_root",
|
|
150
|
-
"type": "bytes32"
|
|
151
|
-
}
|
|
152
|
-
],
|
|
153
|
-
"name": "StateCommitted",
|
|
154
|
-
"type": "event"
|
|
46
|
+
"stateMutability": "view",
|
|
47
|
+
"type": "function"
|
|
155
48
|
},
|
|
156
49
|
{
|
|
157
50
|
"inputs": [],
|
|
158
|
-
"name": "
|
|
51
|
+
"name": "appRegistry",
|
|
159
52
|
"outputs": [{
|
|
160
53
|
"internalType": "address",
|
|
161
54
|
"name": "",
|
|
@@ -192,21 +85,6 @@ const DATA_REGISTRY_ABI = [
|
|
|
192
85
|
"stateMutability": "nonpayable",
|
|
193
86
|
"type": "function"
|
|
194
87
|
},
|
|
195
|
-
{
|
|
196
|
-
"inputs": [{
|
|
197
|
-
"internalType": "bytes32",
|
|
198
|
-
"name": "app_id",
|
|
199
|
-
"type": "bytes32"
|
|
200
|
-
}],
|
|
201
|
-
"name": "getAppOwner",
|
|
202
|
-
"outputs": [{
|
|
203
|
-
"internalType": "address",
|
|
204
|
-
"name": "",
|
|
205
|
-
"type": "address"
|
|
206
|
-
}],
|
|
207
|
-
"stateMutability": "view",
|
|
208
|
-
"type": "function"
|
|
209
|
-
},
|
|
210
88
|
{
|
|
211
89
|
"inputs": [
|
|
212
90
|
{
|
|
@@ -282,17 +160,6 @@ const DATA_REGISTRY_ABI = [
|
|
|
282
160
|
"stateMutability": "payable",
|
|
283
161
|
"type": "function"
|
|
284
162
|
},
|
|
285
|
-
{
|
|
286
|
-
"inputs": [{
|
|
287
|
-
"internalType": "bytes32",
|
|
288
|
-
"name": "app_id",
|
|
289
|
-
"type": "bytes32"
|
|
290
|
-
}],
|
|
291
|
-
"name": "registerApp",
|
|
292
|
-
"outputs": [],
|
|
293
|
-
"stateMutability": "nonpayable",
|
|
294
|
-
"type": "function"
|
|
295
|
-
},
|
|
296
163
|
{
|
|
297
164
|
"inputs": [],
|
|
298
165
|
"name": "registrationFee",
|
|
@@ -304,6 +171,45 @@ const DATA_REGISTRY_ABI = [
|
|
|
304
171
|
"stateMutability": "view",
|
|
305
172
|
"type": "function"
|
|
306
173
|
},
|
|
174
|
+
{
|
|
175
|
+
"inputs": [
|
|
176
|
+
{
|
|
177
|
+
"internalType": "bytes32",
|
|
178
|
+
"name": "app_id",
|
|
179
|
+
"type": "bytes32"
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
"internalType": "address",
|
|
183
|
+
"name": "publisher",
|
|
184
|
+
"type": "address"
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
"internalType": "bytes32",
|
|
188
|
+
"name": "subspace_id",
|
|
189
|
+
"type": "bytes32"
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
"internalType": "bytes32",
|
|
193
|
+
"name": "root",
|
|
194
|
+
"type": "bytes32"
|
|
195
|
+
}
|
|
196
|
+
],
|
|
197
|
+
"name": "seedNamespaceHead",
|
|
198
|
+
"outputs": [],
|
|
199
|
+
"stateMutability": "nonpayable",
|
|
200
|
+
"type": "function"
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
"inputs": [{
|
|
204
|
+
"internalType": "address",
|
|
205
|
+
"name": "registry",
|
|
206
|
+
"type": "address"
|
|
207
|
+
}],
|
|
208
|
+
"name": "setAppRegistry",
|
|
209
|
+
"outputs": [],
|
|
210
|
+
"stateMutability": "nonpayable",
|
|
211
|
+
"type": "function"
|
|
212
|
+
},
|
|
307
213
|
{
|
|
308
214
|
"inputs": [{
|
|
309
215
|
"internalType": "uint256",
|
|
@@ -325,6 +231,103 @@ const DATA_REGISTRY_ABI = [
|
|
|
325
231
|
"outputs": [],
|
|
326
232
|
"stateMutability": "nonpayable",
|
|
327
233
|
"type": "function"
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
"anonymous": false,
|
|
237
|
+
"inputs": [{
|
|
238
|
+
"indexed": true,
|
|
239
|
+
"internalType": "address",
|
|
240
|
+
"name": "publisher",
|
|
241
|
+
"type": "address"
|
|
242
|
+
}, {
|
|
243
|
+
"indexed": false,
|
|
244
|
+
"internalType": "bytes32",
|
|
245
|
+
"name": "initial_root",
|
|
246
|
+
"type": "bytes32"
|
|
247
|
+
}],
|
|
248
|
+
"name": "PublisherRegistered",
|
|
249
|
+
"type": "event"
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
"anonymous": false,
|
|
253
|
+
"inputs": [{
|
|
254
|
+
"indexed": true,
|
|
255
|
+
"internalType": "address",
|
|
256
|
+
"name": "publisher",
|
|
257
|
+
"type": "address"
|
|
258
|
+
}, {
|
|
259
|
+
"indexed": false,
|
|
260
|
+
"internalType": "bytes32",
|
|
261
|
+
"name": "current_root",
|
|
262
|
+
"type": "bytes32"
|
|
263
|
+
}],
|
|
264
|
+
"name": "PublisherReactivated",
|
|
265
|
+
"type": "event"
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
"anonymous": false,
|
|
269
|
+
"inputs": [{
|
|
270
|
+
"indexed": true,
|
|
271
|
+
"internalType": "address",
|
|
272
|
+
"name": "publisher",
|
|
273
|
+
"type": "address"
|
|
274
|
+
}],
|
|
275
|
+
"name": "PublisherSuspended",
|
|
276
|
+
"type": "event"
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
"anonymous": false,
|
|
280
|
+
"inputs": [{
|
|
281
|
+
"indexed": false,
|
|
282
|
+
"internalType": "uint256",
|
|
283
|
+
"name": "fee",
|
|
284
|
+
"type": "uint256"
|
|
285
|
+
}],
|
|
286
|
+
"name": "RegistrationFeeChanged",
|
|
287
|
+
"type": "event"
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
"anonymous": false,
|
|
291
|
+
"inputs": [
|
|
292
|
+
{
|
|
293
|
+
"indexed": true,
|
|
294
|
+
"internalType": "bytes32",
|
|
295
|
+
"name": "namespace_key",
|
|
296
|
+
"type": "bytes32"
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
"indexed": true,
|
|
300
|
+
"internalType": "bytes32",
|
|
301
|
+
"name": "app_id",
|
|
302
|
+
"type": "bytes32"
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
"indexed": true,
|
|
306
|
+
"internalType": "address",
|
|
307
|
+
"name": "publisher",
|
|
308
|
+
"type": "address"
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
"indexed": false,
|
|
312
|
+
"internalType": "bytes32",
|
|
313
|
+
"name": "subspace_id",
|
|
314
|
+
"type": "bytes32"
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
"indexed": false,
|
|
318
|
+
"internalType": "bytes32",
|
|
319
|
+
"name": "old_root",
|
|
320
|
+
"type": "bytes32"
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
"indexed": false,
|
|
324
|
+
"internalType": "bytes32",
|
|
325
|
+
"name": "new_root",
|
|
326
|
+
"type": "bytes32"
|
|
327
|
+
}
|
|
328
|
+
],
|
|
329
|
+
"name": "StateCommitted",
|
|
330
|
+
"type": "event"
|
|
328
331
|
}
|
|
329
332
|
];
|
|
330
333
|
|
|
@@ -1,22 +1,15 @@
|
|
|
1
|
+
import { PublisherStatus } from "../types.js";
|
|
1
2
|
import { Address, Hash, Hex, PublicClient, WalletClient } from "viem";
|
|
2
3
|
|
|
3
4
|
//#region src/contracts/data-registry/index.d.ts
|
|
4
|
-
|
|
5
|
-
UNREGISTERED = 0,
|
|
6
|
-
ACTIVE = 1,
|
|
7
|
-
SUSPENDED = 2,
|
|
8
|
-
}
|
|
5
|
+
|
|
9
6
|
/**
|
|
10
|
-
* The
|
|
11
|
-
*
|
|
12
|
-
* sees these 32 bytes.
|
|
7
|
+
* The onchain id of a namespace within an app is the sha256 hash of its hex representation
|
|
8
|
+
* i.e. ns = 'a' => ns_id = sha256(hex('a'))
|
|
13
9
|
*/
|
|
14
10
|
declare function subspaceId(namespace: string): Hex;
|
|
15
11
|
/**
|
|
16
|
-
* The composite storage key
|
|
17
|
-
* Mirrors `namespace_key()` in contracts/data_registry — keccak256 over the
|
|
18
|
-
* packed 84 bytes. Computing it client-side is what lets a subscriber filter
|
|
19
|
-
* one exact subspace with a single indexed topic.
|
|
12
|
+
* The composite storage key for a full path to a subspace: `app:publisher:subspace`.
|
|
20
13
|
*/
|
|
21
14
|
declare function namespaceKey(appId: Hex, publisher: Address, subspace: Hex): Hex;
|
|
22
15
|
/**
|
|
@@ -62,6 +55,15 @@ interface PreparedTx {
|
|
|
62
55
|
maxFeePerGas: Hex;
|
|
63
56
|
maxPriorityFeePerGas: Hex;
|
|
64
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Publisher registration, the state-root timeline, and nothing about apps.
|
|
60
|
+
*
|
|
61
|
+
* `registerApp` and `getAppOwner` used to live here. They are on
|
|
62
|
+
* {@link AppRegistryClient} now, together with the per-app terms and membership
|
|
63
|
+
* they belong with — and `commitStateRoot` cross-calls that contract, so a
|
|
64
|
+
* publisher must join an app before they can write under it. A commit for an app
|
|
65
|
+
* this wallet never joined reverts `NotRegisteredForApp`.
|
|
66
|
+
*/
|
|
65
67
|
declare class DataRegistryClient {
|
|
66
68
|
private contractAddress;
|
|
67
69
|
private appId;
|
|
@@ -72,7 +74,8 @@ declare class DataRegistryClient {
|
|
|
72
74
|
getAppId(): Hex;
|
|
73
75
|
/** Re-scope every subsequent call to a different app. See `Fangorn.setAppId`. */
|
|
74
76
|
setAppId(appId: Hex): void;
|
|
75
|
-
|
|
77
|
+
/** The deployed DataRegistry this client talks to. */
|
|
78
|
+
getAddress(): Address;
|
|
76
79
|
/**
|
|
77
80
|
* Internal helper to execute state-mutating transactions
|
|
78
81
|
* matching the exact gas buffer and aggressive fee styling of the protocol.
|
|
@@ -80,11 +83,6 @@ declare class DataRegistryClient {
|
|
|
80
83
|
private executeWrite;
|
|
81
84
|
/** The composite key for one of this app's namespaces. */
|
|
82
85
|
namespaceKey(publisher: Address, namespace: string): Hex;
|
|
83
|
-
/**
|
|
84
|
-
* Claim this client's `appId` on-chain. First come, first served — an app
|
|
85
|
-
* must own its id before any publisher can commit under it.
|
|
86
|
-
*/
|
|
87
|
-
registerApp(): Promise<Hash>;
|
|
88
86
|
/**
|
|
89
87
|
* Register as a new data publisher or reactivate a suspended account.
|
|
90
88
|
* Automatically reads the required on-chain fee and attaches it to the call.
|
|
@@ -112,8 +110,8 @@ declare class DataRegistryClient {
|
|
|
112
110
|
* namespace within this app.
|
|
113
111
|
*/
|
|
114
112
|
getNamespaceHead(publisher: Address, namespace: string): Promise<Hex>;
|
|
115
|
-
/**
|
|
116
|
-
|
|
113
|
+
/** The AppRegistry this contract defers to for apps and per-app membership. */
|
|
114
|
+
appRegistry(): Promise<Address>;
|
|
117
115
|
/**
|
|
118
116
|
* Reads the explicit enum lifecycle state from the registry status machine.
|
|
119
117
|
*/
|
|
@@ -130,12 +128,7 @@ declare class DataRegistryClient {
|
|
|
130
128
|
* Historical `StateCommitted` logs for one slice of this app, oldest →
|
|
131
129
|
* newest — the catch-up path for a subscriber resuming from a saved block
|
|
132
130
|
* cursor. Node-side filtered by indexed topics, so no indexer is involved.
|
|
133
|
-
*
|
|
134
|
-
* Fetched in windows: RPC providers cap the block span of a single
|
|
135
|
-
* `eth_getLogs` (the public Arbitrum Sepolia endpoint rejects anything past a
|
|
136
|
-
* couple of thousand blocks with a bare "internal server errror"), so one
|
|
137
|
-
* wide-range call fails outright and takes the whole catch-up with it. Tune
|
|
138
|
-
* the window with `FANGORN_LOG_WINDOW` — a private RPC will take far more.
|
|
131
|
+
* Fetched in block windows (see `getLogsInWindows`).
|
|
139
132
|
*/
|
|
140
133
|
getStateCommittedLogs(filter: CommitFilter, fromBlock: bigint, toBlock?: bigint): Promise<StateCommittedLog[]>;
|
|
141
134
|
/**
|
|
@@ -158,4 +151,4 @@ declare class DataRegistryClient {
|
|
|
158
151
|
setRegistrationFee(fee: bigint): Promise<Hash>;
|
|
159
152
|
}
|
|
160
153
|
//#endregion
|
|
161
|
-
export { CommitFilter, DataRegistryClient, PreparedTx,
|
|
154
|
+
export { CommitFilter, DataRegistryClient, PreparedTx, StateCommittedLog, namespaceKey, subspaceId };
|
|
@@ -1,26 +1,18 @@
|
|
|
1
|
+
import { requireWallet, sendWrite } from "../write.js";
|
|
2
|
+
import { getLogsInWindows } from "../logs.js";
|
|
1
3
|
import { DATA_REGISTRY_ABI } from "./abi.js";
|
|
2
4
|
import { concatHex, encodeFunctionData, keccak256, toHex } from "viem";
|
|
3
5
|
|
|
4
6
|
//#region src/contracts/data-registry/index.ts
|
|
5
|
-
let PublisherStatus = /* @__PURE__ */ function(PublisherStatus$1) {
|
|
6
|
-
PublisherStatus$1[PublisherStatus$1["UNREGISTERED"] = 0] = "UNREGISTERED";
|
|
7
|
-
PublisherStatus$1[PublisherStatus$1["ACTIVE"] = 1] = "ACTIVE";
|
|
8
|
-
PublisherStatus$1[PublisherStatus$1["SUSPENDED"] = 2] = "SUSPENDED";
|
|
9
|
-
return PublisherStatus$1;
|
|
10
|
-
}({});
|
|
11
7
|
/**
|
|
12
|
-
* The
|
|
13
|
-
*
|
|
14
|
-
* sees these 32 bytes.
|
|
8
|
+
* The onchain id of a namespace within an app is the sha256 hash of its hex representation
|
|
9
|
+
* i.e. ns = 'a' => ns_id = sha256(hex('a'))
|
|
15
10
|
*/
|
|
16
11
|
function subspaceId(namespace) {
|
|
17
12
|
return keccak256(toHex(namespace));
|
|
18
13
|
}
|
|
19
14
|
/**
|
|
20
|
-
* The composite storage key
|
|
21
|
-
* Mirrors `namespace_key()` in contracts/data_registry — keccak256 over the
|
|
22
|
-
* packed 84 bytes. Computing it client-side is what lets a subscriber filter
|
|
23
|
-
* one exact subspace with a single indexed topic.
|
|
15
|
+
* The composite storage key for a full path to a subspace: `app:publisher:subspace`.
|
|
24
16
|
*/
|
|
25
17
|
function namespaceKey(appId, publisher, subspace) {
|
|
26
18
|
return keccak256(concatHex([
|
|
@@ -43,6 +35,15 @@ function decodeStateCommitted(log) {
|
|
|
43
35
|
logId: `${log.transactionHash}:${log.logIndex.toString()}`
|
|
44
36
|
};
|
|
45
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Publisher registration, the state-root timeline, and nothing about apps.
|
|
40
|
+
*
|
|
41
|
+
* `registerApp` and `getAppOwner` used to live here. They are on
|
|
42
|
+
* {@link AppRegistryClient} now, together with the per-app terms and membership
|
|
43
|
+
* they belong with — and `commitStateRoot` cross-calls that contract, so a
|
|
44
|
+
* publisher must join an app before they can write under it. A commit for an app
|
|
45
|
+
* this wallet never joined reverts `NotRegisteredForApp`.
|
|
46
|
+
*/
|
|
46
47
|
var DataRegistryClient = class {
|
|
47
48
|
constructor(contractAddress, appId, publicClient, walletClient) {
|
|
48
49
|
this.contractAddress = contractAddress;
|
|
@@ -58,56 +59,22 @@ var DataRegistryClient = class {
|
|
|
58
59
|
setAppId(appId) {
|
|
59
60
|
this.appId = appId;
|
|
60
61
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
chain: this.walletClient.chain,
|
|
66
|
-
account: this.walletClient.account
|
|
67
|
-
};
|
|
62
|
+
/** The deployed DataRegistry this client talks to. */
|
|
63
|
+
getAddress() {
|
|
64
|
+
return this.contractAddress;
|
|
68
65
|
}
|
|
69
66
|
/**
|
|
70
67
|
* Internal helper to execute state-mutating transactions
|
|
71
68
|
* matching the exact gas buffer and aggressive fee styling of the protocol.
|
|
72
69
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const fees = await this.publicClient.estimateFeesPerGas();
|
|
76
|
-
const gas = await this.publicClient.estimateContractGas({
|
|
77
|
-
address: this.contractAddress,
|
|
78
|
-
abi: DATA_REGISTRY_ABI,
|
|
79
|
-
functionName,
|
|
80
|
-
args,
|
|
81
|
-
account,
|
|
82
|
-
value
|
|
83
|
-
});
|
|
84
|
-
const hash = await this.walletClient.writeContract({
|
|
85
|
-
address: this.contractAddress,
|
|
86
|
-
abi: DATA_REGISTRY_ABI,
|
|
87
|
-
functionName,
|
|
88
|
-
args,
|
|
89
|
-
chain,
|
|
90
|
-
account,
|
|
91
|
-
gas: gas * 130n / 100n,
|
|
92
|
-
maxFeePerGas: fees.maxFeePerGas * 3n,
|
|
93
|
-
maxPriorityFeePerGas: fees.maxPriorityFeePerGas,
|
|
94
|
-
value
|
|
95
|
-
});
|
|
96
|
-
await this.publicClient.waitForTransactionReceipt({ hash });
|
|
97
|
-
return hash;
|
|
70
|
+
executeWrite(functionName, args, value) {
|
|
71
|
+
return sendWrite(this.publicClient, requireWallet(this.walletClient, functionName), this.contractAddress, DATA_REGISTRY_ABI, functionName, args, value);
|
|
98
72
|
}
|
|
99
73
|
/** The composite key for one of this app's namespaces. */
|
|
100
74
|
namespaceKey(publisher, namespace) {
|
|
101
75
|
return namespaceKey(this.appId, publisher, subspaceId(namespace));
|
|
102
76
|
}
|
|
103
77
|
/**
|
|
104
|
-
* Claim this client's `appId` on-chain. First come, first served — an app
|
|
105
|
-
* must own its id before any publisher can commit under it.
|
|
106
|
-
*/
|
|
107
|
-
async registerApp() {
|
|
108
|
-
return this.executeWrite("registerApp", [this.appId]);
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
78
|
* Register as a new data publisher or reactivate a suspended account.
|
|
112
79
|
* Automatically reads the required on-chain fee and attaches it to the call.
|
|
113
80
|
*/
|
|
@@ -187,13 +154,12 @@ var DataRegistryClient = class {
|
|
|
187
154
|
]
|
|
188
155
|
});
|
|
189
156
|
}
|
|
190
|
-
/**
|
|
191
|
-
async
|
|
157
|
+
/** The AppRegistry this contract defers to for apps and per-app membership. */
|
|
158
|
+
async appRegistry() {
|
|
192
159
|
return this.publicClient.readContract({
|
|
193
160
|
address: this.contractAddress,
|
|
194
161
|
abi: DATA_REGISTRY_ABI,
|
|
195
|
-
functionName: "
|
|
196
|
-
args: [this.appId]
|
|
162
|
+
functionName: "appRegistry"
|
|
197
163
|
});
|
|
198
164
|
}
|
|
199
165
|
/**
|
|
@@ -235,29 +201,17 @@ var DataRegistryClient = class {
|
|
|
235
201
|
* Historical `StateCommitted` logs for one slice of this app, oldest →
|
|
236
202
|
* newest — the catch-up path for a subscriber resuming from a saved block
|
|
237
203
|
* cursor. Node-side filtered by indexed topics, so no indexer is involved.
|
|
238
|
-
*
|
|
239
|
-
* Fetched in windows: RPC providers cap the block span of a single
|
|
240
|
-
* `eth_getLogs` (the public Arbitrum Sepolia endpoint rejects anything past a
|
|
241
|
-
* couple of thousand blocks with a bare "internal server errror"), so one
|
|
242
|
-
* wide-range call fails outright and takes the whole catch-up with it. Tune
|
|
243
|
-
* the window with `FANGORN_LOG_WINDOW` — a private RPC will take far more.
|
|
204
|
+
* Fetched in block windows (see `getLogsInWindows`).
|
|
244
205
|
*/
|
|
245
206
|
async getStateCommittedLogs(filter, fromBlock, toBlock) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
eventName: "StateCommitted",
|
|
255
|
-
args: this.topicsFor(filter),
|
|
256
|
-
fromBlock: start,
|
|
257
|
-
toBlock: stop
|
|
258
|
-
}));
|
|
259
|
-
}
|
|
260
|
-
return logs.map(decodeStateCommitted).filter((log) => matchesFilter(log, filter)).sort((a, b) => a.blockNumber === b.blockNumber ? a.logId.localeCompare(b.logId) : a.blockNumber < b.blockNumber ? -1 : 1);
|
|
207
|
+
return (await getLogsInWindows(this.publicClient, fromBlock, toBlock, (from, to) => this.publicClient.getContractEvents({
|
|
208
|
+
address: this.contractAddress,
|
|
209
|
+
abi: DATA_REGISTRY_ABI,
|
|
210
|
+
eventName: "StateCommitted",
|
|
211
|
+
args: this.topicsFor(filter),
|
|
212
|
+
fromBlock: from,
|
|
213
|
+
toBlock: to
|
|
214
|
+
}))).map(decodeStateCommitted).filter((log) => matchesFilter(log, filter)).sort((a, b) => a.blockNumber === b.blockNumber ? a.logId.localeCompare(b.logId) : a.blockNumber < b.blockNumber ? -1 : 1);
|
|
261
215
|
}
|
|
262
216
|
/**
|
|
263
217
|
* Live-watch `StateCommitted` for one slice of this app. Returns an
|
|
@@ -327,4 +281,4 @@ function matchesFilter(log, filter) {
|
|
|
327
281
|
}
|
|
328
282
|
|
|
329
283
|
//#endregion
|
|
330
|
-
export { DataRegistryClient,
|
|
284
|
+
export { DataRegistryClient, namespaceKey, subspaceId };
|
package/lib/contracts/index.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import { APP_REGISTRY_ABI } from "./app-registry/abi.js";
|
|
2
|
+
import { PublisherStatus } from "./types.js";
|
|
3
|
+
import { CommitFilter, DataRegistryClient, PreparedTx, StateCommittedLog, namespaceKey, subspaceId } from "./data-registry/index.js";
|
|
4
|
+
import { AppAgentLog, AppJoinInfo, AppRegistryClient, needsReacceptance } from "./app-registry/index.js";
|
|
1
5
|
import { DATA_REGISTRY_ABI } from "./data-registry/abi.js";
|
|
2
|
-
import {
|
|
3
|
-
import { SettlementRegistryClient } from "./settlement-registry/index.js";
|
|
6
|
+
import { Resource, SemaphoreProof, SettlementRegistryClient, TransferAuthorization, packResourceUri, resourceIdOf } from "./settlement-registry/index.js";
|
|
4
7
|
import { SETTLEMENT_REGISTRY_ABI } from "./settlement-registry/abi.js";
|
|
5
|
-
|
|
8
|
+
import { SubscriptionAccess, SubscriptionRegistryClient } from "./subscription-registry/index.js";
|
|
9
|
+
import { SUBSCRIPTION_REGISTRY_ABI } from "./subscription-registry/abi.js";
|
|
10
|
+
export { APP_REGISTRY_ABI, AppAgentLog, AppJoinInfo, AppRegistryClient, CommitFilter, DATA_REGISTRY_ABI, DataRegistryClient, PreparedTx, PublisherStatus, Resource, SETTLEMENT_REGISTRY_ABI, SUBSCRIPTION_REGISTRY_ABI, SemaphoreProof, SettlementRegistryClient, StateCommittedLog, SubscriptionAccess, SubscriptionRegistryClient, TransferAuthorization, namespaceKey, needsReacceptance, packResourceUri, resourceIdOf, subspaceId };
|
package/lib/contracts/index.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { APP_REGISTRY_ABI } from "./app-registry/abi.js";
|
|
2
|
+
import { PublisherStatus } from "./types.js";
|
|
3
|
+
import { AppRegistryClient, needsReacceptance } from "./app-registry/index.js";
|
|
1
4
|
import { DATA_REGISTRY_ABI } from "./data-registry/abi.js";
|
|
2
|
-
import { DataRegistryClient,
|
|
5
|
+
import { DataRegistryClient, namespaceKey, subspaceId } from "./data-registry/index.js";
|
|
3
6
|
import { SETTLEMENT_REGISTRY_ABI } from "./settlement-registry/abi.js";
|
|
4
|
-
import { SettlementRegistryClient } from "./settlement-registry/index.js";
|
|
7
|
+
import { SettlementRegistryClient, packResourceUri, resourceIdOf } from "./settlement-registry/index.js";
|
|
8
|
+
import { SUBSCRIPTION_REGISTRY_ABI } from "./subscription-registry/abi.js";
|
|
9
|
+
import { SubscriptionRegistryClient } from "./subscription-registry/index.js";
|
|
5
10
|
|
|
6
|
-
export { DATA_REGISTRY_ABI, DataRegistryClient, PublisherStatus, SETTLEMENT_REGISTRY_ABI, SettlementRegistryClient, namespaceKey, subspaceId };
|
|
11
|
+
export { APP_REGISTRY_ABI, AppRegistryClient, DATA_REGISTRY_ABI, DataRegistryClient, PublisherStatus, SETTLEMENT_REGISTRY_ABI, SUBSCRIPTION_REGISTRY_ABI, SettlementRegistryClient, SubscriptionRegistryClient, namespaceKey, needsReacceptance, packResourceUri, resourceIdOf, subspaceId };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PublicClient } from "viem";
|
|
2
|
+
|
|
3
|
+
//#region src/contracts/logs.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Run `fetch` over [fromBlock, toBlock] in consecutive block windows and
|
|
7
|
+
* concatenate the results, oldest window first.
|
|
8
|
+
*
|
|
9
|
+
* RPC providers limit how many blocks one `eth_getLogs` call can cover. The
|
|
10
|
+
* public Arbitrum Sepolia endpoint rejects anything past a couple of thousand
|
|
11
|
+
* blocks with a bare "internal server errror". So a single wide-range call fails
|
|
12
|
+
* outright, and whatever depends on it (a catch-up, a directory listing) fails
|
|
13
|
+
* with it. Tune the window with `FANGORN_LOG_WINDOW`; a private RPC will take far
|
|
14
|
+
* more.
|
|
15
|
+
*/
|
|
16
|
+
declare function getLogsInWindows<T>(publicClient: PublicClient, fromBlock: bigint, toBlock: bigint | undefined, fetch: (fromBlock: bigint, toBlock: bigint) => Promise<T[]>): Promise<T[]>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { getLogsInWindows };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/contracts/logs.ts
|
|
2
|
+
/**
|
|
3
|
+
* Run `fetch` over [fromBlock, toBlock] in consecutive block windows and
|
|
4
|
+
* concatenate the results, oldest window first.
|
|
5
|
+
*
|
|
6
|
+
* RPC providers limit how many blocks one `eth_getLogs` call can cover. The
|
|
7
|
+
* public Arbitrum Sepolia endpoint rejects anything past a couple of thousand
|
|
8
|
+
* blocks with a bare "internal server errror". So a single wide-range call fails
|
|
9
|
+
* outright, and whatever depends on it (a catch-up, a directory listing) fails
|
|
10
|
+
* with it. Tune the window with `FANGORN_LOG_WINDOW`; a private RPC will take far
|
|
11
|
+
* more.
|
|
12
|
+
*/
|
|
13
|
+
async function getLogsInWindows(publicClient, fromBlock, toBlock, fetch) {
|
|
14
|
+
const window = BigInt((typeof process !== "undefined" ? process.env.FANGORN_LOG_WINDOW : void 0) ?? 1e3);
|
|
15
|
+
const end = toBlock ?? await publicClient.getBlockNumber({ cacheTime: 0 });
|
|
16
|
+
const out = [];
|
|
17
|
+
for (let start = fromBlock; start <= end; start += window) {
|
|
18
|
+
const stop = start + window - 1n < end ? start + window - 1n : end;
|
|
19
|
+
out.push(...await fetch(start, stop));
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { getLogsInWindows };
|