Skip to content

Commit a3d8a5c

Browse files
committed
update to use correct endpoint
1 parent d4a0a4e commit a3d8a5c

File tree

2 files changed

+51
-45
lines changed

2 files changed

+51
-45
lines changed

components/opensea/opensea.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default {
3131
collectionSlug, ...opts
3232
}) {
3333
return this._makeRequest({
34-
path: `/listings/collection/${collectionSlug}/all`,
34+
path: `/events/collection/${collectionSlug}`,
3535
...opts,
3636
});
3737
},

components/opensea/sources/new-collection-events/new-collection-events.mjs

Lines changed: 50 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
44
export default {
55
key: "opensea-new-collection-events",
66
name: "New Collection Events",
7-
description: "Emit new listings for a collection. [See the documentation](https://docs.opensea.io/reference/get_all_listings_on_collection_v2)",
7+
description: "Emit new filtered events for a collection. [See the documentation](https://docs.opensea.io/reference/list_events_by_collection)",
88
version: "0.0.4",
99
dedupe: "unique",
1010
type: "source",
@@ -22,61 +22,67 @@ export default {
2222
label: "Collection Slug",
2323
description: "Unique string to identify a collection on OpenSea. This can be found by visiting the collection on the OpenSea website and noting the last path parameter.",
2424
},
25+
eventType: {
26+
type: "string[]",
27+
options: [
28+
"all",
29+
"cancel",
30+
"listing",
31+
"offer",
32+
"order",
33+
"redemption",
34+
"sale",
35+
"transfer",
36+
],
37+
label: "Event Type",
38+
description: "The type of event to filter by. If not provided, only sales will be returned.",
39+
optional: true,
40+
},
2541
},
2642
methods: {
27-
_getNextCursor() {
28-
return this.db.get("nextCursor");
29-
},
30-
_setNextCursor(nextCursor) {
31-
this.db.set("nextCursor", nextCursor);
32-
},
33-
async getPaginatedCollectionEvents() {
34-
const args = {
35-
collectionSlug: this.collectionSlug,
36-
params: {
37-
limit: 100,
38-
next: this._getNextCursor(),
39-
},
40-
};
41-
42-
let lastNextCursor, total = 0;
43-
const results = [];
44-
45-
do {
46-
const {
47-
listings, next,
48-
} = await this.opensea.retrieveEvents(args);
49-
results.push(...listings);
50-
total = listings?.length;
51-
lastNextCursor = args.params.next;
52-
args.params.next = next;
53-
} while (total && args.params?.next);
54-
55-
this._setNextCursor(lastNextCursor);
56-
return results;
43+
_getLastTimestamp() {
44+
return this.db.get("lastTimestamp");
5745
},
58-
emitEvents(items) {
59-
items.forEach((item) => {
60-
const meta = this.generateMeta(item);
61-
this.$emit(item, meta);
62-
});
46+
_setLastTimestamp(ts) {
47+
this.db.set("lastTimestamp", ts);
6348
},
64-
generateMeta(item) {
49+
generateMeta(event) {
6550
return {
66-
id: item.order_hash,
67-
summary: `New ${item.type} ${item.chain} Listing`,
68-
ts: item.protocol_data.parameters.startTime,
51+
id: event.order_hash,
52+
summary: `${event.asset.name || event.nft.name} ${this.eventType} event`,
53+
ts: event.event_timestamp,
6954
};
7055
},
7156
async processEvent(max) {
72-
let items = await this.getPaginatedCollectionEvents();
73-
if (!items?.length) {
57+
const lastTimestamp = this._getLastTimestamp();
58+
let next = null;
59+
let events = [];
60+
do {
61+
const resp = await this.opensea.retrieveEvents({
62+
collectionSlug: this.collectionSlug,
63+
params: {
64+
event_type: this.eventType,
65+
after: lastTimestamp,
66+
next,
67+
},
68+
});
69+
if (!resp?.asset_events) {
70+
break;
71+
}
72+
events.push(...resp.asset_events);
73+
next = resp.next;
74+
} while (lastTimestamp && next);
75+
76+
if (!events.length) {
7477
return;
7578
}
79+
this._setLastTimestamp(events[0].event_timestamp);
7680
if (max) {
77-
items = items.slice(-1 * max);
81+
events = events.slice(0, max);
7882
}
79-
this.emitEvents(items);
83+
events.reverse().forEach((event) => {
84+
this.$emit(event, this.generateMeta(event));
85+
});
8086
},
8187
},
8288
hooks: {

0 commit comments

Comments
 (0)