@agent-pay/mcp 2.0.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/dist/wallet.js ADDED
@@ -0,0 +1,119 @@
1
+ import { createPublicClient, createWalletClient, http, } from "viem";
2
+ import { privateKeyToAccount } from "viem/accounts";
3
+ import { base, baseSepolia } from "viem/chains";
4
+ // ── USDC contract addresses ──
5
+ const USDC_ADDRESSES = {
6
+ "base-sepolia": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
7
+ base: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
8
+ };
9
+ const CHAINS = {
10
+ "base-sepolia": baseSepolia,
11
+ base: base,
12
+ };
13
+ // Minimal ERC-20 ABI — only the methods we need
14
+ const ERC20_ABI = [
15
+ {
16
+ name: "transfer",
17
+ type: "function",
18
+ stateMutability: "nonpayable",
19
+ inputs: [
20
+ { name: "to", type: "address" },
21
+ { name: "amount", type: "uint256" },
22
+ ],
23
+ outputs: [{ name: "", type: "bool" }],
24
+ },
25
+ {
26
+ name: "balanceOf",
27
+ type: "function",
28
+ stateMutability: "view",
29
+ inputs: [{ name: "account", type: "address" }],
30
+ outputs: [{ name: "", type: "uint256" }],
31
+ },
32
+ ];
33
+ export class UsdcWallet {
34
+ address;
35
+ network;
36
+ publicClient;
37
+ walletClient;
38
+ usdcAddress;
39
+ constructor(publicClient, walletClient, address, usdcAddress, network) {
40
+ this.publicClient = publicClient;
41
+ this.walletClient = walletClient;
42
+ this.address = address;
43
+ this.usdcAddress = usdcAddress;
44
+ this.network = network;
45
+ }
46
+ /**
47
+ * Transfer USDC to a recipient.
48
+ * @param to - recipient address
49
+ * @param amount - raw amount in USDC smallest unit (6 decimals, e.g. "32200" = 0.0322 USDC)
50
+ */
51
+ async transferUsdc(to, amount) {
52
+ // Simulate first to catch errors (e.g. insufficient balance) before spending gas
53
+ const { request } = await this.publicClient.simulateContract({
54
+ account: this.address,
55
+ address: this.usdcAddress,
56
+ abi: ERC20_ABI,
57
+ functionName: "transfer",
58
+ args: [to, amount],
59
+ });
60
+ const txHash = await this.walletClient.writeContract(request);
61
+ // Wait for 1 confirmation so the gateway can verify the receipt
62
+ await this.publicClient.waitForTransactionReceipt({
63
+ hash: txHash,
64
+ confirmations: 1,
65
+ });
66
+ return { txHash };
67
+ }
68
+ /**
69
+ * Get USDC balance formatted as a human-readable string (e.g. "12.50").
70
+ */
71
+ async getBalance() {
72
+ const raw = await this.publicClient.readContract({
73
+ address: this.usdcAddress,
74
+ abi: ERC20_ABI,
75
+ functionName: "balanceOf",
76
+ args: [this.address],
77
+ });
78
+ // USDC has 6 decimals
79
+ const whole = raw / 1000000n;
80
+ const frac = raw % 1000000n;
81
+ const fracStr = frac.toString().padStart(6, "0").replace(/0+$/, "");
82
+ return fracStr.length > 0
83
+ ? `${whole}.${fracStr.slice(0, 2).padEnd(2, "0")}`
84
+ : `${whole}.00`;
85
+ }
86
+ }
87
+ /**
88
+ * Create a USDC wallet from environment variables.
89
+ * Returns null if AGENT_PAY_WALLET_KEY is not set (simulated mode).
90
+ */
91
+ export function createWallet() {
92
+ const privateKey = process.env.AGENT_PAY_WALLET_KEY;
93
+ if (!privateKey) {
94
+ return null;
95
+ }
96
+ const network = process.env.AGENT_PAY_NETWORK ?? "base";
97
+ const chain = CHAINS[network];
98
+ if (!chain) {
99
+ throw new Error(`Unknown network "${network}". Supported: ${Object.keys(CHAINS).join(", ")}`);
100
+ }
101
+ const usdcAddress = USDC_ADDRESSES[network];
102
+ if (!usdcAddress) {
103
+ throw new Error(`No USDC address configured for network "${network}".`);
104
+ }
105
+ // Ensure the key has 0x prefix
106
+ const key = (privateKey.startsWith("0x") ? privateKey : `0x${privateKey}`);
107
+ const account = privateKeyToAccount(key);
108
+ const publicClient = createPublicClient({
109
+ chain,
110
+ transport: http(),
111
+ });
112
+ const walletClient = createWalletClient({
113
+ account,
114
+ chain,
115
+ transport: http(),
116
+ });
117
+ return new UsdcWallet(publicClient, walletClient, account.address, usdcAddress, network);
118
+ }
119
+ //# sourceMappingURL=wallet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.js","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,IAAI,GAML,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEhD,gCAAgC;AAEhC,MAAM,cAAc,GAA4B;IAC9C,cAAc,EAAE,4CAA4C;IAC5D,IAAI,EAAE,4CAA4C;CACnD,CAAC;AAEF,MAAM,MAAM,GAA0B;IACpC,cAAc,EAAE,WAAW;IAC3B,IAAI,EAAE,IAAI;CACX,CAAC;AAEF,gDAAgD;AAChD,MAAM,SAAS,GAAG;IAChB;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,UAAU;QAChB,eAAe,EAAE,YAAY;QAC7B,MAAM,EAAE;YACN,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE;YAC/B,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE;SACpC;QACD,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;KACtC;IACD;QACE,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,UAAU;QAChB,eAAe,EAAE,MAAM;QACvB,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QAC9C,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;KACzC;CACO,CAAC;AAMX,MAAM,OAAO,UAAU;IACL,OAAO,CAAU;IACjB,OAAO,CAAS;IAExB,YAAY,CAAe;IAC3B,YAAY,CAAe;IAC3B,W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MAAM,OAAO,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;IAEzC,MAAM,YAAY,GAAG,kBAAkB,CAAC;QACtC,KAAK;QACL,SAAS,EAAE,IAAI,EAAE;KAClB,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,kBAAkB,CAAC;QACtC,OAAO;QACP,KAAK;QACL,SAAS,EAAE,IAAI,EAAE;KAClB,CAAC,CAAC;IAEH,OAAO,IAAI,UAAU,CACnB,YAAY,EACZ,YAAY,EACZ,OAAO,CAAC,OAAO,EACf,WAAW,EACX,OAAO,CACR,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@agent-pay/mcp",
3
+ "version": "2.0.0",
4
+ "description": "MCP server for provisioning paid developer services — starting with Akash compute",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "bin": {
8
+ "agent-pay": "dist/cli.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "README.md"
13
+ ],
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "start": "node dist/index.js",
17
+ "dev": "tsx src/index.ts",
18
+ "setup": "tsx src/cli.ts setup",
19
+ "prepublishOnly": "npm run build"
20
+ },
21
+ "keywords": [
22
+ "mcp",
23
+ "claude",
24
+ "akash",
25
+ "usdc",
26
+ "compute",
27
+ "agent",
28
+ "walletconnect"
29
+ ],
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/anthropics/agent-pay.git"
33
+ },
34
+ "license": "MIT",
35
+ "dependencies": {
36
+ "@modelcontextprotocol/sdk": "^1.12.1",
37
+ "@walletconnect/sign-client": "^2.17.0",
38
+ "@walletconnect/types": "^2.17.0",
39
+ "qrcode-terminal": "^0.12.0",
40
+ "viem": "^2.21.0"
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "^22.0.0",
44
+ "@types/qrcode-terminal": "^0.12.2",
45
+ "tsx": "^4.19.0",
46
+ "typescript": "^5.7.0"
47
+ },
48
+ "engines": {
49
+ "node": ">=18"
50
+ }
51
+ }