Skip to content

Commit 5484548

Browse files
committed
feat(nft-collections): Implement createListing method in ReservoirService
- Add comprehensive createListing method for Reservoir API - Include parameter validation and default values - Implement error handling and performance monitoring - Generate marketplace URL for listed token
1 parent d7d0e72 commit 5484548

File tree

1 file changed

+71
-6
lines changed

1 file changed

+71
-6
lines changed

packages/plugin-nft-collections/src/services/reservoir.ts

+71-6
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,77 @@ export class ReservoirService {
280280
transactionHash?: string;
281281
marketplaceUrl: string;
282282
}> {
283-
return Promise.resolve({
284-
listingId: "",
285-
status: "",
286-
transactionHash: undefined,
287-
marketplaceUrl: "",
288-
});
283+
const endOperation = this.performanceMonitor.startOperation(
284+
"createListing",
285+
{ options }
286+
);
287+
288+
try {
289+
// Validate required parameters
290+
if (
291+
!options.tokenId ||
292+
!options.collectionAddress ||
293+
!options.price
294+
) {
295+
throw new Error("Missing required listing parameters");
296+
}
297+
298+
// Default values
299+
const currency = options.currency || "ETH";
300+
const quantity = options.quantity || 1;
301+
const expirationTime =
302+
options.expirationTime ||
303+
Math.floor(Date.now() / 1000) + 30 * 24 * 60 * 60; // 30 days from now
304+
305+
const listingParams = {
306+
maker: "", // Will be set by runtime or current wallet
307+
token: `${options.collectionAddress}:${options.tokenId}`,
308+
quantity: quantity.toString(),
309+
price: options.price.toString(),
310+
currency,
311+
expirationTime: expirationTime.toString(),
312+
};
313+
314+
const response = await this.makeRequest<{
315+
listing: {
316+
id: string;
317+
status: string;
318+
transactionHash?: string;
319+
};
320+
}>("/listings/v5/create", listingParams, 1, {} as IAgentRuntime);
321+
322+
const result = {
323+
listingId: response.listing.id,
324+
status: response.listing.status,
325+
transactionHash: response.listing.transactionHash,
326+
marketplaceUrl: `https://reservoir.market/collections/${options.collectionAddress}/tokens/${options.tokenId}`,
327+
};
328+
329+
endOperation();
330+
return result;
331+
} catch (error) {
332+
this.performanceMonitor.recordMetric({
333+
operation: "createListing",
334+
duration: 0,
335+
success: false,
336+
metadata: { error: error.message, options },
337+
});
338+
339+
const nftError = NFTErrorFactory.create(
340+
ErrorType.API,
341+
ErrorCode.API_ERROR,
342+
"Failed to create NFT listing",
343+
{
344+
originalError: error,
345+
collectionAddress: options.collectionAddress,
346+
tokenId: options.tokenId,
347+
},
348+
true
349+
);
350+
this.errorHandler.handleError(nftError);
351+
352+
throw error;
353+
}
289354
}
290355

291356
async cancelListing(options: {

0 commit comments

Comments
 (0)