agentwallet-sdk 5.0.4 → 5.1.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 +32 -11
- package/dist/ap2/index.d.ts +185 -0
- package/dist/ap2/index.d.ts.map +1 -0
- package/dist/ap2/index.js +255 -0
- package/dist/ap2/index.js.map +1 -0
- package/dist/bridge/unified.d.ts +101 -0
- package/dist/bridge/unified.d.ts.map +1 -0
- package/dist/bridge/unified.js +284 -0
- package/dist/bridge/unified.js.map +1 -0
- package/dist/chains.d.ts +62 -0
- package/dist/chains.d.ts.map +1 -0
- package/dist/chains.js +108 -0
- package/dist/chains.js.map +1 -0
- package/dist/fiat/index.d.ts +10 -0
- package/dist/fiat/index.d.ts.map +1 -0
- package/dist/fiat/index.js +9 -0
- package/dist/fiat/index.js.map +1 -0
- package/dist/fiat/onramp.d.ts +101 -0
- package/dist/fiat/onramp.d.ts.map +1 -0
- package/dist/fiat/onramp.js +155 -0
- package/dist/fiat/onramp.js.map +1 -0
- package/dist/fiat/providers/index.d.ts +16 -0
- package/dist/fiat/providers/index.d.ts.map +1 -0
- package/dist/fiat/providers/index.js +30 -0
- package/dist/fiat/providers/index.js.map +1 -0
- package/dist/fiat/providers/moonpay.d.ts +22 -0
- package/dist/fiat/providers/moonpay.d.ts.map +1 -0
- package/dist/fiat/providers/moonpay.js +107 -0
- package/dist/fiat/providers/moonpay.js.map +1 -0
- package/dist/fiat/providers/stripe.d.ts +26 -0
- package/dist/fiat/providers/stripe.d.ts.map +1 -0
- package/dist/fiat/providers/stripe.js +135 -0
- package/dist/fiat/providers/stripe.js.map +1 -0
- package/dist/fiat/providers/transak.d.ts +26 -0
- package/dist/fiat/providers/transak.d.ts.map +1 -0
- package/dist/fiat/providers/transak.js +119 -0
- package/dist/fiat/providers/transak.js.map +1 -0
- package/dist/fiat/types.d.ts +106 -0
- package/dist/fiat/types.d.ts.map +1 -0
- package/dist/fiat/types.js +13 -0
- package/dist/fiat/types.js.map +1 -0
- package/dist/flash/executor.d.ts +119 -0
- package/dist/flash/executor.d.ts.map +1 -0
- package/dist/flash/executor.js +195 -0
- package/dist/flash/executor.js.map +1 -0
- package/dist/flash/index.d.ts +28 -0
- package/dist/flash/index.d.ts.map +1 -0
- package/dist/flash/index.js +29 -0
- package/dist/flash/index.js.map +1 -0
- package/dist/flash/scanner.d.ts +133 -0
- package/dist/flash/scanner.d.ts.map +1 -0
- package/dist/flash/scanner.js +212 -0
- package/dist/flash/scanner.js.map +1 -0
- package/dist/flash/types.d.ts +136 -0
- package/dist/flash/types.d.ts.map +1 -0
- package/dist/flash/types.js +23 -0
- package/dist/flash/types.js.map +1 -0
- package/dist/gas/index.d.ts +4 -0
- package/dist/gas/index.d.ts.map +1 -0
- package/dist/gas/index.js +3 -0
- package/dist/gas/index.js.map +1 -0
- package/dist/gas/sponsor.d.ts +70 -0
- package/dist/gas/sponsor.d.ts.map +1 -0
- package/dist/gas/sponsor.js +193 -0
- package/dist/gas/sponsor.js.map +1 -0
- package/dist/gas/types.d.ts +76 -0
- package/dist/gas/types.d.ts.map +1 -0
- package/dist/gas/types.js +21 -0
- package/dist/gas/types.js.map +1 -0
- package/dist/identity/agent-identity.d.ts +276 -0
- package/dist/identity/agent-identity.d.ts.map +1 -0
- package/dist/identity/agent-identity.js +300 -0
- package/dist/identity/agent-identity.js.map +1 -0
- package/dist/identity/email-resolver.d.ts +235 -0
- package/dist/identity/email-resolver.js +283 -0
- package/dist/identity/erc6551.d.ts +441 -0
- package/dist/identity/erc6551.d.ts.map +1 -0
- package/dist/identity/erc6551.js +517 -0
- package/dist/identity/erc6551.js.map +1 -0
- package/dist/index.d.ts +286 -213
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/mev/index.d.ts +4 -0
- package/dist/mev/index.d.ts.map +1 -0
- package/dist/mev/index.js +8 -0
- package/dist/mev/index.js.map +1 -0
- package/dist/mev/protection.d.ts +54 -0
- package/dist/mev/protection.d.ts.map +1 -0
- package/dist/mev/protection.js +185 -0
- package/dist/mev/protection.js.map +1 -0
- package/dist/mev/risk.d.ts +19 -0
- package/dist/mev/risk.d.ts.map +1 -0
- package/dist/mev/risk.js +95 -0
- package/dist/mev/risk.js.map +1 -0
- package/dist/mev/types.d.ts +49 -0
- package/dist/mev/types.d.ts.map +1 -0
- package/dist/mev/types.js +2 -0
- package/dist/mev/types.js.map +1 -0
- package/dist/settlement/index.d.ts +4 -0
- package/dist/settlement/index.d.ts.map +1 -0
- package/dist/settlement/index.js +3 -0
- package/dist/settlement/index.js.map +1 -0
- package/dist/settlement/types.d.ts +66 -0
- package/dist/settlement/types.d.ts.map +1 -0
- package/dist/settlement/types.js +37 -0
- package/dist/settlement/types.js.map +1 -0
- package/dist/settlement/verifier.d.ts +75 -0
- package/dist/settlement/verifier.d.ts.map +1 -0
- package/dist/settlement/verifier.js +354 -0
- package/dist/settlement/verifier.js.map +1 -0
- package/dist/solana/bridge.d.ts +144 -0
- package/dist/solana/bridge.d.ts.map +1 -0
- package/dist/solana/bridge.js +352 -0
- package/dist/solana/bridge.js.map +1 -0
- package/dist/solana/index.d.ts +8 -0
- package/dist/solana/index.d.ts.map +1 -0
- package/dist/solana/index.js +6 -0
- package/dist/solana/index.js.map +1 -0
- package/dist/solana/swap.d.ts +85 -0
- package/dist/solana/swap.d.ts.map +1 -0
- package/dist/solana/swap.js +173 -0
- package/dist/solana/swap.js.map +1 -0
- package/dist/solana/types.d.ts +126 -0
- package/dist/solana/types.d.ts.map +1 -0
- package/dist/solana/types.js +10 -0
- package/dist/solana/types.js.map +1 -0
- package/dist/solana/wallet.d.ts +83 -0
- package/dist/solana/wallet.d.ts.map +1 -0
- package/dist/solana/wallet.js +164 -0
- package/dist/solana/wallet.js.map +1 -0
- package/dist/solana/x402.d.ts +69 -0
- package/dist/solana/x402.d.ts.map +1 -0
- package/dist/solana/x402.js +154 -0
- package/dist/solana/x402.js.map +1 -0
- package/dist/solver/adapter.d.ts +47 -0
- package/dist/solver/adapter.d.ts.map +1 -0
- package/dist/solver/adapter.js +146 -0
- package/dist/solver/adapter.js.map +1 -0
- package/dist/solver/analyzer.d.ts +48 -0
- package/dist/solver/analyzer.d.ts.map +1 -0
- package/dist/solver/analyzer.js +171 -0
- package/dist/solver/analyzer.js.map +1 -0
- package/dist/solver/builder.d.ts +31 -0
- package/dist/solver/builder.d.ts.map +1 -0
- package/dist/solver/builder.js +60 -0
- package/dist/solver/builder.js.map +1 -0
- package/dist/solver/index.d.ts +22 -0
- package/dist/solver/index.d.ts.map +1 -0
- package/dist/solver/index.js +25 -0
- package/dist/solver/index.js.map +1 -0
- package/dist/solver/types.d.ts +115 -0
- package/dist/solver/types.d.ts.map +1 -0
- package/dist/solver/types.js +10 -0
- package/dist/solver/types.js.map +1 -0
- package/dist/spend-guard/index.d.ts +125 -0
- package/dist/spend-guard/index.d.ts.map +1 -0
- package/dist/spend-guard/index.js +150 -0
- package/dist/spend-guard/index.js.map +1 -0
- package/dist/swap/router/cache.d.ts +13 -0
- package/dist/swap/router/cache.d.ts.map +1 -0
- package/dist/swap/router/cache.js +30 -0
- package/dist/swap/router/cache.js.map +1 -0
- package/dist/swap/router/flashbots.d.ts +10 -0
- package/dist/swap/router/flashbots.d.ts.map +1 -0
- package/dist/swap/router/flashbots.js +43 -0
- package/dist/swap/router/flashbots.js.map +1 -0
- package/dist/swap/router/health.d.ts +17 -0
- package/dist/swap/router/health.d.ts.map +1 -0
- package/dist/swap/router/health.js +38 -0
- package/dist/swap/router/health.js.map +1 -0
- package/dist/swap/router/index.d.ts +10 -0
- package/dist/swap/router/index.d.ts.map +1 -0
- package/dist/swap/router/index.js +10 -0
- package/dist/swap/router/index.js.map +1 -0
- package/dist/swap/router/providers/cowswap.d.ts +11 -0
- package/dist/swap/router/providers/cowswap.d.ts.map +1 -0
- package/dist/swap/router/providers/cowswap.js +79 -0
- package/dist/swap/router/providers/cowswap.js.map +1 -0
- package/dist/swap/router/providers/index.d.ts +20 -0
- package/dist/swap/router/providers/index.d.ts.map +1 -0
- package/dist/swap/router/providers/index.js +32 -0
- package/dist/swap/router/providers/index.js.map +1 -0
- package/dist/swap/router/providers/jupiter.d.ts +12 -0
- package/dist/swap/router/providers/jupiter.d.ts.map +1 -0
- package/dist/swap/router/providers/jupiter.js +73 -0
- package/dist/swap/router/providers/jupiter.js.map +1 -0
- package/dist/swap/router/providers/lifi.d.ts +11 -0
- package/dist/swap/router/providers/lifi.d.ts.map +1 -0
- package/dist/swap/router/providers/lifi.js +123 -0
- package/dist/swap/router/providers/lifi.js.map +1 -0
- package/dist/swap/router/providers/oneinch.d.ts +13 -0
- package/dist/swap/router/providers/oneinch.d.ts.map +1 -0
- package/dist/swap/router/providers/oneinch.js +71 -0
- package/dist/swap/router/providers/oneinch.js.map +1 -0
- package/dist/swap/router/providers/paraswap.d.ts +11 -0
- package/dist/swap/router/providers/paraswap.d.ts.map +1 -0
- package/dist/swap/router/providers/paraswap.js +73 -0
- package/dist/swap/router/providers/paraswap.js.map +1 -0
- package/dist/swap/router/providers/uniswap.d.ts +31 -0
- package/dist/swap/router/providers/uniswap.d.ts.map +1 -0
- package/dist/swap/router/providers/uniswap.js +237 -0
- package/dist/swap/router/providers/uniswap.js.map +1 -0
- package/dist/swap/router/providers/zerox.d.ts +13 -0
- package/dist/swap/router/providers/zerox.d.ts.map +1 -0
- package/dist/swap/router/providers/zerox.js +94 -0
- package/dist/swap/router/providers/zerox.js.map +1 -0
- package/dist/swap/router/router.d.ts +86 -0
- package/dist/swap/router/router.d.ts.map +1 -0
- package/dist/swap/router/router.js +224 -0
- package/dist/swap/router/router.js.map +1 -0
- package/dist/swap/router/rsi/engine.d.ts +60 -0
- package/dist/swap/router/rsi/engine.d.ts.map +1 -0
- package/dist/swap/router/rsi/engine.js +483 -0
- package/dist/swap/router/rsi/engine.js.map +1 -0
- package/dist/swap/router/rsi/index.d.ts +3 -0
- package/dist/swap/router/rsi/index.d.ts.map +1 -0
- package/dist/swap/router/rsi/index.js +3 -0
- package/dist/swap/router/rsi/index.js.map +1 -0
- package/dist/swap/router/rsi/types.d.ts +106 -0
- package/dist/swap/router/rsi/types.d.ts.map +1 -0
- package/dist/swap/router/rsi/types.js +3 -0
- package/dist/swap/router/rsi/types.js.map +1 -0
- package/dist/swap/router/types.d.ts +120 -0
- package/dist/swap/router/types.d.ts.map +1 -0
- package/dist/swap/router/types.js +16 -0
- package/dist/swap/router/types.js.map +1 -0
- package/dist/tax/engine.d.ts +131 -0
- package/dist/tax/engine.d.ts.map +1 -0
- package/dist/tax/engine.js +307 -0
- package/dist/tax/engine.js.map +1 -0
- package/dist/tax/index.d.ts +9 -0
- package/dist/tax/index.d.ts.map +1 -0
- package/dist/tax/index.js +12 -0
- package/dist/tax/index.js.map +1 -0
- package/dist/tax/lots.d.ts +60 -0
- package/dist/tax/lots.d.ts.map +1 -0
- package/dist/tax/lots.js +129 -0
- package/dist/tax/lots.js.map +1 -0
- package/dist/tax/types.d.ts +113 -0
- package/dist/tax/types.d.ts.map +1 -0
- package/dist/tax/types.js +18 -0
- package/dist/tax/types.js.map +1 -0
- package/dist/verifiable-intent/index.d.ts +84 -0
- package/dist/verifiable-intent/index.js +385 -0
- package/dist/yield/index.d.ts +26 -0
- package/dist/yield/index.d.ts.map +1 -0
- package/dist/yield/index.js +29 -0
- package/dist/yield/index.js.map +1 -0
- package/dist/yield/rates.d.ts +114 -0
- package/dist/yield/rates.d.ts.map +1 -0
- package/dist/yield/rates.js +351 -0
- package/dist/yield/rates.js.map +1 -0
- package/dist/yield/types.d.ts +134 -0
- package/dist/yield/types.d.ts.map +1 -0
- package/dist/yield/types.js +24 -0
- package/dist/yield/types.js.map +1 -0
- package/dist/yield/vault.d.ts +112 -0
- package/dist/yield/vault.d.ts.map +1 -0
- package/dist/yield/vault.js +264 -0
- package/dist/yield/vault.js.map +1 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -204,24 +204,45 @@ await escrow.verify(escrowId);
|
|
|
204
204
|
|
|
205
205
|
Premium access: [github.com/up2itnow/AgentNexus2](https://github.com/up2itnow/AgentNexus2)
|
|
206
206
|
|
|
207
|
-
##
|
|
207
|
+
## x402 Protocol: Supported Chains and Payment Rails
|
|
208
208
|
|
|
209
|
-
|
|
209
|
+
x402 (HTTP 402 Payment Required) is the native payment protocol for agent-to-service transactions. The agent encounters a 402 response, signs a payment proof, and re-sends the request. One round trip. No accounts, no API keys, no invoices.
|
|
210
210
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
211
|
+
As of March 2026, x402 is live on 3 chains/rails:
|
|
212
|
+
|
|
213
|
+
| Chain / Rail | Status | Settlement Token | Gas Cost | Notes |
|
|
214
|
+
|---|---|---|---|---|
|
|
215
|
+
| **Base** (Coinbase L2) | Live | USDC | Sub-cent | Primary x402 chain. 15M+ transactions in Jan 2026. |
|
|
216
|
+
| **Etherlink** (Tezos L2) | Live (Mar 2026) | USDC | Sub-cent | EVM-compatible. Same x402 integration, different RPC + chain ID. |
|
|
217
|
+
| **Stripe** (Fiat offramp) | Live (Feb 2026) | USDC -> USD | N/A | Vendors receive USD in Stripe dashboard. Agents pay USDC. |
|
|
218
|
+
|
|
219
|
+
### x402 + Etherlink Quick Start
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
import { createWallet, agentExecute } from 'agentwallet-sdk';
|
|
214
223
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
224
|
+
const wallet = createWallet({
|
|
225
|
+
accountAddress: '0xYourAgent',
|
|
226
|
+
chain: 'etherlink', // new: Tezos L2 support
|
|
227
|
+
walletClient,
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// x402 payment flow is identical across chains
|
|
231
|
+
const response = await fetch('https://api.vendor.com/data');
|
|
232
|
+
if (response.status === 402) {
|
|
233
|
+
const details = await response.json();
|
|
234
|
+
const proof = await wallet.createX402Proof(details);
|
|
235
|
+
const paid = await fetch('https://api.vendor.com/data', {
|
|
236
|
+
headers: { 'X-Payment': proof }
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
```
|
|
219
240
|
|
|
220
|
-
|
|
241
|
+
The SDK handles chain-specific RPC endpoints, gas estimation, and USDC contract addresses automatically. Swap `chain: 'base'` to `chain: 'etherlink'` and the x402 flow works identically.
|
|
221
242
|
|
|
222
243
|
## Supported Chains
|
|
223
244
|
|
|
224
|
-
Mainnet: Ethereum, Base, Arbitrum, Polygon, Optimism, Avalanche, BSC, Celo, Gnosis, Linea, Mantle, Scroll, and more.
|
|
245
|
+
Mainnet: Ethereum, Base, Arbitrum, Polygon, Optimism, Avalanche, BSC, Celo, Gnosis, Linea, Mantle, Scroll, Etherlink, and more.
|
|
225
246
|
|
|
226
247
|
Testnet: Base Sepolia, Arbitrum Sepolia, and corresponding testnets.
|
|
227
248
|
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AP2Client — ISO 20022 / AP2 European Payment Module for agentwallet-sdk
|
|
3
|
+
*
|
|
4
|
+
* Non-custodial AI agent bridge for AP2 payments:
|
|
5
|
+
* - Parse ISO 20022 pacs.008 XML → bridge quote
|
|
6
|
+
* - Sign x402 payment header locally (private key never leaves agent)
|
|
7
|
+
* - Execute USDC → EUR settlement via CCTP V2 (Base → EUR off-ramp)
|
|
8
|
+
*
|
|
9
|
+
* AP2 context:
|
|
10
|
+
* Nexi + Google Cloud MoU (2026): AP2 processes ~2.9T EUR/year across Europe.
|
|
11
|
+
* ISO 20022 is the wire standard. This module makes AI agents first-class
|
|
12
|
+
* European payment participants — non-custodially.
|
|
13
|
+
*
|
|
14
|
+
* @module ap2
|
|
15
|
+
*/
|
|
16
|
+
/** Parameters for building a pacs.008 XML message from simple inputs. */
|
|
17
|
+
export interface AP2PaymentParams {
|
|
18
|
+
/** Unique message ID (e.g. "MSG-2026-0001") */
|
|
19
|
+
messageId: string;
|
|
20
|
+
/** ISO 8601 creation datetime (defaults to now) */
|
|
21
|
+
creationDateTime?: string;
|
|
22
|
+
/** Payment amount in EUR (or specified currency) */
|
|
23
|
+
amount: number;
|
|
24
|
+
/** Currency code (default: "EUR") */
|
|
25
|
+
currency?: string;
|
|
26
|
+
/** Debtor full name */
|
|
27
|
+
debtorName: string;
|
|
28
|
+
/** Debtor IBAN */
|
|
29
|
+
debtorIban: string;
|
|
30
|
+
/** Debtor BIC */
|
|
31
|
+
debtorBic: string;
|
|
32
|
+
/** Creditor full name */
|
|
33
|
+
creditorName: string;
|
|
34
|
+
/** Creditor IBAN */
|
|
35
|
+
creditorIban: string;
|
|
36
|
+
/** Creditor BIC */
|
|
37
|
+
creditorBic: string;
|
|
38
|
+
/** Optional end-to-end reference */
|
|
39
|
+
endToEndId?: string;
|
|
40
|
+
/** Optional purpose code (e.g. "SUPP") */
|
|
41
|
+
purposeCode?: string;
|
|
42
|
+
/** Optional unstructured remittance info */
|
|
43
|
+
remittanceInfo?: string;
|
|
44
|
+
}
|
|
45
|
+
/** Bridge quote returned by the AP2 facilitator. */
|
|
46
|
+
export interface AP2Quote {
|
|
47
|
+
/** ISO 20022 message ID */
|
|
48
|
+
messageId: string;
|
|
49
|
+
/** Creditor IBAN for SEPA settlement */
|
|
50
|
+
creditorIban: string;
|
|
51
|
+
/** EUR payment amount */
|
|
52
|
+
amountEur: number;
|
|
53
|
+
/** USDC required (6 decimal precision, as bigint μUSDC) */
|
|
54
|
+
usdcRequired: bigint;
|
|
55
|
+
/** Bridge fee in USDC (μUSDC) */
|
|
56
|
+
bridgeFeeUsdc: bigint;
|
|
57
|
+
/** Estimated settlement time in seconds */
|
|
58
|
+
estimatedSettlementSeconds: number;
|
|
59
|
+
/** x402 payment header string */
|
|
60
|
+
x402PaymentHeader: string;
|
|
61
|
+
/** Raw calldata for agentwallet-sdk */
|
|
62
|
+
agentWalletCalldata: Record<string, unknown>;
|
|
63
|
+
/** Quote expiry ISO timestamp */
|
|
64
|
+
expiresAt: string;
|
|
65
|
+
}
|
|
66
|
+
/** Execution receipt after AP2 payment is submitted. */
|
|
67
|
+
export interface AP2Receipt {
|
|
68
|
+
/** ISO 20022 message ID */
|
|
69
|
+
messageId: string;
|
|
70
|
+
/** On-chain transaction hash */
|
|
71
|
+
txHash: string;
|
|
72
|
+
/** USDC bridged (μUSDC as bigint) */
|
|
73
|
+
usdcBridged: bigint;
|
|
74
|
+
/** SEPA creditor reference */
|
|
75
|
+
sepaReference: string;
|
|
76
|
+
/** Payment status */
|
|
77
|
+
status: 'pending' | 'confirmed' | 'failed' | 'dry_run';
|
|
78
|
+
/** True if this was a dry run simulation */
|
|
79
|
+
dryRun: boolean;
|
|
80
|
+
/** x402 payment header signature */
|
|
81
|
+
x402Signature: string;
|
|
82
|
+
/** Agent Ethereum address */
|
|
83
|
+
agentAddress: string;
|
|
84
|
+
/** CCTP bridge nonce */
|
|
85
|
+
nonce: number;
|
|
86
|
+
/** ISO timestamp of execution */
|
|
87
|
+
executedAt: string;
|
|
88
|
+
/** Creditor IBAN */
|
|
89
|
+
creditorIban: string;
|
|
90
|
+
/** Bridge fee in USDC (μUSDC) */
|
|
91
|
+
bridgeFeeUsdc: bigint;
|
|
92
|
+
}
|
|
93
|
+
/** AP2Client configuration */
|
|
94
|
+
export interface AP2ClientConfig {
|
|
95
|
+
/**
|
|
96
|
+
* URL of the AP2 facilitator (FastAPI handler).
|
|
97
|
+
* Defaults to http://localhost:8420
|
|
98
|
+
*/
|
|
99
|
+
facilitatorUrl?: string;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Build a valid ISO 20022 pacs.008 (FIToFICstmrCdtTrf) XML string
|
|
103
|
+
* from simple agent-friendly parameters.
|
|
104
|
+
*
|
|
105
|
+
* @param params - Payment parameters
|
|
106
|
+
* @returns ISO 20022 pacs.008 XML string
|
|
107
|
+
*/
|
|
108
|
+
declare function buildPacs008(params: AP2PaymentParams): string;
|
|
109
|
+
/**
|
|
110
|
+
* AP2Client — Non-custodial ISO 20022 / AP2 payment client for AI agents.
|
|
111
|
+
*
|
|
112
|
+
* Connects to the AP2 facilitator (ap2_handler.py FastAPI service) to
|
|
113
|
+
* get bridge quotes and execute payments via CCTP V2 / x402.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const client = new AP2Client({ facilitatorUrl: 'http://localhost:8420' });
|
|
118
|
+
*
|
|
119
|
+
* const xml = AP2Client.buildPacs008({
|
|
120
|
+
* messageId: 'MSG-2026-0001',
|
|
121
|
+
* amount: 1000,
|
|
122
|
+
* debtorName: 'Agent Zero',
|
|
123
|
+
* debtorIban: 'DE89370400440532013000',
|
|
124
|
+
* debtorBic: 'COBADEFFXXX',
|
|
125
|
+
* creditorName: 'Acme GmbH',
|
|
126
|
+
* creditorIban: 'FR7630006000011234567890189',
|
|
127
|
+
* creditorBic: 'BNPAFRPPXXX',
|
|
128
|
+
* });
|
|
129
|
+
*
|
|
130
|
+
* const quote = await client.quote(xml);
|
|
131
|
+
* const receipt = await client.pay(xml);
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export declare class AP2Client {
|
|
135
|
+
private readonly facilitatorUrl;
|
|
136
|
+
constructor(config?: AP2ClientConfig);
|
|
137
|
+
/**
|
|
138
|
+
* Parse ISO 20022 pacs.008 XML and get a bridge quote from the facilitator.
|
|
139
|
+
*
|
|
140
|
+
* @param iso20022Xml - Raw pacs.008 XML string
|
|
141
|
+
* @returns AP2Quote with USDC amounts and x402 calldata
|
|
142
|
+
* @throws Error if the facilitator returns an error or the XML is invalid
|
|
143
|
+
*/
|
|
144
|
+
quote(iso20022Xml: string): Promise<AP2Quote>;
|
|
145
|
+
/**
|
|
146
|
+
* Execute the full AP2 payment: sign x402 header + bridge USDC + settle.
|
|
147
|
+
*
|
|
148
|
+
* Calls the /ap2/execute endpoint on the facilitator, which:
|
|
149
|
+
* 1. Parses the XML
|
|
150
|
+
* 2. Signs x402 header with agent's private key (server-side in this flow)
|
|
151
|
+
* 3. Submits USDC to CCTP V2 bridge
|
|
152
|
+
* 4. Returns receipt
|
|
153
|
+
*
|
|
154
|
+
* @param iso20022Xml - Raw pacs.008 XML string
|
|
155
|
+
* @returns AP2Receipt with txHash and SEPA reference
|
|
156
|
+
* @throws AP2Error on execution failure
|
|
157
|
+
*/
|
|
158
|
+
pay(iso20022Xml: string): Promise<AP2Receipt>;
|
|
159
|
+
/**
|
|
160
|
+
* Generate a valid ISO 20022 pacs.008 XML string from simple parameters.
|
|
161
|
+
*
|
|
162
|
+
* Handles XML escaping, IBAN normalization, and timestamp formatting.
|
|
163
|
+
* Makes AP2 payments agent-friendly — no ISO 20022 expertise required.
|
|
164
|
+
*
|
|
165
|
+
* @param params - Simple payment parameters
|
|
166
|
+
* @returns Valid pacs.008 XML string
|
|
167
|
+
*/
|
|
168
|
+
static buildPacs008(params: AP2PaymentParams): string;
|
|
169
|
+
/**
|
|
170
|
+
* Estimate USDC required for a given EUR amount.
|
|
171
|
+
*
|
|
172
|
+
* Uses the default EUR/USDC rate. For accurate quotes, call quote() instead.
|
|
173
|
+
*
|
|
174
|
+
* @param amountEur - Amount in EUR
|
|
175
|
+
* @returns Estimated USDC amount as bigint (μUSDC, 6 decimals)
|
|
176
|
+
*/
|
|
177
|
+
static estimateUsdc(amountEur: number): bigint;
|
|
178
|
+
}
|
|
179
|
+
/** AP2-specific error with structured context. */
|
|
180
|
+
export declare class AP2Error extends Error {
|
|
181
|
+
readonly context?: Record<string, unknown> | undefined;
|
|
182
|
+
constructor(message: string, context?: Record<string, unknown> | undefined);
|
|
183
|
+
}
|
|
184
|
+
export { buildPacs008 };
|
|
185
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ap2/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH,yEAAyE;AACzE,MAAM,WAAW,gBAAgB;IAC/B,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAC;IAClB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AAMD,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AP2Client — ISO 20022 / AP2 European Payment Module for agentwallet-sdk
|
|
3
|
+
*
|
|
4
|
+
* Non-custodial AI agent bridge for AP2 payments:
|
|
5
|
+
* - Parse ISO 20022 pacs.008 XML → bridge quote
|
|
6
|
+
* - Sign x402 payment header locally (private key never leaves agent)
|
|
7
|
+
* - Execute USDC → EUR settlement via CCTP V2 (Base → EUR off-ramp)
|
|
8
|
+
*
|
|
9
|
+
* AP2 context:
|
|
10
|
+
* Nexi + Google Cloud MoU (2026): AP2 processes ~2.9T EUR/year across Europe.
|
|
11
|
+
* ISO 20022 is the wire standard. This module makes AI agents first-class
|
|
12
|
+
* European payment participants — non-custodially.
|
|
13
|
+
*
|
|
14
|
+
* @module ap2
|
|
15
|
+
*/
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
// Constants
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
/** USDC decimals (6) */
|
|
20
|
+
const USDC_DECIMALS = 6n;
|
|
21
|
+
const USDC_MULTIPLIER = 10n ** USDC_DECIMALS;
|
|
22
|
+
/** EUR → USDC rate (fallback; production uses Chainlink oracle) */
|
|
23
|
+
const EUR_TO_USDC_RATE = 1.08;
|
|
24
|
+
/** Default facilitator URL */
|
|
25
|
+
const DEFAULT_FACILITATOR_URL = 'http://localhost:8420';
|
|
26
|
+
/** Estimated CCTP V2 settlement time (~20 min) */
|
|
27
|
+
const ESTIMATED_SETTLEMENT_SECONDS = 1200;
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
// ISO 20022 pacs.008 XML Builder
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
/**
|
|
32
|
+
* Build a valid ISO 20022 pacs.008 (FIToFICstmrCdtTrf) XML string
|
|
33
|
+
* from simple agent-friendly parameters.
|
|
34
|
+
*
|
|
35
|
+
* @param params - Payment parameters
|
|
36
|
+
* @returns ISO 20022 pacs.008 XML string
|
|
37
|
+
*/
|
|
38
|
+
function buildPacs008(params) {
|
|
39
|
+
const now = params.creationDateTime ?? new Date().toISOString().replace(/\.\d+Z$/, '+00:00');
|
|
40
|
+
const currency = params.currency ?? 'EUR';
|
|
41
|
+
const e2eId = params.endToEndId ?? params.messageId;
|
|
42
|
+
const amount = params.amount.toFixed(2);
|
|
43
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
44
|
+
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.08">
|
|
45
|
+
<FIToFICstmrCdtTrf>
|
|
46
|
+
<GrpHdr>
|
|
47
|
+
<MsgId>${escapeXml(params.messageId)}</MsgId>
|
|
48
|
+
<CreDtTm>${escapeXml(now)}</CreDtTm>
|
|
49
|
+
<NbOfTxs>1</NbOfTxs>
|
|
50
|
+
<SttlmInf>
|
|
51
|
+
<SttlmMtd>CLRG</SttlmMtd>
|
|
52
|
+
</SttlmInf>
|
|
53
|
+
</GrpHdr>
|
|
54
|
+
<CdtTrfTxInf>
|
|
55
|
+
<PmtId>
|
|
56
|
+
<EndToEndId>${escapeXml(e2eId)}</EndToEndId>
|
|
57
|
+
</PmtId>
|
|
58
|
+
<IntrBkSttlmAmt Ccy="${escapeXml(currency)}">${amount}</IntrBkSttlmAmt>
|
|
59
|
+
<ChrgBr>SHAR</ChrgBr>
|
|
60
|
+
<Dbtr>
|
|
61
|
+
<Nm>${escapeXml(params.debtorName)}</Nm>
|
|
62
|
+
</Dbtr>
|
|
63
|
+
<DbtrAcct>
|
|
64
|
+
<Id>
|
|
65
|
+
<IBAN>${escapeXml(params.debtorIban.replace(/\s/g, '').toUpperCase())}</IBAN>
|
|
66
|
+
</Id>
|
|
67
|
+
</DbtrAcct>
|
|
68
|
+
<DbtrAgt>
|
|
69
|
+
<FinInstnId>
|
|
70
|
+
<BICFI>${escapeXml(params.debtorBic.toUpperCase())}</BICFI>
|
|
71
|
+
</FinInstnId>
|
|
72
|
+
</DbtrAgt>
|
|
73
|
+
<Cdtr>
|
|
74
|
+
<Nm>${escapeXml(params.creditorName)}</Nm>
|
|
75
|
+
</Cdtr>
|
|
76
|
+
<CdtrAcct>
|
|
77
|
+
<Id>
|
|
78
|
+
<IBAN>${escapeXml(params.creditorIban.replace(/\s/g, '').toUpperCase())}</IBAN>
|
|
79
|
+
</Id>
|
|
80
|
+
</CdtrAcct>
|
|
81
|
+
<CdtrAgt>
|
|
82
|
+
<FinInstnId>
|
|
83
|
+
<BICFI>${escapeXml(params.creditorBic.toUpperCase())}</BICFI>
|
|
84
|
+
</FinInstnId>
|
|
85
|
+
</CdtrAgt>${params.purposeCode ? `
|
|
86
|
+
<Purp>
|
|
87
|
+
<Cd>${escapeXml(params.purposeCode)}</Cd>
|
|
88
|
+
</Purp>` : ''}${params.remittanceInfo ? `
|
|
89
|
+
<RmtInf>
|
|
90
|
+
<Ustrd>${escapeXml(params.remittanceInfo)}</Ustrd>
|
|
91
|
+
</RmtInf>` : ''}
|
|
92
|
+
</CdtTrfTxInf>
|
|
93
|
+
</FIToFICstmrCdtTrf>
|
|
94
|
+
</Document>`;
|
|
95
|
+
}
|
|
96
|
+
/** Escape XML special characters. */
|
|
97
|
+
function escapeXml(str) {
|
|
98
|
+
return str
|
|
99
|
+
.replace(/&/g, '&')
|
|
100
|
+
.replace(/</g, '<')
|
|
101
|
+
.replace(/>/g, '>')
|
|
102
|
+
.replace(/"/g, '"')
|
|
103
|
+
.replace(/'/g, ''');
|
|
104
|
+
}
|
|
105
|
+
/** Convert a decimal USDC string to bigint μUSDC. */
|
|
106
|
+
function usdcToBigInt(usdcStr) {
|
|
107
|
+
const [whole, frac = ''] = usdcStr.split('.');
|
|
108
|
+
const fracPadded = frac.padEnd(Number(USDC_DECIMALS), '0').slice(0, Number(USDC_DECIMALS));
|
|
109
|
+
return BigInt(whole) * USDC_MULTIPLIER + BigInt(fracPadded);
|
|
110
|
+
}
|
|
111
|
+
// ---------------------------------------------------------------------------
|
|
112
|
+
// AP2Client
|
|
113
|
+
// ---------------------------------------------------------------------------
|
|
114
|
+
/**
|
|
115
|
+
* AP2Client — Non-custodial ISO 20022 / AP2 payment client for AI agents.
|
|
116
|
+
*
|
|
117
|
+
* Connects to the AP2 facilitator (ap2_handler.py FastAPI service) to
|
|
118
|
+
* get bridge quotes and execute payments via CCTP V2 / x402.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* const client = new AP2Client({ facilitatorUrl: 'http://localhost:8420' });
|
|
123
|
+
*
|
|
124
|
+
* const xml = AP2Client.buildPacs008({
|
|
125
|
+
* messageId: 'MSG-2026-0001',
|
|
126
|
+
* amount: 1000,
|
|
127
|
+
* debtorName: 'Agent Zero',
|
|
128
|
+
* debtorIban: 'DE89370400440532013000',
|
|
129
|
+
* debtorBic: 'COBADEFFXXX',
|
|
130
|
+
* creditorName: 'Acme GmbH',
|
|
131
|
+
* creditorIban: 'FR7630006000011234567890189',
|
|
132
|
+
* creditorBic: 'BNPAFRPPXXX',
|
|
133
|
+
* });
|
|
134
|
+
*
|
|
135
|
+
* const quote = await client.quote(xml);
|
|
136
|
+
* const receipt = await client.pay(xml);
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export class AP2Client {
|
|
140
|
+
constructor(config = {}) {
|
|
141
|
+
this.facilitatorUrl = (config.facilitatorUrl ?? DEFAULT_FACILITATOR_URL).replace(/\/$/, '');
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Parse ISO 20022 pacs.008 XML and get a bridge quote from the facilitator.
|
|
145
|
+
*
|
|
146
|
+
* @param iso20022Xml - Raw pacs.008 XML string
|
|
147
|
+
* @returns AP2Quote with USDC amounts and x402 calldata
|
|
148
|
+
* @throws Error if the facilitator returns an error or the XML is invalid
|
|
149
|
+
*/
|
|
150
|
+
async quote(iso20022Xml) {
|
|
151
|
+
const response = await fetch(`${this.facilitatorUrl}/ap2/payment`, {
|
|
152
|
+
method: 'POST',
|
|
153
|
+
headers: { 'Content-Type': 'application/xml' },
|
|
154
|
+
body: iso20022Xml,
|
|
155
|
+
});
|
|
156
|
+
if (!response.ok) {
|
|
157
|
+
const body = await response.text();
|
|
158
|
+
throw new AP2Error(`Quote failed (${response.status}): ${body}`);
|
|
159
|
+
}
|
|
160
|
+
const json = (await response.json());
|
|
161
|
+
const bq = json.bridge_quote;
|
|
162
|
+
const payment = json.payment;
|
|
163
|
+
return {
|
|
164
|
+
messageId: payment.message_id,
|
|
165
|
+
creditorIban: payment.creditor.iban,
|
|
166
|
+
amountEur: parseFloat(payment.amount),
|
|
167
|
+
usdcRequired: usdcToBigInt(bq.usdc_amount),
|
|
168
|
+
bridgeFeeUsdc: usdcToBigInt(bq.bridge_fee_usdc),
|
|
169
|
+
estimatedSettlementSeconds: ESTIMATED_SETTLEMENT_SECONDS,
|
|
170
|
+
x402PaymentHeader: bq.x402_payment_header,
|
|
171
|
+
agentWalletCalldata: bq.agent_wallet_calldata,
|
|
172
|
+
expiresAt: bq.expires_at,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Execute the full AP2 payment: sign x402 header + bridge USDC + settle.
|
|
177
|
+
*
|
|
178
|
+
* Calls the /ap2/execute endpoint on the facilitator, which:
|
|
179
|
+
* 1. Parses the XML
|
|
180
|
+
* 2. Signs x402 header with agent's private key (server-side in this flow)
|
|
181
|
+
* 3. Submits USDC to CCTP V2 bridge
|
|
182
|
+
* 4. Returns receipt
|
|
183
|
+
*
|
|
184
|
+
* @param iso20022Xml - Raw pacs.008 XML string
|
|
185
|
+
* @returns AP2Receipt with txHash and SEPA reference
|
|
186
|
+
* @throws AP2Error on execution failure
|
|
187
|
+
*/
|
|
188
|
+
async pay(iso20022Xml) {
|
|
189
|
+
const response = await fetch(`${this.facilitatorUrl}/ap2/execute`, {
|
|
190
|
+
method: 'POST',
|
|
191
|
+
headers: { 'Content-Type': 'application/xml' },
|
|
192
|
+
body: iso20022Xml,
|
|
193
|
+
});
|
|
194
|
+
if (!response.ok) {
|
|
195
|
+
const body = await response.text();
|
|
196
|
+
throw new AP2Error(`Execution failed (${response.status}): ${body}`);
|
|
197
|
+
}
|
|
198
|
+
const json = (await response.json());
|
|
199
|
+
const r = json.receipt;
|
|
200
|
+
return {
|
|
201
|
+
messageId: r.message_id,
|
|
202
|
+
txHash: r.tx_hash,
|
|
203
|
+
usdcBridged: usdcToBigInt(r.usdc_bridged),
|
|
204
|
+
sepaReference: r.sepa_reference,
|
|
205
|
+
status: r.status,
|
|
206
|
+
dryRun: r.dry_run,
|
|
207
|
+
x402Signature: r.x402_signature,
|
|
208
|
+
agentAddress: r.agent_address,
|
|
209
|
+
nonce: r.nonce,
|
|
210
|
+
executedAt: r.executed_at,
|
|
211
|
+
creditorIban: r.creditor_iban,
|
|
212
|
+
bridgeFeeUsdc: usdcToBigInt(r.bridge_fee_usdc),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Generate a valid ISO 20022 pacs.008 XML string from simple parameters.
|
|
217
|
+
*
|
|
218
|
+
* Handles XML escaping, IBAN normalization, and timestamp formatting.
|
|
219
|
+
* Makes AP2 payments agent-friendly — no ISO 20022 expertise required.
|
|
220
|
+
*
|
|
221
|
+
* @param params - Simple payment parameters
|
|
222
|
+
* @returns Valid pacs.008 XML string
|
|
223
|
+
*/
|
|
224
|
+
static buildPacs008(params) {
|
|
225
|
+
return buildPacs008(params);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Estimate USDC required for a given EUR amount.
|
|
229
|
+
*
|
|
230
|
+
* Uses the default EUR/USDC rate. For accurate quotes, call quote() instead.
|
|
231
|
+
*
|
|
232
|
+
* @param amountEur - Amount in EUR
|
|
233
|
+
* @returns Estimated USDC amount as bigint (μUSDC, 6 decimals)
|
|
234
|
+
*/
|
|
235
|
+
static estimateUsdc(amountEur) {
|
|
236
|
+
const usdc = amountEur * EUR_TO_USDC_RATE;
|
|
237
|
+
return BigInt(Math.round(usdc * Number(USDC_MULTIPLIER)));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// ---------------------------------------------------------------------------
|
|
241
|
+
// Error class
|
|
242
|
+
// ---------------------------------------------------------------------------
|
|
243
|
+
/** AP2-specific error with structured context. */
|
|
244
|
+
export class AP2Error extends Error {
|
|
245
|
+
constructor(message, context) {
|
|
246
|
+
super(message);
|
|
247
|
+
this.context = context;
|
|
248
|
+
this.name = 'AP2Error';
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// ---------------------------------------------------------------------------
|
|
252
|
+
// Re-export builder as standalone function
|
|
253
|
+
// ---------------------------------------------------------------------------
|
|
254
|
+
export { buildPacs008 };
|
|
255
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ap2/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAiIH,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E,wBAAwB;AACxB,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,MAAM,eAAe,GAAG,GAAG,IAAI,aAAa,CAAC;AAE7C,mEAAmE;AACnE,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAE9B,8BAA8B;AAC9B,MAAM,uBAAuB,GAAG,uBAAuB,CAAC;AAExD,kDAAkD;AAClD,MAAM,4BAA4B,GAAG,IAAI,CAAC;AAE1C,8EAA8E;AAC9E,iCAAiC;AACjC,8EAA8E;AAE9E;;;;;;GAMG;AACH,SAAS,YAAY,CAAC,MAAwB;IAC5C,MAAM,GAAG,GAAG,MAAM,CAAC,gBAAgB,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAC7F,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,KAAK,CAAC;IAC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/web3.js';
|
|
3
|
+
import { BridgeError } from './client.js';
|
|
4
|
+
import type { BridgeChain, BridgeResult } from './types.js';
|
|
5
|
+
import { type CCTPSupportedChain, type BridgeQuote, CCTP_DOMAIN_IDS, BRIDGE_CHAIN_IDS, BRIDGE_RPC_URLS, calcBridgeFee } from './types.js';
|
|
6
|
+
import { SolanaBridgeError } from '../solana/bridge.js';
|
|
7
|
+
export interface UnifiedBridgeConfig {
|
|
8
|
+
/** EVM wallet client (required for any EVM source chain) */
|
|
9
|
+
evmSigner?: WalletClient;
|
|
10
|
+
/** Solana keypair (required when Solana is source) */
|
|
11
|
+
solanaWallet?: Keypair;
|
|
12
|
+
/** Solana RPC URL (default: mainnet-beta public) */
|
|
13
|
+
solanaRpcUrl?: string;
|
|
14
|
+
/** Override EVM RPC URLs per chain */
|
|
15
|
+
evmRpcOverrides?: Partial<Record<BridgeChain, string>>;
|
|
16
|
+
/** Circle attestation API override */
|
|
17
|
+
attestationApiUrl?: string;
|
|
18
|
+
/** Platform fee wallet address (future: fee collection) */
|
|
19
|
+
feeWallet?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface UnifiedBridgeParams {
|
|
22
|
+
/** USDC amount in base units (6 decimals). 1 USDC = 1_000_000 */
|
|
23
|
+
amount: bigint;
|
|
24
|
+
/** Source chain */
|
|
25
|
+
sourceChain: CCTPSupportedChain;
|
|
26
|
+
/** Destination chain */
|
|
27
|
+
destinationChain: CCTPSupportedChain;
|
|
28
|
+
/** Recipient address (hex for EVM, base58 for Solana destination) */
|
|
29
|
+
destinationAddress: string;
|
|
30
|
+
/** Finality: 0 = fast (~20s), 1000 = finalized (~15min) */
|
|
31
|
+
minFinalityThreshold?: number;
|
|
32
|
+
/** Apply 0.1% platform fee (default: true) */
|
|
33
|
+
applyPlatformFee?: boolean;
|
|
34
|
+
/** Override destination RPC URL */
|
|
35
|
+
destinationRpcUrl?: string;
|
|
36
|
+
}
|
|
37
|
+
export type { BridgeResult, BridgeQuote, CCTPSupportedChain };
|
|
38
|
+
/**
|
|
39
|
+
* UnifiedBridge — Cross-chain USDC bridge across all 17 CCTP V2 supported chains.
|
|
40
|
+
*
|
|
41
|
+
* Routing:
|
|
42
|
+
* - EVM → EVM: BridgeModule (approve → burn → attest → mint)
|
|
43
|
+
* - EVM → Solana: BridgeModule burn + SolanaCCTPBridge receive
|
|
44
|
+
* - Solana → EVM: SolanaCCTPBridge burn + EVM receiveMessage
|
|
45
|
+
* - Solana → Solana: throws (use native Solana transfer instead)
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { UnifiedBridge } from 'agentwallet-sdk';
|
|
50
|
+
* import { createWalletClient } from 'viem';
|
|
51
|
+
*
|
|
52
|
+
* const bridge = new UnifiedBridge({ evmSigner });
|
|
53
|
+
*
|
|
54
|
+
* // Bridge 1 USDC from Base to Polygon
|
|
55
|
+
* const result = await bridge.bridge({
|
|
56
|
+
* amount: 1_000_000n,
|
|
57
|
+
* sourceChain: 'base',
|
|
58
|
+
* destinationChain: 'polygon',
|
|
59
|
+
* destinationAddress: '0x...',
|
|
60
|
+
* });
|
|
61
|
+
* console.log(bridge.getSupportedChains()); // 17 chains!
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare class UnifiedBridge {
|
|
65
|
+
private readonly config;
|
|
66
|
+
private readonly solanaConnection;
|
|
67
|
+
constructor(config?: UnifiedBridgeConfig);
|
|
68
|
+
/**
|
|
69
|
+
* Bridge USDC between any two CCTP V2 supported chains.
|
|
70
|
+
* Routes automatically based on source/destination chain types.
|
|
71
|
+
*/
|
|
72
|
+
bridge(params: UnifiedBridgeParams): Promise<BridgeResult>;
|
|
73
|
+
/**
|
|
74
|
+
* Get all supported chains (16 EVM + Solana = 17 total).
|
|
75
|
+
*/
|
|
76
|
+
getSupportedChains(): CCTPSupportedChain[];
|
|
77
|
+
/**
|
|
78
|
+
* Get a bridge quote: fee breakdown + estimated time.
|
|
79
|
+
*/
|
|
80
|
+
getQuote(params: {
|
|
81
|
+
amount: bigint;
|
|
82
|
+
sourceChain: CCTPSupportedChain;
|
|
83
|
+
destinationChain: CCTPSupportedChain;
|
|
84
|
+
}): BridgeQuote;
|
|
85
|
+
/**
|
|
86
|
+
* Check if a route is supported.
|
|
87
|
+
*/
|
|
88
|
+
isRouteSupported(source: CCTPSupportedChain, destination: CCTPSupportedChain): boolean;
|
|
89
|
+
private bridgeEvmToEvm;
|
|
90
|
+
private bridgeSolanaToEvm;
|
|
91
|
+
private bridgeEvmToSolana;
|
|
92
|
+
private validateParams;
|
|
93
|
+
/**
|
|
94
|
+
* Convert a Solana base58 address to a 32-byte hex string for EVM mintRecipient.
|
|
95
|
+
* Per Circle docs: hex-encoded USDC token account address.
|
|
96
|
+
*/
|
|
97
|
+
private solanaAddressToHex;
|
|
98
|
+
}
|
|
99
|
+
export { BridgeError, SolanaBridgeError };
|
|
100
|
+
export { CCTP_DOMAIN_IDS, BRIDGE_CHAIN_IDS, BRIDGE_RPC_URLS, calcBridgeFee, };
|
|
101
|
+
//# sourceMappingURL=unified.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unified.d.ts","sourceRoot":"","sources":["../../src/bridge/unified.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAgB,WAAW,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAChB,eAAe,EACf,gBAAgB,EAChB,eAAe,EAEf,aAAa,EAGd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAoB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAI1E,MAAM,WAAW,mBAAmB;IAClC,4DAA4D;IAC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