@coinbase/agentkit 0.2.3-nightly.20250305.26 → 0.2.3-nightly.20250307.28
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 +13 -0
- package/dist/action-providers/erc721/constants.d.ts +0 -4
- package/dist/action-providers/erc721/constants.js +1 -4
- package/dist/action-providers/erc721/erc721ActionProvider.js +1 -1
- package/dist/action-providers/erc721/erc721ActionProvider.test.js +1 -1
- package/dist/action-providers/index.d.ts +1 -0
- package/dist/action-providers/index.js +1 -0
- package/dist/action-providers/opensea/index.d.ts +1 -0
- package/dist/action-providers/opensea/index.js +17 -0
- package/dist/action-providers/opensea/openseaActionProvider.d.ts +59 -0
- package/dist/action-providers/opensea/openseaActionProvider.js +146 -0
- package/dist/action-providers/opensea/openseaActionProvider.test.d.ts +1 -0
- package/dist/action-providers/opensea/openseaActionProvider.test.js +201 -0
- package/dist/action-providers/opensea/schemas.d.ts +30 -0
- package/dist/action-providers/opensea/schemas.js +33 -0
- package/dist/action-providers/opensea/utils.d.ts +12 -0
- package/dist/action-providers/opensea/utils.js +47 -0
- package/dist/wallet-providers/cdpWalletProvider.d.ts +6 -0
- package/dist/wallet-providers/cdpWalletProvider.js +11 -0
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -248,6 +248,19 @@ const agent = createReactAgent({
|
|
|
248
248
|
</table>
|
|
249
249
|
</details>
|
|
250
250
|
<details>
|
|
251
|
+
<summary><strong>Opensea</strong></summary>
|
|
252
|
+
<table width="100%">
|
|
253
|
+
<tr>
|
|
254
|
+
<td width="200"><code>list_nft</code></td>
|
|
255
|
+
<td width="768">Lists an NFT for sale on OpenSea.</td>
|
|
256
|
+
</tr>
|
|
257
|
+
<tr>
|
|
258
|
+
<td width="200"><code>get_nfts_by_account</code></td>
|
|
259
|
+
<td width="768">Fetches NFTs owned by a specific wallet address on OpenSea.</td>
|
|
260
|
+
</tr>
|
|
261
|
+
</table>
|
|
262
|
+
</details>
|
|
263
|
+
<details>
|
|
251
264
|
<summary><strong>Pyth</strong></summary>
|
|
252
265
|
<table width="100%">
|
|
253
266
|
<tr>
|
|
@@ -3,10 +3,6 @@ export declare const ERC721_ABI: readonly [{
|
|
|
3
3
|
readonly internalType: "address";
|
|
4
4
|
readonly name: "to";
|
|
5
5
|
readonly type: "address";
|
|
6
|
-
}, {
|
|
7
|
-
readonly internalType: "uint256";
|
|
8
|
-
readonly name: "tokenId";
|
|
9
|
-
readonly type: "uint256";
|
|
10
6
|
}];
|
|
11
7
|
readonly name: "mint";
|
|
12
8
|
readonly outputs: readonly [];
|
|
@@ -3,10 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ERC721_ABI = void 0;
|
|
4
4
|
exports.ERC721_ABI = [
|
|
5
5
|
{
|
|
6
|
-
inputs: [
|
|
7
|
-
{ internalType: "address", name: "to", type: "address" },
|
|
8
|
-
{ internalType: "uint256", name: "tokenId", type: "uint256" },
|
|
9
|
-
],
|
|
6
|
+
inputs: [{ internalType: "address", name: "to", type: "address" }],
|
|
10
7
|
name: "mint",
|
|
11
8
|
outputs: [],
|
|
12
9
|
payable: false,
|
|
@@ -46,7 +46,7 @@ class Erc721ActionProvider extends actionProvider_1.ActionProvider {
|
|
|
46
46
|
const data = (0, viem_1.encodeFunctionData)({
|
|
47
47
|
abi: constants_1.ERC721_ABI,
|
|
48
48
|
functionName: "mint",
|
|
49
|
-
args: [args.destination
|
|
49
|
+
args: [args.destination],
|
|
50
50
|
});
|
|
51
51
|
const hash = await walletProvider.sendTransaction({
|
|
52
52
|
to: args.contractAddress,
|
|
@@ -34,7 +34,7 @@ describe("ERC721 Action Provider", () => {
|
|
|
34
34
|
data: (0, viem_1.encodeFunctionData)({
|
|
35
35
|
abi: constants_1.ERC721_ABI,
|
|
36
36
|
functionName: "mint",
|
|
37
|
-
args: [MOCK_DESTINATION
|
|
37
|
+
args: [MOCK_DESTINATION],
|
|
38
38
|
}),
|
|
39
39
|
});
|
|
40
40
|
expect(mockWallet.waitForTransactionReceipt).toHaveBeenCalledWith("0xmockhash");
|
|
@@ -28,6 +28,7 @@ __exportStar(require("./jupiter"), exports);
|
|
|
28
28
|
__exportStar(require("./pyth"), exports);
|
|
29
29
|
__exportStar(require("./moonwell"), exports);
|
|
30
30
|
__exportStar(require("./morpho"), exports);
|
|
31
|
+
__exportStar(require("./opensea"), exports);
|
|
31
32
|
__exportStar(require("./spl"), exports);
|
|
32
33
|
__exportStar(require("./twitter"), exports);
|
|
33
34
|
__exportStar(require("./wallet"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./openseaActionProvider";
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./openseaActionProvider"), exports);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ActionProvider } from "../actionProvider";
|
|
3
|
+
import { ListNftSchema, GetNftsByAccountSchema } from "./schemas";
|
|
4
|
+
import { Network } from "../../network";
|
|
5
|
+
import { EvmWalletProvider } from "../../wallet-providers";
|
|
6
|
+
/**
|
|
7
|
+
* Configuration options for the OpenseaActionProvider.
|
|
8
|
+
*/
|
|
9
|
+
export interface OpenseaActionProviderConfig {
|
|
10
|
+
/**
|
|
11
|
+
* OpenSea API Key.
|
|
12
|
+
*/
|
|
13
|
+
apiKey?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The network ID to use for the OpenseaActionProvider.
|
|
16
|
+
*/
|
|
17
|
+
networkId?: string;
|
|
18
|
+
/**
|
|
19
|
+
* The private key to use for the OpenseaActionProvider.
|
|
20
|
+
*/
|
|
21
|
+
privateKey?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* OpenseaActionProvider is an action provider for OpenSea marketplace interactions.
|
|
25
|
+
*/
|
|
26
|
+
export declare class OpenseaActionProvider extends ActionProvider<EvmWalletProvider> {
|
|
27
|
+
private readonly apiKey;
|
|
28
|
+
private walletWithProvider;
|
|
29
|
+
private openseaSDK;
|
|
30
|
+
private openseaBaseUrl;
|
|
31
|
+
/**
|
|
32
|
+
* Constructor for the OpenseaActionProvider class.
|
|
33
|
+
*
|
|
34
|
+
* @param config - The configuration options for the OpenseaActionProvider.
|
|
35
|
+
*/
|
|
36
|
+
constructor(config?: OpenseaActionProviderConfig);
|
|
37
|
+
/**
|
|
38
|
+
* Lists an NFT for sale on OpenSea.
|
|
39
|
+
*
|
|
40
|
+
* @param args - The input arguments for the action.
|
|
41
|
+
* @returns A message containing the listing details.
|
|
42
|
+
*/
|
|
43
|
+
listNft(args: z.infer<typeof ListNftSchema>): Promise<string>;
|
|
44
|
+
/**
|
|
45
|
+
* Fetch NFTs of a specific wallet address.
|
|
46
|
+
*
|
|
47
|
+
* @param args - The input arguments for the action.
|
|
48
|
+
* @returns A JSON string containing the NFTs or error message
|
|
49
|
+
*/
|
|
50
|
+
getNftsByAccount(args: z.infer<typeof GetNftsByAccountSchema>): Promise<string>;
|
|
51
|
+
/**
|
|
52
|
+
* Checks if the Opensea action provider supports the given network.
|
|
53
|
+
*
|
|
54
|
+
* @param network - The network to check.
|
|
55
|
+
* @returns True if the Opensea action provider supports the network, false otherwise.
|
|
56
|
+
*/
|
|
57
|
+
supportsNetwork: (network: Network) => boolean;
|
|
58
|
+
}
|
|
59
|
+
export declare const openseaActionProvider: (config?: OpenseaActionProviderConfig) => OpenseaActionProvider;
|
|
@@ -0,0 +1,146 @@
|
|
|
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.openseaActionProvider = exports.OpenseaActionProvider = 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
|
+
const opensea_js_1 = require("opensea-js");
|
|
18
|
+
const network_1 = require("../../network");
|
|
19
|
+
const ethers_1 = require("ethers");
|
|
20
|
+
const utils_1 = require("./utils");
|
|
21
|
+
/**
|
|
22
|
+
* OpenseaActionProvider is an action provider for OpenSea marketplace interactions.
|
|
23
|
+
*/
|
|
24
|
+
class OpenseaActionProvider extends actionProvider_1.ActionProvider {
|
|
25
|
+
/**
|
|
26
|
+
* Constructor for the OpenseaActionProvider class.
|
|
27
|
+
*
|
|
28
|
+
* @param config - The configuration options for the OpenseaActionProvider.
|
|
29
|
+
*/
|
|
30
|
+
constructor(config = {}) {
|
|
31
|
+
super("opensea", []);
|
|
32
|
+
/**
|
|
33
|
+
* Checks if the Opensea action provider supports the given network.
|
|
34
|
+
*
|
|
35
|
+
* @param network - The network to check.
|
|
36
|
+
* @returns True if the Opensea action provider supports the network, false otherwise.
|
|
37
|
+
*/
|
|
38
|
+
this.supportsNetwork = (network) => network.chainId !== undefined && utils_1.supportedChains[network.chainId] !== undefined;
|
|
39
|
+
const apiKey = config.apiKey || process.env.OPENSEA_API_KEY;
|
|
40
|
+
if (!apiKey) {
|
|
41
|
+
throw new Error("OPENSEA_API_KEY is not configured.");
|
|
42
|
+
}
|
|
43
|
+
this.apiKey = apiKey;
|
|
44
|
+
const chainId = network_1.NETWORK_ID_TO_CHAIN_ID[config.networkId || "base-sepolia"];
|
|
45
|
+
const provider = ethers_1.ethers.getDefaultProvider(parseInt(chainId));
|
|
46
|
+
const walletWithProvider = new ethers_1.Wallet(config.privateKey, provider);
|
|
47
|
+
this.walletWithProvider = walletWithProvider;
|
|
48
|
+
const openseaSDK = new opensea_js_1.OpenSeaSDK(walletWithProvider, {
|
|
49
|
+
chain: (0, utils_1.chainIdToOpenseaChain)(chainId),
|
|
50
|
+
apiKey: this.apiKey,
|
|
51
|
+
});
|
|
52
|
+
this.openseaSDK = openseaSDK;
|
|
53
|
+
this.openseaBaseUrl = this.openseaSDK.api.apiBaseUrl.replace("-api", "").replace("api", "");
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Lists an NFT for sale on OpenSea.
|
|
57
|
+
*
|
|
58
|
+
* @param args - The input arguments for the action.
|
|
59
|
+
* @returns A message containing the listing details.
|
|
60
|
+
*/
|
|
61
|
+
async listNft(args) {
|
|
62
|
+
try {
|
|
63
|
+
const expirationTime = Math.round(Date.now() / 1000 + args.expirationDays * 24 * 60 * 60);
|
|
64
|
+
await this.openseaSDK.createListing({
|
|
65
|
+
asset: {
|
|
66
|
+
tokenId: args.tokenId,
|
|
67
|
+
tokenAddress: args.contractAddress,
|
|
68
|
+
},
|
|
69
|
+
startAmount: args.price,
|
|
70
|
+
quantity: 1,
|
|
71
|
+
paymentTokenAddress: "0x0000000000000000000000000000000000000000", // ETH
|
|
72
|
+
expirationTime,
|
|
73
|
+
accountAddress: this.walletWithProvider.address,
|
|
74
|
+
});
|
|
75
|
+
const listingLink = `${this.openseaBaseUrl}/assets/${this.openseaSDK.chain}/${args.contractAddress}/${args.tokenId}`;
|
|
76
|
+
return `Successfully listed NFT ${args.contractAddress} token ${args.tokenId} for ${args.price} ETH, expiring in ${args.expirationDays} days. Listing on OpenSea: ${listingLink}.`;
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
return `Error listing NFT ${args.contractAddress} token ${args.tokenId} for ${args.price} ETH using account ${this.walletWithProvider.address}: ${error}`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Fetch NFTs of a specific wallet address.
|
|
84
|
+
*
|
|
85
|
+
* @param args - The input arguments for the action.
|
|
86
|
+
* @returns A JSON string containing the NFTs or error message
|
|
87
|
+
*/
|
|
88
|
+
async getNftsByAccount(args) {
|
|
89
|
+
try {
|
|
90
|
+
const address = args.accountAddress || this.walletWithProvider.address;
|
|
91
|
+
const { nfts } = await this.openseaSDK.api.getNFTsByAccount(address);
|
|
92
|
+
return JSON.stringify(nfts);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
const address = args.accountAddress || this.walletWithProvider.address;
|
|
96
|
+
return `Error fetching NFTs for account ${address}: ${error}`;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.OpenseaActionProvider = OpenseaActionProvider;
|
|
101
|
+
__decorate([
|
|
102
|
+
(0, actionDecorator_1.CreateAction)({
|
|
103
|
+
name: "list_nft",
|
|
104
|
+
description: `
|
|
105
|
+
This tool will list an NFT for sale on the OpenSea marketplace.
|
|
106
|
+
EVM networks are supported on mainnet and testnets.
|
|
107
|
+
|
|
108
|
+
It takes the following inputs:
|
|
109
|
+
- contractAddress: The NFT contract address to list
|
|
110
|
+
- tokenId: The ID of the NFT to list
|
|
111
|
+
- price: The price in ETH for which the NFT will be listed
|
|
112
|
+
- expirationDays: (Optional) Number of days the listing should be active for (default: 90)
|
|
113
|
+
|
|
114
|
+
Important notes:
|
|
115
|
+
- The wallet must own the NFT
|
|
116
|
+
- Price is in ETH (e.g., 1.5 for 1.5 ETH). This is the amount the seller will receive if the NFT is sold. It is not required to have this amount in the wallet.
|
|
117
|
+
- Listing the NFT requires approval for OpenSea to manage the entire NFT collection:
|
|
118
|
+
- If the collection is not already approved, an onchain transaction is required, which will incur gas fees.
|
|
119
|
+
- If already approved, listing is gasless and does not require any onchain transaction.
|
|
120
|
+
- EVM networks are supported on mainnet and testnets, for example: base-mainnet and base-sepolia.
|
|
121
|
+
`,
|
|
122
|
+
schema: schemas_1.ListNftSchema,
|
|
123
|
+
}),
|
|
124
|
+
__metadata("design:type", Function),
|
|
125
|
+
__metadata("design:paramtypes", [void 0]),
|
|
126
|
+
__metadata("design:returntype", Promise)
|
|
127
|
+
], OpenseaActionProvider.prototype, "listNft", null);
|
|
128
|
+
__decorate([
|
|
129
|
+
(0, actionDecorator_1.CreateAction)({
|
|
130
|
+
name: "get_nfts_by_account",
|
|
131
|
+
description: `
|
|
132
|
+
This tool will fetch NFTs owned by a specific wallet address on OpenSea.
|
|
133
|
+
|
|
134
|
+
It takes the following inputs:
|
|
135
|
+
- accountAddress: (Optional) The wallet address to fetch NFTs for. If not provided, uses the connected wallet address.
|
|
136
|
+
|
|
137
|
+
The tool will return a JSON string containing the NFTs owned by the specified address.
|
|
138
|
+
`,
|
|
139
|
+
schema: schemas_1.GetNftsByAccountSchema,
|
|
140
|
+
}),
|
|
141
|
+
__metadata("design:type", Function),
|
|
142
|
+
__metadata("design:paramtypes", [void 0]),
|
|
143
|
+
__metadata("design:returntype", Promise)
|
|
144
|
+
], OpenseaActionProvider.prototype, "getNftsByAccount", null);
|
|
145
|
+
const openseaActionProvider = (config) => new OpenseaActionProvider(config);
|
|
146
|
+
exports.openseaActionProvider = openseaActionProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const opensea_js_1 = require("opensea-js");
|
|
4
|
+
const openseaActionProvider_1 = require("./openseaActionProvider");
|
|
5
|
+
jest.mock("opensea-js");
|
|
6
|
+
describe("OpenSea Action Provider", () => {
|
|
7
|
+
const MOCK_API_KEY = "test-api-key";
|
|
8
|
+
const MOCK_PRIVATE_KEY = "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
9
|
+
const MOCK_CONTRACT = "0x1234567890123456789012345678901234567890";
|
|
10
|
+
const MOCK_TOKEN_ID = "1";
|
|
11
|
+
const MOCK_PRICE = 0.1;
|
|
12
|
+
const MOCK_EXPIRATION_DAYS = 90;
|
|
13
|
+
const MOCK_OPENSEA_BASE_URL = "https://testnets.opensea.io";
|
|
14
|
+
const MOCK_OPENSEA_CHAIN = "base_sepolia";
|
|
15
|
+
let actionProvider;
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
jest.clearAllMocks();
|
|
18
|
+
// Mock OpenSeaSDK constructor
|
|
19
|
+
opensea_js_1.OpenSeaSDK.mockImplementation(() => ({
|
|
20
|
+
createListing: jest.fn(),
|
|
21
|
+
api: {
|
|
22
|
+
apiBaseUrl: MOCK_OPENSEA_BASE_URL,
|
|
23
|
+
getNFTsByAccount: jest.fn(),
|
|
24
|
+
},
|
|
25
|
+
chain: MOCK_OPENSEA_CHAIN,
|
|
26
|
+
}));
|
|
27
|
+
actionProvider = (0, openseaActionProvider_1.openseaActionProvider)({
|
|
28
|
+
apiKey: MOCK_API_KEY,
|
|
29
|
+
privateKey: MOCK_PRIVATE_KEY,
|
|
30
|
+
networkId: "base-sepolia",
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
describe("listNft", () => {
|
|
34
|
+
it("should successfully list an NFT", async () => {
|
|
35
|
+
const mockListing = {};
|
|
36
|
+
const mockCreateListing = jest.fn().mockResolvedValue(mockListing);
|
|
37
|
+
// Update the mock implementation with the mock function
|
|
38
|
+
opensea_js_1.OpenSeaSDK.mockImplementation(() => ({
|
|
39
|
+
createListing: mockCreateListing,
|
|
40
|
+
api: {
|
|
41
|
+
apiBaseUrl: MOCK_OPENSEA_BASE_URL,
|
|
42
|
+
},
|
|
43
|
+
chain: MOCK_OPENSEA_CHAIN,
|
|
44
|
+
}));
|
|
45
|
+
// Re-create provider with new mock
|
|
46
|
+
actionProvider = (0, openseaActionProvider_1.openseaActionProvider)({
|
|
47
|
+
apiKey: MOCK_API_KEY,
|
|
48
|
+
privateKey: MOCK_PRIVATE_KEY,
|
|
49
|
+
networkId: "base-sepolia",
|
|
50
|
+
});
|
|
51
|
+
const args = {
|
|
52
|
+
contractAddress: MOCK_CONTRACT,
|
|
53
|
+
tokenId: MOCK_TOKEN_ID,
|
|
54
|
+
price: MOCK_PRICE,
|
|
55
|
+
expirationDays: MOCK_EXPIRATION_DAYS,
|
|
56
|
+
};
|
|
57
|
+
const response = await actionProvider.listNft(args);
|
|
58
|
+
expect(mockCreateListing).toHaveBeenCalledWith(expect.objectContaining({
|
|
59
|
+
asset: {
|
|
60
|
+
tokenId: MOCK_TOKEN_ID,
|
|
61
|
+
tokenAddress: MOCK_CONTRACT,
|
|
62
|
+
},
|
|
63
|
+
startAmount: MOCK_PRICE,
|
|
64
|
+
quantity: 1,
|
|
65
|
+
}));
|
|
66
|
+
expect(response).toBe(`Successfully listed NFT ${MOCK_CONTRACT} token ${MOCK_TOKEN_ID} for ${MOCK_PRICE} ETH, expiring in ${MOCK_EXPIRATION_DAYS} days. Listing on OpenSea: ${MOCK_OPENSEA_BASE_URL}/assets/${MOCK_OPENSEA_CHAIN}/${MOCK_CONTRACT}/${MOCK_TOKEN_ID}.`);
|
|
67
|
+
});
|
|
68
|
+
it("should handle listing errors", async () => {
|
|
69
|
+
const error = new Error("Listing failed");
|
|
70
|
+
const mockCreateListing = jest.fn().mockRejectedValue(error);
|
|
71
|
+
// Update the mock implementation with the mock function
|
|
72
|
+
opensea_js_1.OpenSeaSDK.mockImplementation(() => ({
|
|
73
|
+
createListing: mockCreateListing,
|
|
74
|
+
api: {
|
|
75
|
+
apiBaseUrl: MOCK_OPENSEA_BASE_URL,
|
|
76
|
+
},
|
|
77
|
+
chain: MOCK_OPENSEA_CHAIN,
|
|
78
|
+
}));
|
|
79
|
+
// Re-create provider with new mock
|
|
80
|
+
actionProvider = (0, openseaActionProvider_1.openseaActionProvider)({
|
|
81
|
+
apiKey: MOCK_API_KEY,
|
|
82
|
+
privateKey: MOCK_PRIVATE_KEY,
|
|
83
|
+
networkId: "base-sepolia",
|
|
84
|
+
});
|
|
85
|
+
const args = {
|
|
86
|
+
contractAddress: MOCK_CONTRACT,
|
|
87
|
+
tokenId: MOCK_TOKEN_ID,
|
|
88
|
+
price: MOCK_PRICE,
|
|
89
|
+
expirationDays: MOCK_EXPIRATION_DAYS,
|
|
90
|
+
};
|
|
91
|
+
const response = await actionProvider.listNft(args);
|
|
92
|
+
expect(response).toContain(`Error listing NFT ${MOCK_CONTRACT} token ${MOCK_TOKEN_ID}`);
|
|
93
|
+
expect(response).toContain(error.message);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
describe("getNftsByAccount", () => {
|
|
97
|
+
const MOCK_WALLET_ADDRESS = "0xabcdef1234567890abcdef1234567890abcdef12";
|
|
98
|
+
const MOCK_NFTS = [
|
|
99
|
+
{
|
|
100
|
+
identifier: "1",
|
|
101
|
+
contract: MOCK_CONTRACT,
|
|
102
|
+
name: "Test NFT 1",
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
identifier: "2",
|
|
106
|
+
contract: MOCK_CONTRACT,
|
|
107
|
+
name: "Test NFT 2",
|
|
108
|
+
},
|
|
109
|
+
];
|
|
110
|
+
it("should successfully fetch NFTs for the specified account", async () => {
|
|
111
|
+
const mockGetNFTsByAccount = jest.fn().mockResolvedValue({ nfts: MOCK_NFTS });
|
|
112
|
+
// Update the mock implementation with the mock function
|
|
113
|
+
opensea_js_1.OpenSeaSDK.mockImplementation(() => ({
|
|
114
|
+
createListing: jest.fn(),
|
|
115
|
+
api: {
|
|
116
|
+
apiBaseUrl: MOCK_OPENSEA_BASE_URL,
|
|
117
|
+
getNFTsByAccount: mockGetNFTsByAccount,
|
|
118
|
+
},
|
|
119
|
+
chain: MOCK_OPENSEA_CHAIN,
|
|
120
|
+
}));
|
|
121
|
+
// Re-create provider with new mock
|
|
122
|
+
actionProvider = (0, openseaActionProvider_1.openseaActionProvider)({
|
|
123
|
+
apiKey: MOCK_API_KEY,
|
|
124
|
+
privateKey: MOCK_PRIVATE_KEY,
|
|
125
|
+
networkId: "base-sepolia",
|
|
126
|
+
});
|
|
127
|
+
const args = {
|
|
128
|
+
accountAddress: MOCK_WALLET_ADDRESS,
|
|
129
|
+
};
|
|
130
|
+
const response = await actionProvider.getNftsByAccount(args);
|
|
131
|
+
expect(mockGetNFTsByAccount).toHaveBeenCalledWith(MOCK_WALLET_ADDRESS);
|
|
132
|
+
expect(response).toBe(JSON.stringify(MOCK_NFTS));
|
|
133
|
+
});
|
|
134
|
+
it("should use connected wallet address when no account is specified", async () => {
|
|
135
|
+
const mockGetNFTsByAccount = jest.fn().mockResolvedValue({ nfts: MOCK_NFTS });
|
|
136
|
+
// Update the mock implementation with the mock function
|
|
137
|
+
opensea_js_1.OpenSeaSDK.mockImplementation(() => ({
|
|
138
|
+
createListing: jest.fn(),
|
|
139
|
+
api: {
|
|
140
|
+
apiBaseUrl: MOCK_OPENSEA_BASE_URL,
|
|
141
|
+
getNFTsByAccount: mockGetNFTsByAccount,
|
|
142
|
+
},
|
|
143
|
+
chain: MOCK_OPENSEA_CHAIN,
|
|
144
|
+
}));
|
|
145
|
+
// Re-create provider with new mock
|
|
146
|
+
actionProvider = (0, openseaActionProvider_1.openseaActionProvider)({
|
|
147
|
+
apiKey: MOCK_API_KEY,
|
|
148
|
+
privateKey: MOCK_PRIVATE_KEY,
|
|
149
|
+
networkId: "base-sepolia",
|
|
150
|
+
});
|
|
151
|
+
const args = {}; // No accountAddress provided
|
|
152
|
+
const response = await actionProvider.getNftsByAccount(args);
|
|
153
|
+
// Should use the wallet address from the provider
|
|
154
|
+
expect(mockGetNFTsByAccount).toHaveBeenCalled();
|
|
155
|
+
expect(response).toBe(JSON.stringify(MOCK_NFTS));
|
|
156
|
+
});
|
|
157
|
+
it("should handle errors when fetching NFTs", async () => {
|
|
158
|
+
const error = new Error("Failed to fetch NFTs");
|
|
159
|
+
const mockGetNFTsByAccount = jest.fn().mockRejectedValue(error);
|
|
160
|
+
// Update the mock implementation with the mock function
|
|
161
|
+
opensea_js_1.OpenSeaSDK.mockImplementation(() => ({
|
|
162
|
+
createListing: jest.fn(),
|
|
163
|
+
api: {
|
|
164
|
+
apiBaseUrl: MOCK_OPENSEA_BASE_URL,
|
|
165
|
+
getNFTsByAccount: mockGetNFTsByAccount,
|
|
166
|
+
},
|
|
167
|
+
chain: MOCK_OPENSEA_CHAIN,
|
|
168
|
+
}));
|
|
169
|
+
// Re-create provider with new mock
|
|
170
|
+
actionProvider = (0, openseaActionProvider_1.openseaActionProvider)({
|
|
171
|
+
apiKey: MOCK_API_KEY,
|
|
172
|
+
privateKey: MOCK_PRIVATE_KEY,
|
|
173
|
+
networkId: "base-sepolia",
|
|
174
|
+
});
|
|
175
|
+
const args = {
|
|
176
|
+
accountAddress: MOCK_WALLET_ADDRESS,
|
|
177
|
+
};
|
|
178
|
+
const response = await actionProvider.getNftsByAccount(args);
|
|
179
|
+
expect(mockGetNFTsByAccount).toHaveBeenCalledWith(MOCK_WALLET_ADDRESS);
|
|
180
|
+
expect(response).toContain(`Error fetching NFTs for account ${MOCK_WALLET_ADDRESS}`);
|
|
181
|
+
expect(response).toContain(error.message);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
describe("supportsNetwork", () => {
|
|
185
|
+
it("should return true for supported networks", () => {
|
|
186
|
+
const baseSepoliaNetwork = {
|
|
187
|
+
protocolFamily: "evm",
|
|
188
|
+
networkId: "base-sepolia",
|
|
189
|
+
chainId: "84532",
|
|
190
|
+
};
|
|
191
|
+
expect(actionProvider.supportsNetwork(baseSepoliaNetwork)).toBe(true);
|
|
192
|
+
});
|
|
193
|
+
it("should return false for unsupported networks", () => {
|
|
194
|
+
const fantomNetwork = {
|
|
195
|
+
protocolFamily: "bitcoin",
|
|
196
|
+
networkId: "any",
|
|
197
|
+
};
|
|
198
|
+
expect(actionProvider.supportsNetwork(fantomNetwork)).toBe(false);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Input schema for listing an NFT on OpenSea.
|
|
4
|
+
*/
|
|
5
|
+
export declare const ListNftSchema: z.ZodObject<{
|
|
6
|
+
contractAddress: z.ZodString;
|
|
7
|
+
tokenId: z.ZodString;
|
|
8
|
+
price: z.ZodNumber;
|
|
9
|
+
expirationDays: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
contractAddress: string;
|
|
12
|
+
price: number;
|
|
13
|
+
tokenId: string;
|
|
14
|
+
expirationDays: number;
|
|
15
|
+
}, {
|
|
16
|
+
contractAddress: string;
|
|
17
|
+
price: number;
|
|
18
|
+
tokenId: string;
|
|
19
|
+
expirationDays?: number | undefined;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Input schema for getting NFTs from a specific wallet address.
|
|
23
|
+
*/
|
|
24
|
+
export declare const GetNftsByAccountSchema: z.ZodObject<{
|
|
25
|
+
accountAddress: z.ZodOptional<z.ZodString>;
|
|
26
|
+
}, "strip", z.ZodTypeAny, {
|
|
27
|
+
accountAddress?: string | undefined;
|
|
28
|
+
}, {
|
|
29
|
+
accountAddress?: string | undefined;
|
|
30
|
+
}>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetNftsByAccountSchema = exports.ListNftSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* Input schema for listing an NFT on OpenSea.
|
|
7
|
+
*/
|
|
8
|
+
exports.ListNftSchema = zod_1.z
|
|
9
|
+
.object({
|
|
10
|
+
contractAddress: zod_1.z.string().nonempty().describe("The NFT contract address to list"),
|
|
11
|
+
tokenId: zod_1.z.string().nonempty().describe("The tokenID of the NFT to list"),
|
|
12
|
+
price: zod_1.z.number().positive().describe("The price in ETH to list the NFT for"),
|
|
13
|
+
expirationDays: zod_1.z
|
|
14
|
+
.number()
|
|
15
|
+
.positive()
|
|
16
|
+
.optional()
|
|
17
|
+
.default(90)
|
|
18
|
+
.describe("Number of days the listing should be active for (default: 90)"),
|
|
19
|
+
})
|
|
20
|
+
.strip()
|
|
21
|
+
.describe("Input schema for listing an NFT on OpenSea");
|
|
22
|
+
/**
|
|
23
|
+
* Input schema for getting NFTs from a specific wallet address.
|
|
24
|
+
*/
|
|
25
|
+
exports.GetNftsByAccountSchema = zod_1.z
|
|
26
|
+
.object({
|
|
27
|
+
accountAddress: zod_1.z
|
|
28
|
+
.string()
|
|
29
|
+
.optional()
|
|
30
|
+
.describe("The wallet address to fetch NFTs for (defaults to connected wallet if not provided)"),
|
|
31
|
+
})
|
|
32
|
+
.strip()
|
|
33
|
+
.describe("Input schema for fetching NFTs by account");
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Chain } from "opensea-js";
|
|
2
|
+
/**
|
|
3
|
+
* Supported Opensea chains
|
|
4
|
+
*/
|
|
5
|
+
export declare const supportedChains: Record<string, Chain>;
|
|
6
|
+
/**
|
|
7
|
+
* Maps EVM chain IDs to Opensea chain
|
|
8
|
+
*
|
|
9
|
+
* @param chainId - The EVM chain ID to map
|
|
10
|
+
* @returns The corresponding OpenSea Chain enum value
|
|
11
|
+
*/
|
|
12
|
+
export declare const chainIdToOpenseaChain: (chainId: string) => Chain;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.chainIdToOpenseaChain = exports.supportedChains = void 0;
|
|
4
|
+
const opensea_js_1 = require("opensea-js");
|
|
5
|
+
/**
|
|
6
|
+
* Supported Opensea chains
|
|
7
|
+
*/
|
|
8
|
+
exports.supportedChains = {
|
|
9
|
+
"1": opensea_js_1.Chain.Mainnet,
|
|
10
|
+
"137": opensea_js_1.Chain.Polygon,
|
|
11
|
+
"80002": opensea_js_1.Chain.Amoy,
|
|
12
|
+
"11155111": opensea_js_1.Chain.Sepolia,
|
|
13
|
+
"8217": opensea_js_1.Chain.Klaytn,
|
|
14
|
+
"1001": opensea_js_1.Chain.Baobab,
|
|
15
|
+
"43114": opensea_js_1.Chain.Avalanche,
|
|
16
|
+
"43113": opensea_js_1.Chain.Fuji,
|
|
17
|
+
"42161": opensea_js_1.Chain.Arbitrum,
|
|
18
|
+
"42170": opensea_js_1.Chain.ArbitrumNova,
|
|
19
|
+
"421614": opensea_js_1.Chain.ArbitrumSepolia,
|
|
20
|
+
"238": opensea_js_1.Chain.Blast,
|
|
21
|
+
"168587773": opensea_js_1.Chain.BlastSepolia,
|
|
22
|
+
"8453": opensea_js_1.Chain.Base,
|
|
23
|
+
"84532": opensea_js_1.Chain.BaseSepolia,
|
|
24
|
+
"10": opensea_js_1.Chain.Optimism,
|
|
25
|
+
"11155420": opensea_js_1.Chain.OptimismSepolia,
|
|
26
|
+
"7777777": opensea_js_1.Chain.Zora,
|
|
27
|
+
"999999999": opensea_js_1.Chain.ZoraSepolia,
|
|
28
|
+
"1329": opensea_js_1.Chain.Sei,
|
|
29
|
+
"1328": opensea_js_1.Chain.SeiTestnet,
|
|
30
|
+
"8333": opensea_js_1.Chain.B3,
|
|
31
|
+
"1993": opensea_js_1.Chain.B3Sepolia,
|
|
32
|
+
"80094": opensea_js_1.Chain.BeraChain,
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Maps EVM chain IDs to Opensea chain
|
|
36
|
+
*
|
|
37
|
+
* @param chainId - The EVM chain ID to map
|
|
38
|
+
* @returns The corresponding OpenSea Chain enum value
|
|
39
|
+
*/
|
|
40
|
+
const chainIdToOpenseaChain = (chainId) => {
|
|
41
|
+
const chain = exports.supportedChains[chainId];
|
|
42
|
+
if (!chain) {
|
|
43
|
+
throw new Error(`Unsupported chain ID on Opensea: ${chainId}`);
|
|
44
|
+
}
|
|
45
|
+
return chain;
|
|
46
|
+
};
|
|
47
|
+
exports.chainIdToOpenseaChain = chainIdToOpenseaChain;
|
|
@@ -227,5 +227,11 @@ export declare class CdpWalletProvider extends EvmWalletProvider {
|
|
|
227
227
|
* @returns The wallet's data.
|
|
228
228
|
*/
|
|
229
229
|
exportWallet(): Promise<WalletData>;
|
|
230
|
+
/**
|
|
231
|
+
* Gets the wallet.
|
|
232
|
+
*
|
|
233
|
+
* @returns The wallet.
|
|
234
|
+
*/
|
|
235
|
+
getWallet(): Wallet;
|
|
230
236
|
}
|
|
231
237
|
export {};
|
|
@@ -381,6 +381,17 @@ class CdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
381
381
|
}
|
|
382
382
|
return __classPrivateFieldGet(this, _CdpWalletProvider_cdpWallet, "f").export();
|
|
383
383
|
}
|
|
384
|
+
/**
|
|
385
|
+
* Gets the wallet.
|
|
386
|
+
*
|
|
387
|
+
* @returns The wallet.
|
|
388
|
+
*/
|
|
389
|
+
getWallet() {
|
|
390
|
+
if (!__classPrivateFieldGet(this, _CdpWalletProvider_cdpWallet, "f")) {
|
|
391
|
+
throw new Error("Wallet not initialized");
|
|
392
|
+
}
|
|
393
|
+
return __classPrivateFieldGet(this, _CdpWalletProvider_cdpWallet, "f");
|
|
394
|
+
}
|
|
384
395
|
}
|
|
385
396
|
exports.CdpWalletProvider = CdpWalletProvider;
|
|
386
397
|
_CdpWalletProvider_cdpWallet = new WeakMap(), _CdpWalletProvider_address = new WeakMap(), _CdpWalletProvider_network = new WeakMap(), _CdpWalletProvider_publicClient = new WeakMap(), _CdpWalletProvider_gasLimitMultiplier = new WeakMap(), _CdpWalletProvider_feePerGasMultiplier = new WeakMap();
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@coinbase/agentkit",
|
|
3
3
|
"description": "Coinbase AgentKit core primitives",
|
|
4
4
|
"repository": "https://github.com/coinbase/agentkit",
|
|
5
|
-
"version": "0.2.3-nightly.
|
|
5
|
+
"version": "0.2.3-nightly.20250307.28",
|
|
6
6
|
"author": "Coinbase Inc.",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"main": "dist/index.js",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"@solana/spl-token": "^0.4.12",
|
|
47
47
|
"@solana/web3.js": "^1.98.0",
|
|
48
48
|
"md5": "^2.3.0",
|
|
49
|
+
"opensea-js": "^7.1.18",
|
|
49
50
|
"reflect-metadata": "^0.2.2",
|
|
50
51
|
"twitter-api-v2": "^1.18.2",
|
|
51
52
|
"viem": "^2.22.16",
|
|
@@ -53,21 +54,21 @@
|
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
56
|
"@types/jest": "^29.5.14",
|
|
56
|
-
"@types/secp256k1": "^4.0.6",
|
|
57
57
|
"@types/nunjucks": "^3.2.6",
|
|
58
58
|
"@types/ora": "^3.2.0",
|
|
59
59
|
"@types/prompts": "^2.4.9",
|
|
60
|
+
"@types/secp256k1": "^4.0.6",
|
|
60
61
|
"http-server": "^14.1.1",
|
|
61
62
|
"jest": "^29.7.0",
|
|
62
63
|
"mock-fs": "^5.2.0",
|
|
63
|
-
"ts-jest": "^29.2.5",
|
|
64
|
-
"tsd": "^0.31.2",
|
|
65
|
-
"typescript": "^5.7.2",
|
|
66
64
|
"nunjucks": "^3.2.4",
|
|
67
65
|
"ora": "^7.0.1",
|
|
68
|
-
"prompts": "^2.4.2",
|
|
69
66
|
"picocolors": "^1.0.0",
|
|
70
|
-
"
|
|
67
|
+
"prompts": "^2.4.2",
|
|
68
|
+
"ts-jest": "^29.2.5",
|
|
69
|
+
"tsd": "^0.31.2",
|
|
70
|
+
"tsx": "^4.7.1",
|
|
71
|
+
"typescript": "^5.7.2"
|
|
71
72
|
},
|
|
72
73
|
"exports": {
|
|
73
74
|
".": {
|