@fangorn-network/sdk 2026.10.28 → 2026.11.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.
Files changed (68) hide show
  1. package/README.md +37 -653
  2. package/lib/cli/cli.js +46 -357
  3. package/lib/cli/index.d.ts +1 -4
  4. package/lib/cli/index.js +2 -20
  5. package/lib/cli/sell.d.ts +28 -0
  6. package/lib/cli/sell.js +95 -0
  7. package/lib/config.d.ts +163 -226
  8. package/lib/config.js +8 -35
  9. package/lib/contracts/data-registry/abi.d.ts +206 -6
  10. package/lib/contracts/data-registry/abi.js +415 -186
  11. package/lib/contracts/data-registry/index.d.ts +126 -2
  12. package/lib/contracts/data-registry/index.js +174 -1
  13. package/lib/contracts/index.d.ts +4 -7
  14. package/lib/contracts/index.js +4 -7
  15. package/lib/contracts/logs.d.ts +1 -1
  16. package/lib/contracts/logs.js +1 -1
  17. package/lib/contracts/{membership-registry → settlement-registry}/abi.d.ts +288 -637
  18. package/lib/contracts/settlement-registry/abi.js +947 -0
  19. package/lib/contracts/settlement-registry/index.d.ts +141 -0
  20. package/lib/contracts/settlement-registry/index.js +209 -0
  21. package/lib/crypto/aes.d.ts +2 -2
  22. package/lib/crypto/aes.js +4 -4
  23. package/lib/crypto/encryption.d.ts +8 -109
  24. package/lib/crypto/encryption.js +16 -114
  25. package/lib/crypto/paid.d.ts +104 -0
  26. package/lib/crypto/paid.js +147 -0
  27. package/lib/engine/index.d.ts +23 -12
  28. package/lib/engine/index.js +68 -29
  29. package/lib/engine/records.d.ts +4 -7
  30. package/lib/engine/records.js +6 -6
  31. package/lib/engine/test-helpers.d.ts +2 -3
  32. package/lib/engine/test-helpers.js +7 -5
  33. package/lib/erc8004.js +7 -10
  34. package/lib/fangorn.d.ts +65 -96
  35. package/lib/fangorn.js +110 -168
  36. package/lib/feed.d.ts +7 -8
  37. package/lib/feed.js +7 -8
  38. package/lib/index.d.ts +10 -13
  39. package/lib/index.js +10 -13
  40. package/lib/providers/storage/signed-url.d.ts +2 -10
  41. package/lib/providers/storage/signed-url.js +5 -15
  42. package/lib/providers/storage/types.d.ts +1 -1
  43. package/lib/providers/storage/utils.js +5 -3
  44. package/lib/test/key-server.d.ts +12 -0
  45. package/lib/test/key-server.js +30 -0
  46. package/lib/test/mem-registry.d.ts +14 -19
  47. package/lib/test/mem-registry.js +44 -37
  48. package/lib/test/sdk-suite.d.ts +1 -4
  49. package/lib/test/sdk-suite.js +16 -87
  50. package/lib/test/testbed.d.ts +35 -45
  51. package/lib/test/testbed.js +29 -56
  52. package/lib/types/index.d.ts +6 -11
  53. package/package.json +2 -5
  54. package/lib/contracts/app-registry/abi.d.ts +0 -1306
  55. package/lib/contracts/app-registry/abi.js +0 -1493
  56. package/lib/contracts/app-registry/index.d.ts +0 -200
  57. package/lib/contracts/app-registry/index.js +0 -325
  58. package/lib/contracts/membership-registry/abi.js +0 -1333
  59. package/lib/contracts/membership-registry/index.d.ts +0 -79
  60. package/lib/contracts/membership-registry/index.js +0 -104
  61. package/lib/contracts/types.d.ts +0 -8
  62. package/lib/contracts/types.js +0 -10
  63. package/lib/harness/examples/hackmd/build-markdown-graph.d.ts +0 -1
  64. package/lib/harness/examples/hackmd/build-markdown-graph.js +0 -17
  65. package/lib/harness/index.d.ts +0 -58
  66. package/lib/harness/index.js +0 -73
  67. package/lib/registry.d.ts +0 -118
  68. package/lib/registry.js +0 -184
