pyre-world-kit 1.0.15 → 1.0.17

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/actions.d.ts CHANGED
@@ -37,17 +37,7 @@ export declare function getWarChest(connection: Connection, mint: string): Promi
37
37
  export declare function getWarLoan(connection: Connection, mint: string, wallet: string): Promise<WarLoan>;
38
38
  /** Get all war loans for a faction */
39
39
  export declare function getAllWarLoans(connection: Connection, mint: string): Promise<AllWarLoansResult>;
40
- /**
41
- * Compute max borrowable SOL for a given collateral amount.
42
- *
43
- * Mirrors the burnfun LendingDashboard logic — effective max borrow is the
44
- * minimum of three caps:
45
- * 1. LTV limit: collateral_value_sol * (max_ltv_bps / 10000)
46
- * 2. Pool available: treasury_sol * utilization_cap - total_lent
47
- * 3. Per-user cap: (collateral / total_supply) * borrow_share_multiplier * max_lendable
48
- *
49
- * All values in lamports. Accounts for Token-2022 transfer fee (4 bps).
50
- */
40
+ /** Compute max borrowable SOL for a given collateral amount */
51
41
  export declare function getMaxWarLoan(connection: Connection, mint: string, collateralAmount: number): Promise<WarLoanQuote>;
52
42
  /** Launch a new faction (create token) */
53
43
  export declare function launchFaction(connection: Connection, params: LaunchFactionParams): Promise<LaunchFactionResult>;
package/dist/actions.js CHANGED
@@ -5,9 +5,6 @@
5
5
  * Thin wrappers that call torchsdk functions and map params/results
6
6
  * into game-semantic Pyre types. No new on-chain logic.
7
7
  */
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
11
8
  Object.defineProperty(exports, "__esModule", { value: true });
12
9
  exports.createEphemeralAgent = void 0;
13
10
  exports.blacklistMints = blacklistMints;
@@ -54,7 +51,6 @@ exports.confirmAction = confirmAction;
54
51
  exports.getDexPool = getDexPool;
55
52
  exports.getDexVaults = getDexVaults;
56
53
  const web3_js_1 = require("@solana/web3.js");
57
- const bs58_1 = __importDefault(require("bs58"));
58
54
  const torchsdk_1 = require("torchsdk");
59
55
  const mappers_1 = require("./mappers");
60
56
  const vanity_1 = require("./vanity");
@@ -124,82 +120,8 @@ async function getMembers(connection, mint, limit) {
124
120
  }
125
121
  /** Get faction comms (trade-bundled messages, including post-ascension DEX messages) */
