@sage-protocol/sdk 0.0.7 → 0.1.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.
package/README.md CHANGED
@@ -42,6 +42,15 @@ const info = await sdk.governance.getGovernorInfo({ provider, governor: subdaos[
42
42
  const sdk = require('@sage-protocol/sdk');
43
43
  ```
44
44
 
45
+ What’s New in 0.0.8
46
+ --------------------
47
+ - 0.0.8 Highlights
48
+ - Governance helpers (additive): resolveVotesToken, buildDelegateSelfPreferred, delegateSelfAndVerify, ensureProposeGates, readinessToPropose, listActiveProposals
49
+ - Library helpers (additive): buildAuthorizeTimelockTx, executionReadiness
50
+ - Subgraph normalization: listProposalsFiltered returns state (string) and stateNum (0–7)
51
+ - Backward compatible: no removed/renamed exports; all additions are optional
52
+ - IPFS worker helpers: discovery signal APIs (`recordMcpUsage`, `recordLaunchEvent`, `recordDiscoveryEvent`) and governance queue actions (`submitGovernanceReport`, `listGovernanceReports`, `reviewGovernanceReport`, `batchGovernanceReports`)
53
+
45
54
  Module Overview
46
55
  ---------------
47
56
 
@@ -53,6 +62,7 @@ Module Overview
53
62
  | `factory` | Config reads, template enumeration, SubDAO create/fork builders | Launch tooling, analytics |
54
63
  | `library` | Manifest listings & scoped ownership checks | Prompt library browsers |
55
64
  | `prompt` | Prompt metadata, fork counts, usage counters | UI prompt catalogues, agent prompt selection |
65
+ | `ipfs` | Upload helpers + discovery/governance worker APIs | CLI sandbox, dashboards, worker automation |
56
66
  | `subdao` | Discovery, staking helpers, per-user stats | SubDAO directories, onboarding |
57
67
  | `token` | SXXX balances/allowances, burner discovery, tx builders | Wallet gating, burner dashboards |
58
68
  | `treasury` | Reserve/POL snapshot, pending withdrawals, liquidity plans | Treasury analytics, Safe operators |
@@ -212,12 +222,111 @@ const tx = await sdk.governance.buildDelegateSelfTx({ provider, governor, accoun
212
222
  // send via userOp (CDP) or EOA
213
223
  ```
214
224
 
225
+ Votes token resolution and gates
226
+ ```js
227
+ // Resolve the IVotes token used for proposals
228
+ const votesToken = await sdk.governance.resolveVotesToken({ provider, governor });
229
+
230
+ // Build preferred self-delegate using resolved token
231
+ const del = await sdk.governance.buildDelegateSelfPreferred({ provider, governor, account: user });
232
+
233
+ // Delegate and verify votes (no throw)
234
+ const res = await sdk.governance.delegateSelfAndVerify({ provider, governor, account: user, signer, minVotes: 1n });
235
+ // → { txHash, ok, votes, payload }
236
+
237
+ // Readiness to propose (preflight)
238
+ const gates = await sdk.governance.ensureProposeGates({ provider, governor, proposer: user });
239
+ // Optionally include execution check (registry update as timelock)
240
+ const ready = await sdk.governance.readinessToPropose({
241
+ provider,
242
+ governor,
243
+ proposer: user,
244
+ execution: { registry, timelock, subdao, libraryId: 'main', manifestCID, promptCount: 12 },
245
+ });
246
+ ```
247
+
248
+ Subgraph normalization
249
+ ```js
250
+ // listProposalsFiltered now returns both state (string) and stateNum (0–7)
251
+ const items = await sdk.subgraph.listProposalsFiltered({ url: SUBGRAPH_URL, governor });
252
+ // item.state → 'PENDING' | 'ACTIVE' | ... ; item.stateNum → 0..7 or null when unknown
253
+ ```
254
+
255
+ Subgraph State Normalization
256
+ ----------------------------
257
+ - State Mapping
258
+ - PENDING → 0
259
+ - ACTIVE → 1
260
+ - CANCELED/CANCELLED → 2
261
+ - DEFEATED → 3
262
+ - SUCCEEDED → 4
263
+ - QUEUED → 5
264
+ - EXPIRED → 6
265
+ - EXECUTED → 7
266
+ - Example
267
+ ```js
268
+ const items = await sdk.subgraph.listProposalsFiltered({ url: SUBGRAPH_URL, governor });
269
+ console.log(items[0].state); // 'PENDING'
270
+ console.log(items[0].stateNum); // 0
271
+ ```
272
+
273
+ New Helper Examples
274
+ -------------------
275
+
276
+ - Votes token + self‑delegate
277
+ ```js
278
+ const votesToken = await sdk.governance.resolveVotesToken({ provider, governor });
279
+ const tx = await sdk.governance.buildDelegateSelfPreferred({ provider, governor, account: user });
280
+ const res = await sdk.governance.delegateSelfAndVerify({ provider, governor, account: user, signer, minVotes: 1n });
281
+ console.log(res.ok, res.votes, res.txHash);
282
+ ```
283
+
284
+ - Propose gates and execution readiness (one‑shot)
285
+ ```js
286
+ const gates = await sdk.governance.ensureProposeGates({ provider, governor, proposer: user });
287
+ const ready = await sdk.governance.readinessToPropose({
288
+ provider, governor, proposer: user,
289
+ execution: { registry, timelock, subdao, libraryId: 'main', manifestCID, promptCount: 12 }
290
+ });
291
+ console.log({ threshold: gates.threshold, votesOk: gates.votesOk, execReady: ready.executionReady });
292
+ ```
293
+
294
+ - List active proposals (subgraph)
295
+ ```js
296
+ const active = await sdk.governance.listActiveProposals({ url: SUBGRAPH_URL, governor });
297
+ // active[i].state (string), active[i].stateNum (0–7)
298
+ ```
299
+
300
+ - Library authorize + readiness
301
+ ```js
302
+ const auth = sdk.library.buildAuthorizeTimelockTx({ registry, timelock, subdao });
303
+ const exec = await sdk.library.executionReadiness({ provider, registry, timelock, subdao, libraryId: 'main', manifestCID, promptCount });
304
+ console.log(exec.ok, exec.error);
305
+ ```
306
+
215
307
  Proposal timeline (subgraph)
216
308
  ```js
217
309
  const t = await sdk.subgraph.getProposalTimeline({ url: SUBGRAPH_URL, id: idHexOrDecimal });
218
310
  // { id, createdAt, queuedAt, executedAt, canceledAt, eta, state }
219
311
  ```
220
312
 
313
+ Compatibility
314
+ -------------
315
+ - 0.0.8 Compatibility
316
+ - All changes are additive; no removed or renamed exports. Existing callers can continue to rely on string state. stateNum is optional.
317
+
318
+ Troubleshooting
319
+ ---------------
320
+ - JSON + BigInt
321
+ - Use a replacer when printing SDK results:
322
+ ```js
323
+ JSON.stringify(obj, (_, v) => (typeof v === 'bigint' ? v.toString() : v));
324
+ ```
325
+ - Governor filter casing
326
+ - The SDK normalizes governor for Bytes filters; if you issue manual GraphQL, use lowercase governor addresses to avoid case sensitivity pitfalls.
327
+ - Votes snapshot timing
328
+ - getVotesLatestMinusOne reads at latest‑1 to avoid same‑block edge cases on ERC20Votes.
329
+
221
330
  Prompt pagination helpers
222
331
  ```js
223
332
  const totalByTag = await sdk.prompt.getByTagCount({ provider, registry, tagHash });