pyre-world-kit 3.0.0 → 3.0.1
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/index.d.ts +11 -3
- package/dist/index.js +17 -12
- package/package.json +1 -1
- package/readme.md +80 -50
- package/src/index.ts +24 -18
package/dist/index.d.ts
CHANGED
|
@@ -24,11 +24,19 @@ export declare class PyreKit {
|
|
|
24
24
|
/** Configure auto-checkpoint behavior */
|
|
25
25
|
setCheckpointConfig(config: CheckpointConfig): void;
|
|
26
26
|
/**
|
|
27
|
-
* Execute an action with
|
|
27
|
+
* Execute an action with deferred state tracking.
|
|
28
28
|
* On first call, initializes state from chain instead of executing.
|
|
29
|
-
*
|
|
29
|
+
*
|
|
30
|
+
* Returns { result, confirm }. Call confirm() after the transaction
|
|
31
|
+
* is signed and confirmed on-chain. This records the action in state
|
|
32
|
+
* (tick, sentiment, holdings, auto-checkpoint).
|
|
33
|
+
*
|
|
34
|
+
* For read-only methods (getFactions, getComms, etc.), confirm is a no-op.
|
|
30
35
|
*/
|
|
31
|
-
exec<T extends 'actions' | 'intel'>(provider: T, method: T extends 'actions' ? keyof Action : keyof Intel, ...args: any[]): Promise<
|
|
36
|
+
exec<T extends 'actions' | 'intel'>(provider: T, method: T extends 'actions' ? keyof Action : keyof Intel, ...args: any[]): Promise<{
|
|
37
|
+
result: any;
|
|
38
|
+
confirm: () => Promise<void>;
|
|
39
|
+
}>;
|
|
32
40
|
/** Map action method names to tracked action types */
|
|
33
41
|
private methodToAction;
|
|
34
42
|
}
|
package/dist/index.js
CHANGED
|
@@ -33,34 +33,39 @@ class PyreKit {
|
|
|
33
33
|
this.state.setCheckpointConfig(config);
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
-
* Execute an action with
|
|
36
|
+
* Execute an action with deferred state tracking.
|
|
37
37
|
* On first call, initializes state from chain instead of executing.
|
|
38
|
-
*
|
|
38
|
+
*
|
|
39
|
+
* Returns { result, confirm }. Call confirm() after the transaction
|
|
40
|
+
* is signed and confirmed on-chain. This records the action in state
|
|
41
|
+
* (tick, sentiment, holdings, auto-checkpoint).
|
|
42
|
+
*
|
|
43
|
+
* For read-only methods (getFactions, getComms, etc.), confirm is a no-op.
|
|
39
44
|
*/
|
|
40
45
|
async exec(provider, method, ...args) {
|
|
41
46
|
// First exec: initialize state
|
|
42
47
|
if (!this.state.initialized) {
|
|
43
48
|
await this.state.init();
|
|
44
|
-
return null;
|
|
49
|
+
return { result: null, confirm: async () => { } };
|
|
45
50
|
}
|
|
46
51
|
const target = provider === 'actions' ? this.actions : this.intel;
|
|
47
52
|
const fn = target[method];
|
|
48
53
|
if (typeof fn !== 'function')
|
|
49
54
|
throw new Error(`Unknown method: ${provider}.${String(method)}`);
|
|
50
55
|
const result = await fn.call(target, ...args);
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
// Build confirm callback for state-mutating actions
|
|
57
|
+
const trackedAction = provider === 'actions' ? this.methodToAction(method) : null;
|
|
58
|
+
const confirm = trackedAction
|
|
59
|
+
? async () => {
|
|
55
60
|
const mint = args[0]?.mint;
|
|
56
61
|
const message = args[0]?.message;
|
|
57
62
|
const description = message
|
|
58
|
-
? `${
|
|
59
|
-
: `${
|
|
60
|
-
await this.state.record(
|
|
63
|
+
? `${trackedAction} ${mint?.slice(0, 8) ?? '?'} — "${message}"`
|
|
64
|
+
: `${trackedAction} ${mint?.slice(0, 8) ?? '?'}`;
|
|
65
|
+
await this.state.record(trackedAction, mint, description);
|
|
61
66
|
}
|
|
62
|
-
|
|
63
|
-
return result;
|
|
67
|
+
: async () => { }; // no-op for reads
|
|
68
|
+
return { result, confirm };
|
|
64
69
|
}
|
|
65
70
|
/** Map action method names to tracked action types */
|
|
66
71
|
methodToAction(method) {
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -42,67 +42,98 @@ const connection = new Connection('https://api.mainnet-beta.solana.com')
|
|
|
42
42
|
const agent = createEphemeralAgent()
|
|
43
43
|
const kit = new PyreKit(connection, agent.publicKey)
|
|
44
44
|
|
|
45
|
-
//
|
|
46
|
-
|
|
45
|
+
// exec() is the primary interface — it builds the transaction,
|
|
46
|
+
// and returns a confirm callback that records state after signing.
|
|
47
|
+
// On first call, it auto-initializes state from chain.
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
const { result, confirm } = await kit.exec('actions', 'join', {
|
|
50
|
+
mint, agent: agent.publicKey, amount_sol: 0.1 * LAMPORTS_PER_SOL,
|
|
51
|
+
strategy: 'fortify', message: 'Pledging allegiance.',
|
|
52
|
+
stronghold: agent.publicKey,
|
|
53
|
+
})
|
|
54
|
+
const signed = agent.sign(result.transaction)
|
|
55
|
+
await connection.sendRawTransaction(signed.serialize())
|
|
56
|
+
await confirm() // records tick, sentiment, holdings
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## `exec()` — The Game Pipeline
|
|
60
|
+
|
|
61
|
+
`exec()` is a single method that runs the entire game pipeline: state initialization, action execution, and state tracking. It is the primary way agents interact with the kit.
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
const { result, confirm } = await kit.exec(provider, method, ...args)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**How it works:**
|
|
68
|
+
|
|
69
|
+
1. **First call auto-initializes** — resolves vault link, loads holdings, loads action counts and personality from the on-chain registry checkpoint. No manual `init()` needed.
|
|
70
|
+
2. **Builds the transaction** — delegates to the appropriate provider method (e.g. `kit.actions.join(params)`) and returns the unsigned transaction.
|
|
71
|
+
3. **Returns a `confirm` callback** — the agent signs and sends the transaction. If the tx succeeds, call `confirm()` to record the action in state. If the tx fails, don't call it — state stays clean.
|
|
72
|
+
|
|
73
|
+
**What `confirm()` does:**
|
|
74
|
+
- Increments the monotonic tick counter
|
|
75
|
+
- Updates the action count for the action type
|
|
76
|
+
- Adjusts sentiment for the target faction (join +1, defect -2, rally +3, etc.)
|
|
77
|
+
- Refreshes token holdings from chain (wallet + vault)
|
|
78
|
+
- Appends to action history (for LLM memory)
|
|
79
|
+
- Triggers auto-checkpoint if the configured tick interval is reached
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
// Type-safe provider dispatch
|
|
83
|
+
const { result, confirm } = await kit.exec('actions', 'join', params) // ActionProvider.join
|
|
84
|
+
const { result, confirm } = await kit.exec('actions', 'defect', params) // ActionProvider.defect
|
|
85
|
+
const { result, confirm } = await kit.exec('actions', 'fud', params) // ActionProvider.fud
|
|
86
|
+
const { result, confirm } = await kit.exec('intel', 'getFactionPower', mint) // IntelProvider (no-op confirm)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Read-only methods** (getFactions, getComms, intel queries) return a no-op `confirm` — call it or don't, nothing happens.
|
|
90
|
+
|
|
91
|
+
**Example: full action lifecycle**
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const kit = new PyreKit(connection, agent.publicKey)
|
|
95
|
+
|
|
96
|
+
// First exec auto-initializes state from chain
|
|
97
|
+
const { result: launchTx, confirm: confirmLaunch } = await kit.exec('actions', 'launch', {
|
|
50
98
|
founder: agent.publicKey,
|
|
51
99
|
name: 'Iron Vanguard',
|
|
52
100
|
symbol: 'IRON',
|
|
53
|
-
metadata_uri: 'https://
|
|
101
|
+
metadata_uri: 'https://pyre.gg/factions/iron.json',
|
|
54
102
|
community_faction: true,
|
|
55
103
|
})
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
// Join a faction (auto-routes bonding curve or DEX based on `ascended`)
|
|
64
|
-
const join = await kit.actions.join({
|
|
65
|
-
mint,
|
|
66
|
-
agent: agent.publicKey,
|
|
67
|
-
amount_sol: 0.1 * LAMPORTS_PER_SOL,
|
|
68
|
-
strategy: 'fortify',
|
|
69
|
-
message: 'Pledging allegiance.',
|
|
70
|
-
stronghold: agent.publicKey,
|
|
71
|
-
})
|
|
72
|
-
agent.sign(join.transaction)
|
|
73
|
-
// ... send + confirm ...
|
|
74
|
-
await kit.state.record('join', mint, 'joined IRON — "Pledging allegiance."')
|
|
75
|
-
|
|
76
|
-
// Defect (sell + message, auto-routes bonding curve or DEX)
|
|
77
|
-
await kit.actions.defect({
|
|
78
|
-
mint,
|
|
79
|
-
agent: agent.publicKey,
|
|
80
|
-
amount_tokens: 1000,
|
|
81
|
-
message: 'Found a stronger faction.',
|
|
104
|
+
// launchTx is null on first call (state init happened instead)
|
|
105
|
+
// On second call, it returns the transaction:
|
|
106
|
+
|
|
107
|
+
const { result: joinTx, confirm: confirmJoin } = await kit.exec('actions', 'join', {
|
|
108
|
+
mint, agent: agent.publicKey, amount_sol: 0.5 * LAMPORTS_PER_SOL,
|
|
109
|
+
strategy: 'fortify', message: 'All in.',
|
|
82
110
|
stronghold: agent.publicKey,
|
|
83
|
-
ascended: false, // set true for DEX-traded factions
|
|
84
111
|
})
|
|
112
|
+
agent.sign(joinTx.transaction)
|
|
113
|
+
await connection.sendRawTransaction(joinTx.transaction.serialize())
|
|
114
|
+
await confirmJoin() // tick: 1, sentiment: +1, holdings refreshed
|
|
85
115
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
agent: agent.publicKey,
|
|
90
|
-
message: 'This faction is done.',
|
|
116
|
+
const { result: defectTx, confirm: confirmDefect } = await kit.exec('actions', 'defect', {
|
|
117
|
+
mint, agent: agent.publicKey, amount_tokens: 500000,
|
|
118
|
+
message: 'Taking profits.',
|
|
91
119
|
stronghold: agent.publicKey,
|
|
92
120
|
})
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
console.log(kit.state.
|
|
121
|
+
agent.sign(defectTx.transaction)
|
|
122
|
+
await connection.sendRawTransaction(defectTx.transaction.serialize())
|
|
123
|
+
await confirmDefect() // tick: 2, sentiment: -2, holdings refreshed
|
|
124
|
+
|
|
125
|
+
// State is always up to date
|
|
126
|
+
console.log(kit.state.tick) // 2
|
|
127
|
+
console.log(kit.state.getSentiment(mint)) // -1 (join +1, defect -2)
|
|
128
|
+
console.log(kit.state.getBalance(mint)) // updated from chain
|
|
129
|
+
console.log(kit.state.history) // ['join ...', 'defect ...']
|
|
99
130
|
```
|
|
100
131
|
|
|
101
132
|
## Architecture
|
|
102
133
|
|
|
103
134
|
```
|
|
104
135
|
src/
|
|
105
|
-
index.ts — PyreKit top-level class + public exports
|
|
136
|
+
index.ts — PyreKit top-level class + exec() + public exports
|
|
106
137
|
types.ts — game-semantic type definitions
|
|
107
138
|
types/
|
|
108
139
|
action.types.ts — Action provider interface
|
|
@@ -129,8 +160,9 @@ Top-level class that wires all providers as singletons:
|
|
|
129
160
|
|
|
130
161
|
```typescript
|
|
131
162
|
const kit = new PyreKit(connection, agentPublicKey)
|
|
132
|
-
kit.
|
|
133
|
-
kit.
|
|
163
|
+
kit.exec(provider, method, ...args) // primary interface — runs full pipeline
|
|
164
|
+
kit.actions // ActionProvider — direct access (bypasses state tracking)
|
|
165
|
+
kit.intel // IntelProvider — direct access
|
|
134
166
|
kit.state // StateProvider — objective game state
|
|
135
167
|
kit.registry // RegistryProvider — on-chain identity
|
|
136
168
|
```
|
|
@@ -164,11 +196,9 @@ kit.actions.getDefectQuote(mint, n) // sell price quote
|
|
|
164
196
|
|
|
165
197
|
### StateProvider
|
|
166
198
|
|
|
167
|
-
Objective game state tracking. Initialized from chain (vault link + registry checkpoint). Updated via `
|
|
199
|
+
Objective game state tracking. Initialized from chain (vault link + registry checkpoint). Updated automatically via `exec()` confirm callbacks.
|
|
168
200
|
|
|
169
201
|
```typescript
|
|
170
|
-
await kit.state.init() // resolve vault, load holdings + checkpoint
|
|
171
|
-
await kit.state.record('join', mint, desc) // increment tick, update sentiment + holdings
|
|
172
202
|
kit.state.tick // monotonic action counter
|
|
173
203
|
kit.state.getSentiment(mint) // -10 to +10
|
|
174
204
|
kit.state.sentimentMap // all sentiment entries
|
|
@@ -180,7 +210,7 @@ kit.state.serialize() // persist to JSON
|
|
|
180
210
|
kit.state.hydrate(saved) // restore from JSON (skip chain reconstruction)
|
|
181
211
|
```
|
|
182
212
|
|
|
183
|
-
**Sentiment scoring** (auto-applied on
|
|
213
|
+
**Sentiment scoring** (auto-applied on confirm):
|
|
184
214
|
- join: +1, reinforce: +1.5, rally: +3, launch: +3
|
|
185
215
|
- defect: -2, fud: -1.5, infiltrate: -5
|
|
186
216
|
- message: +0.5, war_loan: +1
|
package/src/index.ts
CHANGED
|
@@ -42,19 +42,24 @@ export class PyreKit {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
* Execute an action with
|
|
45
|
+
* Execute an action with deferred state tracking.
|
|
46
46
|
* On first call, initializes state from chain instead of executing.
|
|
47
|
-
*
|
|
47
|
+
*
|
|
48
|
+
* Returns { result, confirm }. Call confirm() after the transaction
|
|
49
|
+
* is signed and confirmed on-chain. This records the action in state
|
|
50
|
+
* (tick, sentiment, holdings, auto-checkpoint).
|
|
51
|
+
*
|
|
52
|
+
* For read-only methods (getFactions, getComms, etc.), confirm is a no-op.
|
|
48
53
|
*/
|
|
49
54
|
async exec<T extends 'actions' | 'intel'>(
|
|
50
55
|
provider: T,
|
|
51
56
|
method: T extends 'actions' ? keyof Action : keyof Intel,
|
|
52
57
|
...args: any[]
|
|
53
|
-
): Promise<any> {
|
|
58
|
+
): Promise<{ result: any; confirm: () => Promise<void> }> {
|
|
54
59
|
// First exec: initialize state
|
|
55
60
|
if (!this.state.initialized) {
|
|
56
61
|
await this.state.init()
|
|
57
|
-
return null
|
|
62
|
+
return { result: null, confirm: async () => {} }
|
|
58
63
|
}
|
|
59
64
|
|
|
60
65
|
const target = provider === 'actions' ? this.actions : this.intel
|
|
@@ -63,20 +68,21 @@ export class PyreKit {
|
|
|
63
68
|
|
|
64
69
|
const result = await fn.call(target, ...args)
|
|
65
70
|
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
71
|
+
// Build confirm callback for state-mutating actions
|
|
72
|
+
const trackedAction = provider === 'actions' ? this.methodToAction(method as string) : null
|
|
73
|
+
|
|
74
|
+
const confirm = trackedAction
|
|
75
|
+
? async () => {
|
|
76
|
+
const mint = args[0]?.mint
|
|
77
|
+
const message = args[0]?.message
|
|
78
|
+
const description = message
|
|
79
|
+
? `${trackedAction} ${mint?.slice(0, 8) ?? '?'} — "${message}"`
|
|
80
|
+
: `${trackedAction} ${mint?.slice(0, 8) ?? '?'}`
|
|
81
|
+
await this.state.record(trackedAction, mint, description)
|
|
82
|
+
}
|
|
83
|
+
: async () => {} // no-op for reads
|
|
84
|
+
|
|
85
|
+
return { result, confirm }
|
|
80
86
|
}
|
|
81
87
|
|
|
82
88
|
/** Map action method names to tracked action types */
|