-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathindex.js
More file actions
355 lines (311 loc) · 10.8 KB
/
index.js
File metadata and controls
355 lines (311 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/**
* Giftstat plugin -- Telegram gift market data from giftstat.app
*
* Provides real-time and historical data on Telegram gift collections,
* floor prices, model variants, backdrops, symbols, and TON exchange rates.
* All data comes from the public Giftstat API (no auth required).
*/
const API_BASE = "https://api.giftstat.app";
// Shared fetch helper. Builds the URL, attaches query params, and returns
// parsed JSON. Throws on non-2xx responses so callers can catch uniformly.
async function giftstatFetch(path, params = {}) {
const url = new URL(path, API_BASE);
for (const [key, value] of Object.entries(params)) {
if (value !== undefined && value !== null) {
url.searchParams.set(key, String(value));
}
}
const res = await fetch(url, { signal: AbortSignal.timeout(15000) });
if (!res.ok) {
throw new Error(`Giftstat API error: ${res.status} ${res.statusText}`);
}
return res.json();
}
// ---------------------------------------------------------------------------
// Pagination schema fragment -- reused by most tools
// ---------------------------------------------------------------------------
const paginationProps = {
limit: {
type: "integer",
description: "Maximum number of results to return",
},
offset: {
type: "integer",
description: "Number of results to skip (for pagination)",
},
};
// ---------------------------------------------------------------------------
// Factory for simple paginated endpoints (limit + offset only)
// ---------------------------------------------------------------------------
function makePaginatedTool(name, description, path, sdk) {
return {
name,
description,
category: "data-bearing",
scope: "always",
parameters: {
type: "object",
properties: { ...paginationProps },
},
execute: async (params) => {
try {
const result = await giftstatFetch(path, {
limit: params.limit,
offset: params.offset,
});
return { success: true, data: result };
} catch (err) {
sdk.log.error(`${name}:`, err.message);
return { success: false, error: String(err.message || err).slice(0, 500) };
}
},
};
}
// ---------------------------------------------------------------------------
// Export -- SDK wrapper
// ---------------------------------------------------------------------------
export const manifest = {
name: "giftstat",
version: "1.0.1",
sdkVersion: ">=1.0.0",
description: "Telegram gift market data -- collections, floor prices, models, stats, history",
};
export const tools = (sdk) => {
// ---------------------------------------------------------------------------
// Tool 1: gift_collections
// Lists all gift collections with supply, pricing, and mint data.
// ---------------------------------------------------------------------------
const giftCollections = {
name: "gift_collections",
description:
"List all Telegram gift collections with supply, pricing, and mint data. Use to browse available collections or check if a collection is sold out.",
category: "data-bearing",
scope: "always",
parameters: {
type: "object",
properties: {
fields: {
type: "string",
description: "Comma-separated list of fields to return (filters the response)",
},
...paginationProps,
},
},
execute: async (params) => {
try {
const result = await giftstatFetch("/current/collections", {
fields: params.fields,
limit: params.limit,
offset: params.offset,
});
return { success: true, data: result };
} catch (err) {
sdk.log.error("gift_collections:", err.message);
return { success: false, error: String(err.message || err).slice(0, 500) };
}
},
};
// ---------------------------------------------------------------------------
// Tool 2: gift_floor_prices
// Floor prices per marketplace. Has an extra marketplace param.
// ---------------------------------------------------------------------------
const giftFloorPrices = {
name: "gift_floor_prices",
description:
"Get current floor prices for gift collections on a specific marketplace. Supports portals, tonnel, fragment, and getgems.",
category: "data-bearing",
scope: "always",
parameters: {
type: "object",
properties: {
marketplace: {
type: "string",
enum: ["portals", "tonnel", "fragment", "getgems"],
description: "Marketplace to query (default: portals)",
},
...paginationProps,
},
},
execute: async (params) => {
try {
const result = await giftstatFetch("/current/collections/floor", {
marketplace: params.marketplace ?? "portals",
limit: params.limit,
offset: params.offset,
});
return { success: true, data: result };
} catch (err) {
sdk.log.error("gift_floor_prices:", err.message);
return { success: false, error: String(err.message || err).slice(0, 500) };
}
},
};
// ---------------------------------------------------------------------------
// Tool 3: gift_models
// Model variants with rarity levels.
// ---------------------------------------------------------------------------
const giftModels = makePaginatedTool(
"gift_models",
"List gift model variants with their rarity levels. Models are the specific visual variants within a collection.",
"/current/collections/models",
sdk,
);
// ---------------------------------------------------------------------------
// Tool 4: gift_model_stats
// Per-model statistics: count, total amount, rarity, market share.
// ---------------------------------------------------------------------------
const giftModelStats = makePaginatedTool(
"gift_model_stats",
"Get statistics per gift model: count, total amount, rarity, and market share percentage.",
"/current/collections/models/stat",
sdk,
);
// ---------------------------------------------------------------------------
// Tool 5: gift_model_floor
// Floor price for each model variant.
// ---------------------------------------------------------------------------
const giftModelFloor = makePaginatedTool(
"gift_model_floor",
"Get the current floor price for each gift model variant.",
"/current/collections/models/floor",
sdk,
);
// ---------------------------------------------------------------------------
// Tool 6: gift_backdrops
// Background variants with rarity data.
// ---------------------------------------------------------------------------
const giftBackdrops = makePaginatedTool(
"gift_backdrops",
"List available gift background variants with rarity data.",
"/current/collections/backdrops",
sdk,
);
// ---------------------------------------------------------------------------
// Tool 7: gift_symbols
// Symbol/pattern variants with rarity data.
// ---------------------------------------------------------------------------
const giftSymbols = makePaginatedTool(
"gift_symbols",
"List available gift symbol/pattern variants with rarity data.",
"/current/collections/symbols",
sdk,
);
// ---------------------------------------------------------------------------
// Tool 8: gift_thematics
// Thematic gift categories. No params at all.
// ---------------------------------------------------------------------------
const giftThematics = {
name: "gift_thematics",
description: "List all thematic gift categories.",
category: "data-bearing",
scope: "always",
parameters: {
type: "object",
properties: {},
},
execute: async () => {
try {
const result = await giftstatFetch("/current/thematics");
return { success: true, data: result };
} catch (err) {
sdk.log.error("gift_thematics:", err.message);
return { success: false, error: String(err.message || err).slice(0, 500) };
}
},
};
// ---------------------------------------------------------------------------
// Tool 9: gift_thematic_lines
// Lines grouped by thematic category. Paginated.
// ---------------------------------------------------------------------------
const giftThematicLines = makePaginatedTool(
"gift_thematic_lines",
"List curated gift lines grouped by thematic category.",
"/current/thematics/lines",
sdk,
);
// ---------------------------------------------------------------------------
// Tool 10: gift_ton_rate
// Current TON/USDT exchange rate. No params.
// ---------------------------------------------------------------------------
const giftTonRate = {
name: "gift_ton_rate",
description: "Get the current TON to USDT exchange rate.",
category: "data-bearing",
scope: "always",
parameters: {
type: "object",
properties: {},
},
execute: async () => {
try {
const result = await giftstatFetch("/current/ton-rate");
return { success: true, data: result };
} catch (err) {
sdk.log.error("gift_ton_rate:", err.message);
return { success: false, error: String(err.message || err).slice(0, 500) };
}
},
};
// ---------------------------------------------------------------------------
// Tool 11: gift_price_history
// Historical floor prices. Extra params: marketplace, scale, days.
// ---------------------------------------------------------------------------
const giftPriceHistory = {
name: "gift_price_history",
description:
"Get historical floor price data for gift collections. Supports different time scales and date ranges.",
category: "data-bearing",
scope: "always",
parameters: {
type: "object",
properties: {
marketplace: {
type: "string",
enum: ["portals", "tonnel", "getgems"],
description: "Marketplace to query (default: portals)",
},
scale: {
type: "string",
enum: ["day", "hour"],
description: "Time granularity for data points (default: day)",
},
days: {
type: "integer",
description: "Number of days of history to return",
},
...paginationProps,
},
},
execute: async (params) => {
try {
const result = await giftstatFetch("/history/collections/floor", {
marketplace: params.marketplace ?? "portals",
scale: params.scale ?? "day",
days: params.days,
limit: params.limit,
offset: params.offset,
});
return { success: true, data: result };
} catch (err) {
sdk.log.error("gift_price_history:", err.message);
return { success: false, error: String(err.message || err).slice(0, 500) };
}
},
};
// ---------------------------------------------------------------------------
// Return tools array
// ---------------------------------------------------------------------------
return [
giftCollections,
giftFloorPrices,
giftModels,
giftModelStats,
giftModelFloor,
giftBackdrops,
giftSymbols,
giftThematics,
giftThematicLines,
giftTonRate,
giftPriceHistory,
];
}; // end tools(sdk)