@agentxv2/sdk 0.3.0
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 +195 -0
- package/dist/a2a/a2a.d.ts +37 -0
- package/dist/a2a/a2a.d.ts.map +1 -0
- package/dist/a2a/a2a.js +252 -0
- package/dist/a2a/a2a.js.map +1 -0
- package/dist/a2a/index.d.ts +4 -0
- package/dist/a2a/index.d.ts.map +1 -0
- package/dist/a2a/index.js +4 -0
- package/dist/a2a/index.js.map +1 -0
- package/dist/agent/agent-runner.d.ts +124 -0
- package/dist/agent/agent-runner.d.ts.map +1 -0
- package/dist/agent/agent-runner.js +249 -0
- package/dist/agent/agent-runner.js.map +1 -0
- package/dist/agent/index.d.ts +3 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +3 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/config/config.d.ts +31 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +95 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/index.d.ts +4 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +4 -0
- package/dist/config/index.js.map +1 -0
- package/dist/core/crypto.d.ts +62 -0
- package/dist/core/crypto.d.ts.map +1 -0
- package/dist/core/crypto.js +291 -0
- package/dist/core/crypto.js.map +1 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +4 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/types.d.ts +296 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +30 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/connector.d.ts +43 -0
- package/dist/mcp/connector.d.ts.map +1 -0
- package/dist/mcp/connector.js +79 -0
- package/dist/mcp/connector.js.map +1 -0
- package/dist/mcp/index.d.ts +4 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +4 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/react/index.d.ts +4 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +3 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/useAgentRunner.d.ts +16 -0
- package/dist/react/useAgentRunner.d.ts.map +1 -0
- package/dist/react/useAgentRunner.js +204 -0
- package/dist/react/useAgentRunner.js.map +1 -0
- package/dist/registry/agent-registry.d.ts +52 -0
- package/dist/registry/agent-registry.d.ts.map +1 -0
- package/dist/registry/agent-registry.js +221 -0
- package/dist/registry/agent-registry.js.map +1 -0
- package/dist/registry/index.d.ts +7 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/registry/index.js +6 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/registry/ipfs-fetcher.d.ts +39 -0
- package/dist/registry/ipfs-fetcher.d.ts.map +1 -0
- package/dist/registry/ipfs-fetcher.js +139 -0
- package/dist/registry/ipfs-fetcher.js.map +1 -0
- package/dist/reputation/index.d.ts +4 -0
- package/dist/reputation/index.d.ts.map +1 -0
- package/dist/reputation/index.js +4 -0
- package/dist/reputation/index.js.map +1 -0
- package/dist/reputation/reputation.d.ts +26 -0
- package/dist/reputation/reputation.d.ts.map +1 -0
- package/dist/reputation/reputation.js +113 -0
- package/dist/reputation/reputation.js.map +1 -0
- package/dist/subscription/agent-x402.d.ts +33 -0
- package/dist/subscription/agent-x402.d.ts.map +1 -0
- package/dist/subscription/agent-x402.js +144 -0
- package/dist/subscription/agent-x402.js.map +1 -0
- package/dist/subscription/index.d.ts +6 -0
- package/dist/subscription/index.d.ts.map +1 -0
- package/dist/subscription/index.js +5 -0
- package/dist/subscription/index.js.map +1 -0
- package/dist/subscription/subscription.d.ts +67 -0
- package/dist/subscription/subscription.d.ts.map +1 -0
- package/dist/subscription/subscription.js +346 -0
- package/dist/subscription/subscription.js.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { PublicClient, WalletClient, Address } from 'viem';
|
|
2
|
+
export interface AgentX402Config {
|
|
3
|
+
subscriptionManagerAddress: Address;
|
|
4
|
+
publicClient: PublicClient;
|
|
5
|
+
walletClient: WalletClient;
|
|
6
|
+
}
|
|
7
|
+
export declare class AgentX402 {
|
|
8
|
+
private config;
|
|
9
|
+
constructor(config: AgentX402Config);
|
|
10
|
+
/**
|
|
11
|
+
* Require active subscription — or throw with auto-pay info.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* await x402.requireSubscription(agentId, address, { planIds: [1,2,3] })
|
|
15
|
+
*
|
|
16
|
+
* On success, returns silently.
|
|
17
|
+
* On failure, throws AgentXError with paymentInfo populated
|
|
18
|
+
* so the caller can auto-pay via wallet/X402.
|
|
19
|
+
*/
|
|
20
|
+
requireSubscription(agentId: number, address: Address, opts?: {
|
|
21
|
+
planIds?: number[];
|
|
22
|
+
}): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Subscribe to a plan + wait for receipt.
|
|
25
|
+
* Returns subscriptionId from the Subscribed event.
|
|
26
|
+
*
|
|
27
|
+
* NOTE: For ERC20 plans, the caller must approve token spending
|
|
28
|
+
* BEFORE calling this method. Use X402 SDK or wagmi's useWriteContract
|
|
29
|
+
* for the approve step.
|
|
30
|
+
*/
|
|
31
|
+
subscribeAndWait(planId: number, price: bigint, payToken: Address): Promise<number>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=agent-x402.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-x402.d.ts","sourceRoot":"","sources":["../../src/subscription/agent-x402.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AA4C/D,MAAM,WAAW,eAAe;IAC9B,0BAA0B,EAAE,OAAO,CAAA;IACnC,YAAY,EAAE,YAAY,CAAA;IAC1B,YAAY,EAAE,YAAY,CAAA;CAC3B;AAID,qBAAa,SAAS;IACR,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,eAAe;IAE3C;;;;;;;;;OASG;IACG,mBAAmB,CACvB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,IAAI,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,GAC5B,OAAO,CAAC,IAAI,CAAC;IAsDhB;;;;;;;OAOG;IACG,gBAAgB,CACpB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,OAAO,GAChB,OAAO,CAAC,MAAM,CAAC;CAwBnB"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// agentx-protocol — AgentX402: Auto-Subscription Gate
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Standardized error handling for wallet/X402 integration.
|
|
5
|
+
//
|
|
6
|
+
// AgentX does NOT implement X402 or wallet logic.
|
|
7
|
+
// Instead, it provides a clean subscription guard with structured
|
|
8
|
+
// error metadata so external payment layers can react.
|
|
9
|
+
//
|
|
10
|
+
// Flow:
|
|
11
|
+
// App/Agent → AgentRunner.useAgent(id)
|
|
12
|
+
// → NOT_SUBSCRIBED error + { agentId }
|
|
13
|
+
// → X402 + AgentX402.requireSubscription() checks plans
|
|
14
|
+
// → Wallet/X402 layer: user/Agent approves + subscribes
|
|
15
|
+
// → App/Agent retries AgentRunner.useAgent(id)
|
|
16
|
+
// → ✅ success
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
import { AgentXError, AgentXErrorCode } from '../core/types';
|
|
19
|
+
// ── ABI Fragments (v3 compatible) ──────────────────────────────────────────
|
|
20
|
+
const getPlanAbi = {
|
|
21
|
+
inputs: [{ name: 'planId', type: 'uint256' }],
|
|
22
|
+
name: 'getPlan',
|
|
23
|
+
outputs: [
|
|
24
|
+
{ name: 'planId', type: 'uint256' },
|
|
25
|
+
{ name: 'agentId', type: 'uint256' },
|
|
26
|
+
{ name: 'creator', type: 'address' },
|
|
27
|
+
{ name: 'price', type: 'uint256' },
|
|
28
|
+
{ name: 'period', type: 'string' },
|
|
29
|
+
{ name: 'active', type: 'bool' },
|
|
30
|
+
{ name: 'payToken', type: 'address' },
|
|
31
|
+
{ name: 'trialDays', type: 'uint256' },
|
|
32
|
+
],
|
|
33
|
+
stateMutability: 'view',
|
|
34
|
+
type: 'function',
|
|
35
|
+
};
|
|
36
|
+
const subscribeAbi = {
|
|
37
|
+
inputs: [{ name: 'planId', type: 'uint256' }],
|
|
38
|
+
name: 'subscribe',
|
|
39
|
+
outputs: [{ name: 'subscriptionId', type: 'uint256' }],
|
|
40
|
+
stateMutability: 'payable',
|
|
41
|
+
type: 'function',
|
|
42
|
+
};
|
|
43
|
+
const hasActiveSubAbi = {
|
|
44
|
+
inputs: [
|
|
45
|
+
{ name: 'subscriber', type: 'address' },
|
|
46
|
+
{ name: 'agentId', type: 'uint256' },
|
|
47
|
+
],
|
|
48
|
+
name: 'hasActiveSubscription',
|
|
49
|
+
outputs: [{ name: '', type: 'bool' }],
|
|
50
|
+
stateMutability: 'view',
|
|
51
|
+
type: 'function',
|
|
52
|
+
};
|
|
53
|
+
// ── AgentX402 ──────────────────────────────────────────────────────────────
|
|
54
|
+
export class AgentX402 {
|
|
55
|
+
config;
|
|
56
|
+
constructor(config) {
|
|
57
|
+
this.config = config;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Require active subscription — or throw with auto-pay info.
|
|
61
|
+
*
|
|
62
|
+
* Usage:
|
|
63
|
+
* await x402.requireSubscription(agentId, address, { planIds: [1,2,3] })
|
|
64
|
+
*
|
|
65
|
+
* On success, returns silently.
|
|
66
|
+
* On failure, throws AgentXError with paymentInfo populated
|
|
67
|
+
* so the caller can auto-pay via wallet/X402.
|
|
68
|
+
*/
|
|
69
|
+
async requireSubscription(agentId, address, opts) {
|
|
70
|
+
const { publicClient, subscriptionManagerAddress } = this.config;
|
|
71
|
+
const isActive = (await publicClient.readContract({
|
|
72
|
+
address: subscriptionManagerAddress,
|
|
73
|
+
abi: [hasActiveSubAbi],
|
|
74
|
+
functionName: 'hasActiveSubscription',
|
|
75
|
+
args: [address, BigInt(agentId)],
|
|
76
|
+
}));
|
|
77
|
+
if (isActive)
|
|
78
|
+
return; // ✅ already subscribed
|
|
79
|
+
// ── Build payment info for X402 layer ──
|
|
80
|
+
const plans = [];
|
|
81
|
+
if (opts?.planIds && opts.planIds.length > 0) {
|
|
82
|
+
for (const planId of opts.planIds) {
|
|
83
|
+
try {
|
|
84
|
+
const plan = (await publicClient.readContract({
|
|
85
|
+
address: subscriptionManagerAddress,
|
|
86
|
+
abi: [getPlanAbi],
|
|
87
|
+
functionName: 'getPlan',
|
|
88
|
+
args: [BigInt(planId)],
|
|
89
|
+
}));
|
|
90
|
+
const planAgentId = Number(plan[1]);
|
|
91
|
+
const planActive = plan[5];
|
|
92
|
+
if (planActive && planAgentId === agentId) {
|
|
93
|
+
plans.push({
|
|
94
|
+
planId: Number(plan[0]),
|
|
95
|
+
price: plan[3],
|
|
96
|
+
period: plan[4],
|
|
97
|
+
payToken: plan[6],
|
|
98
|
+
trialDays: Number(plan[7]),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// skip invalid plan IDs silently
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const err = new AgentXError(AgentXErrorCode.NOT_SUBSCRIBED, `No active subscription for Agent #${agentId}. Use error.paymentInfo for auto-subscribe via X402/wallet.`);
|
|
108
|
+
err.paymentInfo = {
|
|
109
|
+
agentId,
|
|
110
|
+
plans: plans.length > 0 ? plans : undefined,
|
|
111
|
+
};
|
|
112
|
+
throw err;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Subscribe to a plan + wait for receipt.
|
|
116
|
+
* Returns subscriptionId from the Subscribed event.
|
|
117
|
+
*
|
|
118
|
+
* NOTE: For ERC20 plans, the caller must approve token spending
|
|
119
|
+
* BEFORE calling this method. Use X402 SDK or wagmi's useWriteContract
|
|
120
|
+
* for the approve step.
|
|
121
|
+
*/
|
|
122
|
+
async subscribeAndWait(planId, price, payToken) {
|
|
123
|
+
const { publicClient, walletClient, subscriptionManagerAddress } = this.config;
|
|
124
|
+
const isETH = payToken === '0x0000000000000000000000000000000000000000';
|
|
125
|
+
const { request } = await publicClient.simulateContract({
|
|
126
|
+
address: subscriptionManagerAddress,
|
|
127
|
+
abi: [subscribeAbi],
|
|
128
|
+
functionName: 'subscribe',
|
|
129
|
+
args: [BigInt(planId)],
|
|
130
|
+
account: walletClient.account?.address,
|
|
131
|
+
value: isETH ? price : 0n,
|
|
132
|
+
});
|
|
133
|
+
const hash = await walletClient.writeContract(request);
|
|
134
|
+
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
135
|
+
// Parse subscriptionId from Subscribed event (topic[1])
|
|
136
|
+
// event Subscribed(uint256 indexed subscriptionId, ...)
|
|
137
|
+
const subIdHex = receipt.logs[0]?.topics?.[1];
|
|
138
|
+
if (!subIdHex || subIdHex === '0x') {
|
|
139
|
+
throw new Error('Failed to parse subscriptionId from Subscribed event');
|
|
140
|
+
}
|
|
141
|
+
return Number(BigInt(subIdHex));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=agent-x402.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-x402.js","sourceRoot":"","sources":["../../src/subscription/agent-x402.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,sDAAsD;AACtD,8EAA8E;AAC9E,2DAA2D;AAC3D,EAAE;AACF,kDAAkD;AAClD,kEAAkE;AAClE,uDAAuD;AACvD,EAAE;AACF,QAAQ;AACR,yCAAyC;AACzC,2CAA2C;AAC3C,4DAA4D;AAC5D,4DAA4D;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;YACnB,YAAY,EAAE,WAAW;YACzB,IAAI,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACtB,OAAO,EAAE,YAAY,CAAC,OAAO,EAAE,OAAkB;YACjD,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;SAC1B,CAAC,CAAA;QAEF,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;QACtD,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,yBAAyB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAA;QAEtE,wDAAwD;QACxD,wDAAwD;QACxD,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAA;QAC7C,IAAI,CAAC,QAAQ,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAA;QACzE,CAAC;QACD,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAA;IACjC,CAAC;CACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { SubscriptionManager, guardSubscription } from './subscription';
|
|
2
|
+
export type { SubscriptionConfig, PlanDetail, SubscriptionDetail } from './subscription';
|
|
3
|
+
export { AgentX402 } from './agent-x402';
|
|
4
|
+
export type { AgentX402Config } from './agent-x402';
|
|
5
|
+
export declare const SUBSCRIPTION_VERSION = "0.2.0";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/subscription/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AACvE,YAAY,EAAE,kBAAkB,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACxF,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACnD,eAAO,MAAM,oBAAoB,UAAU,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/subscription/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAEvE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,MAAM,CAAC,MAAM,oBAAoB,GAAG,OAAO,CAAA"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { PublicClient, WalletClient, Address, Hash } from 'viem';
|
|
2
|
+
import type { AgentSubscription } from '../core/types';
|
|
3
|
+
export interface SubscriptionConfig {
|
|
4
|
+
contractAddress: Address;
|
|
5
|
+
publicClient: PublicClient;
|
|
6
|
+
walletClient: WalletClient;
|
|
7
|
+
}
|
|
8
|
+
export interface PlanDetail {
|
|
9
|
+
planId: number;
|
|
10
|
+
agentId: number;
|
|
11
|
+
creator: Address;
|
|
12
|
+
price: bigint;
|
|
13
|
+
period: string;
|
|
14
|
+
active: boolean;
|
|
15
|
+
payToken: Address;
|
|
16
|
+
trialDays: number;
|
|
17
|
+
}
|
|
18
|
+
export interface SubscriptionDetail {
|
|
19
|
+
subscriptionId: number;
|
|
20
|
+
subscriber: Address;
|
|
21
|
+
agentId: number;
|
|
22
|
+
status: number;
|
|
23
|
+
startedAt: number;
|
|
24
|
+
expiresAt: number;
|
|
25
|
+
period: string;
|
|
26
|
+
payToken: Address;
|
|
27
|
+
amountPaid: bigint;
|
|
28
|
+
trialActive: boolean;
|
|
29
|
+
trialEndsAt: number;
|
|
30
|
+
fundsReleased: boolean;
|
|
31
|
+
}
|
|
32
|
+
export declare class SubscriptionManager {
|
|
33
|
+
private address;
|
|
34
|
+
private publicClient;
|
|
35
|
+
private walletClient;
|
|
36
|
+
constructor(config: SubscriptionConfig);
|
|
37
|
+
/** Get current platform fee in basis points (e.g. 250 = 2.5%). */
|
|
38
|
+
getPlatformFeeBps(): Promise<number>;
|
|
39
|
+
/** Check if a token is whitelisted for payments. */
|
|
40
|
+
isTokenWhitelisted(token: Address): Promise<boolean>;
|
|
41
|
+
/** Get full plan details with v2 fields. */
|
|
42
|
+
getPlan(planId: number): Promise<PlanDetail>;
|
|
43
|
+
/**
|
|
44
|
+
* Subscribe to a plan.
|
|
45
|
+
* For ETH plans: pass valueWei = plan.price.
|
|
46
|
+
* For ERC20 plans: auto-detects from plan.payToken, calls approve + subscribe.
|
|
47
|
+
* User must have approved this contract for plan.price tokens.
|
|
48
|
+
*/
|
|
49
|
+
subscribe(planId: number, opts?: {
|
|
50
|
+
valueWei?: bigint;
|
|
51
|
+
approveTokenFirst?: boolean;
|
|
52
|
+
}): Promise<{
|
|
53
|
+
subscriptionId: number;
|
|
54
|
+
txHash: Hash;
|
|
55
|
+
}>;
|
|
56
|
+
/** Release escrowed funds to creator after trial window ends. */
|
|
57
|
+
releaseFunds(subscriptionId: number): Promise<Hash>;
|
|
58
|
+
/** Cancel subscription (trial refund if within window). */
|
|
59
|
+
cancel(subscriptionId: number): Promise<Hash>;
|
|
60
|
+
hasActiveSubscription(subscriber: Address, agentId: number): Promise<boolean>;
|
|
61
|
+
getSubscription(subscriber: Address, agentId: number): Promise<AgentSubscription | null>;
|
|
62
|
+
/** Get full subscription detail with v2 fields (trial, payToken, fundsReleased). */
|
|
63
|
+
getSubscriptionDetail(subscriptionId: number): Promise<SubscriptionDetail>;
|
|
64
|
+
getUserSubscriptions(user: Address): Promise<number[]>;
|
|
65
|
+
}
|
|
66
|
+
export declare function guardSubscription(manager: SubscriptionManager, user: Address, agentId: number): Promise<AgentSubscription>;
|
|
67
|
+
//# sourceMappingURL=subscription.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAY1D,4CAA4C;IACtC,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAkBlD;;;;;OAKG;IACG,SAAS,CACb,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,iBAAiB,CAAC,EAAE,OAAO,CAAA;KAAE,GACxD,OAAO,CAAC;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,IAAI,CAAA;KAAE,CAAC;IAuDpD,iEAAiE;IAC3D,YAAY,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAczD,2DAA2D;IACrD,MAAM,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgB7C,qBAAqB,CAAC,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAU7E,eAAe,CAAC,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAqB9F,oFAAoF;IAC9E,qBAAqB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAoB1E,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAS7D;AAID,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,mBAAmB,EAC5B,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,iBAAiB,CAAC,CAW5B"}
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// @agentx/sdk — Subscription Manager v2
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Wraps SubscriptionManager v2 contract (escrow, platform fee, multi-currency).
|
|
5
|
+
// Uses viem PublicClient / WalletClient (chain-agnostic).
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
// ── ABI Fragments (v2) ─────────────────────────────────────────────────────
|
|
8
|
+
const SUBSCRIPTION_ABI_V2 = {
|
|
9
|
+
// Admin
|
|
10
|
+
platformFeeBps: {
|
|
11
|
+
inputs: [], name: 'platformFeeBps',
|
|
12
|
+
outputs: [{ name: '', type: 'uint256' }],
|
|
13
|
+
stateMutability: 'view', type: 'function',
|
|
14
|
+
},
|
|
15
|
+
tokenWhitelist: {
|
|
16
|
+
inputs: [{ name: 'token', type: 'address' }],
|
|
17
|
+
name: 'tokenWhitelist',
|
|
18
|
+
outputs: [{ name: '', type: 'bool' }],
|
|
19
|
+
stateMutability: 'view', type: 'function',
|
|
20
|
+
},
|
|
21
|
+
// Plans
|
|
22
|
+
createPlan: {
|
|
23
|
+
inputs: [
|
|
24
|
+
{ name: 'agentId', type: 'uint256' },
|
|
25
|
+
{ name: 'price', type: 'uint256' },
|
|
26
|
+
{ name: 'period', type: 'string' },
|
|
27
|
+
{ name: 'payToken', type: 'address' },
|
|
28
|
+
{ name: 'trialDays', type: 'uint256' },
|
|
29
|
+
],
|
|
30
|
+
name: 'createPlan',
|
|
31
|
+
outputs: [{ name: 'planId', type: 'uint256' }],
|
|
32
|
+
stateMutability: 'nonpayable', type: 'function',
|
|
33
|
+
},
|
|
34
|
+
getPlan: {
|
|
35
|
+
inputs: [{ name: 'planId', type: 'uint256' }],
|
|
36
|
+
name: 'getPlan',
|
|
37
|
+
outputs: [
|
|
38
|
+
{ name: 'planId', type: 'uint256' },
|
|
39
|
+
{ name: 'agentId', type: 'uint256' },
|
|
40
|
+
{ name: 'creator', type: 'address' },
|
|
41
|
+
{ name: 'price', type: 'uint256' },
|
|
42
|
+
{ name: 'period', type: 'string' },
|
|
43
|
+
{ name: 'active', type: 'bool' },
|
|
44
|
+
{ name: 'payToken', type: 'address' },
|
|
45
|
+
{ name: 'trialDays', type: 'uint256' },
|
|
46
|
+
],
|
|
47
|
+
stateMutability: 'view', type: 'function',
|
|
48
|
+
},
|
|
49
|
+
// Subscribe
|
|
50
|
+
subscribe: {
|
|
51
|
+
inputs: [{ name: 'planId', type: 'uint256' }],
|
|
52
|
+
name: 'subscribe',
|
|
53
|
+
outputs: [{ name: 'subscriptionId', type: 'uint256' }],
|
|
54
|
+
stateMutability: 'payable', type: 'function',
|
|
55
|
+
},
|
|
56
|
+
// Trial / Release
|
|
57
|
+
releaseFunds: {
|
|
58
|
+
inputs: [{ name: 'subscriptionId', type: 'uint256' }],
|
|
59
|
+
name: 'releaseFunds',
|
|
60
|
+
outputs: [],
|
|
61
|
+
stateMutability: 'nonpayable', type: 'function',
|
|
62
|
+
},
|
|
63
|
+
cancelSubscription: {
|
|
64
|
+
inputs: [{ name: 'subscriptionId', type: 'uint256' }],
|
|
65
|
+
name: 'cancelSubscription',
|
|
66
|
+
outputs: [],
|
|
67
|
+
stateMutability: 'nonpayable', type: 'function',
|
|
68
|
+
},
|
|
69
|
+
// Queries
|
|
70
|
+
getSubscription: {
|
|
71
|
+
inputs: [
|
|
72
|
+
{ name: 'subscriber', type: 'address' },
|
|
73
|
+
{ name: 'agentId', type: 'uint256' },
|
|
74
|
+
],
|
|
75
|
+
name: 'getSubscription',
|
|
76
|
+
outputs: [
|
|
77
|
+
{ name: 'subscriptionId', type: 'uint256' },
|
|
78
|
+
{ name: 'subscriber', type: 'address' },
|
|
79
|
+
{ name: 'agentId', type: 'uint256' },
|
|
80
|
+
{ name: 'status', type: 'uint8' },
|
|
81
|
+
{ name: 'startedAt', type: 'uint256' },
|
|
82
|
+
{ name: 'expiresAt', type: 'uint256' },
|
|
83
|
+
{ name: 'period', type: 'string' },
|
|
84
|
+
],
|
|
85
|
+
stateMutability: 'view', type: 'function',
|
|
86
|
+
},
|
|
87
|
+
hasActiveSubscription: {
|
|
88
|
+
inputs: [
|
|
89
|
+
{ name: 'subscriber', type: 'address' },
|
|
90
|
+
{ name: 'agentId', type: 'uint256' },
|
|
91
|
+
],
|
|
92
|
+
name: 'hasActiveSubscription',
|
|
93
|
+
outputs: [{ name: '', type: 'bool' }],
|
|
94
|
+
stateMutability: 'view', type: 'function',
|
|
95
|
+
},
|
|
96
|
+
getUserSubscriptions: {
|
|
97
|
+
inputs: [{ name: 'user', type: 'address' }],
|
|
98
|
+
name: 'getUserSubscriptions',
|
|
99
|
+
outputs: [{ name: '', type: 'uint256[]' }],
|
|
100
|
+
stateMutability: 'view', type: 'function',
|
|
101
|
+
},
|
|
102
|
+
getSubscriptionDetail: {
|
|
103
|
+
inputs: [{ name: 'subscriptionId', type: 'uint256' }],
|
|
104
|
+
name: 'getSubscriptionDetail',
|
|
105
|
+
outputs: [
|
|
106
|
+
{ name: 'subscriptionId', type: 'uint256' },
|
|
107
|
+
{ name: 'subscriber', type: 'address' },
|
|
108
|
+
{ name: 'agentId', type: 'uint256' },
|
|
109
|
+
{ name: 'status', type: 'uint8' },
|
|
110
|
+
{ name: 'startedAt', type: 'uint256' },
|
|
111
|
+
{ name: 'expiresAt', type: 'uint256' },
|
|
112
|
+
{ name: 'period', type: 'string' },
|
|
113
|
+
{ name: 'payToken', type: 'address' },
|
|
114
|
+
{ name: 'amountPaid', type: 'uint256' },
|
|
115
|
+
{ name: 'trialActive', type: 'bool' },
|
|
116
|
+
{ name: 'trialEndsAt', type: 'uint256' },
|
|
117
|
+
{ name: 'fundsReleased', type: 'bool' },
|
|
118
|
+
],
|
|
119
|
+
stateMutability: 'view', type: 'function',
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
// ── ERC20 ABI (approve) ────────────────────────────────────────────────────
|
|
123
|
+
const ERC20_ABI = {
|
|
124
|
+
approve: {
|
|
125
|
+
inputs: [
|
|
126
|
+
{ name: 'spender', type: 'address' },
|
|
127
|
+
{ name: 'amount', type: 'uint256' },
|
|
128
|
+
],
|
|
129
|
+
name: 'approve',
|
|
130
|
+
outputs: [{ name: '', type: 'bool' }],
|
|
131
|
+
stateMutability: 'nonpayable', type: 'function',
|
|
132
|
+
},
|
|
133
|
+
allowance: {
|
|
134
|
+
inputs: [
|
|
135
|
+
{ name: 'owner', type: 'address' },
|
|
136
|
+
{ name: 'spender', type: 'address' },
|
|
137
|
+
],
|
|
138
|
+
name: 'allowance',
|
|
139
|
+
outputs: [{ name: '', type: 'uint256' }],
|
|
140
|
+
stateMutability: 'view', type: 'function',
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
// ── Subscription Manager ───────────────────────────────────────────────────
|
|
144
|
+
export class SubscriptionManager {
|
|
145
|
+
address;
|
|
146
|
+
publicClient;
|
|
147
|
+
walletClient;
|
|
148
|
+
constructor(config) {
|
|
149
|
+
this.address = config.contractAddress;
|
|
150
|
+
this.publicClient = config.publicClient;
|
|
151
|
+
this.walletClient = config.walletClient;
|
|
152
|
+
}
|
|
153
|
+
// ── Config Read ──────────────────────────────────────────────────────────
|
|
154
|
+
/** Get current platform fee in basis points (e.g. 250 = 2.5%). */
|
|
155
|
+
async getPlatformFeeBps() {
|
|
156
|
+
const result = await this.publicClient.readContract({
|
|
157
|
+
address: this.address,
|
|
158
|
+
abi: [SUBSCRIPTION_ABI_V2.platformFeeBps],
|
|
159
|
+
functionName: 'platformFeeBps',
|
|
160
|
+
});
|
|
161
|
+
return Number(result);
|
|
162
|
+
}
|
|
163
|
+
/** Check if a token is whitelisted for payments. */
|
|
164
|
+
async isTokenWhitelisted(token) {
|
|
165
|
+
const result = await this.publicClient.readContract({
|
|
166
|
+
address: this.address,
|
|
167
|
+
abi: [SUBSCRIPTION_ABI_V2.tokenWhitelist],
|
|
168
|
+
functionName: 'tokenWhitelist',
|
|
169
|
+
args: [token],
|
|
170
|
+
});
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
173
|
+
// ── Plans ────────────────────────────────────────────────────────────────
|
|
174
|
+
/** Get full plan details with v2 fields. */
|
|
175
|
+
async getPlan(planId) {
|
|
176
|
+
const result = await this.publicClient.readContract({
|
|
177
|
+
address: this.address,
|
|
178
|
+
abi: [SUBSCRIPTION_ABI_V2.getPlan],
|
|
179
|
+
functionName: 'getPlan',
|
|
180
|
+
args: [BigInt(planId)],
|
|
181
|
+
});
|
|
182
|
+
const [pid, aid, creator, price, period, active, payToken, trialDays] = result;
|
|
183
|
+
return {
|
|
184
|
+
planId: Number(pid), agentId: Number(aid),
|
|
185
|
+
creator: creator, price, period, active,
|
|
186
|
+
payToken: payToken, trialDays: Number(trialDays),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
// ── Subscribe ────────────────────────────────────────────────────────────
|
|
190
|
+
/**
|
|
191
|
+
* Subscribe to a plan.
|
|
192
|
+
* For ETH plans: pass valueWei = plan.price.
|
|
193
|
+
* For ERC20 plans: auto-detects from plan.payToken, calls approve + subscribe.
|
|
194
|
+
* User must have approved this contract for plan.price tokens.
|
|
195
|
+
*/
|
|
196
|
+
async subscribe(planId, opts) {
|
|
197
|
+
const [account] = await this.walletClient.getAddresses();
|
|
198
|
+
if (!account)
|
|
199
|
+
throw new Error('Wallet not connected');
|
|
200
|
+
const plan = await this.getPlan(planId);
|
|
201
|
+
if (!plan.active)
|
|
202
|
+
throw new Error('Plan not active');
|
|
203
|
+
if (plan.payToken === '0x0000000000000000000000000000000000000000') {
|
|
204
|
+
// ── ETH ──
|
|
205
|
+
const value = opts?.valueWei ?? plan.price;
|
|
206
|
+
const { request } = await this.publicClient.simulateContract({
|
|
207
|
+
account,
|
|
208
|
+
address: this.address,
|
|
209
|
+
abi: [SUBSCRIPTION_ABI_V2.subscribe],
|
|
210
|
+
functionName: 'subscribe',
|
|
211
|
+
args: [BigInt(planId)],
|
|
212
|
+
value,
|
|
213
|
+
});
|
|
214
|
+
const hash = await this.walletClient.writeContract(request);
|
|
215
|
+
return { subscriptionId: 0, txHash: hash };
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
// ── ERC20 ──
|
|
219
|
+
// Optionally approve first
|
|
220
|
+
if (opts?.approveTokenFirst !== false) {
|
|
221
|
+
const allowance = await this.publicClient.readContract({
|
|
222
|
+
address: plan.payToken,
|
|
223
|
+
abi: [ERC20_ABI.allowance],
|
|
224
|
+
functionName: 'allowance',
|
|
225
|
+
args: [account, this.address],
|
|
226
|
+
});
|
|
227
|
+
if (allowance < plan.price) {
|
|
228
|
+
const { request: approveReq } = await this.publicClient.simulateContract({
|
|
229
|
+
account,
|
|
230
|
+
address: plan.payToken,
|
|
231
|
+
abi: [ERC20_ABI.approve],
|
|
232
|
+
functionName: 'approve',
|
|
233
|
+
args: [this.address, plan.price],
|
|
234
|
+
});
|
|
235
|
+
await this.walletClient.writeContract(approveReq);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
const { request } = await this.publicClient.simulateContract({
|
|
239
|
+
account,
|
|
240
|
+
address: this.address,
|
|
241
|
+
abi: [SUBSCRIPTION_ABI_V2.subscribe],
|
|
242
|
+
functionName: 'subscribe',
|
|
243
|
+
args: [BigInt(planId)],
|
|
244
|
+
});
|
|
245
|
+
const hash = await this.walletClient.writeContract(request);
|
|
246
|
+
return { subscriptionId: 0, txHash: hash };
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/** Release escrowed funds to creator after trial window ends. */
|
|
250
|
+
async releaseFunds(subscriptionId) {
|
|
251
|
+
const [account] = await this.walletClient.getAddresses();
|
|
252
|
+
if (!account)
|
|
253
|
+
throw new Error('Wallet not connected');
|
|
254
|
+
const { request } = await this.publicClient.simulateContract({
|
|
255
|
+
account,
|
|
256
|
+
address: this.address,
|
|
257
|
+
abi: [SUBSCRIPTION_ABI_V2.releaseFunds],
|
|
258
|
+
functionName: 'releaseFunds',
|
|
259
|
+
args: [BigInt(subscriptionId)],
|
|
260
|
+
});
|
|
261
|
+
return this.walletClient.writeContract(request);
|
|
262
|
+
}
|
|
263
|
+
/** Cancel subscription (trial refund if within window). */
|
|
264
|
+
async cancel(subscriptionId) {
|
|
265
|
+
const [account] = await this.walletClient.getAddresses();
|
|
266
|
+
if (!account)
|
|
267
|
+
throw new Error('Wallet not connected');
|
|
268
|
+
const { request } = await this.publicClient.simulateContract({
|
|
269
|
+
account,
|
|
270
|
+
address: this.address,
|
|
271
|
+
abi: [SUBSCRIPTION_ABI_V2.cancelSubscription],
|
|
272
|
+
functionName: 'cancelSubscription',
|
|
273
|
+
args: [BigInt(subscriptionId)],
|
|
274
|
+
});
|
|
275
|
+
return this.walletClient.writeContract(request);
|
|
276
|
+
}
|
|
277
|
+
// ── Read ─────────────────────────────────────────────────────────────────
|
|
278
|
+
async hasActiveSubscription(subscriber, agentId) {
|
|
279
|
+
const result = await this.publicClient.readContract({
|
|
280
|
+
address: this.address,
|
|
281
|
+
abi: [SUBSCRIPTION_ABI_V2.hasActiveSubscription],
|
|
282
|
+
functionName: 'hasActiveSubscription',
|
|
283
|
+
args: [subscriber, BigInt(agentId)],
|
|
284
|
+
});
|
|
285
|
+
return result;
|
|
286
|
+
}
|
|
287
|
+
async getSubscription(subscriber, agentId) {
|
|
288
|
+
const result = await this.publicClient.readContract({
|
|
289
|
+
address: this.address,
|
|
290
|
+
abi: [SUBSCRIPTION_ABI_V2.getSubscription],
|
|
291
|
+
functionName: 'getSubscription',
|
|
292
|
+
args: [subscriber, BigInt(agentId)],
|
|
293
|
+
});
|
|
294
|
+
const [subId, sub, aId, status, started, expires, period] = result;
|
|
295
|
+
if (Number(subId) === 0)
|
|
296
|
+
return null;
|
|
297
|
+
return {
|
|
298
|
+
subscriptionId: Number(subId),
|
|
299
|
+
subscriber: sub,
|
|
300
|
+
agentId: Number(aId),
|
|
301
|
+
status: ['active', 'expired', 'cancelled', 'pending'][status],
|
|
302
|
+
startedAt: Number(started),
|
|
303
|
+
expiresAt: Number(expires),
|
|
304
|
+
period,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
/** Get full subscription detail with v2 fields (trial, payToken, fundsReleased). */
|
|
308
|
+
async getSubscriptionDetail(subscriptionId) {
|
|
309
|
+
const result = await this.publicClient.readContract({
|
|
310
|
+
address: this.address,
|
|
311
|
+
abi: [SUBSCRIPTION_ABI_V2.getSubscriptionDetail],
|
|
312
|
+
functionName: 'getSubscriptionDetail',
|
|
313
|
+
args: [BigInt(subscriptionId)],
|
|
314
|
+
});
|
|
315
|
+
const [sid, sub, aId, status, started, expires, period, payToken, amountPaid, trialActive, trialEndsAt, fundsReleased] = result;
|
|
316
|
+
return {
|
|
317
|
+
subscriptionId: Number(sid), subscriber: sub,
|
|
318
|
+
agentId: Number(aId), status, startedAt: Number(started),
|
|
319
|
+
expiresAt: Number(expires), period,
|
|
320
|
+
payToken: payToken, amountPaid,
|
|
321
|
+
trialActive, trialEndsAt: Number(trialEndsAt), fundsReleased,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
async getUserSubscriptions(user) {
|
|
325
|
+
const result = await this.publicClient.readContract({
|
|
326
|
+
address: this.address,
|
|
327
|
+
abi: [SUBSCRIPTION_ABI_V2.getUserSubscriptions],
|
|
328
|
+
functionName: 'getUserSubscriptions',
|
|
329
|
+
args: [user],
|
|
330
|
+
});
|
|
331
|
+
return result.map(Number);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
// ── Subscription Guard ─────────────────────────────────────────────────────
|
|
335
|
+
export async function guardSubscription(manager, user, agentId) {
|
|
336
|
+
const active = await manager.hasActiveSubscription(user, agentId);
|
|
337
|
+
if (!active) {
|
|
338
|
+
throw new Error(`No active subscription for agent #${agentId}. ` +
|
|
339
|
+
`Address ${user} must purchase a subscription first.`);
|
|
340
|
+
}
|
|
341
|
+
const sub = await manager.getSubscription(user, agentId);
|
|
342
|
+
if (!sub)
|
|
343
|
+
throw new Error(`Subscription not found for agent #${agentId}`);
|
|
344
|
+
return sub;
|
|
345
|
+
}
|
|
346
|
+
//# sourceMappingURL=subscription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription.js","sourceRoot":"","sources":["../../src/subscription/subscription.ts"],"names":[],"mappings":"AAAA,8EAA8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