126
122
  async function getComms(connection, mint, limit) {
127
- const safeLimit = Math.min(limit || 50, 100);
128
- const MEMO_PROGRAM = 'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr';
129
- // Fetch bonding curve messages AND pool state messages in parallel
130
- const bondingCommsPromise = (0, torchsdk_1.getMessages)(connection, mint, safeLimit)
131
- .then(r => (0, mappers_1.mapMessagesResult)(r))
132
- .catch(() => ({ comms: [], total: 0 }));
133
- const poolCommsPromise = (async () => {
134
- try {
135
- const mintPubkey = new web3_js_1.PublicKey(mint);
136
- const { poolState } = (0, torchsdk_1.getRaydiumMigrationAccounts)(mintPubkey);
137
- const signatures = await connection.getSignaturesForAddress(poolState, { limit: Math.min(safeLimit, 50) }, 'confirmed');
138
- if (signatures.length === 0)
139
- return { comms: [], total: 0 };
140
- const txs = await connection.getParsedTransactions(signatures.map(s => s.signature), { maxSupportedTransactionVersion: 0 });
141
- const comms = [];
142
- for (let i = 0; i < txs.length; i++) {
143
- const tx = txs[i];
144
- if (!tx?.meta || tx.meta.err)
145
- continue;
146
- const sig = signatures[i];
147
- // Check top-level and inner instructions for memo
148
- const allInstructions = [
149
- ...tx.transaction.message.instructions,
150
- ...(tx.meta.innerInstructions || []).flatMap(inner => inner.instructions),
151
- ];
152
- for (const ix of allInstructions) {
153
- const programId = 'programId' in ix ? ix.programId.toString() : '';
154
- const programName = 'program' in ix ? ix.program : '';
155
- const isMemo = programId === MEMO_PROGRAM || programName === 'spl-memo';
156
- if (isMemo) {
157
- let memoText = '';
158
- if ('parsed' in ix) {
159
- memoText = typeof ix.parsed === 'string' ? ix.parsed : JSON.stringify(ix.parsed);
160
- }
161
- else if ('data' in ix && typeof ix.data === 'string') {
162
- try {
163
- memoText = new TextDecoder().decode(bs58_1.default.decode(ix.data));
164
- }
165
- catch {
166
- memoText = ix.data;
167
- }
168
- }
169
- if (memoText && memoText.trim()) {
170
- const sender = tx.transaction.message.accountKeys[0]?.pubkey?.toString() || 'Unknown';
171
- comms.push({
172
- signature: sig.signature,
173
- memo: memoText.trim(),
174
- sender,
175
- timestamp: sig.blockTime || 0,
176
- });
177
- break;
178
- }
179
- }
180
- }
181
- }
182
- return { comms, total: comms.length };
183
- }
184
- catch {
185
- return { comms: [], total: 0 };
186
- }
187
- })();
188
- const [bondingResult, poolResult] = await Promise.all([bondingCommsPromise, poolCommsPromise]);
189
- // Merge, dedupe by signature, sort newest first, trim to limit
190
- const seen = new Set();
191
- const allComms = [];
192
- for (const c of [...bondingResult.comms, ...poolResult.comms]) {
193
- if (!seen.has(c.signature)) {
194
- seen.add(c.signature);
195
- allComms.push(c);
196
- }
197
- }
198
- allComms.sort((a, b) => b.timestamp - a.timestamp);
199
- return {
200
- comms: allComms.slice(0, safeLimit),
201
- total: allComms.length,
202
- };
123
+ const result = await (0, torchsdk_1.getMessages)(connection, mint, limit);
124
+ return (0, mappers_1.mapMessagesResult)(result);
203
125
  }
204
126
  /** Get a quote for joining a faction (buying tokens) */
