@coinbase/agentkit 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 (148) hide show
  1. package/README.md +305 -0
  2. package/dist/action-providers/actionDecorator.d.ts +69 -0
  3. package/dist/action-providers/actionDecorator.js +96 -0
  4. package/dist/action-providers/actionProvider.d.ts +48 -0
  5. package/dist/action-providers/actionProvider.js +62 -0
  6. package/dist/action-providers/basename/basenameActionProvider.d.ts +30 -0
  7. package/dist/action-providers/basename/basenameActionProvider.js +109 -0
  8. package/dist/action-providers/basename/basenameActionProvider.test.d.ts +1 -0
  9. package/dist/action-providers/basename/basenameActionProvider.test.js +146 -0
  10. package/dist/action-providers/basename/constants.d.ts +52 -0
  11. package/dist/action-providers/basename/constants.js +81 -0
  12. package/dist/action-providers/basename/index.d.ts +2 -0
  13. package/dist/action-providers/basename/index.js +18 -0
  14. package/dist/action-providers/basename/schemas.d.ts +14 -0
  15. package/dist/action-providers/basename/schemas.js +14 -0
  16. package/dist/action-providers/cdp/cdpApiActionProvider.d.ts +41 -0
  17. package/dist/action-providers/cdp/cdpApiActionProvider.js +111 -0
  18. package/dist/action-providers/cdp/cdpApiActionProvider.test.d.ts +1 -0
  19. package/dist/action-providers/cdp/cdpApiActionProvider.test.js +134 -0
  20. package/dist/action-providers/cdp/cdpWalletActionProvider.d.ts +58 -0
  21. package/dist/action-providers/cdp/cdpWalletActionProvider.js +218 -0
  22. package/dist/action-providers/cdp/cdpWalletActionProvider.test.d.ts +1 -0
  23. package/dist/action-providers/cdp/cdpWalletActionProvider.test.js +259 -0
  24. package/dist/action-providers/cdp/constants.d.ts +31 -0
  25. package/dist/action-providers/cdp/constants.js +34 -0
  26. package/dist/action-providers/cdp/index.d.ts +3 -0
  27. package/dist/action-providers/cdp/index.js +19 -0
  28. package/dist/action-providers/cdp/schemas.d.ts +91 -0
  29. package/dist/action-providers/cdp/schemas.js +77 -0
  30. package/dist/action-providers/customActionProvider.d.ts +30 -0
  31. package/dist/action-providers/customActionProvider.js +66 -0
  32. package/dist/action-providers/erc20/constants.d.ts +135 -0
  33. package/dist/action-providers/erc20/constants.js +191 -0
  34. package/dist/action-providers/erc20/erc20ActionProvider.d.ts +38 -0
  35. package/dist/action-providers/erc20/erc20ActionProvider.js +118 -0
  36. package/dist/action-providers/erc20/erc20ActionProvider.test.d.ts +1 -0
  37. package/dist/action-providers/erc20/erc20ActionProvider.test.js +117 -0
  38. package/dist/action-providers/erc20/index.d.ts +1 -0
  39. package/dist/action-providers/erc20/index.js +17 -0
  40. package/dist/action-providers/erc20/schemas.d.ts +27 -0
  41. package/dist/action-providers/erc20/schemas.js +26 -0
  42. package/dist/action-providers/erc721/constants.d.ts +236 -0
  43. package/dist/action-providers/erc721/constants.js +301 -0
  44. package/dist/action-providers/erc721/erc721ActionProvider.d.ts +46 -0
  45. package/dist/action-providers/erc721/erc721ActionProvider.js +164 -0
  46. package/dist/action-providers/erc721/erc721ActionProvider.test.d.ts +1 -0
  47. package/dist/action-providers/erc721/erc721ActionProvider.test.js +137 -0
  48. package/dist/action-providers/erc721/index.d.ts +1 -0
  49. package/dist/action-providers/erc721/index.js +17 -0
  50. package/dist/action-providers/erc721/schemas.d.ts +46 -0
  51. package/dist/action-providers/erc721/schemas.js +44 -0
  52. package/dist/action-providers/farcaster/farcasterActionProvider.d.ts +57 -0
  53. package/dist/action-providers/farcaster/farcasterActionProvider.js +142 -0
  54. package/dist/action-providers/farcaster/farcasterActionProvider.test.d.ts +1 -0
  55. package/dist/action-providers/farcaster/farcasterActionProvider.test.js +143 -0
  56. package/dist/action-providers/farcaster/index.d.ts +2 -0
  57. package/dist/action-providers/farcaster/index.js +18 -0
  58. package/dist/action-providers/farcaster/schemas.d.ts +15 -0
  59. package/dist/action-providers/farcaster/schemas.js +20 -0
  60. package/dist/action-providers/index.d.ts +13 -0
  61. package/dist/action-providers/index.js +29 -0
  62. package/dist/action-providers/morpho/constants.d.ts +16 -0
  63. package/dist/action-providers/morpho/constants.js +27 -0
  64. package/dist/action-providers/morpho/index.d.ts +2 -0
  65. package/dist/action-providers/morpho/index.js +18 -0
  66. package/dist/action-providers/morpho/morphoActionProvider.d.ts +39 -0
  67. package/dist/action-providers/morpho/morphoActionProvider.js +147 -0
  68. package/dist/action-providers/morpho/morphoActionProvider.test.d.ts +1 -0
  69. package/dist/action-providers/morpho/morphoActionProvider.test.js +126 -0
  70. package/dist/action-providers/morpho/schemas.d.ts +36 -0
  71. package/dist/action-providers/morpho/schemas.js +47 -0
  72. package/dist/action-providers/pyth/index.d.ts +2 -0
  73. package/dist/action-providers/pyth/index.js +18 -0
  74. package/dist/action-providers/pyth/pythActionProvider.d.ts +33 -0
  75. package/dist/action-providers/pyth/pythActionProvider.js +121 -0
  76. package/dist/action-providers/pyth/schemas.d.ts +21 -0
  77. package/dist/action-providers/pyth/schemas.js +20 -0
  78. package/dist/action-providers/twitter/index.d.ts +2 -0
  79. package/dist/action-providers/twitter/index.js +18 -0
  80. package/dist/action-providers/twitter/schemas.d.ts +38 -0
  81. package/dist/action-providers/twitter/schemas.js +44 -0
  82. package/dist/action-providers/twitter/twitterActionProvider.d.ts +82 -0
  83. package/dist/action-providers/twitter/twitterActionProvider.js +204 -0
  84. package/dist/action-providers/twitter/twitterActionProvider.test.d.ts +1 -0
  85. package/dist/action-providers/twitter/twitterActionProvider.test.js +185 -0
  86. package/dist/action-providers/wallet/index.d.ts +1 -0
  87. package/dist/action-providers/wallet/index.js +17 -0
  88. package/dist/action-providers/wallet/schemas.d.ts +19 -0
  89. package/dist/action-providers/wallet/schemas.js +19 -0
  90. package/dist/action-providers/wallet/walletActionProvider.d.ts +44 -0
  91. package/dist/action-providers/wallet/walletActionProvider.js +127 -0
  92. package/dist/action-providers/wallet/walletActionProvider.test.d.ts +1 -0
  93. package/dist/action-providers/wallet/walletActionProvider.test.js +116 -0
  94. package/dist/action-providers/weth/constants.d.ts +19 -0
  95. package/dist/action-providers/weth/constants.js +29 -0
  96. package/dist/action-providers/weth/index.d.ts +1 -0
  97. package/dist/action-providers/weth/index.js +17 -0
  98. package/dist/action-providers/weth/schemas.d.ts +8 -0
  99. package/dist/action-providers/weth/schemas.js +10 -0
  100. package/dist/action-providers/weth/wethActionProvider.d.ts +30 -0
  101. package/dist/action-providers/weth/wethActionProvider.js +89 -0
  102. package/dist/action-providers/weth/wethActionProvider.test.d.ts +1 -0
  103. package/dist/action-providers/weth/wethActionProvider.test.js +92 -0
  104. package/dist/action-providers/wow/constants.d.ts +15 -0
  105. package/dist/action-providers/wow/constants.js +844 -0
  106. package/dist/action-providers/wow/index.d.ts +2 -0
  107. package/dist/action-providers/wow/index.js +18 -0
  108. package/dist/action-providers/wow/schemas.d.ts +43 -0
  109. package/dist/action-providers/wow/schemas.js +47 -0
  110. package/dist/action-providers/wow/uniswap/constants.d.ts +3 -0
  111. package/dist/action-providers/wow/uniswap/constants.js +100 -0
  112. package/dist/action-providers/wow/uniswap/utils.d.ts +82 -0
  113. package/dist/action-providers/wow/uniswap/utils.js +226 -0
  114. package/dist/action-providers/wow/utils.d.ts +27 -0
  115. package/dist/action-providers/wow/utils.js +63 -0
  116. package/dist/action-providers/wow/wowActionProvider.d.ts +46 -0
  117. package/dist/action-providers/wow/wowActionProvider.js +223 -0
  118. package/dist/action-providers/wow/wowActionProvider.test.d.ts +1 -0
  119. package/dist/action-providers/wow/wowActionProvider.test.js +287 -0
  120. package/dist/agentkit.d.ts +45 -0
  121. package/dist/agentkit.js +60 -0
  122. package/dist/analytics/index.d.ts +1 -0
  123. package/dist/analytics/index.js +17 -0
  124. package/dist/analytics/sendAnalyticsEvent.d.ts +31 -0
  125. package/dist/analytics/sendAnalyticsEvent.js +51 -0
  126. package/dist/index.d.ts +3 -0
  127. package/dist/index.js +22 -0
  128. package/dist/network/index.d.ts +1 -0
  129. package/dist/network/index.js +17 -0
  130. package/dist/network/network.d.ts +13 -0
  131. package/dist/network/network.js +41 -0
  132. package/dist/network/types.d.ts +17 -0
  133. package/dist/network/types.js +2 -0
  134. package/dist/utils.d.ts +11 -0
  135. package/dist/utils.js +43 -0
  136. package/dist/utils.test.d.ts +1 -0
  137. package/dist/utils.test.js +50 -0
  138. package/dist/wallet-providers/cdpWalletProvider.d.ts +218 -0
  139. package/dist/wallet-providers/cdpWalletProvider.js +362 -0
  140. package/dist/wallet-providers/evmWalletProvider.d.ts +51 -0
  141. package/dist/wallet-providers/evmWalletProvider.js +14 -0
  142. package/dist/wallet-providers/index.d.ts +4 -0
  143. package/dist/wallet-providers/index.js +20 -0
  144. package/dist/wallet-providers/viemWalletProvider.d.ts +89 -0
  145. package/dist/wallet-providers/viemWalletProvider.js +187 -0
  146. package/dist/wallet-providers/walletProvider.d.ts +48 -0
  147. package/dist/wallet-providers/walletProvider.js +41 -0
  148. package/package.json +65 -0
