@poa-box/core 0.1.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.
Files changed (220) hide show
  1. package/README.md +201 -0
  2. package/dist/abis/DirectDemocracyVotingNew.d.ts +749 -0
  3. package/dist/abis/DirectDemocracyVotingNew.js +961 -0
  4. package/dist/abis/ERC20.d.ts +90 -0
  5. package/dist/abis/ERC20.js +125 -0
  6. package/dist/abis/EducationHubNew.d.ts +590 -0
  7. package/dist/abis/EducationHubNew.js +762 -0
  8. package/dist/abis/EligibilityModuleNew.d.ts +1615 -0
  9. package/dist/abis/EligibilityModuleNew.js +2082 -0
  10. package/dist/abis/Executor.d.ts +619 -0
  11. package/dist/abis/Executor.js +796 -0
  12. package/dist/abis/HybridVotingNew.d.ts +898 -0
  13. package/dist/abis/HybridVotingNew.js +1149 -0
  14. package/dist/abis/ImplementationRegistry.d.ts +270 -0
  15. package/dist/abis/ImplementationRegistry.js +355 -0
  16. package/dist/abis/OrgDeployerNew.d.ts +1275 -0
  17. package/dist/abis/OrgDeployerNew.js +1630 -0
  18. package/dist/abis/OrgRegistry.d.ts +670 -0
  19. package/dist/abis/OrgRegistry.js +868 -0
  20. package/dist/abis/ParticipationToken.d.ts +1086 -0
  21. package/dist/abis/ParticipationToken.js +1415 -0
  22. package/dist/abis/PasskeyAccount.d.ts +788 -0
  23. package/dist/abis/PasskeyAccount.js +1019 -0
  24. package/dist/abis/PasskeyAccountFactory.d.ts +344 -0
  25. package/dist/abis/PasskeyAccountFactory.js +449 -0
  26. package/dist/abis/PaymasterHub.d.ts +1603 -0
  27. package/dist/abis/PaymasterHub.js +2048 -0
  28. package/dist/abis/PaymentManager.d.ts +520 -0
  29. package/dist/abis/PaymentManager.js +671 -0
  30. package/dist/abis/PoaManager.d.ts +344 -0
  31. package/dist/abis/PoaManager.js +449 -0
  32. package/dist/abis/QuickJoinNew.d.ts +855 -0
  33. package/dist/abis/QuickJoinNew.js +1098 -0
  34. package/dist/abis/TaskManagerNew.d.ts +1236 -0
  35. package/dist/abis/TaskManagerNew.js +1573 -0
  36. package/dist/abis/ToggleModule.d.ts +193 -0
  37. package/dist/abis/ToggleModule.js +255 -0
  38. package/dist/abis/UniversalAccountRegistry.d.ts +577 -0
  39. package/dist/abis/UniversalAccountRegistry.js +750 -0
  40. package/dist/abis/ZkEmailInvites.d.ts +823 -0
  41. package/dist/abis/ZkEmailInvites.js +1060 -0
  42. package/dist/abis/external/AaveGovernanceV2.d.ts +128 -0
  43. package/dist/abis/external/AaveGovernanceV2.js +177 -0
  44. package/dist/abis/external/AaveGovernanceV3.d.ts +160 -0
  45. package/dist/abis/external/AaveGovernanceV3.js +220 -0
  46. package/dist/abis/external/AragonVoting.d.ts +107 -0
  47. package/dist/abis/external/AragonVoting.js +150 -0
  48. package/dist/abis/external/CurveGaugeController.d.ts +95 -0
  49. package/dist/abis/external/CurveGaugeController.js +130 -0
  50. package/dist/abis/external/CurveVotingEscrow.d.ts +86 -0
  51. package/dist/abis/external/CurveVotingEscrow.js +116 -0
  52. package/dist/abis/external/GovernorAlpha.d.ts +172 -0
  53. package/dist/abis/external/GovernorAlpha.js +228 -0
  54. package/dist/abis/external/MakerDAOChief.d.ts +92 -0
  55. package/dist/abis/external/MakerDAOChief.js +129 -0
  56. package/dist/abis/external/OZGovernor.d.ts +227 -0
  57. package/dist/abis/external/OZGovernor.js +317 -0
  58. package/dist/abis/external/SolidlyVotingEscrow.d.ts +196 -0
  59. package/dist/abis/external/SolidlyVotingEscrow.js +260 -0
  60. package/dist/abis/index.d.ts +62 -0
  61. package/dist/abis/index.js +98 -0
  62. package/dist/chains.d.ts +150 -0
  63. package/dist/chains.js +320 -0
  64. package/dist/context.d.ts +48 -0
  65. package/dist/context.js +38 -0
  66. package/dist/contracts.d.ts +24 -0
  67. package/dist/contracts.js +41 -0
  68. package/dist/encoding.d.ts +58 -0
  69. package/dist/encoding.js +243 -0
  70. package/dist/env.d.ts +10 -0
  71. package/dist/env.js +4 -0
  72. package/dist/error-catalog.d.ts +41 -0
  73. package/dist/error-catalog.js +941 -0
  74. package/dist/errors.d.ts +27 -0
  75. package/dist/errors.js +60 -0
  76. package/dist/execute/ethers.d.ts +93 -0
  77. package/dist/execute/ethers.js +323 -0
  78. package/dist/execute/index.d.ts +7 -0
  79. package/dist/execute/index.js +23 -0
  80. package/dist/execute/sponsored.d.ts +68 -0
  81. package/dist/execute/sponsored.js +277 -0
  82. package/dist/exit-codes.d.ts +18 -0
  83. package/dist/exit-codes.js +21 -0
  84. package/dist/format.d.ts +21 -0
  85. package/dist/format.js +89 -0
  86. package/dist/graph/client.d.ts +298 -0
  87. package/dist/graph/client.js +702 -0
  88. package/dist/graph/documents/activity.d.ts +9 -0
  89. package/dist/graph/documents/activity.js +164 -0
  90. package/dist/graph/documents/beacons.d.ts +172 -0
  91. package/dist/graph/documents/beacons.js +345 -0
  92. package/dist/graph/documents/index.d.ts +21 -0
  93. package/dist/graph/documents/index.js +57 -0
  94. package/dist/graph/documents/infrastructure.d.ts +30 -0
  95. package/dist/graph/documents/infrastructure.js +34 -0
  96. package/dist/graph/documents/org.d.ts +15 -0
  97. package/dist/graph/documents/org.js +249 -0
  98. package/dist/graph/documents/paymaster.d.ts +95 -0
  99. package/dist/graph/documents/paymaster.js +101 -0
  100. package/dist/graph/documents/role.d.ts +6 -0
  101. package/dist/graph/documents/role.js +41 -0
  102. package/dist/graph/documents/roles.d.ts +50 -0
  103. package/dist/graph/documents/roles.js +112 -0
  104. package/dist/graph/documents/task.d.ts +84 -0
  105. package/dist/graph/documents/task.js +236 -0
  106. package/dist/graph/documents/token.d.ts +13 -0
  107. package/dist/graph/documents/token.js +126 -0
  108. package/dist/graph/documents/treasury.d.ts +39 -0
  109. package/dist/graph/documents/treasury.js +136 -0
  110. package/dist/graph/documents/user.d.ts +120 -0
  111. package/dist/graph/documents/user.js +302 -0
  112. package/dist/graph/documents/voting-classes.d.ts +69 -0
  113. package/dist/graph/documents/voting-classes.js +149 -0
  114. package/dist/graph/documents/voting.d.ts +28 -0
  115. package/dist/graph/documents/voting.js +163 -0
  116. package/dist/graph/documents/vouch.d.ts +79 -0
  117. package/dist/graph/documents/vouch.js +171 -0
  118. package/dist/graph/documents/zkemail.d.ts +63 -0
  119. package/dist/graph/documents/zkemail.js +188 -0
  120. package/dist/graph/index.d.ts +2 -0
  121. package/dist/graph/index.js +41 -0
  122. package/dist/index.d.ts +49 -0
  123. package/dist/index.js +92 -0
  124. package/dist/ipfs.d.ts +39 -0
  125. package/dist/ipfs.js +214 -0
  126. package/dist/label-aliases.d.ts +31 -0
  127. package/dist/label-aliases.js +70 -0
  128. package/dist/metadata/education.d.ts +30 -0
  129. package/dist/metadata/education.js +31 -0
  130. package/dist/metadata/index.d.ts +12 -0
  131. package/dist/metadata/index.js +48 -0
  132. package/dist/metadata/org.d.ts +92 -0
  133. package/dist/metadata/org.js +93 -0
  134. package/dist/metadata/proposal.d.ts +44 -0
  135. package/dist/metadata/proposal.js +45 -0
  136. package/dist/metadata/role.d.ts +38 -0
  137. package/dist/metadata/role.js +35 -0
  138. package/dist/metadata/task.d.ts +108 -0
  139. package/dist/metadata/task.js +81 -0
  140. package/dist/metadata/token.d.ts +32 -0
  141. package/dist/metadata/token.js +36 -0
  142. package/dist/metadata/user.d.ts +63 -0
  143. package/dist/metadata/user.js +70 -0
  144. package/dist/multicall.d.ts +32 -0
  145. package/dist/multicall.js +96 -0
  146. package/dist/payout.d.ts +59 -0
  147. package/dist/payout.js +96 -0
  148. package/dist/perms.d.ts +47 -0
  149. package/dist/perms.js +120 -0
  150. package/dist/preflight.d.ts +72 -0
  151. package/dist/preflight.js +269 -0
  152. package/dist/reads/education.d.ts +79 -0
  153. package/dist/reads/education.js +122 -0
  154. package/dist/reads/eligibility.d.ts +377 -0
  155. package/dist/reads/eligibility.js +687 -0
  156. package/dist/reads/index.d.ts +16 -0
  157. package/dist/reads/index.js +55 -0
  158. package/dist/reads/org.d.ts +258 -0
  159. package/dist/reads/org.js +220 -0
  160. package/dist/reads/paymaster.d.ts +147 -0
  161. package/dist/reads/paymaster.js +235 -0
  162. package/dist/reads/project.d.ts +33 -0
  163. package/dist/reads/project.js +62 -0
  164. package/dist/reads/resolve.d.ts +34 -0
  165. package/dist/reads/resolve.js +64 -0
  166. package/dist/reads/task.d.ts +286 -0
  167. package/dist/reads/task.js +280 -0
  168. package/dist/reads/token.d.ts +94 -0
  169. package/dist/reads/token.js +75 -0
  170. package/dist/reads/treasury.d.ts +222 -0
  171. package/dist/reads/treasury.js +241 -0
  172. package/dist/reads/user.d.ts +229 -0
  173. package/dist/reads/user.js +155 -0
  174. package/dist/reads/vote.d.ts +296 -0
  175. package/dist/reads/vote.js +392 -0
  176. package/dist/reads/zkemail.d.ts +117 -0
  177. package/dist/reads/zkemail.js +217 -0
  178. package/dist/similarity.d.ts +36 -0
  179. package/dist/similarity.js +67 -0
  180. package/dist/sponsorship-config.d.ts +47 -0
  181. package/dist/sponsorship-config.js +41 -0
  182. package/dist/stats.d.ts +11 -0
  183. package/dist/stats.js +27 -0
  184. package/dist/task-lens.d.ts +113 -0
  185. package/dist/task-lens.js +210 -0
  186. package/dist/tx/education.d.ts +169 -0
  187. package/dist/tx/education.js +344 -0
  188. package/dist/tx/eligibility.d.ts +511 -0
  189. package/dist/tx/eligibility.js +818 -0
  190. package/dist/tx/governance.d.ts +85 -0
  191. package/dist/tx/governance.js +87 -0
  192. package/dist/tx/index.d.ts +17 -0
  193. package/dist/tx/index.js +56 -0
  194. package/dist/tx/intent.d.ts +67 -0
  195. package/dist/tx/intent.js +48 -0
  196. package/dist/tx/org.d.ts +321 -0
  197. package/dist/tx/org.js +544 -0
  198. package/dist/tx/paymaster.d.ts +140 -0
  199. package/dist/tx/paymaster.js +251 -0
  200. package/dist/tx/project.d.ts +146 -0
  201. package/dist/tx/project.js +217 -0
  202. package/dist/tx/task.d.ts +480 -0
  203. package/dist/tx/task.js +1149 -0
  204. package/dist/tx/token.d.ts +96 -0
  205. package/dist/tx/token.js +165 -0
  206. package/dist/tx/treasury.d.ts +474 -0
  207. package/dist/tx/treasury.js +911 -0
  208. package/dist/tx/user.d.ts +177 -0
  209. package/dist/tx/user.js +292 -0
  210. package/dist/tx/vote.d.ts +332 -0
  211. package/dist/tx/vote.js +762 -0
  212. package/dist/tx/zkemail.d.ts +90 -0
  213. package/dist/tx/zkemail.js +210 -0
  214. package/dist/validation.d.ts +8 -0
  215. package/dist/validation.js +39 -0
  216. package/dist/version.d.ts +142 -0
  217. package/dist/version.js +257 -0
  218. package/dist/zkemail.d.ts +161 -0
  219. package/dist/zkemail.js +299 -0
  220. package/package.json +130 -0