205
127
  async function getJoinQuote(connection, mint, amountSolLamports) {
@@ -239,52 +161,9 @@ async function getAllWarLoans(connection, mint) {
239
161
  const result = await (0, torchsdk_1.getAllLoanPositions)(connection, mint);
240
162
  return (0, mappers_1.mapAllLoansResult)(result);
241
163
  }
242
- /**
243
- * Compute max borrowable SOL for a given collateral amount.
244
- *
245
- * Mirrors the burnfun LendingDashboard logic — effective max borrow is the
246
- * minimum of three caps:
247
- * 1. LTV limit: collateral_value_sol * (max_ltv_bps / 10000)
248
- * 2. Pool available: treasury_sol * utilization_cap - total_lent
249
- * 3. Per-user cap: (collateral / total_supply) * borrow_share_multiplier * max_lendable
250
- *
251
- * All values in lamports. Accounts for Token-2022 transfer fee (4 bps).
252
- */
164
+ /** Compute max borrowable SOL for a given collateral amount */
253
165
  async function getMaxWarLoan(connection, mint, collateralAmount) {
254
- const TOTAL_SUPPLY = 1_000_000_000_000_000; // 1B tokens * 1e6 multiplier (base units)
255
- const TRANSFER_FEE_BPS = 4;
256
- const LAMPORTS_PER_SOL = 1_000_000_000;
257
- const [lending, detail] = await Promise.all([
258
- (0, torchsdk_1.getLendingInfo)(connection, mint),
259
- (0, torchsdk_1.getToken)(connection, mint),
260
- ]);
261
- // Price per base-unit token in SOL (lamports)
262
- const pricePerToken = detail.price_sol; // SOL per display token
263
- const TOKEN_MULTIPLIER = 1_000_000;
264
- // Collateral value in SOL (lamports)
265
- const collateralDisplayTokens = collateralAmount / TOKEN_MULTIPLIER;
266
- const collateralValueSol = collateralDisplayTokens * pricePerToken * LAMPORTS_PER_SOL;
267
- // 1. LTV cap
268
- const ltvMaxSol = collateralValueSol * (lending.max_ltv_bps / 10000);
269
- // 2. Pool available
270
- const treasurySol = detail.treasury_sol_balance * LAMPORTS_PER_SOL;
271
- const maxLendableSol = treasurySol * lending.utilization_cap_bps / 10000;
272
- const totalLent = (lending.total_sol_lent ?? 0);
273
- const poolAvailableSol = Math.max(0, maxLendableSol - totalLent);
274
- // 3. Per-user cap (accounts for transfer fee reducing net collateral)
275
- const netCollateral = collateralAmount * (1 - TRANSFER_FEE_BPS / 10000);
276
- const borrowMultiplier = lending.borrow_share_multiplier || 3;
277
- const perUserCapSol = maxLendableSol * netCollateral * borrowMultiplier / TOTAL_SUPPLY;
278
- const maxBorrowSol = Math.max(0, Math.min(ltvMaxSol, poolAvailableSol, perUserCapSol));
279
- return {
280
- max_borrow_sol: Math.floor(maxBorrowSol),
281
- collateral_value_sol: Math.floor(collateralValueSol),
282
- ltv_max_sol: Math.floor(ltvMaxSol),
283
- pool_available_sol: Math.floor(poolAvailableSol),
284
- per_user_cap_sol: Math.floor(perUserCapSol),
285
- interest_rate_bps: lending.interest_rate_bps,
286
- liquidation_threshold_bps: lending.liquidation_threshold_bps,
287
- };
166
+ return (0, torchsdk_1.getBorrowQuote)(connection, mint, collateralAmount);
288
167
  }
289
168
  // ─── Faction Operations (controller) ───────────────────────────────
290
169
  /** Launch a new faction (create token) */
@@ -355,7 +234,7 @@ async function messageFaction(connection, params) {
355
234
  amount_sol: MICRO_BUY_LAMPORTS,
356
235
  message: params.message,
357
236
  vault: params.stronghold,
358
- vote: (0, mappers_1.mapVote)(Math.random() > 0.5 ? 'fortify' : 'scorched_earth'),
237
+ vote: params.first_buy ? (0, mappers_1.mapVote)(Math.random() > 0.5 ? 'fortify' : 'scorched_earth') : undefined,
359
238
  });
360
239
  return (0, mappers_1.mapBuyResult)(result);
361
240
  }
package/dist/types.d.ts CHANGED
@@ -193,6 +193,7 @@ export interface MessageFactionParams {
193
193
  message: string;
194
194
  stronghold: string;
195
195
  ascended?: boolean;
196
+ first_buy?: boolean;
196
197
  }
197
198
  /** "Argued in" — micro sell + negative message (sells 100 tokens) */
