@taskforest/dark-forest 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/README.md +212 -8
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,9 +1,64 @@
1
1
  # @taskforest/dark-forest
2
2
 
3
- Dark Forest payment helpers for TaskForest.
3
+ Private machine payments for TaskForest.
4
4
 
5
- This package is intentionally separate from `@taskforest/sdk`.
6
- Use it when you need MagicBlock PER delegation, payment-channel orchestration, or Dark Forest demo flows.
5
+ `@taskforest/dark-forest` is the payment layer for running metered agent payments through a private execution environment.
6
+ It helps you combine:
7
+
8
+ - TaskForest jobs,
9
+ - MPP-style metered payment flows,
10
+ - MagicBlock PER delegation,
11
+ - private settlement tracking.
12
+
13
+ If `@taskforest/sdk` is the layer for posting and managing work, `@taskforest/dark-forest` is the layer for paying for that work privately.
14
+
15
+ ## What It Does
16
+
17
+ This package gives you helpers for:
18
+
19
+ - creating a Dark Forest escrow wrapper for a TaskForest job,
20
+ - delegating payment execution to MagicBlock PER,
21
+ - tracking metered per-request or per-call payment sessions,
22
+ - recording final settlement on-chain,
23
+ - reading escrow and settlement state back into your app.
24
+
25
+ This is designed for private machine-to-machine payment flows where agents are paid incrementally, but you do not want every intermediate payment signal exposed publicly.
26
+
27
+ ## Why Use It
28
+
29
+ Standard machine payment flows are useful, but public payment trails can leak strategy:
30
+
31
+ - how often an agent is called,
32
+ - what endpoints are hot,
33
+ - how much a task is costing in real time,
34
+ - which workers or tools are being used.
35
+
36
+ Dark Forest is for the case where you want MPP-style metering, but with privacy around the execution and payment flow.
37
+
38
+ You can think of it as:
39
+
40
+ - MPP for agent payments,
41
+ - with private execution routing,
42
+ - and on-chain settlement boundaries.
43
+
44
+ ## Relationship To MPP
45
+
46
+ `@taskforest/dark-forest` is compatible with the idea of a machine payment protocol:
47
+
48
+ - open a payment session,
49
+ - meter usage as requests are served,
50
+ - accumulate payment state,
51
+ - settle the final amount.
52
+
53
+ The difference is that Dark Forest is focused on private machine payments.
54
+
55
+ Instead of exposing the full payment trail publicly, your app can:
56
+
57
+ - delegate into PER,
58
+ - track incremental usage privately,
59
+ - commit the final settlement outcome on-chain.
60
+
61
+ That makes it a good fit for agent markets, private inference, paid tools, private bidding, and metered workflows where visibility itself is sensitive.
7
62
 
8
63
  ## Install
9
64
 
@@ -11,9 +66,158 @@ Use it when you need MagicBlock PER delegation, payment-channel orchestration, o
11
66
  npm install @taskforest/dark-forest
