logiqical 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,508 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ DexModule: () => DexModule,
24
+ LaunchpadModule: () => LaunchpadModule,
25
+ LogiqicalAuthError: () => LogiqicalAuthError,
26
+ LogiqicalClient: () => LogiqicalClient,
27
+ LogiqicalError: () => LogiqicalError,
28
+ StakingModule: () => StakingModule,
29
+ SwapModule: () => SwapModule
30
+ });
31
+ module.exports = __toCommonJS(index_exports);
32
+
33
+ // src/errors.ts
34
+ var LogiqicalError = class extends Error {
35
+ constructor(message, statusCode, endpoint) {
36
+ super(message);
37
+ this.statusCode = statusCode;
38
+ this.endpoint = endpoint;
39
+ this.name = "LogiqicalError";
40
+ }
41
+ };
42
+ var LogiqicalAuthError = class extends LogiqicalError {
43
+ constructor(endpoint) {
44
+ super("Invalid or missing API key. Call client.register() or provide an apiKey in config.", 401, endpoint);
45
+ this.name = "LogiqicalAuthError";
46
+ }
47
+ };
48
+
49
+ // src/http.ts
50
+ var HttpClient = class {
51
+ constructor(baseUrl, apiKey) {
52
+ this.baseUrl = baseUrl;
53
+ this.apiKey = apiKey ?? null;
54
+ }
55
+ apiKey;
56
+ setApiKey(key) {
57
+ this.apiKey = key;
58
+ }
59
+ getApiKey() {
60
+ return this.apiKey;
61
+ }
62
+ async get(path, params, skipAuth = false) {
63
+ const url = new URL(path, this.baseUrl);
64
+ if (params) {
65
+ for (const [k, v] of Object.entries(params)) {
66
+ if (v !== void 0) url.searchParams.set(k, String(v));
67
+ }
68
+ }
69
+ const headers = {};
70
+ if (!skipAuth && this.apiKey) headers["X-API-Key"] = this.apiKey;
71
+ const res = await fetch(url.toString(), { headers });
72
+ return this.handleResponse(res, path);
73
+ }
74
+ async post(path, body) {
75
+ const url = new URL(path, this.baseUrl);
76
+ const headers = { "Content-Type": "application/json" };
77
+ if (this.apiKey) headers["X-API-Key"] = this.apiKey;
78
+ const res = await fetch(url.toString(), { method: "POST", headers, body: JSON.stringify(body) });
79
+ return this.handleResponse(res, path);
80
+ }
81
+ async handleResponse(res, endpoint) {
82
+ if (res.status === 401) throw new LogiqicalAuthError(endpoint);
83
+ const data = await res.json().catch(() => null);
84
+ if (!res.ok) {
85
+ const msg = data?.error ?? `HTTP ${res.status}`;
86
+ throw new LogiqicalError(msg, res.status, endpoint);
87
+ }
88
+ return data;
89
+ }
90
+ };
91
+
92
+ // src/modules/swap.ts
93
+ var SwapModule = class {
94
+ constructor(http, auth) {
95
+ this.http = http;
96
+ this.auth = auth;
97
+ }
98
+ /**
99
+ * Get AVAX and ARENA token balances for a wallet.
100
+ * @param wallet - Wallet address to check
101
+ */
102
+ async getBalances(wallet) {
103
+ await this.auth();
104
+ return this.http.get("/balances", { wallet });
105
+ }
106
+ /**
107
+ * Quote how much ARENA you get for a given amount of AVAX.
108
+ * @param avax - Amount of AVAX to spend
109
+ */
110
+ async quote(avax) {
111
+ await this.auth();
112
+ return this.http.get("/quote", { avax });
113
+ }
114
+ /**
115
+ * Quote how much AVAX you get for selling a given amount of ARENA.
116
+ * @param arena - Amount of ARENA to sell
117
+ */
118
+ async sellQuote(arena) {
119
+ await this.auth();
120
+ return this.http.get("/quote/sell", { arena });
121
+ }
122
+ /**
123
+ * Build unsigned transaction to buy ARENA with AVAX.
124
+ *
125
+ * Sign the transaction, then broadcast via `client.broadcast()`.
126
+ *
127
+ * @param wallet - Your wallet address
128
+ * @param avax - Amount of AVAX to spend
129
+ * @param slippage - Slippage tolerance in basis points (default: 500 = 5%)
130
+ */
131
+ async buildBuy(wallet, avax, slippage) {
132
+ await this.auth();
133
+ return this.http.get("/build/buy", { wallet, avax, slippage });
134
+ }
135
+ /**
136
+ * Build unsigned transactions to sell ARENA for AVAX.
137
+ *
138
+ * Returns 2 transactions — execute in order:
139
+ * 1. Approve — allows the DEX router to spend your ARENA
140
+ * 2. Swap — executes the ARENA → AVAX swap
141
+ *
142
+ * Sign each, broadcast via `client.broadcast()`, wait for confirmation before the next.
143
+ *
144
+ * @param wallet - Your wallet address
145
+ * @param amount - Amount of ARENA to sell, or "max" for entire balance
146
+ * @param slippage - Slippage tolerance in basis points (default: 500 = 5%)
147
+ */
148
+ async buildSell(wallet, amount, slippage) {
149
+ await this.auth();
150
+ return this.http.get("/build/sell-arena", { wallet, amount, slippage });
151
+ }
152
+ };
153
+
154
+ // src/modules/staking.ts
155
+ var StakingModule = class {
156
+ constructor(http, auth) {
157
+ this.http = http;
158
+ this.auth = auth;
159
+ }
160
+ /**
161
+ * Get staking info for a wallet — staked amount, pending rewards, APY.
162
+ * @param wallet - Wallet address to check
163
+ */
164
+ async getInfo(wallet) {
165
+ await this.auth();
166
+ return this.http.get("/stake/info", { wallet });
167
+ }
168
+ /**
169
+ * Build unsigned transactions to stake ARENA tokens.
170
+ *
171
+ * Returns 2 transactions — execute in order:
172
+ * 1. Approve — allows the staking contract to spend your ARENA
173
+ * 2. Stake — deposits ARENA into staking
174
+ *
175
+ * @param wallet - Your wallet address
176
+ * @param amount - Amount of ARENA to stake
177
+ */
178
+ async buildStake(wallet, amount) {
179
+ await this.auth();
180
+ return this.http.get("/build/stake", { wallet, amount });
181
+ }
182
+ /**
183
+ * Build unsigned transactions to buy ARENA with AVAX and stake in one flow.
184
+ *
185
+ * Combines swap + approve + stake. Returns multiple transactions — execute in order.
186
+ *
187
+ * @param wallet - Your wallet address
188
+ * @param avax - Amount of AVAX to spend
189
+ * @param slippage - Slippage tolerance in basis points (default: 500 = 5%)
190
+ */
191
+ async buildBuyAndStake(wallet, avax, slippage) {
192
+ await this.auth();
193
+ return this.http.get("/build/buy-and-stake", { wallet, avax, slippage });
194
+ }
195
+ /**
196
+ * Build unsigned transaction to unstake ARENA tokens and claim rewards.
197
+ * @param wallet - Your wallet address
198
+ * @param amount - Amount of ARENA to unstake
199
+ */
200
+ async buildUnstake(wallet, amount) {
201
+ await this.auth();
202
+ return this.http.get("/build/unstake", { wallet, amount });
203
+ }
204
+ };
205
+
206
+ // src/modules/launchpad.ts
207
+ var LaunchpadModule = class {
208
+ constructor(http, auth) {
209
+ this.http = http;
210
+ this.auth = auth;
211
+ }
212
+ // ── Discovery ──
213
+ /**
214
+ * Get recently launched tokens on Arena.
215
+ * @param count - Number of tokens (max 50, default 10)
216
+ * @param type - Filter: "all", "avax" (AVAX-paired), or "arena" (ARENA-paired)
217
+ */
218
+ async getRecent(count, type) {
219
+ await this.auth();
220
+ return this.http.get("/launchpad/recent", { count, type });
221
+ }
222
+ /**
223
+ * Search for a token by name, symbol, or contract address.
224
+ * @param q - Search query — name, symbol, or 0x contract address
225
+ */
226
+ async search(q) {
227
+ await this.auth();
228
+ return this.http.get("/launchpad/search", { q });
229
+ }
230
+ /**
231
+ * Get tokens that are closest to graduating from the bonding curve to DEX.
232
+ * @param count - Number of tokens (max 20, default 5)
233
+ */
234
+ async getGraduating(count) {
235
+ await this.auth();
236
+ return this.http.get("/launchpad/graduating", { count });
237
+ }
238
+ /**
239
+ * Get tokens that have already graduated from the bonding curve to DEX.
240
+ * @param count - Number of tokens (max 50, default 10)
241
+ */
242
+ async getGraduated(count) {
243
+ await this.auth();
244
+ return this.http.get("/launchpad/graduated", { count });
245
+ }
246
+ /**
247
+ * Get top tokens by trading volume.
248
+ * @param timeframe - "5m", "1h", "4h", "24h", or "all_time"
249
+ * @param count - Number of tokens (max 50, default 10)
250
+ */
251
+ async getTopVolume(timeframe, count) {
252
+ await this.auth();
253
+ return this.http.get("/launchpad/top-volume", { timeframe, count });
254
+ }
255
+ // ── Intelligence ──
256
+ /**
257
+ * Get full token profile with stats — price, market cap, graduation progress, buy/sell activity.
258
+ * @param tokenId - Arena token ID
259
+ * @param address - Or token contract address (0x...)
260
+ */
261
+ async getToken(tokenId, address) {
262
+ await this.auth();
263
+ return this.http.get("/launchpad/token", { tokenId, address });
264
+ }
265
+ /**
266
+ * Get a buy or sell quote for a bonding curve token.
267
+ * @param tokenId - Arena token ID
268
+ * @param side - "buy" or "sell"
269
+ * @param amount - For buy: AVAX amount. For sell: token amount.
270
+ */
271
+ async quote(tokenId, side, amount) {
272
+ await this.auth();
273
+ const params = { tokenId, side };
274
+ if (side === "buy") params.avax = amount;
275
+ else params.tokenAmount = amount;
276
+ return this.http.get("/launchpad/quote", params);
277
+ }
278
+ /**
279
+ * Get agent's tracked portfolio — all launchpad tokens the agent has bought.
280
+ * @param wallet - Agent wallet address
281
+ */
282
+ async getPortfolio(wallet) {
283
+ await this.auth();
284
+ return this.http.get("/launchpad/portfolio", { wallet });
285
+ }
286
+ /**
287
+ * Get market cap data for a token.
288
+ * @param tokenId - Arena token ID
289
+ */
290
+ async getMarketCap(tokenId) {
291
+ await this.auth();
292
+ return this.http.get("/launchpad/market-cap", { tokenId });
293
+ }
294
+ /**
295
+ * Get recent trade activity for a token.
296
+ * @param tokenId - Arena token ID
297
+ * @param address - Or token contract address
298
+ * @param count - Number of trades (max 50, default 20)
299
+ */
300
+ async getActivity(tokenId, address, count) {
301
+ await this.auth();
302
+ return this.http.get("/launchpad/activity", { tokenId, address, count });
303
+ }
304
+ /**
305
+ * Get top holders for a token with PnL data.
306
+ * @param address - Token contract address
307
+ * @param tokenId - Or Arena token ID
308
+ * @param count - Number of holders (max 50, default 20)
309
+ */
310
+ async getHolders(address, tokenId, count) {
311
+ await this.auth();
312
+ return this.http.get("/launchpad/holders", { address, tokenId, count });
313
+ }
314
+ /**
315
+ * Get platform overview — total tokens launched, contract addresses, stats.
316
+ */
317
+ async getOverview() {
318
+ await this.auth();
319
+ return this.http.get("/launchpad/overview");
320
+ }
321
+ /**
322
+ * Get the global trade feed across all launchpad tokens.
323
+ * @param count - Number of trades (max 100, default 50)
324
+ * @param offset - Pagination offset
325
+ */
326
+ async getTrades(count, offset) {
327
+ await this.auth();
328
+ return this.http.get("/launchpad/trades", { count, offset });
329
+ }
330
+ // ── Trading ──
331
+ /**
332
+ * Build unsigned transaction to buy a launchpad token with AVAX.
333
+ *
334
+ * Auto-detects if the token is AVAX-paired or ARENA-paired and routes accordingly.
335
+ * If the token has graduated to DEX, returns transactions for DEX swap instead.
336
+ *
337
+ * @param wallet - Your wallet address
338
+ * @param tokenId - Arena token ID
339
+ * @param avax - Amount of AVAX to spend
340
+ * @param slippage - Slippage in basis points (default: 500 = 5%)
341
+ */
342
+ async buildBuy(wallet, tokenId, avax, slippage) {
343
+ await this.auth();
344
+ return this.http.get("/launchpad/build/buy", { wallet, tokenId, avax, slippage });
345
+ }
346
+ /**
347
+ * Build unsigned transaction(s) to sell a launchpad token.
348
+ *
349
+ * Returns approve + sell transactions. Execute in order.
350
+ * Use amount="max" to sell entire balance.
351
+ *
352
+ * If the token has graduated to DEX, returns transactions for DEX swap instead.
353
+ *
354
+ * @param wallet - Your wallet address
355
+ * @param tokenId - Arena token ID
356
+ * @param amount - Token amount to sell, or "max" for entire balance
357
+ * @param slippage - Slippage in basis points (default: 500 = 5%)
358
+ */
359
+ async buildSell(wallet, tokenId, amount, slippage) {
360
+ await this.auth();
361
+ return this.http.get("/launchpad/build/sell", { wallet, tokenId, amount, slippage });
362
+ }
363
+ };
364
+
365
+ // src/modules/dex.ts
366
+ var DexModule = class {
367
+ constructor(http, auth) {
368
+ this.http = http;
369
+ this.auth = auth;
370
+ }
371
+ /**
372
+ * List all known tokens with addresses and decimals.
373
+ * You can also pass any contract address directly to other methods — not limited to this list.
374
+ */
375
+ async getTokens() {
376
+ await this.auth();
377
+ return this.http.get("/dex/tokens");
378
+ }
379
+ /**
380
+ * Get on-chain info for any token by contract address — name, symbol, decimals.
381
+ * @param address - Token contract address (0x...)
382
+ */
383
+ async getTokenInfo(address) {
384
+ await this.auth();
385
+ return this.http.get("/dex/token-info", { address });
386
+ }
387
+ /**
388
+ * Quote a swap between any two tokens on Avalanche.
389
+ * @param from - Source token symbol or contract address
390
+ * @param to - Destination token symbol or contract address
391
+ * @param amount - Amount of source token to swap
392
+ */
393
+ async quote(from, to, amount) {
394
+ await this.auth();
395
+ return this.http.get("/dex/quote", { from, to, amount });
396
+ }
397
+ /**
398
+ * Get the balance of any token for a wallet.
399
+ * @param wallet - Wallet address
400
+ * @param token - Token symbol or contract address
401
+ */
402
+ async getBalance(wallet, token) {
403
+ await this.auth();
404
+ return this.http.get("/dex/balance", { wallet, token });
405
+ }
406
+ /**
407
+ * Build unsigned transaction(s) to swap any token pair on Avalanche via LFJ/Pharaoh DEX.
408
+ *
409
+ * May return multiple transactions (approve + swap). Execute in order.
410
+ *
411
+ * @param wallet - Your wallet address
412
+ * @param from - Source token symbol or contract address
413
+ * @param to - Destination token symbol or contract address
414
+ * @param amount - Amount to swap, or "max" for entire balance
415
+ * @param slippage - Slippage tolerance in basis points (default: 500 = 5%)
416
+ */
417
+ async buildSwap(wallet, from, to, amount, slippage) {
418
+ await this.auth();
419
+ return this.http.get("/dex/build/swap", { wallet, from, to, amount, slippage });
420
+ }
421
+ };
422
+
423
+ // src/client.ts
424
+ var DEFAULT_BASE_URL = "https://brave-alignment-production-1706.up.railway.app";
425
+ var LogiqicalClient = class {
426
+ /** Buy/sell ARENA tokens via LFJ DEX */
427
+ swap;
428
+ /** Stake ARENA tokens for rewards */
429
+ staking;
430
+ /** Discover, research, and trade launchpad tokens on bonding curves */
431
+ launchpad;
432
+ /** Swap any Avalanche token via LFJ + Pharaoh DEX */
433
+ dex;
434
+ http;
435
+ wallet;
436
+ agentName;
437
+ registrationPromise = null;
438
+ constructor(config) {
439
+ this.wallet = config.wallet;
440
+ this.agentName = config.name ?? "agent";
441
+ this.http = new HttpClient(config.baseUrl ?? DEFAULT_BASE_URL, config.apiKey);
442
+ const auth = () => this.ensureRegistered();
443
+ this.swap = new SwapModule(this.http, auth);
444
+ this.staking = new StakingModule(this.http, auth);
445
+ this.launchpad = new LaunchpadModule(this.http, auth);
446
+ this.dex = new DexModule(this.http, auth);
447
+ }
448
+ /** The API key (available after first call or if provided in config) */
449
+ get apiKey() {
450
+ return this.http.getApiKey();
451
+ }
452
+ /**
453
+ * Broadcast a signed transaction to the Avalanche network.
454
+ * @param signedTx - Signed transaction hex string
455
+ * @returns Transaction hash
456
+ */
457
+ async broadcast(signedTx) {
458
+ await this.ensureRegistered();
459
+ return this.http.post("/broadcast", { signedTx });
460
+ }
461
+ /**
462
+ * Get the full agent instructions document — describes all available capabilities.
463
+ */
464
+ async getInstructions() {
465
+ await this.ensureRegistered();
466
+ return this.http.get("/agent-instructions");
467
+ }
468
+ /**
469
+ * Check if the API is healthy and responsive.
470
+ */
471
+ async health() {
472
+ return this.http.get("/health", void 0, true);
473
+ }
474
+ /**
475
+ * Manually register and get an API key.
476
+ * Usually not needed — the client auto-registers on first call.
477
+ */
478
+ async register() {
479
+ const data = await this.http.get("/register", {
480
+ wallet: this.wallet,
481
+ name: this.agentName
482
+ }, true);
483
+ const apiKey = data.apiKey || data.key;
484
+ this.http.setApiKey(apiKey);
485
+ return { apiKey, wallet: data.wallet, name: data.name };
486
+ }
487
+ async ensureRegistered() {
488
+ if (this.http.getApiKey()) return;
489
+ if (!this.registrationPromise) {
490
+ this.registrationPromise = this.register().then(() => {
491
+ }).catch((e) => {
492
+ this.registrationPromise = null;
493
+ throw e;
494
+ });
495
+ }
496
+ return this.registrationPromise;
497
+ }
498
+ };
499
+ // Annotate the CommonJS export names for ESM import in node:
500
+ 0 && (module.exports = {
501
+ DexModule,
502
+ LaunchpadModule,
503
+ LogiqicalAuthError,
504
+ LogiqicalClient,
505
+ LogiqicalError,
506
+ StakingModule,
507
+ SwapModule
508
+ });