basileus-agentkit-plugin 0.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.
Files changed (69) hide show
  1. package/.nvmrc +1 -0
  2. package/.prettierrc +7 -0
  3. package/dist/actions/aleph.d.ts +2 -0
  4. package/dist/actions/aleph.js +114 -0
  5. package/dist/actions/aleph.js.map +1 -0
  6. package/dist/actions/compound/compoundActionProvider.d.ts +2 -0
  7. package/dist/actions/compound/compoundActionProvider.js +130 -0
  8. package/dist/actions/compound/compoundActionProvider.js.map +1 -0
  9. package/dist/actions/compound/constants.d.ts +194 -0
  10. package/dist/actions/compound/constants.js +134 -0
  11. package/dist/actions/compound/constants.js.map +1 -0
  12. package/dist/actions/compound/index.d.ts +1 -0
  13. package/dist/actions/compound/index.js +2 -0
  14. package/dist/actions/compound/index.js.map +1 -0
  15. package/dist/actions/compound/schemas.d.ts +42 -0
  16. package/dist/actions/compound/schemas.js +41 -0
  17. package/dist/actions/compound/schemas.js.map +1 -0
  18. package/dist/actions/compound/utils.d.ts +15 -0
  19. package/dist/actions/compound/utils.js +260 -0
  20. package/dist/actions/compound/utils.js.map +1 -0
  21. package/dist/actions/constants.d.ts +69 -0
  22. package/dist/actions/constants.js +50 -0
  23. package/dist/actions/constants.js.map +1 -0
  24. package/dist/actions/index.d.ts +2 -0
  25. package/dist/actions/index.js +3 -0
  26. package/dist/actions/index.js.map +1 -0
  27. package/dist/agent-loop.d.ts +14 -0
  28. package/dist/agent-loop.js +60 -0
  29. package/dist/agent-loop.js.map +1 -0
  30. package/dist/aleph-publisher.d.ts +9 -0
  31. package/dist/aleph-publisher.js +41 -0
  32. package/dist/aleph-publisher.js.map +1 -0
  33. package/dist/index.d.ts +11 -0
  34. package/dist/index.js +9 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/summarizer.d.ts +3 -0
  37. package/dist/summarizer.js +21 -0
  38. package/dist/summarizer.js.map +1 -0
  39. package/dist/tools.d.ts +6 -0
  40. package/dist/tools.js +30 -0
  41. package/dist/tools.js.map +1 -0
  42. package/dist/types.d.ts +15 -0
  43. package/dist/types.js +2 -0
  44. package/dist/types.js.map +1 -0
  45. package/dist/wallet.d.ts +17520 -0
  46. package/dist/wallet.js +47 -0
  47. package/dist/wallet.js.map +1 -0
  48. package/dist/x402-tracker.d.ts +2 -0
  49. package/dist/x402-tracker.js +39 -0
  50. package/dist/x402-tracker.js.map +1 -0
  51. package/eslint.config.js +26 -0
  52. package/package.json +86 -0
  53. package/src/actions/aleph.ts +145 -0
  54. package/src/actions/compound/compoundActionProvider.ts +166 -0
  55. package/src/actions/compound/constants.ts +140 -0
  56. package/src/actions/compound/index.ts +1 -0
  57. package/src/actions/compound/schemas.ts +45 -0
  58. package/src/actions/compound/utils.ts +367 -0
  59. package/src/actions/constants.ts +53 -0
  60. package/src/actions/index.ts +2 -0
  61. package/src/agent-loop.ts +93 -0
  62. package/src/aleph-publisher.ts +44 -0
  63. package/src/index.ts +11 -0
  64. package/src/summarizer.ts +30 -0
  65. package/src/tools.ts +40 -0
  66. package/src/types.ts +17 -0
  67. package/src/wallet.ts +73 -0
  68. package/src/x402-tracker.ts +43 -0
  69. package/tsconfig.json +15 -0