@@ -0,0 +1,147 @@
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.morphoActionProvider = exports.MorphoActionProvider = exports.SUPPORTED_NETWORKS = void 0;
13
+ const zod_1 = require("zod");
14
+ const decimal_js_1 = require("decimal.js");
15
+ const viem_1 = require("viem");
16
+ const actionProvider_1 = require("../actionProvider");
17
+ const wallet_providers_1 = require("../../wallet-providers");
18
+ const actionDecorator_1 = require("../actionDecorator");
19
+ const utils_1 = require("../../utils");
20
+ const constants_1 = require("./constants");
21
+ const schemas_1 = require("./schemas");
22
+ exports.SUPPORTED_NETWORKS = ["base-mainnet", "base-sepolia"];
23
+ /**
24
+ * MorphoActionProvider is an action provider for Morpho Vault interactions.
25
+ */
26
+ class MorphoActionProvider extends actionProvider_1.ActionProvider {
27
+ /**
28
+ * Constructor for the MorphoActionProvider class.
29
+ */
30
+ constructor() {
31
+ super("morpho", []);
32
+ /**
33
+ * Checks if the Morpho action provider supports the given network.
34
+ *
35
+ * @param network - The network to check.
36
+ * @returns True if the Morpho action provider supports the network, false otherwise.
37
+ */
38
+ this.supportsNetwork = (network) => network.protocolFamily === "evm" && exports.SUPPORTED_NETWORKS.includes(network.networkId);
39
+ }
40
+ /**
41
+ * Deposits assets into a Morpho Vault
42
+ *
43
+ * @param wallet - The wallet instance to execute the transaction
44
+ * @param args - The input arguments for the action
45
+ * @returns A success message with transaction details or an error message
46
+ */
47
+ async deposit(wallet, args) {
48
+ const assets = new decimal_js_1.Decimal(args.assets);
49
+ if (assets.comparedTo(new decimal_js_1.Decimal(0.0)) != 1) {
50
+ return "Error: Assets amount must be greater than 0";
51
+ }
52
+ try {
53
+ const atomicAssets = (0, viem_1.parseEther)(args.assets);
54
+ const approvalResult = await (0, utils_1.approve)(wallet, args.tokenAddress, args.vaultAddress, atomicAssets);
55
+ if (approvalResult.startsWith("Error")) {
56
+ return `Error approving Morpho Vault as spender: ${approvalResult}`;
57
+ }
58
+ const data = (0, viem_1.encodeFunctionData)({
59
+ abi: constants_1.METAMORPHO_ABI,
60
+ functionName: "deposit",
61
+ args: [atomicAssets, args.receiver],
62
+ });
63
+ const txHash = await wallet.sendTransaction({
64
+ to: args.vaultAddress,
65
+ data,
66
+ });
67
+ const receipt = await wallet.waitForTransactionReceipt(txHash);
68
+ return `Deposited ${args.assets} to Morpho Vault ${args.vaultAddress} with transaction hash: ${txHash}\nTransaction receipt: ${JSON.stringify(receipt)}`;
69
+ }
70
+ catch (error) {
71
+ return `Error depositing to Morpho Vault: ${error}`;
72
+ }
73
+ }
74
+ /**
75
+ * Withdraws assets from a Morpho Vault
76
+ *
77
+ * @param wallet - The wallet instance to execute the transaction
78
+ * @param args - The input arguments for the action
79
+ * @returns A success message with transaction details or an error message
80
+ */
81
+ async withdraw(wallet, args) {
82
+ if (BigInt(args.assets) <= 0) {
83
+ return "Error: Assets amount must be greater than 0";
84
+ }
85
+ try {
86
+ const data = (0, viem_1.encodeFunctionData)({
87
+ abi: constants_1.METAMORPHO_ABI,
88
+ functionName: "withdraw",
89
+ args: [BigInt(args.assets), args.receiver, args.receiver],
90
+ });
91
+ const txHash = await wallet.sendTransaction({
92
+ to: args.vaultAddress,
93
+ data,
94
+ });
95
+ const receipt = await wallet.waitForTransactionReceipt(txHash);
96
+ return `Withdrawn ${args.assets} from Morpho Vault ${args.vaultAddress} with transaction hash: ${txHash}\nTransaction receipt: ${JSON.stringify(receipt)}`;
97
+ }
98
+ catch (error) {
99
+ return `Error withdrawing from Morpho Vault: ${error}`;
100
+ }
101
+ }
102
+ }
103
+ exports.MorphoActionProvider = MorphoActionProvider;
104
+ __decorate([
105
+ (0, actionDecorator_1.CreateAction)({
106
+ name: "deposit",
107
+ description: `
108
+ This tool allows depositing assets into a Morpho Vault.
109
+
110
+ It takes:
111
+ - vaultAddress: The address of the Morpho Vault to deposit to
112
+ - assets: The amount of assets to deposit in whole units
113
+ Examples for WETH:
114
+ - 1 WETH
115
+ - 0.1 WETH
116
+ - 0.01 WETH
117
+ - receiver: The address to receive the shares
118
+ - tokenAddress: The address of the token to approve
119
+
120
+ Important notes:
121
+ - Make sure to use the exact amount provided. Do not convert units for assets for this action.
122
+ - Please use a token address (example 0x4200000000000000000000000000000000000006) for the tokenAddress field.
123
+ `,
124
+ schema: schemas_1.DepositSchema,
125
+ }),
126
+ __metadata("design:type", Function),
127
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
128
+ __metadata("design:returntype", Promise)
129
+ ], MorphoActionProvider.prototype, "deposit", null);
130
+ __decorate([
131
+ (0, actionDecorator_1.CreateAction)({
132
+ name: "withdraw",
133
+ description: `
134
+ This tool allows withdrawing assets from a Morpho Vault. It takes:
135
+
136
+ - vaultAddress: The address of the Morpho Vault to withdraw from
137
+ - assets: The amount of assets to withdraw in atomic units (wei)
138
+ - receiver: The address to receive the shares
139
+ `,
140
+ schema: schemas_1.WithdrawSchema,
141
+ }),
142
+ __metadata("design:type", Function),
143
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
144
+ __metadata("design:returntype", Promise)
145
+ ], MorphoActionProvider.prototype, "withdraw", null);
146
+ const morphoActionProvider = () => new MorphoActionProvider();
147
+ exports.morphoActionProvider = morphoActionProvider;
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const viem_1 = require("viem");
4
+ const utils_1 = require("../../utils");
5
+ const morphoActionProvider_1 = require("./morphoActionProvider");
6
+ const constants_1 = require("./constants");
7
+ const MOCK_VAULT_ADDRESS = "0x1234567890123456789012345678901234567890";
8
+ const MOCK_ATOMIC_ASSETS = "1000000000000000000";
9
+ const MOCK_WHOLE_ASSETS = "1.0";
10
+ const MOCK_RECEIVER_ID = "0x9876543210987654321098765432109876543210";
11
+ const MOCK_TOKEN_ADDRESS = "0x4200000000000000000000000000000000000006";
12
+ const MOCK_TX_HASH = "0xabcdef1234567890";
13
+ const MOCK_RECEIPT = { status: 1, blockNumber: 1234567 };
14
+ jest.mock("../../utils");
15
+ const mockApprove = utils_1.approve;
16
+ describe("Morpho Action Provider", () => {
17
+ const actionProvider = new morphoActionProvider_1.MorphoActionProvider();
18
+ let mockWallet;
19
+ beforeEach(() => {
20
+ mockWallet = {
21
+ getAddress: jest.fn().mockReturnValue(MOCK_RECEIVER_ID),
22
+ getNetwork: jest.fn().mockReturnValue({ protocolFamily: "evm", networkId: "1" }),
23
+ sendTransaction: jest.fn().mockResolvedValue(MOCK_TX_HASH),
24
+ waitForTransactionReceipt: jest.fn().mockResolvedValue(MOCK_RECEIPT),
25
+ };
26
+ mockApprove.mockResolvedValue("Approval successful");
27
+ });
28
+ describe("deposit", () => {
29
+ it("should successfully deposit to Morpho vault", async () => {
30
+ const args = {
31
+ vaultAddress: MOCK_VAULT_ADDRESS,
32
+ assets: MOCK_WHOLE_ASSETS,
33
+ receiver: MOCK_RECEIVER_ID,
34
+ tokenAddress: MOCK_TOKEN_ADDRESS,
35
+ };
36
+ const atomicAssets = (0, viem_1.parseEther)(MOCK_WHOLE_ASSETS);
37
+ const response = await actionProvider.deposit(mockWallet, args);
38
+ expect(mockApprove).toHaveBeenCalledWith(mockWallet, MOCK_TOKEN_ADDRESS, MOCK_VAULT_ADDRESS, atomicAssets);
39
+ expect(mockWallet.sendTransaction).toHaveBeenCalledWith({
40
+ to: MOCK_VAULT_ADDRESS,
41
+ data: (0, viem_1.encodeFunctionData)({
42
+ abi: constants_1.METAMORPHO_ABI,
43
+ functionName: "deposit",
44
+ args: [atomicAssets, MOCK_RECEIVER_ID],
45
+ }),
46
+ });
47
+ expect(mockWallet.waitForTransactionReceipt).toHaveBeenCalledWith(MOCK_TX_HASH);
48
+ expect(response).toContain(`Deposited ${MOCK_WHOLE_ASSETS}`);
49
+ expect(response).toContain(MOCK_TX_HASH);
50
+ expect(response).toContain(JSON.stringify(MOCK_RECEIPT));
51
+ });
52
+ it("should handle errors when depositing", async () => {
53
+ const args = {
54
+ vaultAddress: MOCK_VAULT_ADDRESS,
55
+ assets: MOCK_WHOLE_ASSETS,
56
+ receiver: MOCK_RECEIVER_ID,
57
+ tokenAddress: MOCK_TOKEN_ADDRESS,
58
+ };
59
+ mockWallet.sendTransaction.mockRejectedValue(new Error("Failed to deposit"));
60
+ const response = await actionProvider.deposit(mockWallet, args);
61
+ expect(response).toContain("Error depositing to Morpho Vault: Error: Failed to deposit");
62
+ });
63
+ });
64
+ describe("withdraw", () => {
65
+ it("should successfully withdraw from Morpho vault", async () => {
66
+ const args = {
67
+ vaultAddress: MOCK_VAULT_ADDRESS,
68
+ assets: MOCK_ATOMIC_ASSETS,
69
+ receiver: MOCK_RECEIVER_ID,
70
+ };
71
+ const response = await actionProvider.withdraw(mockWallet, args);
72
+ expect(mockWallet.sendTransaction).toHaveBeenCalledWith({
73
+ to: MOCK_VAULT_ADDRESS,
74
+ data: (0, viem_1.encodeFunctionData)({
75
+ abi: constants_1.METAMORPHO_ABI,
76
+ functionName: "withdraw",
77
+ args: [BigInt(MOCK_ATOMIC_ASSETS), MOCK_RECEIVER_ID, MOCK_RECEIVER_ID],
78
+ }),
79
+ });
80
+ expect(mockWallet.waitForTransactionReceipt).toHaveBeenCalledWith(MOCK_TX_HASH);
81
+ expect(response).toContain(`Withdrawn ${MOCK_ATOMIC_ASSETS}`);
82
+ expect(response).toContain(MOCK_TX_HASH);
83
+ expect(response).toContain(JSON.stringify(MOCK_RECEIPT));
84
+ });
85
+ it("should handle errors when withdrawing", async () => {
86
+ const args = {
87
+ vaultAddress: MOCK_VAULT_ADDRESS,
88
+ assets: MOCK_ATOMIC_ASSETS,
89
+ receiver: MOCK_RECEIVER_ID,
90
+ };
91
+ mockWallet.sendTransaction.mockRejectedValue(new Error("Failed to withdraw"));
92
+ const response = await actionProvider.withdraw(mockWallet, args);
93
+ expect(response).toContain("Error withdrawing from Morpho Vault: Error: Failed to withdraw");
94
+ });
95
+ });
96
+ describe("supportsNetwork", () => {
97
+ it("should return true for Base Mainnet", () => {
98
+ const result = actionProvider.supportsNetwork({
99
+ protocolFamily: "evm",
100
+ networkId: "base-mainnet",
101
+ });
102
+ expect(result).toBe(true);
103
+ });
104
+ it("should return true for Base Sepolia", () => {
105
+ const result = actionProvider.supportsNetwork({
106
+ protocolFamily: "evm",
107
+ networkId: "base-sepolia",
108
+ });
109
+ expect(result).toBe(true);
110
+ });
111
+ it("should return false for other EVM networks", () => {
112
+ const result = actionProvider.supportsNetwork({
113
+ protocolFamily: "evm",
114
+ networkId: "ethereum",
115
+ });
116
+ expect(result).toBe(false);
117
+ });
118
+ it("should return false for non-EVM networks", () => {
119
+ const result = actionProvider.supportsNetwork({
120
+ protocolFamily: "bitcoin",
121
+ networkId: "base-mainnet",
122
+ });
123
+ expect(result).toBe(false);
124
+ });
125
+ });
126
+ });
@@ -0,0 +1,36 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Input schema for Morpho Vault deposit action.
4
+ */
5
+ export declare const DepositSchema: z.ZodObject<{
6
+ assets: z.ZodString;
7
+ receiver: z.ZodString;
8
+ tokenAddress: z.ZodString;
9
+ vaultAddress: z.ZodString;
10
+ }, "strip", z.ZodTypeAny, {
11
+ assets: string;
12
+ receiver: string;
13
+ tokenAddress: string;
14
+ vaultAddress: string;
15
+ }, {
16
+ assets: string;
17
+ receiver: string;
18
+ tokenAddress: string;
19
+ vaultAddress: string;
20
+ }>;
21
+ /**
22
+ * Input schema for Morpho Vault withdraw action.
23
+ */
24
+ export declare const WithdrawSchema: z.ZodObject<{
25
+ vaultAddress: z.ZodString;
26
+ assets: z.ZodString;
27
+ receiver: z.ZodString;
28
+ }, "strip", z.ZodTypeAny, {
29
+ assets: string;
30
+ receiver: string;
31
+ vaultAddress: string;
32
+ }, {
33
+ assets: string;
34
+ receiver: string;
35
+ vaultAddress: string;
36
+ }>;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WithdrawSchema = exports.DepositSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ /**
6
+ * Input schema for Morpho Vault deposit action.
7
+ */
8
+ exports.DepositSchema = zod_1.z
9
+ .object({
10
+ assets: zod_1.z
11
+ .string()
12
+ .regex(/^\d+(\.\d+)?$/, "Must be a valid integer or decimal value")
13
+ .describe("The quantity of assets to deposit, in whole units"),
14
+ receiver: zod_1.z
15
+ .string()
16
+ .regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
17
+ .describe("The address that will own the position on the vault which will receive the shares"),
18
+ tokenAddress: zod_1.z
19
+ .string()
20
+ .regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
21
+ .describe("The address of the assets token to approve for deposit"),
22
+ vaultAddress: zod_1.z
23
+ .string()
24
+ .regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
25
+ .describe("The address of the Morpho Vault to deposit to"),
26
+ })
27
+ .describe("Input schema for Morpho Vault deposit action");
28
+ /**
29
+ * Input schema for Morpho Vault withdraw action.
30
+ */
31
+ exports.WithdrawSchema = zod_1.z
32
+ .object({
33
+ vaultAddress: zod_1.z
34
+ .string()
35
+ .regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
36
+ .describe("The address of the Morpho Vault to withdraw from"),
37
+ assets: zod_1.z
38
+ .string()
39
+ .regex(/^\d+$/, "Must be a valid whole number")
40
+ .describe("The amount of assets to withdraw in atomic units e.g. 1"),
41
+ receiver: zod_1.z
42
+ .string()
43
+ .regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
44
+ .describe("The address to receive the shares"),
45
+ })
46
+ .strip()
47
+ .describe("Input schema for Morpho Vault withdraw action");
@@ -0,0 +1,2 @@
1
+ export * from "./pythActionProvider";
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("./pythActionProvider"), exports);
18
+ __exportStar(require("./schemas"), exports);
@@ -0,0 +1,33 @@
1
+ import { z } from "zod";
2
+ import { ActionProvider } from "../actionProvider";
3
+ import { PythFetchPriceFeedIDSchema, PythFetchPriceSchema } from "./schemas";
4
+ /**
5
+ * PythActionProvider is an action provider for Pyth.
6
+ */
7
+ export declare class PythActionProvider extends ActionProvider {
8
+ /**
9
+ * Constructs a new PythActionProvider.
10
+ */
11
+ constructor();
12
+ /**
13
+ * Fetch the price feed ID for a given token symbol from Pyth.
14
+ *
15
+ * @param args - The arguments for the action.
16
+ * @returns The price feed ID as a string.
17
+ */
18
+ fetchPriceFeed(args: z.infer<typeof PythFetchPriceFeedIDSchema>): Promise<string>;
19
+ /**
20
+ * Fetches the price from Pyth given a Pyth price feed ID.
21
+ *
22
+ * @param args - The arguments for the action.
23
+ * @returns The price as a string.
24
+ */
25
+ fetchPrice(args: z.infer<typeof PythFetchPriceSchema>): Promise<string>;
26
+ /**
27
+ * Checks if the Pyth action provider supports the given network.
28
+ *
29
+ * @returns True if the Pyth action provider supports the network, false otherwise.
30
+ */
31
+ supportsNetwork: () => boolean;
32
+ }
33
+ export declare const pythActionProvider: () => PythActionProvider;
@@ -0,0 +1,121 @@
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.pythActionProvider = exports.PythActionProvider = void 0;
13
+ const zod_1 = require("zod");
14
+ const actionProvider_1 = require("../actionProvider");
15
+ const actionDecorator_1 = require("../actionDecorator");
16
+ const schemas_1 = require("./schemas");
17
+ /**
18
+ * PythActionProvider is an action provider for Pyth.
19
+ */
20
+ class PythActionProvider extends actionProvider_1.ActionProvider {
21
+ /**
22
+ * Constructs a new PythActionProvider.
23
+ */
24
+ constructor() {
25
+ super("pyth", []);
26
+ /**
27
+ * Checks if the Pyth action provider supports the given network.
28
+ *
29
+ * @returns True if the Pyth action provider supports the network, false otherwise.
30
+ */
31
+ this.supportsNetwork = () => true;
32
+ }
33
+ /**
34
+ * Fetch the price feed ID for a given token symbol from Pyth.
35
+ *
36
+ * @param args - The arguments for the action.
37
+ * @returns The price feed ID as a string.
38
+ */
39
+ async fetchPriceFeed(args) {
40
+ const url = `https://hermes.pyth.network/v2/price_feeds?query=${args.tokenSymbol}&asset_type=crypto`;
41
+ const response = await fetch(url);
42
+ if (!response.ok) {
43
+ throw new Error(`HTTP error! status: ${response.status}`);
44
+ }
45
+ const data = await response.json();
46
+ if (data.length === 0) {
47
+ throw new Error(`No price feed found for ${args.tokenSymbol}`);
48
+ }
49
+ const filteredData = data.filter(
50
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
+ (item) => item.attributes.base.toLowerCase() === args.tokenSymbol.toLowerCase());
52
+ if (filteredData.length === 0) {
53
+ throw new Error(`No price feed found for ${args.tokenSymbol}`);
54
+ }
55
+ return filteredData[0].id;
56
+ }
57
+ /**
58
+ * Fetches the price from Pyth given a Pyth price feed ID.
59
+ *
60
+ * @param args - The arguments for the action.
61
+ * @returns The price as a string.
62
+ */
63
+ async fetchPrice(args) {
64
+ const url = `https://hermes.pyth.network/v2/updates/price/latest?ids[]=${args.priceFeedID}`;
65
+ const response = await fetch(url);
66
+ if (!response.ok) {
67
+ throw new Error(`HTTP error! status: ${response.status}`);
68
+ }
69
+ const data = await response.json();
70
+ const parsedData = data.parsed;
71
+ if (parsedData.length === 0) {
72
+ throw new Error(`No price data found for ${args.priceFeedID}`);
73
+ }
74
+ const priceInfo = parsedData[0].price;
75
+ const price = BigInt(priceInfo.price);
76
+ const exponent = priceInfo.expo;
77
+ if (exponent < 0) {
78
+ const adjustedPrice = price * BigInt(100);
79
+ const divisor = BigInt(10) ** BigInt(-exponent);
80
+ const scaledPrice = adjustedPrice / BigInt(divisor);
81
+ const priceStr = scaledPrice.toString();
82
+ const formattedPrice = `${priceStr.slice(0, -2)}.${priceStr.slice(-2)}`;
83
+ return formattedPrice.startsWith(".") ? `0${formattedPrice}` : formattedPrice;
84
+ }
85
+ const scaledPrice = price / BigInt(10) ** BigInt(exponent);
86
+ return scaledPrice.toString();
87
+ }
88
+ }
89
+ exports.PythActionProvider = PythActionProvider;
90
+ __decorate([
91
+ (0, actionDecorator_1.CreateAction)({
92
+ name: "fetch_price_feed",
93
+ description: "Fetch the price feed ID for a given token symbol from Pyth.",
94
+ schema: schemas_1.PythFetchPriceFeedIDSchema,
95
+ }),
96
+ __metadata("design:type", Function),
97
+ __metadata("design:paramtypes", [void 0]),
98
+ __metadata("design:returntype", Promise)
99
+ ], PythActionProvider.prototype, "fetchPriceFeed", null);
100
+ __decorate([
101
+ (0, actionDecorator_1.CreateAction)({
102
+ name: "fetch_price",
103
+ description: `Fetch the price of a given price feed from Pyth.
104
+
105
+ Inputs:
106
+ - Pyth price feed ID
107
+
108
+ Important notes:
109
+ - Do not assume that a random ID is a Pyth price feed ID. If you are confused, ask a clarifying question.
110
+ - This action only fetches price inputs from Pyth price feeds. No other source.
111
+ - If you are asked to fetch the price from Pyth for a ticker symbol such as BTC, you must first use the pyth_fetch_price_feed_id
112
+ action to retrieve the price feed ID before invoking the pyth_Fetch_price action
113
+ `,
114
+ schema: schemas_1.PythFetchPriceSchema,
115
+ }),
116
+ __metadata("design:type", Function),
117
+ __metadata("design:paramtypes", [void 0]),
118
+ __metadata("design:returntype", Promise)
119
+ ], PythActionProvider.prototype, "fetchPrice", null);
120
+ const pythActionProvider = () => new PythActionProvider();
121
+ exports.pythActionProvider = pythActionProvider;
@@ -0,0 +1,21 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Input schema for Pyth fetch price feed ID action.
4
+ */
5
+ export declare const PythFetchPriceFeedIDSchema: z.ZodObject<{
6
+ tokenSymbol: z.ZodString;
7
+ }, "strict", z.ZodTypeAny, {
8
+ tokenSymbol: string;
9
+ }, {
10
+ tokenSymbol: string;
11
+ }>;
12
+ /**
13
+ * Input schema for Pyth fetch price action.
14
+ */
15
+ export declare const PythFetchPriceSchema: z.ZodObject<{
16
+ priceFeedID: z.ZodString;
17
+ }, "strict", z.ZodTypeAny, {
18
+ priceFeedID: string;
19
+ }, {
20
+ priceFeedID: string;
21
+ }>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PythFetchPriceSchema = exports.PythFetchPriceFeedIDSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ /**
6
+ * Input schema for Pyth fetch price feed ID action.
7
+ */
8
+ exports.PythFetchPriceFeedIDSchema = zod_1.z
9
+ .object({
10
+ tokenSymbol: zod_1.z.string().describe("The token symbol to fetch the price feed ID for"),
11
+ })
12
+ .strict();
13
+ /**
14
+ * Input schema for Pyth fetch price action.
15
+ */
16
+ exports.PythFetchPriceSchema = zod_1.z
17
+ .object({
18
+ priceFeedID: zod_1.z.string().describe("The price feed ID to fetch the price for"),
19
+ })
20
+ .strict();
@@ -0,0 +1,2 @@
1
+ export * from "./schemas";
2
+ export * from "./twitterActionProvider";
@@ -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("./schemas"), exports);
18
+ __exportStar(require("./twitterActionProvider"), exports);
@@ -0,0 +1,38 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Input schema for retrieving account details.
4
+ */
5
+ export declare const TwitterAccountDetailsSchema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
6
+ /**
7
+ * Input schema for retrieving account mentions.
8
+ */
9
+ export declare const TwitterAccountMentionsSchema: z.ZodObject<{
10
+ userId: z.ZodString;
11
+ }, "strip", z.ZodTypeAny, {
12
+ userId: string;
13
+ }, {
14
+ userId: string;
15
+ }>;
16
+ /**
17
+ * Input schema for posting a tweet.
18
+ */
19
+ export declare const TwitterPostTweetSchema: z.ZodObject<{
20
+ tweet: z.ZodString;
21
+ }, "strip", z.ZodTypeAny, {
22
+ tweet: string;
23
+ }, {
24
+ tweet: string;
25
+ }>;
26
+ /**
27
+ * Input schema for posting a tweet reply.
28
+ */
29
+ export declare const TwitterPostTweetReplySchema: z.ZodObject<{
30
+ tweetId: z.ZodString;
31
+ tweetReply: z.ZodString;
32
+ }, "strip", z.ZodTypeAny, {
33
+ tweetId: string;
34
+ tweetReply: string;
35
+ }, {
36
+ tweetId: string;
37
+ tweetReply: string;
38
+ }>;