@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
@@ -0,0 +1,229 @@
1
+ /**
2
+ * User & account reads — typed wrappers over graph/documents/user.
3
+ *
4
+ * Serves the read paths of `pop user whoami` (src/commands/user/whoami.ts),
5
+ * `pop user profile` (src/commands/user/profile.ts), and the pre-write reads
6
+ * of `pop user join` / `pop user claim-hats` / `pop user update-profile`.
7
+ *
8
+ * Usernames and profile metadata are HOME-CHAIN account-registry state
9
+ * (that's where `pop user register` writes and `pop user profile` reads), so
10
+ * the account-scoped helpers default to HOME_CHAIN_ID rather than the
11
+ * client's default chain. An explicit chainId always wins.
12
+ *
13
+ * A null row from any of these means NOT-INDEXED, not nonexistent — the CLI
14
+ * keeps live RPC fallbacks (getUsername, balanceOf, Hats.balanceOf) for every
15
+ * decision where that difference matters, and `isAccountAuthoritative`
16
+ * (re-exported below) is the guard that says when an indexed account may
17
+ * stand in for a live registry read.
18
+ */
19
+ import type { GraphClient } from '../graph/client';
20
+ import { IndexedAccount, IndexedQuickJoin } from '../graph/documents/user';
21
+ export { isAccountAuthoritative } from '../graph/documents/user';
22
+ export type { IndexedAccount, IndexedQuickJoin } from '../graph/documents/user';
23
+ /** Row shape of GET_ACCOUNT_BY_USERNAME. `id` is the lowercased address. */
24
+ export interface AccountByUsername {
25
+ id: string;
26
+ user: string;
27
+ username: string;
28
+ }
29
+ /**
30
+ * Username → address resolution (GET_ACCOUNT_BY_USERNAME). Returns null when
31
+ * no account is indexed under that exact username (usernames are unique on
32
+ * the registry, so first-of-one is the whole answer).
33
+ */
34
+ export declare function getAccountByUsername(client: GraphClient, username: string, chainId?: number): Promise<AccountByUsername | null>;
35
+ /** Account + profile metadata served by FETCH_USERNAME. */
36
+ export interface AccountProfile {
37
+ id: string;
38
+ username: string;
39
+ profileMetadataHash: string | null;
40
+ metadata: {
41
+ id: string;
42
+ bio: string | null;
43
+ avatar: string | null;
44
+ github: string | null;
45
+ twitter: string | null;
46
+ website: string | null;
47
+ } | null;
48
+ }
49
+ /**
50
+ * One address's username + profile metadata — the home-chain read behind
51
+ * `pop user profile` (src/commands/user/profile.ts). Null means no indexed
52
+ * account (never registered, or indexer lag after a fresh registration).
53
+ */
54
+ export declare function getAccountProfile(client: GraphClient, address: string, chainId?: number): Promise<AccountProfile | null>;
55
+ /**
56
+ * Standalone username lookup (username + isDeleted + registry) — the no-org
57
+ * path of `pop user whoami` (src/commands/user/whoami.ts). Gate any use of
58
+ * the returned username with isAccountAuthoritative before trusting it in
59
+ * place of a live registry.getUsername read.
60
+ */
61
+ export declare function getAccountUsername(client: GraphClient, address: string, chainId?: number): Promise<IndexedAccount | null>;
62
+ /**
63
+ * The org QuickJoin's module pointers plus one caller's account, in one
64
+ * round-trip — the pre-write read of `pop user join`
65
+ * (src/commands/user/join.ts). The account may only stand in for a live
66
+ * getUsername read when
67
+ * `isAccountAuthoritative(account, quickJoinContract.accountRegistry)`; and
68
+ * the CLI ALWAYS re-reads the registry pointer live before writing, because
69
+ * QuickJoin.updateAddresses can re-point it (see the join command header for
70
+ * why trusting the indexed pointer is unrecoverable in both directions).
71
+ */
72
+ export declare function getQuickJoinAccount(client: GraphClient, quickJoinAddress: string, accountAddress: string, chainId?: number): Promise<{
73
+ quickJoinContract: IndexedQuickJoin | null;
74
+ account: IndexedAccount | null;
75
+ }>;
76
+ /**
77
+ * Just the QuickJoin module pointers (accountRegistry / hatsContract /
78
+ * memberHatIds) — the address read of `pop user claim-hats`
79
+ * (src/commands/user/claim-hats.ts). The pointers are static deploy-time
80
+ * values, byte-verified against the live eth_calls on Gnosis and Arbitrum;
81
+ * the claim pre-flight probes themselves stay on-chain in the CLI.
82
+ */
83
+ export declare function getQuickJoinModules(client: GraphClient, quickJoinAddress: string, chainId?: number): Promise<IndexedQuickJoin | null>;
84
+ /** Account row served by FETCH_REGISTRY_AND_ACCOUNT (profile-merge shape). */
85
+ export interface RegistryAccount {
86
+ id: string;
87
+ username: string;
88
+ isDeleted: boolean;
89
+ metadata: {
90
+ bio: string | null;
91
+ avatar: string | null;
92
+ github: string | null;
93
+ twitter: string | null;
94
+ website: string | null;
95
+ } | null;
96
+ }
97
+ /**
98
+ * The indexed account registry plus one account's username and profile
99
+ * metadata, in one round-trip — everything `pop user update-profile`
100
+ * (src/commands/user/update-profile.ts) reads before it writes.
101
+ * `registryAddress === null` means the registry is not indexed on this chain
102
+ * (subgraph syncing) — the CLI treats that as EXIT.INFRA.
103
+ */
104
+ export declare function getRegistryAndAccount(client: GraphClient, address: string, chainId?: number): Promise<{
105
+ registryAddress: string | null;
106
+ account: RegistryAccount | null;
107
+ }>;
108
+ /** Org-scoped user entity served by the FETCH_USER_DATA tier family. */
109
+ export interface OrgUser {
110
+ id: string;
111
+ address: string;
112
+ participationTokenBalance: string | null;
113
+ membershipStatus: string | null;
114
+ currentHatIds: string[] | null;
115
+ joinMethod: string | null;
116
+ totalTasksCompleted: string | null;
117
+ totalVotes: string | null;
118
+ totalModulesCompleted: string | null;
119
+ firstSeenAt: string | null;
120
+ lastActiveAt: string | null;
121
+ assignedTasks: Array<{
122
+ id: string;
123
+ taskId: string;
124
+ title: string | null;
125
+ payout: string | null;
126
+ status: string;
127
+ }>;
128
+ completedTasks: Array<{
129
+ id: string;
130
+ taskId: string;
131
+ title: string | null;
132
+ payout: string | null;
133
+ }>;
134
+ hybridProposalsCreated: Array<{
135
+ id: string;
136
+ proposalId: string;
137
+ title: string | null;
138
+ status: string | null;
139
+ startTimestamp: string | null;
140
+ endTimestamp: string | null;
141
+ }>;
142
+ modulesCompleted: Array<{
143
+ moduleId: string;
144
+ completedAt: string | null;
145
+ }>;
146
+ /** v7 claim-churn counters — ONLY when hasChurnCounters (tier 0, Gnosis today). */
147
+ totalTasksReleased?: string;
148
+ totalTasksLostToExpiry?: string;
149
+ }
150
+ export interface OrgUserProfile {
151
+ /** Org-scoped User entity, or null when the address never touched the org. */
152
+ user: OrgUser | null;
153
+ /** Same-chain account row (username), or null. */
154
+ account: {
155
+ id: string;
156
+ username: string;
157
+ } | null;
158
+ /**
159
+ * True when tier 0 (FETCH_USER_DATA_WITH_CHURN) served the answer. Callers
160
+ * must gate any use of totalTasksReleased/totalTasksLostToExpiry on this —
161
+ * `0` ("indexed, never churned") must stay distinguishable from absent
162
+ * ("not indexed on this chain").
163
+ */
164
+ hasChurnCounters: boolean;
165
+ }
166
+ /**
167
+ * Org membership stats for one address — the org-scoped read of
168
+ * `pop user profile` (src/commands/user/profile.ts). The subgraph User id is
169
+ * `<orgHexId>-<address>`, so an org NAME resolves to the hex id first
170
+ * (a name used directly would silently match nothing). Tier 0 carries the v7
171
+ * claim-churn counters (Gnosis only today); tier 1 is the same document
172
+ * without them.
173
+ */
174
+ export declare function getOrgUserProfile(client: GraphClient, orgIdOrName: string, address: string, chainId?: number): Promise<OrgUserProfile>;
175
+ /** Full whoami snapshot — the one-round-trip payload of FETCH_WHOAMI_ORG_DATA. */
176
+ export interface WhoamiOrgData {
177
+ organization: {
178
+ id: string;
179
+ name: string | null;
180
+ roles: Array<{
181
+ hatId: string;
182
+ name: string | null;
183
+ hat: {
184
+ active: boolean;
185
+ } | null;
186
+ }>;
187
+ } | null;
188
+ quickJoinContract: IndexedQuickJoin | null;
189
+ account: IndexedAccount | null;
190
+ tokenBalance: {
191
+ id: string;
192
+ balance: string;
193
+ } | null;
194
+ user: {
195
+ id: string;
196
+ membershipStatus: string | null;
197
+ participationTokenBalance: string | null;
198
+ currentHatIds: string[] | null;
199
+ } | null;
200
+ /** Pending requests by this user — the CLI reports `tokenRequests.length`. */
201
+ tokenRequests: Array<{
202
+ id: string;
203
+ }>;
204
+ }
205
+ /**
206
+ * One-round-trip org snapshot for `pop user whoami`
207
+ * (src/commands/user/whoami.ts): org name + role hats (with the Hats toggle
208
+ * flag), QuickJoin pointers, the caller's account/PT balance/org-user row,
209
+ * and their pending token requests. Variables are composed exactly as the
210
+ * CLI does — AddressZero placeholders keep the document valid when a module
211
+ * is missing (those selections then simply return null).
212
+ *
213
+ * Interpretation stays with the caller (the CLI keeps RPC fallbacks for
214
+ * username/PT/membership): gate `account.username` with
215
+ * isAccountAuthoritative(account, quickJoinContract?.accountRegistry), AND
216
+ * membership derived from currentHatIds with the role's `hat.active` flag —
217
+ * a toggled-off hat still appears in currentHatIds because Hats does not
218
+ * burn the token.
219
+ */
220
+ export declare function getWhoamiOrgData(client: GraphClient, params: {
221
+ /** Org hex ID (as returned by resolveOrgId / OrgModules.orgId). */
222
+ orgId: string;
223
+ /** ParticipationToken address, or null/undefined when the org has none. */
224
+ participationTokenAddress?: string | null;
225
+ /** QuickJoin address, or null/undefined when the org has none. */
226
+ quickJoinAddress?: string | null;
227
+ /** The identity being inspected. */
228
+ address: string;
229
+ }, chainId?: number): Promise<WhoamiOrgData | null>;
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ /**
3
+ * User & account reads — typed wrappers over graph/documents/user.
4
+ *
5
+ * Serves the read paths of `pop user whoami` (src/commands/user/whoami.ts),
6
+ * `pop user profile` (src/commands/user/profile.ts), and the pre-write reads
7
+ * of `pop user join` / `pop user claim-hats` / `pop user update-profile`.
8
+ *
9
+ * Usernames and profile metadata are HOME-CHAIN account-registry state
10
+ * (that's where `pop user register` writes and `pop user profile` reads), so
11
+ * the account-scoped helpers default to HOME_CHAIN_ID rather than the
12
+ * client's default chain. An explicit chainId always wins.
13
+ *
14
+ * A null row from any of these means NOT-INDEXED, not nonexistent — the CLI
15
+ * keeps live RPC fallbacks (getUsername, balanceOf, Hats.balanceOf) for every
16
+ * decision where that difference matters, and `isAccountAuthoritative`
17
+ * (re-exported below) is the guard that says when an indexed account may
18
+ * stand in for a live registry read.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.isAccountAuthoritative = void 0;
22
+ exports.getAccountByUsername = getAccountByUsername;
23
+ exports.getAccountProfile = getAccountProfile;
24
+ exports.getAccountUsername = getAccountUsername;
25
+ exports.getQuickJoinAccount = getQuickJoinAccount;
26
+ exports.getQuickJoinModules = getQuickJoinModules;
27
+ exports.getRegistryAndAccount = getRegistryAndAccount;
28
+ exports.getOrgUserProfile = getOrgUserProfile;
29
+ exports.getWhoamiOrgData = getWhoamiOrgData;
30
+ const ethers_1 = require("ethers");
31
+ const user_1 = require("../graph/documents/user");
32
+ const chains_1 = require("../chains");
33
+ const resolve_1 = require("./resolve");
34
+ // Pure selection helpers live in the documents module — re-exported here so
35
+ // read-layer consumers get the guard next to the reads it guards.
36
+ var user_2 = require("../graph/documents/user");
37
+ Object.defineProperty(exports, "isAccountAuthoritative", { enumerable: true, get: function () { return user_2.isAccountAuthoritative; } });
38
+ /**
39
+ * Username → address resolution (GET_ACCOUNT_BY_USERNAME). Returns null when
40
+ * no account is indexed under that exact username (usernames are unique on
41
+ * the registry, so first-of-one is the whole answer).
42
+ */
43
+ async function getAccountByUsername(client, username, chainId = chains_1.HOME_CHAIN_ID) {
44
+ const result = await client.query(user_1.GET_ACCOUNT_BY_USERNAME, { username }, chainId);
45
+ return result.accounts?.[0] ?? null;
46
+ }
47
+ /**
48
+ * One address's username + profile metadata — the home-chain read behind
49
+ * `pop user profile` (src/commands/user/profile.ts). Null means no indexed
50
+ * account (never registered, or indexer lag after a fresh registration).
51
+ */
52
+ async function getAccountProfile(client, address, chainId = chains_1.HOME_CHAIN_ID) {
53
+ const result = await client.query(user_1.FETCH_USERNAME, { id: address.toLowerCase() }, chainId);
54
+ return result.account ?? null;
55
+ }
56
+ /**
57
+ * Standalone username lookup (username + isDeleted + registry) — the no-org
58
+ * path of `pop user whoami` (src/commands/user/whoami.ts). Gate any use of
59
+ * the returned username with isAccountAuthoritative before trusting it in
60
+ * place of a live registry.getUsername read.
61
+ */
62
+ async function getAccountUsername(client, address, chainId = chains_1.HOME_CHAIN_ID) {
63
+ const result = await client.query(user_1.FETCH_ACCOUNT_USERNAME, { accountID: address.toLowerCase() }, chainId);
64
+ return result.account ?? null;
65
+ }
66
+ /**
67
+ * The org QuickJoin's module pointers plus one caller's account, in one
68
+ * round-trip — the pre-write read of `pop user join`
69
+ * (src/commands/user/join.ts). The account may only stand in for a live
70
+ * getUsername read when
71
+ * `isAccountAuthoritative(account, quickJoinContract.accountRegistry)`; and
72
+ * the CLI ALWAYS re-reads the registry pointer live before writing, because
73
+ * QuickJoin.updateAddresses can re-point it (see the join command header for
74
+ * why trusting the indexed pointer is unrecoverable in both directions).
75
+ */
76
+ async function getQuickJoinAccount(client, quickJoinAddress, accountAddress, chainId) {
77
+ const result = await client.query(user_1.FETCH_QUICKJOIN_ACCOUNT, { quickJoinAddress: quickJoinAddress.toLowerCase(), accountID: accountAddress.toLowerCase() }, chainId);
78
+ return {
79
+ quickJoinContract: result?.quickJoinContract ?? null,
80
+ account: result?.account ?? null,
81
+ };
82
+ }
83
+ /**
84
+ * Just the QuickJoin module pointers (accountRegistry / hatsContract /
85
+ * memberHatIds) — the address read of `pop user claim-hats`
86
+ * (src/commands/user/claim-hats.ts). The pointers are static deploy-time
87
+ * values, byte-verified against the live eth_calls on Gnosis and Arbitrum;
88
+ * the claim pre-flight probes themselves stay on-chain in the CLI.
89
+ */
90
+ async function getQuickJoinModules(client, quickJoinAddress, chainId) {
91
+ const result = await client.query(user_1.FETCH_QUICKJOIN_MODULES, { quickJoinAddress: quickJoinAddress.toLowerCase() }, chainId);
92
+ return result?.quickJoinContract ?? null;
93
+ }
94
+ /**
95
+ * The indexed account registry plus one account's username and profile
96
+ * metadata, in one round-trip — everything `pop user update-profile`
97
+ * (src/commands/user/update-profile.ts) reads before it writes.
98
+ * `registryAddress === null` means the registry is not indexed on this chain
99
+ * (subgraph syncing) — the CLI treats that as EXIT.INFRA.
100
+ */
101
+ async function getRegistryAndAccount(client, address, chainId = chains_1.HOME_CHAIN_ID) {
102
+ const result = await client.query(user_1.FETCH_REGISTRY_AND_ACCOUNT, { accountID: address.toLowerCase() }, chainId);
103
+ return {
104
+ registryAddress: result?.universalAccountRegistries?.[0]?.id ?? null,
105
+ account: result?.account ?? null,
106
+ };
107
+ }
108
+ /**
109
+ * Org membership stats for one address — the org-scoped read of
110
+ * `pop user profile` (src/commands/user/profile.ts). The subgraph User id is
111
+ * `<orgHexId>-<address>`, so an org NAME resolves to the hex id first
112
+ * (a name used directly would silently match nothing). Tier 0 carries the v7
113
+ * claim-churn counters (Gnosis only today); tier 1 is the same document
114
+ * without them.
115
+ */
116
+ async function getOrgUserProfile(client, orgIdOrName, address, chainId) {
117
+ const orgId = await (0, resolve_1.resolveOrgId)(client, orgIdOrName, chainId);
118
+ const orgUserID = `${orgId.toLowerCase()}-${address.toLowerCase()}`;
119
+ const { data, tierIndex } = await client.queryWithFieldFallback((0, user_1.userDataTiers)(orgUserID, address.toLowerCase()), { chainId });
120
+ return {
121
+ user: data.user ?? null,
122
+ account: data.account ?? null,
123
+ hasChurnCounters: tierIndex === 0,
124
+ };
125
+ }
126
+ /**
127
+ * One-round-trip org snapshot for `pop user whoami`
128
+ * (src/commands/user/whoami.ts): org name + role hats (with the Hats toggle
129
+ * flag), QuickJoin pointers, the caller's account/PT balance/org-user row,
130
+ * and their pending token requests. Variables are composed exactly as the
131
+ * CLI does — AddressZero placeholders keep the document valid when a module
132
+ * is missing (those selections then simply return null).
133
+ *
134
+ * Interpretation stays with the caller (the CLI keeps RPC fallbacks for
135
+ * username/PT/membership): gate `account.username` with
136
+ * isAccountAuthoritative(account, quickJoinContract?.accountRegistry), AND
137
+ * membership derived from currentHatIds with the role's `hat.active` flag —
138
+ * a toggled-off hat still appears in currentHatIds because Hats does not
139
+ * burn the token.
140
+ */
141
+ async function getWhoamiOrgData(client, params, chainId) {
142
+ const address = params.address.toLowerCase();
143
+ const tokenAddress = params.participationTokenAddress || ethers_1.ethers.constants.AddressZero;
144
+ const quickJoinAddress = (params.quickJoinAddress || ethers_1.ethers.constants.AddressZero).toLowerCase();
145
+ const result = await client.query(user_1.FETCH_WHOAMI_ORG_DATA, {
146
+ orgId: params.orgId,
147
+ orgUserID: `${params.orgId}-${address}`,
148
+ tokenAddress,
149
+ userAddress: address,
150
+ quickJoinAddress,
151
+ accountID: address,
152
+ tokenBalanceID: `${tokenAddress.toLowerCase()}-${address}`,
153
+ }, chainId);
154
+ return result ?? null;
155
+ }
@@ -0,0 +1,296 @@
1
+ /**
2
+ * Vote/governance reads — typed wrappers over the voting graph documents for
3
+ * the entities the CLI's `pop vote list / results / execute / classes show`
4
+ * commands read, plus the pure selection helpers those commands share
5
+ * (fuzzy --proposal resolution, announce-all candidate selection, the
6
+ * execute state gate, results tallying, class-snapshot normalization).
7
+ *
8
+ * Raw subgraph entity shapes only — scalars arrive as strings.
9
+ */
10
+ import type { GraphClient } from '../graph/client';
11
+ import { SubgraphVotingClass } from '../graph/documents/voting-classes';
12
+ /** One ballot as indexed by the subgraph (FETCH_VOTING_DATA field set). */
13
+ export interface SubgraphProposalVote {
14
+ voter: string;
15
+ voterUsername?: string | null;
16
+ optionIndexes: string[];
17
+ optionWeights: string[];
18
+ classRawPowers?: string[] | null;
19
+ votedAt?: string | null;
20
+ }
21
+ /**
22
+ * One proposal row (hybrid `proposals` or DD `ddvProposals`). Fields absent on
23
+ * the legacy (pre-#195) tier — proposer/proposerUsername/creatorUsername/
24
+ * classesVersion — arrive as undefined when that tier served the request.
25
+ */
26
+ export interface SubgraphProposal {
27
+ id?: string;
28
+ proposalId: string;
29
+ title?: string | null;
30
+ descriptionHash?: string;
31
+ metadata?: {
32
+ id?: string;
33
+ description?: string | null;
34
+ optionNames?: string[] | null;
35
+ } | null;
36
+ numOptions?: string | number;
37
+ startTimestamp?: string;
38
+ endTimestamp?: string | null;
39
+ status: string;
40
+ winningOption?: string | null;
41
+ isValid?: boolean | null;
42
+ wasExecuted?: boolean | null;
43
+ executionFailed?: boolean | null;
44
+ executionError?: string | null;
45
+ isHatRestricted?: boolean | null;
46
+ restrictedHatIds?: string[] | null;
47
+ proposer?: string | null;
48
+ proposerUsername?: string | null;
49
+ creatorUsername?: string | null;
50
+ classesVersion?: string | null;
51
+ votes?: SubgraphProposalVote[];
52
+ }
53
+ export interface SubgraphHybridVoting {
54
+ id: string;
55
+ thresholdPct?: string | number | null;
56
+ quorum?: string | number | null;
57
+ classVersion?: string | null;
58
+ votingClasses?: SubgraphVotingClass[];
59
+ proposals?: SubgraphProposal[];
60
+ }
61
+ export interface SubgraphDirectDemocracyVoting {
62
+ id: string;
63
+ thresholdPct?: string | number | null;
64
+ quorum?: string | number | null;
65
+ ddvProposals?: SubgraphProposal[];
66
+ }
67
+ /** Organization root of FETCH_VOTING_DATA — null means the org is not indexed. */
68
+ export interface VotingOrgData {
69
+ id: string;
70
+ hybridVoting?: SubgraphHybridVoting | null;
71
+ directDemocracyVoting?: SubgraphDirectDemocracyVoting | null;
72
+ }
73
+ /**
74
+ * Port of the `pop vote list` / `pop vote announce-all` data fetch
75
+ * (src/commands/vote/list.ts, src/commands/vote/announce-all.ts):
76
+ * FETCH_VOTING_DATA with the pre-#195 legacy tier as fallback.
77
+ *
78
+ * A GraphQL document validates as a whole, so one unknown field fails the
79
+ * entire query — the legacy tier keeps listing (and announcing) working
80
+ * against a pre-#195 subgraph deployment.
81
+ */
82
+ export declare function fetchVotingData(client: GraphClient, orgIdOrName: string, chainId?: number): Promise<VotingOrgData | null>;
83
+ export interface ProposalCandidate {
84
+ proposalId: string;
85
+ title: string;
86
+ status: string;
87
+ endTimestamp?: string;
88
+ }
89
+ /**
90
+ * Port of `fetchRecentProposals` (src/commands/vote/helpers.ts): recent
91
+ * proposal titles for ONE voting contract, addressed by contract address —
92
+ * works for both Hybrid and DD (whichever entity matches answers, the other
93
+ * root field returns null).
94
+ */
95
+ export declare function fetchRecentProposals(client: GraphClient, contractAddr: string, chainId?: number, first?: number): Promise<ProposalCandidate[]>;
96
+ /**
97
+ * Port of `resolveProposalId` (src/commands/vote/helpers.ts): resolve a
98
+ * user-supplied proposal argument to a numeric proposal ID.
99
+ *
100
+ * - Numeric input → returned as-is (no network round-trip).
101
+ * - Anything else → fuzzy title query against the voting contract's recent
102
+ * proposals, scored with Jaccard bestMatches at threshold 0.5.
103
+ * - exactly one match → resolved
104
+ * - multiple matches → CliError listing the candidates (the CLI's
105
+ * non-TTY behavior; the interactive picker is CLI UX and not ported)
106
+ * - zero matches → CliError listing the 5 most recent titles
107
+ *
108
+ * opts.preferActive (used by `vote cast`): when several proposals match but
109
+ * exactly ONE is still Active, that one wins — you can only cast on an open
110
+ * proposal, so ended homonyms are not ambiguity.
111
+ */
112
+ export declare function resolveProposalId(client: GraphClient, input: string, contractAddr: string, chainId?: number, opts?: {
113
+ preferActive?: boolean;
114
+ }): Promise<number>;
115
+ export interface AnnounceCandidate {
116
+ id: string;
117
+ type: 'hybrid' | 'dd';
118
+ title: string;
119
+ /** True when this is an H-05 retry of a failed execution. */
120
+ retry: boolean;
121
+ }
122
+ /**
123
+ * Pure port of the `pop vote announce-all` candidate filter
124
+ * (src/commands/vote/announce-all.ts): proposals ready to announce are
125
+ * - status "Ended" (subgraph updated), OR
126
+ * - status "Active" but endTimestamp has passed (subgraph hasn't updated)
127
+ * excluding already-announced ones — EXCEPT the H-05 retry case: a FAILED
128
+ * execution is not "done". Audit H-05 releases the in-flight `executed` lock
129
+ * in the catch branch, so the proposal is re-announceable — but it already
130
+ * has a winningOption (Winner is emitted regardless), so the plain
131
+ * already-announced test would skip it forever and silently.
132
+ *
133
+ * Callers should still per-proposal callStatic-probe announceWinner before
134
+ * broadcasting (the CLI skips would-revert candidates without burning gas).
135
+ *
136
+ * @param nowSeconds unix seconds "now" — pass chain time when available.
137
+ */
138
+ export declare function selectAnnounceCandidates(org: VotingOrgData, nowSeconds: number): AnnounceCandidate[];
139
+ /** Pre-broadcast finalization state machine row (pop vote execute). */
140
+ export interface ProposalExecutionState {
141
+ proposalId: string;
142
+ status: string;
143
+ winningOption?: string | null;
144
+ wasExecuted?: boolean | null;
145
+ executionFailed?: boolean | null;
146
+ isValid?: boolean | null;
147
+ winnerAnnouncedAt?: string | null;
148
+ }
149
+ /** The `pop vote execute` state-gate document (src/commands/vote/execute.ts). */
150
+ export declare const GET_PROPOSAL_EXECUTION_STATE = "\n query GetProposal($votingId: String!, $proposalId: String!) {\n proposals(where: { hybridVoting: $votingId, proposalId: $proposalId }, first: 1) {\n proposalId\n status\n winningOption\n wasExecuted\n executionFailed\n isValid\n winnerAnnouncedAt\n }\n }\n";
151
+ /**
152
+ * Port of the `pop vote execute` subgraph state gate: fetch the one proposal
153
+ * row the finalize decision is made from. Null row means the proposal is not
154
+ * indexed (the CLI treats that as not found).
155
+ */
156
+ export declare function fetchProposalExecutionState(client: GraphClient, hybridVotingAddress: string, proposalId: number | string, chainId?: number): Promise<ProposalExecutionState | null>;
157
+ export type ExecuteGateDecision =
158
+ /** wasExecuted — nothing to do (the CLI info-returns). */
159
+ {
160
+ kind: 'already-executed';
161
+ }
162
+ /** Announced and execution did NOT fail — nothing to do. */
163
+ | {
164
+ kind: 'already-announced';
165
+ isValid?: boolean | null;
166
+ }
167
+ /** Still Active/etc. — the CLI throws PRECONDITION here. */
168
+ | {
169
+ kind: 'not-ended';
170
+ status: string;
171
+ }
172
+ /**
173
+ * Proceed to the callStatic probe + announceWinner. When
174
+ * retryingFailedExecution is true this is the H-05 retry path: the
175
+ * announce succeeded, the execution reverted, and re-running
176
+ * announceWinner is the intended fix (the callStatic probe arbitrates —
177
+ * a pre-#185 contract reverts AlreadyExecuted there).
178
+ */
179
+ | {
180
+ kind: 'ready';
181
+ retryingFailedExecution: boolean;
182
+ };
183
+ /**
184
+ * Pure port of the `pop vote execute` decision ladder over the subgraph row
185
+ * (same evaluation order as src/commands/vote/execute.ts). The caller maps
186
+ * 'not-ended' to the CLI's PRECONDITION error and the two "nothing to do"
187
+ * kinds to graceful no-ops.
188
+ */
189
+ export declare function evaluateExecuteGate(proposal: ProposalExecutionState): ExecuteGateDecision;
190
+ export interface ProposalResultsRankEntry {
191
+ rank: number;
192
+ option: number;
193
+ name: string;
194
+ score: number;
195
+ }
196
+ export interface ProposalResultsVoter {
197
+ voter: string;
198
+ allocations: Record<string, number>;
199
+ }
200
+ /** The `pop vote results --json` report shape (an output contract — do not reshape). */
201
+ export interface ProposalResults {
202
+ proposalId: string;
203
+ title?: string | null;
204
+ status: string;
205
+ /** IDENTITY or null — deliberately never an address (see fetch doc comment). */
206
+ proposedBy: string | null;
207
+ proposerAddress: string | null;
208
+ classVersionAtCreation: string | null;
209
+ liveClassVersion: string | null;
210
+ classConfigDrifted: boolean;
211
+ winnerAnnouncedAt: number | null;
212
+ executedAt: number | null;
213
+ executedCallsCount: number | null;
214
+ actionSummaries: string[];
215
+ promotedFrom: string | null;
216
+ totalVoters: number;
217
+ supportThresholdPct?: number;
218
+ quorumVoterCount?: number;
219
+ ranking: ProposalResultsRankEntry[];
220
+ voters: ProposalResultsVoter[];
221
+ winner?: ProposalResultsRankEntry;
222
+ }
223
+ /**
224
+ * The `pop vote results` proposal document (src/commands/vote/results.ts).
225
+ * Two tiers: the #195 attribution/provenance fields, then the pre-#195 field
226
+ * set. A GraphQL document validates as a whole, so without the fallback an
227
+ * endpoint that predates #195 would lose the rankings and voter breakdown
228
+ * this read exists to serve. The legacy tier is spelled out rather than
229
+ * derived so a reformat cannot silently turn it into a copy of the modern one.
230
+ */
231
+ export declare function buildProposalResultsQuery(orgId: string, proposalId: number, modern: boolean): string;
232
+ /**
233
+ * Pure port of the `pop vote results` tally/ranking/attribution computation
234
+ * (src/commands/vote/results.ts) over the fetched hybridVoting row.
235
+ *
236
+ * Attribution: subgraph #195. proposer* are the current names; creator* the
237
+ * older aliases populated identically from transaction.from. proposedBy is an
238
+ * IDENTITY or null — never an address: most proposers are Executor or
239
+ * smart-account addresses with no username, and returning the address here
240
+ * would make `proposedBy === 'someone'` silently false for them while looking
241
+ * like a resolved name. The address is always available as proposerAddress.
242
+ */
243
+ export declare function computeProposalResults(hybridVoting: {
244
+ thresholdPct?: string | number | null;
245
+ quorum?: string | number | null;
246
+ classVersion?: string | null;
247
+ proposals?: Array<SubgraphProposal & {
248
+ winnerAnnouncedAt?: string | null;
249
+ executedAt?: string | null;
250
+ executedCallsCount?: string | number | null;
251
+ metadata?: {
252
+ description?: string | null;
253
+ optionNames?: string[] | null;
254
+ actionSummaries?: string[] | null;
255
+ promotedFrom?: string | null;
256
+ } | null;
257
+ }>;
258
+ }): ProposalResults | null;
259
+ /**
260
+ * Port of `pop vote results` (src/commands/vote/results.ts): rankings +
261
+ * per-voter breakdown for one proposal. Throws the CLI's not-found error when
262
+ * the proposal is not indexed.
263
+ */
264
+ export declare function fetchProposalResults(client: GraphClient, orgIdOrName: string, proposalId: number, chainId?: number): Promise<ProposalResults>;
265
+ /** Normalized class row — identical shape from the subgraph and the contract. */
266
+ export interface NormalizedClass {
267
+ classIndex: number;
268
+ strategy: string;
269
+ slicePct: number;
270
+ quadratic: boolean;
271
+ minBalance: string;
272
+ asset: string;
273
+ hatIds: string[];
274
+ }
275
+ export interface ClassConfigSnapshot {
276
+ classes: NormalizedClass[];
277
+ supportThresholdPct: number;
278
+ quorumVoterCount: number;
279
+ }
280
+ /**
281
+ * Subgraph rows → the exact shape the contract path produces. `asset` is
282
+ * checksummed because ethers returns a checksummed address and the subgraph
283
+ * returns lowercase Bytes; without this the `asset` value would change casing
284
+ * depending on which source answered.
285
+ */
286
+ export declare function normalizeSubgraphClasses(rows: SubgraphVotingClass[]): NormalizedClass[];
287
+ /**
288
+ * Port of `pop vote classes show`'s subgraph read
289
+ * (fetchClassConfigFromSubgraph, src/commands/vote/classes.ts): the class
290
+ * table + both validity parameters. Returns null whenever the subgraph cannot
291
+ * answer authoritatively (contract not indexed, no rows for the requested
292
+ * version, missing schema fields, network error) so the caller falls back to
293
+ * the contract (getClasses()/getProposalClasses()/thresholdPct()/quorum())
294
+ * instead of showing an empty table.
295
+ */
296
+ export declare function fetchClassConfig(client: GraphClient, hybridVotingAddress: string, proposalId?: number, chainId?: number): Promise<ClassConfigSnapshot | null>;