@coinbase/agentkit 0.1.0 → 0.1.2
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 +27 -7
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.d.ts +55 -0
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.js +173 -0
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.test.d.ts +1 -0
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.test.js +131 -0
- package/dist/action-providers/alchemy/index.d.ts +2 -0
- package/dist/action-providers/alchemy/index.js +18 -0
- package/dist/action-providers/alchemy/schemas.d.ts +41 -0
- package/dist/action-providers/alchemy/schemas.js +34 -0
- package/dist/action-providers/basename/basenameActionProvider.d.ts +1 -1
- package/dist/action-providers/cdp/cdpApiActionProvider.js +7 -1
- package/dist/action-providers/erc20/erc20ActionProvider.d.ts +1 -1
- package/dist/action-providers/erc721/erc721ActionProvider.d.ts +1 -1
- package/dist/action-providers/index.d.ts +2 -0
- package/dist/action-providers/index.js +2 -0
- package/dist/action-providers/moonwell/constants.d.ts +78 -0
- package/dist/action-providers/moonwell/constants.js +111 -0
- package/dist/action-providers/moonwell/index.d.ts +1 -0
- package/dist/action-providers/moonwell/index.js +5 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.d.ts +39 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.js +249 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.test.d.ts +1 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.test.js +455 -0
- package/dist/action-providers/moonwell/schemas.d.ts +30 -0
- package/dist/action-providers/moonwell/schemas.js +39 -0
- package/dist/action-providers/morpho/morphoActionProvider.d.ts +1 -1
- package/dist/action-providers/pyth/pythActionProvider.test.d.ts +1 -0
- package/dist/action-providers/pyth/pythActionProvider.test.js +113 -0
- package/dist/action-providers/weth/wethActionProvider.d.ts +1 -1
- package/dist/action-providers/wow/wowActionProvider.d.ts +1 -1
- package/dist/agentkit.d.ts +1 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -4
- package/dist/network/index.d.ts +1 -0
- package/dist/network/index.js +1 -0
- package/dist/wallet-providers/cdpWalletProvider.js +17 -1
- package/dist/wallet-providers/viemWalletProvider.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,9 +8,14 @@ AgentKit is a framework for easily enabling AI agents to take actions onchain. I
|
|
|
8
8
|
- [Getting Started](#getting-started)
|
|
9
9
|
- [Installation](#installation)
|
|
10
10
|
- [Usage](#usage)
|
|
11
|
-
- [Create an AgentKit instance](
|
|
12
|
-
- [Create an AgentKit instance with a specified wallet provider](#
|
|
13
|
-
- [Create an AgentKit instance with a specified action providers](#
|
|
11
|
+
- [Create an AgentKit instance](##create-an-agentkit-instance-if-no-wallet-or-action-providers-are-specified-the-agent-will-use-the-cdpwalletprovider-and-walletprovider-action-provider)
|
|
12
|
+
- [Create an AgentKit instance with a specified wallet provider](#create-an-agentkit-instance-with-a-specified-wallet-provider)
|
|
13
|
+
- [Create an AgentKit instance with a specified action providers](#create-an-agentkit-instance-with-a-specified-action-providers)
|
|
14
|
+
- [Use the agent's actions with a framework extension. For example, using LangChain + OpenAI](#use-the-agents-actions-with-a-framework-extension-for-example-using-langchain--openai)
|
|
15
|
+
- [Creating an Action Provider](#creating-an-action-provider)
|
|
16
|
+
- [Adding Actions to your Action Provider](#adding-actions-to-your-action-provider)
|
|
17
|
+
- [Adding Actions to your Action Provider that use a Wallet Provider](#adding-actions-to-your-action-provider-that-use-a-wallet-provider)
|
|
18
|
+
- [Adding an Action Provider to your AgentKit instance](#adding-an-action-provider-to-your-agentkit-instance)
|
|
14
19
|
- [Wallet Providers](#wallet-providers)
|
|
15
20
|
- [CdpWalletProvider](#cdpwalletprovider)
|
|
16
21
|
- [Network Configuration](#network-configuration)
|
|
@@ -35,7 +40,7 @@ npm install @coinbase/agentkit
|
|
|
35
40
|
|
|
36
41
|
## Usage
|
|
37
42
|
|
|
38
|
-
|
|
43
|
+
### Create an AgentKit instance. If no wallet or action providers are specified, the agent will use the `CdpWalletProvider` and `WalletProvider` action provider.
|
|
39
44
|
|
|
40
45
|
```typescript
|
|
41
46
|
const agentKit = await AgentKit.from({
|
|
@@ -44,7 +49,7 @@ const agentKit = await AgentKit.from({
|
|
|
44
49
|
});
|
|
45
50
|
```
|
|
46
51
|
|
|
47
|
-
|
|
52
|
+
### Create an AgentKit instance with a specified wallet provider.
|
|
48
53
|
|
|
49
54
|
```typescript
|
|
50
55
|
import { CdpWalletProvider } from "@coinbase/agentkit";
|
|
@@ -60,7 +65,7 @@ const agentKit = await AgentKit.from({
|
|
|
60
65
|
});
|
|
61
66
|
```
|
|
62
67
|
|
|
63
|
-
|
|
68
|
+
### Create an AgentKit instance with a specified action providers.
|
|
64
69
|
|
|
65
70
|
```typescript
|
|
66
71
|
import { cdpApiActionProvider, pythActionProvider } from "@coinbase/agentkit";
|
|
@@ -77,7 +82,7 @@ const agentKit = await AgentKit.from({
|
|
|
77
82
|
});
|
|
78
83
|
```
|
|
79
84
|
|
|
80
|
-
|
|
85
|
+
### Use the agent's actions with a framework extension. For example, using LangChain + OpenAI.
|
|
81
86
|
|
|
82
87
|
*Prerequisites*:
|
|
83
88
|
- [OpenAI API Key](https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key)
|
|
@@ -126,6 +131,21 @@ class MyActionProvider extends ActionProvider<WalletProvider> {
|
|
|
126
131
|
|
|
127
132
|
Actions are defined as instance methods on the action provider class with the `@CreateAction` decorator. Actions can use a wallet provider or not and always return a Promise that resolves to a string.
|
|
128
133
|
|
|
134
|
+
#### Required Typescript Compiler Options
|
|
135
|
+
|
|
136
|
+
Creating actions with the `@CreateAction` decorator requires the following compilerOptions to be included in your project's `tsconfig.json`.
|
|
137
|
+
|
|
138
|
+
```json
|
|
139
|
+
{
|
|
140
|
+
"compilerOptions": {
|
|
141
|
+
"experimentalDecorators": true,
|
|
142
|
+
"emitDecoratorMetadata": true
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
#### Steps to create an action
|
|
148
|
+
|
|
129
149
|
1. Define the action schema. Action schemas are defined using the `zod` library.
|
|
130
150
|
|
|
131
151
|
```typescript
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ActionProvider } from "../actionProvider";
|
|
3
|
+
import { AlchemyTokenPricesBySymbolSchema, AlchemyTokenPricesByAddressSchema } from "./schemas";
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for the AlchemyTokenPricesActionProvider.
|
|
6
|
+
*/
|
|
7
|
+
export interface AlchemyTokenPricesActionProviderConfig {
|
|
8
|
+
/**
|
|
9
|
+
* Alchemy API Key
|
|
10
|
+
*/
|
|
11
|
+
apiKey?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* AlchemyTokenPricesActionProvider is an action provider for fetching token prices via the Alchemy Prices API.
|
|
15
|
+
* This provider enables querying current and historical token prices using symbols or addresses.
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
export declare class AlchemyTokenPricesActionProvider extends ActionProvider {
|
|
19
|
+
private readonly apiKey;
|
|
20
|
+
private readonly baseUrl;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new instance of AlchemyTokenPricesActionProvider
|
|
23
|
+
*
|
|
24
|
+
* @param config - Configuration options including the API key
|
|
25
|
+
*/
|
|
26
|
+
constructor(config?: AlchemyTokenPricesActionProviderConfig);
|
|
27
|
+
/**
|
|
28
|
+
* Fetch current token prices for one or more token symbols.
|
|
29
|
+
*
|
|
30
|
+
* @param args - The arguments containing an array of token symbols.
|
|
31
|
+
* @returns A JSON string with the token prices or an error message.
|
|
32
|
+
*/
|
|
33
|
+
tokenPricesBySymbol(args: z.infer<typeof AlchemyTokenPricesBySymbolSchema>): Promise<string>;
|
|
34
|
+
/**
|
|
35
|
+
* Fetch current token prices for one or more tokens identified by network and address pairs.
|
|
36
|
+
*
|
|
37
|
+
* @param args - The arguments containing an array of token network/address pairs.
|
|
38
|
+
* @returns A JSON string with the token prices or an error message.
|
|
39
|
+
*/
|
|
40
|
+
tokenPricesByAddress(args: z.infer<typeof AlchemyTokenPricesByAddressSchema>): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Checks if the Alchemy Prices action provider supports the given network.
|
|
43
|
+
* Since the API works with multiple networks, this always returns true.
|
|
44
|
+
*
|
|
45
|
+
* @returns Always returns true.
|
|
46
|
+
*/
|
|
47
|
+
supportsNetwork(): boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Factory function to create a new AlchemyTokenPricesActionProvider instance.
|
|
51
|
+
*
|
|
52
|
+
* @param config - The configuration options for the provider.
|
|
53
|
+
* @returns A new instance of AlchemyTokenPricesActionProvider.
|
|
54
|
+
*/
|
|
55
|
+
export declare const alchemyTokenPricesActionProvider: (config?: AlchemyTokenPricesActionProviderConfig) => AlchemyTokenPricesActionProvider;
|
|
@@ -0,0 +1,173 @@
|
|
|
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.alchemyTokenPricesActionProvider = exports.AlchemyTokenPricesActionProvider = 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
|
+
* AlchemyTokenPricesActionProvider is an action provider for fetching token prices via the Alchemy Prices API.
|
|
19
|
+
* This provider enables querying current and historical token prices using symbols or addresses.
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
class AlchemyTokenPricesActionProvider extends actionProvider_1.ActionProvider {
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new instance of AlchemyTokenPricesActionProvider
|
|
25
|
+
*
|
|
26
|
+
* @param config - Configuration options including the API key
|
|
27
|
+
*/
|
|
28
|
+
constructor(config = {}) {
|
|
29
|
+
super("alchemyTokenPrices", []);
|
|
30
|
+
config.apiKey || (config.apiKey = process.env.ALCHEMY_API_KEY);
|
|
31
|
+
if (!config.apiKey) {
|
|
32
|
+
throw new Error("ALCHEMY_API_KEY is not configured.");
|
|
33
|
+
}
|
|
34
|
+
this.apiKey = config.apiKey;
|
|
35
|
+
this.baseUrl = "https://api.g.alchemy.com/prices/v1";
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Fetch current token prices for one or more token symbols.
|
|
39
|
+
*
|
|
40
|
+
* @param args - The arguments containing an array of token symbols.
|
|
41
|
+
* @returns A JSON string with the token prices or an error message.
|
|
42
|
+
*/
|
|
43
|
+
async tokenPricesBySymbol(args) {
|
|
44
|
+
try {
|
|
45
|
+
// Build query parameters: for each symbol add a separate query parameter
|
|
46
|
+
const params = new URLSearchParams();
|
|
47
|
+
for (const symbol of args.symbols) {
|
|
48
|
+
params.append("symbols", symbol);
|
|
49
|
+
}
|
|
50
|
+
const url = `${this.baseUrl}/${this.apiKey}/tokens/by-symbol?${params.toString()}`;
|
|
51
|
+
const response = await fetch(url, {
|
|
52
|
+
method: "GET",
|
|
53
|
+
headers: {
|
|
54
|
+
Accept: "application/json",
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
if (!response.ok) {
|
|
58
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
59
|
+
}
|
|
60
|
+
const data = await response.json();
|
|
61
|
+
return `Successfully fetched token prices by symbol:\n${JSON.stringify(data, null, 2)}`;
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
return `Error fetching token prices by symbol: ${error}`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Fetch current token prices for one or more tokens identified by network and address pairs.
|
|
69
|
+
*
|
|
70
|
+
* @param args - The arguments containing an array of token network/address pairs.
|
|
71
|
+
* @returns A JSON string with the token prices or an error message.
|
|
72
|
+
*/
|
|
73
|
+
async tokenPricesByAddress(args) {
|
|
74
|
+
try {
|
|
75
|
+
const url = `${this.baseUrl}/${this.apiKey}/tokens/by-address`;
|
|
76
|
+
const response = await fetch(url, {
|
|
77
|
+
method: "POST",
|
|
78
|
+
headers: {
|
|
79
|
+
Accept: "application/json",
|
|
80
|
+
"Content-Type": "application/json",
|
|
81
|
+
},
|
|
82
|
+
body: JSON.stringify(args),
|
|
83
|
+
});
|
|
84
|
+
if (!response.ok) {
|
|
85
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
86
|
+
}
|
|
87
|
+
const data = await response.json();
|
|
88
|
+
return `Successfully fetched token prices by address:\n${JSON.stringify(data, null, 2)}`;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
return `Error fetching token prices by address: ${error}`;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Checks if the Alchemy Prices action provider supports the given network.
|
|
96
|
+
* Since the API works with multiple networks, this always returns true.
|
|
97
|
+
*
|
|
98
|
+
* @returns Always returns true.
|
|
99
|
+
*/
|
|
100
|
+
supportsNetwork() {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.AlchemyTokenPricesActionProvider = AlchemyTokenPricesActionProvider;
|
|
105
|
+
__decorate([
|
|
106
|
+
(0, actionDecorator_1.CreateAction)({
|
|
107
|
+
name: "token_prices_by_symbol",
|
|
108
|
+
description: `
|
|
109
|
+
This tool will fetch current prices for one or more tokens using their symbols via the Alchemy Prices API.
|
|
110
|
+
|
|
111
|
+
A successful response will return a JSON payload similar to:
|
|
112
|
+
{
|
|
113
|
+
"data": [
|
|
114
|
+
{
|
|
115
|
+
"symbol": "ETH",
|
|
116
|
+
"prices": [
|
|
117
|
+
{
|
|
118
|
+
"currency": "usd",
|
|
119
|
+
"value": "2873.490923459",
|
|
120
|
+
"lastUpdatedAt": "2025-02-03T23:46:40Z"
|
|
121
|
+
}
|
|
122
|
+
]
|
|
123
|
+
}
|
|
124
|
+
]
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
A failure response will return an error message with details.
|
|
128
|
+
`,
|
|
129
|
+
schema: schemas_1.AlchemyTokenPricesBySymbolSchema,
|
|
130
|
+
}),
|
|
131
|
+
__metadata("design:type", Function),
|
|
132
|
+
__metadata("design:paramtypes", [void 0]),
|
|
133
|
+
__metadata("design:returntype", Promise)
|
|
134
|
+
], AlchemyTokenPricesActionProvider.prototype, "tokenPricesBySymbol", null);
|
|
135
|
+
__decorate([
|
|
136
|
+
(0, actionDecorator_1.CreateAction)({
|
|
137
|
+
name: "token_prices_by_address",
|
|
138
|
+
description: `
|
|
139
|
+
This tool will fetch current prices for tokens using network and address pairs via the Alchemy Prices API.
|
|
140
|
+
|
|
141
|
+
A successful response will return a JSON payload similar to:
|
|
142
|
+
{
|
|
143
|
+
"data": [
|
|
144
|
+
{
|
|
145
|
+
"network": "eth-mainnet",
|
|
146
|
+
"address": "0xYourTokenAddress",
|
|
147
|
+
"prices": [
|
|
148
|
+
{
|
|
149
|
+
"currency": "usd",
|
|
150
|
+
"value": "1234.56",
|
|
151
|
+
"lastUpdatedAt": "2025-02-03T23:46:40Z"
|
|
152
|
+
}
|
|
153
|
+
]
|
|
154
|
+
}
|
|
155
|
+
]
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
A failure response will return an error message with details.
|
|
159
|
+
`,
|
|
160
|
+
schema: schemas_1.AlchemyTokenPricesByAddressSchema,
|
|
161
|
+
}),
|
|
162
|
+
__metadata("design:type", Function),
|
|
163
|
+
__metadata("design:paramtypes", [void 0]),
|
|
164
|
+
__metadata("design:returntype", Promise)
|
|
165
|
+
], AlchemyTokenPricesActionProvider.prototype, "tokenPricesByAddress", null);
|
|
166
|
+
/**
|
|
167
|
+
* Factory function to create a new AlchemyTokenPricesActionProvider instance.
|
|
168
|
+
*
|
|
169
|
+
* @param config - The configuration options for the provider.
|
|
170
|
+
* @returns A new instance of AlchemyTokenPricesActionProvider.
|
|
171
|
+
*/
|
|
172
|
+
const alchemyTokenPricesActionProvider = (config) => new AlchemyTokenPricesActionProvider(config);
|
|
173
|
+
exports.alchemyTokenPricesActionProvider = alchemyTokenPricesActionProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const alchemyTokenPricesActionProvider_1 = require("./alchemyTokenPricesActionProvider");
|
|
4
|
+
const MOCK_API_KEY = "alch-demo";
|
|
5
|
+
// Sample responses for each action
|
|
6
|
+
const MOCK_TOKEN_PRICES_BY_SYMBOL_RESPONSE = {
|
|
7
|
+
data: [
|
|
8
|
+
{
|
|
9
|
+
symbol: "ETH",
|
|
10
|
+
prices: [
|
|
11
|
+
{
|
|
12
|
+
currency: "usd",
|
|
13
|
+
value: "2873.490923459",
|
|
14
|
+
lastUpdatedAt: "2025-02-03T23:46:40Z",
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
};
|
|
20
|
+
const MOCK_TOKEN_PRICES_BY_ADDRESS_RESPONSE = {
|
|
21
|
+
data: [
|
|
22
|
+
{
|
|
23
|
+
network: "eth-mainnet",
|
|
24
|
+
address: "0x1234567890abcdef",
|
|
25
|
+
prices: [
|
|
26
|
+
{
|
|
27
|
+
currency: "usd",
|
|
28
|
+
value: "1234.56",
|
|
29
|
+
lastUpdatedAt: "2025-02-03T23:46:40Z",
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
describe("AlchemyTokenPricesActionProvider", () => {
|
|
36
|
+
let provider;
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
process.env.ALCHEMY_API_KEY = MOCK_API_KEY;
|
|
39
|
+
provider = (0, alchemyTokenPricesActionProvider_1.alchemyTokenPricesActionProvider)({ apiKey: MOCK_API_KEY });
|
|
40
|
+
jest.restoreAllMocks();
|
|
41
|
+
});
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
jest.clearAllMocks();
|
|
44
|
+
});
|
|
45
|
+
describe("tokenPricesBySymbol", () => {
|
|
46
|
+
it("should successfully fetch token prices by symbol", async () => {
|
|
47
|
+
const fetchMock = jest.spyOn(global, "fetch").mockResolvedValue({
|
|
48
|
+
ok: true,
|
|
49
|
+
json: async () => MOCK_TOKEN_PRICES_BY_SYMBOL_RESPONSE,
|
|
50
|
+
});
|
|
51
|
+
const response = await provider.tokenPricesBySymbol({ symbols: ["ETH", "BTC"] });
|
|
52
|
+
// Verify the URL has the correct API key and query parameters.
|
|
53
|
+
const expectedUrlPart = `${provider["baseUrl"]}/${MOCK_API_KEY}/tokens/by-symbol`;
|
|
54
|
+
expect(fetchMock).toHaveBeenCalled();
|
|
55
|
+
const calledUrl = fetchMock.mock.calls[0][0];
|
|
56
|
+
expect(calledUrl).toContain(expectedUrlPart);
|
|
57
|
+
expect(calledUrl).toContain("symbols=ETH");
|
|
58
|
+
expect(calledUrl).toContain("symbols=BTC");
|
|
59
|
+
expect(response).toContain("Successfully fetched token prices by symbol");
|
|
60
|
+
expect(response).toContain(JSON.stringify(MOCK_TOKEN_PRICES_BY_SYMBOL_RESPONSE, null, 2));
|
|
61
|
+
});
|
|
62
|
+
it("should handle non-ok response for token prices by symbol", async () => {
|
|
63
|
+
jest.spyOn(global, "fetch").mockResolvedValue({
|
|
64
|
+
ok: false,
|
|
65
|
+
status: 400,
|
|
66
|
+
});
|
|
67
|
+
const response = await provider.tokenPricesBySymbol({ symbols: ["ETH"] });
|
|
68
|
+
expect(response).toContain("Error fetching token prices by symbol");
|
|
69
|
+
expect(response).toContain("400");
|
|
70
|
+
});
|
|
71
|
+
it("should handle fetch error for token prices by symbol", async () => {
|
|
72
|
+
const error = new Error("Fetch error");
|
|
73
|
+
jest.spyOn(global, "fetch").mockRejectedValue(error);
|
|
74
|
+
const response = await provider.tokenPricesBySymbol({ symbols: ["ETH"] });
|
|
75
|
+
expect(response).toContain("Error fetching token prices by symbol");
|
|
76
|
+
expect(response).toContain(error.message);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
describe("tokenPricesByAddress", () => {
|
|
80
|
+
it("should successfully fetch token prices by address", async () => {
|
|
81
|
+
const fetchMock = jest.spyOn(global, "fetch").mockResolvedValue({
|
|
82
|
+
ok: true,
|
|
83
|
+
json: async () => MOCK_TOKEN_PRICES_BY_ADDRESS_RESPONSE,
|
|
84
|
+
});
|
|
85
|
+
const payload = {
|
|
86
|
+
addresses: [{ network: "eth-mainnet", address: "0x1234567890abcdef" }],
|
|
87
|
+
};
|
|
88
|
+
const response = await provider.tokenPricesByAddress(payload);
|
|
89
|
+
expect(fetchMock).toHaveBeenCalled();
|
|
90
|
+
// Verify that fetch was called with the correct POST URL and options.
|
|
91
|
+
const expectedUrl = `${provider["baseUrl"]}/${MOCK_API_KEY}/tokens/by-address`;
|
|
92
|
+
expect(fetchMock).toHaveBeenCalledWith(expectedUrl, expect.objectContaining({
|
|
93
|
+
method: "POST",
|
|
94
|
+
headers: expect.objectContaining({
|
|
95
|
+
Accept: "application/json",
|
|
96
|
+
"Content-Type": "application/json",
|
|
97
|
+
}),
|
|
98
|
+
body: JSON.stringify(payload),
|
|
99
|
+
}));
|
|
100
|
+
expect(response).toContain("Successfully fetched token prices by address");
|
|
101
|
+
expect(response).toContain(JSON.stringify(MOCK_TOKEN_PRICES_BY_ADDRESS_RESPONSE, null, 2));
|
|
102
|
+
});
|
|
103
|
+
it("should handle non-ok response for token prices by address", async () => {
|
|
104
|
+
jest.spyOn(global, "fetch").mockResolvedValue({
|
|
105
|
+
ok: false,
|
|
106
|
+
status: 429,
|
|
107
|
+
});
|
|
108
|
+
const payload = {
|
|
109
|
+
addresses: [{ network: "eth-mainnet", address: "0x1234567890abcdef" }],
|
|
110
|
+
};
|
|
111
|
+
const response = await provider.tokenPricesByAddress(payload);
|
|
112
|
+
expect(response).toContain("Error fetching token prices by address");
|
|
113
|
+
expect(response).toContain("429");
|
|
114
|
+
});
|
|
115
|
+
it("should handle fetch error for token prices by address", async () => {
|
|
116
|
+
const error = new Error("Fetch error");
|
|
117
|
+
jest.spyOn(global, "fetch").mockRejectedValue(error);
|
|
118
|
+
const payload = {
|
|
119
|
+
addresses: [{ network: "eth-mainnet", address: "0x1234567890abcdef" }],
|
|
120
|
+
};
|
|
121
|
+
const response = await provider.tokenPricesByAddress(payload);
|
|
122
|
+
expect(response).toContain("Error fetching token prices by address");
|
|
123
|
+
expect(response).toContain(error.message);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
describe("supportsNetwork", () => {
|
|
127
|
+
it("should always return true", () => {
|
|
128
|
+
expect(provider.supportsNetwork()).toBe(true);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
});
|
|
@@ -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("./alchemyTokenPricesActionProvider"), exports);
|
|
18
|
+
__exportStar(require("./schemas"), exports);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Input schema for fetching token prices by symbol.
|
|
4
|
+
*
|
|
5
|
+
* The API expects a list of token symbols.
|
|
6
|
+
*/
|
|
7
|
+
export declare const AlchemyTokenPricesBySymbolSchema: z.ZodObject<{
|
|
8
|
+
symbols: z.ZodArray<z.ZodString, "many">;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
symbols: string[];
|
|
11
|
+
}, {
|
|
12
|
+
symbols: string[];
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* Input schema for fetching token prices by address.
|
|
16
|
+
*
|
|
17
|
+
* The API expects an object with an array of addresses, where each address contains
|
|
18
|
+
* a network identifier and a token contract address.
|
|
19
|
+
*/
|
|
20
|
+
export declare const AlchemyTokenPricesByAddressSchema: z.ZodObject<{
|
|
21
|
+
addresses: z.ZodArray<z.ZodObject<{
|
|
22
|
+
network: z.ZodString;
|
|
23
|
+
address: z.ZodString;
|
|
24
|
+
}, "strip", z.ZodTypeAny, {
|
|
25
|
+
address: string;
|
|
26
|
+
network: string;
|
|
27
|
+
}, {
|
|
28
|
+
address: string;
|
|
29
|
+
network: string;
|
|
30
|
+
}>, "many">;
|
|
31
|
+
}, "strip", z.ZodTypeAny, {
|
|
32
|
+
addresses: {
|
|
33
|
+
address: string;
|
|
34
|
+
network: string;
|
|
35
|
+
}[];
|
|
36
|
+
}, {
|
|
37
|
+
addresses: {
|
|
38
|
+
address: string;
|
|
39
|
+
network: string;
|
|
40
|
+
}[];
|
|
41
|
+
}>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AlchemyTokenPricesByAddressSchema = exports.AlchemyTokenPricesBySymbolSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* Input schema for fetching token prices by symbol.
|
|
7
|
+
*
|
|
8
|
+
* The API expects a list of token symbols.
|
|
9
|
+
*/
|
|
10
|
+
exports.AlchemyTokenPricesBySymbolSchema = zod_1.z
|
|
11
|
+
.object({
|
|
12
|
+
symbols: zod_1.z
|
|
13
|
+
.array(zod_1.z.string())
|
|
14
|
+
.min(1, "At least one token symbol is required. Example: ETH, BTC, SOL, etc.")
|
|
15
|
+
.max(25, "A maximum of 25 token symbols can be provided."),
|
|
16
|
+
})
|
|
17
|
+
.describe("Input schema for fetching token prices by symbol from Alchemy");
|
|
18
|
+
/**
|
|
19
|
+
* Input schema for fetching token prices by address.
|
|
20
|
+
*
|
|
21
|
+
* The API expects an object with an array of addresses, where each address contains
|
|
22
|
+
* a network identifier and a token contract address.
|
|
23
|
+
*/
|
|
24
|
+
exports.AlchemyTokenPricesByAddressSchema = zod_1.z
|
|
25
|
+
.object({
|
|
26
|
+
addresses: zod_1.z
|
|
27
|
+
.array(zod_1.z.object({
|
|
28
|
+
network: zod_1.z.string().describe("Network identifier (e.g., eth-mainnet, base-mainnet etc.)"),
|
|
29
|
+
address: zod_1.z.string().describe("Token contract address"),
|
|
30
|
+
}))
|
|
31
|
+
.min(1, "At least one address is required.")
|
|
32
|
+
.max(25, "A maximum of 25 addresses can be provided."),
|
|
33
|
+
})
|
|
34
|
+
.describe("Input schema for fetching token prices by address from Alchemy");
|
|
@@ -6,7 +6,7 @@ import { EvmWalletProvider } from "../../wallet-providers";
|
|
|
6
6
|
/**
|
|
7
7
|
* Action provider for registering Basenames.
|
|
8
8
|
*/
|
|
9
|
-
export declare class BasenameActionProvider extends ActionProvider {
|
|
9
|
+
export declare class BasenameActionProvider extends ActionProvider<EvmWalletProvider> {
|
|
10
10
|
/**
|
|
11
11
|
* Constructs a new BasenameActionProvider.
|
|
12
12
|
*/
|
|
@@ -10,6 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.cdpApiActionProvider = exports.CdpApiActionProvider = void 0;
|
|
13
|
+
const package_json_1 = require("../../../package.json");
|
|
13
14
|
const coinbase_sdk_1 = require("@coinbase/coinbase-sdk");
|
|
14
15
|
const zod_1 = require("zod");
|
|
15
16
|
const actionDecorator_1 = require("../actionDecorator");
|
|
@@ -37,7 +38,12 @@ class CdpApiActionProvider extends actionProvider_1.ActionProvider {
|
|
|
37
38
|
*/
|
|
38
39
|
this.supportsNetwork = (_) => true;
|
|
39
40
|
if (config.apiKeyName && config.apiKeyPrivateKey) {
|
|
40
|
-
coinbase_sdk_1.Coinbase.configure({
|
|
41
|
+
coinbase_sdk_1.Coinbase.configure({
|
|
42
|
+
apiKeyName: config.apiKeyName,
|
|
43
|
+
privateKey: config.apiKeyPrivateKey,
|
|
44
|
+
source: "agentkit",
|
|
45
|
+
sourceVersion: package_json_1.version,
|
|
46
|
+
});
|
|
41
47
|
}
|
|
42
48
|
else {
|
|
43
49
|
coinbase_sdk_1.Coinbase.configureFromJson();
|
|
@@ -6,7 +6,7 @@ import { EvmWalletProvider } from "../../wallet-providers";
|
|
|
6
6
|
/**
|
|
7
7
|
* ERC20ActionProvider is an action provider for ERC20 tokens.
|
|
8
8
|
*/
|
|
9
|
-
export declare class ERC20ActionProvider extends ActionProvider {
|
|
9
|
+
export declare class ERC20ActionProvider extends ActionProvider<EvmWalletProvider> {
|
|
10
10
|
/**
|
|
11
11
|
* Constructor for the ERC20ActionProvider.
|
|
12
12
|
*/
|
|
@@ -6,7 +6,7 @@ import { Network } from "../../network";
|
|
|
6
6
|
/**
|
|
7
7
|
* Erc721ActionProvider is an action provider for Erc721 contract interactions.
|
|
8
8
|
*/
|
|
9
|
-
export declare class Erc721ActionProvider extends ActionProvider {
|
|
9
|
+
export declare class Erc721ActionProvider extends ActionProvider<EvmWalletProvider> {
|
|
10
10
|
/**
|
|
11
11
|
* Constructor for the Erc721ActionProvider class.
|
|
12
12
|
*/
|
|
@@ -27,3 +27,5 @@ __exportStar(require("./farcaster"), exports);
|
|
|
27
27
|
__exportStar(require("./twitter"), exports);
|
|
28
28
|
__exportStar(require("./wallet"), exports);
|
|
29
29
|
__exportStar(require("./customActionProvider"), exports);
|
|
30
|
+
__exportStar(require("./alchemy"), exports);
|
|
31
|
+
__exportStar(require("./moonwell"), exports);
|