pyre-world-kit 3.2.0 → 3.2.2

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.
@@ -24,6 +24,8 @@ export declare class StateProvider implements State {
24
24
  record(action: TrackedAction, mint?: string, description?: string): Promise<void>;
25
25
  private updateSentiment;
26
26
  onCheckpointDue: (() => void) | null;
27
+ /** Sync totalSolSpent/Received from on-chain vault data (fresh read) */
28
+ private syncPnl;
27
29
  getHoldings(): Promise<Map<string, number>>;
28
30
  getBalance(mint: string): Promise<number>;
29
31
  getSentiment(mint: string): number;
@@ -196,6 +196,10 @@ class StateProvider {
196
196
  this._state.recentHistory = this._state.recentHistory.slice(-20);
197
197
  }
198
198
  }
199
+ // Sync P&L from vault every 10 ticks
200
+ if (this._state.tick % 10 === 0) {
201
+ this.syncPnl();
202
+ }
199
203
  if (this.checkpointConfig && this.ticksSinceCheckpoint >= this.checkpointConfig.interval) {
200
204
  this.ticksSinceCheckpoint = 0;
201
205
  this.onCheckpointDue?.();
@@ -222,6 +226,20 @@ class StateProvider {
222
226
  }
223
227
  }
224
228
  onCheckpointDue = null;
229
+ /** Sync totalSolSpent/Received from on-chain vault data (fresh read) */
230
+ async syncPnl() {
231
+ if (!this._state)
232
+ return;
233
+ try {
234
+ const { getVaultForWallet } = await torchsdkImport;
235
+ const vault = await getVaultForWallet(this.connection, this.publicKey);
236
+ if (vault) {
237
+ this._state.totalSolSpent = Math.round(vault.total_spent * 1e9);
238
+ this._state.totalSolReceived = Math.round(vault.total_received * 1e9);
239
+ }
240
+ }
241
+ catch { }
242
+ }
225
243
  async getHoldings() {
226
244
  const { TOKEN_2022_PROGRAM_ID } = await splTokenImport;
227
245
  const walletPk = new web3_js_1.PublicKey(this.publicKey);
@@ -243,7 +261,7 @@ class StateProvider {
243
261
  const holdings = new Map();
244
262
  for (const a of [...walletValues, ...vaultValues]) {
245
263
  const mint = a.account.data.parsed.info.mint;
246
- const balance = Number(a.account.data.parsed.info.tokenAmount.uiAmount ?? 0);
264
+ const balance = Number(a.account.data.parsed.info.tokenAmount.amount ?? 0);
247
265
  if (balance > 0 && (0, vanity_1.isPyreMint)(mint) && !(0, util_1.isBlacklistedMint)(mint)) {
248
266
  holdings.set(mint, (holdings.get(mint) ?? 0) + balance);
249
267
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pyre-world-kit",
3
- "version": "3.2.0",
3
+ "version": "3.2.2",
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",
@@ -190,6 +190,11 @@ export class StateProvider implements State {
190
190
  }
191
191
  }
192
192
 
193
+ // Sync P&L from vault every 10 ticks
194
+ if (this._state.tick % 10 === 0) {
195
+ this.syncPnl()
196
+ }
197
+
193
198
  if (this.checkpointConfig && this.ticksSinceCheckpoint >= this.checkpointConfig.interval) {
194
199
  this.ticksSinceCheckpoint = 0
195
200
  this.onCheckpointDue?.()
@@ -219,6 +224,19 @@ export class StateProvider implements State {
219
224
 
220
225
  onCheckpointDue: (() => void) | null = null
221
226
 
227
+ /** Sync totalSolSpent/Received from on-chain vault data (fresh read) */
228
+ private async syncPnl(): Promise<void> {
229
+ if (!this._state) return
230
+ try {
231
+ const { getVaultForWallet } = await torchsdkImport
232
+ const vault = await getVaultForWallet(this.connection, this.publicKey)
233
+ if (vault) {
234
+ this._state.totalSolSpent = Math.round(vault.total_spent * 1e9)
235
+ this._state.totalSolReceived = Math.round(vault.total_received * 1e9)
236
+ }
237
+ } catch {}
238
+ }
239
+
222
240
  async getHoldings(): Promise<Map<string, number>> {
223
241
  const { TOKEN_2022_PROGRAM_ID } = await splTokenImport
224
242
  const walletPk = new PublicKey(this.publicKey)
@@ -244,7 +262,7 @@ export class StateProvider implements State {
244
262
  const holdings = new Map<string, number>()
245
263
  for (const a of [...walletValues, ...vaultValues]) {
246
264
  const mint = a.account.data.parsed.info.mint as string
247
- const balance = Number(a.account.data.parsed.info.tokenAmount.uiAmount ?? 0)
265
+ const balance = Number(a.account.data.parsed.info.tokenAmount.amount ?? 0)
248
266
  if (balance > 0 && isPyreMint(mint) && !isBlacklistedMint(mint)) {
249
267
  holdings.set(mint, (holdings.get(mint) ?? 0) + balance)
250
268
  }