198
199
  export interface FudFactionParams {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pyre-world-kit",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "Agent-first faction warfare kit — game-semantic wrapper over torchsdk",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  "@solana/spl-token": "^0.4.6",
16
16
  "@solana/web3.js": "^1.98.4",
17
17
  "bs58": "^6.0.0",
18
- "torchsdk": "^3.7.34"
18
+ "torchsdk": "^3.7.35"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/node": "^22.15.0",
package/src/actions.ts CHANGED
@@ -6,7 +6,6 @@
6
6
  */
7
7
 
8
8
  import { Connection, PublicKey } from '@solana/web3.js';
9
- import bs58 from 'bs58';
10
9
  import {
11
10
  // Read operations
12
11
  getTokens,
@@ -15,6 +14,7 @@ import {
15
14
  getMessages,
16
15
  getBuyQuote,
17
16
  getSellQuote,
17
+ getBorrowQuote,
18
18
  getVault,
19
19
  getVaultForWallet,
20
20
  getVaultWalletLink,
@@ -197,102 +197,8 @@ export async function getComms(
197
197
  mint: string,
198
198
  limit?: number,
199
199
  ): Promise<CommsResult> {
200
- const safeLimit = Math.min(limit || 50, 100);
201
- const MEMO_PROGRAM = 'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr';
202
-
203
- // Fetch bonding curve messages AND pool state messages in parallel
204
- const bondingCommsPromise = getMessages(connection, mint, safeLimit)
205
- .then(r => mapMessagesResult(r))
206
- .catch(() => ({ comms: [], total: 0 } as CommsResult));
207
-
208
- const poolCommsPromise = (async (): Promise<CommsResult> => {
209
- try {
210
- const mintPubkey = new PublicKey(mint);
211
- const { poolState } = getRaydiumMigrationAccounts(mintPubkey);
212
-
213
- const signatures = await connection.getSignaturesForAddress(
214
- poolState,
215
- { limit: Math.min(safeLimit, 50) },
216
- 'confirmed',
217
- );
218
-
219
- if (signatures.length === 0) return { comms: [], total: 0 };
220
-
221
- const txs = await connection.getParsedTransactions(
222
- signatures.map(s => s.signature),
223
- { maxSupportedTransactionVersion: 0 },
224
- );
225
-
226
- const comms: CommsResult['comms'] = [];
227
-
228
- for (let i = 0; i < txs.length; i++) {
229
- const tx = txs[i];
230
- if (!tx?.meta || tx.meta.err) continue;
231
-
232
- const sig = signatures[i];
233
-
234
- // Check top-level and inner instructions for memo
235
- const allInstructions = [
236
- ...tx.transaction.message.instructions,
237
- ...(tx.meta.innerInstructions || []).flatMap(inner => inner.instructions),
238
- ];
239
-
240
- for (const ix of allInstructions) {
241
- const programId = 'programId' in ix ? ix.programId.toString() : '';
242
- const programName = 'program' in ix ? (ix as { program: string }).program : '';
243
- const isMemo = programId === MEMO_PROGRAM || programName === 'spl-memo';
244
-
245
- if (isMemo) {
246
- let memoText = '';
247
- if ('parsed' in ix) {
248
- memoText = typeof ix.parsed === 'string' ? ix.parsed : JSON.stringify(ix.parsed);
249
- } else if ('data' in ix && typeof ix.data === 'string') {
250
- try {
251
- memoText = new TextDecoder().decode(bs58.decode(ix.data));
252
- } catch {
253
- memoText = ix.data;
254
- }
255
- }
256
-
257
- if (memoText && memoText.trim()) {
258
- const sender = tx.transaction.message.accountKeys[0]?.pubkey?.toString() || 'Unknown';
259
- comms.push({
260
- signature: sig.signature,
261
- memo: memoText.trim(),
262
- sender,
263
- timestamp: sig.blockTime || 0,
264
- });
265
- break;
266
- }
267
- }
268
- }
269
- }
270
-
271
- return { comms, total: comms.length };
272
- } catch {
273
- return { comms: [], total: 0 };
274
- }
275
- })();
276
-
277
- const [bondingResult, poolResult] = await Promise.all([bondingCommsPromise, poolCommsPromise]);
278
-
279
- // Merge, dedupe by signature, sort newest first, trim to limit
280
- const seen = new Set<string>();
281
- const allComms: CommsResult['comms'] = [];
282
-
283
- for (const c of [...bondingResult.comms, ...poolResult.comms]) {
284
- if (!seen.has(c.signature)) {
285
- seen.add(c.signature);
286
- allComms.push(c);
287
- }
288
- }
289
-
290
- allComms.sort((a, b) => b.timestamp - a.timestamp);
291
-
292
- return {
293
- comms: allComms.slice(0, safeLimit),
294
- total: allComms.length,
295
- };
200
+ const result = await getMessages(connection, mint, limit);
201
+ return mapMessagesResult(result);
296
202
  }
297
203
 
298
204
  /** Get a quote for joining a faction (buying tokens) */
@@ -368,64 +274,13 @@ export async function getAllWarLoans(
368
274
  return mapAllLoansResult(result);
369
275
  }
370
276
 
371
- /**
372
- * Compute max borrowable SOL for a given collateral amount.
373
- *
374
- * Mirrors the burnfun LendingDashboard logic — effective max borrow is the
375
- * minimum of three caps:
376
- * 1. LTV limit: collateral_value_sol * (max_ltv_bps / 10000)
377
- * 2. Pool available: treasury_sol * utilization_cap - total_lent
378
- * 3. Per-user cap: (collateral / total_supply) * borrow_share_multiplier * max_lendable
379
- *
380
- * All values in lamports. Accounts for Token-2022 transfer fee (4 bps).
381
- */
277
+ /** Compute max borrowable SOL for a given collateral amount */
382
278
  export async function getMaxWarLoan(
383
279
  connection: Connection,
384
280
  mint: string,
385
281
  collateralAmount: number,
386
282
  ): Promise<WarLoanQuote> {
387
- const TOTAL_SUPPLY = 1_000_000_000_000_000; // 1B tokens * 1e6 multiplier (base units)
388
- const TRANSFER_FEE_BPS = 4;
389
- const LAMPORTS_PER_SOL = 1_000_000_000;
390
-
391
- const [lending, detail] = await Promise.all([
392
- getLendingInfo(connection, mint),
393
- getToken(connection, mint),
394
- ]);
395
-
396
- // Price per base-unit token in SOL (lamports)
397
- const pricePerToken = detail.price_sol; // SOL per display token
398
- const TOKEN_MULTIPLIER = 1_000_000;
399
-
400
- // Collateral value in SOL (lamports)
401
- const collateralDisplayTokens = collateralAmount / TOKEN_MULTIPLIER;
402
- const collateralValueSol = collateralDisplayTokens * pricePerToken * LAMPORTS_PER_SOL;
403
-
404
- // 1. LTV cap
405
- const ltvMaxSol = collateralValueSol * (lending.max_ltv_bps / 10000);
406
-
407
- // 2. Pool available
408
- const treasurySol = detail.treasury_sol_balance * LAMPORTS_PER_SOL;
409
- const maxLendableSol = treasurySol * lending.utilization_cap_bps / 10000;
410
- const totalLent = (lending.total_sol_lent ?? 0);
411
- const poolAvailableSol = Math.max(0, maxLendableSol - totalLent);
412
-
413
- // 3. Per-user cap (accounts for transfer fee reducing net collateral)
414
- const netCollateral = collateralAmount * (1 - TRANSFER_FEE_BPS / 10000);
415
- const borrowMultiplier = lending.borrow_share_multiplier || 3;
416
- const perUserCapSol = maxLendableSol * netCollateral * borrowMultiplier / TOTAL_SUPPLY;
417
-
418
- const maxBorrowSol = Math.max(0, Math.min(ltvMaxSol, poolAvailableSol, perUserCapSol));
419
-
420
- return {
421
- max_borrow_sol: Math.floor(maxBorrowSol),
422
- collateral_value_sol: Math.floor(collateralValueSol),
423
- ltv_max_sol: Math.floor(ltvMaxSol),
424
- pool_available_sol: Math.floor(poolAvailableSol),
425
- per_user_cap_sol: Math.floor(perUserCapSol),
426
- interest_rate_bps: lending.interest_rate_bps,
427
- liquidation_threshold_bps: lending.liquidation_threshold_bps,
428
- };
283
+ return getBorrowQuote(connection, mint, collateralAmount);
429
284
  }
430
285
 
431
286
  // ─── Faction Operations (controller) ───────────────────────────────
@@ -517,7 +372,7 @@ export async function messageFaction(
517
372
  amount_sol: MICRO_BUY_LAMPORTS,
518
373
  message: params.message,
519
374
  vault: params.stronghold,
520
- vote: mapVote(Math.random() > 0.5 ? 'fortify' : 'scorched_earth'),
375
+ vote: params.first_buy ? mapVote(Math.random() > 0.5 ? 'fortify' : 'scorched_earth') : undefined,
521
376
  });
522
377
  return mapBuyResult(result);
523
378
  }
package/src/types.ts CHANGED
@@ -231,6 +231,7 @@ export interface MessageFactionParams {
231
231
  message: string;
232
232
  stronghold: string;
233
233
  ascended?: boolean;
234
+ first_buy?: boolean;
234
235
  }
235
236
 
236
237
  /** "Argued in" — micro sell + negative message (sells 100 tokens) */