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