pyre-world-kit 1.0.8 → 1.0.10
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 +19 -1
- package/dist/actions.js +69 -32
- package/dist/index.d.ts +2 -2
- package/dist/index.js +7 -2
- package/dist/types.d.ts +17 -0
- package/package.json +1 -1
- package/src/actions.ts +83 -35
- package/src/index.ts +6 -0
- package/src/types.ts +20 -0
package/dist/actions.d.ts
CHANGED
|
@@ -6,7 +6,13 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { Connection, PublicKey } from '@solana/web3.js';
|
|
8
8
|
import type { BuyQuoteResult, SellQuoteResult, TransactionResult, SaidVerification, ConfirmResult } from 'torchsdk';
|
|
9
|
-
import type { FactionListParams, FactionListResult, FactionDetail, MembersResult, CommsResult, Stronghold, AgentLink, WarChest, WarLoan, AllWarLoansResult, LaunchFactionParams, JoinFactionParams, DirectJoinFactionParams, DefectParams, RallyParams, RequestWarLoanParams, RepayWarLoanParams, SiegeParams, TradeOnDexParams, ClaimSpoilsParams, CreateStrongholdParams, FundStrongholdParams, WithdrawFromStrongholdParams, RecruitAgentParams, ExileAgentParams, CoupParams, WithdrawAssetsParams, AscendParams, RazeParams, TitheParams, ConvertTitheParams, JoinFactionResult, LaunchFactionResult } from './types';
|
|
9
|
+
import type { FactionListParams, FactionListResult, FactionDetail, MembersResult, CommsResult, Stronghold, AgentLink, WarChest, WarLoan, WarLoanQuote, AllWarLoansResult, LaunchFactionParams, JoinFactionParams, DirectJoinFactionParams, DefectParams, RallyParams, RequestWarLoanParams, RepayWarLoanParams, SiegeParams, TradeOnDexParams, ClaimSpoilsParams, CreateStrongholdParams, FundStrongholdParams, WithdrawFromStrongholdParams, RecruitAgentParams, ExileAgentParams, CoupParams, WithdrawAssetsParams, AscendParams, RazeParams, TitheParams, ConvertTitheParams, JoinFactionResult, LaunchFactionResult } from './types';
|
|
10
|
+
/** Add mints to the blacklist (call at startup with old mints) */
|
|
11
|
+
export declare function blacklistMints(mints: string[]): void;
|
|
12
|
+
/** Check if a mint is blacklisted */
|
|
13
|
+
export declare function isBlacklistedMint(mint: string): boolean;
|
|
14
|
+
/** Get all blacklisted mints */
|
|
15
|
+
export declare function getBlacklistedMints(): string[];
|
|
10
16
|
/** List all factions with optional filtering and sorting */
|
|
11
17
|
export declare function getFactions(connection: Connection, params?: FactionListParams): Promise<FactionListResult>;
|
|
12
18
|
/** Get detailed info for a single faction */
|
|
@@ -31,6 +37,18 @@ export declare function getWarChest(connection: Connection, mint: string): Promi
|
|
|
31
37
|
export declare function getWarLoan(connection: Connection, mint: string, wallet: string): Promise<WarLoan>;
|
|
32
38
|
/** Get all war loans for a faction */
|
|
33
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
|
+
*/
|
|
51
|
+
export declare function getMaxWarLoan(connection: Connection, mint: string, collateralAmount: number): Promise<WarLoanQuote>;
|
|
34
52
|
/** Launch a new faction (create token) */
|
|
35
53
|
export declare function launchFaction(connection: Connection, params: LaunchFactionParams): Promise<LaunchFactionResult>;
|
|
36
54
|
/** Join a faction via stronghold (vault-funded buy) */
|
package/dist/actions.js
CHANGED
|
@@ -10,6 +10,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.createEphemeralAgent = void 0;
|
|
13
|
+
exports.blacklistMints = blacklistMints;
|
|
14
|
+
exports.isBlacklistedMint = isBlacklistedMint;
|
|
15
|
+
exports.getBlacklistedMints = getBlacklistedMints;
|
|
13
16
|
exports.getFactions = getFactions;
|
|
14
17
|
exports.getFaction = getFaction;
|
|
15
18
|
exports.getMembers = getMembers;
|
|
@@ -22,6 +25,7 @@ exports.getAgentLink = getAgentLink;
|
|
|
22
25
|
exports.getWarChest = getWarChest;
|
|
23
26
|
exports.getWarLoan = getWarLoan;
|
|
24
27
|
exports.getAllWarLoans = getAllWarLoans;
|
|
28
|
+
exports.getMaxWarLoan = getMaxWarLoan;
|
|
25
29
|
exports.launchFaction = launchFaction;
|
|
26
30
|
exports.joinFaction = joinFaction;
|
|
27
31
|
exports.directJoinFaction = directJoinFaction;
|
|
@@ -52,6 +56,23 @@ const bs58_1 = __importDefault(require("bs58"));
|
|
|
52
56
|
const torchsdk_1 = require("torchsdk");
|
|
53
57
|
const mappers_1 = require("./mappers");
|
|
54
58
|
const vanity_1 = require("./vanity");
|
|
59
|
+
// ─── Blacklist ──────────────────────────────────────────────────────
|
|
60
|
+
// Mints from previous swarm runs. Agents should skip these and only
|
|
61
|
+
// interact with freshly launched factions.
|
|
62
|
+
const BLACKLISTED_MINTS = new Set();
|
|
63
|
+
/** Add mints to the blacklist (call at startup with old mints) */
|
|
64
|
+
function blacklistMints(mints) {
|
|
65
|
+
for (const m of mints)
|
|
66
|
+
BLACKLISTED_MINTS.add(m);
|
|
67
|
+
}
|
|
68
|
+
/** Check if a mint is blacklisted */
|
|
69
|
+
function isBlacklistedMint(mint) {
|
|
70
|
+
return BLACKLISTED_MINTS.has(mint);
|
|
71
|
+
}
|
|
72
|
+
/** Get all blacklisted mints */
|
|
73
|
+
function getBlacklistedMints() {
|
|
74
|
+
return Array.from(BLACKLISTED_MINTS);
|
|
75
|
+
}
|
|
55
76
|
// ─── Read Operations ───────────────────────────────────────────────
|
|
56
77
|
/** List all factions with optional filtering and sorting */
|
|
57
78
|
async function getFactions(connection, params) {
|
|
@@ -62,38 +83,7 @@ async function getFactions(connection, params) {
|
|
|
62
83
|
sort: params.sort,
|
|
63
84
|
} : undefined;
|
|
64
85
|
const result = await (0, torchsdk_1.getTokens)(connection, sdkParams);
|
|
65
|
-
|
|
66
|
-
// Enrich ascended factions with live pool price (list endpoint only has stale bonding curve mcap)
|
|
67
|
-
// Use Promise.allSettled so a single failure doesn't block/break the list
|
|
68
|
-
const ascended = listResult.factions.filter(f => f.status === 'ascended');
|
|
69
|
-
if (ascended.length > 0) {
|
|
70
|
-
const enrichPromise = Promise.allSettled(ascended.map(async (faction) => {
|
|
71
|
-
const mint = new web3_js_1.PublicKey(faction.mint);
|
|
72
|
-
const raydium = (0, torchsdk_1.getRaydiumMigrationAccounts)(mint);
|
|
73
|
-
const [vault0Info, vault1Info] = await Promise.all([
|
|
74
|
-
connection.getTokenAccountBalance(raydium.token0Vault),
|
|
75
|
-
connection.getTokenAccountBalance(raydium.token1Vault),
|
|
76
|
-
]);
|
|
77
|
-
const vault0 = Number(vault0Info.value.amount);
|
|
78
|
-
const vault1 = Number(vault1Info.value.amount);
|
|
79
|
-
const solReserves = raydium.isWsolToken0 ? vault0 : vault1;
|
|
80
|
-
const tokenReserves = raydium.isWsolToken0 ? vault1 : vault0;
|
|
81
|
-
if (tokenReserves > 0) {
|
|
82
|
-
const LAMPORTS = 1_000_000_000;
|
|
83
|
-
const TOKEN_MUL = 1_000_000;
|
|
84
|
-
const priceInSol = (solReserves * TOKEN_MUL) / (tokenReserves * LAMPORTS);
|
|
85
|
-
const TOTAL_SUPPLY = 1_000_000_000 * TOKEN_MUL;
|
|
86
|
-
faction.price_sol = priceInSol;
|
|
87
|
-
faction.market_cap_sol = (priceInSol * TOTAL_SUPPLY) / TOKEN_MUL;
|
|
88
|
-
}
|
|
89
|
-
}));
|
|
90
|
-
// Race enrichment against a 3s timeout so the list always loads
|
|
91
|
-
await Promise.race([
|
|
92
|
-
enrichPromise,
|
|
93
|
-
new Promise(resolve => setTimeout(resolve, 3000)),
|
|
94
|
-
]);
|
|
95
|
-
}
|
|
96
|
-
return listResult;
|
|
86
|
+
return (0, mappers_1.mapTokenListResult)(result);
|
|
97
87
|
}
|
|
98
88
|
/** Get detailed info for a single faction */
|
|
99
89
|
async function getFaction(connection, mint) {
|
|
@@ -222,6 +212,53 @@ async function getAllWarLoans(connection, mint) {
|
|
|
222
212
|
const result = await (0, torchsdk_1.getAllLoanPositions)(connection, mint);
|
|
223
213
|
return (0, mappers_1.mapAllLoansResult)(result);
|
|
224
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Compute max borrowable SOL for a given collateral amount.
|
|
217
|
+
*
|
|
218
|
+
* Mirrors the burnfun LendingDashboard logic — effective max borrow is the
|
|
219
|
+
* minimum of three caps:
|
|
220
|
+
* 1. LTV limit: collateral_value_sol * (max_ltv_bps / 10000)
|
|
221
|
+
* 2. Pool available: treasury_sol * utilization_cap - total_lent
|
|
222
|
+
* 3. Per-user cap: (collateral / total_supply) * borrow_share_multiplier * max_lendable
|
|
223
|
+
*
|
|
224
|
+
* All values in lamports. Accounts for Token-2022 transfer fee (4 bps).
|
|
225
|
+
*/
|
|
226
|
+
async function getMaxWarLoan(connection, mint, collateralAmount) {
|
|
227
|
+
const TOTAL_SUPPLY = 1_000_000_000_000_000; // 1B tokens * 1e6 multiplier (base units)
|
|
228
|
+
const TRANSFER_FEE_BPS = 4;
|
|
229
|
+
const LAMPORTS_PER_SOL = 1_000_000_000;
|
|
230
|
+
const [lending, detail] = await Promise.all([
|
|
231
|
+
(0, torchsdk_1.getLendingInfo)(connection, mint),
|
|
232
|
+
(0, torchsdk_1.getToken)(connection, mint),
|
|
233
|
+
]);
|
|
234
|
+
// Price per base-unit token in SOL (lamports)
|
|
235
|
+
const pricePerToken = detail.price_sol; // SOL per display token
|
|
236
|
+
const TOKEN_MULTIPLIER = 1_000_000;
|
|
237
|
+
// Collateral value in SOL (lamports)
|
|
238
|
+
const collateralDisplayTokens = collateralAmount / TOKEN_MULTIPLIER;
|
|
239
|
+
const collateralValueSol = collateralDisplayTokens * pricePerToken * LAMPORTS_PER_SOL;
|
|
240
|
+
// 1. LTV cap
|
|
241
|
+
const ltvMaxSol = collateralValueSol * (lending.max_ltv_bps / 10000);
|
|
242
|
+
// 2. Pool available
|
|
243
|
+
const treasurySol = detail.treasury_sol_balance * LAMPORTS_PER_SOL;
|
|
244
|
+
const maxLendableSol = treasurySol * lending.utilization_cap_bps / 10000;
|
|
245
|
+
const totalLent = (lending.total_sol_lent ?? 0);
|
|
246
|
+
const poolAvailableSol = Math.max(0, maxLendableSol - totalLent);
|
|
247
|
+
// 3. Per-user cap (accounts for transfer fee reducing net collateral)
|
|
248
|
+
const netCollateral = collateralAmount * (1 - TRANSFER_FEE_BPS / 10000);
|
|
249
|
+
const borrowMultiplier = lending.borrow_share_multiplier || 3;
|
|
250
|
+
const perUserCapSol = maxLendableSol * netCollateral * borrowMultiplier / TOTAL_SUPPLY;
|
|
251
|
+
const maxBorrowSol = Math.max(0, Math.min(ltvMaxSol, poolAvailableSol, perUserCapSol));
|
|
252
|
+
return {
|
|
253
|
+
max_borrow_sol: Math.floor(maxBorrowSol),
|
|
254
|
+
collateral_value_sol: Math.floor(collateralValueSol),
|
|
255
|
+
ltv_max_sol: Math.floor(ltvMaxSol),
|
|
256
|
+
pool_available_sol: Math.floor(poolAvailableSol),
|
|
257
|
+
per_user_cap_sol: Math.floor(perUserCapSol),
|
|
258
|
+
interest_rate_bps: lending.interest_rate_bps,
|
|
259
|
+
liquidation_threshold_bps: lending.liquidation_threshold_bps,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
225
262
|
// ─── Faction Operations (controller) ───────────────────────────────
|
|
226
263
|
/** Launch a new faction (create token) */
|
|
227
264
|
async function launchFaction(connection, params) {
|
package/dist/index.d.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* This kit translates protocol primitives into faction warfare language
|
|
6
6
|
* so agents think in factions, not tokens.
|
|
7
7
|
*/
|
|
8
|
-
export type { FactionStatus, FactionTier, Strategy, AgentHealth, FactionSummary, FactionDetail, Stronghold, AgentLink, Comms, WarChest, WarLoan, WarLoanWithAgent, Member, FactionListResult, MembersResult, CommsResult, AllWarLoansResult, LaunchFactionParams, JoinFactionParams, DirectJoinFactionParams, DefectParams, RallyParams, RequestWarLoanParams, RepayWarLoanParams, SiegeParams, TradeOnDexParams, ClaimSpoilsParams, CreateStrongholdParams, FundStrongholdParams, WithdrawFromStrongholdParams, RecruitAgentParams, ExileAgentParams, CoupParams, WithdrawAssetsParams, AscendParams, RazeParams, TitheParams, ConvertTitheParams, JoinFactionResult, LaunchFactionResult, TransactionResult, EphemeralAgent, SaidVerification, ConfirmResult, FactionSortOption, FactionStatusFilter, FactionListParams, FactionPower, AllianceCluster, RivalFaction, AgentProfile, AgentFactionPosition, WorldEventType, WorldEvent, WorldStats, } from './types';
|
|
9
|
-
export { getFactions, getFaction, getMembers, getComms, getJoinQuote, getDefectQuote, getStronghold, getStrongholdForAgent, getAgentLink, getWarChest, getWarLoan, getAllWarLoans, launchFaction, joinFaction, directJoinFaction, defect, rally, requestWarLoan, repayWarLoan, tradeOnDex, claimSpoils, createStronghold, fundStronghold, withdrawFromStronghold, recruitAgent, exileAgent, coup, withdrawAssets, siege, ascend, raze, tithe, convertTithe, verifyAgent, confirmAction, createEphemeralAgent, getDexPool, getDexVaults, } from './actions';
|
|
8
|
+
export type { FactionStatus, FactionTier, Strategy, AgentHealth, FactionSummary, FactionDetail, Stronghold, AgentLink, Comms, WarChest, WarLoan, WarLoanWithAgent, Member, FactionListResult, MembersResult, CommsResult, AllWarLoansResult, WarLoanQuote, LaunchFactionParams, JoinFactionParams, DirectJoinFactionParams, DefectParams, RallyParams, RequestWarLoanParams, RepayWarLoanParams, SiegeParams, TradeOnDexParams, ClaimSpoilsParams, CreateStrongholdParams, FundStrongholdParams, WithdrawFromStrongholdParams, RecruitAgentParams, ExileAgentParams, CoupParams, WithdrawAssetsParams, AscendParams, RazeParams, TitheParams, ConvertTitheParams, JoinFactionResult, LaunchFactionResult, TransactionResult, EphemeralAgent, SaidVerification, ConfirmResult, FactionSortOption, FactionStatusFilter, FactionListParams, FactionPower, AllianceCluster, RivalFaction, AgentProfile, AgentFactionPosition, WorldEventType, WorldEvent, WorldStats, } from './types';
|
|
9
|
+
export { getFactions, getFaction, getMembers, getComms, getJoinQuote, getDefectQuote, getStronghold, getStrongholdForAgent, getAgentLink, getWarChest, getWarLoan, getAllWarLoans, getMaxWarLoan, blacklistMints, isBlacklistedMint, getBlacklistedMints, launchFaction, joinFaction, directJoinFaction, defect, rally, requestWarLoan, repayWarLoan, tradeOnDex, claimSpoils, createStronghold, fundStronghold, withdrawFromStronghold, recruitAgent, exileAgent, coup, withdrawAssets, siege, ascend, raze, tithe, convertTithe, verifyAgent, confirmAction, createEphemeralAgent, getDexPool, getDexVaults, } from './actions';
|
|
10
10
|
export { getFactionPower, getFactionLeaderboard, detectAlliances, getFactionRivals, getAgentProfile, getAgentFactions, getWorldFeed, getWorldStats, } from './intel';
|
|
11
11
|
export { isPyreMint, grindPyreMint } from './vanity';
|
|
12
12
|
export { PROGRAM_ID, LAMPORTS_PER_SOL, TOKEN_MULTIPLIER, TOTAL_SUPPLY } from 'torchsdk';
|
package/dist/index.js
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* so agents think in factions, not tokens.
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.
|
|
11
|
-
exports.TOTAL_SUPPLY = exports.TOKEN_MULTIPLIER = void 0;
|
|
10
|
+
exports.getWorldStats = exports.getWorldFeed = exports.getAgentFactions = exports.getAgentProfile = exports.getFactionRivals = exports.detectAlliances = exports.getFactionLeaderboard = exports.getFactionPower = exports.getDexVaults = exports.getDexPool = exports.createEphemeralAgent = exports.confirmAction = exports.verifyAgent = exports.convertTithe = exports.tithe = exports.raze = exports.ascend = exports.siege = exports.withdrawAssets = exports.coup = exports.exileAgent = exports.recruitAgent = exports.withdrawFromStronghold = exports.fundStronghold = exports.createStronghold = exports.claimSpoils = exports.tradeOnDex = exports.repayWarLoan = exports.requestWarLoan = exports.rally = exports.defect = exports.directJoinFaction = exports.joinFaction = exports.launchFaction = exports.getBlacklistedMints = exports.isBlacklistedMint = exports.blacklistMints = exports.getMaxWarLoan = exports.getAllWarLoans = exports.getWarLoan = exports.getWarChest = exports.getAgentLink = exports.getStrongholdForAgent = exports.getStronghold = exports.getDefectQuote = exports.getJoinQuote = exports.getComms = exports.getMembers = exports.getFaction = exports.getFactions = void 0;
|
|
11
|
+
exports.TOTAL_SUPPLY = exports.TOKEN_MULTIPLIER = exports.LAMPORTS_PER_SOL = exports.PROGRAM_ID = exports.grindPyreMint = exports.isPyreMint = void 0;
|
|
12
12
|
// ─── Actions ───────────────────────────────────────────────────────
|
|
13
13
|
var actions_1 = require("./actions");
|
|
14
14
|
// Read operations
|
|
@@ -24,6 +24,11 @@ Object.defineProperty(exports, "getAgentLink", { enumerable: true, get: function
|
|
|
24
24
|
Object.defineProperty(exports, "getWarChest", { enumerable: true, get: function () { return actions_1.getWarChest; } });
|
|
25
25
|
Object.defineProperty(exports, "getWarLoan", { enumerable: true, get: function () { return actions_1.getWarLoan; } });
|
|
26
26
|
Object.defineProperty(exports, "getAllWarLoans", { enumerable: true, get: function () { return actions_1.getAllWarLoans; } });
|
|
27
|
+
Object.defineProperty(exports, "getMaxWarLoan", { enumerable: true, get: function () { return actions_1.getMaxWarLoan; } });
|
|
28
|
+
// Blacklist
|
|
29
|
+
Object.defineProperty(exports, "blacklistMints", { enumerable: true, get: function () { return actions_1.blacklistMints; } });
|
|
30
|
+
Object.defineProperty(exports, "isBlacklistedMint", { enumerable: true, get: function () { return actions_1.isBlacklistedMint; } });
|
|
31
|
+
Object.defineProperty(exports, "getBlacklistedMints", { enumerable: true, get: function () { return actions_1.getBlacklistedMints; } });
|
|
27
32
|
// Faction operations
|
|
28
33
|
Object.defineProperty(exports, "launchFaction", { enumerable: true, get: function () { return actions_1.launchFaction; } });
|
|
29
34
|
Object.defineProperty(exports, "joinFaction", { enumerable: true, get: function () { return actions_1.joinFaction; } });
|
package/dist/types.d.ts
CHANGED
|
@@ -296,6 +296,23 @@ export interface FactionListParams {
|
|
|
296
296
|
status?: FactionStatusFilter;
|
|
297
297
|
sort?: FactionSortOption;
|
|
298
298
|
}
|
|
299
|
+
/** Result of computing max borrowable SOL for a given collateral amount */
|
|
300
|
+
export interface WarLoanQuote {
|
|
301
|
+
/** Max SOL borrowable (lamports) — minimum of LTV cap, pool available, per-user cap */
|
|
302
|
+
max_borrow_sol: number;
|
|
303
|
+
/** Collateral value in SOL (lamports) */
|
|
304
|
+
collateral_value_sol: number;
|
|
305
|
+
/** LTV-limited max borrow (lamports) */
|
|
306
|
+
ltv_max_sol: number;
|
|
307
|
+
/** Pool available SOL (lamports) */
|
|
308
|
+
pool_available_sol: number;
|
|
309
|
+
/** Per-user cap SOL (lamports) — based on share of supply * borrow_share_multiplier */
|
|
310
|
+
per_user_cap_sol: number;
|
|
311
|
+
/** Current interest rate in bps per epoch */
|
|
312
|
+
interest_rate_bps: number;
|
|
313
|
+
/** Liquidation threshold in bps */
|
|
314
|
+
liquidation_threshold_bps: number;
|
|
315
|
+
}
|
|
299
316
|
export interface FactionPower {
|
|
300
317
|
mint: string;
|
|
301
318
|
name: string;
|
package/package.json
CHANGED
package/src/actions.ts
CHANGED
|
@@ -61,6 +61,7 @@ import type {
|
|
|
61
61
|
AgentLink,
|
|
62
62
|
WarChest,
|
|
63
63
|
WarLoan,
|
|
64
|
+
WarLoanQuote,
|
|
64
65
|
AllWarLoansResult,
|
|
65
66
|
LaunchFactionParams,
|
|
66
67
|
JoinFactionParams,
|
|
@@ -105,6 +106,27 @@ import {
|
|
|
105
106
|
|
|
106
107
|
import { buildCreateFactionTransaction, isPyreMint } from './vanity';
|
|
107
108
|
|
|
109
|
+
// ─── Blacklist ──────────────────────────────────────────────────────
|
|
110
|
+
// Mints from previous swarm runs. Agents should skip these and only
|
|
111
|
+
// interact with freshly launched factions.
|
|
112
|
+
|
|
113
|
+
const BLACKLISTED_MINTS = new Set<string>();
|
|
114
|
+
|
|
115
|
+
/** Add mints to the blacklist (call at startup with old mints) */
|
|
116
|
+
export function blacklistMints(mints: string[]): void {
|
|
117
|
+
for (const m of mints) BLACKLISTED_MINTS.add(m);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Check if a mint is blacklisted */
|
|
121
|
+
export function isBlacklistedMint(mint: string): boolean {
|
|
122
|
+
return BLACKLISTED_MINTS.has(mint);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Get all blacklisted mints */
|
|
126
|
+
export function getBlacklistedMints(): string[] {
|
|
127
|
+
return Array.from(BLACKLISTED_MINTS);
|
|
128
|
+
}
|
|
129
|
+
|
|
108
130
|
// ─── Read Operations ───────────────────────────────────────────────
|
|
109
131
|
|
|
110
132
|
/** List all factions with optional filtering and sorting */
|
|
@@ -119,41 +141,7 @@ export async function getFactions(
|
|
|
119
141
|
sort: params.sort,
|
|
120
142
|
} : undefined;
|
|
121
143
|
const result = await getTokens(connection, sdkParams);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
// Enrich ascended factions with live pool price (list endpoint only has stale bonding curve mcap)
|
|
125
|
-
// Use Promise.allSettled so a single failure doesn't block/break the list
|
|
126
|
-
const ascended = listResult.factions.filter(f => f.status === 'ascended');
|
|
127
|
-
if (ascended.length > 0) {
|
|
128
|
-
const enrichPromise = Promise.allSettled(ascended.map(async (faction) => {
|
|
129
|
-
const mint = new PublicKey(faction.mint);
|
|
130
|
-
const raydium = getRaydiumMigrationAccounts(mint);
|
|
131
|
-
const [vault0Info, vault1Info] = await Promise.all([
|
|
132
|
-
connection.getTokenAccountBalance(raydium.token0Vault),
|
|
133
|
-
connection.getTokenAccountBalance(raydium.token1Vault),
|
|
134
|
-
]);
|
|
135
|
-
const vault0 = Number(vault0Info.value.amount);
|
|
136
|
-
const vault1 = Number(vault1Info.value.amount);
|
|
137
|
-
const solReserves = raydium.isWsolToken0 ? vault0 : vault1;
|
|
138
|
-
const tokenReserves = raydium.isWsolToken0 ? vault1 : vault0;
|
|
139
|
-
if (tokenReserves > 0) {
|
|
140
|
-
const LAMPORTS = 1_000_000_000;
|
|
141
|
-
const TOKEN_MUL = 1_000_000;
|
|
142
|
-
const priceInSol = (solReserves * TOKEN_MUL) / (tokenReserves * LAMPORTS);
|
|
143
|
-
const TOTAL_SUPPLY = 1_000_000_000 * TOKEN_MUL;
|
|
144
|
-
faction.price_sol = priceInSol;
|
|
145
|
-
faction.market_cap_sol = (priceInSol * TOTAL_SUPPLY) / TOKEN_MUL;
|
|
146
|
-
}
|
|
147
|
-
}));
|
|
148
|
-
|
|
149
|
-
// Race enrichment against a 3s timeout so the list always loads
|
|
150
|
-
await Promise.race([
|
|
151
|
-
enrichPromise,
|
|
152
|
-
new Promise(resolve => setTimeout(resolve, 3000)),
|
|
153
|
-
]);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return listResult;
|
|
144
|
+
return mapTokenListResult(result);
|
|
157
145
|
}
|
|
158
146
|
|
|
159
147
|
/** Get detailed info for a single faction */
|
|
@@ -352,6 +340,66 @@ export async function getAllWarLoans(
|
|
|
352
340
|
return mapAllLoansResult(result);
|
|
353
341
|
}
|
|
354
342
|
|
|
343
|
+
/**
|
|
344
|
+
* Compute max borrowable SOL for a given collateral amount.
|
|
345
|
+
*
|
|
346
|
+
* Mirrors the burnfun LendingDashboard logic — effective max borrow is the
|
|
347
|
+
* minimum of three caps:
|
|
348
|
+
* 1. LTV limit: collateral_value_sol * (max_ltv_bps / 10000)
|
|
349
|
+
* 2. Pool available: treasury_sol * utilization_cap - total_lent
|
|
350
|
+
* 3. Per-user cap: (collateral / total_supply) * borrow_share_multiplier * max_lendable
|
|
351
|
+
*
|
|
352
|
+
* All values in lamports. Accounts for Token-2022 transfer fee (4 bps).
|
|
353
|
+
*/
|
|
354
|
+
export async function getMaxWarLoan(
|
|
355
|
+
connection: Connection,
|
|
356
|
+
mint: string,
|
|
357
|
+
collateralAmount: number,
|
|
358
|
+
): Promise<WarLoanQuote> {
|
|
359
|
+
const TOTAL_SUPPLY = 1_000_000_000_000_000; // 1B tokens * 1e6 multiplier (base units)
|
|
360
|
+
const TRANSFER_FEE_BPS = 4;
|
|
361
|
+
const LAMPORTS_PER_SOL = 1_000_000_000;
|
|
362
|
+
|
|
363
|
+
const [lending, detail] = await Promise.all([
|
|
364
|
+
getLendingInfo(connection, mint),
|
|
365
|
+
getToken(connection, mint),
|
|
366
|
+
]);
|
|
367
|
+
|
|
368
|
+
// Price per base-unit token in SOL (lamports)
|
|
369
|
+
const pricePerToken = detail.price_sol; // SOL per display token
|
|
370
|
+
const TOKEN_MULTIPLIER = 1_000_000;
|
|
371
|
+
|
|
372
|
+
// Collateral value in SOL (lamports)
|
|
373
|
+
const collateralDisplayTokens = collateralAmount / TOKEN_MULTIPLIER;
|
|
374
|
+
const collateralValueSol = collateralDisplayTokens * pricePerToken * LAMPORTS_PER_SOL;
|
|
375
|
+
|
|
376
|
+
// 1. LTV cap
|
|
377
|
+
const ltvMaxSol = collateralValueSol * (lending.max_ltv_bps / 10000);
|
|
378
|
+
|
|
379
|
+
// 2. Pool available
|
|
380
|
+
const treasurySol = detail.treasury_sol_balance * LAMPORTS_PER_SOL;
|
|
381
|
+
const maxLendableSol = treasurySol * lending.utilization_cap_bps / 10000;
|
|
382
|
+
const totalLent = (lending.total_sol_lent ?? 0);
|
|
383
|
+
const poolAvailableSol = Math.max(0, maxLendableSol - totalLent);
|
|
384
|
+
|
|
385
|
+
// 3. Per-user cap (accounts for transfer fee reducing net collateral)
|
|
386
|
+
const netCollateral = collateralAmount * (1 - TRANSFER_FEE_BPS / 10000);
|
|
387
|
+
const borrowMultiplier = lending.borrow_share_multiplier || 3;
|
|
388
|
+
const perUserCapSol = maxLendableSol * netCollateral * borrowMultiplier / TOTAL_SUPPLY;
|
|
389
|
+
|
|
390
|
+
const maxBorrowSol = Math.max(0, Math.min(ltvMaxSol, poolAvailableSol, perUserCapSol));
|
|
391
|
+
|
|
392
|
+
return {
|
|
393
|
+
max_borrow_sol: Math.floor(maxBorrowSol),
|
|
394
|
+
collateral_value_sol: Math.floor(collateralValueSol),
|
|
395
|
+
ltv_max_sol: Math.floor(ltvMaxSol),
|
|
396
|
+
pool_available_sol: Math.floor(poolAvailableSol),
|
|
397
|
+
per_user_cap_sol: Math.floor(perUserCapSol),
|
|
398
|
+
interest_rate_bps: lending.interest_rate_bps,
|
|
399
|
+
liquidation_threshold_bps: lending.liquidation_threshold_bps,
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
355
403
|
// ─── Faction Operations (controller) ───────────────────────────────
|
|
356
404
|
|
|
357
405
|
/** Launch a new faction (create token) */
|
package/src/index.ts
CHANGED
|
@@ -29,6 +29,7 @@ export type {
|
|
|
29
29
|
MembersResult,
|
|
30
30
|
CommsResult,
|
|
31
31
|
AllWarLoansResult,
|
|
32
|
+
WarLoanQuote,
|
|
32
33
|
// Params
|
|
33
34
|
LaunchFactionParams,
|
|
34
35
|
JoinFactionParams,
|
|
@@ -89,6 +90,11 @@ export {
|
|
|
89
90
|
getWarChest,
|
|
90
91
|
getWarLoan,
|
|
91
92
|
getAllWarLoans,
|
|
93
|
+
getMaxWarLoan,
|
|
94
|
+
// Blacklist
|
|
95
|
+
blacklistMints,
|
|
96
|
+
isBlacklistedMint,
|
|
97
|
+
getBlacklistedMints,
|
|
92
98
|
// Faction operations
|
|
93
99
|
launchFaction,
|
|
94
100
|
joinFaction,
|
package/src/types.ts
CHANGED
|
@@ -360,6 +360,26 @@ export interface FactionListParams {
|
|
|
360
360
|
sort?: FactionSortOption;
|
|
361
361
|
}
|
|
362
362
|
|
|
363
|
+
// ─── War Loan Quote ─────────────────────────────────────────────
|
|
364
|
+
|
|
365
|
+
/** Result of computing max borrowable SOL for a given collateral amount */
|
|
366
|
+
export interface WarLoanQuote {
|
|
367
|
+
/** Max SOL borrowable (lamports) — minimum of LTV cap, pool available, per-user cap */
|
|
368
|
+
max_borrow_sol: number;
|
|
369
|
+
/** Collateral value in SOL (lamports) */
|
|
370
|
+
collateral_value_sol: number;
|
|
371
|
+
/** LTV-limited max borrow (lamports) */
|
|
372
|
+
ltv_max_sol: number;
|
|
373
|
+
/** Pool available SOL (lamports) */
|
|
374
|
+
pool_available_sol: number;
|
|
375
|
+
/** Per-user cap SOL (lamports) — based on share of supply * borrow_share_multiplier */
|
|
376
|
+
per_user_cap_sol: number;
|
|
377
|
+
/** Current interest rate in bps per epoch */
|
|
378
|
+
interest_rate_bps: number;
|
|
379
|
+
/** Liquidation threshold in bps */
|
|
380
|
+
liquidation_threshold_bps: number;
|
|
381
|
+
}
|
|
382
|
+
|
|
363
383
|
// ─── Intel Types ───────────────────────────────────────────────────
|
|
364
384
|
|
|
365
385
|
export interface FactionPower {
|