@fangorn-network/sdk 2026.8.18-dev → 2026.10.1-9.0-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.
Files changed (91) hide show
  1. package/README.md +191 -195
  2. package/lib/cli/cli.d.ts +0 -0
  3. package/lib/cli/cli.js +198 -164
  4. package/lib/cli/index.d.ts +3 -91
  5. package/lib/cli/index.js +5 -2
  6. package/lib/config.d.ts +349 -433
  7. package/lib/config.js +41 -28
  8. package/lib/contracts/app-registry/abi.d.ts +1064 -265
  9. package/lib/contracts/app-registry/abi.js +1233 -308
  10. package/lib/contracts/app-registry/index.d.ts +123 -102
  11. package/lib/contracts/app-registry/index.js +200 -198
  12. package/lib/contracts/data-registry/abi.d.ts +166 -187
  13. package/lib/contracts/data-registry/abi.js +207 -237
  14. package/lib/contracts/data-registry/index.d.ts +4 -160
  15. package/lib/contracts/data-registry/index.js +5 -294
  16. package/lib/contracts/index.d.ts +6 -7
  17. package/lib/contracts/index.js +6 -8
  18. package/lib/contracts/logs.d.ts +21 -0
  19. package/lib/contracts/logs.js +32 -0
  20. package/lib/contracts/membership-registry/abi.d.ts +1145 -0
  21. package/lib/contracts/membership-registry/abi.js +1333 -0
  22. package/lib/contracts/membership-registry/index.d.ts +79 -0
  23. package/lib/contracts/membership-registry/index.js +104 -0
  24. package/lib/contracts/types.d.ts +3 -1
  25. package/lib/contracts/types.js +3 -1
  26. package/lib/contracts/write.d.ts +34 -2
  27. package/lib/contracts/write.js +48 -1
  28. package/lib/crypto/encryption.js +4 -4
  29. package/lib/engine/car.d.ts +2 -2
  30. package/lib/engine/car.js +10 -5
  31. package/lib/engine/index.d.ts +99 -143
  32. package/lib/engine/index.js +156 -295
  33. package/lib/engine/records.d.ts +110 -0
  34. package/lib/engine/records.js +165 -0
  35. package/lib/engine/test-helpers.d.ts +7 -14
  36. package/lib/engine/test-helpers.js +7 -18
  37. package/lib/fangorn.d.ts +163 -155
  38. package/lib/fangorn.js +284 -248
  39. package/lib/feed.d.ts +7 -4
  40. package/lib/feed.js +4 -1
  41. package/lib/index.d.ts +9 -9
  42. package/lib/index.js +9 -10
  43. package/lib/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.js +77 -0
  44. package/lib/node_modules/@vitest/expect/dist/index.js +1414 -0
  45. package/lib/node_modules/@vitest/pretty-format/dist/index.js +858 -0
  46. package/lib/node_modules/@vitest/runner/dist/chunk-tasks.js +51 -0
  47. package/lib/node_modules/@vitest/runner/dist/index.js +1199 -0
  48. package/lib/node_modules/@vitest/runner/dist/utils.js +3 -0
  49. package/lib/node_modules/@vitest/snapshot/dist/index.js +1075 -0
  50. package/lib/node_modules/@vitest/spy/dist/index.js +353 -0
  51. package/lib/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.js +7 -0
  52. package/lib/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.js +81 -0
  53. package/lib/node_modules/@vitest/utils/dist/diff.js +1345 -0
  54. package/lib/node_modules/@vitest/utils/dist/display.js +534 -0
  55. package/lib/node_modules/@vitest/utils/dist/error.js +30 -0
  56. package/lib/node_modules/@vitest/utils/dist/helpers.js +118 -0
  57. package/lib/node_modules/@vitest/utils/dist/serialize.js +76 -0
  58. package/lib/node_modules/@vitest/utils/dist/source-map.js +93 -0
  59. package/lib/node_modules/@vitest/utils/dist/timers.js +36 -0
  60. package/lib/node_modules/chai/index.js +2874 -0
  61. package/lib/node_modules/magic-string/dist/magic-string.es.js +939 -0
  62. package/lib/node_modules/pathe/dist/shared/pathe.M-eThtNZ.js +81 -0
  63. package/lib/node_modules/tinyrainbow/dist/index.js +85 -0
  64. package/lib/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.js +5 -0
  65. package/lib/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.js +50 -0
  66. package/lib/node_modules/vitest/dist/chunks/utils.DvEY5TfP.js +44 -0
  67. package/lib/node_modules/vitest/dist/chunks/vi.2VT5v0um.js +2578 -0
  68. package/lib/providers/storage/signed-url.d.ts +16 -6
  69. package/lib/providers/storage/signed-url.js +20 -8
  70. package/lib/registry.d.ts +116 -0
  71. package/lib/registry.js +182 -0
  72. package/lib/test/mem-registry.d.ts +51 -0
  73. package/lib/test/mem-registry.js +107 -0
  74. package/lib/test/sdk-suite.d.ts +13 -0
  75. package/lib/test/sdk-suite.js +226 -0
  76. package/lib/test/testbed.d.ts +16411 -61
  77. package/lib/test/testbed.js +190 -84
  78. package/lib/types/index.d.ts +13 -11
  79. package/package.json +89 -72
  80. package/lib/contracts/data-registry/test.d.ts +0 -1
  81. package/lib/contracts/data-registry/test.js +0 -1
  82. package/lib/contracts/settlement-registry/abi.d.ts +0 -466
  83. package/lib/contracts/settlement-registry/abi.js +0 -535
  84. package/lib/contracts/settlement-registry/index.d.ts +0 -163
  85. package/lib/contracts/settlement-registry/index.js +0 -264
  86. package/lib/contracts/subscription-registry/abi.d.ts +0 -179
  87. package/lib/contracts/subscription-registry/abi.js +0 -195
  88. package/lib/contracts/subscription-registry/index.d.ts +0 -59
  89. package/lib/contracts/subscription-registry/index.js +0 -116
  90. package/lib/engine/graph.d.ts +0 -70
  91. package/lib/engine/graph.js +0 -73
