1
1
import { Action , IAgentRuntime , Memory , State } from "@elizaos/core" ;
2
- import { NFTService } from "../types " ;
2
+ import { ReservoirService } from "../services/reservoir " ;
3
3
4
4
// Helper function to extract NFT listing details from the message
5
5
function extractListingDetails ( text : string ) : {
@@ -18,132 +18,135 @@ function extractListingDetails(text: string): {
18
18
} ;
19
19
}
20
20
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." ,
26
27
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
+ } ,
37
38
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 ) ;
45
50
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
+ }
51
56
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
+ }
58
60
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
+ ) ;
67
69
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
+ }
71
73
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
+ } ) ;
81
83
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
+ : "" ) ;
92
94
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
+ } ) ;
100
102
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
+ } ,
116
118
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
+ } ,
123
126
} ,
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
+ } ,
130
133
} ,
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
+ } ,
138
141
} ,
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
+ } ,
145
148
} ,
146
- } ,
149
+ ] ,
147
150
] ,
148
- ] ,
151
+ } ;
149
152
} ;
0 commit comments