package/src/types.ts ADDED
@@ -0,0 +1,17 @@
1
+ export interface ToolExecution {
2
+ name: string;
3
+ args?: Record<string, string>;
4
+ result?: string;
5
+ txHash?: string;
6
+ meta?: Record<string, string>;
7
+ }
8
+
9
+ export type ActivityType = "inventory" | "survival" | "strategy" | "error";
10
+
11
+ export interface AgentActivity {
12
+ summary: string;
13
+ model: string;
14
+ cycleId: string;
15
+ tools?: ToolExecution[];
16
+ txHashes?: string[];
17
+ }
package/src/wallet.ts ADDED
@@ -0,0 +1,73 @@
1
+ import {
2
+ createWalletClient,
3
+ createPublicClient,
4
+ http,
5
+ formatUnits,
6
+ type Hex,
7
+ type Chain,
8
+ } from "viem";
9
+ import { privateKeyToAccount } from "viem/accounts";
10
+ import { erc20Abi } from "viem";
11
+ import { ViemWalletProvider } from "@coinbase/agentkit";
12
+ import { Attribution } from "ox/erc8021";
13
+
14
+ const BUILDER_CODE = "bc_kj26kx76";
15
+
16
+ // USDC on Base mainnet
17
+ const USDC_BASE = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" as const;
18
+ // USDC on Base Sepolia
19
+ const USDC_BASE_SEPOLIA = "0x036CbD53842c5426634e7929541eC2318f3dCF7e" as const;
20
+
21
+ export interface WalletInfo {
22
+ address: string;
23
+ ethBalance: string;
24
+ usdcBalance: string;
25
+ chainName: string;
26
+ }
27
+
28
+ export async function createAgentWallet(privateKey: Hex, chain: Chain, rpcUrl?: string) {
29
+ const account = privateKeyToAccount(privateKey);
30
+ const dataSuffix = Attribution.toDataSuffix({ codes: [BUILDER_CODE] });
31
+
32
+ const walletClient = createWalletClient({
33
+ account,
34
+ chain,
35
+ transport: http(rpcUrl),
36
+ dataSuffix,
37
+ });
38
+
39
+ const publicClient = createPublicClient({
40
+ chain,
41
+ transport: http(rpcUrl),
42
+ });
43
+
44
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
+ const provider = new ViemWalletProvider(walletClient as any);
46
+
47
+ const usdcAddress = chain.id === 8453 ? USDC_BASE : USDC_BASE_SEPOLIA;
48
+
49
+ return { walletClient, publicClient, provider, account, usdcAddress };
50
+ }
51
+
52
+ export async function getBalances(
53
+ wallet: Awaited<ReturnType<typeof createAgentWallet>>,
54
+ ): Promise<WalletInfo> {
55
+ const { publicClient, account, usdcAddress, walletClient } = wallet;
56
+
57
+ const [ethBal, usdcBal] = await Promise.all([
58
+ publicClient.getBalance({ address: account.address }),
59
+ publicClient.readContract({
60
+ address: usdcAddress,
61
+ abi: erc20Abi,
62
+ functionName: "balanceOf",
63
+ args: [account.address],
64
+ }),
65
+ ]);
66
+
67
+ return {
68
+ address: account.address,
69
+ ethBalance: formatUnits(ethBal, 18),
70
+ usdcBalance: formatUnits(usdcBal as bigint, 6),
71
+ chainName: walletClient.chain?.name ?? "unknown",
72
+ };
73
+ }
@@ -0,0 +1,43 @@
1
+ let paymentTxHashes: string[] = [];
2
+ let installed = false;
3
+
4
+ export function installX402Tracker(): void {
5
+ if (installed) return;
6
+ const originalFetch = globalThis.fetch;
7
+
8
+ globalThis.fetch = async (...args: Parameters<typeof fetch>): Promise<Response> => {
9
+ const response = await originalFetch(...args);
10
+
11
+ const receipt = response.headers.get("x-payment-receipt");
12
+ if (receipt && /^0x[a-fA-F0-9]{64}$/.test(receipt)) {
13
+ paymentTxHashes.push(receipt);
14
+ console.log(`[x402] Captured payment tx: ${receipt.slice(0, 14)}...`);
15
+ return response;
16
+ }
17
+
18
+ const paymentHeader = response.headers.get("payment-response");
19
+ if (paymentHeader) {
20
+ try {
21
+ const decoded = JSON.parse(atob(paymentHeader));
22
+ const txHash = decoded.transaction ?? decoded.txHash;
23
+ if (txHash && typeof txHash === "string") {
24
+ paymentTxHashes.push(txHash);
25
+ console.log(`[x402] Captured payment tx: ${txHash.slice(0, 14)}...`);
26
+ }
27
+ } catch {
28
+ console.warn("[x402] Failed to decode payment-response header");
29
+ }
30
+ }
31
+
32
+ return response;
33
+ };
34
+
35
+ installed = true;
36
+ console.log("[x402] Fetch interceptor installed");
37
+ }
38
+
39
+ export function drainX402TxHashes(): string[] {
40
+ const hashes = [...paymentTxHashes];
41
+ paymentTxHashes = [];
42
+ return hashes;
43
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "outDir": "dist",
10
+ "rootDir": "src",
11
+ "declaration": true,
12
+ "sourceMap": true
13
+ },
14
+ "include": ["src/**/*"]
15
+ }