package/README.md ADDED
@@ -0,0 +1,201 @@
1
+ # @poa-box/core
2
+
3
+ The stable protocol layer for POP (Proof of Participation): **transaction
4
+ creation** and **data reads** for every consumer — the `pop` CLI, web
5
+ frontends, autonomous agents, and third-party integrations. Protocol changes
6
+ land here; consumers update one dependency instead of chasing contract or
7
+ subgraph churn.
8
+
9
+ - **Browser-and-Node pure.** No `fs`, no `process.env`, no terminal deps
10
+ anywhere in the package (enforced by `test/purity.test.ts`). Environment is
11
+ injected.
12
+ - **Wallet-agnostic writes.** Every on-chain operation is a `TxIntent` —
13
+ plain data you can execute with an ethers signer, wagmi/viem, an ERC-4337
14
+ passkey account, an EIP-7702 sponsored userop, a Safe batch, or raw JSON-RPC.
15
+ - **Canonical protocol knowledge.** ABIs (generated, drift-proof), metadata
16
+ JSON shapes (key order is a protocol contract), subgraph documents with
17
+ field-fallback tiers, payout conventions, error decoding — one copy, shared.
18
+
19
+ ```
20
+ ethers ^5.7 is a peer dependency (viem + permissionless only if you use the
21
+ sponsored/4337 execution path — they are optional peers).
22
+ ```
23
+
24
+ ## Quickstart — reads
25
+
26
+ ```ts
27
+ import { createPopContext } from '@poa-box/core';
28
+ import { resolveOrgModules } from '@poa-box/core/reads/resolve';
29
+ import { listTasks } from '@poa-box/core/reads/task';
30
+
31
+ const ctx = createPopContext({ chainId: 100 }); // Gnosis; zero config
32
+
33
+ const org = await resolveOrgModules(ctx.client, 'my-org'); // name or 0x… id
34
+ const tasks = await listTasks(ctx.client, org.orgId);
35
+ ```
36
+
37
+ Reads are **subgraph-first** through a tiered transport: the free Graph Studio
38
+ endpoint first, automatic failover to the paid gateway (`GRAPH_API_KEY` via
39
+ `env`) when the free quota is spent, and **field-fallback tiers** that keep
40
+ queries working across the different subgraph deployments on Gnosis and
41
+ Arbitrum. Raw GraphQL documents stay exported (`@poa-box/core/graph/documents`) if
42
+ you'd rather run them through Apollo — you keep your cache, we keep the
43
+ documents canonical.
44
+
45
+ ## Quickstart — writes
46
+
47
+ Building a transaction never signs or sends. Builders return a `TxIntent`:
48
+
49
+ ```ts
50
+ import { createPopContext } from '@poa-box/core';
51
+ import { createTaskIntent } from '@poa-box/core/tx/task';
52
+
53
+ const ctx = createPopContext({ chainId: 100, provider }); // provider: feature detection
54
+ const intent = await createTaskIntent(ctx, {
55
+ org: 'my-org',
56
+ project: 'Ops',
57
+ name: 'Write docs',
58
+ description: 'Draft the treasury guide',
59
+ payout: 25, // omit to derive from the org's payout convention
60
+ });
61
+ // intent = { to, abi, method, args, value?, meta: { summary, ipfs, … } }
62
+ ```
63
+
64
+ Execute it with whatever stack you have:
65
+
66
+ ```ts
67
+ // 1. ethers EOA (what the CLI does)
68
+ import { executeIntent } from '@poa-box/core/execute/ethers';
69
+ const result = await executeIntent(signer, intent, { dryRun: false });
70
+ // result: { success, txHash, explorerUrl, logs, errorCode?, suggestion?, … }
71
+
72
+ // 2. wagmi / viem
73
+ import { encodeIntent } from '@poa-box/core/tx/intent';
74
+ writeContract({
75
+ address: intent.to as `0x${string}`,
76
+ abi: intent.abi,
77
+ functionName: intent.method,
78
+ args: intent.args,
79
+ });
80
+
81
+ // 3. ERC-4337 / EIP-7702 sponsored (PaymasterHub pays gas)
82
+ import { sendSponsored } from '@poa-box/core/execute/sponsored';
83
+ const { data } = encodeIntent(intent);
84
+ await sendSponsored(privateKey, intent.to, data, orgId, hatId, {
85
+ bundlerUrl, // or pimlicoApiKey
86
+ });
87
+
88
+ // 4. anything else — Safe, multisig proposal, raw RPC
89
+ const { to, data, value } = encodeIntent(intent);
90
+ ```
91
+
92
+ Every builder has two levels:
93
+
94
+ - **`build*` (pure, sync)** — you supply resolved addresses and values, it
95
+ returns the intent. Zero I/O; right for frontends that already hold org
96
+ context.
97
+ - **`*Intent(ctx, params)` (resolved, async)** — resolves the org via
98
+ subgraph, derives conventions (payout pricing, feature-gated calldata for
99
+ v6/v7 TaskManagers), pins metadata to IPFS, then calls the pure builder.
100
+
101
+ `meta.summary` on every intent carries human-readable preview fields for your
102
+ confirmation UI; `meta.ipfs` carries the pinned CID + document.
103
+
104
+ ## Metadata is canonical here
105
+
106
+ The subgraph and every frontend parse metadata JSON **by exact key order**.
107
+ Never hand-build these objects — use `@poa-box/core/metadata/*`:
108
+
109
+ ```ts
110
+ import { task } from '@poa-box/core/metadata';
111
+ const doc = task.buildTaskMetadata({ name, description, location, difficulty, estHours });
112
+ ```
113
+
114
+ ## Environment injection
115
+
116
+ Core never reads `process.env`. Hosts pass an `EnvSource` where env-derived
117
+ behavior is wanted:
118
+
119
+ ```ts
120
+ // Node CLI
121
+ const ctx = createPopContext({ chainId: 100, env: process.env });
122
+
123
+ // Next.js
124
+ const ctx = createPopContext({
125
+ chainId: 100,
126
+ env: { GRAPH_API_KEY: process.env.NEXT_PUBLIC_GRAPH_API_KEY },
127
+ graph: { stateStore: myLocalStorageStore }, // free-tier quota memory
128
+ ipfs: { apiUrl: myPinningEndpoint },
129
+ });
130
+ ```
131
+
132
+ Injection seams: `EnvSource` (endpoints, tier mode, API keys),
133
+ `TierStateStore` (subgraph quota pins — in-memory default, the CLI uses a
134
+ file, a browser can use localStorage), `IpfsOptions`, `fetch`, and `onWarn`.
135
+
136
+ ## Module map
137
+
138
+ | Subpath | Contents |
139
+ |---|---|
140
+ | `@poa-box/core/chains` | chain table, env-injected RPC/subgraph resolution, token registry |
141
+ | `@poa-box/core/abis` | generated contract ABIs (`ALL_ABIS`), regenerated from forge artifacts |
142
+ | `@poa-box/core/graph/client` | tiered subgraph client (`GraphClient`) |
143
+ | `@poa-box/core/graph/documents` | GraphQL documents + pure derivation helpers, per domain |
144
+ | `@poa-box/core/reads/*` | typed reads: `resolve`, `task`, `org`, `vote`, `token`, `user`, `eligibility`, `treasury`, `paymaster`, `education`, `project`, `zkemail` |
145
+ | `@poa-box/core/tx/*` | `intent` (TxIntent/encodeIntent) + builders per domain, incl. `governance` (proposal wraps) |
146
+ | `@poa-box/core/execute/*` | `ethers` (EOA executor, error classification, 4337 inner-revert detection), `sponsored` (7702/4337 userop path) |
147
+ | `@poa-box/core/metadata/*` | canonical metadata builders (key order = protocol) |
148
+ | `@poa-box/core/payout`, `perms`, `zkemail`, `encoding`, `format`, `validation`, `multicall`, `error-catalog`, `preflight`, `version`, `task-lens`, `ipfs` | shared protocol logic |
149
+
150
+ Prefer subpath imports — the root barrel re-exports everything but pulls the
151
+ whole package into a bundle.
152
+
153
+ ## Stability contract
154
+
155
+ - **Semver.** Additive changes ship as patches. Renaming, removing, or moving
156
+ an export is a breaking change. **While this package is on 0.x**, semver
157
+ puts breaking changes in the MINOR position, so a break bumps `0.x → 0.(x+1)`
158
+ and a patch (`0.x.y → 0.x.(y+1)`) is always safe — pin `~0.1.0` to get safe
159
+ patches only. After 1.0.0 a break bumps the major, as usual. This matches
160
+ [docs/RELEASING.md](../../docs/RELEASING.md) exactly; the two documents are
161
+ one policy.
162
+ - **Enforced.** `api-surface.json` records every export of every module;
163
+ `yarn api:check` fails if any recorded export disappears (additions are
164
+ allowed and recorded with `yarn api:update`, so they show up in review).
165
+ Same policy as the CLI's `--json` output contracts.
166
+ - **Encoding parity.** `test/calldata-parity.test.ts` pins intent builders to
167
+ the exact bytes the CLI has always broadcast; `test/purity.test.ts` pins
168
+ browser purity.
169
+ - Frozen shapes: `TxIntent`, `TxResult`, error codes (`TX_REVERTED`,
170
+ `INSUFFICIENT_FUNDS`, `NETWORK_ERROR`, `GAS_ESTIMATION_FAILED`, …), and all
171
+ metadata document shapes.
172
+
173
+ ## Not building in JS? Or building an AI agent?
174
+
175
+ This package is one of three integration surfaces (the others: the `pop` CLI
176
+ with `--json` for any language, and `pop mcp serve` for tool-calling AI
177
+ agents). All three produce byte-identical transactions and metadata. The
178
+ chooser + quickstarts for all three live in
179
+ [`docs/guides/integrators.md`](../../docs/guides/integrators.md).
180
+
181
+ ## Relationship to the CLI and frontend
182
+
183
+ The `pop` CLI consumes this package for all shared logic (its `src/lib/*`
184
+ modules are thin wrappers binding `process.env` and the terminal), so core is
185
+ exercised by the CLI's full test suite on every change. The reference frontend
186
+ (`poa-app`) has the same layering (`src/services/web3/` with pluggable
187
+ transaction managers); migrating a service means adapting its
188
+ `txManager.execute(contract, method, args)` call to accept a `TxIntent` and
189
+ replacing the service internals with the corresponding `tx/<domain>` builders.
190
+
191
+ ## Development
192
+
193
+ ```bash
194
+ yarn build # gen-abis (from ../../src/abi) + tsc → dist/
195
+ yarn test # purity gate + calldata parity
196
+ yarn api:check # exported-surface tripwire (run after build)
197
+ ```
198
+
199
+ ABIs track the contracts repo's deployed `main` via the CLI's
200
+ `yarn sync-abis`; `scripts/gen-abis.mjs` derives the TS modules at every core
201
+ build, so the checked-in copies self-heal.