@coinbase/agentkit 0.10.0 → 0.10.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.
Files changed (131) hide show
  1. package/README.md +75 -0
  2. package/dist/action-providers/across/acrossActionProvider.js +3 -3
  3. package/dist/action-providers/cdp/cdpApiActionProvider.d.ts +3 -12
  4. package/dist/action-providers/cdp/cdpApiActionProvider.js +2 -81
  5. package/dist/action-providers/cdp/cdpApiActionProvider.test.js +0 -125
  6. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.d.ts +18 -3
  7. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.js +223 -23
  8. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.js +278 -0
  9. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.d.ts +17 -2
  10. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.js +223 -18
  11. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.js +265 -1
  12. package/dist/action-providers/cdp/schemas.d.ts +12 -12
  13. package/dist/action-providers/cdp/schemas.js +17 -5
  14. package/dist/action-providers/cdp/swapUtils.d.ts +32 -0
  15. package/dist/action-providers/cdp/swapUtils.js +142 -0
  16. package/dist/action-providers/clanker/clankerActionProvider.d.ts +43 -0
  17. package/dist/action-providers/clanker/clankerActionProvider.js +130 -0
  18. package/dist/action-providers/clanker/clankerActionProvider.test.d.ts +4 -0
  19. package/dist/action-providers/clanker/clankerActionProvider.test.js +119 -0
  20. package/dist/action-providers/clanker/index.d.ts +2 -0
  21. package/dist/action-providers/clanker/index.js +18 -0
  22. package/dist/action-providers/clanker/schemas.d.ts +56 -0
  23. package/dist/action-providers/clanker/schemas.js +47 -0
  24. package/dist/action-providers/clanker/utils.d.ts +9 -0
  25. package/dist/action-providers/clanker/utils.js +23 -0
  26. package/dist/action-providers/compound/constants.d.ts +1 -1
  27. package/dist/action-providers/compound/constants.js +2 -2
  28. package/dist/action-providers/erc20/constants.d.ts +35 -135
  29. package/dist/action-providers/erc20/constants.js +37 -189
  30. package/dist/action-providers/erc20/erc20ActionProvider.d.ts +9 -1
  31. package/dist/action-providers/erc20/erc20ActionProvider.js +87 -35
  32. package/dist/action-providers/erc20/erc20ActionProvider.test.js +115 -52
  33. package/dist/action-providers/erc20/schemas.d.ts +25 -12
  34. package/dist/action-providers/erc20/schemas.js +34 -6
  35. package/dist/action-providers/erc20/utils.d.ts +19 -0
  36. package/dist/action-providers/erc20/utils.js +54 -0
  37. package/dist/action-providers/flaunch/constants.d.ts +1 -1
  38. package/dist/action-providers/flaunch/constants.js +2 -2
  39. package/dist/action-providers/flaunch/flaunchActionProvider.js +3 -11
  40. package/dist/action-providers/flaunch/flaunchActionProvider.test.js +5 -0
  41. package/dist/action-providers/index.d.ts +3 -0
  42. package/dist/action-providers/index.js +3 -0
  43. package/dist/action-providers/jupiter/schemas.d.ts +1 -1
  44. package/dist/action-providers/moonwell/schemas.d.ts +2 -2
  45. package/dist/action-providers/morpho/morphoActionProvider.js +5 -5
  46. package/dist/action-providers/morpho/schemas.d.ts +2 -2
  47. package/dist/action-providers/pyth/pythActionProvider.js +5 -0
  48. package/dist/action-providers/pyth/pythActionProvider.test.js +5 -1
  49. package/dist/action-providers/superfluid/constants.d.ts +814 -0
  50. package/dist/action-providers/superfluid/constants.js +2826 -0
  51. package/dist/action-providers/superfluid/graphQueries/endpoints.d.ts +2 -0
  52. package/dist/action-providers/superfluid/graphQueries/endpoints.js +5 -0
  53. package/dist/action-providers/superfluid/graphQueries/queries.d.ts +1 -0
  54. package/dist/action-providers/superfluid/graphQueries/queries.js +35 -0
  55. package/dist/action-providers/superfluid/graphQueries/superfluidGraphQueries.d.ts +8 -0
  56. package/dist/action-providers/superfluid/graphQueries/superfluidGraphQueries.js +24 -0
  57. package/dist/action-providers/superfluid/graphQueries/types.d.ts +27 -0
  58. package/dist/action-providers/superfluid/graphQueries/types.js +2 -0
  59. package/dist/action-providers/superfluid/index.d.ts +7 -0
  60. package/dist/action-providers/superfluid/index.js +23 -0
  61. package/dist/action-providers/superfluid/schemas.d.ts +86 -0
  62. package/dist/action-providers/superfluid/schemas.js +103 -0
  63. package/dist/action-providers/superfluid/superfluidActionProvider.d.ts +20 -0
  64. package/dist/action-providers/superfluid/superfluidActionProvider.js +36 -0
  65. package/dist/action-providers/superfluid/superfluidPoolActionProvider.d.ts +46 -0
  66. package/dist/action-providers/superfluid/superfluidPoolActionProvider.js +143 -0
  67. package/dist/action-providers/superfluid/superfluidPoolActionProvider.test.d.ts +1 -0
  68. package/dist/action-providers/superfluid/superfluidPoolActionProvider.test.js +92 -0
  69. package/dist/action-providers/superfluid/superfluidQueryActionProvider.d.ts +27 -0
  70. package/dist/action-providers/superfluid/superfluidQueryActionProvider.js +71 -0
  71. package/dist/action-providers/superfluid/superfluidQueryActionProvider.test.d.ts +1 -0
  72. package/dist/action-providers/superfluid/superfluidQueryActionProvider.test.js +57 -0
  73. package/dist/action-providers/superfluid/superfluidStreamActionProvider.d.ts +56 -0
  74. package/dist/action-providers/superfluid/superfluidStreamActionProvider.js +191 -0
  75. package/dist/action-providers/superfluid/superfluidStreamActionProvider.test.d.ts +1 -0
  76. package/dist/action-providers/superfluid/superfluidStreamActionProvider.test.js +80 -0
  77. package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.d.ts +30 -0
  78. package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.js +108 -0
  79. package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.test.d.ts +1 -0
  80. package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.test.js +75 -0
  81. package/dist/action-providers/superfluid/superfluidWrapperActionProvider.d.ts +32 -0
  82. package/dist/action-providers/superfluid/superfluidWrapperActionProvider.js +101 -0
  83. package/dist/action-providers/superfluid/superfluidWrapperActionProvider.test.d.ts +1 -0
  84. package/dist/action-providers/superfluid/superfluidWrapperActionProvider.test.js +85 -0
  85. package/dist/action-providers/superfluid/utils/parseLogs.d.ts +18 -0
  86. package/dist/action-providers/superfluid/utils/parseLogs.js +78 -0
  87. package/dist/action-providers/truemarkets/truemarketsActionProvider.d.ts +4 -16
  88. package/dist/action-providers/truemarkets/truemarketsActionProvider.js +20 -41
  89. package/dist/action-providers/truemarkets/truemarketsActionProvider.test.js +11 -33
  90. package/dist/action-providers/wallet/walletActionProvider.js +21 -10
  91. package/dist/action-providers/wallet/walletActionProvider.test.js +6 -2
  92. package/dist/action-providers/zeroX/index.d.ts +1 -0
  93. package/dist/action-providers/zeroX/index.js +17 -0
  94. package/dist/action-providers/zeroX/schemas.d.ts +51 -0
  95. package/dist/action-providers/zeroX/schemas.js +82 -0
  96. package/dist/action-providers/zeroX/utils.d.ts +23 -0
  97. package/dist/action-providers/zeroX/utils.js +106 -0
  98. package/dist/action-providers/zeroX/zeroXActionProvider.d.ts +57 -0
  99. package/dist/action-providers/zeroX/zeroXActionProvider.js +407 -0
  100. package/dist/action-providers/zeroX/zeroXActionProvider.test.d.ts +1 -0
  101. package/dist/action-providers/zeroX/zeroXActionProvider.test.js +445 -0
  102. package/dist/wallet-providers/cdpEvmWalletProvider.d.ts +20 -2
  103. package/dist/wallet-providers/cdpEvmWalletProvider.js +40 -15
  104. package/dist/wallet-providers/cdpShared.d.ts +5 -0
  105. package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +22 -3
  106. package/dist/wallet-providers/cdpSmartWalletProvider.js +43 -19
  107. package/dist/wallet-providers/cdpSolanaWalletProvider.d.ts +1 -1
  108. package/dist/wallet-providers/cdpSolanaWalletProvider.js +7 -7
  109. package/dist/wallet-providers/cdpSolanaWalletProvider.test.js +15 -12
  110. package/dist/wallet-providers/evmWalletProvider.d.ts +5 -1
  111. package/dist/wallet-providers/legacyCdpSmartWalletProvider.d.ts +9 -2
  112. package/dist/wallet-providers/legacyCdpSmartWalletProvider.js +12 -2
  113. package/dist/wallet-providers/legacyCdpWalletProvider.d.ts +12 -2
  114. package/dist/wallet-providers/legacyCdpWalletProvider.js +11 -2
  115. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.d.ts +10 -2
  116. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.js +12 -3
  117. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.test.js +1 -1
  118. package/dist/wallet-providers/privyEvmWalletProvider.d.ts +2 -0
  119. package/dist/wallet-providers/privyEvmWalletProvider.js +2 -1
  120. package/dist/wallet-providers/privyEvmWalletProvider.test.js +1 -1
  121. package/dist/wallet-providers/solanaKeypairWalletProvider.d.ts +1 -1
  122. package/dist/wallet-providers/solanaKeypairWalletProvider.js +3 -4
  123. package/dist/wallet-providers/solanaKeypairWalletProvider.test.js +4 -2
  124. package/dist/wallet-providers/viemWalletProvider.d.ts +12 -2
  125. package/dist/wallet-providers/viemWalletProvider.js +12 -3
  126. package/dist/wallet-providers/viemWalletProvider.test.js +6 -5
  127. package/dist/wallet-providers/walletProvider.d.ts +1 -1
  128. package/dist/wallet-providers/zeroDevWalletProvider.d.ts +10 -2
  129. package/dist/wallet-providers/zeroDevWalletProvider.js +14 -5
  130. package/dist/wallet-providers/zeroDevWalletProvider.test.js +2 -2
  131. package/package.json +4 -2