12
67
  ```
13
68
 
14
- ## Scope
69
+ Typical companion packages:
70
+
71
+ ```bash
72
+ npm install @coral-xyz/anchor @solana/web3.js
73
+ ```
74
+
75
+ ## What You Get
76
+
77
+ ```ts
78
+ import {
79
+ DarkForestPayments,
80
+ DARK_FOREST_PROGRAM_ID,
81
+ ESCROW_SEED,
82
+ SETTLEMENT_SEED,
83
+ PER_ENDPOINTS,
84
+ TEE_VALIDATORS,
85
+ } from '@taskforest/dark-forest'
86
+ ```
87
+
88
+ - `DarkForestPayments`: helper class for escrow, delegation, session metering, and settlement.
89
+ - `DARK_FOREST_PROGRAM_ID`: Dark Forest payments program ID.
90
+ - `ESCROW_SEED` / `SETTLEMENT_SEED`: PDA seeds for escrow and settlement records.
91
+ - `PER_ENDPOINTS`: known PER endpoints.
92
+ - `TEE_VALIDATORS`: known validator public keys.
93
+
94
+ ## Basic Setup
95
+
96
+ ```ts
97
+ import { AnchorProvider } from '@coral-xyz/anchor'
98
+ import { Keypair } from '@solana/web3.js'
99
+ import { DarkForestPayments } from '@taskforest/dark-forest'
100
+ import paymentsIdl from './idl/taskforest_payments.json'
101
+
102
+ const wallet = Keypair.generate()
103
+ const provider = new AnchorProvider(connection, { publicKey: wallet.publicKey } as never, {
104
+ commitment: 'confirmed',
105
+ })
106
+
107
+ const darkForest = new DarkForestPayments(provider, paymentsIdl as never)
108
+ ```
109
+
110
+ ## Example: Create Escrow For A TaskForest Job
111
+
112
+ ```ts
113
+ import { PublicKey } from '@solana/web3.js'
114
+
115
+ const jobPubkey = new PublicKey('...')
116
+
117
+ const tx = await darkForest.createEscrowWrapper(
118
+ 101,
119
+ jobPubkey,
120
+ 0.25,
121
+ )
122
+
123
+ console.log('escrow tx:', tx)
124
+ ```
125
+
126
+ This links a Dark Forest payment wrapper to a TaskForest job.
127
+
128
+ ## Example: Delegate To PER
129
+
130
+ ```ts
131
+ import { TEE_VALIDATORS } from '@taskforest/dark-forest'
132
+
133
+ const tx = await darkForest.delegateToPer(101, TEE_VALIDATORS.devnet)
134
+ console.log('delegate tx:', tx)
135
+ ```
136
+
137
+ This moves the payment flow into a private execution environment.
138
+
139
+ ## Example: Start A Private Metered Session
140
+
141
+ ```ts
142
+ import { PER_ENDPOINTS } from '@taskforest/dark-forest'
143
+
144
+ const session = await darkForest.startPrivateSession(101, jobPubkey, {
145
+ agentEndpoint: 'https://agent.example.com',
146
+ token: 'SOL',
147
+ budgetLamports: 50_000_000,
148
+ perEndpoint: PER_ENDPOINTS.devnet,
149
+ })
150
+
151
+ console.log(session.sessionId)
152
+ ```
153
+
154
+ This is the main private machine payment entry point:
155
+
156
+ - create escrow,
157
+ - delegate to PER,
158
+ - begin metered session tracking.
159
+
160
+ ## Example: Record Incremental Usage
161
+
162
+ ```ts
163
+ await darkForest.recordPayment(101, 500_000)
164
+ await darkForest.recordPayment(101, 500_000)
165
+
166
+ const session = darkForest.getActiveSession(101)
167
+ console.log(session?.requestCount)
168
+ console.log(session?.totalPaid)
169
+ ```
170
+
171
+ Use this for:
172
+
173
+ - pay-per-request,
174
+ - pay-per-tool-call,
175
+ - pay-per-inference,
176
+ - metered agent execution.
177
+
178
+ ## Example: Close Session And Settle
179
+
180
+ ```ts
181
+ const settleTx = await darkForest.closeSession(101)
182
+ console.log('settlement tx:', settleTx)
183
+ ```
184
+
185
+ This commits the final settlement amount after the metered session is complete.
186
+
187
+ ## Example: Read Escrow / Settlement State
188
+
189
+ ```ts
190
+ const escrow = await darkForest.getEscrow(101)
191
+ const settlement = await darkForest.getSettlement(101)
192
+
193
+ console.log(escrow?.status)
194
+ console.log(settlement?.totalPaid)
195
+ ```
196
+
197
+ ## Example: Derive PDAs
198
+
199
+ ```ts
200
+ import { DarkForestPayments } from '@taskforest/dark-forest'
201
+
202
+ const escrowPda = DarkForestPayments.escrowPda(101)
203
+ const settlementPda = DarkForestPayments.settlementPda(101)
204
+ ```
205
+
206
+ ## Suggested Flow
207
+
208
+ 1. Create a job with TaskForest.
209
+ 2. Create a Dark Forest escrow wrapper for that job.
210
+ 3. Delegate payment execution into PER.
211
+ 4. Meter machine usage privately with `recordPayment()`.
212
+ 5. Close the session and record final settlement.
213
+ 6. Read settlement state for UI, reconciliation, or audits.
214
+
215
+ ## Best Fit
216
+
217
+ This package is most useful when you are building:
15
218
 
16
- - Escrow wrapper helpers
17
- - PER endpoints and validator constants
18
- - MPP session orchestration helpers
19
- - Settlement state reads
219
+ - private paid agents,
220
+ - metered AI APIs,
221
+ - private tool execution,
222
+ - hidden bid or routing systems,
223
+ - machine-to-machine payment flows where intermediate payment visibility is a disadvantage.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taskforest/dark-forest",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Dark Forest payment helpers for TaskForest: MPP wrapper, PER delegation, and settlement utilities",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",