@agirails/sdk 2.2.3 → 2.3.1
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 +65 -31
- package/dist/ACTPClient.d.ts +42 -1
- package/dist/ACTPClient.d.ts.map +1 -1
- package/dist/ACTPClient.js +207 -22
- package/dist/ACTPClient.js.map +1 -1
- package/dist/abi/AgentRegistry.json +133 -0
- package/dist/adapters/AdapterRouter.d.ts.map +1 -1
- package/dist/adapters/AdapterRouter.js.map +1 -1
- package/dist/adapters/BasicAdapter.d.ts +10 -1
- package/dist/adapters/BasicAdapter.d.ts.map +1 -1
- package/dist/adapters/BasicAdapter.js +36 -1
- package/dist/adapters/BasicAdapter.js.map +1 -1
- package/dist/adapters/X402Adapter.d.ts +34 -7
- package/dist/adapters/X402Adapter.d.ts.map +1 -1
- package/dist/adapters/X402Adapter.js +36 -8
- package/dist/adapters/X402Adapter.js.map +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/cli/commands/diff.d.ts +11 -0
- package/dist/cli/commands/diff.d.ts.map +1 -0
- package/dist/cli/commands/diff.js +115 -0
- package/dist/cli/commands/diff.js.map +1 -0
- package/dist/cli/commands/init.d.ts +1 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +260 -19
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/publish.d.ts +11 -0
- package/dist/cli/commands/publish.d.ts.map +1 -0
- package/dist/cli/commands/publish.js +170 -0
- package/dist/cli/commands/publish.js.map +1 -0
- package/dist/cli/commands/pull.d.ts +12 -0
- package/dist/cli/commands/pull.d.ts.map +1 -0
- package/dist/cli/commands/pull.js +99 -0
- package/dist/cli/commands/pull.js.map +1 -0
- package/dist/cli/commands/register.d.ts +16 -0
- package/dist/cli/commands/register.d.ts.map +1 -0
- package/dist/cli/commands/register.js +211 -0
- package/dist/cli/commands/register.js.map +1 -0
- package/dist/cli/index.js +10 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/utils/config.d.ts +6 -0
- package/dist/cli/utils/config.d.ts.map +1 -1
- package/dist/cli/utils/config.js.map +1 -1
- package/dist/config/agirailsmd.d.ts +94 -0
- package/dist/config/agirailsmd.d.ts.map +1 -0
- package/dist/config/agirailsmd.js +209 -0
- package/dist/config/agirailsmd.js.map +1 -0
- package/dist/config/networks.d.ts +22 -4
- package/dist/config/networks.d.ts.map +1 -1
- package/dist/config/networks.js +64 -26
- package/dist/config/networks.js.map +1 -1
- package/dist/config/publishPipeline.d.ts +75 -0
- package/dist/config/publishPipeline.d.ts.map +1 -0
- package/dist/config/publishPipeline.js +193 -0
- package/dist/config/publishPipeline.js.map +1 -0
- package/dist/config/syncOperations.d.ts +67 -0
- package/dist/config/syncOperations.d.ts.map +1 -0
- package/dist/config/syncOperations.js +208 -0
- package/dist/config/syncOperations.js.map +1 -0
- package/dist/erc8004/ERC8004Bridge.d.ts.map +1 -1
- package/dist/erc8004/ERC8004Bridge.js +6 -5
- package/dist/erc8004/ERC8004Bridge.js.map +1 -1
- package/dist/erc8004/ReputationReporter.d.ts.map +1 -1
- package/dist/erc8004/ReputationReporter.js +9 -12
- package/dist/erc8004/ReputationReporter.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -3
- package/dist/index.js.map +1 -1
- package/dist/level0/request.d.ts.map +1 -1
- package/dist/level0/request.js +23 -86
- package/dist/level0/request.js.map +1 -1
- package/dist/level1/Agent.d.ts +0 -11
- package/dist/level1/Agent.d.ts.map +1 -1
- package/dist/level1/Agent.js +19 -36
- package/dist/level1/Agent.js.map +1 -1
- package/dist/protocol/ACTPKernel.d.ts +7 -1
- package/dist/protocol/ACTPKernel.d.ts.map +1 -1
- package/dist/protocol/ACTPKernel.js +13 -10
- package/dist/protocol/ACTPKernel.js.map +1 -1
- package/dist/protocol/EventMonitor.d.ts +14 -0
- package/dist/protocol/EventMonitor.d.ts.map +1 -1
- package/dist/protocol/EventMonitor.js +14 -0
- package/dist/protocol/EventMonitor.js.map +1 -1
- package/dist/registry/AgentRegistryClient.d.ts +75 -0
- package/dist/registry/AgentRegistryClient.d.ts.map +1 -0
- package/dist/registry/AgentRegistryClient.js +160 -0
- package/dist/registry/AgentRegistryClient.js.map +1 -0
- package/dist/runtime/BlockchainRuntime.d.ts +5 -0
- package/dist/runtime/BlockchainRuntime.d.ts.map +1 -1
- package/dist/runtime/BlockchainRuntime.js +1 -1
- package/dist/runtime/BlockchainRuntime.js.map +1 -1
- package/dist/storage/ArchiveBundleBuilder.d.ts.map +1 -1
- package/dist/storage/ArchiveBundleBuilder.js.map +1 -1
- package/dist/storage/ArweaveClient.d.ts.map +1 -1
- package/dist/storage/ArweaveClient.js +2 -0
- package/dist/storage/ArweaveClient.js.map +1 -1
- package/dist/storage/FilebaseClient.d.ts.map +1 -1
- package/dist/storage/FilebaseClient.js +2 -0
- package/dist/storage/FilebaseClient.js.map +1 -1
- package/dist/types/adapter.d.ts +39 -0
- package/dist/types/adapter.d.ts.map +1 -1
- package/dist/types/adapter.js +7 -0
- package/dist/types/adapter.js.map +1 -1
- package/dist/types/x402.d.ts +23 -0
- package/dist/types/x402.d.ts.map +1 -1
- package/dist/types/x402.js.map +1 -1
- package/dist/utils/ErrorRecoveryGuide.d.ts.map +1 -1
- package/dist/utils/ErrorRecoveryGuide.js +3 -2
- package/dist/utils/ErrorRecoveryGuide.js.map +1 -1
- package/dist/utils/IPFSClient.d.ts +3 -2
- package/dist/utils/IPFSClient.d.ts.map +1 -1
- package/dist/utils/IPFSClient.js +7 -5
- package/dist/utils/IPFSClient.js.map +1 -1
- package/dist/utils/computeTypeHash.js +1 -3
- package/dist/utils/computeTypeHash.js.map +1 -1
- package/dist/utils/retry.d.ts.map +1 -1
- package/dist/utils/retry.js +0 -1
- package/dist/utils/retry.js.map +1 -1
- package/dist/utils/validation.d.ts +2 -2
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +2 -2
- package/dist/utils/validation.js.map +1 -1
- package/dist/wallet/AutoWalletProvider.d.ts +77 -0
- package/dist/wallet/AutoWalletProvider.d.ts.map +1 -0
- package/dist/wallet/AutoWalletProvider.js +197 -0
- package/dist/wallet/AutoWalletProvider.js.map +1 -0
- package/dist/wallet/EOAWalletProvider.d.ts +21 -0
- package/dist/wallet/EOAWalletProvider.d.ts.map +1 -0
- package/dist/wallet/EOAWalletProvider.js +57 -0
- package/dist/wallet/EOAWalletProvider.js.map +1 -0
- package/dist/wallet/IWalletProvider.d.ts +115 -0
- package/dist/wallet/IWalletProvider.d.ts.map +1 -0
- package/dist/wallet/IWalletProvider.js +12 -0
- package/dist/wallet/IWalletProvider.js.map +1 -0
- package/dist/wallet/aa/BundlerClient.d.ts +70 -0
- package/dist/wallet/aa/BundlerClient.d.ts.map +1 -0
- package/dist/wallet/aa/BundlerClient.js +183 -0
- package/dist/wallet/aa/BundlerClient.js.map +1 -0
- package/dist/wallet/aa/DualNonceManager.d.ts +55 -0
- package/dist/wallet/aa/DualNonceManager.d.ts.map +1 -0
- package/dist/wallet/aa/DualNonceManager.js +131 -0
- package/dist/wallet/aa/DualNonceManager.js.map +1 -0
- package/dist/wallet/aa/PaymasterClient.d.ts +52 -0
- package/dist/wallet/aa/PaymasterClient.d.ts.map +1 -0
- package/dist/wallet/aa/PaymasterClient.js +115 -0
- package/dist/wallet/aa/PaymasterClient.js.map +1 -0
- package/dist/wallet/aa/TransactionBatcher.d.ts +87 -0
- package/dist/wallet/aa/TransactionBatcher.d.ts.map +1 -0
- package/dist/wallet/aa/TransactionBatcher.js +148 -0
- package/dist/wallet/aa/TransactionBatcher.js.map +1 -0
- package/dist/wallet/aa/UserOpBuilder.d.ts +71 -0
- package/dist/wallet/aa/UserOpBuilder.d.ts.map +1 -0
- package/dist/wallet/aa/UserOpBuilder.js +196 -0
- package/dist/wallet/aa/UserOpBuilder.js.map +1 -0
- package/dist/wallet/aa/constants.d.ts +54 -0
- package/dist/wallet/aa/constants.d.ts.map +1 -0
- package/dist/wallet/aa/constants.js +18 -0
- package/dist/wallet/aa/constants.js.map +1 -0
- package/dist/wallet/keystore.d.ts +16 -0
- package/dist/wallet/keystore.d.ts.map +1 -0
- package/dist/wallet/keystore.js +132 -0
- package/dist/wallet/keystore.js.map +1 -0
- package/package.json +5 -2
- package/src/ACTPClient.ts +275 -27
- package/src/abi/AgentRegistry.json +133 -0
- package/src/adapters/AdapterRouter.ts +0 -1
- package/src/adapters/BasicAdapter.ts +41 -1
- package/src/adapters/X402Adapter.ts +94 -16
- package/src/adapters/index.ts +9 -1
- package/src/cli/commands/diff.ts +141 -0
- package/src/cli/commands/init.ts +311 -22
- package/src/cli/commands/publish.ts +208 -0
- package/src/cli/commands/pull.ts +124 -0
- package/src/cli/commands/register.ts +233 -0
- package/src/cli/index.ts +12 -0
- package/src/cli/utils/config.ts +9 -0
- package/src/config/agirailsmd.ts +262 -0
- package/src/config/networks.ts +89 -26
- package/src/config/publishPipeline.ts +276 -0
- package/src/config/syncOperations.ts +279 -0
- package/src/erc8004/ERC8004Bridge.ts +6 -5
- package/src/erc8004/ReputationReporter.ts +14 -18
- package/src/index.ts +15 -0
- package/src/level0/request.ts +27 -88
- package/src/level1/Agent.ts +21 -37
- package/src/protocol/ACTPKernel.ts +20 -10
- package/src/protocol/EventMonitor.ts +14 -0
- package/src/registry/AgentRegistryClient.ts +202 -0
- package/src/runtime/BlockchainRuntime.ts +7 -1
- package/src/storage/ArchiveBundleBuilder.ts +0 -2
- package/src/storage/ArweaveClient.ts +2 -1
- package/src/storage/FilebaseClient.ts +3 -3
- package/src/types/adapter.ts +14 -0
- package/src/types/x402.ts +32 -0
- package/src/utils/ErrorRecoveryGuide.ts +4 -2
- package/src/utils/IPFSClient.ts +9 -7
- package/src/utils/computeTypeHash.ts +1 -3
- package/src/utils/retry.ts +0 -1
- package/src/utils/validation.ts +2 -2
- package/src/wallet/AutoWalletProvider.ts +294 -0
- package/src/wallet/EOAWalletProvider.ts +69 -0
- package/src/wallet/IWalletProvider.ts +133 -0
- package/src/wallet/aa/BundlerClient.ts +273 -0
- package/src/wallet/aa/DualNonceManager.ts +163 -0
- package/src/wallet/aa/PaymasterClient.ts +173 -0
- package/src/wallet/aa/TransactionBatcher.ts +240 -0
- package/src/wallet/aa/UserOpBuilder.ts +246 -0
- package/src/wallet/aa/constants.ts +60 -0
- package/src/wallet/keystore.ts +119 -0
|
@@ -22,6 +22,8 @@ import {
|
|
|
22
22
|
UnifiedPayParams,
|
|
23
23
|
UnifiedPayResult,
|
|
24
24
|
} from '../types/adapter';
|
|
25
|
+
import { IWalletProvider } from '../wallet/IWalletProvider';
|
|
26
|
+
import { ethers } from 'ethers';
|
|
25
27
|
|
|
26
28
|
/**
|
|
27
29
|
* Parameters for creating a simple payment.
|
|
@@ -116,11 +118,15 @@ export class BasicAdapter extends BaseAdapter implements IAdapter {
|
|
|
116
118
|
* @param runtime - ACTP runtime implementation (MockRuntime or BlockchainRuntime)
|
|
117
119
|
* @param requesterAddress - The requester's Ethereum address
|
|
118
120
|
* @param easHelper - Optional EAS helper for attestation verification (SECURITY FIX C-4)
|
|
121
|
+
* @param walletProvider - Optional wallet provider for AA batched payments
|
|
122
|
+
* @param contractAddresses - Optional contract addresses for batched payment encoding
|
|
119
123
|
*/
|
|
120
124
|
constructor(
|
|
121
125
|
private runtime: IACTPRuntime,
|
|
122
126
|
requesterAddress: string,
|
|
123
|
-
private easHelper?: EASHelper
|
|
127
|
+
private easHelper?: EASHelper,
|
|
128
|
+
private walletProvider?: IWalletProvider,
|
|
129
|
+
private contractAddresses?: { usdc: string; actpKernel: string; escrowVault: string }
|
|
124
130
|
) {
|
|
125
131
|
super(requesterAddress);
|
|
126
132
|
}
|
|
@@ -187,6 +193,40 @@ export class BasicAdapter extends BaseAdapter implements IAdapter {
|
|
|
187
193
|
);
|
|
188
194
|
}
|
|
189
195
|
|
|
196
|
+
// ====================================================================
|
|
197
|
+
// AIP-12: Batched payment via AA wallet (1 UserOp = 3 on-chain calls)
|
|
198
|
+
// ====================================================================
|
|
199
|
+
if (this.walletProvider?.payACTPBatched && this.contractAddresses) {
|
|
200
|
+
const serviceHash = ethers.ZeroHash;
|
|
201
|
+
const result = await this.walletProvider.payACTPBatched({
|
|
202
|
+
provider,
|
|
203
|
+
requester,
|
|
204
|
+
amount: amount.toString(),
|
|
205
|
+
deadline,
|
|
206
|
+
disputeWindow,
|
|
207
|
+
serviceHash,
|
|
208
|
+
agentId: agentId || '0',
|
|
209
|
+
contracts: this.contractAddresses,
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
if (!result.success) {
|
|
213
|
+
throw new Error(`Batched payment UserOp failed: ${result.hash}`);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return {
|
|
217
|
+
txId: result.txId,
|
|
218
|
+
provider,
|
|
219
|
+
requester,
|
|
220
|
+
amount: this.formatAmount(amount),
|
|
221
|
+
deadline: new Date(deadline * 1000).toISOString(),
|
|
222
|
+
state: 'COMMITTED',
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// ====================================================================
|
|
227
|
+
// Legacy flow: sequential on-chain calls (EOA / mock)
|
|
228
|
+
// ====================================================================
|
|
229
|
+
|
|
190
230
|
// Create transaction
|
|
191
231
|
const txId = await this.runtime.createTransaction({
|
|
192
232
|
provider,
|
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
X402Error,
|
|
36
36
|
X402ErrorCode,
|
|
37
37
|
X402Network,
|
|
38
|
+
X402FeeBreakdown,
|
|
38
39
|
isValidX402Network,
|
|
39
40
|
} from '../types/x402';
|
|
40
41
|
|
|
@@ -46,14 +47,33 @@ import {
|
|
|
46
47
|
export type FetchFunction = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
47
48
|
|
|
48
49
|
/**
|
|
49
|
-
* Transfer function for atomic payments.
|
|
50
|
-
*
|
|
50
|
+
* Transfer function for atomic payments (legacy direct transfer).
|
|
51
|
+
*
|
|
51
52
|
* @param to - Recipient address
|
|
52
53
|
* @param amount - Amount in USDC wei (string)
|
|
53
54
|
* @returns Transaction hash as proof
|
|
54
55
|
*/
|
|
55
56
|
export type TransferFunction = (to: string, amount: string) => Promise<string>;
|
|
56
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Approve function for USDC allowance (used with X402Relay).
|
|
60
|
+
*
|
|
61
|
+
* @param spender - Spender address (relay contract)
|
|
62
|
+
* @param amount - Amount in USDC wei (string)
|
|
63
|
+
* @returns Transaction hash
|
|
64
|
+
*/
|
|
65
|
+
export type ApproveFunction = (spender: string, amount: string) => Promise<string>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Relay pay function — calls X402Relay.payWithFee().
|
|
69
|
+
*
|
|
70
|
+
* @param provider - Provider address
|
|
71
|
+
* @param grossAmount - Gross USDC amount (string)
|
|
72
|
+
* @param serviceId - Service identifier (bytes32 hex)
|
|
73
|
+
* @returns Transaction hash
|
|
74
|
+
*/
|
|
75
|
+
export type RelayPayFunction = (provider: string, grossAmount: string, serviceId: string) => Promise<string>;
|
|
76
|
+
|
|
57
77
|
/** Supported HTTP methods for x402 requests */
|
|
58
78
|
export type X402HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
59
79
|
|
|
@@ -76,12 +96,15 @@ export interface X402PayParams extends UnifiedPayParams {
|
|
|
76
96
|
|
|
77
97
|
/**
|
|
78
98
|
* Configuration options for X402Adapter.
|
|
99
|
+
*
|
|
100
|
+
* For fee-enabled payments via X402Relay, provide relayAddress + approveFn + relayPayFn.
|
|
101
|
+
* Without relay config, falls back to legacy direct transfer (no platform fee).
|
|
79
102
|
*/
|
|
80
103
|
export interface X402AdapterConfig {
|
|
81
104
|
/** Expected network for validation (must match server's X-Payment-Network) */
|
|
82
105
|
expectedNetwork: X402Network;
|
|
83
106
|
|
|
84
|
-
/** Transfer function for atomic payments (
|
|
107
|
+
/** Transfer function for direct atomic payments (legacy fallback) */
|
|
85
108
|
transferFn: TransferFunction;
|
|
86
109
|
|
|
87
110
|
/** Request timeout in milliseconds (default: 30000) */
|
|
@@ -92,6 +115,20 @@ export interface X402AdapterConfig {
|
|
|
92
115
|
|
|
93
116
|
/** Default headers to include in all requests */
|
|
94
117
|
defaultHeaders?: Record<string, string>;
|
|
118
|
+
|
|
119
|
+
// --- X402Relay fee-splitting (optional, recommended) ---
|
|
120
|
+
|
|
121
|
+
/** X402Relay contract address for on-chain fee splitting */
|
|
122
|
+
relayAddress?: string;
|
|
123
|
+
|
|
124
|
+
/** USDC approve function — required when relayAddress is set */
|
|
125
|
+
approveFn?: ApproveFunction;
|
|
126
|
+
|
|
127
|
+
/** Relay payWithFee function — required when relayAddress is set */
|
|
128
|
+
relayPayFn?: RelayPayFunction;
|
|
129
|
+
|
|
130
|
+
/** Platform fee in basis points (default: 100 = 1%). Read-only display hint. */
|
|
131
|
+
platformFeeBps?: number;
|
|
95
132
|
}
|
|
96
133
|
|
|
97
134
|
/**
|
|
@@ -104,6 +141,7 @@ interface AtomicPaymentRecord {
|
|
|
104
141
|
amount: string;
|
|
105
142
|
timestamp: number;
|
|
106
143
|
endpoint: string;
|
|
144
|
+
feeBreakdown?: X402FeeBreakdown;
|
|
107
145
|
}
|
|
108
146
|
|
|
109
147
|
// ============================================================================
|
|
@@ -287,15 +325,15 @@ export class X402Adapter extends BaseAdapter implements IAdapter {
|
|
|
287
325
|
);
|
|
288
326
|
}
|
|
289
327
|
|
|
290
|
-
// Step 6: ATOMIC PAYMENT - direct transfer
|
|
291
|
-
const txHash = await this.executeAtomicPayment(paymentHeaders);
|
|
328
|
+
// Step 6: ATOMIC PAYMENT - via relay (with fee) or direct transfer (legacy)
|
|
329
|
+
const { txHash, feeBreakdown } = await this.executeAtomicPayment(paymentHeaders);
|
|
292
330
|
|
|
293
331
|
// Step 7: Retry with proof (same method/headers/body + payment proof)
|
|
294
332
|
const serviceResponse = await this.retryWithProof(
|
|
295
|
-
endpoint,
|
|
296
|
-
txHash,
|
|
297
|
-
method,
|
|
298
|
-
requestHeaders,
|
|
333
|
+
endpoint,
|
|
334
|
+
txHash,
|
|
335
|
+
method,
|
|
336
|
+
requestHeaders,
|
|
299
337
|
requestBody,
|
|
300
338
|
contentType
|
|
301
339
|
);
|
|
@@ -308,6 +346,7 @@ export class X402Adapter extends BaseAdapter implements IAdapter {
|
|
|
308
346
|
amount: paymentHeaders.amount,
|
|
309
347
|
timestamp: now,
|
|
310
348
|
endpoint,
|
|
349
|
+
feeBreakdown,
|
|
311
350
|
});
|
|
312
351
|
|
|
313
352
|
// Step 9: Return result - DONE! No release needed.
|
|
@@ -323,6 +362,7 @@ export class X402Adapter extends BaseAdapter implements IAdapter {
|
|
|
323
362
|
provider: paymentHeaders.paymentAddress.toLowerCase(),
|
|
324
363
|
requester: this.requesterAddress.toLowerCase(),
|
|
325
364
|
deadline: new Date(paymentHeaders.deadline * 1000).toISOString(),
|
|
365
|
+
feeBreakdown,
|
|
326
366
|
};
|
|
327
367
|
}
|
|
328
368
|
|
|
@@ -562,20 +602,58 @@ export class X402Adapter extends BaseAdapter implements IAdapter {
|
|
|
562
602
|
}
|
|
563
603
|
|
|
564
604
|
/**
|
|
565
|
-
* Execute atomic payment
|
|
605
|
+
* Execute atomic payment with fee splitting via X402Relay (if configured),
|
|
606
|
+
* or direct transfer as legacy fallback.
|
|
566
607
|
*
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
* - No state machine
|
|
570
|
-
* - Just transfer and done
|
|
608
|
+
* Relay flow: approve relay → relay.payWithFee(provider, gross, serviceId)
|
|
609
|
+
* Legacy flow: transferFn(provider, amount) — no fee extraction
|
|
571
610
|
*/
|
|
572
|
-
private async executeAtomicPayment(headers: X402PaymentHeaders): Promise<
|
|
611
|
+
private async executeAtomicPayment(headers: X402PaymentHeaders): Promise<{
|
|
612
|
+
txHash: string;
|
|
613
|
+
feeBreakdown?: X402FeeBreakdown;
|
|
614
|
+
}> {
|
|
573
615
|
try {
|
|
616
|
+
// Relay path: on-chain fee splitting
|
|
617
|
+
if (this.config.relayAddress && this.config.approveFn && this.config.relayPayFn) {
|
|
618
|
+
const grossAmount = headers.amount;
|
|
619
|
+
const feeBps = this.config.platformFeeBps ?? 100;
|
|
620
|
+
const MIN_FEE = 50_000n; // $0.05 USDC
|
|
621
|
+
|
|
622
|
+
// Calculate fee: max(gross * bps / 10000, MIN_FEE)
|
|
623
|
+
const grossBig = BigInt(grossAmount);
|
|
624
|
+
const bpsFee = (grossBig * BigInt(feeBps)) / 10_000n;
|
|
625
|
+
const fee = bpsFee > MIN_FEE ? bpsFee : MIN_FEE;
|
|
626
|
+
const providerNet = grossBig - fee;
|
|
627
|
+
|
|
628
|
+
// 1. Approve relay for gross amount
|
|
629
|
+
await this.config.approveFn(this.config.relayAddress, grossAmount);
|
|
630
|
+
|
|
631
|
+
// 2. Call relay.payWithFee
|
|
632
|
+
const serviceId = headers.serviceId ?? '0x' + '0'.repeat(64);
|
|
633
|
+
const txHash = await this.config.relayPayFn(
|
|
634
|
+
headers.paymentAddress,
|
|
635
|
+
grossAmount,
|
|
636
|
+
serviceId
|
|
637
|
+
);
|
|
638
|
+
|
|
639
|
+
return {
|
|
640
|
+
txHash,
|
|
641
|
+
feeBreakdown: {
|
|
642
|
+
grossAmount,
|
|
643
|
+
providerNet: providerNet.toString(),
|
|
644
|
+
platformFee: fee.toString(),
|
|
645
|
+
feeBps,
|
|
646
|
+
estimated: true,
|
|
647
|
+
},
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
// Legacy path: direct transfer, no fee
|
|
574
652
|
const txHash = await this.transferFn(
|
|
575
653
|
headers.paymentAddress,
|
|
576
654
|
headers.amount
|
|
577
655
|
);
|
|
578
|
-
return txHash;
|
|
656
|
+
return { txHash };
|
|
579
657
|
} catch (error) {
|
|
580
658
|
throw new X402Error(
|
|
581
659
|
`Atomic payment failed: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
package/src/adapters/index.ts
CHANGED
|
@@ -23,7 +23,15 @@ export {
|
|
|
23
23
|
} from './BaseAdapter';
|
|
24
24
|
export { BasicAdapter, BasicPayParams, BasicPayResult } from './BasicAdapter';
|
|
25
25
|
export { StandardAdapter, StandardTransactionParams } from './StandardAdapter';
|
|
26
|
-
export {
|
|
26
|
+
export {
|
|
27
|
+
X402Adapter,
|
|
28
|
+
X402AdapterConfig,
|
|
29
|
+
X402PayParams,
|
|
30
|
+
X402HttpMethod,
|
|
31
|
+
FetchFunction,
|
|
32
|
+
ApproveFunction,
|
|
33
|
+
RelayPayFunction,
|
|
34
|
+
} from './X402Adapter';
|
|
27
35
|
export { AdapterRegistry } from './AdapterRegistry';
|
|
28
36
|
export { AdapterRouter, AdapterSelectionResult } from './AdapterRouter';
|
|
29
37
|
export {
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diff Command - Compare local AGIRAILS.md with on-chain config
|
|
3
|
+
*
|
|
4
|
+
* Shows sync status between local file and AgentRegistry state.
|
|
5
|
+
* Terraform-style: never auto-overwrites, just shows differences.
|
|
6
|
+
*
|
|
7
|
+
* @module cli/commands/diff
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Command } from 'commander';
|
|
11
|
+
import { Output, ExitCode } from '../utils/output';
|
|
12
|
+
import { mapError } from '../utils/client';
|
|
13
|
+
import { resolve } from 'path';
|
|
14
|
+
import { ethers } from 'ethers';
|
|
15
|
+
import { diff } from '../../config/syncOperations';
|
|
16
|
+
import { getNetwork } from '../../config/networks';
|
|
17
|
+
|
|
18
|
+
// ============================================================================
|
|
19
|
+
// Command Definition
|
|
20
|
+
// ============================================================================
|
|
21
|
+
|
|
22
|
+
export function createDiffCommand(): Command {
|
|
23
|
+
const cmd = new Command('diff')
|
|
24
|
+
.description('Compare local AGIRAILS.md with on-chain config')
|
|
25
|
+
.argument('[path]', 'Path to AGIRAILS.md', './AGIRAILS.md')
|
|
26
|
+
.option('-n, --network <network>', 'Network (base-sepolia | base-mainnet)', 'base-sepolia')
|
|
27
|
+
.option('-a, --address <address>', 'Agent address to compare with')
|
|
28
|
+
.option('--json', 'Output as JSON')
|
|
29
|
+
.option('-q, --quiet', 'Output only sync status')
|
|
30
|
+
.action(async (path, options) => {
|
|
31
|
+
const output = new Output(
|
|
32
|
+
options.json ? 'json' : options.quiet ? 'quiet' : 'human'
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
await runDiff(path, options, output);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
const structuredError = mapError(error);
|
|
39
|
+
output.errorResult({
|
|
40
|
+
code: structuredError.code,
|
|
41
|
+
message: structuredError.message,
|
|
42
|
+
details: structuredError.details,
|
|
43
|
+
});
|
|
44
|
+
process.exit(ExitCode.ERROR);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return cmd;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// ============================================================================
|
|
52
|
+
// Implementation
|
|
53
|
+
// ============================================================================
|
|
54
|
+
|
|
55
|
+
interface DiffCommandOptions {
|
|
56
|
+
network: string;
|
|
57
|
+
address?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function runDiff(
|
|
61
|
+
filePath: string,
|
|
62
|
+
options: DiffCommandOptions,
|
|
63
|
+
output: Output
|
|
64
|
+
): Promise<void> {
|
|
65
|
+
const resolvedPath = resolve(filePath);
|
|
66
|
+
|
|
67
|
+
// Determine agent address
|
|
68
|
+
let agentAddress = options.address;
|
|
69
|
+
if (!agentAddress) {
|
|
70
|
+
const privateKey = process.env.ACTP_PRIVATE_KEY || process.env.PRIVATE_KEY;
|
|
71
|
+
if (!privateKey) {
|
|
72
|
+
output.error('Agent address required. Use --address or set ACTP_PRIVATE_KEY env var.');
|
|
73
|
+
process.exit(ExitCode.INVALID_INPUT);
|
|
74
|
+
}
|
|
75
|
+
agentAddress = new ethers.Wallet(privateKey).address;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const networkConfig = getNetwork(options.network);
|
|
79
|
+
if (!networkConfig.contracts.agentRegistry) {
|
|
80
|
+
output.error(`AgentRegistry not deployed on ${options.network}`);
|
|
81
|
+
process.exit(ExitCode.ERROR);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const spinner = output.spinner('Comparing local and on-chain config...');
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
const provider = new ethers.JsonRpcProvider(networkConfig.rpcUrl);
|
|
88
|
+
|
|
89
|
+
const result = await diff({
|
|
90
|
+
path: resolvedPath,
|
|
91
|
+
agentAddress,
|
|
92
|
+
registryAddress: networkConfig.contracts.agentRegistry,
|
|
93
|
+
provider,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
spinner.stop(true);
|
|
97
|
+
|
|
98
|
+
output.result(
|
|
99
|
+
{
|
|
100
|
+
status: result.status,
|
|
101
|
+
inSync: result.inSync,
|
|
102
|
+
localHash: result.localHash,
|
|
103
|
+
onChainHash: result.onChainHash,
|
|
104
|
+
onChainCID: result.onChainCID || null,
|
|
105
|
+
hasLocalFile: result.hasLocalFile,
|
|
106
|
+
hasOnChainConfig: result.hasOnChainConfig,
|
|
107
|
+
network: options.network,
|
|
108
|
+
agent: agentAddress,
|
|
109
|
+
},
|
|
110
|
+
{ quietKey: 'status' }
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
output.blank();
|
|
114
|
+
|
|
115
|
+
// Human-friendly status messages
|
|
116
|
+
switch (result.status) {
|
|
117
|
+
case 'in-sync':
|
|
118
|
+
output.success('Local and on-chain configs are in sync.');
|
|
119
|
+
break;
|
|
120
|
+
case 'local-ahead':
|
|
121
|
+
output.warning('Local changes not yet published. Run: actp publish');
|
|
122
|
+
break;
|
|
123
|
+
case 'remote-ahead':
|
|
124
|
+
output.warning('On-chain config is newer. Run: actp pull');
|
|
125
|
+
break;
|
|
126
|
+
case 'diverged':
|
|
127
|
+
output.warning('Local and on-chain configs have diverged.');
|
|
128
|
+
output.print(' Resolve by running: actp publish (to push local) or actp pull --force (to accept remote)');
|
|
129
|
+
break;
|
|
130
|
+
case 'no-local':
|
|
131
|
+
output.info('No local AGIRAILS.md found. Run: actp pull');
|
|
132
|
+
break;
|
|
133
|
+
case 'no-remote':
|
|
134
|
+
output.info('No config published on-chain. Run: actp publish');
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
} catch (error) {
|
|
138
|
+
spinner.stop(false);
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
}
|