@@ -13,20 +13,20 @@ export declare const RequestFaucetFundsV2Schema: z.ZodObject<{
13
13
  * Input schema for swap tokens action.
14
14
  */
15
15
  export declare const SwapSchema: z.ZodObject<{
16
- fromAssetId: z.ZodString;
17
- toAssetId: z.ZodString;
18
- amount: z.ZodString;
19
- network: z.ZodOptional<z.ZodString>;
16
+ fromToken: z.ZodString;
17
+ toToken: z.ZodString;
18
+ fromAmount: z.ZodString;
19
+ slippageBps: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
20
20
  }, "strip", z.ZodTypeAny, {
21
- amount: string;
22
- fromAssetId: string;
23
- toAssetId: string;
24
- network?: string | undefined;
21
+ fromToken: string;
22
+ toToken: string;
23
+ fromAmount: string;
24
+ slippageBps: number;
25
25
  }, {
26
- amount: string;
27
- fromAssetId: string;
28
- toAssetId: string;
29
- network?: string | undefined;
26
+ fromToken: string;
27
+ toToken: string;
28
+ fromAmount: string;
29
+ slippageBps?: number | undefined;
30
30
  }>;
31
31
  /**
32
32
  * Input schema for listing spend permissions action.
@@ -16,13 +16,25 @@ exports.RequestFaucetFundsV2Schema = zod_1.z
16
16
  */
17
17
  exports.SwapSchema = zod_1.z
18
18
  .object({
19
- fromAssetId: zod_1.z.string().describe("The asset ID to swap from (e.g., 'eth', 'usdc')"),
20
- toAssetId: zod_1.z.string().describe("The asset ID to swap to (e.g., 'eth', 'usdc')"),
21
- amount: zod_1.z.string().describe("The amount to swap (in the from asset's units)"),
22
- network: zod_1.z
19
+ fromToken: zod_1.z
20
+ .string()
21
+ .regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
22
+ .describe("The token contract address to swap from"),
23
+ toToken: zod_1.z
24
+ .string()
25
+ .regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
26
+ .describe("The token contract address to swap to"),
27
+ fromAmount: zod_1.z
23
28
  .string()
29
+ .describe("The amount of fromToken to sell in whole units (e.g., 1.5 WETH, 10.5 USDC)"),
30
+ slippageBps: zod_1.z
31
+ .number()
32
+ .int()
33
+ .min(0)
34
+ .max(10000)
24
35
  .optional()
25
- .describe("The network to perform the swap on (defaults to wallet's network)"),
36
+ .default(100)
37
+ .describe("The maximum acceptable slippage in basis points (0-10000, default: 100 = 1%)"),
26
38
  })
27
39
  .strip()
28
40
  .describe("Instructions for swapping tokens");
@@ -0,0 +1,32 @@
1
+ import { EvmWalletProvider } from "../../wallet-providers";
2
+ export declare const PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
3
+ /**
4
+ * Checks if a token is native ETH.
5
+ *
6
+ * @param token - The token address to check.
7
+ * @returns True if the token is native ETH, false otherwise.
8
+ */
9
+ export declare function isNativeEth(token: string): boolean;
10
+ /**
11
+ * Gets the details (decimals and name) for both fromToken and toToken
12
+ *
13
+ * @param walletProvider - The EVM wallet provider to read contracts
14
+ * @param fromToken - The contract address of the from token
15
+ * @param toToken - The contract address of the to token
16
+ * @returns Promise<{fromTokenDecimals: number, toTokenDecimals: number, fromTokenName: string, toTokenName: string}>
17
+ */
18
+ export declare function getTokenDetails(walletProvider: EvmWalletProvider, fromToken: string, toToken: string): Promise<{
19
+ fromTokenDecimals: number;
20
+ toTokenDecimals: number;
21
+ fromTokenName: string;
22
+ toTokenName: string;
23
+ }>;
24
+ /**
25
+ * Retry function with exponential backoff
26
+ *
27
+ * @param fn - The function to retry
28
+ * @param maxRetries - Maximum number of retries (default: 3)
29
+ * @param baseDelay - Base delay in milliseconds (default: 1000)
30
+ * @returns Promise that resolves with the function result or rejects with the last error
31
+ */
32
+ export declare function retryWithExponentialBackoff<T>(fn: () => Promise<T>, maxRetries?: number, baseDelay?: number): Promise<T>;
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PERMIT2_ADDRESS = void 0;
4
+ exports.isNativeEth = isNativeEth;
5
+ exports.getTokenDetails = getTokenDetails;
6
+ exports.retryWithExponentialBackoff = retryWithExponentialBackoff;
7
+ const viem_1 = require("viem");
8
+ // Permit2 contract address is the same across all networks
9
+ exports.PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
10
+ /**
11
+ * Checks if a token is native ETH.
12
+ *
13
+ * @param token - The token address to check.
14
+ * @returns True if the token is native ETH, false otherwise.
15
+ */
16
+ function isNativeEth(token) {
17
+ return token.toLowerCase() === "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
18
+ }
19
+ /**
20
+ * Gets the details (decimals and name) for both fromToken and toToken
21
+ *
22
+ * @param walletProvider - The EVM wallet provider to read contracts
23
+ * @param fromToken - The contract address of the from token
24
+ * @param toToken - The contract address of the to token
25
+ * @returns Promise<{fromTokenDecimals: number, toTokenDecimals: number, fromTokenName: string, toTokenName: string}>
26
+ */
27
+ async function getTokenDetails(walletProvider, fromToken, toToken) {
28
+ // Initialize default values for native ETH
29
+ let fromTokenDecimals = 18;
30
+ let fromTokenName = "ETH";
31
+ let toTokenDecimals = 18;
32
+ let toTokenName = "ETH";
33
+ // Prepare multicall contracts array
34
+ const contracts = [];
35
+ const contractIndexMap = {
36
+ fromDecimals: -1,
37
+ fromName: -1,
38
+ toDecimals: -1,
39
+ toName: -1,
40
+ };
41
+ // Add from token contracts if not native ETH
42
+ if (!isNativeEth(fromToken)) {
43
+ contractIndexMap.fromDecimals = contracts.length;
44
+ contracts.push({
45
+ address: fromToken,
46
+ abi: viem_1.erc20Abi,
47
+ functionName: "decimals",
48
+ });
49
+ contractIndexMap.fromName = contracts.length;
50
+ contracts.push({
51
+ address: fromToken,
52
+ abi: viem_1.erc20Abi,
53
+ functionName: "name",
54
+ });
55
+ }
56
+ // Add to token contracts if not native ETH
57
+ if (!isNativeEth(toToken)) {
58
+ contractIndexMap.toDecimals = contracts.length;
59
+ contracts.push({
60
+ address: toToken,
61
+ abi: viem_1.erc20Abi,
62
+ functionName: "decimals",
63
+ });
64
+ contractIndexMap.toName = contracts.length;
65
+ contracts.push({
66
+ address: toToken,
67
+ abi: viem_1.erc20Abi,
68
+ functionName: "name",
69
+ });
70
+ }
71
+ // Execute multicall if there are contracts to call
72
+ if (contracts.length > 0) {
73
+ try {
74
+ const results = await walletProvider.getPublicClient().multicall({
75
+ contracts,
76
+ });
77
+ // Extract from token details
78
+ if (contractIndexMap.fromDecimals !== -1) {
79
+ const decimalsResult = results[contractIndexMap.fromDecimals];
80
+ const nameResult = results[contractIndexMap.fromName];
81
+ if (decimalsResult.status === "success" && nameResult.status === "success") {
82
+ fromTokenDecimals = decimalsResult.result;
83
+ fromTokenName = nameResult.result;
84
+ }
85
+ else {
86
+ throw new Error(`Failed to read details for fromToken ${fromToken}. This address may not be a valid ERC20 contract.`);
87
+ }
88
+ }
89
+ // Extract to token details
90
+ if (contractIndexMap.toDecimals !== -1) {
91
+ const decimalsResult = results[contractIndexMap.toDecimals];
92
+ const nameResult = results[contractIndexMap.toName];
93
+ if (decimalsResult.status === "success" && nameResult.status === "success") {
94
+ toTokenDecimals = decimalsResult.result;
95
+ toTokenName = nameResult.result;
96
+ }
97
+ else {
98
+ throw new Error(`Failed to read details for toToken ${toToken}. This address may not be a valid ERC20 contract.`);
99
+ }
100
+ }
101
+ }
102
+ catch (error) {
103
+ throw new Error(`Failed to read token details via multicall. Error: ${error}`);
104
+ }
105
+ }
106
+ return { fromTokenDecimals, toTokenDecimals, fromTokenName, toTokenName };
107
+ }
108
+ /**
109
+ * Utility function to sleep for a given number of milliseconds
110
+ *
111
+ * @param ms - Number of milliseconds to sleep
112
+ * @returns Promise that resolves after the specified delay
113
+ */
114
+ const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
115
+ /**
116
+ * Retry function with exponential backoff
117
+ *
118
+ * @param fn - The function to retry
119
+ * @param maxRetries - Maximum number of retries (default: 3)
120
+ * @param baseDelay - Base delay in milliseconds (default: 1000)
121
+ * @returns Promise that resolves with the function result or rejects with the last error
122
+ */
123
+ async function retryWithExponentialBackoff(fn, maxRetries = 3, baseDelay = 1000) {
124
+ let lastError;
125
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
126
+ // Wait before each attempt
127
+ // Calculate delay with exponential backoff: baseDelay * 2^attempt
128
+ const delay = baseDelay * Math.pow(2, attempt);
129
+ await sleep(delay);
130
+ try {
131
+ return await fn();
132
+ }
133
+ catch (error) {
134
+ lastError = error;
135
+ // If this was the last attempt, throw the error
136
+ if (attempt === maxRetries) {
137
+ throw lastError;
138
+ }
139
+ }
140
+ }
141
+ throw lastError;
142
+ }
@@ -0,0 +1,43 @@
1
+ import { z } from "zod";
2
+ import { ActionProvider } from "../actionProvider";
3
+ import { Network } from "../../network";
4
+ import { EvmWalletProvider } from "../../wallet-providers";
5
+ import { ClankTokenSchema } from "./schemas";
6
+ /**
7
+ * ClankerActionProvider provides actions for clanker operations.
8
+ *
9
+ * @description
10
+ * This provider is designed to work with EvmWalletProvider for blockchain interactions.
11
+ * It supports all evm networks.
12
+ */
13
+ export declare class ClankerActionProvider extends ActionProvider<EvmWalletProvider> {
14
+ /**
15
+ * Constructor for the ClankerActionProvider.
16
+ */
17
+ constructor();
18
+ /**
19
+ * Clanker action provider
20
+ *
21
+ * @description
22
+ * This action deploys a clanker token using the Clanker sdk
23
+ * It automatically includes the coin in the Clanker ecosystem
24
+ *
25
+ * @param walletProvider - The wallet provider instance for blockchain interactions
26
+ * @param args - Clanker arguments (modify these to fine tune token deployment, like initial quote token and rewards config)
27
+ * @returns A promise that resolves to a string describing the clanker result
28
+ */
29
+ clankToken(walletProvider: EvmWalletProvider, args: z.infer<typeof ClankTokenSchema>): Promise<string>;
30
+ /**
31
+ * Checks if this provider supports the given network.
32
+ *
33
+ * @param network - The network to check support for
34
+ * @returns True if the network is supported
35
+ */
36
+ supportsNetwork(network: Network): boolean;
37
+ }
38
+ /**
39
+ * Factory function to create a new ClankerActionProvider instance.
40
+ *
41
+ * @returns A new ClankerActionProvider instance
42
+ */
43
+ export declare const clankerActionProvider: () => ClankerActionProvider;
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.clankerActionProvider = exports.ClankerActionProvider = void 0;
13
+ const zod_1 = require("zod");
14
+ const actionProvider_1 = require("../actionProvider");
15
+ const actionDecorator_1 = require("../actionDecorator");
16
+ const wallet_providers_1 = require("../../wallet-providers");
17
+ const schemas_1 = require("./schemas");
18
+ const utils_1 = require("./utils");
19
+ /**
20
+ * ClankerActionProvider provides actions for clanker operations.
21
+ *
22
+ * @description
23
+ * This provider is designed to work with EvmWalletProvider for blockchain interactions.
24
+ * It supports all evm networks.
25
+ */
26
+ class ClankerActionProvider extends actionProvider_1.ActionProvider {
27
+ /**
28
+ * Constructor for the ClankerActionProvider.
29
+ */
30
+ constructor() {
31
+ super("clanker", []);
32
+ }
33
+ /**
34
+ * Clanker action provider
35
+ *
36
+ * @description
37
+ * This action deploys a clanker token using the Clanker sdk
38
+ * It automatically includes the coin in the Clanker ecosystem
39
+ *
40
+ * @param walletProvider - The wallet provider instance for blockchain interactions
41
+ * @param args - Clanker arguments (modify these to fine tune token deployment, like initial quote token and rewards config)
42
+ * @returns A promise that resolves to a string describing the clanker result
43
+ */
44
+ async clankToken(walletProvider, args) {
45
+ const network = walletProvider.getNetwork();
46
+ const networkId = network.networkId || "base-mainnet";
47
+ if (!this.supportsNetwork(network)) {
48
+ return `Can't Clank token; network ${networkId} is not supported`;
49
+ }
50
+ const clanker = await (0, utils_1.createClankerClient)(walletProvider, networkId);
51
+ const lockDuration = args.lockDuration_Days * 24 * 60 * 60;
52
+ const vestingDuration = args.vestingDuration_Days * 24 * 60 * 60;
53
+ const tokenConfig = {
54
+ name: args.tokenName,
55
+ symbol: args.tokenSymbol,
56
+ image: args.image,
57
+ metadata: {
58
+ socialMediaUrls: args.socialMediaUrls,
59
+ description: args.description,
60
+ },
61
+ context: {
62
+ interface: args.interface,
63
+ id: args.id,
64
+ },
65
+ tokenAdmin: walletProvider.getAddress(),
66
+ vault: {
67
+ percentage: args.vaultPercentage,
68
+ lockupDuration: lockDuration,
69
+ vestingDuration: vestingDuration,
70
+ },
71
+ chainId: Number(network.chainId),
72
+ };
73
+ try {
74
+ const res = await clanker.deploy(tokenConfig);
75
+ if ("error" in res) {
76
+ return `There was an error deploying the clanker token: ${res}`;
77
+ }
78
+ const { txHash } = res;
79
+ const confirmed = await res.waitForTransaction();
80
+ if ("error" in confirmed) {
81
+ return `There was an error confirming the clanker token deployment: ${confirmed}`;
82
+ }
83
+ const { address } = confirmed;
84
+ return `Clanker token deployed at ${address}! View the transaction at ${txHash}, or view the token page at https://clanker.world/clanker/${address}`;
85
+ }
86
+ catch (error) {
87
+ return `There was an error deploying the clanker token: ${error}`;
88
+ }
89
+ }
90
+ /**
91
+ * Checks if this provider supports the given network.
92
+ *
93
+ * @param network - The network to check support for
94
+ * @returns True if the network is supported
95
+ */
96
+ supportsNetwork(network) {
97
+ return (network.networkId === "base-mainnet" ||
98
+ network.networkId === "base-sepolia" ||
99
+ network.networkId === "arbitrum-mainnet");
100
+ }
101
+ }
102
+ exports.ClankerActionProvider = ClankerActionProvider;
103
+ __decorate([
104
+ (0, actionDecorator_1.CreateAction)({
105
+ name: "clank_token",
106
+ description: `
107
+ his tool will launch a Clanker token using the Clanker SDK.
108
+ It takes the following inputs:
109
+ - tokenName: The name of the deployed token
110
+ - tokenSymbol: The symbol of the deployed token
111
+ - description: An optional description of the token or token project
112
+ - socialMediaUrls: An optional array of social media links for the token, each with a platform and url
113
+ - image: A normal or ipfs URL pointing to the image of the token
114
+ - vaultPercentage: The percentage of the token supply to allocate to a vault accessible to the deployed after the lockup period with optional vesting
115
+ - lockDuration_Days: The lock duration of the tokens in the vault (in days) (minimum 7 days)
116
+ - vestingDuration_Days: The duration (in days) that the token should vest after lockup period, vesting is linear.
117
+ `,
118
+ schema: schemas_1.ClankTokenSchema,
119
+ }),
120
+ __metadata("design:type", Function),
121
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
122
+ __metadata("design:returntype", Promise)
123
+ ], ClankerActionProvider.prototype, "clankToken", null);
124
+ /**
125
+ * Factory function to create a new ClankerActionProvider instance.
126
+ *
127
+ * @returns A new ClankerActionProvider instance
128
+ */
129
+ const clankerActionProvider = () => new ClankerActionProvider();
130
+ exports.clankerActionProvider = clankerActionProvider;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Clanker Action Provider tests
3
+ */
4
+ export {};
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ /**
3
+ * Clanker Action Provider tests
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const clankerActionProvider_1 = require("./clankerActionProvider");
7
+ const schemas_1 = require("./schemas");
8
+ const utils_1 = require("./utils");
9
+ jest.mock("./utils", () => ({
10
+ createClankerClient: jest.fn(),
11
+ }));
12
+ const createClankerClientMock = utils_1.createClankerClient;
13
+ const DEPLOYED_HASH = "0xdeadbeef";
14
+ const DEPLOYED_TOKEN_ADDRESS = "0xabc123abc123abc123abc123abc123abc123abc1";
15
+ describe("Clanker action provider tests", () => {
16
+ const provider = (0, clankerActionProvider_1.clankerActionProvider)();
17
+ let mockWalletProvider;
18
+ beforeEach(() => {
19
+ mockWalletProvider = {
20
+ getAddress: jest.fn(),
21
+ getBalance: jest.fn(),
22
+ getName: jest.fn(),
23
+ getNetwork: jest.fn().mockReturnValue({
24
+ protocolFamily: "evm",
25
+ networkId: "base-mainnet",
26
+ }),
27
+ nativeTransfer: jest.fn(),
28
+ };
29
+ const fakeClanker = {
30
+ deploy: jest.fn(async (_tokenCfg) => ({
31
+ txHash: DEPLOYED_HASH,
32
+ waitForTransaction: async () => ({ address: DEPLOYED_TOKEN_ADDRESS }),
33
+ })),
34
+ };
35
+ createClankerClientMock.mockResolvedValue(fakeClanker);
36
+ });
37
+ describe("network validation", () => {
38
+ it("should support the protocol family and network", () => {
39
+ expect(provider.supportsNetwork({
40
+ protocolFamily: "evm",
41
+ networkId: "base-mainnet",
42
+ })).toBe(true);
43
+ });
44
+ it("should not support other protocol families", () => {
45
+ expect(provider.supportsNetwork({
46
+ protocolFamily: "other-protocol-family",
47
+ })).toBe(false);
48
+ });
49
+ it("should handle invalid network objects", () => {
50
+ expect(provider.supportsNetwork({ protocolFamily: "invalid-protocol" })).toBe(false);
51
+ expect(provider.supportsNetwork({})).toBe(false);
52
+ });
53
+ });
54
+ describe("schema validation", () => {
55
+ it("should validate example action schema", () => {
56
+ const validInput = {
57
+ tokenName: "testTokenName",
58
+ tokenSymbol: "TTN",
59
+ image: "https://test.com",
60
+ vaultPercentage: 10,
61
+ vestingDuration_Days: 30,
62
+ lockDuration_Days: 30,
63
+ interface: "CDP AgentKit",
64
+ id: "test-id",
65
+ };
66
+ const parseResult = schemas_1.ClankTokenSchema.safeParse(validInput);
67
+ expect(parseResult.success).toBe(true);
68
+ if (parseResult.success) {
69
+ expect(parseResult.data.tokenName).toBe("testTokenName");
70
+ expect(parseResult.data.tokenSymbol).toBe("TTN");
71
+ expect(parseResult.data.image).toBe("https://test.com");
72
+ expect(parseResult.data.vaultPercentage).toBe(10);
73
+ expect(parseResult.data.vestingDuration_Days).toBe(30);
74
+ expect(parseResult.data.lockDuration_Days).toBe(30);
75
+ }
76
+ });
77
+ it("should reject invalid example action input", () => {
78
+ const invalidInput = {
79
+ fieldName: "",
80
+ amount: "invalid",
81
+ };
82
+ const parseResult = schemas_1.ClankTokenSchema.safeParse(invalidInput);
83
+ expect(parseResult.success).toBe(false);
84
+ });
85
+ });
86
+ describe("clanker action execution", () => {
87
+ it("should execute the clanker action with wallet provider", async () => {
88
+ const args = {
89
+ tokenName: "testTokenName",
90
+ tokenSymbol: "TTN",
91
+ image: "https://test.com",
92
+ vaultPercentage: 10,
93
+ vestingDuration_Days: 30,
94
+ lockDuration_Days: 30,
95
+ interface: "CDP AgentKit",
96
+ id: "test-id",
97
+ };
98
+ const result = await provider.clankToken(mockWalletProvider, args);
99
+ expect(result).toContain(`Clanker token deployed at ${DEPLOYED_TOKEN_ADDRESS}`);
100
+ expect(result).toContain(`View the transaction at ${DEPLOYED_HASH}`);
101
+ expect(mockWalletProvider.getNetwork).toHaveBeenCalled();
102
+ expect(createClankerClientMock).toHaveBeenCalledWith(expect.any(Object), expect.any(String));
103
+ });
104
+ });
105
+ describe("supportsNetwork", () => {
106
+ it("should return true for base-mainnet with evm protocol", () => {
107
+ expect(provider.supportsNetwork({
108
+ protocolFamily: "evm",
109
+ networkId: "base-mainnet",
110
+ })).toBe(true);
111
+ });
112
+ it("should return false for non-base networks", () => {
113
+ expect(provider.supportsNetwork({
114
+ protocolFamily: "evm",
115
+ networkId: "ethereum-mainnet",
116
+ })).toBe(false);
117
+ });
118
+ });
119
+ });
@@ -0,0 +1,2 @@
1
+ export * from "./clankerActionProvider";
2
+ export * from "./schemas";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./clankerActionProvider"), exports);
18
+ __exportStar(require("./schemas"), exports);
@@ -0,0 +1,56 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Action schemas for the clanker action provider.
4
+ *
5
+ * This file contains the Zod schemas that define the shape and validation
6
+ * rules for action parameters in the clanker action provider.
7
+ */
8
+ export declare const ClankTokenSchema: z.ZodObject<{
9
+ tokenName: z.ZodString;
10
+ tokenSymbol: z.ZodString;
11
+ image: z.ZodString;
12
+ vaultPercentage: z.ZodNumber;
13
+ lockDuration_Days: z.ZodNumber;
14
+ vestingDuration_Days: z.ZodNumber;
15
+ description: z.ZodOptional<z.ZodString>;
16
+ socialMediaUrls: z.ZodOptional<z.ZodArray<z.ZodObject<{
17
+ platform: z.ZodString;
18
+ url: z.ZodString;
19
+ }, "strip", z.ZodTypeAny, {
20
+ url: string;
21
+ platform: string;
22
+ }, {
23
+ url: string;
24
+ platform: string;
25
+ }>, "many">>;
26
+ interface: z.ZodDefault<z.ZodString>;
27
+ id: z.ZodDefault<z.ZodString>;
28
+ }, "strip", z.ZodTypeAny, {
29
+ id: string;
30
+ tokenSymbol: string;
31
+ image: string;
32
+ tokenName: string;
33
+ vaultPercentage: number;
34
+ lockDuration_Days: number;
35
+ vestingDuration_Days: number;
36
+ interface: string;
37
+ description?: string | undefined;
38
+ socialMediaUrls?: {
39
+ url: string;
40
+ platform: string;
41
+ }[] | undefined;
42
+ }, {
43
+ tokenSymbol: string;
44
+ image: string;
45
+ tokenName: string;
46
+ vaultPercentage: number;
47
+ lockDuration_Days: number;
48
+ vestingDuration_Days: number;
49
+ id?: string | undefined;
50
+ description?: string | undefined;
51
+ socialMediaUrls?: {
52
+ url: string;
53
+ platform: string;
54
+ }[] | undefined;
55
+ interface?: string | undefined;
56
+ }>;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClankTokenSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ /**
6
+ * Action schemas for the clanker action provider.
7
+ *
8
+ * This file contains the Zod schemas that define the shape and validation
9
+ * rules for action parameters in the clanker action provider.
10
+ */
11
+ exports.ClankTokenSchema = zod_1.z
12
+ .object({
13
+ tokenName: zod_1.z.string().min(1).max(100).describe("The name of the token (max 100 characters)"),
14
+ tokenSymbol: zod_1.z.string().min(1).max(10).describe("The symbol of the token (max 10 characters)"),
15
+ image: zod_1.z.string().url().describe("Normal or ipfs URL pointing to the token image"),
16
+ vaultPercentage: zod_1.z
17
+ .number()
18
+ .min(0)
19
+ .max(90)
20
+ .describe("Percentage of token supply allocated to a vault that can be claimed by deployer after lockup period with optional vesting"),
21
+ lockDuration_Days: zod_1.z
22
+ .number()
23
+ .min(7)
24
+ .describe("Lockup duration of token (in days), minimum 7 days"),
25
+ vestingDuration_Days: zod_1.z
26
+ .number()
27
+ .min(0)
28
+ .describe("Vesting duration of token after lockup has passed (in days). Vesting is linear over the duration"),
29
+ description: zod_1.z
30
+ .string()
31
+ .optional()
32
+ .describe("Description of the token or token project (optional)"),
33
+ socialMediaUrls: zod_1.z
34
+ .array(zod_1.z.object({ platform: zod_1.z.string(), url: zod_1.z.string() }))
35
+ .optional()
36
+ .describe("Socials for the token. These may be displayed on aggregators."),
37
+ interface: zod_1.z
38
+ .string()
39
+ .default("CDP AgentKit")
40
+ .describe('System the token was deployed via. Defaults to "CDP AgentKit".'),
41
+ id: zod_1.z
42
+ .string()
43
+ .default("")
44
+ .describe("User id of the poster on the social platform the token was deployed from. Used for provenance and will be verified by aggregators."),
45
+ })
46
+ .strip()
47
+ .describe("Instructions for deploying a Clanker token");