@@ -1,200 +0,0 @@
1
- import { PublisherStatus } from "../types.js";
2
- import { PreparedTx } from "../write.js";
3
- import { Address, Hash, Hex, PublicClient, WalletClient } from "viem";
4
-
5
- //#region src/contracts/app-registry/index.d.ts
6
- /** What the upload gate needs to decide whether to serve a publisher under an app. */
7
- interface AppAccess {
8
- /** May publish to the app now (see `canPublish`). */
9
- canPublish: boolean;
10
- /** The app's owner, or the zero address for an unclaimed app. */
11
- owner: Address;
12
- /** Unix seconds the app's subscription expires at; 0 if unclaimed or cancelled. */
13
- expiresAt: bigint;
14
- }
15
- /** One `AppAgentChanged` event: an app owner pointed their app at a card. */
16
- interface AppAgentLog {
17
- appId: Hex;
18
- agentUri: string;
19
- blockNumber: bigint;
20
- transactionHash: Hash;
21
- }
22
- /**
23
- * Client for the AppRegistry's app management: apps and their ERC-5643
24
- * subscriptions, the publishers each app accepts, the agent card, and the
25
- * protocol admin's powers.
26
- *
27
- * An app can be renamed (`renameApp`): the new id is an alias of the id the app
28
- * was claimed under, its canonical id. The contract accepts any id an app has gone
29
- * by, so this client may be scoped to any of them; what the contract keys by the
30
- * canonical id alone (the token, events) is resolved here first.
31
- *
32
- * What an app presents — its members, less exclusions — is read through the
33
- * registry (`ChainRegistry`), not this client.
34
- *
35
- * Scoped to one app, which may be unset: then only the calls that take no app work.
36
- */
37
- declare class AppRegistryClient {
38
- private contractAddress;
39
- private appId;
40
- private publicClient;
41
- private walletClient;
42
- private logWindow?;
43
- constructor(contractAddress: Address, appId: Hex | undefined, publicClient: PublicClient, walletClient: WalletClient, logWindow?: bigint | undefined);
44
- getAppId(): Hex | undefined;
45
- setAppId(appId: Hex | undefined): void;
46
- getAddress(): Address;
47
- /** This client's app, or a clear error for a call that needs one. */
48
- private app;
49
- /**
50
- * The app's subscription token: its canonical id, as a number. Not the id
51
- * passed in, if that is an id the app was renamed to.
52
- */
53
- tokenId(appId?: Hex): Promise<bigint>;
54
- private executeWrite;
55
- private read;
56
- /**
57
- * Claim this app, if nobody has. Claiming IS subscribing: it pays one period
58
- * of `subscriptionFee()` in USDC and mints the app's token to the caller,
59
- * who becomes the app's first accepted publisher.
60
- *
61
- * The fee read now is approved and passed as the most the claim may cost,
62
- * so a fee raised in the meantime makes the claim revert instead of charging
63
- * more.
64
- */
65
- registerApp(): Promise<Hash>;
66
- /**
67
- * Pay for one more period (the owner, or an address they approved for the
68
- * app's token). Allowed once less than a period is left; the period is added
69
- * to the current expiry, or to now if it has passed.
70
- *
71
- * The standard gives the contract no maximum-fee argument, so the allowance
72
- * is the cap: exactly the fee read now is approved.
73
- */
74
- renewSubscription(): Promise<Hash>;
75
- /**
76
- * End this app's subscription now (owner only): the expiry becomes zero and
77
- * nothing is refunded. Until it is renewed the app provides no storage and includes nothing.
78
- */
79
- cancelSubscription(): Promise<Hash>;
80
- /** Unix seconds this app's subscription expires at; 0 once cancelled. Reverts for an unclaimed app. */
81
- expiresAt(appId?: Hex): Promise<bigint>;
82
- /** True while less than one period is left, or the subscription has expired. */
83
- isRenewable(): Promise<boolean>;
84
- /** How long one payment lasts, in seconds. */
85
- subscriptionPeriod(): Promise<bigint>;
86
- /** What claiming or renewing an app costs, in USDC base units (6 decimals), not wei. */
87
- subscriptionFee(): Promise<bigint>;
88
- /** The ERC-20 token (USDC) every fee is paid in. */
89
- usdc(): Promise<Address>;
90
- getAppOwner(appId?: Hex): Promise<Address>;
91
- /**
92
- * Give this app a new id (owner only). Nothing moves: `newId` becomes an
93
- * alias of the canonical id, so the app's publishers, exclusions,
94
- * subscription and token carry on, and every id it went by still resolves to
95
- * it. `newId` must be unclaimed, or an id this app already goes by (renaming
96
- * back); one held by another app reverts `AppAlreadyRegistered`.
97
- *
98
- * This client stays scoped to the id it had, which still works; switch it
99
- * with `setAppId(newId)`.
100
- */
101
- renameApp(newId: Hex): Promise<Hash>;
102
- /** The id this app (or `appId`) was claimed under. An id no app goes by comes back unchanged. */
103
- canonicalAppId(appId?: Hex): Promise<Hex>;
104
- /**
105
- * The id this app (or `appId`) goes by now: the last it was renamed to, or its
106
- * canonical id. An id no app goes by comes back unchanged.
107
- */
108
- currentAppId(appId?: Hex): Promise<Hex>;
109
- /** How many apps have been claimed. A rename adds none. */
110
- appCount(): Promise<bigint>;
111
- /** Up to `limit` canonical app ids from position `offset`, oldest first; fewer past the end. */
112
- appsPage(offset: bigint, limit: bigint): Promise<readonly Hex[]>;
113
- /**
114
- * Every claimed app id (canonical; see `currentAppId`), oldest first.
115
- * ponytail: one eth_call for all of them; page with `appsPage` once the list
116
- * outgrows the RPC's eth_call gas cap (tens of thousands of apps).
117
- */
118
- allApps(): Promise<readonly Hex[]>;
119
- /** The app ids `owner` claimed (canonical; see `currentAppId`), oldest first. */
120
- appsOf(owner: Address): Promise<readonly Hex[]>;
121
- /**
122
- * Point this app at its ERC-8004 agent card.
123
- *
124
- * Safe to call whenever the card moves: it leaves the app's publishers alone.
125
- */
126
- setAppAgentUri(agentUri: string): Promise<Hash>;
127
- isAppSuspended(): Promise<boolean>;
128
- /** The agent card URI of this app, or of `appId`. Empty if none is set. */
129
- appAgentUri(appId?: Hex): Promise<string>;
130
- /**
131
- * Accept a publisher into this app (owner only). That is the whole
132
- * membership: from here it uploads with storage the app provides, and the app
133
- * includes its data, while `canPublish` holds. A suspended publisher comes
134
- * back with `setPublisherSuspended(publisher, false)`.
135
- */
136
- acceptPublisher(publisher: Address): Promise<Hash>;
137
- /**
138
- * Suspend an accepted publisher from this app, or reinstate them (owner
139
- * only). An owner cannot suspend themselves.
140
- */
141
- setPublisherSuspended(publisher: Address, suspended: boolean): Promise<Hash>;
142
- /** `publisher`'s standing in this app. */
143
- status(publisher: Address): Promise<PublisherStatus>;
144
- /**
145
- * May `publisher` publish to this app now: accepted and not suspended, not
146
- * banned network-wide, and the app is live and paid up.
147
- */
148
- canPublish(publisher: Address, appId?: Hex): Promise<boolean>;
149
- /** The single oracle the upload gate reads for one publisher under this app. */
150
- access(publisher: Address, appId?: Hex): Promise<AppAccess>;
151
- /**
152
- * `AppAgentChanged` events, oldest first. The last one for an app is its
153
- * current card; an empty `agentUri` means the owner unset it.
154
- *
155
- * Events carry the canonical id: `appId` may be any id the app goes by, and
156
- * each log's `appId` is the canonical one.
157
- *
158
- * Leave `appId` out to list every app that has ever set a card. To list apps,
159
- * use `allApps` or `appsOf`, which are one read each; this is a windowed log
160
- * scan, for a card's history. `fromBlock` is required because scanning from genesis on an L2 costs
161
- * hundreds of thousands of RPC calls. Pass the AppRegistry's deploy block, or
162
- * a block you know to be before the app's registration.
163
- */
164
- getAppAgentLogs(opts: {
165
- appId?: Hex;
166
- fromBlock: bigint;
167
- toBlock?: bigint;
168
- }): Promise<AppAgentLog[]>;
169
- admin(): Promise<Address>;
170
- /** The DataRegistry this contract names. */
171
- dataRegistry(): Promise<Address>;
172
- /** Whether the protocol admin has banned `wallet` network-wide. */
173
- isGloballySuspended(wallet: Address): Promise<boolean>;
174
- /**
175
- * Ban `wallet` network-wide, or lift the ban. A banned wallet cannot claim an
176
- * app or be accepted into one, and no app stores or includes it; a banned
177
- * owner's app keeps running, but they cannot accept anyone or move its agent card.
178
- */
179
- setGlobalSuspension(wallet: Address, suspended: boolean): Promise<Hash>;
180
- /** Take this app down for every publisher at once, or restore it. */
181
- setAppSuspended(suspended: boolean): Promise<Hash>;
182
- setDataRegistry(registry: Address): Promise<Hash>;
183
- setSubscriptionFee(fee: bigint): Promise<Hash>;
184
- /** Applies from each app's next payment. */
185
- setSubscriptionPeriod(period: bigint): Promise<Hash>;
186
- /**
187
- * Send `amount` of `token` to `to`. Of USDC, only the protocol's share: what
188
- * app owners are owed in join fees stays (`ExceedsProtocolBalance`).
189
- */
190
- withdrawToken(token: Address, to: Address, amount: bigint): Promise<Hash>;
191
- /**
192
- * Fees are pulled with `transferFrom`, so the registry needs an allowance.
193
- * Without one the call reverts with a fee error that reads like a pricing
194
- * problem but is really an allowance one. Approves exactly `amount`.
195
- */
196
- private approveUsdc;
197
- private senderAddress;
198
- }
199
- //#endregion
200
- export { AppAccess, AppAgentLog, AppRegistryClient, type PreparedTx };
@@ -1,325 +0,0 @@
1
- import { APP_REGISTRY_ABI } from "./abi.js";
2
- import { requireWallet, sendWrite } from "../write.js";
3
- import { getLogsInWindows } from "../logs.js";
4
- import { erc20Abi, hexToBigInt } from "viem";
5
-
6
- //#region src/contracts/app-registry/index.ts
7
- /**
8
- * Client for the AppRegistry's app management: apps and their ERC-5643
9
- * subscriptions, the publishers each app accepts, the agent card, and the
10
- * protocol admin's powers.
11
- *
12
- * An app can be renamed (`renameApp`): the new id is an alias of the id the app
13
- * was claimed under, its canonical id. The contract accepts any id an app has gone
14
- * by, so this client may be scoped to any of them; what the contract keys by the
15
- * canonical id alone (the token, events) is resolved here first.
16
- *
17
- * What an app presents — its members, less exclusions — is read through the
18
- * registry (`ChainRegistry`), not this client.
19
- *
20
- * Scoped to one app, which may be unset: then only the calls that take no app work.
21
- */
22
- var AppRegistryClient = class {
23
- constructor(contractAddress, appId, publicClient, walletClient, logWindow) {
24
- this.contractAddress = contractAddress;
25
- this.appId = appId;
26
- this.publicClient = publicClient;
27
- this.walletClient = walletClient;
28
- this.logWindow = logWindow;
29
- }
30
- getAppId() {
31
- return this.appId;
32
- }
33
- setAppId(appId) {
34
- this.appId = appId;
35
- }
36
- getAddress() {
37
- return this.contractAddress;
38
- }
39
- /** This client's app, or a clear error for a call that needs one. */
40
- app() {
41
- if (!this.appId) throw new Error("no app chosen: pass `appId` to Fangorn.create() or call setAppId()");
42
- return this.appId;
43
- }
44
- /**
45
- * The app's subscription token: its canonical id, as a number. Not the id
46
- * passed in, if that is an id the app was renamed to.
47
- */
48
- async tokenId(appId = this.app()) {
49
- return hexToBigInt(await this.canonicalAppId(appId));
50
- }
51
- executeWrite(functionName, args) {
52
- return sendWrite(this.publicClient, requireWallet(this.walletClient, functionName), this.contractAddress, APP_REGISTRY_ABI, functionName, args);
53
- }
54
- read(functionName, args) {
55
- return this.publicClient.readContract({
56
- address: this.contractAddress,
57
- abi: APP_REGISTRY_ABI,
58
- functionName,
59
- args
60
- });
61
- }
62
- /**
63
- * Claim this app, if nobody has. Claiming IS subscribing: it pays one period
64
- * of `subscriptionFee()` in USDC and mints the app's token to the caller,
65
- * who becomes the app's first accepted publisher.
66
- *
67
- * The fee read now is approved and passed as the most the claim may cost,
68
- * so a fee raised in the meantime makes the claim revert instead of charging
69
- * more.
70
- */
71
- async registerApp() {
72
- const fee = await this.subscriptionFee();
73
- await this.approveUsdc(fee);
74
- return this.executeWrite("registerApp", [this.app(), fee]);
75
- }
76
- /**
77
- * Pay for one more period (the owner, or an address they approved for the
78
- * app's token). Allowed once less than a period is left; the period is added
79
- * to the current expiry, or to now if it has passed.
80
- *
81
- * The standard gives the contract no maximum-fee argument, so the allowance
82
- * is the cap: exactly the fee read now is approved.
83
- */
84
- async renewSubscription() {
85
- const [renewable, period, fee] = await Promise.all([
86
- this.isRenewable(),
87
- this.subscriptionPeriod(),
88
- this.subscriptionFee()
89
- ]);
90
- if (!renewable) {
91
- const expiry = await this.expiresAt();
92
- throw new Error(`app ${this.app()} cannot be renewed until less than one period is left — it expires ${(/* @__PURE__ */ new Date(Number(expiry) * 1e3)).toISOString()}`);
93
- }
94
- const tokenId = await this.tokenId();
95
- await this.approveUsdc(fee);
96
- return this.executeWrite("renewSubscription", [tokenId, period]);
97
- }
98
- /**
99
- * End this app's subscription now (owner only): the expiry becomes zero and
100
- * nothing is refunded. Until it is renewed the app provides no storage and includes nothing.
101
- */
102
- async cancelSubscription() {
103
- return this.executeWrite("cancelSubscription", [await this.tokenId()]);
104
- }
105
- /** Unix seconds this app's subscription expires at; 0 once cancelled. Reverts for an unclaimed app. */
106
- async expiresAt(appId = this.app()) {
107
- return this.read("expiresAt", [await this.tokenId(appId)]);
108
- }
109
- /** True while less than one period is left, or the subscription has expired. */
110
- async isRenewable() {
111
- return this.read("isRenewable", [await this.tokenId()]);
112
- }
113
- /** How long one payment lasts, in seconds. */
114
- async subscriptionPeriod() {
115
- return this.read("subscriptionPeriod", []);
116
- }
117
- /** What claiming or renewing an app costs, in USDC base units (6 decimals), not wei. */
118
- async subscriptionFee() {
119
- return this.read("subscriptionFee", []);
120
- }
121
- /** The ERC-20 token (USDC) every fee is paid in. */
122
- async usdc() {
123
- return this.read("usdc", []);
124
- }
125
- async getAppOwner(appId = this.app()) {
126
- return this.read("getAppOwner", [appId]);
127
- }
128
- /**
129
- * Give this app a new id (owner only). Nothing moves: `newId` becomes an
130
- * alias of the canonical id, so the app's publishers, exclusions,
131
- * subscription and token carry on, and every id it went by still resolves to
132
- * it. `newId` must be unclaimed, or an id this app already goes by (renaming
133
- * back); one held by another app reverts `AppAlreadyRegistered`.
134
- *
135
- * This client stays scoped to the id it had, which still works; switch it
136
- * with `setAppId(newId)`.
137
- */
138
- async renameApp(newId) {
139
- return this.executeWrite("renameApp", [this.app(), newId]);
140
- }
141
- /** The id this app (or `appId`) was claimed under. An id no app goes by comes back unchanged. */
142
- async canonicalAppId(appId = this.app()) {
143
- return this.read("canonicalAppId", [appId]);
144
- }
145
- /**
146
- * The id this app (or `appId`) goes by now: the last it was renamed to, or its
147
- * canonical id. An id no app goes by comes back unchanged.
148
- */
149
- async currentAppId(appId = this.app()) {
150
- return this.read("currentAppId", [appId]);
151
- }
152
- /** How many apps have been claimed. A rename adds none. */
153
- async appCount() {
154
- return this.read("appCount", []);
155
- }
156
- /** Up to `limit` canonical app ids from position `offset`, oldest first; fewer past the end. */
157
- async appsPage(offset, limit) {
158
- return this.read("appsPage", [offset, limit]);
159
- }
160
- /**
161
- * Every claimed app id (canonical; see `currentAppId`), oldest first.
162
- * ponytail: one eth_call for all of them; page with `appsPage` once the list
163
- * outgrows the RPC's eth_call gas cap (tens of thousands of apps).
164
- */
165
- async allApps() {
166
- return this.appsPage(0n, await this.appCount());
167
- }
168
- /** The app ids `owner` claimed (canonical; see `currentAppId`), oldest first. */
169
- async appsOf(owner) {
170
- return this.read("appsOf", [owner]);
171
- }
172
- /**
173
- * Point this app at its ERC-8004 agent card.
174
- *
175
- * Safe to call whenever the card moves: it leaves the app's publishers alone.
176
- */
177
- async setAppAgentUri(agentUri) {
178
- return this.executeWrite("setAppAgentUri", [this.app(), agentUri]);
179
- }
180
- async isAppSuspended() {
181
- return this.read("isAppSuspended", [this.app()]);
182
- }
183
- /** The agent card URI of this app, or of `appId`. Empty if none is set. */
184
- async appAgentUri(appId = this.app()) {
185
- return this.read("appAgentUri", [appId]);
186
- }
187
- /**
188
- * Accept a publisher into this app (owner only). That is the whole
189
- * membership: from here it uploads with storage the app provides, and the app
190
- * includes its data, while `canPublish` holds. A suspended publisher comes
191
- * back with `setPublisherSuspended(publisher, false)`.
192
- */
193
- async acceptPublisher(publisher) {
194
- return this.executeWrite("acceptPublisher", [this.app(), publisher]);
195
- }
196
- /**
197
- * Suspend an accepted publisher from this app, or reinstate them (owner
198
- * only). An owner cannot suspend themselves.
199
- */
200
- async setPublisherSuspended(publisher, suspended) {
201
- return this.executeWrite("setPublisherSuspended", [
202
- this.app(),
203
- publisher,
204
- suspended
205
- ]);
206
- }
207
- /** `publisher`'s standing in this app. */
208
- async status(publisher) {
209
- return await this.read("statusForApp", [this.app(), publisher]);
210
- }
211
- /**
212
- * May `publisher` publish to this app now: accepted and not suspended, not
213
- * banned network-wide, and the app is live and paid up.
214
- */
215
- async canPublish(publisher, appId = this.app()) {
216
- return this.read("canPublish", [appId, publisher]);
217
- }
218
- /** The single oracle the upload gate reads for one publisher under this app. */
219
- async access(publisher, appId = this.app()) {
220
- const [canPublish, owner, expiresAt] = await this.read("access", [appId, publisher]);
221
- return {
222
- canPublish,
223
- owner,
224
- expiresAt
225
- };
226
- }
227
- /**
228
- * `AppAgentChanged` events, oldest first. The last one for an app is its
229
- * current card; an empty `agentUri` means the owner unset it.
230
- *
231
- * Events carry the canonical id: `appId` may be any id the app goes by, and
232
- * each log's `appId` is the canonical one.
233
- *
234
- * Leave `appId` out to list every app that has ever set a card. To list apps,
235
- * use `allApps` or `appsOf`, which are one read each; this is a windowed log
236
- * scan, for a card's history. `fromBlock` is required because scanning from genesis on an L2 costs
237
- * hundreds of thousands of RPC calls. Pass the AppRegistry's deploy block, or
238
- * a block you know to be before the app's registration.
239
- */
240
- async getAppAgentLogs(opts) {
241
- const appId = opts.appId && await this.canonicalAppId(opts.appId);
242
- return (await getLogsInWindows(this.publicClient, opts.fromBlock, opts.toBlock, (from, to) => this.publicClient.getContractEvents({
243
- address: this.contractAddress,
244
- abi: APP_REGISTRY_ABI,
245
- eventName: "AppAgentChanged",
246
- args: appId ? { app_id: appId } : {},
247
- fromBlock: from,
248
- toBlock: to,
249
- strict: true
250
- }), this.logWindow)).map((log) => ({
251
- appId: log.args.app_id,
252
- agentUri: log.args.agent_uri,
253
- blockNumber: log.blockNumber,
254
- transactionHash: log.transactionHash
255
- }));
256
- }
257
- async admin() {
258
- return this.read("admin", []);
259
- }
260
- /** The DataRegistry this contract names. */
261
- async dataRegistry() {
262
- return this.read("dataRegistry", []);
263
- }
264
- /** Whether the protocol admin has banned `wallet` network-wide. */
265
- async isGloballySuspended(wallet) {
266
- return this.read("globalSuspensions", [wallet]);
267
- }
268
- /**
269
- * Ban `wallet` network-wide, or lift the ban. A banned wallet cannot claim an
270
- * app or be accepted into one, and no app stores or includes it; a banned
271
- * owner's app keeps running, but they cannot accept anyone or move its agent card.
272
- */
273
- async setGlobalSuspension(wallet, suspended) {
274
- return this.executeWrite("setGlobalSuspension", [wallet, suspended]);
275
- }
276
- /** Take this app down for every publisher at once, or restore it. */
277
- async setAppSuspended(suspended) {
278
- return this.executeWrite("setAppSuspended", [this.app(), suspended]);
279
- }
280
- async setDataRegistry(registry) {
281
- return this.executeWrite("setDataRegistry", [registry]);
282
- }
283
- async setSubscriptionFee(fee) {
284
- return this.executeWrite("setSubscriptionFee", [fee]);
285
- }
286
- /** Applies from each app's next payment. */
287
- async setSubscriptionPeriod(period) {
288
- return this.executeWrite("setSubscriptionPeriod", [period]);
289
- }
290
- /**
291
- * Send `amount` of `token` to `to`. Of USDC, only the protocol's share: what
292
- * app owners are owed in join fees stays (`ExceedsProtocolBalance`).
293
- */
294
- async withdrawToken(token, to, amount) {
295
- return this.executeWrite("withdrawToken", [
296
- token,
297
- to,
298
- amount
299
- ]);
300
- }
301
- /**
302
- * Fees are pulled with `transferFrom`, so the registry needs an allowance.
303
- * Without one the call reverts with a fee error that reads like a pricing
304
- * problem but is really an allowance one. Approves exactly `amount`.
305
- */
306
- async approveUsdc(amount) {
307
- if (amount === 0n) return;
308
- const token = await this.usdc();
309
- if (await this.publicClient.readContract({
310
- address: token,
311
- abi: erc20Abi,
312
- functionName: "allowance",
313
- args: [this.senderAddress(), this.contractAddress]
314
- }) >= amount) return;
315
- await sendWrite(this.publicClient, requireWallet(this.walletClient, "approve"), token, erc20Abi, "approve", [this.contractAddress, amount]);
316
- }
317
- senderAddress() {
318
- const account = this.walletClient.account;
319
- if (!account) throw new Error("Account required");
320
- return account.address;
321
- }
322
- };
323
-
324
- //#endregion
325
- export { AppRegistryClient };