Skip to content

Commit 57f0eff

Browse files
committed
update plugin
1 parent 7817056 commit 57f0eff

File tree

10 files changed

+546
-562
lines changed

10 files changed

+546
-562
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,60 @@
1-
import { Action, IAgentRuntime, Memory } from "@elizaos/core";
2-
import { nftCollectionProvider } from "../providers/nft-collections";
1+
import { Action, IAgentRuntime, Memory, Provider } from "@elizaos/core";
32

4-
export const getCollectionsAction: Action = {
5-
name: "GET_NFT_COLLECTIONS",
6-
similes: ["LIST_NFT_COLLECTIONS", "SHOW_NFT_COLLECTIONS"],
7-
description:
8-
"Fetches information about curated NFT collections on Ethereum",
9-
validate: async (runtime: IAgentRuntime, message: Memory) => {
10-
return message.content.text.toLowerCase().includes("nft collections");
11-
},
12-
handler: async (runtime: IAgentRuntime, message: Memory) => {
13-
try {
14-
const response = await nftCollectionProvider.get(runtime, message);
15-
await runtime.messageManager.createMemory({
16-
id: message.id,
17-
content: { text: response },
18-
roomId: message.roomId,
19-
userId: message.userId,
20-
agentId: runtime.agentId,
21-
});
22-
return true;
23-
} catch (error) {
24-
console.error("Error fetching NFT collections:", error);
25-
await runtime.messageManager.createMemory({
26-
id: message.id,
27-
content: { text: "Failed to fetch NFT collection data." },
28-
roomId: message.roomId,
29-
userId: message.userId,
30-
agentId: runtime.agentId,
31-
});
32-
return false;
33-
}
34-
},
35-
examples: [
36-
[
37-
{
38-
user: "{{user1}}",
39-
content: {
40-
text: "Can you tell me about the top NFT collections?",
3+
export const getCollectionsAction = (
4+
nftCollectionProvider: Provider
5+
): Action => {
6+
return {
7+
name: "GET_NFT_COLLECTIONS",
8+
similes: ["LIST_NFT_COLLECTIONS", "SHOW_NFT_COLLECTIONS"],
9+
description:
10+
"Fetches information about curated NFT collections on Ethereum",
11+
validate: async (runtime: IAgentRuntime, message: Memory) => {
12+
return message.content.text
13+
.toLowerCase()
14+
.includes("nft collections");
15+
},
16+
handler: async (runtime: IAgentRuntime, message: Memory) => {
17+
try {
18+
const response = await nftCollectionProvider.get(
19+
runtime,
20+
message
21+
);
22+
await runtime.messageManager.createMemory({
23+
id: message.id,
24+
content: { text: response },
25+
roomId: message.roomId,
26+
userId: message.userId,
27+
agentId: runtime.agentId,
28+
});
29+
return true;
30+
} catch (error) {
31+
console.error("Error fetching NFT collections:", error);
32+
await runtime.messageManager.createMemory({
33+
id: message.id,
34+
content: { text: "Failed to fetch NFT collection data." },
35+
roomId: message.roomId,
36+
userId: message.userId,
37+
agentId: runtime.agentId,
38+
});
39+
return false;
40+
}
41+
},
42+
examples: [
43+
[
44+
{
45+
user: "{{user1}}",
46+
content: {
47+
text: "Can you tell me about the top NFT collections?",
48+
},
4149
},
42-
},
43-
{
44-
user: "{{user2}}",
45-
content: {
46-
text: "Certainly! Here are the top NFT collections on Ethereum:",
47-
action: "GET_NFT_COLLECTIONS",
50+
{
51+
user: "{{user2}}",
52+
content: {
53+
text: "Certainly! Here are the top NFT collections on Ethereum:",
54+
action: "GET_NFT_COLLECTIONS",
55+
},
4856
},
49-
},
57+
],
5058
],
51-
],
59+
};
5260
};
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Action, IAgentRuntime, Memory, State } from "@elizaos/core";
2-
import { NFTService } from "../types";
2+
import { ReservoirService } from "../services/reservoir";
33

44
// Helper function to extract NFT listing details from the message
55
function extractListingDetails(text: string): {
@@ -18,132 +18,135 @@ function extractListingDetails(text: string): {
1818
};
1919
}
2020

21-
export const listNFTAction: Action = {
22-
name: "LIST_NFT",
23-
similes: ["SELL_NFT", "CREATE_LISTING"],
24-
description:
25-
"Lists an NFT for sale on ikigailabs.xyz marketplace at double the purchase price.",
21+
export const listNFTAction = (nftService: ReservoirService): Action => {
22+
return {
23+
name: "LIST_NFT",
24+
similes: ["SELL_NFT", "CREATE_LISTING"],
25+
description:
26+
"Lists an NFT for sale on ikigailabs.xyz marketplace at double the purchase price.",
2627

27-
validate: async (runtime: IAgentRuntime, message: Memory) => {
28-
const content = message.content.text.toLowerCase();
29-
return (
30-
(content.includes("list") || content.includes("sell")) &&
31-
content.includes("nft") &&
32-
(content.includes("0x") ||
33-
content.includes("token") ||
34-
content.includes("#"))
35-
);
36-
},
28+
validate: async (runtime: IAgentRuntime, message: Memory) => {
29+
const content = message.content.text.toLowerCase();
30+
return (
31+
(content.includes("list") || content.includes("sell")) &&
32+
content.includes("nft") &&
33+
(content.includes("0x") ||
34+
content.includes("token") ||
35+
content.includes("#"))
36+
);
37+
},
3738

38-
handler: async (runtime: IAgentRuntime, message: Memory, state?: State) => {
39-
try {
40-
const {
41-
collectionAddress,
42-
tokenId,
43-
price: userSpecifiedPrice,
44-
} = extractListingDetails(message.content.text);
39+
handler: async (
40+
runtime: IAgentRuntime,
41+
message: Memory,
42+
state?: State
43+
) => {
44+
try {
45+
const {
46+
collectionAddress,
47+
tokenId,
48+
price: userSpecifiedPrice,
49+
} = extractListingDetails(message.content.text);
4550

46-
if (!collectionAddress || !tokenId) {
47-
throw new Error(
48-
"Please provide the collection address and token ID"
49-
);
50-
}
51+
if (!collectionAddress || !tokenId) {
52+
throw new Error(
53+
"Please provide the collection address and token ID"
54+
);
55+
}
5156

52-
const nftService = runtime.services.get(
53-
"nft" as any
54-
) as unknown as NFTService;
55-
if (!nftService) {
56-
throw new Error("NFT service not found");
57-
}
57+
if (!nftService) {
58+
throw new Error("NFT service not found");
59+
}
5860

59-
// Verify ownership before listing
60-
const ownedNFTs = await nftService.getOwnedNFTs(message.userId);
61-
const ownedNFT = ownedNFTs.find(
62-
(nft) =>
63-
nft.collectionAddress.toLowerCase() ===
64-
collectionAddress.toLowerCase() &&
65-
nft.tokenId === tokenId
66-
);
61+
// Verify ownership before listing
62+
const ownedNFTs = await nftService.getOwnedNFTs(message.userId);
63+
const ownedNFT = ownedNFTs.find(
64+
(nft) =>
65+
nft.collectionAddress.toLowerCase() ===
66+
collectionAddress.toLowerCase() &&
67+
nft.tokenId === tokenId
68+
);
6769

68-
if (!ownedNFT) {
69-
throw new Error("You don't own this NFT");
70-
}
70+
if (!ownedNFT) {
71+
throw new Error("You don't own this NFT");
72+
}
7173

72-
// Create the listing on ikigailabs
73-
const listing = await nftService.createListing({
74-
tokenId,
75-
collectionAddress,
76-
price: userSpecifiedPrice || 0, // Default to 0 if no price specified
77-
marketplace: "ikigailabs",
78-
expirationTime:
79-
Math.floor(Date.now() / 1000) + 30 * 24 * 60 * 60, // 30 days
80-
});
74+
// Create the listing on ikigailabs
75+
const listing = await nftService.createListing({
76+
tokenId,
77+
collectionAddress,
78+
price: userSpecifiedPrice || 0, // Default to 0 if no price specified
79+
marketplace: "ikigailabs",
80+
expirationTime:
81+
Math.floor(Date.now() / 1000) + 30 * 24 * 60 * 60, // 30 days
82+
});
8183

82-
const response =
83-
`Successfully created listing on ikigailabs.xyz:\n` +
84-
`• Collection: ${collectionAddress}\n` +
85-
`• Token ID: ${tokenId}\n` +
86-
`• Listing Price: ${userSpecifiedPrice} ETH\n` +
87-
`• Status: ${listing.status}\n` +
88-
`• Listing URL: ${listing.marketplaceUrl}\n` +
89-
(listing.transactionHash
90-
? `• Transaction: ${listing.transactionHash}\n`
91-
: "");
84+
const response =
85+
`Successfully created listing on ikigailabs.xyz:\n` +
86+
`• Collection: ${collectionAddress}\n` +
87+
`• Token ID: ${tokenId}\n` +
88+
`• Listing Price: ${userSpecifiedPrice} ETH\n` +
89+
`• Status: ${listing.status}\n` +
90+
`• Listing URL: ${listing.marketplaceUrl}\n` +
91+
(listing.transactionHash
92+
? `• Transaction: ${listing.transactionHash}\n`
93+
: "");
9294

93-
await runtime.messageManager.createMemory({
94-
id: message.id,
95-
content: { text: response },
96-
roomId: message.roomId,
97-
userId: message.userId,
98-
agentId: runtime.agentId,
99-
});
95+
await runtime.messageManager.createMemory({
96+
id: message.id,
97+
content: { text: response },
98+
roomId: message.roomId,
99+
userId: message.userId,
100+
agentId: runtime.agentId,
101+
});
100102

101-
return true;
102-
} catch (error) {
103-
console.error("NFT listing failed:", error);
104-
await runtime.messageManager.createMemory({
105-
id: message.id,
106-
content: {
107-
text: `Failed to list NFT: ${error.message}`,
108-
},
109-
roomId: message.roomId,
110-
userId: message.userId,
111-
agentId: runtime.agentId,
112-
});
113-
return false;
114-
}
115-
},
103+
return true;
104+
} catch (error) {
105+
console.error("NFT listing failed:", error);
106+
await runtime.messageManager.createMemory({
107+
id: message.id,
108+
content: {
109+
text: `Failed to list NFT: ${error.message}`,
110+
},
111+
roomId: message.roomId,
112+
userId: message.userId,
113+
agentId: runtime.agentId,
114+
});
115+
return false;
116+
}
117+
},
116118

117-
examples: [
118-
[
119-
{
120-
user: "{{user1}}",
121-
content: {
122-
text: "List token #123 from collection 0x1234...abcd",
119+
examples: [
120+
[
121+
{
122+
user: "{{user1}}",
123+
content: {
124+
text: "List token #123 from collection 0x1234...abcd",
125+
},
123126
},
124-
},
125-
{
126-
user: "{{user2}}",
127-
content: {
128-
text: "Creating listing on ikigailabs.xyz at 2x purchase price...",
129-
action: "LIST_NFT",
127+
{
128+
user: "{{user2}}",
129+
content: {
130+
text: "Creating listing on ikigailabs.xyz at 2x purchase price...",
131+
action: "LIST_NFT",
132+
},
130133
},
131-
},
132-
],
133-
[
134-
{
135-
user: "{{user1}}",
136-
content: {
137-
text: "List token #123 from collection 0x1234...abcd for 5 ETH",
134+
],
135+
[
136+
{
137+
user: "{{user1}}",
138+
content: {
139+
text: "List token #123 from collection 0x1234...abcd for 5 ETH",
140+
},
138141
},
139-
},
140-
{
141-
user: "{{user2}}",
142-
content: {
143-
text: "Creating listing on ikigailabs.xyz with specified price...",
144-
action: "LIST_NFT",
142+
{
143+
user: "{{user2}}",
144+
content: {
145+
text: "Creating listing on ikigailabs.xyz with specified price...",
146+
action: "LIST_NFT",
147+
},
145148
},
146-
},
149+
],
147150
],
148-
],
151+
};
149152
};

0 commit comments

Comments
 (0)