@fangorn-network/sdk 2026.7.29 → 2026.8.18-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 +313 -31
- package/lib/config.d.ts +9 -8
- package/lib/config.js +6 -8
- package/lib/contracts/app-registry/abi.d.ts +466 -0
- package/lib/contracts/app-registry/abi.js +529 -0
- package/lib/contracts/app-registry/index.d.ts +139 -0
- package/lib/contracts/app-registry/index.js +271 -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 +22 -14
- package/lib/contracts/data-registry/index.js +40 -58
- package/lib/contracts/index.d.ts +8 -3
- package/lib/contracts/index.js +8 -3
- 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 +15 -13
- package/lib/engine/index.js +14 -8
- package/lib/fangorn.d.ts +45 -8
- package/lib/fangorn.js +59 -8
- package/lib/index.d.ts +8 -3
- package/lib/index.js +8 -3
- package/lib/test/testbed.js +9 -3
- package/lib/types/index.d.ts +6 -0
- package/package.json +72 -96
|
@@ -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,11 +1,8 @@
|
|
|
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
7
|
* The on-chain id of a namespace within an app: the SDK's human-readable
|
|
11
8
|
* namespace name, hashed. Names never touch storage — the contract only ever
|
|
@@ -62,6 +59,15 @@ interface PreparedTx {
|
|
|
62
59
|
maxFeePerGas: Hex;
|
|
63
60
|
maxPriorityFeePerGas: Hex;
|
|
64
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Publisher registration, the state-root timeline, and nothing about apps.
|
|
64
|
+
*
|
|
65
|
+
* `registerApp` and `getAppOwner` used to live here. They are on
|
|
66
|
+
* {@link AppRegistryClient} now, together with the per-app terms and membership
|
|
67
|
+
* they belong with — and `commitStateRoot` cross-calls that contract, so a
|
|
68
|
+
* publisher must join an app before they can write under it. A commit for an app
|
|
69
|
+
* this wallet never joined reverts `NotRegisteredForApp`.
|
|
70
|
+
*/
|
|
65
71
|
declare class DataRegistryClient {
|
|
66
72
|
private contractAddress;
|
|
67
73
|
private appId;
|
|
@@ -72,7 +78,8 @@ declare class DataRegistryClient {
|
|
|
72
78
|
getAppId(): Hex;
|
|
73
79
|
/** Re-scope every subsequent call to a different app. See `Fangorn.setAppId`. */
|
|
74
80
|
setAppId(appId: Hex): void;
|
|
75
|
-
|
|
81
|
+
/** The deployed DataRegistry this client talks to. */
|
|
82
|
+
getAddress(): Address;
|
|
76
83
|
/**
|
|
77
84
|
* Internal helper to execute state-mutating transactions
|
|
78
85
|
* matching the exact gas buffer and aggressive fee styling of the protocol.
|
|
@@ -80,11 +87,6 @@ declare class DataRegistryClient {
|
|
|
80
87
|
private executeWrite;
|
|
81
88
|
/** The composite key for one of this app's namespaces. */
|
|
82
89
|
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
90
|
/**
|
|
89
91
|
* Register as a new data publisher or reactivate a suspended account.
|
|
90
92
|
* Automatically reads the required on-chain fee and attaches it to the call.
|
|
@@ -112,8 +114,8 @@ declare class DataRegistryClient {
|
|
|
112
114
|
* namespace within this app.
|
|
113
115
|
*/
|
|
114
116
|
getNamespaceHead(publisher: Address, namespace: string): Promise<Hex>;
|
|
115
|
-
/**
|
|
116
|
-
|
|
117
|
+
/** The AppRegistry this contract defers to for apps and per-app membership. */
|
|
118
|
+
appRegistry(): Promise<Address>;
|
|
117
119
|
/**
|
|
118
120
|
* Reads the explicit enum lifecycle state from the registry status machine.
|
|
119
121
|
*/
|
|
@@ -130,6 +132,12 @@ declare class DataRegistryClient {
|
|
|
130
132
|
* Historical `StateCommitted` logs for one slice of this app, oldest →
|
|
131
133
|
* newest — the catch-up path for a subscriber resuming from a saved block
|
|
132
134
|
* cursor. Node-side filtered by indexed topics, so no indexer is involved.
|
|
135
|
+
*
|
|
136
|
+
* Fetched in windows: RPC providers cap the block span of a single
|
|
137
|
+
* `eth_getLogs` (the public Arbitrum Sepolia endpoint rejects anything past a
|
|
138
|
+
* couple of thousand blocks with a bare "internal server errror"), so one
|
|
139
|
+
* wide-range call fails outright and takes the whole catch-up with it. Tune
|
|
140
|
+
* the window with `FANGORN_LOG_WINDOW` — a private RPC will take far more.
|
|
133
141
|
*/
|
|
134
142
|
getStateCommittedLogs(filter: CommitFilter, fromBlock: bigint, toBlock?: bigint): Promise<StateCommittedLog[]>;
|
|
135
143
|
/**
|
|
@@ -152,4 +160,4 @@ declare class DataRegistryClient {
|
|
|
152
160
|
setRegistrationFee(fee: bigint): Promise<Hash>;
|
|
153
161
|
}
|
|
154
162
|
//#endregion
|
|
155
|
-
export { CommitFilter, DataRegistryClient, PreparedTx,
|
|
163
|
+
export { CommitFilter, DataRegistryClient, PreparedTx, StateCommittedLog, namespaceKey, subspaceId };
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
+
import { requireWallet, sendWrite } from "../write.js";
|
|
1
2
|
import { DATA_REGISTRY_ABI } from "./abi.js";
|
|
2
3
|
import { concatHex, encodeFunctionData, keccak256, toHex } from "viem";
|
|
3
4
|
|
|
4
5
|
//#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
6
|
/**
|
|
12
7
|
* The on-chain id of a namespace within an app: the SDK's human-readable
|
|
13
8
|
* namespace name, hashed. Names never touch storage — the contract only ever
|
|
@@ -43,6 +38,15 @@ function decodeStateCommitted(log) {
|
|
|
43
38
|
logId: `${log.transactionHash}:${log.logIndex.toString()}`
|
|
44
39
|
};
|
|
45
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Publisher registration, the state-root timeline, and nothing about apps.
|
|
43
|
+
*
|
|
44
|
+
* `registerApp` and `getAppOwner` used to live here. They are on
|
|
45
|
+
* {@link AppRegistryClient} now, together with the per-app terms and membership
|
|
46
|
+
* they belong with — and `commitStateRoot` cross-calls that contract, so a
|
|
47
|
+
* publisher must join an app before they can write under it. A commit for an app
|
|
48
|
+
* this wallet never joined reverts `NotRegisteredForApp`.
|
|
49
|
+
*/
|
|
46
50
|
var DataRegistryClient = class {
|
|
47
51
|
constructor(contractAddress, appId, publicClient, walletClient) {
|
|
48
52
|
this.contractAddress = contractAddress;
|
|
@@ -58,56 +62,22 @@ var DataRegistryClient = class {
|
|
|
58
62
|
setAppId(appId) {
|
|
59
63
|
this.appId = appId;
|
|
60
64
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
chain: this.walletClient.chain,
|
|
66
|
-
account: this.walletClient.account
|
|
67
|
-
};
|
|
65
|
+
/** The deployed DataRegistry this client talks to. */
|
|
66
|
+
getAddress() {
|
|
67
|
+
return this.contractAddress;
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
70
|
* Internal helper to execute state-mutating transactions
|
|
71
71
|
* matching the exact gas buffer and aggressive fee styling of the protocol.
|
|
72
72
|
*/
|
|
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;
|
|
73
|
+
executeWrite(functionName, args, value) {
|
|
74
|
+
return sendWrite(this.publicClient, requireWallet(this.walletClient, functionName), this.contractAddress, DATA_REGISTRY_ABI, functionName, args, value);
|
|
98
75
|
}
|
|
99
76
|
/** The composite key for one of this app's namespaces. */
|
|
100
77
|
namespaceKey(publisher, namespace) {
|
|
101
78
|
return namespaceKey(this.appId, publisher, subspaceId(namespace));
|
|
102
79
|
}
|
|
103
80
|
/**
|
|
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
81
|
* Register as a new data publisher or reactivate a suspended account.
|
|
112
82
|
* Automatically reads the required on-chain fee and attaches it to the call.
|
|
113
83
|
*/
|
|
@@ -187,13 +157,12 @@ var DataRegistryClient = class {
|
|
|
187
157
|
]
|
|
188
158
|
});
|
|
189
159
|
}
|
|
190
|
-
/**
|
|
191
|
-
async
|
|
160
|
+
/** The AppRegistry this contract defers to for apps and per-app membership. */
|
|
161
|
+
async appRegistry() {
|
|
192
162
|
return this.publicClient.readContract({
|
|
193
163
|
address: this.contractAddress,
|
|
194
164
|
abi: DATA_REGISTRY_ABI,
|
|
195
|
-
functionName: "
|
|
196
|
-
args: [this.appId]
|
|
165
|
+
functionName: "appRegistry"
|
|
197
166
|
});
|
|
198
167
|
}
|
|
199
168
|
/**
|
|
@@ -235,16 +204,29 @@ var DataRegistryClient = class {
|
|
|
235
204
|
* Historical `StateCommitted` logs for one slice of this app, oldest →
|
|
236
205
|
* newest — the catch-up path for a subscriber resuming from a saved block
|
|
237
206
|
* cursor. Node-side filtered by indexed topics, so no indexer is involved.
|
|
207
|
+
*
|
|
208
|
+
* Fetched in windows: RPC providers cap the block span of a single
|
|
209
|
+
* `eth_getLogs` (the public Arbitrum Sepolia endpoint rejects anything past a
|
|
210
|
+
* couple of thousand blocks with a bare "internal server errror"), so one
|
|
211
|
+
* wide-range call fails outright and takes the whole catch-up with it. Tune
|
|
212
|
+
* the window with `FANGORN_LOG_WINDOW` — a private RPC will take far more.
|
|
238
213
|
*/
|
|
239
214
|
async getStateCommittedLogs(filter, fromBlock, toBlock) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
215
|
+
const window = BigInt(process.env.FANGORN_LOG_WINDOW ?? 1e3);
|
|
216
|
+
const end = toBlock ?? await this.publicClient.getBlockNumber();
|
|
217
|
+
const logs = [];
|
|
218
|
+
for (let start = fromBlock; start <= end; start += window) {
|
|
219
|
+
const stop = start + window - 1n < end ? start + window - 1n : end;
|
|
220
|
+
logs.push(...await this.publicClient.getContractEvents({
|
|
221
|
+
address: this.contractAddress,
|
|
222
|
+
abi: DATA_REGISTRY_ABI,
|
|
223
|
+
eventName: "StateCommitted",
|
|
224
|
+
args: this.topicsFor(filter),
|
|
225
|
+
fromBlock: start,
|
|
226
|
+
toBlock: stop
|
|
227
|
+
}));
|
|
228
|
+
}
|
|
229
|
+
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);
|
|
248
230
|
}
|
|
249
231
|
/**
|
|
250
232
|
* Live-watch `StateCommitted` for one slice of this app. Returns an
|
|
@@ -314,4 +296,4 @@ function matchesFilter(log, filter) {
|
|
|
314
296
|
}
|
|
315
297
|
|
|
316
298
|
//#endregion
|
|
317
|
-
export { DataRegistryClient,
|
|
299
|
+
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 { 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, 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 };
|