pyre-world-kit 2.0.11 → 3.0.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/.prettierrc.json +6 -0
- package/dist/actions.js +16 -0
- package/dist/index.d.ts +38 -4
- package/dist/index.js +100 -85
- package/dist/providers/action.provider.d.ts +46 -0
- package/dist/providers/action.provider.js +331 -0
- package/dist/providers/intel.provider.d.ts +29 -0
- package/dist/providers/intel.provider.js +363 -0
- package/dist/providers/mapper.provider.d.ts +197 -0
- package/dist/providers/mapper.provider.js +158 -0
- package/dist/providers/registry.provider.d.ts +25 -0
- package/dist/providers/registry.provider.js +229 -0
- package/dist/providers/state.provider.d.ts +42 -0
- package/dist/providers/state.provider.js +348 -0
- package/dist/pyre_world.json +34 -229
- package/dist/types/action.types.d.ts +41 -0
- package/dist/types/action.types.js +2 -0
- package/dist/types/intel.types.d.ts +20 -0
- package/dist/types/intel.types.js +2 -0
- package/dist/types/mapper.types.d.ts +27 -0
- package/dist/types/mapper.types.js +22 -0
- package/dist/types/registry.types.d.ts +0 -0
- package/dist/types/registry.types.js +1 -0
- package/dist/types/state.types.d.ts +112 -0
- package/dist/types/state.types.js +2 -0
- package/dist/types.d.ts +8 -24
- package/dist/util.d.ts +29 -0
- package/dist/util.js +144 -0
- package/dist/vanity.d.ts +3 -3
- package/dist/vanity.js +18 -15
- package/package.json +4 -2
- package/readme.md +134 -122
- package/src/index.ts +127 -92
- package/src/providers/action.provider.ts +443 -0
- package/src/providers/intel.provider.ts +383 -0
- package/src/providers/mapper.provider.ts +195 -0
- package/src/providers/registry.provider.ts +277 -0
- package/src/providers/state.provider.ts +357 -0
- package/src/pyre_world.json +35 -230
- package/src/types/action.types.ts +76 -0
- package/src/types/intel.types.ts +22 -0
- package/src/types/mapper.types.ts +84 -0
- package/src/types/registry.types.ts +0 -0
- package/src/types/state.types.ts +144 -0
- package/src/types.ts +329 -333
- package/src/util.ts +148 -0
- package/src/vanity.ts +27 -14
- package/tests/test_e2e.ts +339 -172
- package/src/actions.ts +0 -703
- package/src/intel.ts +0 -521
- package/src/mappers.ts +0 -302
- package/src/registry.ts +0 -317
- package/tests/test_devnet_e2e.ts +0 -401
- package/tests/test_sim.ts +0 -458
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Pyre Kit Mappers
|
|
4
|
+
*
|
|
5
|
+
* Internal mapping functions between Torch SDK types and Pyre game types.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.MapperProvider = void 0;
|
|
9
|
+
const mapper_types_1 = require("../types/mapper.types");
|
|
10
|
+
class MapperProvider {
|
|
11
|
+
allLoansResult = (r) => ({
|
|
12
|
+
positions: r.positions.map(this.loanWithKeyToWarLoan),
|
|
13
|
+
pool_price_sol: r.pool_price_sol,
|
|
14
|
+
});
|
|
15
|
+
buyResult = (r) => ({
|
|
16
|
+
transaction: r.transaction,
|
|
17
|
+
additionalTransactions: r.additionalTransactions,
|
|
18
|
+
message: r.message,
|
|
19
|
+
migrationTransaction: r.migrationTransaction,
|
|
20
|
+
});
|
|
21
|
+
createResult = (r) => ({
|
|
22
|
+
transaction: r.transaction,
|
|
23
|
+
additionalTransactions: r.additionalTransactions,
|
|
24
|
+
message: r.message,
|
|
25
|
+
mint: r.mint,
|
|
26
|
+
mintKeypair: r.mintKeypair,
|
|
27
|
+
});
|
|
28
|
+
factionStatus = (status) => mapper_types_1.STATUS_MAP[status];
|
|
29
|
+
holdersResult = (r) => ({
|
|
30
|
+
members: r.holders.map(this.holderToMember),
|
|
31
|
+
total_members: r.total_holders,
|
|
32
|
+
});
|
|
33
|
+
holderToMember = (h) => ({
|
|
34
|
+
address: h.address,
|
|
35
|
+
balance: h.balance,
|
|
36
|
+
percentage: h.percentage,
|
|
37
|
+
});
|
|
38
|
+
lendingToWarChest = (l) => ({
|
|
39
|
+
interest_rate_bps: l.interest_rate_bps,
|
|
40
|
+
max_ltv_bps: l.max_ltv_bps,
|
|
41
|
+
liquidation_threshold_bps: l.liquidation_threshold_bps,
|
|
42
|
+
liquidation_bonus_bps: l.liquidation_bonus_bps,
|
|
43
|
+
utilization_cap_bps: l.utilization_cap_bps,
|
|
44
|
+
borrow_share_multiplier: l.borrow_share_multiplier,
|
|
45
|
+
total_sol_lent: l.total_sol_lent,
|
|
46
|
+
active_loans: l.active_loans,
|
|
47
|
+
war_chest_sol_available: l.treasury_sol_available,
|
|
48
|
+
warnings: l.warnings,
|
|
49
|
+
});
|
|
50
|
+
loanToWarLoan = (l) => ({
|
|
51
|
+
collateral_amount: l.collateral_amount,
|
|
52
|
+
borrowed_amount: l.borrowed_amount,
|
|
53
|
+
accrued_interest: l.accrued_interest,
|
|
54
|
+
total_owed: l.total_owed,
|
|
55
|
+
collateral_value_sol: l.collateral_value_sol,
|
|
56
|
+
current_ltv_bps: l.current_ltv_bps,
|
|
57
|
+
health: l.health,
|
|
58
|
+
warnings: l.warnings,
|
|
59
|
+
});
|
|
60
|
+
loanWithKeyToWarLoan = (l) => ({
|
|
61
|
+
...this.loanToWarLoan(l),
|
|
62
|
+
borrower: l.borrower,
|
|
63
|
+
});
|
|
64
|
+
messagesResult = (r) => ({
|
|
65
|
+
comms: r.messages.map(this.tokenMessageToComms),
|
|
66
|
+
total: r.total,
|
|
67
|
+
});
|
|
68
|
+
strategy = (vote) => (vote === 'burn' ? 'smelt' : 'fortify');
|
|
69
|
+
tokenDetailToFaction = (t) => ({
|
|
70
|
+
mint: t.mint,
|
|
71
|
+
name: t.name,
|
|
72
|
+
symbol: t.symbol,
|
|
73
|
+
description: t.description,
|
|
74
|
+
image: t.image,
|
|
75
|
+
status: this.factionStatus(t.status),
|
|
76
|
+
price_sol: t.price_sol,
|
|
77
|
+
price_usd: t.price_usd,
|
|
78
|
+
market_cap_sol: t.market_cap_sol,
|
|
79
|
+
market_cap_usd: t.market_cap_usd,
|
|
80
|
+
progress_percent: t.progress_percent,
|
|
81
|
+
sol_raised: t.sol_raised,
|
|
82
|
+
sol_target: t.sol_target,
|
|
83
|
+
total_supply: t.total_supply,
|
|
84
|
+
circulating_supply: t.circulating_supply,
|
|
85
|
+
tokens_in_curve: t.tokens_in_curve,
|
|
86
|
+
tokens_in_vote_vault: t.tokens_in_vote_vault,
|
|
87
|
+
tokens_burned: t.tokens_burned,
|
|
88
|
+
war_chest_sol: t.treasury_sol_balance,
|
|
89
|
+
war_chest_tokens: t.treasury_token_balance,
|
|
90
|
+
total_bought_back: t.total_bought_back,
|
|
91
|
+
buyback_count: t.buyback_count,
|
|
92
|
+
votes_scorched_earth: t.votes_burn,
|
|
93
|
+
votes_fortify: t.votes_return,
|
|
94
|
+
founder: t.creator,
|
|
95
|
+
members: t.holders,
|
|
96
|
+
rallies: t.stars,
|
|
97
|
+
created_at: t.created_at,
|
|
98
|
+
last_activity_at: t.last_activity_at,
|
|
99
|
+
twitter: t.twitter,
|
|
100
|
+
telegram: t.telegram,
|
|
101
|
+
website: t.website,
|
|
102
|
+
founder_verified: t.creator_verified,
|
|
103
|
+
founder_trust_tier: t.creator_trust_tier,
|
|
104
|
+
founder_said_name: t.creator_said_name,
|
|
105
|
+
founder_badge_url: t.creator_badge_url,
|
|
106
|
+
warnings: t.warnings,
|
|
107
|
+
});
|
|
108
|
+
tokenListResult = (r) => ({
|
|
109
|
+
factions: r.tokens.map(this.tokenSummaryToFaction),
|
|
110
|
+
total: r.total,
|
|
111
|
+
limit: r.limit,
|
|
112
|
+
offset: r.offset,
|
|
113
|
+
});
|
|
114
|
+
tokenMessageToComms = (m) => ({
|
|
115
|
+
signature: m.signature,
|
|
116
|
+
memo: m.memo,
|
|
117
|
+
sender: m.sender,
|
|
118
|
+
timestamp: m.timestamp,
|
|
119
|
+
sender_verified: m.sender_verified,
|
|
120
|
+
sender_trust_tier: m.sender_trust_tier,
|
|
121
|
+
sender_said_name: m.sender_said_name,
|
|
122
|
+
sender_badge_url: m.sender_badge_url,
|
|
123
|
+
});
|
|
124
|
+
tokenStatus = (status) => mapper_types_1.STATUS_REVERSE[status];
|
|
125
|
+
tokenStatusFilter = (status) => mapper_types_1.STATUS_FILTER_REVERSE[status];
|
|
126
|
+
tokenSummaryToFaction = (t) => ({
|
|
127
|
+
mint: t.mint,
|
|
128
|
+
name: t.name,
|
|
129
|
+
symbol: t.symbol,
|
|
130
|
+
status: this.factionStatus(t.status),
|
|
131
|
+
price_sol: t.price_sol,
|
|
132
|
+
market_cap_sol: t.market_cap_sol,
|
|
133
|
+
progress_percent: t.progress_percent,
|
|
134
|
+
members: t.holders,
|
|
135
|
+
created_at: t.created_at,
|
|
136
|
+
last_activity_at: t.last_activity_at,
|
|
137
|
+
});
|
|
138
|
+
vote = (strategy) => (strategy === 'smelt' ? 'burn' : 'return');
|
|
139
|
+
vaultToStronghold = (v) => ({
|
|
140
|
+
address: v.address,
|
|
141
|
+
creator: v.creator,
|
|
142
|
+
authority: v.authority,
|
|
143
|
+
sol_balance: v.sol_balance,
|
|
144
|
+
total_deposited: v.total_deposited,
|
|
145
|
+
total_withdrawn: v.total_withdrawn,
|
|
146
|
+
total_spent: v.total_spent,
|
|
147
|
+
total_received: v.total_received,
|
|
148
|
+
linked_agents: v.linked_wallets,
|
|
149
|
+
created_at: v.created_at,
|
|
150
|
+
});
|
|
151
|
+
walletLinkToAgentLink = (l) => ({
|
|
152
|
+
address: l.address,
|
|
153
|
+
stronghold: l.vault,
|
|
154
|
+
wallet: l.wallet,
|
|
155
|
+
linked_at: l.linked_at,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
exports.MapperProvider = MapperProvider;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pyre World Agent Registry Provider
|
|
3
|
+
*
|
|
4
|
+
* On-chain agent identity and state persistence.
|
|
5
|
+
* Agents checkpoint their action distributions and personality summaries
|
|
6
|
+
* so any machine with the wallet key can reconstruct the agent.
|
|
7
|
+
*/
|
|
8
|
+
import { Connection, PublicKey } from '@solana/web3.js';
|
|
9
|
+
import type { TransactionResult } from 'torchsdk';
|
|
10
|
+
import type { RegistryProfile, RegistryWalletLink, RegisterAgentParams, CheckpointParams, LinkAgentWalletParams, UnlinkAgentWalletParams, TransferAgentAuthorityParams } from '../types';
|
|
11
|
+
export declare const REGISTRY_PROGRAM_ID: PublicKey;
|
|
12
|
+
export declare function getAgentProfilePda(creator: PublicKey): [PublicKey, number];
|
|
13
|
+
export declare function getAgentWalletLinkPda(wallet: PublicKey): [PublicKey, number];
|
|
14
|
+
export declare class RegistryProvider {
|
|
15
|
+
private connection;
|
|
16
|
+
constructor(connection: Connection);
|
|
17
|
+
private getProgram;
|
|
18
|
+
getProfile(creator: string): Promise<RegistryProfile | null>;
|
|
19
|
+
getWalletLink(wallet: string): Promise<RegistryWalletLink | null>;
|
|
20
|
+
register(params: RegisterAgentParams): Promise<TransactionResult>;
|
|
21
|
+
checkpoint(params: CheckpointParams): Promise<TransactionResult>;
|
|
22
|
+
linkWallet(params: LinkAgentWalletParams): Promise<TransactionResult>;
|
|
23
|
+
unlinkWallet(params: UnlinkAgentWalletParams): Promise<TransactionResult>;
|
|
24
|
+
transferAuthority(params: TransferAgentAuthorityParams): Promise<TransactionResult>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Pyre World Agent Registry Provider
|
|
4
|
+
*
|
|
5
|
+
* On-chain agent identity and state persistence.
|
|
6
|
+
* Agents checkpoint their action distributions and personality summaries
|
|
7
|
+
* so any machine with the wallet key can reconstruct the agent.
|
|
8
|
+
*/
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.RegistryProvider = exports.REGISTRY_PROGRAM_ID = void 0;
|
|
14
|
+
exports.getAgentProfilePda = getAgentProfilePda;
|
|
15
|
+
exports.getAgentWalletLinkPda = getAgentWalletLinkPda;
|
|
16
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
17
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
18
|
+
const pyre_world_json_1 = __importDefault(require("../pyre_world.json"));
|
|
19
|
+
// ─── Program ID ─────────────────────────────────────────────────────
|
|
20
|
+
exports.REGISTRY_PROGRAM_ID = new web3_js_1.PublicKey(pyre_world_json_1.default.address);
|
|
21
|
+
// ─── PDA Seeds ──────────────────────────────────────────────────────
|
|
22
|
+
const AGENT_SEED = 'pyre_agent';
|
|
23
|
+
const AGENT_WALLET_SEED = 'pyre_agent_wallet';
|
|
24
|
+
// ─── PDA Helpers ────────────────────────────────────────────────────
|
|
25
|
+
function getAgentProfilePda(creator) {
|
|
26
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(AGENT_SEED), creator.toBuffer()], exports.REGISTRY_PROGRAM_ID);
|
|
27
|
+
}
|
|
28
|
+
function getAgentWalletLinkPda(wallet) {
|
|
29
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(AGENT_WALLET_SEED), wallet.toBuffer()], exports.REGISTRY_PROGRAM_ID);
|
|
30
|
+
}
|
|
31
|
+
// ─── Anchor Program Helper ──────────────────────────────────────────
|
|
32
|
+
function makeDummyProvider(connection, payer) {
|
|
33
|
+
const dummyWallet = {
|
|
34
|
+
publicKey: payer,
|
|
35
|
+
signTransaction: async (t) => t,
|
|
36
|
+
signAllTransactions: async (t) => t,
|
|
37
|
+
};
|
|
38
|
+
return new anchor_1.AnchorProvider(connection, dummyWallet, {});
|
|
39
|
+
}
|
|
40
|
+
async function finalizeTransaction(connection, tx, feePayer) {
|
|
41
|
+
const { blockhash } = await connection.getLatestBlockhash();
|
|
42
|
+
tx.recentBlockhash = blockhash;
|
|
43
|
+
tx.feePayer = feePayer;
|
|
44
|
+
}
|
|
45
|
+
// ─── Provider ───────────────────────────────────────────────────────
|
|
46
|
+
class RegistryProvider {
|
|
47
|
+
connection;
|
|
48
|
+
constructor(connection) {
|
|
49
|
+
this.connection = connection;
|
|
50
|
+
}
|
|
51
|
+
getProgram(payer) {
|
|
52
|
+
const provider = makeDummyProvider(this.connection, payer);
|
|
53
|
+
return new anchor_1.Program(pyre_world_json_1.default, provider);
|
|
54
|
+
}
|
|
55
|
+
// ─── Read Operations ──────────────────────────────────────────────
|
|
56
|
+
async getProfile(creator) {
|
|
57
|
+
const creatorPk = new web3_js_1.PublicKey(creator);
|
|
58
|
+
const [profilePda] = getAgentProfilePda(creatorPk);
|
|
59
|
+
const program = this.getProgram(creatorPk);
|
|
60
|
+
try {
|
|
61
|
+
const account = await program.account.agentProfile.fetch(profilePda);
|
|
62
|
+
return {
|
|
63
|
+
address: profilePda.toBase58(),
|
|
64
|
+
creator: account.creator.toBase58(),
|
|
65
|
+
authority: account.authority.toBase58(),
|
|
66
|
+
linked_wallet: account.linkedWallet.toBase58(),
|
|
67
|
+
personality_summary: account.personalitySummary,
|
|
68
|
+
last_checkpoint: account.lastCheckpoint.toNumber(),
|
|
69
|
+
joins: account.joins.toNumber(),
|
|
70
|
+
defects: account.defects.toNumber(),
|
|
71
|
+
rallies: account.rallies.toNumber(),
|
|
72
|
+
launches: account.launches.toNumber(),
|
|
73
|
+
messages: account.messages.toNumber(),
|
|
74
|
+
fuds: account.fuds.toNumber(),
|
|
75
|
+
infiltrates: account.infiltrates.toNumber(),
|
|
76
|
+
reinforces: account.reinforces.toNumber(),
|
|
77
|
+
war_loans: account.warLoans.toNumber(),
|
|
78
|
+
repay_loans: account.repayLoans.toNumber(),
|
|
79
|
+
sieges: account.sieges.toNumber(),
|
|
80
|
+
ascends: account.ascends.toNumber(),
|
|
81
|
+
razes: account.razes.toNumber(),
|
|
82
|
+
tithes: account.tithes.toNumber(),
|
|
83
|
+
created_at: account.createdAt.toNumber(),
|
|
84
|
+
bump: account.bump,
|
|
85
|
+
total_sol_spent: account.totalSolSpent?.toNumber() ?? 0,
|
|
86
|
+
total_sol_received: account.totalSolReceived?.toNumber() ?? 0,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async getWalletLink(wallet) {
|
|
94
|
+
const walletPk = new web3_js_1.PublicKey(wallet);
|
|
95
|
+
const [linkPda] = getAgentWalletLinkPda(walletPk);
|
|
96
|
+
const program = this.getProgram(walletPk);
|
|
97
|
+
try {
|
|
98
|
+
const account = await program.account.agentWalletLink.fetch(linkPda);
|
|
99
|
+
return {
|
|
100
|
+
address: linkPda.toBase58(),
|
|
101
|
+
profile: account.profile.toBase58(),
|
|
102
|
+
wallet: account.wallet.toBase58(),
|
|
103
|
+
linked_at: account.linkedAt.toNumber(),
|
|
104
|
+
bump: account.bump,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// ─── Transaction Builders ─────────────────────────────────────────
|
|
112
|
+
async register(params) {
|
|
113
|
+
const creator = new web3_js_1.PublicKey(params.creator);
|
|
114
|
+
const [profile] = getAgentProfilePda(creator);
|
|
115
|
+
const [walletLink] = getAgentWalletLinkPda(creator);
|
|
116
|
+
const program = this.getProgram(creator);
|
|
117
|
+
const tx = new web3_js_1.Transaction();
|
|
118
|
+
const ix = await program.methods.register()
|
|
119
|
+
.accounts({ creator, profile, walletLink, systemProgram: web3_js_1.SystemProgram.programId })
|
|
120
|
+
.instruction();
|
|
121
|
+
tx.add(ix);
|
|
122
|
+
await finalizeTransaction(this.connection, tx, creator);
|
|
123
|
+
return {
|
|
124
|
+
transaction: tx,
|
|
125
|
+
message: `Register agent profile [${profile.toBase58()}]`,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
async checkpoint(params) {
|
|
129
|
+
const signer = new web3_js_1.PublicKey(params.signer);
|
|
130
|
+
const creatorPk = new web3_js_1.PublicKey(params.creator);
|
|
131
|
+
const [profile] = getAgentProfilePda(creatorPk);
|
|
132
|
+
const program = this.getProgram(signer);
|
|
133
|
+
const args = {
|
|
134
|
+
joins: new anchor_1.BN(params.joins),
|
|
135
|
+
defects: new anchor_1.BN(params.defects),
|
|
136
|
+
rallies: new anchor_1.BN(params.rallies),
|
|
137
|
+
launches: new anchor_1.BN(params.launches),
|
|
138
|
+
messages: new anchor_1.BN(params.messages),
|
|
139
|
+
fuds: new anchor_1.BN(params.fuds),
|
|
140
|
+
infiltrates: new anchor_1.BN(params.infiltrates),
|
|
141
|
+
reinforces: new anchor_1.BN(params.reinforces),
|
|
142
|
+
warLoans: new anchor_1.BN(params.war_loans),
|
|
143
|
+
repayLoans: new anchor_1.BN(params.repay_loans),
|
|
144
|
+
sieges: new anchor_1.BN(params.sieges),
|
|
145
|
+
ascends: new anchor_1.BN(params.ascends),
|
|
146
|
+
razes: new anchor_1.BN(params.razes),
|
|
147
|
+
tithes: new anchor_1.BN(params.tithes),
|
|
148
|
+
personalitySummary: params.personality_summary,
|
|
149
|
+
totalSolSpent: new anchor_1.BN(params.total_sol_spent),
|
|
150
|
+
totalSolReceived: new anchor_1.BN(params.total_sol_received),
|
|
151
|
+
};
|
|
152
|
+
const tx = new web3_js_1.Transaction();
|
|
153
|
+
const ix = await program.methods.checkpoint(args)
|
|
154
|
+
.accounts({ signer, profile, systemProgram: web3_js_1.SystemProgram.programId })
|
|
155
|
+
.instruction();
|
|
156
|
+
tx.add(ix);
|
|
157
|
+
await finalizeTransaction(this.connection, tx, signer);
|
|
158
|
+
return {
|
|
159
|
+
transaction: tx,
|
|
160
|
+
message: `Checkpoint agent [${profile.toBase58()}]`,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
async linkWallet(params) {
|
|
164
|
+
const authority = new web3_js_1.PublicKey(params.authority);
|
|
165
|
+
const creatorPk = new web3_js_1.PublicKey(params.creator);
|
|
166
|
+
const walletToLink = new web3_js_1.PublicKey(params.wallet_to_link);
|
|
167
|
+
const [profile] = getAgentProfilePda(creatorPk);
|
|
168
|
+
const [walletLink] = getAgentWalletLinkPda(walletToLink);
|
|
169
|
+
const program = this.getProgram(authority);
|
|
170
|
+
const tx = new web3_js_1.Transaction();
|
|
171
|
+
const ix = await program.methods.linkWallet()
|
|
172
|
+
.accounts({
|
|
173
|
+
authority,
|
|
174
|
+
profile,
|
|
175
|
+
walletToLink,
|
|
176
|
+
walletLink,
|
|
177
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
178
|
+
})
|
|
179
|
+
.instruction();
|
|
180
|
+
tx.add(ix);
|
|
181
|
+
await finalizeTransaction(this.connection, tx, authority);
|
|
182
|
+
return {
|
|
183
|
+
transaction: tx,
|
|
184
|
+
message: `Link wallet ${walletToLink.toBase58()} to agent [${profile.toBase58()}]`,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
async unlinkWallet(params) {
|
|
188
|
+
const authority = new web3_js_1.PublicKey(params.authority);
|
|
189
|
+
const creatorPk = new web3_js_1.PublicKey(params.creator);
|
|
190
|
+
const walletToUnlink = new web3_js_1.PublicKey(params.wallet_to_unlink);
|
|
191
|
+
const [profile] = getAgentProfilePda(creatorPk);
|
|
192
|
+
const [walletLink] = getAgentWalletLinkPda(walletToUnlink);
|
|
193
|
+
const program = this.getProgram(authority);
|
|
194
|
+
const tx = new web3_js_1.Transaction();
|
|
195
|
+
const ix = await program.methods.unlinkWallet()
|
|
196
|
+
.accounts({
|
|
197
|
+
authority,
|
|
198
|
+
profile,
|
|
199
|
+
walletToUnlink,
|
|
200
|
+
walletLink,
|
|
201
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
202
|
+
})
|
|
203
|
+
.instruction();
|
|
204
|
+
tx.add(ix);
|
|
205
|
+
await finalizeTransaction(this.connection, tx, authority);
|
|
206
|
+
return {
|
|
207
|
+
transaction: tx,
|
|
208
|
+
message: `Unlink wallet ${walletToUnlink.toBase58()} from agent [${profile.toBase58()}]`,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
async transferAuthority(params) {
|
|
212
|
+
const authority = new web3_js_1.PublicKey(params.authority);
|
|
213
|
+
const creatorPk = new web3_js_1.PublicKey(params.creator);
|
|
214
|
+
const newAuthority = new web3_js_1.PublicKey(params.new_authority);
|
|
215
|
+
const [profile] = getAgentProfilePda(creatorPk);
|
|
216
|
+
const program = this.getProgram(authority);
|
|
217
|
+
const tx = new web3_js_1.Transaction();
|
|
218
|
+
const ix = await program.methods.transferAuthority()
|
|
219
|
+
.accounts({ authority, profile, newAuthority })
|
|
220
|
+
.instruction();
|
|
221
|
+
tx.add(ix);
|
|
222
|
+
await finalizeTransaction(this.connection, tx, authority);
|
|
223
|
+
return {
|
|
224
|
+
transaction: tx,
|
|
225
|
+
message: `Transfer agent authority to ${newAuthority.toBase58()}`,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
exports.RegistryProvider = RegistryProvider;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pyre Kit State Provider
|
|
3
|
+
*
|
|
4
|
+
* Objective game state tracking for an agent.
|
|
5
|
+
* Owns holdings, action counts, vault resolution, tick counter.
|
|
6
|
+
* Injected into ActionProvider so every action automatically updates state.
|
|
7
|
+
*/
|
|
8
|
+
import { Connection } from '@solana/web3.js';
|
|
9
|
+
import type { State, AgentGameState, SerializedGameState, TrackedAction, CheckpointConfig } from '../types/state.types';
|
|
10
|
+
import { RegistryProvider } from './registry.provider';
|
|
11
|
+
export declare class StateProvider implements State {
|
|
12
|
+
private connection;
|
|
13
|
+
private publicKey;
|
|
14
|
+
private registry;
|
|
15
|
+
private _state;
|
|
16
|
+
private checkpointConfig;
|
|
17
|
+
private ticksSinceCheckpoint;
|
|
18
|
+
constructor(connection: Connection, publicKey: string, registry: RegistryProvider);
|
|
19
|
+
get state(): AgentGameState | null;
|
|
20
|
+
get vaultCreator(): string | null;
|
|
21
|
+
get initialized(): boolean;
|
|
22
|
+
get tick(): number;
|
|
23
|
+
/** Configure auto-checkpoint behavior */
|
|
24
|
+
setCheckpointConfig(config: CheckpointConfig): void;
|
|
25
|
+
init(): Promise<AgentGameState>;
|
|
26
|
+
record(action: TrackedAction, mint?: string, description?: string): Promise<void>;
|
|
27
|
+
/** Update sentiment score for a faction based on action type */
|
|
28
|
+
private updateSentiment;
|
|
29
|
+
/** Callback set by PyreKit to handle checkpoint triggers */
|
|
30
|
+
onCheckpointDue: (() => void) | null;
|
|
31
|
+
refreshHoldings(): Promise<void>;
|
|
32
|
+
getSentiment(mint: string): number;
|
|
33
|
+
get sentimentMap(): ReadonlyMap<string, number>;
|
|
34
|
+
get history(): readonly string[];
|
|
35
|
+
getBalance(mint: string): number;
|
|
36
|
+
hasVoted(mint: string): boolean;
|
|
37
|
+
hasRallied(mint: string): boolean;
|
|
38
|
+
markVoted(mint: string): void;
|
|
39
|
+
markRallied(mint: string): void;
|
|
40
|
+
serialize(): SerializedGameState;
|
|
41
|
+
hydrate(saved: SerializedGameState): void;
|
|
42
|
+
}
|