@@ -1,25 +1,16 @@
1
1
  import { APP_REGISTRY_ABI } from "./abi.js";
2
2
  import { requireWallet, sendWrite } from "../write.js";
3
- import { PublisherStatus } from "../types.js";
4
- import { encodeFunctionData, toHex } from "viem";
3
+ import { getLogsInWindows } from "../logs.js";
4
+ import { erc20Abi, hexToBigInt } from "viem";
5
5
 
6
6
  //#region src/contracts/app-registry/index.ts
7
- /** True when the publisher joined but the app's terms have since changed. */
8
- function needsReacceptance(info) {
9
- return !info.registered && info.status === PublisherStatus.ACTIVE && info.acceptedTerms !== info.termsHash;
10
- }
11
7
  /**
12
- * Client for the AppRegistry — app ids, per-app publisher terms, per-app join
13
- * fees, and per-app membership.
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. What an app presents — its members, less exclusions — is
11
+ * read through the registry (`ChainRegistry`), not this client.
14
12
  *
15
- * This contract owns what an "app" is. `registerApp` and `getAppOwner` used to
16
- * live on the DataRegistry, which meant two contracts held partial opinions about
17
- * apps and neither could enforce membership. The dependency now runs one way:
18
- * `DataRegistry.commitStateRoot` cross-calls `isRegisteredForApp` here, so a
19
- * publisher must join an app *before* they can write under it.
20
- *
21
- * Scoped to one `appId`, like `DataRegistryClient` — the app is an identity the
22
- * client carries, not an argument every call repeats.
13
+ * Scoped to one app, which may be unset: then only the calls that take no app work.
23
14
  */
