@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,177 @@
1
+ /**
2
+ * User write builders — UniversalAccountRegistry (registerAccount /
3
+ * changeUsername / setProfileMetadata) and QuickJoinNew (quickJoinWithUser /
4
+ * claimHatsWithUser).
5
+ *
6
+ * Level 1: pure, sync builders taking resolved addresses + prepared values.
7
+ * Level 2: async `<action>Intent(ctx, params)` builders that resolve the
8
+ * registry / QuickJoin address via the subgraph, merge + pin profile
9
+ * metadata, and delegate to Level 1.
10
+ *
11
+ * Chain semantics (preserved CLI behavior): usernames and profile metadata
12
+ * are HOME-CHAIN account-registry state, so the registry-scoped Level-2
13
+ * builders default to HOME_CHAIN_ID — deliberately IGNORING ctx.chainId (the
14
+ * CLI ignores POP_DEFAULT_CHAIN the same way; an explicit `chainId` param
15
+ * wins). The org-scoped QuickJoin builders use ctx.chainId as usual.
16
+ *
17
+ * NOT ported (CLI-side revert prediction / flow UX): checkUsernameFree,
18
+ * AccountUnknown prediction, the live re-read of quickJoin.accountRegistry()
19
+ * before a 2-tx join (a write-target pointer that updateAddresses can
20
+ * re-point — see src/commands/user/join.ts), and the claim-hats Multicall3
21
+ * probes (NoUsername / MAX_HATS_PER_MINT / HatOpenlyClaimable sentinel).
22
+ */
23
+ import { ethers } from 'ethers';
24
+ import type { TxIntent } from './intent';
25
+ import type { PopContext } from '../context';
26
+ import { UserProfileUpdates } from '../metadata/user';
27
+ /**
28
+ * Parse a comma-separated hat-ID list into BigNumbers. Accepts decimal and
29
+ * 0x-hex forms. Hats Protocol IDs are uint256 — far beyond 2^53 — so
30
+ * parseInt/Number would silently corrupt them.
31
+ * Port of parseHatIds in `pop user claim-hats` —
32
+ * src/commands/user/claim-hats.ts (same messages and exit codes).
33
+ */
34
+ export declare function parseHatIds(input: string): ethers.BigNumber[];
35
+ export interface RegisterAccountArgs {
36
+ /** UniversalAccountRegistry address (home chain unless overridden). */
37
+ registryAddress: string;
38
+ /** Validated username (3-32 alphanumeric+underscore — requireValidUsername). */
39
+ username: string;
40
+ }
41
+ /**
42
+ * Port of `pop user register` — src/commands/user/register.ts (also tx 1 of
43
+ * the 2-tx `pop user join` flow — src/commands/user/join.ts).
44
+ * UniversalAccountRegistry.registerAccount(string username); reverts
45
+ * UsernameTaken when the name is held. For the join flow, register on the
46
+ * SAME registry the org's QuickJoin consults (quickJoin.accountRegistry(),
47
+ * re-read live in the CLI) — registering anywhere else leaves
48
+ * quickJoinWithUser reverting NoUsername.
49
+ */
50
+ export declare function buildRegisterAccount(a: RegisterAccountArgs): TxIntent;
51
+ export interface ChangeUsernameArgs {
52
+ registryAddress: string;
53
+ /** Validated new username. */
54
+ newUsername: string;
55
+ }
56
+ /**
57
+ * Port of `pop user update-profile --username` —
58
+ * src/commands/user/update-profile.ts.
59
+ * UniversalAccountRegistry.changeUsername(string newUsername) — DESTRUCTIVE:
60
+ * the old username is released for anyone to claim the moment the tx lands.
61
+ * Reverts AccountUnknown without an existing registration and UsernameTaken
62
+ * when the new name is held.
63
+ */
64
+ export declare function buildChangeUsername(a: ChangeUsernameArgs): TxIntent;
65
+ export interface SetProfileMetadataArgs {
66
+ registryAddress: string;
67
+ /** bytes32 metadata hash — ipfsCidToBytes32 of the pinned profile document. */
68
+ metadataHash: string;
69
+ }
70
+ /**
71
+ * Port of the metadata tx of `pop user update-profile` —
72
+ * src/commands/user/update-profile.ts.
73
+ * UniversalAccountRegistry.setProfileMetadata(bytes32 metadataHash), where
74
+ * metadataHash = ipfsCidToBytes32(pinJson(serialized profile document)).
75
+ */
76
+ export declare function buildSetProfileMetadata(a: SetProfileMetadataArgs): TxIntent;
77
+ export interface QuickJoinWithUserArgs {
78
+ quickJoinAddress: string;
79
+ orgId?: string;
80
+ }
81
+ /**
82
+ * Port of `pop user join` (the join tx) — src/commands/user/join.ts.
83
+ * QuickJoinNew.quickJoinWithUser() — NO arguments. The contract reads
84
+ * accountRegistry.getUsername(msg.sender) and reverts NoUsername when it is
85
+ * empty, so the sender must already hold a username on the registry this
86
+ * QuickJoin consults (register first via buildRegisterAccount when needed).
87
+ */
88
+ export declare function buildQuickJoinWithUser(a: QuickJoinWithUserArgs): TxIntent;
89
+ export interface ClaimHatsWithUserArgs {
90
+ quickJoinAddress: string;
91
+ /** uint256 hat IDs — parse strings with parseHatIds, never parseInt. */
92
+ hatIds: ethers.BigNumber[];
93
+ orgId?: string;
94
+ }
95
+ /**
96
+ * Port of `pop user claim-hats` — src/commands/user/claim-hats.ts.
97
+ * QuickJoinNew.claimHatsWithUser(uint256[] claimHatIds). The caller must
98
+ * already have a username (reverts NoUsername); since audit H-03 QuickJoin
99
+ * refuses openly-claimable hats (reverts HatOpenlyClaimable), and the
100
+ * executor bounds the batch at MAX_HATS_PER_MINT.
101
+ */
102
+ export declare function buildClaimHatsWithUser(a: ClaimHatsWithUserArgs): TxIntent;
103
+ export interface RegisterAccountParams {
104
+ username: string;
105
+ /** Registry chain. Defaults to HOME_CHAIN_ID (Arbitrum) — NOT ctx.chainId. */
106
+ chainId?: number;
107
+ }
108
+ /**
109
+ * Resolved builder for `pop user register` — src/commands/user/register.ts.
110
+ * Validates the username, resolves the UniversalAccountRegistry address from
111
+ * the infrastructure subgraph (universalAccountRegistries[0].id, falling back
112
+ * to poaManagerContracts[0].globalAccountRegistryProxy), then builds the
113
+ * registerAccount intent. Defaults to the HOME chain, deliberately ignoring
114
+ * ctx.chainId — usernames live on the home chain (the CLI ignores
115
+ * POP_DEFAULT_CHAIN the same way).
116
+ */
117
+ export declare function registerAccountIntent(ctx: PopContext, params: RegisterAccountParams): Promise<TxIntent>;
118
+ export interface ChangeUsernameParams {
119
+ /** The account being renamed (the eventual tx sender). */
120
+ address: string;
121
+ newUsername: string;
122
+ /** Registry chain. Defaults to HOME_CHAIN_ID — NOT ctx.chainId. */
123
+ chainId?: number;
124
+ }
125
+ /**
126
+ * Resolved builder for the username tx of `pop user update-profile` —
127
+ * src/commands/user/update-profile.ts. DESTRUCTIVE: the old username is
128
+ * released on-chain for anyone to claim. Resolves the registry from the same
129
+ * one-round-trip document the CLI uses. The CLI's AccountUnknown /
130
+ * UsernameTaken / no-op-rename predictions are preflight and are not ported.
131
+ */
132
+ export declare function changeUsernameIntent(ctx: PopContext, params: ChangeUsernameParams): Promise<TxIntent>;
133
+ export interface SetProfileMetadataParams extends UserProfileUpdates {
134
+ /** The account whose profile is being updated (the eventual tx sender). */
135
+ address: string;
136
+ /** Registry chain. Defaults to HOME_CHAIN_ID — NOT ctx.chainId. */
137
+ chainId?: number;
138
+ }
139
+ /**
140
+ * Resolved builder for the metadata tx of `pop user update-profile` —
141
+ * src/commands/user/update-profile.ts. Reads the existing indexed profile
142
+ * metadata (read-then-merge, so single-field edits preserve the others),
143
+ * builds the {bio, avatar, github, twitter, website} document with the CLI's
144
+ * exact conditional key order, pins it to IPFS, converts the CID to bytes32,
145
+ * and builds the setProfileMetadata intent.
146
+ */
147
+ export declare function setProfileMetadataIntent(ctx: PopContext, params: SetProfileMetadataParams): Promise<TxIntent>;
148
+ export interface QuickJoinParams {
149
+ /** Org name or hex ID. */
150
+ org: string;
151
+ }
152
+ /**
153
+ * Resolved builder for `pop user join` (join tx only) —
154
+ * src/commands/user/join.ts. Resolves the org's QuickJoin via the subgraph
155
+ * and builds the quickJoinWithUser intent. The 1-tx vs 2-tx decision (does
156
+ * the sender already hold a username on the registry this QuickJoin
157
+ * consults?) is host orchestration: read state with
158
+ * reads/user.getQuickJoinAccount, re-verify the registry pointer LIVE
159
+ * (quickJoin.accountRegistry() — it is a write target updateAddresses can
160
+ * re-point), and when registration is needed send buildRegisterAccount
161
+ * against THAT registry first.
162
+ */
163
+ export declare function quickJoinWithUserIntent(ctx: PopContext, params: QuickJoinParams): Promise<TxIntent>;
164
+ export interface ClaimHatsParams {
165
+ /** Org name or hex ID. */
166
+ org: string;
167
+ /** Comma-separated hat-ID string (as the CLI's --hats), or pre-parsed IDs. */
168
+ hats: string | Array<string | ethers.BigNumberish>;
169
+ }
170
+ /**
171
+ * Resolved builder for `pop user claim-hats` —
172
+ * src/commands/user/claim-hats.ts. Parses hat IDs with BigNumber (uint256 —
173
+ * never parseInt), resolves the org's QuickJoin via the subgraph, and builds
174
+ * the claimHatsWithUser intent. The CLI's Multicall3 preflight (NoUsername /
175
+ * batch cap / open-hat sentinel probes) stays in the CLI.
176
+ */
177
+ export declare function claimHatsWithUserIntent(ctx: PopContext, params: ClaimHatsParams): Promise<TxIntent>;
@@ -0,0 +1,292 @@
1
+ "use strict";
2
+ /**
3
+ * User write builders — UniversalAccountRegistry (registerAccount /
4
+ * changeUsername / setProfileMetadata) and QuickJoinNew (quickJoinWithUser /
5
+ * claimHatsWithUser).
6
+ *
7
+ * Level 1: pure, sync builders taking resolved addresses + prepared values.
8
+ * Level 2: async `<action>Intent(ctx, params)` builders that resolve the
9
+ * registry / QuickJoin address via the subgraph, merge + pin profile
10
+ * metadata, and delegate to Level 1.
11
+ *
12
+ * Chain semantics (preserved CLI behavior): usernames and profile metadata
13
+ * are HOME-CHAIN account-registry state, so the registry-scoped Level-2
14
+ * builders default to HOME_CHAIN_ID — deliberately IGNORING ctx.chainId (the
15
+ * CLI ignores POP_DEFAULT_CHAIN the same way; an explicit `chainId` param
16
+ * wins). The org-scoped QuickJoin builders use ctx.chainId as usual.
17
+ *
18
+ * NOT ported (CLI-side revert prediction / flow UX): checkUsernameFree,
19
+ * AccountUnknown prediction, the live re-read of quickJoin.accountRegistry()
20
+ * before a 2-tx join (a write-target pointer that updateAddresses can
21
+ * re-point — see src/commands/user/join.ts), and the claim-hats Multicall3
22
+ * probes (NoUsername / MAX_HATS_PER_MINT / HatOpenlyClaimable sentinel).
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.parseHatIds = parseHatIds;
26
+ exports.buildRegisterAccount = buildRegisterAccount;
27
+ exports.buildChangeUsername = buildChangeUsername;
28
+ exports.buildSetProfileMetadata = buildSetProfileMetadata;
29
+ exports.buildQuickJoinWithUser = buildQuickJoinWithUser;
30
+ exports.buildClaimHatsWithUser = buildClaimHatsWithUser;
31
+ exports.registerAccountIntent = registerAccountIntent;
32
+ exports.changeUsernameIntent = changeUsernameIntent;
33
+ exports.setProfileMetadataIntent = setProfileMetadataIntent;
34
+ exports.quickJoinWithUserIntent = quickJoinWithUserIntent;
35
+ exports.claimHatsWithUserIntent = claimHatsWithUserIntent;
36
+ const ethers_1 = require("ethers");
37
+ const contracts_1 = require("../contracts");
38
+ const ipfs_1 = require("../ipfs");
39
+ const encoding_1 = require("../encoding");
40
+ const validation_1 = require("../validation");
41
+ const chains_1 = require("../chains");
42
+ const errors_1 = require("../errors");
43
+ const exit_codes_1 = require("../exit-codes");
44
+ const infrastructure_1 = require("../graph/documents/infrastructure");
45
+ const user_1 = require("../metadata/user");
46
+ const resolve_1 = require("../reads/resolve");
47
+ const user_2 = require("../reads/user");
48
+ /**
49
+ * Parse a comma-separated hat-ID list into BigNumbers. Accepts decimal and
50
+ * 0x-hex forms. Hats Protocol IDs are uint256 — far beyond 2^53 — so
51
+ * parseInt/Number would silently corrupt them.
52
+ * Port of parseHatIds in `pop user claim-hats` —
53
+ * src/commands/user/claim-hats.ts (same messages and exit codes).
54
+ */
55
+ function parseHatIds(input) {
56
+ const parts = String(input).split(',').map(part => part.trim()).filter(part => part.length > 0);
57
+ if (parts.length === 0) {
58
+ throw new errors_1.CliError('No hat IDs given.', exit_codes_1.EXIT.USAGE, 'Pass --hats <id>[,<id>...] (see pop org roles for hat IDs).');
59
+ }
60
+ return parts.map(part => {
61
+ try {
62
+ return ethers_1.ethers.BigNumber.from(part);
63
+ }
64
+ catch {
65
+ throw new errors_1.CliError(`Invalid hat ID "${part}".`, exit_codes_1.EXIT.USAGE, 'Hat IDs are uint256 integers — pass them as decimal or 0x-hex strings (see pop org roles).');
66
+ }
67
+ });
68
+ }
69
+ /**
70
+ * Port of `pop user register` — src/commands/user/register.ts (also tx 1 of
71
+ * the 2-tx `pop user join` flow — src/commands/user/join.ts).
72
+ * UniversalAccountRegistry.registerAccount(string username); reverts
73
+ * UsernameTaken when the name is held. For the join flow, register on the
74
+ * SAME registry the org's QuickJoin consults (quickJoin.accountRegistry(),
75
+ * re-read live in the CLI) — registering anywhere else leaves
76
+ * quickJoinWithUser reverting NoUsername.
77
+ */
78
+ function buildRegisterAccount(a) {
79
+ return {
80
+ to: a.registryAddress,
81
+ abi: (0, contracts_1.getAbi)('UniversalAccountRegistry'),
82
+ method: 'registerAccount',
83
+ args: [a.username],
84
+ meta: {
85
+ domain: 'user',
86
+ action: 'register',
87
+ summary: { username: a.username, registry: a.registryAddress },
88
+ },
89
+ };
90
+ }
91
+ /**
92
+ * Port of `pop user update-profile --username` —
93
+ * src/commands/user/update-profile.ts.
94
+ * UniversalAccountRegistry.changeUsername(string newUsername) — DESTRUCTIVE:
95
+ * the old username is released for anyone to claim the moment the tx lands.
96
+ * Reverts AccountUnknown without an existing registration and UsernameTaken
97
+ * when the new name is held.
98
+ */
99
+ function buildChangeUsername(a) {
100
+ return {
101
+ to: a.registryAddress,
102
+ abi: (0, contracts_1.getAbi)('UniversalAccountRegistry'),
103
+ method: 'changeUsername',
104
+ args: [a.newUsername],
105
+ meta: {
106
+ domain: 'user',
107
+ action: 'change-username',
108
+ summary: { username: a.newUsername, registry: a.registryAddress },
109
+ },
110
+ };
111
+ }
112
+ /**
113
+ * Port of the metadata tx of `pop user update-profile` —
114
+ * src/commands/user/update-profile.ts.
115
+ * UniversalAccountRegistry.setProfileMetadata(bytes32 metadataHash), where
116
+ * metadataHash = ipfsCidToBytes32(pinJson(serialized profile document)).
117
+ */
118
+ function buildSetProfileMetadata(a) {
119
+ return {
120
+ to: a.registryAddress,
121
+ abi: (0, contracts_1.getAbi)('UniversalAccountRegistry'),
122
+ method: 'setProfileMetadata',
123
+ args: [a.metadataHash],
124
+ meta: {
125
+ domain: 'user',
126
+ action: 'set-profile-metadata',
127
+ summary: { metadataHash: a.metadataHash, registry: a.registryAddress },
128
+ },
129
+ };
130
+ }
131
+ /**
132
+ * Port of `pop user join` (the join tx) — src/commands/user/join.ts.
133
+ * QuickJoinNew.quickJoinWithUser() — NO arguments. The contract reads
134
+ * accountRegistry.getUsername(msg.sender) and reverts NoUsername when it is
135
+ * empty, so the sender must already hold a username on the registry this
136
+ * QuickJoin consults (register first via buildRegisterAccount when needed).
137
+ */
138
+ function buildQuickJoinWithUser(a) {
139
+ return {
140
+ to: a.quickJoinAddress,
141
+ abi: (0, contracts_1.getAbi)('QuickJoinNew'),
142
+ method: 'quickJoinWithUser',
143
+ args: [],
144
+ meta: {
145
+ domain: 'user',
146
+ action: 'join',
147
+ orgId: a.orgId,
148
+ summary: {},
149
+ },
150
+ };
151
+ }
152
+ /**
153
+ * Port of `pop user claim-hats` — src/commands/user/claim-hats.ts.
154
+ * QuickJoinNew.claimHatsWithUser(uint256[] claimHatIds). The caller must
155
+ * already have a username (reverts NoUsername); since audit H-03 QuickJoin
156
+ * refuses openly-claimable hats (reverts HatOpenlyClaimable), and the
157
+ * executor bounds the batch at MAX_HATS_PER_MINT.
158
+ */
159
+ function buildClaimHatsWithUser(a) {
160
+ return {
161
+ to: a.quickJoinAddress,
162
+ abi: (0, contracts_1.getAbi)('QuickJoinNew'),
163
+ method: 'claimHatsWithUser',
164
+ args: [a.hatIds],
165
+ meta: {
166
+ domain: 'user',
167
+ action: 'claim-hats',
168
+ orgId: a.orgId,
169
+ summary: { hatIds: a.hatIds.map(id => id.toString()).join(',') },
170
+ },
171
+ };
172
+ }
173
+ // ──────────────────────────── Level 2 — resolved ───────────────────────────
174
+ /** Validate a username with the CLI's wrapping (usage error, not a bare throw). */
175
+ function requireUsernameArg(username) {
176
+ try {
177
+ return (0, validation_1.requireValidUsername)(username);
178
+ }
179
+ catch (err) {
180
+ throw new errors_1.CliError(err.message, exit_codes_1.EXIT.USAGE);
181
+ }
182
+ }
183
+ /**
184
+ * Resolved builder for `pop user register` — src/commands/user/register.ts.
185
+ * Validates the username, resolves the UniversalAccountRegistry address from
186
+ * the infrastructure subgraph (universalAccountRegistries[0].id, falling back
187
+ * to poaManagerContracts[0].globalAccountRegistryProxy), then builds the
188
+ * registerAccount intent. Defaults to the HOME chain, deliberately ignoring
189
+ * ctx.chainId — usernames live on the home chain (the CLI ignores
190
+ * POP_DEFAULT_CHAIN the same way).
191
+ */
192
+ async function registerAccountIntent(ctx, params) {
193
+ const username = requireUsernameArg(params.username);
194
+ const chainId = params.chainId || chains_1.HOME_CHAIN_ID;
195
+ const infra = await ctx.client.query(infrastructure_1.FETCH_INFRASTRUCTURE_ADDRESSES, {}, chainId);
196
+ const registryAddr = infra.universalAccountRegistries?.[0]?.id
197
+ || infra.poaManagerContracts?.[0]?.globalAccountRegistryProxy;
198
+ if (!registryAddr) {
199
+ throw new errors_1.CliError('Could not resolve the UniversalAccountRegistry address from the subgraph.', exit_codes_1.EXIT.INFRA, 'The subgraph may be syncing — retry shortly, or pass --chain for a chain with a deployed registry.');
200
+ }
201
+ return buildRegisterAccount({ registryAddress: registryAddr, username });
202
+ }
203
+ /**
204
+ * Resolved builder for the username tx of `pop user update-profile` —
205
+ * src/commands/user/update-profile.ts. DESTRUCTIVE: the old username is
206
+ * released on-chain for anyone to claim. Resolves the registry from the same
207
+ * one-round-trip document the CLI uses. The CLI's AccountUnknown /
208
+ * UsernameTaken / no-op-rename predictions are preflight and are not ported.
209
+ */
210
+ async function changeUsernameIntent(ctx, params) {
211
+ const newUsername = requireUsernameArg(params.newUsername);
212
+ const chainId = params.chainId ?? chains_1.HOME_CHAIN_ID;
213
+ const { registryAddress } = await (0, user_2.getRegistryAndAccount)(ctx.client, params.address, chainId);
214
+ if (!registryAddress) {
215
+ throw new errors_1.CliError('UniversalAccountRegistry not found on this chain.', exit_codes_1.EXIT.INFRA, 'The subgraph may be syncing — retry shortly.');
216
+ }
217
+ return buildChangeUsername({ registryAddress, newUsername });
218
+ }
219
+ /**
220
+ * Resolved builder for the metadata tx of `pop user update-profile` —
221
+ * src/commands/user/update-profile.ts. Reads the existing indexed profile
222
+ * metadata (read-then-merge, so single-field edits preserve the others),
223
+ * builds the {bio, avatar, github, twitter, website} document with the CLI's
224
+ * exact conditional key order, pins it to IPFS, converts the CID to bytes32,
225
+ * and builds the setProfileMetadata intent.
226
+ */
227
+ async function setProfileMetadataIntent(ctx, params) {
228
+ const updates = {
229
+ bio: params.bio,
230
+ avatar: params.avatar,
231
+ github: params.github,
232
+ twitter: params.twitter,
233
+ website: params.website,
234
+ };
235
+ if (!user_1.USER_PROFILE_FIELDS.some(field => updates[field] !== undefined)) {
236
+ throw new errors_1.CliError('Provide at least one field: --bio, --avatar, --github, --twitter, --website', exit_codes_1.EXIT.USAGE);
237
+ }
238
+ const chainId = params.chainId ?? chains_1.HOME_CHAIN_ID;
239
+ const { registryAddress, account } = await (0, user_2.getRegistryAndAccount)(ctx.client, params.address, chainId);
240
+ if (!registryAddress) {
241
+ throw new errors_1.CliError('UniversalAccountRegistry not found on this chain.', exit_codes_1.EXIT.INFRA, 'The subgraph may be syncing — retry shortly.');
242
+ }
243
+ // Merge over the indexed metadata exactly as the CLI does
244
+ // (indexed.account?.metadata || {} — no authority gating on the merge read).
245
+ const metadata = (0, user_1.buildUserProfileMetadata)(updates, account?.metadata ?? {});
246
+ const cid = await (0, ipfs_1.pinJson)((0, user_1.serializeUserProfileMetadata)(metadata), ctx.ipfs);
247
+ const metadataHash = (0, encoding_1.ipfsCidToBytes32)(cid);
248
+ const intent = buildSetProfileMetadata({ registryAddress, metadataHash });
249
+ intent.meta.ipfs = { cid, metadata };
250
+ return intent;
251
+ }
252
+ /**
253
+ * Resolved builder for `pop user join` (join tx only) —
254
+ * src/commands/user/join.ts. Resolves the org's QuickJoin via the subgraph
255
+ * and builds the quickJoinWithUser intent. The 1-tx vs 2-tx decision (does
256
+ * the sender already hold a username on the registry this QuickJoin
257
+ * consults?) is host orchestration: read state with
258
+ * reads/user.getQuickJoinAccount, re-verify the registry pointer LIVE
259
+ * (quickJoin.accountRegistry() — it is a write target updateAddresses can
260
+ * re-point), and when registration is needed send buildRegisterAccount
261
+ * against THAT registry first.
262
+ */
263
+ async function quickJoinWithUserIntent(ctx, params) {
264
+ const modules = await (0, resolve_1.resolveOrgModules)(ctx.client, params.org, ctx.chainId);
265
+ const quickJoinAddress = (0, resolve_1.requireModule)(modules, 'quickJoinAddress');
266
+ return buildQuickJoinWithUser({ quickJoinAddress, orgId: modules.orgId });
267
+ }
268
+ /**
269
+ * Resolved builder for `pop user claim-hats` —
270
+ * src/commands/user/claim-hats.ts. Parses hat IDs with BigNumber (uint256 —
271
+ * never parseInt), resolves the org's QuickJoin via the subgraph, and builds
272
+ * the claimHatsWithUser intent. The CLI's Multicall3 preflight (NoUsername /
273
+ * batch cap / open-hat sentinel probes) stays in the CLI.
274
+ */
275
+ async function claimHatsWithUserIntent(ctx, params) {
276
+ const hatIds = typeof params.hats === 'string'
277
+ ? parseHatIds(params.hats)
278
+ : params.hats.map(part => {
279
+ try {
280
+ return ethers_1.ethers.BigNumber.from(part);
281
+ }
282
+ catch {
283
+ throw new errors_1.CliError(`Invalid hat ID "${part}".`, exit_codes_1.EXIT.USAGE, 'Hat IDs are uint256 integers — pass them as decimal or 0x-hex strings (see pop org roles).');
284
+ }
285
+ });
286
+ if (hatIds.length === 0) {
287
+ throw new errors_1.CliError('No hat IDs given.', exit_codes_1.EXIT.USAGE, 'Pass --hats <id>[,<id>...] (see pop org roles for hat IDs).');
288
+ }
289
+ const modules = await (0, resolve_1.resolveOrgModules)(ctx.client, params.org, ctx.chainId);
290
+ const quickJoinAddress = (0, resolve_1.requireModule)(modules, 'quickJoinAddress');
291
+ return buildClaimHatsWithUser({ quickJoinAddress, hatIds, orgId: modules.orgId });
292
+ }