pyre-agent-kit 2.0.14 → 2.0.16
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/executor.js +15 -13
- package/dist/index.js +2 -0
- package/dist/stronghold.js +34 -25
- package/dist/types.d.ts +2 -0
- package/package.json +2 -2
package/dist/executor.js
CHANGED
|
@@ -10,6 +10,8 @@ const action_1 = require("./action");
|
|
|
10
10
|
const error_1 = require("./error");
|
|
11
11
|
const faction_1 = require("./faction");
|
|
12
12
|
const findFaction = (factions, symbol) => factions.find(f => f.symbol === symbol);
|
|
13
|
+
/** Vault creator key — may differ from agent key for linked vaults */
|
|
14
|
+
const vault = (agent) => agent.vaultCreator ?? agent.publicKey;
|
|
13
15
|
const handlers = {
|
|
14
16
|
async join(ctx) {
|
|
15
17
|
const faction = findFaction(ctx.factions, ctx.decision.faction);
|
|
@@ -22,7 +24,7 @@ const handlers = {
|
|
|
22
24
|
return null;
|
|
23
25
|
if (faction.status === 'ascended') {
|
|
24
26
|
const result = await (0, pyre_world_kit_1.tradeOnDex)(ctx.connection, {
|
|
25
|
-
mint: faction.mint, signer: ctx.agent.publicKey, stronghold_creator: ctx.agent
|
|
27
|
+
mint: faction.mint, signer: ctx.agent.publicKey, stronghold_creator: vault(ctx.agent),
|
|
26
28
|
amount_in: lamports, minimum_amount_out: 1, is_buy: true, message: ctx.decision.message,
|
|
27
29
|
});
|
|
28
30
|
await (0, tx_1.sendAndConfirm)(ctx.connection, ctx.agent.keypair, result);
|
|
@@ -31,7 +33,7 @@ const handlers = {
|
|
|
31
33
|
const alreadyVoted = ctx.agent.voted.has(faction.mint);
|
|
32
34
|
const params = {
|
|
33
35
|
mint: faction.mint, agent: ctx.agent.publicKey, amount_sol: lamports,
|
|
34
|
-
message: ctx.decision.message, stronghold: ctx.agent
|
|
36
|
+
message: ctx.decision.message, stronghold: vault(ctx.agent),
|
|
35
37
|
};
|
|
36
38
|
if (!alreadyVoted)
|
|
37
39
|
params.strategy = Math.random() > 0.5 ? 'fortify' : 'scorched_earth';
|
|
@@ -73,7 +75,7 @@ const handlers = {
|
|
|
73
75
|
if (!ctx.agent.hasStronghold)
|
|
74
76
|
return null;
|
|
75
77
|
const result = await (0, pyre_world_kit_1.tradeOnDex)(ctx.connection, {
|
|
76
|
-
mint: faction.mint, signer: ctx.agent.publicKey, stronghold_creator: ctx.agent
|
|
78
|
+
mint: faction.mint, signer: ctx.agent.publicKey, stronghold_creator: vault(ctx.agent),
|
|
77
79
|
amount_in: sellAmount, minimum_amount_out: 1, is_buy: false, message: ctx.decision.message,
|
|
78
80
|
});
|
|
79
81
|
await (0, tx_1.sendAndConfirm)(ctx.connection, ctx.agent.keypair, result);
|
|
@@ -81,7 +83,7 @@ const handlers = {
|
|
|
81
83
|
else {
|
|
82
84
|
const result = await (0, pyre_world_kit_1.defect)(ctx.connection, {
|
|
83
85
|
mint: faction.mint, agent: ctx.agent.publicKey, amount_tokens: sellAmount,
|
|
84
|
-
message: ctx.decision.message, stronghold: ctx.agent
|
|
86
|
+
message: ctx.decision.message, stronghold: vault(ctx.agent),
|
|
85
87
|
});
|
|
86
88
|
await (0, tx_1.sendAndConfirm)(ctx.connection, ctx.agent.keypair, result);
|
|
87
89
|
}
|
|
@@ -102,7 +104,7 @@ const handlers = {
|
|
|
102
104
|
if (!faction || ctx.agent.rallied.has(faction.mint))
|
|
103
105
|
return null;
|
|
104
106
|
const result = await (0, pyre_world_kit_1.rally)(ctx.connection, {
|
|
105
|
-
mint: faction.mint, agent: ctx.agent.publicKey, stronghold: ctx.agent
|
|
107
|
+
mint: faction.mint, agent: ctx.agent.publicKey, stronghold: vault(ctx.agent),
|
|
106
108
|
});
|
|
107
109
|
await (0, tx_1.sendAndConfirm)(ctx.connection, ctx.agent.keypair, result);
|
|
108
110
|
ctx.agent.rallied.add(faction.mint);
|
|
@@ -151,7 +153,7 @@ const handlers = {
|
|
|
151
153
|
return null;
|
|
152
154
|
let result = await (0, pyre_world_kit_1.messageFaction)(ctx.connection, {
|
|
153
155
|
mint: faction.mint, agent: ctx.agent.publicKey, message: ctx.decision.message,
|
|
154
|
-
stronghold: ctx.agent
|
|
156
|
+
stronghold: vault(ctx.agent), ascended: faction.status === 'ascended',
|
|
155
157
|
first_buy: !ctx.agent.voted.has(faction.mint),
|
|
156
158
|
});
|
|
157
159
|
try {
|
|
@@ -163,7 +165,7 @@ const handlers = {
|
|
|
163
165
|
ctx.agent.voted.add(faction.mint);
|
|
164
166
|
result = await (0, pyre_world_kit_1.messageFaction)(ctx.connection, {
|
|
165
167
|
mint: faction.mint, agent: ctx.agent.publicKey, message: ctx.decision.message,
|
|
166
|
-
stronghold: ctx.agent
|
|
168
|
+
stronghold: vault(ctx.agent), ascended: faction.status === 'ascended', first_buy: false,
|
|
167
169
|
});
|
|
168
170
|
await (0, tx_1.sendAndConfirm)(ctx.connection, ctx.agent.keypair, result);
|
|
169
171
|
}
|
|
@@ -205,7 +207,7 @@ const handlers = {
|
|
|
205
207
|
await (0, stronghold_1.ensureStronghold)(ctx.connection, ctx.agent, ctx.log, ctx.strongholdOpts);
|
|
206
208
|
const result = await (0, pyre_world_kit_1.requestWarLoan)(ctx.connection, {
|
|
207
209
|
mint: faction.mint, borrower: ctx.agent.publicKey, collateral_amount: collateral,
|
|
208
|
-
sol_to_borrow: borrowLamports, stronghold: ctx.agent
|
|
210
|
+
sol_to_borrow: borrowLamports, stronghold: vault(ctx.agent),
|
|
209
211
|
});
|
|
210
212
|
await (0, tx_1.sendAndConfirm)(ctx.connection, ctx.agent.keypair, result);
|
|
211
213
|
ctx.agent.activeLoans.add(faction.mint);
|
|
@@ -229,7 +231,7 @@ const handlers = {
|
|
|
229
231
|
}
|
|
230
232
|
const result = await (0, pyre_world_kit_1.repayWarLoan)(ctx.connection, {
|
|
231
233
|
mint: faction.mint, borrower: ctx.agent.publicKey,
|
|
232
|
-
sol_amount: Math.ceil(loan.total_owed), stronghold: ctx.agent
|
|
234
|
+
sol_amount: Math.ceil(loan.total_owed), stronghold: vault(ctx.agent),
|
|
233
235
|
});
|
|
234
236
|
await (0, tx_1.sendAndConfirm)(ctx.connection, ctx.agent.keypair, result);
|
|
235
237
|
ctx.agent.activeLoans.delete(faction.mint);
|
|
@@ -257,7 +259,7 @@ const handlers = {
|
|
|
257
259
|
return null;
|
|
258
260
|
const result = await (0, pyre_world_kit_1.siege)(ctx.connection, {
|
|
259
261
|
mint: faction.mint, liquidator: ctx.agent.publicKey,
|
|
260
|
-
borrower: targetBorrower, stronghold: ctx.agent
|
|
262
|
+
borrower: targetBorrower, stronghold: vault(ctx.agent),
|
|
261
263
|
});
|
|
262
264
|
await (0, tx_1.sendAndConfirm)(ctx.connection, ctx.agent.keypair, result);
|
|
263
265
|
ctx.agent.lastAction = `siege ${faction.symbol}`;
|
|
@@ -308,7 +310,7 @@ const handlers = {
|
|
|
308
310
|
return null;
|
|
309
311
|
if (faction.status === 'ascended') {
|
|
310
312
|
const result = await (0, pyre_world_kit_1.tradeOnDex)(ctx.connection, {
|
|
311
|
-
mint: faction.mint, signer: ctx.agent.publicKey, stronghold_creator: ctx.agent
|
|
313
|
+
mint: faction.mint, signer: ctx.agent.publicKey, stronghold_creator: vault(ctx.agent),
|
|
312
314
|
amount_in: lamports, minimum_amount_out: 1, is_buy: true, message: ctx.decision.message,
|
|
313
315
|
});
|
|
314
316
|
await (0, tx_1.sendAndConfirm)(ctx.connection, ctx.agent.keypair, result);
|
|
@@ -317,7 +319,7 @@ const handlers = {
|
|
|
317
319
|
const alreadyVoted = ctx.agent.voted.has(faction.mint);
|
|
318
320
|
const params = {
|
|
319
321
|
mint: faction.mint, agent: ctx.agent.publicKey, amount_sol: lamports,
|
|
320
|
-
message: ctx.decision.message, stronghold: ctx.agent
|
|
322
|
+
message: ctx.decision.message, stronghold: vault(ctx.agent),
|
|
321
323
|
};
|
|
322
324
|
if (!alreadyVoted)
|
|
323
325
|
params.strategy = 'scorched_earth';
|
|
@@ -341,7 +343,7 @@ const handlers = {
|
|
|
341
343
|
return null;
|
|
342
344
|
const result = await (0, pyre_world_kit_1.fudFaction)(ctx.connection, {
|
|
343
345
|
mint: faction.mint, agent: ctx.agent.publicKey, message: ctx.decision.message,
|
|
344
|
-
stronghold: ctx.agent
|
|
346
|
+
stronghold: vault(ctx.agent), ascended: faction.status === 'ascended',
|
|
345
347
|
});
|
|
346
348
|
await (0, tx_1.sendAndConfirm)(ctx.connection, ctx.agent.keypair, result);
|
|
347
349
|
// Fudding tanks your own sentiment — you're going bearish
|
package/dist/index.js
CHANGED
|
@@ -92,6 +92,7 @@ async function createPyreAgent(config) {
|
|
|
92
92
|
rallied: new Set(prior?.rallied ?? []),
|
|
93
93
|
voted: new Set([...(prior?.voted ?? []), ...Object.keys(prior?.holdings ?? {})]),
|
|
94
94
|
hasStronghold: prior?.hasStronghold ?? false,
|
|
95
|
+
vaultCreator: prior?.vaultCreator,
|
|
95
96
|
activeLoans: new Set(prior?.activeLoans ?? []),
|
|
96
97
|
infiltrated: new Set(prior?.infiltrated ?? []),
|
|
97
98
|
// Chain-derived sentiment as baseline, overwritten by serialized if available
|
|
@@ -123,6 +124,7 @@ async function createPyreAgent(config) {
|
|
|
123
124
|
rallied: Array.from(state.rallied),
|
|
124
125
|
voted: Array.from(state.voted),
|
|
125
126
|
hasStronghold: state.hasStronghold,
|
|
127
|
+
vaultCreator: state.vaultCreator,
|
|
126
128
|
activeLoans: Array.from(state.activeLoans),
|
|
127
129
|
infiltrated: Array.from(state.infiltrated),
|
|
128
130
|
sentiment: Object.fromEntries(state.sentiment),
|
package/dist/stronghold.js
CHANGED
|
@@ -9,36 +9,45 @@ const ensureStronghold = async (connection, agent, log, opts) => {
|
|
|
9
9
|
const short = agent.publicKey.slice(0, 8);
|
|
10
10
|
const topupThreshold = opts?.topupThresholdSol ?? defaults_1.STRONGHOLD_TOPUP_THRESHOLD_SOL;
|
|
11
11
|
const topupReserve = opts?.topupReserveSol ?? defaults_1.STRONGHOLD_TOPUP_RESERVE_SOL;
|
|
12
|
-
// Check if stronghold exists on-chain
|
|
12
|
+
// Check if stronghold exists on-chain (try creator lookup, then linked agent lookup)
|
|
13
|
+
let existing = null;
|
|
13
14
|
try {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
existing = await (0, pyre_world_kit_1.getStronghold)(connection, agent.publicKey);
|
|
16
|
+
}
|
|
17
|
+
catch { /* fetch failed */ }
|
|
18
|
+
if (!existing) {
|
|
19
|
+
try {
|
|
20
|
+
existing = await (0, pyre_world_kit_1.getStrongholdForAgent)(connection, agent.publicKey);
|
|
21
|
+
}
|
|
22
|
+
catch { /* fetch failed */ }
|
|
23
|
+
}
|
|
24
|
+
if (existing) {
|
|
25
|
+
agent.hasStronghold = true;
|
|
26
|
+
// Track vault creator for use in tx params (may differ from agent key for linked vaults)
|
|
27
|
+
agent.vaultCreator = existing.creator;
|
|
28
|
+
// Top up if below threshold
|
|
29
|
+
const vaultBal = existing.sol_balance ?? 0;
|
|
30
|
+
const threshold = topupThreshold * pyre_world_kit_1.LAMPORTS_PER_SOL;
|
|
31
|
+
if (vaultBal < threshold) {
|
|
32
|
+
try {
|
|
33
|
+
const walletBal = await connection.getBalance(new web3_js_1.PublicKey(agent.publicKey));
|
|
34
|
+
const reserve = topupReserve * pyre_world_kit_1.LAMPORTS_PER_SOL;
|
|
35
|
+
const available = walletBal - reserve;
|
|
36
|
+
if (available > 0.01 * pyre_world_kit_1.LAMPORTS_PER_SOL) {
|
|
37
|
+
const fundAmt = Math.floor(available);
|
|
38
|
+
const fundResult = await (0, pyre_world_kit_1.fundStronghold)(connection, {
|
|
39
|
+
depositor: agent.publicKey,
|
|
40
|
+
stronghold_creator: existing.creator,
|
|
41
|
+
amount_sol: fundAmt,
|
|
42
|
+
});
|
|
43
|
+
await (0, tx_1.sendAndConfirm)(connection, agent.keypair, fundResult);
|
|
44
|
+
log(`[${short}] topped up vault with ${(fundAmt / pyre_world_kit_1.LAMPORTS_PER_SOL).toFixed(2)} SOL`);
|
|
35
45
|
}
|
|
36
|
-
catch { /* top-up failed, continue anyway */ }
|
|
37
46
|
}
|
|
38
|
-
|
|
47
|
+
catch { /* top-up failed, continue anyway */ }
|
|
39
48
|
}
|
|
49
|
+
return;
|
|
40
50
|
}
|
|
41
|
-
catch { /* fetch failed */ }
|
|
42
51
|
// No vault found — user needs to create one on pyre.world
|
|
43
52
|
log(`[${short}] no vault found — create one at pyre.world and link agent key ${agent.publicKey}`);
|
|
44
53
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export interface AgentState {
|
|
|
35
35
|
rallied: Set<string>;
|
|
36
36
|
voted: Set<string>;
|
|
37
37
|
hasStronghold: boolean;
|
|
38
|
+
vaultCreator?: string;
|
|
38
39
|
activeLoans: Set<string>;
|
|
39
40
|
infiltrated: Set<string>;
|
|
40
41
|
sentiment: Map<string, number>;
|
|
@@ -94,6 +95,7 @@ export interface SerializedAgentState {
|
|
|
94
95
|
rallied: string[];
|
|
95
96
|
voted: string[];
|
|
96
97
|
hasStronghold: boolean;
|
|
98
|
+
vaultCreator?: string;
|
|
97
99
|
activeLoans: string[];
|
|
98
100
|
infiltrated: string[];
|
|
99
101
|
sentiment: Record<string, number>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pyre-agent-kit",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.16",
|
|
4
4
|
"description": "Autonomous agent kit for Pyre — plug in your own LLM and play pyre.world",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@solana/spl-token": "^0.4.6",
|
|
17
17
|
"@solana/web3.js": "^1.98.4",
|
|
18
|
-
"pyre-world-kit": "1.0.
|
|
18
|
+
"pyre-world-kit": "1.0.23"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/node": "^25.4.0",
|