@fangorn-network/sdk 2026.9.22-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.
- package/README.md +190 -194
- package/lib/cli/cli.d.ts +0 -0
- package/lib/cli/cli.js +177 -201
- package/lib/cli/index.d.ts +3 -91
- package/lib/cli/index.js +5 -2
- package/lib/config.d.ts +358 -117
- package/lib/config.js +43 -23
- package/lib/contracts/app-registry/abi.d.ts +1033 -277
- package/lib/contracts/app-registry/abi.js +1214 -335
- package/lib/contracts/app-registry/index.d.ts +105 -65
- package/lib/contracts/app-registry/index.js +182 -175
- package/lib/contracts/data-registry/abi.d.ts +166 -187
- package/lib/contracts/data-registry/abi.js +207 -237
- package/lib/contracts/data-registry/index.d.ts +4 -151
- package/lib/contracts/data-registry/index.js +5 -279
- package/lib/contracts/index.d.ts +6 -7
- package/lib/contracts/index.js +6 -8
- package/lib/contracts/logs.d.ts +4 -1
- package/lib/contracts/logs.js +9 -2
- package/lib/contracts/membership-registry/abi.d.ts +1145 -0
- package/lib/contracts/membership-registry/abi.js +1333 -0
- package/lib/contracts/membership-registry/index.d.ts +79 -0
- package/lib/contracts/membership-registry/index.js +104 -0
- package/lib/contracts/types.d.ts +3 -1
- package/lib/contracts/types.js +3 -1
- package/lib/contracts/write.d.ts +34 -2
- package/lib/contracts/write.js +48 -1
- package/lib/crypto/encryption.js +4 -4
- package/lib/engine/car.d.ts +2 -2
- package/lib/engine/car.js +10 -5
- package/lib/engine/index.d.ts +99 -143
- package/lib/engine/index.js +156 -295
- package/lib/engine/records.d.ts +110 -0
- package/lib/engine/records.js +165 -0
- package/lib/engine/test-helpers.d.ts +7 -14
- package/lib/engine/test-helpers.js +7 -18
- package/lib/fangorn.d.ts +129 -156
- package/lib/fangorn.js +250 -250
- package/lib/feed.d.ts +7 -4
- package/lib/feed.js +4 -1
- package/lib/index.d.ts +9 -9
- package/lib/index.js +8 -9
- package/lib/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.js +77 -0
- package/lib/node_modules/@vitest/expect/dist/index.js +1414 -0
- package/lib/node_modules/@vitest/pretty-format/dist/index.js +858 -0
- package/lib/node_modules/@vitest/runner/dist/chunk-tasks.js +51 -0
- package/lib/node_modules/@vitest/runner/dist/index.js +1199 -0
- package/lib/node_modules/@vitest/runner/dist/utils.js +3 -0
- package/lib/node_modules/@vitest/snapshot/dist/index.js +1075 -0
- package/lib/node_modules/@vitest/spy/dist/index.js +353 -0
- package/lib/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.js +7 -0
- package/lib/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.js +81 -0
- package/lib/node_modules/@vitest/utils/dist/diff.js +1345 -0
- package/lib/node_modules/@vitest/utils/dist/display.js +534 -0
- package/lib/node_modules/@vitest/utils/dist/error.js +30 -0
- package/lib/node_modules/@vitest/utils/dist/helpers.js +118 -0
- package/lib/node_modules/@vitest/utils/dist/serialize.js +76 -0
- package/lib/node_modules/@vitest/utils/dist/source-map.js +93 -0
- package/lib/node_modules/@vitest/utils/dist/timers.js +36 -0
- package/lib/node_modules/chai/index.js +2874 -0
- package/lib/node_modules/magic-string/dist/magic-string.es.js +939 -0
- package/lib/node_modules/pathe/dist/shared/pathe.M-eThtNZ.js +81 -0
- package/lib/node_modules/tinyrainbow/dist/index.js +85 -0
- package/lib/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.js +5 -0
- package/lib/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.js +50 -0
- package/lib/node_modules/vitest/dist/chunks/utils.DvEY5TfP.js +44 -0
- package/lib/node_modules/vitest/dist/chunks/vi.2VT5v0um.js +2578 -0
- package/lib/providers/storage/signed-url.d.ts +16 -6
- package/lib/providers/storage/signed-url.js +20 -8
- package/lib/registry.d.ts +116 -0
- package/lib/registry.js +182 -0
- package/lib/test/mem-registry.d.ts +51 -0
- package/lib/test/mem-registry.js +107 -0
- package/lib/test/sdk-suite.d.ts +13 -0
- package/lib/test/sdk-suite.js +226 -0
- package/lib/test/testbed.d.ts +16411 -61
- package/lib/test/testbed.js +190 -84
- package/lib/types/index.d.ts +13 -11
- package/package.json +89 -73
- package/lib/contracts/data-registry/test.d.ts +0 -1
- package/lib/contracts/data-registry/test.js +0 -1
- package/lib/contracts/settlement-registry/abi.d.ts +0 -466
- package/lib/contracts/settlement-registry/abi.js +0 -535
- package/lib/contracts/settlement-registry/index.d.ts +0 -163
- package/lib/contracts/settlement-registry/index.js +0 -264
- package/lib/contracts/subscription-registry/abi.d.ts +0 -179
- package/lib/contracts/subscription-registry/abi.js +0 -195
- package/lib/contracts/subscription-registry/index.d.ts +0 -59
- package/lib/contracts/subscription-registry/index.js +0 -116
- package/lib/engine/graph.d.ts +0 -70
- package/lib/engine/graph.js +0 -73
|
@@ -1,27 +1,16 @@
|
|
|
1
1
|
import { PublisherStatus } from "../types.js";
|
|
2
|
-
import { PreparedTx } from "../
|
|
2
|
+
import { PreparedTx } from "../write.js";
|
|
3
3
|
import { Address, Hash, Hex, PublicClient, WalletClient } from "viem";
|
|
4
4
|
|
|
5
5
|
//#region src/contracts/app-registry/index.d.ts
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
termsUri: string;
|
|
15
|
-
/** publisher defined joiners fee */
|
|
16
|
-
fee: bigint;
|
|
17
|
-
/** app publisher status (active, unregistered, suspended) */
|
|
18
|
-
status: PublisherStatus;
|
|
19
|
-
/** Active AND up-to-date with term agreements */
|
|
20
|
-
registered: boolean;
|
|
21
|
-
/** The terms hash this publisher actually accepted, or zero. */
|
|
22
|
-
acceptedTerms: Hex;
|
|
23
|
-
/** The protocol admin has taken the whole app down — nobody is registered. */
|
|
24
|
-
appSuspended: boolean;
|
|
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;
|
|
25
14
|
}
|
|
26
15
|
/** One `AppAgentChanged` event: an app owner pointed their app at a card. */
|
|
27
16
|
interface AppAgentLog {
|
|
@@ -30,71 +19,98 @@ interface AppAgentLog {
|
|
|
30
19
|
blockNumber: bigint;
|
|
31
20
|
transactionHash: Hash;
|
|
32
21
|
}
|
|
33
|
-
/** True when the publisher joined but the app's terms have since changed. */
|
|
34
|
-
declare function needsReacceptance(info: AppJoinInfo): boolean;
|
|
35
22
|
/**
|
|
36
|
-
* Client for the AppRegistry
|
|
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. What an app presents — its members, less exclusions — is
|
|
26
|
+
* read through the registry (`ChainRegistry`), not this client.
|
|
27
|
+
*
|
|
28
|
+
* Scoped to one app, which may be unset: then only the calls that take no app work.
|
|
37
29
|
*/
|
|
38
30
|
declare class AppRegistryClient {
|
|
39
31
|
private contractAddress;
|
|
40
32
|
private appId;
|
|
41
33
|
private publicClient;
|
|
42
34
|
private walletClient;
|
|
43
|
-
constructor(contractAddress: Address, appId: Hex, publicClient: PublicClient, walletClient: WalletClient);
|
|
44
|
-
getAppId(): Hex;
|
|
45
|
-
setAppId(appId: Hex): void;
|
|
35
|
+
constructor(contractAddress: Address, appId: Hex | undefined, publicClient: PublicClient, walletClient: WalletClient);
|
|
36
|
+
getAppId(): Hex | undefined;
|
|
37
|
+
setAppId(appId: Hex | undefined): void;
|
|
46
38
|
getAddress(): Address;
|
|
39
|
+
/** This client's app, or a clear error for a call that needs one. */
|
|
40
|
+
private app;
|
|
41
|
+
/** The app's subscription token: an app's token id is its app id. */
|
|
42
|
+
tokenId(appId?: Hex): bigint;
|
|
47
43
|
private executeWrite;
|
|
44
|
+
private read;
|
|
48
45
|
/**
|
|
49
|
-
*
|
|
46
|
+
* Claim this app, if nobody has. Claiming IS subscribing: it pays one period
|
|
47
|
+
* of `subscriptionFee()` in USDC and mints the app's token to the caller,
|
|
48
|
+
* who becomes the app's first accepted publisher.
|
|
49
|
+
*
|
|
50
|
+
* The fee read now is approved and passed as the most the claim may cost,
|
|
51
|
+
* so a fee raised in the meantime makes the claim revert instead of charging
|
|
52
|
+
* more.
|
|
50
53
|
*/
|
|
51
|
-
registerApp(
|
|
54
|
+
registerApp(): Promise<Hash>;
|
|
52
55
|
/**
|
|
53
|
-
*
|
|
56
|
+
* Pay for one more period (the owner, or an address they approved for the
|
|
57
|
+
* app's token). Allowed once less than a period is left; the period is added
|
|
58
|
+
* to the current expiry, or to now if it has passed.
|
|
54
59
|
*
|
|
55
|
-
*
|
|
60
|
+
* The standard gives the contract no maximum-fee argument, so the allowance
|
|
61
|
+
* is the cap: exactly the fee read now is approved.
|
|
62
|
+
*/
|
|
63
|
+
renewSubscription(): Promise<Hash>;
|
|
64
|
+
/**
|
|
65
|
+
* End this app's subscription now (owner only): the expiry becomes zero and
|
|
66
|
+
* nothing is refunded. Until it is renewed the app provides no storage and includes nothing.
|
|
56
67
|
*/
|
|
57
|
-
|
|
68
|
+
cancelSubscription(): Promise<Hash>;
|
|
69
|
+
/** Unix seconds this app's subscription expires at; 0 once cancelled. Reverts for an unclaimed app. */
|
|
70
|
+
expiresAt(appId?: Hex): Promise<bigint>;
|
|
71
|
+
/** True while less than one period is left, or the subscription has expired. */
|
|
72
|
+
isRenewable(): Promise<boolean>;
|
|
73
|
+
/** How long one payment lasts, in seconds. */
|
|
74
|
+
subscriptionPeriod(): Promise<bigint>;
|
|
75
|
+
/** What claiming or renewing an app costs, in USDC base units (6 decimals), not wei. */
|
|
76
|
+
subscriptionFee(): Promise<bigint>;
|
|
77
|
+
/** The ERC-20 token (USDC) every fee is paid in. */
|
|
78
|
+
usdc(): Promise<Address>;
|
|
79
|
+
getAppOwner(appId?: Hex): Promise<Address>;
|
|
58
80
|
/**
|
|
59
81
|
* Point this app at its ERC-8004 agent card.
|
|
60
82
|
*
|
|
61
|
-
* Safe to call whenever the card moves
|
|
62
|
-
* URI for one reason: publishers are bound to `termsHash`, so anything sharing
|
|
63
|
-
* that slot unregisters every publisher in the app the moment it changes (see
|
|
64
|
-
* `needsReacceptance`). A card holds endpoints and pubkeys, which rotate.
|
|
83
|
+
* Safe to call whenever the card moves: it leaves the app's publishers alone.
|
|
65
84
|
*/
|
|
66
85
|
setAppAgentUri(agentUri: string): Promise<Hash>;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
86
|
+
/** Send the join fees the caller is still owed, from the old join flow, to `to`. */
|
|
87
|
+
withdrawJoinFees(to?: Address): Promise<Hash>;
|
|
88
|
+
/** Join fees still owed to `owner` from the old join flow, in USDC base units. Nothing adds to it. */
|
|
89
|
+
joinFeesOwed(owner?: Address): Promise<bigint>;
|
|
90
|
+
isAppSuspended(): Promise<boolean>;
|
|
91
|
+
/** The agent card URI of this app, or of `appId`. Empty if none is set. */
|
|
92
|
+
appAgentUri(appId?: Hex): Promise<string>;
|
|
74
93
|
/**
|
|
75
|
-
*
|
|
94
|
+
* Accept a publisher into this app (owner only). That is the whole
|
|
95
|
+
* membership: from here it uploads with storage the app provides, and the app
|
|
96
|
+
* includes its data, while `canPublish` holds. A suspended publisher comes
|
|
97
|
+
* back with `setPublisherSuspended(publisher, false)`.
|
|
76
98
|
*/
|
|
77
|
-
|
|
78
|
-
reinstateApp(): Promise<Hash>;
|
|
79
|
-
admin(): Promise<Address>;
|
|
99
|
+
acceptPublisher(publisher: Address): Promise<Hash>;
|
|
80
100
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
101
|
+
* Suspend an accepted publisher from this app, or reinstate them (owner
|
|
102
|
+
* only). An owner cannot suspend themselves.
|
|
83
103
|
*/
|
|
84
|
-
|
|
104
|
+
setPublisherSuspended(publisher: Address, suspended: boolean): Promise<Hash>;
|
|
105
|
+
/** `publisher`'s standing in this app. */
|
|
106
|
+
status(publisher: Address): Promise<PublisherStatus>;
|
|
85
107
|
/**
|
|
86
|
-
*
|
|
108
|
+
* May `publisher` publish to this app now: accepted and not suspended, not
|
|
109
|
+
* banned network-wide, and the app is live and paid up.
|
|
87
110
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
getAppOwner(): Promise<Address>;
|
|
92
|
-
isRegisteredForApp(publisher: Address): Promise<boolean>;
|
|
93
|
-
isAppSuspended(): Promise<boolean>;
|
|
94
|
-
appTerms(): Promise<Hex>;
|
|
95
|
-
appTermsUri(): Promise<string>;
|
|
96
|
-
/** The agent card URI of this app, or of `appId`. Empty if none is set. */
|
|
97
|
-
appAgentUri(appId?: Hex): Promise<string>;
|
|
111
|
+
canPublish(publisher: Address, appId?: Hex): Promise<boolean>;
|
|
112
|
+
/** The single oracle the upload gate reads for one publisher under this app. */
|
|
113
|
+
access(publisher: Address, appId?: Hex): Promise<AppAccess>;
|
|
98
114
|
/**
|
|
99
115
|
* `AppAgentChanged` events, oldest first. The last one for an app is its
|
|
100
116
|
* current card; an empty `agentUri` means the owner unset it.
|
|
@@ -110,11 +126,35 @@ declare class AppRegistryClient {
|
|
|
110
126
|
fromBlock: bigint;
|
|
111
127
|
toBlock?: bigint;
|
|
112
128
|
}): Promise<AppAgentLog[]>;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
129
|
+
admin(): Promise<Address>;
|
|
130
|
+
/** The DataRegistry this contract names. */
|
|
131
|
+
dataRegistry(): Promise<Address>;
|
|
132
|
+
/** Whether the protocol admin has banned `wallet` network-wide. */
|
|
133
|
+
isGloballySuspended(wallet: Address): Promise<boolean>;
|
|
134
|
+
/**
|
|
135
|
+
* Ban `wallet` network-wide, or lift the ban. A banned wallet cannot claim an
|
|
136
|
+
* app or be accepted into one, and no app stores or includes it; a banned
|
|
137
|
+
* owner's app keeps running, but they cannot accept anyone or move its agent card.
|
|
138
|
+
*/
|
|
139
|
+
setGlobalSuspension(wallet: Address, suspended: boolean): Promise<Hash>;
|
|
140
|
+
/** Take this app down for every publisher at once, or restore it. */
|
|
141
|
+
setAppSuspended(suspended: boolean): Promise<Hash>;
|
|
142
|
+
setDataRegistry(registry: Address): Promise<Hash>;
|
|
143
|
+
setSubscriptionFee(fee: bigint): Promise<Hash>;
|
|
144
|
+
/** Applies from each app's next payment. */
|
|
145
|
+
setSubscriptionPeriod(period: bigint): Promise<Hash>;
|
|
146
|
+
/**
|
|
147
|
+
* Send `amount` of `token` to `to`. Of USDC, only the protocol's share: what
|
|
148
|
+
* app owners are owed in join fees stays (`ExceedsProtocolBalance`).
|
|
149
|
+
*/
|
|
150
|
+
withdrawToken(token: Address, to: Address, amount: bigint): Promise<Hash>;
|
|
151
|
+
/**
|
|
152
|
+
* Fees are pulled with `transferFrom`, so the registry needs an allowance.
|
|
153
|
+
* Without one the call reverts with a fee error that reads like a pricing
|
|
154
|
+
* problem but is really an allowance one. Approves exactly `amount`.
|
|
155
|
+
*/
|
|
156
|
+
private approveUsdc;
|
|
117
157
|
private senderAddress;
|
|
118
158
|
}
|
|
119
159
|
//#endregion
|
|
120
|
-
export {
|
|
160
|
+
export { AppAccess, AppAgentLog, AppRegistryClient, type PreparedTx };
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { APP_REGISTRY_ABI } from "./abi.js";
|
|
2
2
|
import { requireWallet, sendWrite } from "../write.js";
|
|
3
3
|
import { getLogsInWindows } from "../logs.js";
|
|
4
|
-
import {
|
|
5
|
-
import { encodeFunctionData, toHex } from "viem";
|
|
4
|
+
import { erc20Abi, hexToBigInt } from "viem";
|
|
6
5
|
|
|
7
6
|
//#region src/contracts/app-registry/index.ts
|
|
8
|
-
/** True when the publisher joined but the app's terms have since changed. */
|
|
9
|
-
function needsReacceptance(info) {
|
|
10
|
-
return !info.registered && info.status === PublisherStatus.ACTIVE && info.acceptedTerms !== info.termsHash;
|
|
11
|
-
}
|
|
12
7
|
/**
|
|
13
|
-
* Client for the AppRegistry
|
|
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.
|
|
12
|
+
*
|
|
13
|
+
* Scoped to one app, which may be unset: then only the calls that take no app work.
|
|
14
14
|
*/
|
|
15
15
|
var AppRegistryClient = class {
|
|
16
16
|
constructor(contractAddress, appId, publicClient, walletClient) {
|
|
@@ -28,164 +28,153 @@ var AppRegistryClient = class {
|
|
|
28
28
|
getAddress() {
|
|
29
29
|
return this.contractAddress;
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
|
|
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
|
+
});
|
|
33
50
|
}
|
|
34
51
|
/**
|
|
35
|
-
*
|
|
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.
|
|
55
|
+
*
|
|
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.
|
|
36
59
|
*/
|
|
37
|
-
async registerApp(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
termsUri,
|
|
42
|
-
fee
|
|
43
|
-
]);
|
|
60
|
+
async registerApp() {
|
|
61
|
+
const fee = await this.subscriptionFee();
|
|
62
|
+
await this.approveUsdc(fee);
|
|
63
|
+
return this.executeWrite("registerApp", [this.app(), fee]);
|
|
44
64
|
}
|
|
45
65
|
/**
|
|
46
|
-
*
|
|
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.
|
|
47
69
|
*
|
|
48
|
-
*
|
|
70
|
+
* The standard gives the contract no maximum-fee argument, so the allowance
|
|
71
|
+
* is the cap: exactly the fee read now is approved.
|
|
49
72
|
*/
|
|
50
|
-
async
|
|
51
|
-
|
|
52
|
-
this.
|
|
53
|
-
|
|
54
|
-
|
|
73
|
+
async renewSubscription() {
|
|
74
|
+
const [renewable, period, fee] = await Promise.all([
|
|
75
|
+
this.isRenewable(),
|
|
76
|
+
this.subscriptionPeriod(),
|
|
77
|
+
this.subscriptionFee()
|
|
55
78
|
]);
|
|
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]);
|
|
56
85
|
}
|
|
57
86
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* Safe to call whenever the card moves. It is a separate field from the terms
|
|
61
|
-
* URI for one reason: publishers are bound to `termsHash`, so anything sharing
|
|
62
|
-
* that slot unregisters every publisher in the app the moment it changes (see
|
|
63
|
-
* `needsReacceptance`). A card holds endpoints and pubkeys, which rotate.
|
|
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.
|
|
64
89
|
*/
|
|
65
|
-
async
|
|
66
|
-
return this.executeWrite("
|
|
90
|
+
async cancelSubscription() {
|
|
91
|
+
return this.executeWrite("cancelSubscription", [this.tokenId()]);
|
|
67
92
|
}
|
|
68
|
-
|
|
69
|
-
|
|
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)]);
|
|
70
96
|
}
|
|
71
|
-
/**
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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", []);
|
|
104
|
+
}
|
|
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", []);
|
|
77
112
|
}
|
|
78
|
-
async
|
|
79
|
-
return this.
|
|
113
|
+
async getAppOwner(appId = this.app()) {
|
|
114
|
+
return this.read("getAppOwner", [appId]);
|
|
80
115
|
}
|
|
81
116
|
/**
|
|
82
|
-
*
|
|
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.
|
|
83
120
|
*/
|
|
84
|
-
async
|
|
85
|
-
return this.executeWrite("
|
|
121
|
+
async setAppAgentUri(agentUri) {
|
|
122
|
+
return this.executeWrite("setAppAgentUri", [this.app(), agentUri]);
|
|
86
123
|
}
|
|
87
|
-
|
|
88
|
-
|
|
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]);
|
|
89
127
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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]);
|
|
96
138
|
}
|
|
97
139
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
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)`.
|
|
100
144
|
*/
|
|
101
|
-
async
|
|
102
|
-
|
|
103
|
-
if (termsHash === ZERO_HASH) throw new Error(`app ${this.appId} has published no terms — it cannot be joined until its owner sets them`);
|
|
104
|
-
return this.executeWrite("registerForApp", [this.appId, termsHash], fee);
|
|
145
|
+
async acceptPublisher(publisher) {
|
|
146
|
+
return this.executeWrite("acceptPublisher", [this.app(), publisher]);
|
|
105
147
|
}
|
|
106
148
|
/**
|
|
107
|
-
*
|
|
149
|
+
* Suspend an accepted publisher from this app, or reinstate them (owner
|
|
150
|
+
* only). An owner cannot suspend themselves.
|
|
108
151
|
*/
|
|
109
|
-
async
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
args: [this.appId, termsHash]
|
|
116
|
-
});
|
|
117
|
-
const fees = await this.publicClient.estimateFeesPerGas();
|
|
118
|
-
let gas;
|
|
119
|
-
try {
|
|
120
|
-
gas = await this.publicClient.estimateGas({
|
|
121
|
-
account: publisher,
|
|
122
|
-
to: this.contractAddress,
|
|
123
|
-
data,
|
|
124
|
-
value: fee
|
|
125
|
-
}) * 3n / 2n;
|
|
126
|
-
} catch (err) {
|
|
127
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
128
|
-
if (/revert/i.test(message)) throw new Error(`joining would revert — this wallet may already be registered, or suspended from this app: ${message}`);
|
|
129
|
-
gas = 1000000n;
|
|
130
|
-
}
|
|
131
|
-
return {
|
|
132
|
-
to: this.contractAddress,
|
|
133
|
-
data,
|
|
134
|
-
chainId: this.publicClient.chain?.id,
|
|
135
|
-
gas: toHex(gas),
|
|
136
|
-
maxFeePerGas: toHex(fees.maxFeePerGas * 2n),
|
|
137
|
-
maxPriorityFeePerGas: toHex(fees.maxPriorityFeePerGas),
|
|
138
|
-
value: toHex(fee)
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
async getAppOwner() {
|
|
142
|
-
return this.publicClient.readContract({
|
|
143
|
-
address: this.contractAddress,
|
|
144
|
-
abi: APP_REGISTRY_ABI,
|
|
145
|
-
functionName: "getAppOwner",
|
|
146
|
-
args: [this.appId]
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
async isRegisteredForApp(publisher) {
|
|
150
|
-
return this.publicClient.readContract({
|
|
151
|
-
address: this.contractAddress,
|
|
152
|
-
abi: APP_REGISTRY_ABI,
|
|
153
|
-
functionName: "isRegisteredForApp",
|
|
154
|
-
args: [this.appId, publisher]
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
async isAppSuspended() {
|
|
158
|
-
return this.publicClient.readContract({
|
|
159
|
-
address: this.contractAddress,
|
|
160
|
-
abi: APP_REGISTRY_ABI,
|
|
161
|
-
functionName: "isAppSuspended",
|
|
162
|
-
args: [this.appId]
|
|
163
|
-
});
|
|
152
|
+
async setPublisherSuspended(publisher, suspended) {
|
|
153
|
+
return this.executeWrite("setPublisherSuspended", [
|
|
154
|
+
this.app(),
|
|
155
|
+
publisher,
|
|
156
|
+
suspended
|
|
157
|
+
]);
|
|
164
158
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
abi: APP_REGISTRY_ABI,
|
|
169
|
-
functionName: "appTerms",
|
|
170
|
-
args: [this.appId]
|
|
171
|
-
});
|
|
159
|
+
/** `publisher`'s standing in this app. */
|
|
160
|
+
async status(publisher) {
|
|
161
|
+
return await this.read("statusForApp", [this.app(), publisher]);
|
|
172
162
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
});
|
|
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]);
|
|
180
169
|
}
|
|
181
|
-
/** The
|
|
182
|
-
async
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
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]);
|
|
173
|
+
return {
|
|
174
|
+
canPublish,
|
|
175
|
+
owner,
|
|
176
|
+
expiresAt
|
|
177
|
+
};
|
|
189
178
|
}
|
|
190
179
|
/**
|
|
191
180
|
* `AppAgentChanged` events, oldest first. The last one for an app is its
|
|
@@ -213,46 +202,65 @@ var AppRegistryClient = class {
|
|
|
213
202
|
transactionHash: log.transactionHash
|
|
214
203
|
}));
|
|
215
204
|
}
|
|
216
|
-
async
|
|
217
|
-
return this.
|
|
218
|
-
address: this.contractAddress,
|
|
219
|
-
abi: APP_REGISTRY_ABI,
|
|
220
|
-
functionName: "appFee",
|
|
221
|
-
args: [this.appId]
|
|
222
|
-
});
|
|
205
|
+
async admin() {
|
|
206
|
+
return this.read("admin", []);
|
|
223
207
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
208
|
+
/** The DataRegistry this contract names. */
|
|
209
|
+
async dataRegistry() {
|
|
210
|
+
return this.read("dataRegistry", []);
|
|
211
|
+
}
|
|
212
|
+
/** Whether the protocol admin has banned `wallet` network-wide. */
|
|
213
|
+
async isGloballySuspended(wallet) {
|
|
214
|
+
return this.read("globalSuspensions", [wallet]);
|
|
215
|
+
}
|
|
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]);
|
|
223
|
+
}
|
|
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]);
|
|
231
230
|
}
|
|
232
|
-
async
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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]);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
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`).
|
|
241
|
+
*/
|
|
242
|
+
async withdrawToken(token, to, amount) {
|
|
243
|
+
return this.executeWrite("withdrawToken", [
|
|
244
|
+
token,
|
|
245
|
+
to,
|
|
246
|
+
amount
|
|
237
247
|
]);
|
|
238
|
-
const [termsHash, termsUri, fee, status, registered] = tuple;
|
|
239
|
-
return {
|
|
240
|
-
termsHash,
|
|
241
|
-
termsUri,
|
|
242
|
-
fee,
|
|
243
|
-
status,
|
|
244
|
-
registered,
|
|
245
|
-
acceptedTerms,
|
|
246
|
-
appSuspended
|
|
247
|
-
};
|
|
248
248
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
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]);
|
|
256
264
|
}
|
|
257
265
|
senderAddress() {
|
|
258
266
|
const account = this.walletClient.account;
|
|
@@ -260,7 +268,6 @@ var AppRegistryClient = class {
|
|
|
260
268
|
return account.address;
|
|
261
269
|
}
|
|
262
270
|
};
|
|
263
|
-
const ZERO_HASH = `0x${"0".repeat(64)}`;
|
|
264
271
|
|
|
265
272
|
//#endregion
|
|
266
|
-
export { AppRegistryClient
|
|
273
|
+
export { AppRegistryClient };
|