24
15
  var AppRegistryClient = class {
25
16
  constructor(contractAddress, appId, publicClient, walletClient) {
@@ -28,236 +19,248 @@ var AppRegistryClient = class {
28
19
  this.publicClient = publicClient;
29
20
  this.walletClient = walletClient;
30
21
  }
31
- /** The app every call on this client is scoped to. */
32
22
  getAppId() {
33
23
  return this.appId;
34
24
  }
35
- /** Re-scope every subsequent call to a different app. */
36
25
  setAppId(appId) {
37
26
  this.appId = appId;
38
27
  }
39
- /** The deployed AppRegistry this client talks to. */
40
28
  getAddress() {
41
29
  return this.contractAddress;
42
30
  }
43
- /** Same gas buffer and fee styling as DataRegistryClient.executeWrite. */
44
- executeWrite(functionName, args, value) {
45
- return sendWrite(this.publicClient, requireWallet(this.walletClient, functionName), this.contractAddress, APP_REGISTRY_ABI, functionName, args, value);
31
+ /** This client's app, or a clear error for a call that needs one. */
32
+ app() {
33
+ if (!this.appId) throw new Error("no app chosen: pass `appId` to Fangorn.create() or call setAppId()");
34
+ return this.appId;
35
+ }
36
+ /** The app's subscription token: an app's token id is its app id. */
37
+ tokenId(appId = this.app()) {
38
+ return hexToBigInt(appId);
39
+ }
40
+ executeWrite(functionName, args) {
41
+ return sendWrite(this.publicClient, requireWallet(this.walletClient, functionName), this.contractAddress, APP_REGISTRY_ABI, functionName, args);
42
+ }
43
+ read(functionName, args) {
44
+ return this.publicClient.readContract({
45
+ address: this.contractAddress,
46
+ abi: APP_REGISTRY_ABI,
47
+ functionName,
48
+ args
49
+ });
46
50
  }
47
51
  /**
48
- * Claim this client's `appId` and open it in one transaction — owner, terms
49
- * and join fee together. First come, first served, and irreversible: there is
50
- * no transfer and no release.
52
+ * Claim this app, if nobody has. Claiming IS subscribing: it pays one period
53
+ * of `subscriptionFee()` in USDC and mints the app's token to the caller,
54
+ * who becomes the app's first accepted publisher.
51
55
  *
52
- * `termsHash` must be real. An app whose terms hash is zero cannot be joined
53
- * by anyone, so claiming an id without them creates a market nobody can enter.
56
+ * The fee read now is approved and passed as the most the claim may cost,
57
+ * so a fee raised in the meantime makes the claim revert instead of charging
58
+ * more.
54
59
  */
55
- async registerApp(termsHash, termsUri, fee = 0n) {
56
- return this.executeWrite("registerApp", [
57
- this.appId,
58
- termsHash,
59
- termsUri,
60
- fee
61
- ]);
60
+ async registerApp() {
61
+ const fee = await this.subscriptionFee();
62
+ await this.approveUsdc(fee);
63
+ return this.executeWrite("registerApp", [this.app(), fee]);
62
64
  }
63
65
  /**
64
- * Publish new terms for this app.
66
+ * Pay for one more period (the owner, or an address they approved for the
67
+ * app's token). Allowed once less than a period is left; the period is added
68
+ * to the current expiry, or to now if it has passed.
65
69
  *
66
- * This drops every publisher back to "must accept again" — `isRegisteredForApp`
67
- * is false for anyone whose accepted hash no longer matches — so it is a real
68
- * act with a real consequence, not a copy edit. Re-accepting is free for them.
70
+ * The standard gives the contract no maximum-fee argument, so the allowance
71
+ * is the cap: exactly the fee read now is approved.
69
72
  */
70
- async setAppTerms(termsHash, termsUri) {
71
- return this.executeWrite("setAppTerms", [
72
- this.appId,
73
- termsHash,
74
- termsUri
73
+ async renewSubscription() {
74
+ const [renewable, period, fee] = await Promise.all([
75
+ this.isRenewable(),
76
+ this.subscriptionPeriod(),
77
+ this.subscriptionFee()
75
78
  ]);
76
- }
77
- /** Set what joining this app costs, in wei. Paid to the app owner. */
78
- async setAppFee(fee) {
79
- return this.executeWrite("setAppFee", [this.appId, fee]);
79
+ if (!renewable) {
80
+ const expiry = await this.expiresAt();
81
+ 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()}`);
82
+ }
83
+ await this.approveUsdc(fee);
84
+ return this.executeWrite("renewSubscription", [this.tokenId(), period]);
80
85
  }
81
86
  /**
82
- * Eject a publisher from THIS app. Their global DataRegistry standing and
83
- * their membership of every other app are untouched.
87
+ * End this app's subscription now (owner only): the expiry becomes zero and
88
+ * nothing is refunded. Until it is renewed the app provides no storage and includes nothing.
84
89
  */
85
- async suspendForApp(publisher) {
86
- return this.executeWrite("suspendForApp", [this.appId, publisher]);
90
+ async cancelSubscription() {
91
+ return this.executeWrite("cancelSubscription", [this.tokenId()]);
92
+ }
93
+ /** Unix seconds this app's subscription expires at; 0 once cancelled. Reverts for an unclaimed app. */
94
+ async expiresAt(appId = this.app()) {
95
+ return this.read("expiresAt", [this.tokenId(appId)]);
96
+ }
97
+ /** True while less than one period is left, or the subscription has expired. */
98
+ async isRenewable() {
99
+ return this.read("isRenewable", [this.tokenId()]);
100
+ }
101
+ /** How long one payment lasts, in seconds. */
102
+ async subscriptionPeriod() {
103
+ return this.read("subscriptionPeriod", []);
87
104
  }
88
- async reinstateForApp(publisher) {
89
- return this.executeWrite("reinstateForApp", [this.appId, publisher]);
105
+ /** What claiming or renewing an app costs, in USDC base units (6 decimals), not wei. */
106
+ async subscriptionFee() {
107
+ return this.read("subscriptionFee", []);
108
+ }
109
+ /** The ERC-20 token (USDC) every fee is paid in. */
110
+ async usdc() {
111
+ return this.read("usdc", []);
112
+ }
113
+ async getAppOwner(appId = this.app()) {
114
+ return this.read("getAppOwner", [appId]);
90
115
  }
91
116
  /**
92
- * Take this whole app down. Protocol-admin only, and a level above
93
- * `suspendForApp`: every publisher of the app — its owner included — reads as
94
- * unregistered, so nothing commits under it until it is reinstated. The
95
- * memberships underneath are left intact, so reinstating restores them exactly.
117
+ * Point this app at its ERC-8004 agent card.
118
+ *
119
+ * Safe to call whenever the card moves: it leaves the app's publishers alone.
96
120
  */
97
- async suspendApp() {
98
- return this.executeWrite("suspendApp", [this.appId]);
121
+ async setAppAgentUri(agentUri) {
122
+ return this.executeWrite("setAppAgentUri", [this.app(), agentUri]);
99
123
  }
100
- /** Lift an admin takedown, restoring every membership as it was. */
101
- async reinstateApp() {
102
- return this.executeWrite("reinstateApp", [this.appId]);
124
+ /** Send the join fees the caller is still owed, from the old join flow, to `to`. */
125
+ async withdrawJoinFees(to = this.senderAddress()) {
126
+ return this.executeWrite("withdrawJoinFees", [to]);
103
127
  }
104
- /** The protocol admin of this AppRegistry — the only caller `suspendApp` accepts. */
105
- async admin() {
106
- return this.publicClient.readContract({
107
- address: this.contractAddress,
108
- abi: APP_REGISTRY_ABI,
109
- functionName: "admin"
110
- });
128
+ /** Join fees still owed to `owner` from the old join flow, in USDC base units. Nothing adds to it. */
129
+ async joinFeesOwed(owner = this.senderAddress()) {
130
+ return this.read("joinFeesOwed", [owner]);
131
+ }
132
+ async isAppSuspended() {
133
+ return this.read("isAppSuspended", [this.app()]);
134
+ }
135
+ /** The agent card URI of this app, or of `appId`. Empty if none is set. */
136
+ async appAgentUri(appId = this.app()) {
137
+ return this.read("appAgentUri", [appId]);
111
138
  }
112
139
  /**
113
- * Join this app, accepting its current terms by the act of doing so.
114
- *
115
- * The hash is read immediately before sending and passed as an argument, and
116
- * the contract reverts `TermsMismatch` if it no longer matches. That is the
117
- * point: the transaction is only valid against the exact version that was in
118
- * front of the caller, so terms cannot change under a pending registration and
119
- * land as agreement to something else. A race here is a revert, not a
120
- * surprise obligation.
121
- *
122
- * The join fee is read from the chain rather than passed in, for the same
123
- * reason `DataRegistryClient.register()` reads the registration fee: a caller
124
- * who supplies it can supply the wrong one.
140
+ * Accept a publisher into this app (owner only). That is the whole
141
+ * membership: from here it uploads with storage the app provides, and the app
142
+ * includes its data, while `canPublish` holds. A suspended publisher comes
143
+ * back with `setPublisherSuspended(publisher, false)`.
125
144
  */
126
- async registerForApp() {
127
- const [termsHash, , fee] = await this.readJoinInfoTuple(this.senderAddress());
128
- if (termsHash === ZERO_HASH) throw new Error(`app ${this.appId} has published no terms — it cannot be joined until its owner sets them`);
129
- return this.executeWrite("registerForApp", [this.appId, termsHash], fee);
145
+ async acceptPublisher(publisher) {
146
+ return this.executeWrite("acceptPublisher", [this.app(), publisher]);
130
147
  }
131
148
  /**
132
- * The same join, as an unsigned transaction for a wallet that signs elsewhere
133
- * (the sond3r relay never holds a key). Mirrors `prepareCommitStateRoot`.
149
+ * Suspend an accepted publisher from this app, or reinstate them (owner
150
+ * only). An owner cannot suspend themselves.
134
151
  */
135
- async prepareRegisterForApp(publisher) {
136
- const [termsHash, , fee] = await this.readJoinInfoTuple(publisher);
137
- if (termsHash === ZERO_HASH) throw new Error(`app ${this.appId} has published no terms — it cannot be joined until its owner sets them`);
138
- const data = encodeFunctionData({
139
- abi: APP_REGISTRY_ABI,
140
- functionName: "registerForApp",
141
- args: [this.appId, termsHash]
142
- });
143
- const fees = await this.publicClient.estimateFeesPerGas();
144
- let gas;
145
- try {
146
- gas = await this.publicClient.estimateGas({
147
- account: publisher,
148
- to: this.contractAddress,
149
- data,
150
- value: fee
151
- }) * 3n / 2n;
152
- } catch (err) {
153
- const message = err instanceof Error ? err.message : String(err);
154
- if (/revert/i.test(message)) throw new Error(`joining would revert — this wallet may already be registered, or suspended from this app: ${message}`);
155
- gas = 1000000n;
156
- }
152
+ async setPublisherSuspended(publisher, suspended) {
153
+ return this.executeWrite("setPublisherSuspended", [
154
+ this.app(),
155
+ publisher,
156
+ suspended
157
+ ]);
158
+ }
159
+ /** `publisher`'s standing in this app. */
160
+ async status(publisher) {
161
+ return await this.read("statusForApp", [this.app(), publisher]);
162
+ }
163
+ /**
164
+ * May `publisher` publish to this app now: accepted and not suspended, not
165
+ * banned network-wide, and the app is live and paid up.
166
+ */
167
+ async canPublish(publisher, appId = this.app()) {
168
+ return this.read("canPublish", [appId, publisher]);
169
+ }
170
+ /** The single oracle the upload gate reads for one publisher under this app. */
171
+ async access(publisher, appId = this.app()) {
172
+ const [canPublish, owner, expiresAt] = await this.read("access", [appId, publisher]);
157
173
  return {
158
- to: this.contractAddress,
159
- data,
160
- chainId: this.publicClient.chain?.id,
161
- gas: toHex(gas),
162
- maxFeePerGas: toHex(fees.maxFeePerGas * 2n),
163
- maxPriorityFeePerGas: toHex(fees.maxPriorityFeePerGas),
164
- value: toHex(fee)
174
+ canPublish,
175
+ owner,
176
+ expiresAt
165
177
  };
166
178
  }
167
- /** Owner of this client's app id, or the zero address if unclaimed. */
168
- async getAppOwner() {
169
- return this.publicClient.readContract({
170
- address: this.contractAddress,
171
- abi: APP_REGISTRY_ABI,
172
- functionName: "getAppOwner",
173
- args: [this.appId]
174
- });
175
- }
176
179
  /**
177
- * May this publisher commit under this app? This is the exact question
178
- * `DataRegistry.commitStateRoot` asks on-chain, so a false here means a
179
- * publish would revert.
180
+ * `AppAgentChanged` events, oldest first. The last one for an app is its
181
+ * current card; an empty `agentUri` means the owner unset it.
182
+ *
183
+ * Leave `appId` out to list every app that has ever set a card. The chain is
184
+ * the directory: one windowed log scan, no indexer and no registry namespace.
185
+ * `fromBlock` is required because scanning from genesis on an L2 costs
186
+ * hundreds of thousands of RPC calls. Pass the AppRegistry's deploy block, or
187
+ * a block you know to be before the app's registration.
180
188
  */
181
- async isRegisteredForApp(publisher) {
182
- return this.publicClient.readContract({
189
+ async getAppAgentLogs(opts) {
190
+ return (await getLogsInWindows(this.publicClient, opts.fromBlock, opts.toBlock, (from, to) => this.publicClient.getContractEvents({
183
191
  address: this.contractAddress,
184
192
  abi: APP_REGISTRY_ABI,
185
- functionName: "isRegisteredForApp",
186
- args: [this.appId, publisher]
187
- });
193
+ eventName: "AppAgentChanged",
194
+ args: opts.appId ? { app_id: opts.appId } : {},
195
+ fromBlock: from,
196
+ toBlock: to,
197
+ strict: true
198
+ }))).map((log) => ({
199
+ appId: log.args.app_id,
200
+ agentUri: log.args.agent_uri,
201
+ blockNumber: log.blockNumber,
202
+ transactionHash: log.transactionHash
203
+ }));
188
204
  }
189
- /** Has the protocol admin taken this app down? */
190
- async isAppSuspended() {
191
- return this.publicClient.readContract({
192
- address: this.contractAddress,
193
- abi: APP_REGISTRY_ABI,
194
- functionName: "isAppSuspended",
195
- args: [this.appId]
196
- });
205
+ async admin() {
206
+ return this.read("admin", []);
197
207
  }
198
- /** This app's current terms hash, or the zero hash if it has published none. */
199
- async appTerms() {
200
- return this.publicClient.readContract({
201
- address: this.contractAddress,
202
- abi: APP_REGISTRY_ABI,
203
- functionName: "appTerms",
204
- args: [this.appId]
205
- });
208
+ /** The DataRegistry this contract names. */
209
+ async dataRegistry() {
210
+ return this.read("dataRegistry", []);
206
211
  }
207
- async appTermsUri() {
208
- return this.publicClient.readContract({
209
- address: this.contractAddress,
210
- abi: APP_REGISTRY_ABI,
211
- functionName: "appTermsUri",
212
- args: [this.appId]
213
- });
212
+ /** Whether the protocol admin has banned `wallet` network-wide. */
213
+ async isGloballySuspended(wallet) {
214
+ return this.read("globalSuspensions", [wallet]);
214
215
  }
215
- async appFee() {
216
- return this.publicClient.readContract({
217
- address: this.contractAddress,
218
- abi: APP_REGISTRY_ABI,
219
- functionName: "appFee",
220
- args: [this.appId]
221
- });
216
+ /**
217
+ * Ban `wallet` network-wide, or lift the ban. A banned wallet cannot claim an
218
+ * app or be accepted into one, and no app stores or includes it; a banned
219
+ * owner's app keeps running, but they cannot accept anyone or move its agent card.
220
+ */
221
+ async setGlobalSuspension(wallet, suspended) {
222
+ return this.executeWrite("setGlobalSuspension", [wallet, suspended]);
222
223
  }
223
- /** The terms hash this publisher accepted, or the zero hash. */
224
- async acceptedTerms(publisher) {
225
- return this.publicClient.readContract({
226
- address: this.contractAddress,
227
- abi: APP_REGISTRY_ABI,
228
- functionName: "acceptedTerms",
229
- args: [this.appId, publisher]
230
- });
224
+ /** Take this app down for every publisher at once, or restore it. */
225
+ async setAppSuspended(suspended) {
226
+ return this.executeWrite("setAppSuspended", [this.app(), suspended]);
227
+ }
228
+ async setDataRegistry(registry) {
229
+ return this.executeWrite("setDataRegistry", [registry]);
230
+ }
231
+ async setSubscriptionFee(fee) {
232
+ return this.executeWrite("setSubscriptionFee", [fee]);
233
+ }
234
+ /** Applies from each app's next payment. */
235
+ async setSubscriptionPeriod(period) {
236
+ return this.executeWrite("setSubscriptionPeriod", [period]);
231
237
  }
232
238
  /**
233
- * Everything a join screen needs. Two reads rather than one, because the
234
- * accepted hash is what turns "not registered" into the far more useful "the
235
- * terms changed since you joined".
239
+ * Send `amount` of `token` to `to`. Of USDC, only the protocol's share: what
240
+ * app owners are owed in join fees stays (`ExceedsProtocolBalance`).
236
241
  */
237
- async joinInfo(publisher) {
238
- const [tuple, acceptedTerms, appSuspended] = await Promise.all([
239
- this.readJoinInfoTuple(publisher),
240
- this.acceptedTerms(publisher),
241
- this.isAppSuspended()
242
+ async withdrawToken(token, to, amount) {
243
+ return this.executeWrite("withdrawToken", [
244
+ token,
245
+ to,
246
+ amount
242
247
  ]);
243
- const [termsHash, termsUri, fee, status, registered] = tuple;
244
- return {
245
- termsHash,
246
- termsUri,
247
- fee,
248
- status,
249
- registered,
250
- acceptedTerms,
251
- appSuspended
252
- };
253
248
  }
254
- async readJoinInfoTuple(publisher) {
255
- return this.publicClient.readContract({
256
- address: this.contractAddress,
257
- abi: APP_REGISTRY_ABI,
258
- functionName: "joinInfo",
259
- args: [this.appId, publisher]
260
- });
249
+ /**
250
+ * Fees are pulled with `transferFrom`, so the registry needs an allowance.
251
+ * Without one the call reverts with a fee error that reads like a pricing
252
+ * problem but is really an allowance one. Approves exactly `amount`.
253
+ */
254
+ async approveUsdc(amount) {
255
+ if (amount === 0n) return;
256
+ const token = await this.usdc();
257
+ if (await this.publicClient.readContract({
258
+ address: token,
259
+ abi: erc20Abi,
260
+ functionName: "allowance",
261
+ args: [this.senderAddress(), this.contractAddress]
262
+ }) >= amount) return;
263
+ await sendWrite(this.publicClient, requireWallet(this.walletClient, "approve"), token, erc20Abi, "approve", [this.contractAddress, amount]);
261
264
  }
262
265
  senderAddress() {
263
266
  const account = this.walletClient.account;
@@ -265,7 +268,6 @@ var AppRegistryClient = class {
265
268
  return account.address;
266
269
  }
267
270
  };
268
- const ZERO_HASH = `0x${"0".repeat(64)}`;
269
271
 
270
272
  //#endregion
271
- export { AppRegistryClient, needsReacceptance };
273
+ export { AppRegistryClient };