@capxul/mcp 1.2.2 → 2.0.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.
- package/README.md +3 -5
- package/dist/{_esm-CC5QpzeQ.mjs → _esm-BJMBPEEJ.mjs} +113 -113
- package/dist/{chunk-B5meny8j.mjs → chunk-2rV9d50f.mjs} +1 -2
- package/dist/{eventemitter3-D-pLUuAN.mjs → eventemitter3-BAR9woZ4.mjs} +1 -1
- package/dist/{lib-Dn7-RQTV.mjs → lib-6VZsqqnl.mjs} +3 -3
- package/dist/{lib-CifIgXqP.mjs → lib-BPNIfCSS.mjs} +5 -5
- package/dist/{lib-BRkcywUv.mjs → lib-BuBlVXhu.mjs} +1 -1
- package/dist/lib-CMLhJW3x.mjs +3 -0
- package/dist/{lib-CnLS6gjn.mjs → lib-CQ44Cugp.mjs} +4 -4
- package/dist/lib-CQVjg2KA.mjs +3 -0
- package/dist/{lib-hCYuvdcy.mjs → lib-CQ_IHsde.mjs} +4 -4
- package/dist/lib-Cs29vVRx.mjs +3 -0
- package/dist/{lib-cc_08w0f.mjs → lib-DY_aksO0.mjs} +5 -5
- package/dist/{lib-B8hqwgiz.mjs → lib-DYnihSM4.mjs} +2 -2
- package/dist/lib-S7tWZSeq.mjs +3 -0
- package/dist/main.mjs +3554 -3854
- package/package.json +9 -11
- package/dist/alchemy-rpc-BuobS4-x.mjs +0 -2
- package/dist/alchemy-rpc-vGO5qErZ.mjs +0 -343
- package/dist/lib-BGlYlc2Y.mjs +0 -3
- package/dist/lib-BSq2-y-R.mjs +0 -3
- package/dist/lib-YbuuWTqT.mjs +0 -3
- package/dist/lib-yehPdjuB.mjs +0 -3
- package/dist/src-2B8HO-zu.mjs +0 -2244
- package/dist/src-HgvNZjX7.mjs +0 -2
- package/dist/src-Iv70gRG_.mjs +0 -10639
package/dist/src-2B8HO-zu.mjs
DELETED
|
@@ -1,2244 +0,0 @@
|
|
|
1
|
-
import { concat, encodeAbiParameters, encodeFunctionData, encodePacked, getContractAddress, hashTypedData, isAddress, keccak256, pad, padHex, parseAbiParameters, stringToHex, toBytes, toEventSelector, toFunctionSelector, toHex } from "viem";
|
|
2
|
-
//#region ../../packages/errors/src/errors.ts
|
|
3
|
-
const CAPXUL_ERROR_CODES = [
|
|
4
|
-
"NOT_AUTHENTICATED",
|
|
5
|
-
"EMAIL_DELIVERY_FAILED",
|
|
6
|
-
"PROFILE_NOT_FOUND",
|
|
7
|
-
"SMART_ACCOUNT_MISSING",
|
|
8
|
-
"PLAYER_NOT_FOUND",
|
|
9
|
-
"ACCOUNT_NOT_FOUND",
|
|
10
|
-
"PROVIDER_ERROR",
|
|
11
|
-
"INVALID_INPUT",
|
|
12
|
-
"ENV_MISSING",
|
|
13
|
-
"NOT_IMPLEMENTED",
|
|
14
|
-
"VERIFICATION_REQUIRED",
|
|
15
|
-
"INSUFFICIENT_BALANCE",
|
|
16
|
-
"INVALID_RECIPIENT",
|
|
17
|
-
"ROLE_PERMISSION_DENIED",
|
|
18
|
-
"TRANSACTION_FAILED",
|
|
19
|
-
"RATE_LIMITED",
|
|
20
|
-
"NETWORK_ERROR",
|
|
21
|
-
"UNKNOWN",
|
|
22
|
-
"OTP_EXPIRED",
|
|
23
|
-
"SIGNER_REJECTED",
|
|
24
|
-
"CANCELLED",
|
|
25
|
-
"WRONG_STATE",
|
|
26
|
-
"STALE_EPOCH",
|
|
27
|
-
"SUPERSEDED",
|
|
28
|
-
"WORK_DIED",
|
|
29
|
-
"ACTOR_STOPPED"
|
|
30
|
-
];
|
|
31
|
-
/**
|
|
32
|
-
* The error codes that represent an expected product outcome rather than a
|
|
33
|
-
* defect. The SDK and backend observation boundaries both classify failures
|
|
34
|
-
* against this set to route expected outcomes to their own PostHog event
|
|
35
|
-
* stream; keeping the single copy here (adjacent to `CAPXUL_ERROR_CODES`, so a
|
|
36
|
-
* code rename forces this set to move with it) stops the two sides of the wire
|
|
37
|
-
* from drifting and silently splitting one outcome across two streams.
|
|
38
|
-
*/
|
|
39
|
-
const EXPECTED_OPERATION_OUTCOMES = new Set([
|
|
40
|
-
"INVALID_INPUT",
|
|
41
|
-
"NOT_AUTHENTICATED",
|
|
42
|
-
"SMART_ACCOUNT_MISSING",
|
|
43
|
-
"CANCELLED",
|
|
44
|
-
"SIGNER_REJECTED",
|
|
45
|
-
"VERIFICATION_REQUIRED",
|
|
46
|
-
"INSUFFICIENT_BALANCE",
|
|
47
|
-
"INVALID_RECIPIENT",
|
|
48
|
-
"ROLE_PERMISSION_DENIED",
|
|
49
|
-
"RATE_LIMITED",
|
|
50
|
-
"OTP_EXPIRED",
|
|
51
|
-
"WRONG_STATE",
|
|
52
|
-
"STALE_EPOCH",
|
|
53
|
-
"SUPERSEDED",
|
|
54
|
-
"ACTOR_STOPPED"
|
|
55
|
-
]);
|
|
56
|
-
var CapxulError = class extends Error {
|
|
57
|
-
code;
|
|
58
|
-
details;
|
|
59
|
-
correlationId;
|
|
60
|
-
layer;
|
|
61
|
-
constructor(code, message, options = {}) {
|
|
62
|
-
super(message, "cause" in options ? { cause: options.cause } : void 0);
|
|
63
|
-
this.name = "CapxulError";
|
|
64
|
-
this.code = code;
|
|
65
|
-
if (options.details !== void 0) this.details = options.details;
|
|
66
|
-
if (options.correlationId !== void 0) this.correlationId = options.correlationId;
|
|
67
|
-
if (options.layer !== void 0) this.layer = options.layer;
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
function isCapxulError(value) {
|
|
71
|
-
return value instanceof CapxulError;
|
|
72
|
-
}
|
|
73
|
-
function deserializeCapxulError(serialized) {
|
|
74
|
-
return new CapxulError(serialized.code, serialized.message, compactErrorOptions({
|
|
75
|
-
details: serialized.details,
|
|
76
|
-
correlationId: serialized.correlationId,
|
|
77
|
-
layer: serialized.layer
|
|
78
|
-
}));
|
|
79
|
-
}
|
|
80
|
-
function compactErrorOptions(options) {
|
|
81
|
-
const result = {};
|
|
82
|
-
if ("cause" in options) result.cause = options.cause;
|
|
83
|
-
if (options.details !== void 0) result.details = options.details;
|
|
84
|
-
if (options.correlationId !== void 0) result.correlationId = options.correlationId;
|
|
85
|
-
if (options.layer !== void 0) result.layer = options.layer;
|
|
86
|
-
return result;
|
|
87
|
-
}
|
|
88
|
-
const Errors = {
|
|
89
|
-
notAuthenticated: (message, opts) => new CapxulError("NOT_AUTHENTICATED", message ?? "Not authenticated", opts?.failure_mode ? { details: { failure_mode: opts.failure_mode } } : void 0),
|
|
90
|
-
emailDeliveryFailed: (detail) => new CapxulError("EMAIL_DELIVERY_FAILED", "Failed to send email", { details: { detail } }),
|
|
91
|
-
profileNotFound: (authUserId) => new CapxulError("PROFILE_NOT_FOUND", `Profile not found for user ${authUserId}`, { details: { authUserId } }),
|
|
92
|
-
smartAccountMissing: (authUserId) => new CapxulError("SMART_ACCOUNT_MISSING", "Smart account not provisioned", { details: { authUserId } }),
|
|
93
|
-
playerNotFound: (playerId) => new CapxulError("PLAYER_NOT_FOUND", playerId ? `Openfort player ${playerId} not found` : "Openfort player not found", playerId === void 0 ? void 0 : { details: { playerId } }),
|
|
94
|
-
accountNotFound: (accountId) => new CapxulError("ACCOUNT_NOT_FOUND", accountId ? `Openfort account ${accountId} not found` : "Openfort account not found", accountId === void 0 ? void 0 : { details: { accountId } }),
|
|
95
|
-
providerError: (provider, operation, cause, opts) => {
|
|
96
|
-
const details = {
|
|
97
|
-
provider,
|
|
98
|
-
operation
|
|
99
|
-
};
|
|
100
|
-
if (opts?.failure_mode) details.failure_mode = opts.failure_mode;
|
|
101
|
-
return new CapxulError("PROVIDER_ERROR", `Provider error: ${provider} ${operation}`, {
|
|
102
|
-
cause,
|
|
103
|
-
details
|
|
104
|
-
});
|
|
105
|
-
},
|
|
106
|
-
invalidInput: (field, reason) => new CapxulError("INVALID_INPUT", `Invalid ${field}: ${reason}`, { details: {
|
|
107
|
-
field,
|
|
108
|
-
reason
|
|
109
|
-
} }),
|
|
110
|
-
envMissing: (name) => new CapxulError("ENV_MISSING", `Environment variable ${name} not configured`, { details: { name } }),
|
|
111
|
-
notImplemented: (domain, method) => new CapxulError("NOT_IMPLEMENTED", `${domain}.${method} is not yet implemented. This feature is planned for a future release.`, { details: {
|
|
112
|
-
domain,
|
|
113
|
-
method
|
|
114
|
-
} }),
|
|
115
|
-
/**
|
|
116
|
-
* Sibling factory to {@link Errors.providerError} for the per-state timeout
|
|
117
|
-
* path in flows. Same `PROVIDER_ERROR` code as
|
|
118
|
-
* `providerError`, plus a `details.reason: "timeout"` discriminator so
|
|
119
|
-
* downstream observers can distinguish failure modes without parsing the
|
|
120
|
-
* message string. The redacted message names the timeout budget; the
|
|
121
|
-
* native `cause` carries the same information for `reportError` fidelity.
|
|
122
|
-
*/
|
|
123
|
-
providerTimeout: (provider, operation, timeoutMs) => new CapxulError("PROVIDER_ERROR", `Provider error: ${provider} ${operation} (timeout exceeded ${timeoutMs}ms)`, {
|
|
124
|
-
details: {
|
|
125
|
-
provider,
|
|
126
|
-
operation,
|
|
127
|
-
reason: "timeout"
|
|
128
|
-
},
|
|
129
|
-
cause: /* @__PURE__ */ new Error(`timeout: ${operation} exceeded ${timeoutMs}ms`)
|
|
130
|
-
}),
|
|
131
|
-
verificationRequired: (details) => {
|
|
132
|
-
return new CapxulError("VERIFICATION_REQUIRED", "rail" in details ? `Verification is required before ${details.rail} can use ${details.currentKind}.` : `Verification tier ${details.requiredTier} is required.`, { details });
|
|
133
|
-
},
|
|
134
|
-
insufficientBalance: (asset, available, required) => new CapxulError("INSUFFICIENT_BALANCE", `Insufficient ${asset} balance`, { details: {
|
|
135
|
-
asset,
|
|
136
|
-
available,
|
|
137
|
-
required
|
|
138
|
-
} }),
|
|
139
|
-
invalidRecipient: (reason) => new CapxulError("INVALID_RECIPIENT", `Invalid recipient: ${reason}`, { details: { reason } }),
|
|
140
|
-
/**
|
|
141
|
-
* The org Zodiac Roles modifier REFUSED the spend on-chain (G4 · #547): the
|
|
142
|
-
* member's role condition (per-tx cap, per-day allowance, allowed recipient,
|
|
143
|
-
* or membership) was violated, so `execTransactionWithRole` reverted. This is
|
|
144
|
-
* a PERMISSION denial — explicitly NOT an `INSUFFICIENT_BALANCE` (the treasury
|
|
145
|
-
* held the funds; the role's authority is what bound). `reason` discriminates
|
|
146
|
-
* the violated condition (`over_cap` / `daily_cap` / `not_member` /
|
|
147
|
-
* `disallowed_recipient` / `condition_violation`); leak-safe — no on-chain
|
|
148
|
-
* identifiers ever enter the details.
|
|
149
|
-
*/
|
|
150
|
-
rolePermissionDenied: (details) => new CapxulError("ROLE_PERMISSION_DENIED", `Org role denied this spend on-chain (${details.reason}).`, { details: details.operation === void 0 ? { reason: details.reason } : {
|
|
151
|
-
reason: details.reason,
|
|
152
|
-
operation: details.operation
|
|
153
|
-
} }),
|
|
154
|
-
/**
|
|
155
|
-
* A transaction (or sponsored UserOp) failed. `details.reason` discriminates
|
|
156
|
-
* the failure mode for callers that must distinguish a CONFIRMED on-chain
|
|
157
|
-
* revert (`"onchain_revert"` — the op executed and reverted, e.g. a Zodiac
|
|
158
|
-
* Roles condition violation) from an inconclusive infra failure. A confirmed
|
|
159
|
-
* revert is the ONLY mode the org spend port may map to a roles denial.
|
|
160
|
-
*/
|
|
161
|
-
transactionFailed: (operation, cause, extra) => new CapxulError("TRANSACTION_FAILED", `Transaction failed: ${operation}`, {
|
|
162
|
-
cause,
|
|
163
|
-
details: extra?.reason === void 0 ? { operation } : {
|
|
164
|
-
operation,
|
|
165
|
-
reason: extra.reason
|
|
166
|
-
}
|
|
167
|
-
}),
|
|
168
|
-
rateLimited: (details) => new CapxulError("RATE_LIMITED", "Rate limit exceeded", details === void 0 ? void 0 : { details: { ...details } }),
|
|
169
|
-
networkError: (operation, cause) => new CapxulError("NETWORK_ERROR", `Network error during ${operation}`, {
|
|
170
|
-
cause,
|
|
171
|
-
details: { operation }
|
|
172
|
-
}),
|
|
173
|
-
unknown: (cause) => new CapxulError("UNKNOWN", "Unknown error", { cause }),
|
|
174
|
-
otpExpired: (details) => new CapxulError("OTP_EXPIRED", "Verification code has expired. Request a new one.", details === void 0 ? void 0 : { details: { ...details } }),
|
|
175
|
-
signerRejected: (details) => new CapxulError("SIGNER_REJECTED", "Signer rejected the request.", {
|
|
176
|
-
cause: details.cause,
|
|
177
|
-
details: details.reason === void 0 ? { source: details.source } : {
|
|
178
|
-
source: details.source,
|
|
179
|
-
reason: details.reason
|
|
180
|
-
}
|
|
181
|
-
}),
|
|
182
|
-
cancelled: (details) => new CapxulError("CANCELLED", "Operation was cancelled.", details === void 0 ? void 0 : { details: { ...details } }),
|
|
183
|
-
/**
|
|
184
|
-
* Method called from a flow state where its precondition fails (TA16). The
|
|
185
|
-
* SDK's method API short-circuits with this error before driving the
|
|
186
|
-
* internal state machine. `currentState` is the Effect-machine snapshot
|
|
187
|
-
* tag (stringified from the SDK's actor-shell snapshot; see
|
|
188
|
-
* `packages/errors/CONTEXT.md`); `validStates`
|
|
189
|
-
* enumerates the states the method accepts.
|
|
190
|
-
*/
|
|
191
|
-
wrongState: (details) => new CapxulError("WRONG_STATE", `${details.method} called from state '${details.currentState}'; valid states: ${details.validStates.join(", ")}`, { details: {
|
|
192
|
-
...details,
|
|
193
|
-
validStates: [...details.validStates]
|
|
194
|
-
} })
|
|
195
|
-
};
|
|
196
|
-
//#endregion
|
|
197
|
-
//#region ../../packages/errors/src/convex-error-decoding.ts
|
|
198
|
-
const KNOWN_CODES = new Set(CAPXUL_ERROR_CODES);
|
|
199
|
-
function isCapxulCode(value) {
|
|
200
|
-
return typeof value === "string" && KNOWN_CODES.has(value);
|
|
201
|
-
}
|
|
202
|
-
function reconstruct(serialized) {
|
|
203
|
-
if (!isCapxulCode(serialized.code)) return null;
|
|
204
|
-
return deserializeCapxulError({
|
|
205
|
-
code: serialized.code,
|
|
206
|
-
message: typeof serialized.message === "string" ? serialized.message : String(serialized.code),
|
|
207
|
-
...typeof serialized.details === "object" && serialized.details !== null && !Array.isArray(serialized.details) ? { details: serialized.details } : {},
|
|
208
|
-
...typeof serialized.correlationId === "string" ? { correlationId: serialized.correlationId } : {},
|
|
209
|
-
...typeof serialized.layer === "string" ? { layer: serialized.layer } : {}
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
function decodeConvexError(err) {
|
|
213
|
-
if (err === null || err === void 0) return null;
|
|
214
|
-
if (err instanceof CapxulError) return err;
|
|
215
|
-
if (typeof err !== "object") return null;
|
|
216
|
-
const record = err;
|
|
217
|
-
if (!("data" in record)) return null;
|
|
218
|
-
const data = record.data;
|
|
219
|
-
if (typeof data === "object" && data !== null) return reconstruct(data);
|
|
220
|
-
if (typeof data === "string") try {
|
|
221
|
-
const parsed = JSON.parse(data);
|
|
222
|
-
if (typeof parsed === "object" && parsed !== null) return reconstruct(parsed);
|
|
223
|
-
} catch {}
|
|
224
|
-
return null;
|
|
225
|
-
}
|
|
226
|
-
//#endregion
|
|
227
|
-
//#region ../../packages/config/src/tokens.ts
|
|
228
|
-
/** `TestUSDC` ("USDX") — Base Sepolia, 6 decimals, open `mint`. (Canon §1.) */
|
|
229
|
-
const USDX_ADDRESS_BASE_SEPOLIA = "0xf09fcbb6df9f8f918e58f9c8ab15a76ade862b77";
|
|
230
|
-
/**
|
|
231
|
-
* Exact-transfer token allowlist (#536 / G2 HITL gate): the only ERC-20s the
|
|
232
|
-
* `CapxulPayments` adapter may move via `send(token, …)`. v1 permits USDX on
|
|
233
|
-
* Base Sepolia only. Enforced BEFORE any execute so a tainted or fuzzy token
|
|
234
|
-
* address can never be transferred — the allowlist is the policy boundary, not
|
|
235
|
-
* the caller's input. Lowercased for case-insensitive comparison.
|
|
236
|
-
*/
|
|
237
|
-
const EXACT_TRANSFER_TOKEN_ALLOWLIST = [USDX_ADDRESS_BASE_SEPOLIA.toLowerCase()];
|
|
238
|
-
/** True iff `tokenAddress` is on the exact-transfer allowlist (case-insensitive). */
|
|
239
|
-
function isExactTransferTokenAllowed(tokenAddress) {
|
|
240
|
-
return EXACT_TRANSFER_TOKEN_ALLOWLIST.includes(tokenAddress.toLowerCase());
|
|
241
|
-
}
|
|
242
|
-
//#endregion
|
|
243
|
-
//#region ../../packages/config/src/org-payments.ts
|
|
244
|
-
/** Zodiac MultiSendCallOnly module on Base Sepolia. */
|
|
245
|
-
const MULTI_SEND_CALL_ONLY = "0x9641d764fc13c8b624c04430c7356c1c7c8102e2";
|
|
246
|
-
/** Zodiac Roles v2 mastercopy on Base Sepolia. */
|
|
247
|
-
const ROLES_MASTERCOPY = "0x9646fdad06d3e24444381f44362a3b0eb343d337";
|
|
248
|
-
/** Zodiac ModuleProxyFactory on Base Sepolia. */
|
|
249
|
-
const ZODIAC_MODULE_PROXY_FACTORY = "0x000000000000addb49795b0f9ba5bc298cdda236";
|
|
250
|
-
/** Zodiac MultiSend unwrapper on Base Sepolia. */
|
|
251
|
-
const ZODIAC_MULTI_SEND_UNWRAPPER = "0x93b7fcbc63ed8a3a24b59e1c3e6649d50b7427c0";
|
|
252
|
-
/** CapxulPayments proxy on Base Sepolia. */
|
|
253
|
-
const CAPXUL_PAYMENTS_ADDRESS = "0xe740ea65521edc9bef0ea75d30b5334711db99f4";
|
|
254
|
-
const CAPXUL_PAYMENTS_SEND_ABI = [{
|
|
255
|
-
type: "function",
|
|
256
|
-
name: "send",
|
|
257
|
-
stateMutability: "nonpayable",
|
|
258
|
-
inputs: [
|
|
259
|
-
{
|
|
260
|
-
name: "token",
|
|
261
|
-
type: "address"
|
|
262
|
-
},
|
|
263
|
-
{
|
|
264
|
-
name: "recipient",
|
|
265
|
-
type: "address"
|
|
266
|
-
},
|
|
267
|
-
{
|
|
268
|
-
name: "amount",
|
|
269
|
-
type: "uint256"
|
|
270
|
-
},
|
|
271
|
-
{
|
|
272
|
-
name: "documentHash",
|
|
273
|
-
type: "bytes32"
|
|
274
|
-
},
|
|
275
|
-
{
|
|
276
|
-
name: "paymentType",
|
|
277
|
-
type: "uint8"
|
|
278
|
-
}
|
|
279
|
-
],
|
|
280
|
-
outputs: []
|
|
281
|
-
}];
|
|
282
|
-
const ERC20_APPROVE_ABI = [{
|
|
283
|
-
type: "function",
|
|
284
|
-
name: "approve",
|
|
285
|
-
stateMutability: "nonpayable",
|
|
286
|
-
inputs: [{
|
|
287
|
-
name: "spender",
|
|
288
|
-
type: "address"
|
|
289
|
-
}, {
|
|
290
|
-
name: "amount",
|
|
291
|
-
type: "uint256"
|
|
292
|
-
}],
|
|
293
|
-
outputs: [{
|
|
294
|
-
name: "",
|
|
295
|
-
type: "bool"
|
|
296
|
-
}]
|
|
297
|
-
}];
|
|
298
|
-
const MULTI_SEND_CALL_ONLY_ABI = [{
|
|
299
|
-
type: "function",
|
|
300
|
-
name: "multiSend",
|
|
301
|
-
stateMutability: "payable",
|
|
302
|
-
inputs: [{
|
|
303
|
-
name: "transactions",
|
|
304
|
-
type: "bytes"
|
|
305
|
-
}],
|
|
306
|
-
outputs: []
|
|
307
|
-
}];
|
|
308
|
-
const ROLES_EXEC_TRANSACTION_WITH_ROLE_ABI$1 = [{
|
|
309
|
-
type: "function",
|
|
310
|
-
name: "execTransactionWithRole",
|
|
311
|
-
stateMutability: "nonpayable",
|
|
312
|
-
inputs: [
|
|
313
|
-
{
|
|
314
|
-
name: "to",
|
|
315
|
-
type: "address"
|
|
316
|
-
},
|
|
317
|
-
{
|
|
318
|
-
name: "value",
|
|
319
|
-
type: "uint256"
|
|
320
|
-
},
|
|
321
|
-
{
|
|
322
|
-
name: "data",
|
|
323
|
-
type: "bytes"
|
|
324
|
-
},
|
|
325
|
-
{
|
|
326
|
-
name: "operation",
|
|
327
|
-
type: "uint8"
|
|
328
|
-
},
|
|
329
|
-
{
|
|
330
|
-
name: "roleKey",
|
|
331
|
-
type: "bytes32"
|
|
332
|
-
},
|
|
333
|
-
{
|
|
334
|
-
name: "shouldRevert",
|
|
335
|
-
type: "bool"
|
|
336
|
-
}
|
|
337
|
-
],
|
|
338
|
-
outputs: [{
|
|
339
|
-
name: "success",
|
|
340
|
-
type: "bool"
|
|
341
|
-
}]
|
|
342
|
-
}];
|
|
343
|
-
const SAFE4337_EXECUTE_USEROP_ABI = [{
|
|
344
|
-
type: "function",
|
|
345
|
-
name: "executeUserOpWithErrorString",
|
|
346
|
-
stateMutability: "nonpayable",
|
|
347
|
-
inputs: [
|
|
348
|
-
{
|
|
349
|
-
name: "to",
|
|
350
|
-
type: "address"
|
|
351
|
-
},
|
|
352
|
-
{
|
|
353
|
-
name: "value",
|
|
354
|
-
type: "uint256"
|
|
355
|
-
},
|
|
356
|
-
{
|
|
357
|
-
name: "data",
|
|
358
|
-
type: "bytes"
|
|
359
|
-
},
|
|
360
|
-
{
|
|
361
|
-
name: "operation",
|
|
362
|
-
type: "uint8"
|
|
363
|
-
}
|
|
364
|
-
],
|
|
365
|
-
outputs: []
|
|
366
|
-
}];
|
|
367
|
-
const OPERATION_CALL = 0;
|
|
368
|
-
const OPERATION_DELEGATECALL = 1;
|
|
369
|
-
const BYTES32_RE = /^0x[0-9a-fA-F]{64}$/;
|
|
370
|
-
function normalizeAddress(address, field) {
|
|
371
|
-
if (!isAddress(address)) throw new RangeError(`${field} must be a valid EVM address`);
|
|
372
|
-
return address.toLowerCase();
|
|
373
|
-
}
|
|
374
|
-
function normalizeBytes32(value, field) {
|
|
375
|
-
if (!BYTES32_RE.test(value)) throw new RangeError(`${field} must be a 32-byte 0x-prefixed hex string`);
|
|
376
|
-
return value.toLowerCase();
|
|
377
|
-
}
|
|
378
|
-
function normalizeUint8(value, field) {
|
|
379
|
-
if (!Number.isInteger(value) || value < 0 || value > 255) throw new RangeError(`${field} must be an integer between 0 and 255`);
|
|
380
|
-
return value;
|
|
381
|
-
}
|
|
382
|
-
function normalizePositiveAmount(value, field) {
|
|
383
|
-
if (value <= 0n) throw new RangeError(`${field} must be positive`);
|
|
384
|
-
return value;
|
|
385
|
-
}
|
|
386
|
-
function buildCapxulPaymentsSendCalls(input) {
|
|
387
|
-
const tokenAddress = normalizeAddress(input.tokenAddress, "tokenAddress");
|
|
388
|
-
const recipientAddress = normalizeAddress(input.recipientAddress, "recipientAddress");
|
|
389
|
-
const amount = normalizePositiveAmount(input.amount, "amount");
|
|
390
|
-
const documentHash = normalizeBytes32(input.documentHash ?? `0x${"0".repeat(64)}`, "documentHash");
|
|
391
|
-
const paymentType = normalizeUint8(input.paymentType ?? 0, "paymentType");
|
|
392
|
-
return [{
|
|
393
|
-
to: tokenAddress,
|
|
394
|
-
data: encodeFunctionData({
|
|
395
|
-
abi: ERC20_APPROVE_ABI,
|
|
396
|
-
functionName: "approve",
|
|
397
|
-
args: [CAPXUL_PAYMENTS_ADDRESS, amount]
|
|
398
|
-
}),
|
|
399
|
-
value: 0n
|
|
400
|
-
}, {
|
|
401
|
-
to: CAPXUL_PAYMENTS_ADDRESS,
|
|
402
|
-
data: encodeFunctionData({
|
|
403
|
-
abi: CAPXUL_PAYMENTS_SEND_ABI,
|
|
404
|
-
functionName: "send",
|
|
405
|
-
args: [
|
|
406
|
-
tokenAddress,
|
|
407
|
-
recipientAddress,
|
|
408
|
-
amount,
|
|
409
|
-
documentHash,
|
|
410
|
-
paymentType
|
|
411
|
-
]
|
|
412
|
-
}),
|
|
413
|
-
value: 0n
|
|
414
|
-
}];
|
|
415
|
-
}
|
|
416
|
-
function buildCapxulCreateCommitmentCalls(input) {
|
|
417
|
-
const tokenAddress = normalizeAddress(input.tokenAddress, "tokenAddress");
|
|
418
|
-
const recipientAddress = normalizeAddress(input.recipientAddress, "recipientAddress");
|
|
419
|
-
const totalAmount = normalizePositiveAmount(input.totalAmount, "totalAmount");
|
|
420
|
-
const startTime = normalizeUint48(input.startTime, "startTime");
|
|
421
|
-
const cliffTime = normalizeUint48(input.cliffTime, "cliffTime");
|
|
422
|
-
const endTime = normalizeUint48(input.endTime, "endTime");
|
|
423
|
-
if (startTime > endTime || cliffTime < startTime || cliffTime > endTime) throw new RangeError("commitment times must satisfy start <= cliff <= end");
|
|
424
|
-
const documentHash = normalizeBytes32(input.documentHash ?? `0x${"0".repeat(64)}`, "documentHash");
|
|
425
|
-
const paymentType = normalizeUint8(input.paymentType ?? 0, "paymentType");
|
|
426
|
-
return [{
|
|
427
|
-
to: tokenAddress,
|
|
428
|
-
data: encodeFunctionData({
|
|
429
|
-
abi: ERC20_APPROVE_ABI,
|
|
430
|
-
functionName: "approve",
|
|
431
|
-
args: [CAPXUL_PAYMENTS_ADDRESS, totalAmount]
|
|
432
|
-
}),
|
|
433
|
-
value: 0n
|
|
434
|
-
}, {
|
|
435
|
-
to: CAPXUL_PAYMENTS_ADDRESS,
|
|
436
|
-
data: encodeFunctionData({
|
|
437
|
-
abi: CAPXUL_PAYMENTS_COMMITMENT_ABI,
|
|
438
|
-
functionName: "createCommitment",
|
|
439
|
-
args: [
|
|
440
|
-
tokenAddress,
|
|
441
|
-
recipientAddress,
|
|
442
|
-
totalAmount,
|
|
443
|
-
startTime,
|
|
444
|
-
cliffTime,
|
|
445
|
-
endTime,
|
|
446
|
-
documentHash,
|
|
447
|
-
paymentType
|
|
448
|
-
]
|
|
449
|
-
}),
|
|
450
|
-
value: 0n
|
|
451
|
-
}];
|
|
452
|
-
}
|
|
453
|
-
/**
|
|
454
|
-
* Wrap an org Roles `execTransactionWithRole` call (from `*RoleSpendCall` /
|
|
455
|
-
* `*RoleBatchSpendCall`) into the member Safe's `executeUserOpWithErrorString`
|
|
456
|
-
* (operation = CALL into the Roles module) — the full Safe callData a sponsored
|
|
457
|
-
* UserOp from the member's personal Safe carries (G4 · #547).
|
|
458
|
-
*/
|
|
459
|
-
function buildOrgRoleSpendPersonalCallData(roleSpendCall) {
|
|
460
|
-
return encodeFunctionData({
|
|
461
|
-
abi: SAFE4337_EXECUTE_USEROP_ABI,
|
|
462
|
-
functionName: "executeUserOpWithErrorString",
|
|
463
|
-
args: [
|
|
464
|
-
normalizeAddress(roleSpendCall.to, "rolesModuleAddress"),
|
|
465
|
-
0n,
|
|
466
|
-
roleSpendCall.data,
|
|
467
|
-
OPERATION_CALL
|
|
468
|
-
]
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
/**
|
|
472
|
-
* Wrap an ARBITRARY batch of calls into a member Safe's
|
|
473
|
-
* `executeUserOpWithErrorString` via a delegatecall into MultiSendCallOnly
|
|
474
|
-
* (G4 · #547 dev seam). Used by the dev MCP proof to drive the org's Zodiac
|
|
475
|
-
* Roles DEPLOY (deployModule + enableModule + setUpRoles) and role GRANT
|
|
476
|
-
* (assignRoles) as ONE sponsored UserOp from the founder's personal Safe —
|
|
477
|
-
* the same `buildSponsoredSafeUserOp` mechanism the spend path uses. A single
|
|
478
|
-
* call is still wrapped (MultiSend of length 1) so the caller need not branch.
|
|
479
|
-
*/
|
|
480
|
-
function buildOrgPersonalMultiCallData(calls) {
|
|
481
|
-
if (calls.length === 0) throw new RangeError("multi-call batch must include at least one call");
|
|
482
|
-
return encodeFunctionData({
|
|
483
|
-
abi: SAFE4337_EXECUTE_USEROP_ABI,
|
|
484
|
-
functionName: "executeUserOpWithErrorString",
|
|
485
|
-
args: [
|
|
486
|
-
MULTI_SEND_CALL_ONLY,
|
|
487
|
-
0n,
|
|
488
|
-
encodeFunctionData({
|
|
489
|
-
abi: MULTI_SEND_CALL_ONLY_ABI,
|
|
490
|
-
functionName: "multiSend",
|
|
491
|
-
args: [concat(calls.map(encodeMultiSendCallTransaction))]
|
|
492
|
-
}),
|
|
493
|
-
OPERATION_DELEGATECALL
|
|
494
|
-
]
|
|
495
|
-
});
|
|
496
|
-
}
|
|
497
|
-
/**
|
|
498
|
-
* Encode an org PAYROLL BATCH (G4 · #547): one `execTransactionWithRole`
|
|
499
|
-
* (the member's role key) → MultiSendCallOnly → N × (approve + CapxulPayments
|
|
500
|
-
* settlement call), one call per employee. Instant lines use `send`; scheduled
|
|
501
|
-
* and stream salary lines use `createCommitment`. Each line keeps its own
|
|
502
|
-
* recipient + amount, so each is bounded independently by the role's on-chain
|
|
503
|
-
* Zodiac conditions (per-tx cap, per-day allowance, allowed recipient). One
|
|
504
|
-
* sponsored UserOp settles the batch.
|
|
505
|
-
*/
|
|
506
|
-
function buildCapxulPaymentsRoleBatchSpendCall(input) {
|
|
507
|
-
if (input.runs.length === 0) throw new RangeError("payroll batch must include at least one run");
|
|
508
|
-
const roleKey = normalizeBytes32(input.roleKey, "roleKey");
|
|
509
|
-
const paymentType = input.paymentType ?? 0;
|
|
510
|
-
const multiSendData = encodeFunctionData({
|
|
511
|
-
abi: MULTI_SEND_CALL_ONLY_ABI,
|
|
512
|
-
functionName: "multiSend",
|
|
513
|
-
args: [concat(input.runs.flatMap((run) => {
|
|
514
|
-
if (run.timing !== void 0) return [...buildCapxulCreateCommitmentCalls({
|
|
515
|
-
tokenAddress: input.tokenAddress,
|
|
516
|
-
recipientAddress: run.recipientAddress,
|
|
517
|
-
totalAmount: run.amount,
|
|
518
|
-
startTime: run.timing.startTime,
|
|
519
|
-
cliffTime: run.timing.cliffTime,
|
|
520
|
-
endTime: run.timing.endTime,
|
|
521
|
-
paymentType,
|
|
522
|
-
...run.documentHash === void 0 ? {} : { documentHash: run.documentHash }
|
|
523
|
-
})];
|
|
524
|
-
return [...buildCapxulPaymentsSendCalls({
|
|
525
|
-
tokenAddress: input.tokenAddress,
|
|
526
|
-
recipientAddress: run.recipientAddress,
|
|
527
|
-
amount: run.amount,
|
|
528
|
-
paymentType,
|
|
529
|
-
...run.documentHash === void 0 ? {} : { documentHash: run.documentHash }
|
|
530
|
-
})];
|
|
531
|
-
}).map(encodeMultiSendCallTransaction))]
|
|
532
|
-
});
|
|
533
|
-
return {
|
|
534
|
-
to: normalizeAddress(input.rolesModuleAddress, "rolesModuleAddress"),
|
|
535
|
-
data: encodeFunctionData({
|
|
536
|
-
abi: ROLES_EXEC_TRANSACTION_WITH_ROLE_ABI$1,
|
|
537
|
-
functionName: "execTransactionWithRole",
|
|
538
|
-
args: [
|
|
539
|
-
MULTI_SEND_CALL_ONLY,
|
|
540
|
-
0n,
|
|
541
|
-
multiSendData,
|
|
542
|
-
OPERATION_DELEGATECALL,
|
|
543
|
-
roleKey,
|
|
544
|
-
true
|
|
545
|
-
]
|
|
546
|
-
}),
|
|
547
|
-
value: 0n
|
|
548
|
-
};
|
|
549
|
-
}
|
|
550
|
-
function encodeMultiSendCallTransaction(call) {
|
|
551
|
-
return encodePacked([
|
|
552
|
-
"uint8",
|
|
553
|
-
"address",
|
|
554
|
-
"uint256",
|
|
555
|
-
"uint256",
|
|
556
|
-
"bytes"
|
|
557
|
-
], [
|
|
558
|
-
OPERATION_CALL,
|
|
559
|
-
call.to,
|
|
560
|
-
call.value,
|
|
561
|
-
BigInt((call.data.length - 2) / 2),
|
|
562
|
-
call.data
|
|
563
|
-
]);
|
|
564
|
-
}
|
|
565
|
-
/**
|
|
566
|
-
* Encode a personal Safe's `executeUserOpWithErrorString` callData that pays via
|
|
567
|
-
* CapxulPayments in one UserOp: approve + send batched through a delegatecall
|
|
568
|
-
* into MultiSendCallOnly. The Safe4337Module invokes this on the Safe; the
|
|
569
|
-
* MultiSend then CALLs each sub-transaction from the Safe's own context.
|
|
570
|
-
*/
|
|
571
|
-
function buildCapxulPaymentsPersonalSendCallData(input) {
|
|
572
|
-
return encodeFunctionData({
|
|
573
|
-
abi: SAFE4337_EXECUTE_USEROP_ABI,
|
|
574
|
-
functionName: "executeUserOpWithErrorString",
|
|
575
|
-
args: [
|
|
576
|
-
MULTI_SEND_CALL_ONLY,
|
|
577
|
-
0n,
|
|
578
|
-
encodeFunctionData({
|
|
579
|
-
abi: MULTI_SEND_CALL_ONLY_ABI,
|
|
580
|
-
functionName: "multiSend",
|
|
581
|
-
args: [concat(buildCapxulPaymentsSendCalls(input).map(encodeMultiSendCallTransaction))]
|
|
582
|
-
}),
|
|
583
|
-
OPERATION_DELEGATECALL
|
|
584
|
-
]
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
|
-
const CAPXUL_PAYMENTS_COMMITMENT_ABI = [
|
|
588
|
-
{
|
|
589
|
-
type: "function",
|
|
590
|
-
name: "createCommitment",
|
|
591
|
-
stateMutability: "nonpayable",
|
|
592
|
-
inputs: [
|
|
593
|
-
{
|
|
594
|
-
name: "token",
|
|
595
|
-
type: "address"
|
|
596
|
-
},
|
|
597
|
-
{
|
|
598
|
-
name: "recipient",
|
|
599
|
-
type: "address"
|
|
600
|
-
},
|
|
601
|
-
{
|
|
602
|
-
name: "totalAmount",
|
|
603
|
-
type: "uint256"
|
|
604
|
-
},
|
|
605
|
-
{
|
|
606
|
-
name: "startTime",
|
|
607
|
-
type: "uint48"
|
|
608
|
-
},
|
|
609
|
-
{
|
|
610
|
-
name: "cliffTime",
|
|
611
|
-
type: "uint48"
|
|
612
|
-
},
|
|
613
|
-
{
|
|
614
|
-
name: "endTime",
|
|
615
|
-
type: "uint48"
|
|
616
|
-
},
|
|
617
|
-
{
|
|
618
|
-
name: "documentHash",
|
|
619
|
-
type: "bytes32"
|
|
620
|
-
},
|
|
621
|
-
{
|
|
622
|
-
name: "paymentType",
|
|
623
|
-
type: "uint8"
|
|
624
|
-
}
|
|
625
|
-
],
|
|
626
|
-
outputs: [{
|
|
627
|
-
name: "commitmentId",
|
|
628
|
-
type: "uint256"
|
|
629
|
-
}]
|
|
630
|
-
},
|
|
631
|
-
{
|
|
632
|
-
type: "function",
|
|
633
|
-
name: "claim",
|
|
634
|
-
stateMutability: "nonpayable",
|
|
635
|
-
inputs: [{
|
|
636
|
-
name: "commitmentId",
|
|
637
|
-
type: "uint256"
|
|
638
|
-
}],
|
|
639
|
-
outputs: []
|
|
640
|
-
},
|
|
641
|
-
{
|
|
642
|
-
type: "function",
|
|
643
|
-
name: "cancel",
|
|
644
|
-
stateMutability: "nonpayable",
|
|
645
|
-
inputs: [{
|
|
646
|
-
name: "commitmentId",
|
|
647
|
-
type: "uint256"
|
|
648
|
-
}, {
|
|
649
|
-
name: "documentHash",
|
|
650
|
-
type: "bytes32"
|
|
651
|
-
}],
|
|
652
|
-
outputs: []
|
|
653
|
-
},
|
|
654
|
-
{
|
|
655
|
-
type: "function",
|
|
656
|
-
name: "redirect",
|
|
657
|
-
stateMutability: "nonpayable",
|
|
658
|
-
inputs: [
|
|
659
|
-
{
|
|
660
|
-
name: "commitmentId",
|
|
661
|
-
type: "uint256"
|
|
662
|
-
},
|
|
663
|
-
{
|
|
664
|
-
name: "newRecipient",
|
|
665
|
-
type: "address"
|
|
666
|
-
},
|
|
667
|
-
{
|
|
668
|
-
name: "newDocumentHash",
|
|
669
|
-
type: "bytes32"
|
|
670
|
-
}
|
|
671
|
-
],
|
|
672
|
-
outputs: []
|
|
673
|
-
},
|
|
674
|
-
{
|
|
675
|
-
type: "function",
|
|
676
|
-
name: "claimableAmount",
|
|
677
|
-
stateMutability: "view",
|
|
678
|
-
inputs: [{
|
|
679
|
-
name: "commitmentId",
|
|
680
|
-
type: "uint256"
|
|
681
|
-
}],
|
|
682
|
-
outputs: [{
|
|
683
|
-
name: "",
|
|
684
|
-
type: "uint256"
|
|
685
|
-
}]
|
|
686
|
-
},
|
|
687
|
-
{
|
|
688
|
-
type: "function",
|
|
689
|
-
name: "commitments",
|
|
690
|
-
stateMutability: "view",
|
|
691
|
-
inputs: [{
|
|
692
|
-
name: "",
|
|
693
|
-
type: "uint256"
|
|
694
|
-
}],
|
|
695
|
-
outputs: [
|
|
696
|
-
{
|
|
697
|
-
name: "creator",
|
|
698
|
-
type: "address"
|
|
699
|
-
},
|
|
700
|
-
{
|
|
701
|
-
name: "token",
|
|
702
|
-
type: "address"
|
|
703
|
-
},
|
|
704
|
-
{
|
|
705
|
-
name: "recipient",
|
|
706
|
-
type: "address"
|
|
707
|
-
},
|
|
708
|
-
{
|
|
709
|
-
name: "totalAmount",
|
|
710
|
-
type: "uint256"
|
|
711
|
-
},
|
|
712
|
-
{
|
|
713
|
-
name: "claimed",
|
|
714
|
-
type: "uint256"
|
|
715
|
-
},
|
|
716
|
-
{
|
|
717
|
-
name: "startTime",
|
|
718
|
-
type: "uint48"
|
|
719
|
-
},
|
|
720
|
-
{
|
|
721
|
-
name: "cliffTime",
|
|
722
|
-
type: "uint48"
|
|
723
|
-
},
|
|
724
|
-
{
|
|
725
|
-
name: "endTime",
|
|
726
|
-
type: "uint48"
|
|
727
|
-
},
|
|
728
|
-
{
|
|
729
|
-
name: "documentHash",
|
|
730
|
-
type: "bytes32"
|
|
731
|
-
},
|
|
732
|
-
{
|
|
733
|
-
name: "paymentType",
|
|
734
|
-
type: "uint8"
|
|
735
|
-
},
|
|
736
|
-
{
|
|
737
|
-
name: "cancelled",
|
|
738
|
-
type: "bool"
|
|
739
|
-
}
|
|
740
|
-
]
|
|
741
|
-
}
|
|
742
|
-
];
|
|
743
|
-
function normalizeUint48(value, field) {
|
|
744
|
-
if (!Number.isInteger(value) || value < 0 || value > 0xffffffffffff) throw new RangeError(`${field} must be a uint48 (epoch seconds)`);
|
|
745
|
-
return value;
|
|
746
|
-
}
|
|
747
|
-
/**
|
|
748
|
-
* Encode a personal Safe's `createCommitment` UserOp: approve + createCommitment
|
|
749
|
-
* batched through a delegatecall into MultiSendCallOnly (one sponsored UserOp).
|
|
750
|
-
* The creator (payer Safe) escrows `totalAmount` into CapxulPayments.
|
|
751
|
-
*/
|
|
752
|
-
function buildCapxulCreateCommitmentPersonalCallData(input) {
|
|
753
|
-
const tokenAddress = normalizeAddress(input.tokenAddress, "tokenAddress");
|
|
754
|
-
const recipientAddress = normalizeAddress(input.recipientAddress, "recipientAddress");
|
|
755
|
-
const totalAmount = normalizePositiveAmount(input.totalAmount, "totalAmount");
|
|
756
|
-
const startTime = normalizeUint48(input.startTime, "startTime");
|
|
757
|
-
const cliffTime = normalizeUint48(input.cliffTime, "cliffTime");
|
|
758
|
-
const endTime = normalizeUint48(input.endTime, "endTime");
|
|
759
|
-
if (startTime > endTime || cliffTime < startTime || cliffTime > endTime) throw new RangeError("commitment times must satisfy start <= cliff <= end");
|
|
760
|
-
const documentHash = normalizeBytes32(input.documentHash ?? `0x${"0".repeat(64)}`, "documentHash");
|
|
761
|
-
const paymentType = normalizeUint8(input.paymentType ?? 0, "paymentType");
|
|
762
|
-
return encodeFunctionData({
|
|
763
|
-
abi: SAFE4337_EXECUTE_USEROP_ABI,
|
|
764
|
-
functionName: "executeUserOpWithErrorString",
|
|
765
|
-
args: [
|
|
766
|
-
MULTI_SEND_CALL_ONLY,
|
|
767
|
-
0n,
|
|
768
|
-
encodeFunctionData({
|
|
769
|
-
abi: MULTI_SEND_CALL_ONLY_ABI,
|
|
770
|
-
functionName: "multiSend",
|
|
771
|
-
args: [concat([{
|
|
772
|
-
to: tokenAddress,
|
|
773
|
-
data: encodeFunctionData({
|
|
774
|
-
abi: ERC20_APPROVE_ABI,
|
|
775
|
-
functionName: "approve",
|
|
776
|
-
args: [CAPXUL_PAYMENTS_ADDRESS, totalAmount]
|
|
777
|
-
}),
|
|
778
|
-
value: 0n
|
|
779
|
-
}, {
|
|
780
|
-
to: CAPXUL_PAYMENTS_ADDRESS,
|
|
781
|
-
data: encodeFunctionData({
|
|
782
|
-
abi: CAPXUL_PAYMENTS_COMMITMENT_ABI,
|
|
783
|
-
functionName: "createCommitment",
|
|
784
|
-
args: [
|
|
785
|
-
tokenAddress,
|
|
786
|
-
recipientAddress,
|
|
787
|
-
totalAmount,
|
|
788
|
-
startTime,
|
|
789
|
-
cliffTime,
|
|
790
|
-
endTime,
|
|
791
|
-
documentHash,
|
|
792
|
-
paymentType
|
|
793
|
-
]
|
|
794
|
-
}),
|
|
795
|
-
value: 0n
|
|
796
|
-
}].map(encodeMultiSendCallTransaction))]
|
|
797
|
-
}),
|
|
798
|
-
OPERATION_DELEGATECALL
|
|
799
|
-
]
|
|
800
|
-
});
|
|
801
|
-
}
|
|
802
|
-
function buildSingleCapxulPaymentsCallData(data) {
|
|
803
|
-
return encodeFunctionData({
|
|
804
|
-
abi: SAFE4337_EXECUTE_USEROP_ABI,
|
|
805
|
-
functionName: "executeUserOpWithErrorString",
|
|
806
|
-
args: [
|
|
807
|
-
CAPXUL_PAYMENTS_ADDRESS,
|
|
808
|
-
0n,
|
|
809
|
-
data,
|
|
810
|
-
OPERATION_CALL
|
|
811
|
-
]
|
|
812
|
-
});
|
|
813
|
-
}
|
|
814
|
-
/** Encode a recipient Safe's `claim(commitmentId)` UserOp callData. */
|
|
815
|
-
function buildCapxulCommitmentClaimCallData(commitmentId) {
|
|
816
|
-
return buildSingleCapxulPaymentsCallData(encodeFunctionData({
|
|
817
|
-
abi: CAPXUL_PAYMENTS_COMMITMENT_ABI,
|
|
818
|
-
functionName: "claim",
|
|
819
|
-
args: [commitmentId]
|
|
820
|
-
}));
|
|
821
|
-
}
|
|
822
|
-
/** Encode a creator Safe's `cancel(commitmentId, documentHash)` UserOp callData. */
|
|
823
|
-
function buildCapxulCommitmentCancelCallData(commitmentId, documentHash) {
|
|
824
|
-
return buildSingleCapxulPaymentsCallData(encodeFunctionData({
|
|
825
|
-
abi: CAPXUL_PAYMENTS_COMMITMENT_ABI,
|
|
826
|
-
functionName: "cancel",
|
|
827
|
-
args: [commitmentId, normalizeBytes32(documentHash ?? `0x${"0".repeat(64)}`, "documentHash")]
|
|
828
|
-
}));
|
|
829
|
-
}
|
|
830
|
-
/** Encode a creator Safe's `redirect(commitmentId, newRecipient, newDocumentHash)` UserOp callData. */
|
|
831
|
-
function buildCapxulCommitmentRedirectCallData(commitmentId, newRecipient, newDocumentHash) {
|
|
832
|
-
return buildSingleCapxulPaymentsCallData(encodeFunctionData({
|
|
833
|
-
abi: CAPXUL_PAYMENTS_COMMITMENT_ABI,
|
|
834
|
-
functionName: "redirect",
|
|
835
|
-
args: [
|
|
836
|
-
commitmentId,
|
|
837
|
-
normalizeAddress(newRecipient, "newRecipient"),
|
|
838
|
-
normalizeBytes32(newDocumentHash ?? `0x${"0".repeat(64)}`, "newDocumentHash")
|
|
839
|
-
]
|
|
840
|
-
}));
|
|
841
|
-
}
|
|
842
|
-
//#endregion
|
|
843
|
-
//#region ../../packages/config/src/safe.ts
|
|
844
|
-
const BASE_SEPOLIA_CHAIN_ID = 84532;
|
|
845
|
-
const SAFE_PROXY_FACTORY = "0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67";
|
|
846
|
-
const SAFE_L2_SINGLETON = "0x29fcB43b46531BcA003ddC8FCB67FFE91900C762";
|
|
847
|
-
const SAFE_MODULE_SETUP = "0x2dd68b007B46fBe91B9A7c3EDa5A7a1063cB5b47";
|
|
848
|
-
const SAFE_4337_MODULE = "0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226";
|
|
849
|
-
const MULTI_SEND = "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526";
|
|
850
|
-
/**
|
|
851
|
-
* Canonical personal-Safe salt namespace — **v2** (PRD #462). v2 derives the
|
|
852
|
-
* address from the email ONLY: the initializer's sole owner is the fixed
|
|
853
|
-
* `CAPXUL_BOOTSTRAP_OWNER`, so the address exists before any user signer does
|
|
854
|
-
* and can never rotate with one. The user's signer is installed at claim time
|
|
855
|
-
* via `swapOwner` (see `capxulClaimOwnerCallData`).
|
|
856
|
-
*/
|
|
857
|
-
const CAPXUL_SAFE_SALT_NAMESPACE = "capxul:safe:email:v2";
|
|
858
|
-
/**
|
|
859
|
-
* The Capxul bootstrap owner — the sole `setup()` owner of every unclaimed
|
|
860
|
-
* personal Safe under derivation v2. This address is part of the CREATE2
|
|
861
|
-
* preimage of EVERY personal Safe address: treat it exactly like
|
|
862
|
-
* `SAFE_PROXY_FACTORY` (changing it is a derivation-version event → v3).
|
|
863
|
-
* The private key lives backend-only (`CAPXUL_BOOTSTRAP_OWNER_PRIVATE_KEY`)
|
|
864
|
-
* and signs exactly one kind of operation: the claim userOp that deploys the
|
|
865
|
-
* Safe and swaps this owner out for the user's signer (PRD #462). The earlier
|
|
866
|
-
* ClaimGuard derivation-v3 placeholder (#461) is closed; future mainnet-scale
|
|
867
|
-
* hardening should be filed against the current payments/claim architecture.
|
|
868
|
-
*/
|
|
869
|
-
const CAPXUL_BOOTSTRAP_OWNER = "0x425fca96f4a3e18fb80974e38096b5da460f2704";
|
|
870
|
-
const UINT48_MAX = 0xffffffffffff;
|
|
871
|
-
const SAFE_PROXY_CREATION_CODE = "0x608060405234801561001057600080fd5b506040516101e63803806101e68339818101604052602081101561003357600080fd5b8101908080519060200190929190505050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156100ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806101c46022913960400191505060405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505060ab806101196000396000f3fe608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea264697066735822122003d1488ee65e08fa41e58e888a9865554c535f2c77126a82cb4c0f917f31441364736f6c63430007060033496e76616c69642073696e676c65746f6e20616464726573732070726f7669646564";
|
|
872
|
-
/**
|
|
873
|
-
* Normalize an email for use as a Capxul Safe salt input.
|
|
874
|
-
*
|
|
875
|
-
* Trims surrounding whitespace and lowercases the address so that
|
|
876
|
-
* `" User+Demo@Example.COM "` and `"user+demo@example.com"` derive
|
|
877
|
-
* the same `safeAddress`. This is the canonical normalization rule —
|
|
878
|
-
* any future change here would shift every existing user's Safe
|
|
879
|
-
* address, so the rule is pinned by the fixture matrix in
|
|
880
|
-
* `packages/config/tests/safe-address-conformance.test.ts`.
|
|
881
|
-
*
|
|
882
|
-
* @param email - The raw email address to normalize
|
|
883
|
-
* @returns The trimmed, lowercased email
|
|
884
|
-
*/
|
|
885
|
-
function normalizeSafeSaltEmail(email) {
|
|
886
|
-
return email.trim().toLowerCase();
|
|
887
|
-
}
|
|
888
|
-
/**
|
|
889
|
-
* Compute the deterministic Safe salt nonce for a `(namespace, email)`
|
|
890
|
-
* pair. The salt nonce is the `bigint` reading of
|
|
891
|
-
* `keccak256(namespace + ":" + normalizeSafeSaltEmail(email))`.
|
|
892
|
-
*
|
|
893
|
-
* Namespace defaults to `CAPXUL_SAFE_SALT_NAMESPACE`
|
|
894
|
-
* (`"capxul:safe:email:v2"`) — the per-version Capxul scheme. Pass a
|
|
895
|
-
* different namespace only for pinned pre-v2 artifacts
|
|
896
|
-
* (`CAPXUL_SAFE_SALT_NAMESPACE_V1`, faucet Safe) or when bumping the scheme.
|
|
897
|
-
*
|
|
898
|
-
* @param input.email - The email to derive the salt nonce from
|
|
899
|
-
* @param input.namespace - Optional namespace override (defaults to `CAPXUL_SAFE_SALT_NAMESPACE`)
|
|
900
|
-
* @returns The Capxul-namespaced salt nonce as a `bigint`
|
|
901
|
-
*/
|
|
902
|
-
function computeCapxulSafeSaltNonce(input) {
|
|
903
|
-
const namespace = input.namespace ?? "capxul:safe:email:v2";
|
|
904
|
-
const normalizedEmail = normalizeSafeSaltEmail(input.email);
|
|
905
|
-
return BigInt(keccak256(toBytes(`${namespace}:${normalizedEmail}`)));
|
|
906
|
-
}
|
|
907
|
-
const ZERO_ADDRESS$1 = "0x0000000000000000000000000000000000000000";
|
|
908
|
-
const safeSetupAbi$1 = [{
|
|
909
|
-
type: "function",
|
|
910
|
-
name: "setup",
|
|
911
|
-
stateMutability: "nonpayable",
|
|
912
|
-
inputs: [
|
|
913
|
-
{
|
|
914
|
-
name: "_owners",
|
|
915
|
-
type: "address[]"
|
|
916
|
-
},
|
|
917
|
-
{
|
|
918
|
-
name: "_threshold",
|
|
919
|
-
type: "uint256"
|
|
920
|
-
},
|
|
921
|
-
{
|
|
922
|
-
name: "to",
|
|
923
|
-
type: "address"
|
|
924
|
-
},
|
|
925
|
-
{
|
|
926
|
-
name: "data",
|
|
927
|
-
type: "bytes"
|
|
928
|
-
},
|
|
929
|
-
{
|
|
930
|
-
name: "fallbackHandler",
|
|
931
|
-
type: "address"
|
|
932
|
-
},
|
|
933
|
-
{
|
|
934
|
-
name: "paymentToken",
|
|
935
|
-
type: "address"
|
|
936
|
-
},
|
|
937
|
-
{
|
|
938
|
-
name: "payment",
|
|
939
|
-
type: "uint256"
|
|
940
|
-
},
|
|
941
|
-
{
|
|
942
|
-
name: "paymentReceiver",
|
|
943
|
-
type: "address"
|
|
944
|
-
}
|
|
945
|
-
],
|
|
946
|
-
outputs: []
|
|
947
|
-
}];
|
|
948
|
-
const enableModulesAbi$1 = [{
|
|
949
|
-
type: "function",
|
|
950
|
-
name: "enableModules",
|
|
951
|
-
stateMutability: "nonpayable",
|
|
952
|
-
inputs: [{
|
|
953
|
-
name: "modules",
|
|
954
|
-
type: "address[]"
|
|
955
|
-
}],
|
|
956
|
-
outputs: []
|
|
957
|
-
}];
|
|
958
|
-
const multiSendAbi$1 = [{
|
|
959
|
-
type: "function",
|
|
960
|
-
name: "multiSend",
|
|
961
|
-
stateMutability: "payable",
|
|
962
|
-
inputs: [{
|
|
963
|
-
name: "transactions",
|
|
964
|
-
type: "bytes"
|
|
965
|
-
}],
|
|
966
|
-
outputs: []
|
|
967
|
-
}];
|
|
968
|
-
const safeExecTransactionAbi = [{
|
|
969
|
-
type: "function",
|
|
970
|
-
name: "execTransaction",
|
|
971
|
-
stateMutability: "payable",
|
|
972
|
-
inputs: [
|
|
973
|
-
{
|
|
974
|
-
name: "to",
|
|
975
|
-
type: "address"
|
|
976
|
-
},
|
|
977
|
-
{
|
|
978
|
-
name: "value",
|
|
979
|
-
type: "uint256"
|
|
980
|
-
},
|
|
981
|
-
{
|
|
982
|
-
name: "data",
|
|
983
|
-
type: "bytes"
|
|
984
|
-
},
|
|
985
|
-
{
|
|
986
|
-
name: "operation",
|
|
987
|
-
type: "uint8"
|
|
988
|
-
},
|
|
989
|
-
{
|
|
990
|
-
name: "safeTxGas",
|
|
991
|
-
type: "uint256"
|
|
992
|
-
},
|
|
993
|
-
{
|
|
994
|
-
name: "baseGas",
|
|
995
|
-
type: "uint256"
|
|
996
|
-
},
|
|
997
|
-
{
|
|
998
|
-
name: "gasPrice",
|
|
999
|
-
type: "uint256"
|
|
1000
|
-
},
|
|
1001
|
-
{
|
|
1002
|
-
name: "gasToken",
|
|
1003
|
-
type: "address"
|
|
1004
|
-
},
|
|
1005
|
-
{
|
|
1006
|
-
name: "refundReceiver",
|
|
1007
|
-
type: "address"
|
|
1008
|
-
},
|
|
1009
|
-
{
|
|
1010
|
-
name: "signatures",
|
|
1011
|
-
type: "bytes"
|
|
1012
|
-
}
|
|
1013
|
-
],
|
|
1014
|
-
outputs: [{
|
|
1015
|
-
name: "success",
|
|
1016
|
-
type: "bool"
|
|
1017
|
-
}]
|
|
1018
|
-
}];
|
|
1019
|
-
/**
|
|
1020
|
-
* Encode ordered calls as one Safe `execTransaction` through MultiSend.
|
|
1021
|
-
*
|
|
1022
|
-
* The owner must approve the surrounding transaction, so this builder uses
|
|
1023
|
-
* Safe's prevalidated-signature format and delegates the ordered calls through
|
|
1024
|
-
* the canonical MultiSend contract.
|
|
1025
|
-
*/
|
|
1026
|
-
function buildSafeMultiSendExecTransactionCall(input) {
|
|
1027
|
-
const multiSendData = encodeFunctionData({
|
|
1028
|
-
abi: multiSendAbi$1,
|
|
1029
|
-
functionName: "multiSend",
|
|
1030
|
-
args: [concat(input.calls.map(encodeSafeMultiSendCallTransaction))]
|
|
1031
|
-
});
|
|
1032
|
-
return {
|
|
1033
|
-
to: input.safeAddress,
|
|
1034
|
-
value: 0n,
|
|
1035
|
-
data: encodeFunctionData({
|
|
1036
|
-
abi: safeExecTransactionAbi,
|
|
1037
|
-
functionName: "execTransaction",
|
|
1038
|
-
args: [
|
|
1039
|
-
MULTI_SEND,
|
|
1040
|
-
0n,
|
|
1041
|
-
multiSendData,
|
|
1042
|
-
1,
|
|
1043
|
-
0n,
|
|
1044
|
-
0n,
|
|
1045
|
-
0n,
|
|
1046
|
-
ZERO_ADDRESS$1,
|
|
1047
|
-
ZERO_ADDRESS$1,
|
|
1048
|
-
`${pad(input.ownerAddress, { size: 32 })}${"0".repeat(64)}01`
|
|
1049
|
-
]
|
|
1050
|
-
})
|
|
1051
|
-
};
|
|
1052
|
-
}
|
|
1053
|
-
function encodeSafeMultiSendCallTransaction(call) {
|
|
1054
|
-
return encodePacked([
|
|
1055
|
-
"uint8",
|
|
1056
|
-
"address",
|
|
1057
|
-
"uint256",
|
|
1058
|
-
"uint256",
|
|
1059
|
-
"bytes"
|
|
1060
|
-
], [
|
|
1061
|
-
0,
|
|
1062
|
-
call.to,
|
|
1063
|
-
call.value,
|
|
1064
|
-
BigInt((call.data.length - 2) / 2),
|
|
1065
|
-
call.data
|
|
1066
|
-
]);
|
|
1067
|
-
}
|
|
1068
|
-
function buildCapxulSafeInitializer(owner) {
|
|
1069
|
-
const enableModulesCall = encodeFunctionData({
|
|
1070
|
-
abi: enableModulesAbi$1,
|
|
1071
|
-
functionName: "enableModules",
|
|
1072
|
-
args: [[SAFE_4337_MODULE]]
|
|
1073
|
-
});
|
|
1074
|
-
const setupData = encodeFunctionData({
|
|
1075
|
-
abi: multiSendAbi$1,
|
|
1076
|
-
functionName: "multiSend",
|
|
1077
|
-
args: [encodePacked([
|
|
1078
|
-
"uint8",
|
|
1079
|
-
"address",
|
|
1080
|
-
"uint256",
|
|
1081
|
-
"uint256",
|
|
1082
|
-
"bytes"
|
|
1083
|
-
], [
|
|
1084
|
-
1,
|
|
1085
|
-
SAFE_MODULE_SETUP,
|
|
1086
|
-
0n,
|
|
1087
|
-
BigInt((enableModulesCall.length - 2) / 2),
|
|
1088
|
-
enableModulesCall
|
|
1089
|
-
])]
|
|
1090
|
-
});
|
|
1091
|
-
return encodeFunctionData({
|
|
1092
|
-
abi: safeSetupAbi$1,
|
|
1093
|
-
functionName: "setup",
|
|
1094
|
-
args: [
|
|
1095
|
-
[owner],
|
|
1096
|
-
1n,
|
|
1097
|
-
MULTI_SEND,
|
|
1098
|
-
setupData,
|
|
1099
|
-
SAFE_4337_MODULE,
|
|
1100
|
-
ZERO_ADDRESS$1,
|
|
1101
|
-
0n,
|
|
1102
|
-
ZERO_ADDRESS$1
|
|
1103
|
-
]
|
|
1104
|
-
});
|
|
1105
|
-
}
|
|
1106
|
-
const ADDRESS_REGEX$1 = /^0x[0-9a-fA-F]{40}$/;
|
|
1107
|
-
function validateAndNormalizeAddress(field, value) {
|
|
1108
|
-
const address = value.toLowerCase();
|
|
1109
|
-
if (!ADDRESS_REGEX$1.test(address)) throw Errors.invalidInput(field, `must be 0x + 40 hex chars, got ${value}`);
|
|
1110
|
-
return address;
|
|
1111
|
-
}
|
|
1112
|
-
/**
|
|
1113
|
-
* Pure derivation of the Capxul personal Safe address — **v2: email only**
|
|
1114
|
-
* (PRD #462). The Safe v1.4.1 (SafeL2) + 4337-module initializer's sole owner
|
|
1115
|
-
* is the fixed `CAPXUL_BOOTSTRAP_OWNER`, so the address is a pure function of
|
|
1116
|
-
* the (normalized) email and exists before any user signer does. The user's
|
|
1117
|
-
* signer is installed at claim time via `swapOwner` — signer rotation can
|
|
1118
|
-
* never move the address (org-domain rule D7, now system-wide).
|
|
1119
|
-
*
|
|
1120
|
-
* Returns the lowercased `0x` + 40 hex string (raw — no brand applied so this
|
|
1121
|
-
* function is callable from both `@capxul/config` consumers that don't have
|
|
1122
|
-
* `@capxul/types` available, and from packages that re-brand at their own
|
|
1123
|
-
* boundary).
|
|
1124
|
-
*
|
|
1125
|
-
* Algorithm: exactly mirrors `permissionless.toSafeSmartAccount({ version:
|
|
1126
|
-
* "1.4.1", safeSingletonAddress: SAFE_L2_SINGLETON, owners: [BOOTSTRAP] })`
|
|
1127
|
-
* + the Capxul-canonical module setup (delegatecall into
|
|
1128
|
-
* `SafeModuleSetup.enableModules([SAFE_4337_MODULE])` via the MultiSend lane
|
|
1129
|
-
* during proxy setup). The proxy creation code is pinned at
|
|
1130
|
-
* `SAFE_PROXY_CREATION_CODE`; the salt is Capxul-namespaced (v2) via
|
|
1131
|
-
* `computeCapxulSafeSaltNonce({ email })`.
|
|
1132
|
-
*
|
|
1133
|
-
* Canonical: SDK deployment adapters and
|
|
1134
|
-
* `packages/backend/convex/smartAccount/mutations.ts:provision` import this
|
|
1135
|
-
* function; the conformance test at
|
|
1136
|
-
* `packages/config/tests/safe-address-conformance.test.ts` pins the matrix.
|
|
1137
|
-
*/
|
|
1138
|
-
function deriveCapxulSafeAddress(input) {
|
|
1139
|
-
return deriveCapxulSafeAddressForOwner({
|
|
1140
|
-
ownerAddress: CAPXUL_BOOTSTRAP_OWNER,
|
|
1141
|
-
email: input.email
|
|
1142
|
-
});
|
|
1143
|
-
}
|
|
1144
|
-
/**
|
|
1145
|
-
* Owner-parametrized derivation core. Two callers only:
|
|
1146
|
-
* 1. `deriveCapxulSafeAddress` (canonical v2: owner = bootstrap, namespace v2);
|
|
1147
|
-
* 2. the backend faucet Safe (`testUsdcMint.ts`: owner = deployer EOA,
|
|
1148
|
-
* namespace pinned to `CAPXUL_SAFE_SALT_NAMESPACE_V1` so its deployed
|
|
1149
|
-
* address never moves).
|
|
1150
|
-
* Do NOT introduce new owner-parametrized lanes — per-user owners in the
|
|
1151
|
-
* derivation is exactly the v1 mistake v2 removes.
|
|
1152
|
-
*/
|
|
1153
|
-
function deriveCapxulSafeAddressForOwner(input) {
|
|
1154
|
-
const initializer = buildCapxulSafeInitializer(validateAndNormalizeAddress("ownerAddress", input.ownerAddress));
|
|
1155
|
-
const saltNonce = computeCapxulSafeSaltNonce(input.namespace === void 0 ? { email: input.email } : {
|
|
1156
|
-
email: input.email,
|
|
1157
|
-
namespace: input.namespace
|
|
1158
|
-
});
|
|
1159
|
-
return getContractAddress({
|
|
1160
|
-
opcode: "CREATE2",
|
|
1161
|
-
from: SAFE_PROXY_FACTORY,
|
|
1162
|
-
salt: keccak256(encodePacked(["bytes32", "uint256"], [keccak256(initializer), saltNonce])),
|
|
1163
|
-
bytecodeHash: keccak256(concat([SAFE_PROXY_CREATION_CODE, encodeAbiParameters([{ type: "uint256" }], [BigInt(SAFE_L2_SINGLETON)])]))
|
|
1164
|
-
}).toLowerCase();
|
|
1165
|
-
}
|
|
1166
|
-
/** Canonical ERC-4337 EntryPoint v0.7 address (same on every chain). */
|
|
1167
|
-
const ENTRY_POINT_07_ADDRESS = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
|
|
1168
|
-
/** EIP-712 `SafeOp` typed-data fields for EntryPoint v0.7 (Safe4337Module). */
|
|
1169
|
-
const EIP712_SAFE_OPERATION_TYPE_V07 = { SafeOp: [
|
|
1170
|
-
{
|
|
1171
|
-
type: "address",
|
|
1172
|
-
name: "safe"
|
|
1173
|
-
},
|
|
1174
|
-
{
|
|
1175
|
-
type: "uint256",
|
|
1176
|
-
name: "nonce"
|
|
1177
|
-
},
|
|
1178
|
-
{
|
|
1179
|
-
type: "bytes",
|
|
1180
|
-
name: "initCode"
|
|
1181
|
-
},
|
|
1182
|
-
{
|
|
1183
|
-
type: "bytes",
|
|
1184
|
-
name: "callData"
|
|
1185
|
-
},
|
|
1186
|
-
{
|
|
1187
|
-
type: "uint128",
|
|
1188
|
-
name: "verificationGasLimit"
|
|
1189
|
-
},
|
|
1190
|
-
{
|
|
1191
|
-
type: "uint128",
|
|
1192
|
-
name: "callGasLimit"
|
|
1193
|
-
},
|
|
1194
|
-
{
|
|
1195
|
-
type: "uint256",
|
|
1196
|
-
name: "preVerificationGas"
|
|
1197
|
-
},
|
|
1198
|
-
{
|
|
1199
|
-
type: "uint128",
|
|
1200
|
-
name: "maxPriorityFeePerGas"
|
|
1201
|
-
},
|
|
1202
|
-
{
|
|
1203
|
-
type: "uint128",
|
|
1204
|
-
name: "maxFeePerGas"
|
|
1205
|
-
},
|
|
1206
|
-
{
|
|
1207
|
-
type: "bytes",
|
|
1208
|
-
name: "paymasterAndData"
|
|
1209
|
-
},
|
|
1210
|
-
{
|
|
1211
|
-
type: "uint48",
|
|
1212
|
-
name: "validAfter"
|
|
1213
|
-
},
|
|
1214
|
-
{
|
|
1215
|
-
type: "uint48",
|
|
1216
|
-
name: "validUntil"
|
|
1217
|
-
},
|
|
1218
|
-
{
|
|
1219
|
-
type: "address",
|
|
1220
|
-
name: "entryPoint"
|
|
1221
|
-
}
|
|
1222
|
-
] };
|
|
1223
|
-
/** Pack EntryPoint v0.7 `factory` + `factoryData` into the SafeOp `initCode`. */
|
|
1224
|
-
function safe4337InitCode(userOp) {
|
|
1225
|
-
if (userOp.factory === void 0 || userOp.factory === "0x") return "0x";
|
|
1226
|
-
return concat([userOp.factory, userOp.factoryData ?? "0x"]);
|
|
1227
|
-
}
|
|
1228
|
-
/** Pack EntryPoint v0.7 unpacked paymaster fields into SafeOp `paymasterAndData`. */
|
|
1229
|
-
function safe4337PaymasterAndData(userOp) {
|
|
1230
|
-
if (userOp.paymaster === void 0 || userOp.paymaster === "0x") return "0x";
|
|
1231
|
-
return concat([
|
|
1232
|
-
userOp.paymaster,
|
|
1233
|
-
pad(toHex(userOp.paymasterVerificationGasLimit ?? 0n), { size: 16 }),
|
|
1234
|
-
pad(toHex(userOp.paymasterPostOpGasLimit ?? 0n), { size: 16 }),
|
|
1235
|
-
userOp.paymasterData ?? "0x"
|
|
1236
|
-
]);
|
|
1237
|
-
}
|
|
1238
|
-
/**
|
|
1239
|
-
* Compute the EIP-712 `SafeOp` digest the Safe4337Module owner must sign for a
|
|
1240
|
-
* prepared deployment UserOperation. The `CapxulSigner` signs THIS digest.
|
|
1241
|
-
*/
|
|
1242
|
-
function safe4337SafeOpDigest(input) {
|
|
1243
|
-
return hashTypedData({
|
|
1244
|
-
domain: {
|
|
1245
|
-
chainId: input.chainId,
|
|
1246
|
-
verifyingContract: input.safe4337ModuleAddress ?? "0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226"
|
|
1247
|
-
},
|
|
1248
|
-
types: EIP712_SAFE_OPERATION_TYPE_V07,
|
|
1249
|
-
primaryType: "SafeOp",
|
|
1250
|
-
message: {
|
|
1251
|
-
safe: input.userOp.sender,
|
|
1252
|
-
nonce: input.userOp.nonce,
|
|
1253
|
-
initCode: safe4337InitCode(input.userOp),
|
|
1254
|
-
callData: input.userOp.callData,
|
|
1255
|
-
verificationGasLimit: input.userOp.verificationGasLimit,
|
|
1256
|
-
callGasLimit: input.userOp.callGasLimit,
|
|
1257
|
-
preVerificationGas: input.userOp.preVerificationGas,
|
|
1258
|
-
maxPriorityFeePerGas: input.userOp.maxPriorityFeePerGas,
|
|
1259
|
-
maxFeePerGas: input.userOp.maxFeePerGas,
|
|
1260
|
-
paymasterAndData: safe4337PaymasterAndData(input.userOp),
|
|
1261
|
-
validAfter: input.validAfter ?? 0,
|
|
1262
|
-
validUntil: input.validUntil ?? 0,
|
|
1263
|
-
entryPoint: input.entryPointAddress ?? "0x0000000071727De22E5E9d8BAf0edAc6f37da032"
|
|
1264
|
-
}
|
|
1265
|
-
});
|
|
1266
|
-
}
|
|
1267
|
-
/** Pack a single-owner ECDSA signature into the Safe4337 UserOp signature. */
|
|
1268
|
-
function packSafe4337OwnerSignature(input) {
|
|
1269
|
-
assertUint48(input.validAfter ?? 0, "validAfter");
|
|
1270
|
-
assertUint48(input.validUntil ?? 0, "validUntil");
|
|
1271
|
-
return encodePacked([
|
|
1272
|
-
"uint48",
|
|
1273
|
-
"uint48",
|
|
1274
|
-
"bytes"
|
|
1275
|
-
], [
|
|
1276
|
-
input.validAfter ?? 0,
|
|
1277
|
-
input.validUntil ?? 0,
|
|
1278
|
-
input.signature
|
|
1279
|
-
]);
|
|
1280
|
-
}
|
|
1281
|
-
function assertUint48(value, field) {
|
|
1282
|
-
if (!Number.isSafeInteger(value) || value < 0 || value > UINT48_MAX) throw Errors.invalidInput(field, `must fit uint48 (0..${UINT48_MAX})`);
|
|
1283
|
-
}
|
|
1284
|
-
const SAFE4337_STUB_OWNER_ECDSA = "0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c";
|
|
1285
|
-
/**
|
|
1286
|
-
* Packed Safe4337 stub signature (single static owner) for gas estimation —
|
|
1287
|
-
* byte-for-byte equal to permissionless's `getStubSignature()`.
|
|
1288
|
-
*/
|
|
1289
|
-
function safe4337StubSignature() {
|
|
1290
|
-
return packSafe4337OwnerSignature({ signature: SAFE4337_STUB_OWNER_ECDSA });
|
|
1291
|
-
}
|
|
1292
|
-
//#endregion
|
|
1293
|
-
//#region ../../packages/config/src/binding.ts
|
|
1294
|
-
/** Openfort `thirdPartyUserId` namespace for email bindings (epic #331 / #332). */
|
|
1295
|
-
const CAPXUL_BINDING_EMAIL_NAMESPACE = "capxul:binding:email:v1";
|
|
1296
|
-
/**
|
|
1297
|
-
* Normalize a raw email for binding id + Safe salt derivation.
|
|
1298
|
-
* Delegates to {@link normalizeSafeSaltEmail} so binding resolution and
|
|
1299
|
-
* `deriveCapxulSafeAddress` never drift apart.
|
|
1300
|
-
*/
|
|
1301
|
-
function normalizeBindingEmail(email) {
|
|
1302
|
-
return normalizeSafeSaltEmail(email);
|
|
1303
|
-
}
|
|
1304
|
-
//#endregion
|
|
1305
|
-
//#region ../../packages/config/src/route.ts
|
|
1306
|
-
/** USDX on Base Sepolia — the only settlement token in v1. */
|
|
1307
|
-
const USDX_BASE_SEPOLIA_TOKEN = {
|
|
1308
|
-
chainId: BASE_SEPOLIA_CHAIN_ID,
|
|
1309
|
-
address: USDX_ADDRESS_BASE_SEPOLIA,
|
|
1310
|
-
decimals: 6
|
|
1311
|
-
};
|
|
1312
|
-
/**
|
|
1313
|
-
* The `direct-base` settlement route: USDX on Base Sepolia, settled directly
|
|
1314
|
-
* through the `CapxulPayments` contract. This is the ONLY route implemented in
|
|
1315
|
-
* D1; the `Route` shape is the seam future provider routes slot into.
|
|
1316
|
-
*/
|
|
1317
|
-
const DIRECT_BASE_ROUTE = {
|
|
1318
|
-
kind: "direct-base",
|
|
1319
|
-
token: USDX_BASE_SEPOLIA_TOKEN,
|
|
1320
|
-
chainId: USDX_BASE_SEPOLIA_TOKEN.chainId,
|
|
1321
|
-
verifyingContract: CAPXUL_PAYMENTS_ADDRESS
|
|
1322
|
-
};
|
|
1323
|
-
USDX_BASE_SEPOLIA_TOKEN.chainId;
|
|
1324
|
-
//#endregion
|
|
1325
|
-
//#region ../../packages/config/src/org-safe.ts
|
|
1326
|
-
/**
|
|
1327
|
-
* Per-version Capxul Org Safe salt namespace (D10a). Distinct from the
|
|
1328
|
-
* personal-Safe namespace (`capxul:safe:email:v1`) so an Org Safe and a
|
|
1329
|
-
* personal Safe with the same `(signer, email)` never collide. Bump only when
|
|
1330
|
-
* the Org Safe scheme itself changes (e.g. a Safe factory bytecode migration).
|
|
1331
|
-
*/
|
|
1332
|
-
const CAPXUL_ORG_SALT_NAMESPACE = "capxul:org:v1";
|
|
1333
|
-
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
1334
|
-
const ORG_HANDLE_REGEX = /^[a-z0-9-]{3,32}$/;
|
|
1335
|
-
const ADDRESS_REGEX = /^0x[0-9a-f]{40}$/;
|
|
1336
|
-
const safeSetupAbi = [{
|
|
1337
|
-
type: "function",
|
|
1338
|
-
name: "setup",
|
|
1339
|
-
stateMutability: "nonpayable",
|
|
1340
|
-
inputs: [
|
|
1341
|
-
{
|
|
1342
|
-
name: "_owners",
|
|
1343
|
-
type: "address[]"
|
|
1344
|
-
},
|
|
1345
|
-
{
|
|
1346
|
-
name: "_threshold",
|
|
1347
|
-
type: "uint256"
|
|
1348
|
-
},
|
|
1349
|
-
{
|
|
1350
|
-
name: "to",
|
|
1351
|
-
type: "address"
|
|
1352
|
-
},
|
|
1353
|
-
{
|
|
1354
|
-
name: "data",
|
|
1355
|
-
type: "bytes"
|
|
1356
|
-
},
|
|
1357
|
-
{
|
|
1358
|
-
name: "fallbackHandler",
|
|
1359
|
-
type: "address"
|
|
1360
|
-
},
|
|
1361
|
-
{
|
|
1362
|
-
name: "paymentToken",
|
|
1363
|
-
type: "address"
|
|
1364
|
-
},
|
|
1365
|
-
{
|
|
1366
|
-
name: "payment",
|
|
1367
|
-
type: "uint256"
|
|
1368
|
-
},
|
|
1369
|
-
{
|
|
1370
|
-
name: "paymentReceiver",
|
|
1371
|
-
type: "address"
|
|
1372
|
-
}
|
|
1373
|
-
],
|
|
1374
|
-
outputs: []
|
|
1375
|
-
}];
|
|
1376
|
-
const enableModulesAbi = [{
|
|
1377
|
-
type: "function",
|
|
1378
|
-
name: "enableModules",
|
|
1379
|
-
stateMutability: "nonpayable",
|
|
1380
|
-
inputs: [{
|
|
1381
|
-
name: "modules",
|
|
1382
|
-
type: "address[]"
|
|
1383
|
-
}],
|
|
1384
|
-
outputs: []
|
|
1385
|
-
}];
|
|
1386
|
-
const multiSendAbi = [{
|
|
1387
|
-
type: "function",
|
|
1388
|
-
name: "multiSend",
|
|
1389
|
-
stateMutability: "payable",
|
|
1390
|
-
inputs: [{
|
|
1391
|
-
name: "transactions",
|
|
1392
|
-
type: "bytes"
|
|
1393
|
-
}],
|
|
1394
|
-
outputs: []
|
|
1395
|
-
}];
|
|
1396
|
-
/**
|
|
1397
|
-
* Normalize an org handle for both salting and storage (D10a — trim +
|
|
1398
|
-
* lowercase). Idempotent: `normalizeOrgHandle(normalizeOrgHandle(x)) ===
|
|
1399
|
-
* normalizeOrgHandle(x)`.
|
|
1400
|
-
*
|
|
1401
|
-
* @param handle - The raw org handle
|
|
1402
|
-
* @returns The trimmed, lowercased handle
|
|
1403
|
-
*/
|
|
1404
|
-
function normalizeOrgHandle(handle) {
|
|
1405
|
-
return handle.trim().toLowerCase();
|
|
1406
|
-
}
|
|
1407
|
-
/**
|
|
1408
|
-
* Validate an org handle against the D10a rule `^[a-z0-9-]{3,32}$` over its
|
|
1409
|
-
* NORMALIZED form. Returns the normalized handle on success; throws a typed
|
|
1410
|
-
* `INVALID_INPUT` `CapxulError` (field `orgHandle`) on failure — never a raw
|
|
1411
|
-
* `Error`, so SDK / backend boundary handlers can route on the code.
|
|
1412
|
-
*
|
|
1413
|
-
* @param handle - The raw org handle
|
|
1414
|
-
* @returns The normalized, validated handle
|
|
1415
|
-
*/
|
|
1416
|
-
function validateOrgHandle(handle) {
|
|
1417
|
-
const normalized = normalizeOrgHandle(handle);
|
|
1418
|
-
if (!ORG_HANDLE_REGEX.test(normalized)) throw Errors.invalidInput("orgHandle", `must match ^[a-z0-9-]{3,32}$ after trim+lowercase, got ${handle}`);
|
|
1419
|
-
return normalized;
|
|
1420
|
-
}
|
|
1421
|
-
/**
|
|
1422
|
-
* Compute the deterministic Org Safe salt nonce for a `(namespace, email,
|
|
1423
|
-
* orgHandle)` triple (D10a). The salt nonce is the `bigint` reading of
|
|
1424
|
-
* `keccak256(namespace + ":" + normalizeSafeSaltEmail(email) + ":" +
|
|
1425
|
-
* normalizeOrgHandle(orgHandle))`.
|
|
1426
|
-
*
|
|
1427
|
-
* Keyed on email + handle, NOT the signer — so the Org address survives signer
|
|
1428
|
-
* rotation (D7). Namespace defaults to `CAPXUL_ORG_SALT_NAMESPACE`.
|
|
1429
|
-
*
|
|
1430
|
-
* @param input.email - The founder email to derive the salt nonce from
|
|
1431
|
-
* @param input.orgHandle - The org handle (normalized internally)
|
|
1432
|
-
* @param input.namespace - Optional namespace override
|
|
1433
|
-
* @returns The Capxul-namespaced Org salt nonce as a `bigint`
|
|
1434
|
-
*/
|
|
1435
|
-
function computeCapxulOrgSaltNonce(input) {
|
|
1436
|
-
const namespace = input.namespace ?? "capxul:org:v1";
|
|
1437
|
-
const normalizedEmail = normalizeSafeSaltEmail(input.email);
|
|
1438
|
-
const normalizedHandle = normalizeOrgHandle(input.orgHandle);
|
|
1439
|
-
return BigInt(keccak256(toBytes(`${namespace}:${normalizedEmail}:${normalizedHandle}`)));
|
|
1440
|
-
}
|
|
1441
|
-
/**
|
|
1442
|
-
* Pure derivation of the Org Safe v1.4.1 (SafeL2) + 4337-module-enabled
|
|
1443
|
-
* counterfactual address for a Capxul `(founderPersonalSafe, email, orgHandle)`
|
|
1444
|
-
* triple (D10a). Mirrors `deriveCapxulSafeAddress` byte-for-byte except the salt
|
|
1445
|
-
* nonce (Org-namespaced, keyed on email+handle) and the initializer owner
|
|
1446
|
-
* (the founder's PERSONAL Safe address, passed in directly — D7).
|
|
1447
|
-
*
|
|
1448
|
-
* Returns the lowercased `0x` + 40 hex string (raw — no brand applied; callers
|
|
1449
|
-
* brand at their own boundary). Throws a typed `INVALID_INPUT` `CapxulError`
|
|
1450
|
-
* (field `orgHandle`) if the handle is malformed.
|
|
1451
|
-
*
|
|
1452
|
-
* Canonical conformance: `packages/config/tests/org-safe-address-conformance.test.ts`
|
|
1453
|
-
* pins the matrix against Safes actually deployed on Base Sepolia.
|
|
1454
|
-
*/
|
|
1455
|
-
/**
|
|
1456
|
-
* Build the EXACT Org Safe `setup()` initializer calldata (D10a). This is the
|
|
1457
|
-
* single source of truth for the initializer bytes: `deriveCapxulOrgAddress`
|
|
1458
|
-
* hashes it into the CREATE2 salt, and the live Org deploy adapter passes the
|
|
1459
|
-
* IDENTICAL bytes to `SafeProxyFactory.createProxyWithNonce` — so the deployed
|
|
1460
|
-
* address provably equals the counterfactual byte-for-byte.
|
|
1461
|
-
*
|
|
1462
|
-
* `setup([founderPersonalSafe], 1, MULTI_SEND, <enableModules([SAFE_4337_MODULE])
|
|
1463
|
-
* MultiSend>, SAFE_4337_MODULE, 0, 0, 0)` — owner is the founder's PERSONAL Safe
|
|
1464
|
-
* (D7), the 4337 module is enabled via the same MultiSend lane as the personal
|
|
1465
|
-
* Safe. NO Zodiac Roles / Allowance at setup() (S1 decision A — those land in S2).
|
|
1466
|
-
*
|
|
1467
|
-
* Validates (and lowercases) `founderPersonalSafe`; throws a typed INVALID_INPUT
|
|
1468
|
-
* (`founderPersonalSafe`) on a malformed address.
|
|
1469
|
-
*
|
|
1470
|
-
* @param input.founderPersonalSafe - The founder's personal Safe address (owner)
|
|
1471
|
-
* @returns The `0x`-prefixed `setup()` calldata
|
|
1472
|
-
*/
|
|
1473
|
-
function buildCapxulOrgInitializer(input) {
|
|
1474
|
-
const founderPersonalSafe = input.founderPersonalSafe.toLowerCase();
|
|
1475
|
-
if (!ADDRESS_REGEX.test(founderPersonalSafe)) throw Errors.invalidInput("founderPersonalSafe", `must be 0x + 40 hex chars, got ${input.founderPersonalSafe}`);
|
|
1476
|
-
const enableModulesCall = encodeFunctionData({
|
|
1477
|
-
abi: enableModulesAbi,
|
|
1478
|
-
functionName: "enableModules",
|
|
1479
|
-
args: [[SAFE_4337_MODULE]]
|
|
1480
|
-
});
|
|
1481
|
-
const setupData = encodeFunctionData({
|
|
1482
|
-
abi: multiSendAbi,
|
|
1483
|
-
functionName: "multiSend",
|
|
1484
|
-
args: [encodePacked([
|
|
1485
|
-
"uint8",
|
|
1486
|
-
"address",
|
|
1487
|
-
"uint256",
|
|
1488
|
-
"uint256",
|
|
1489
|
-
"bytes"
|
|
1490
|
-
], [
|
|
1491
|
-
1,
|
|
1492
|
-
SAFE_MODULE_SETUP,
|
|
1493
|
-
0n,
|
|
1494
|
-
BigInt((enableModulesCall.length - 2) / 2),
|
|
1495
|
-
enableModulesCall
|
|
1496
|
-
])]
|
|
1497
|
-
});
|
|
1498
|
-
return encodeFunctionData({
|
|
1499
|
-
abi: safeSetupAbi,
|
|
1500
|
-
functionName: "setup",
|
|
1501
|
-
args: [
|
|
1502
|
-
[founderPersonalSafe],
|
|
1503
|
-
1n,
|
|
1504
|
-
MULTI_SEND,
|
|
1505
|
-
setupData,
|
|
1506
|
-
SAFE_4337_MODULE,
|
|
1507
|
-
ZERO_ADDRESS,
|
|
1508
|
-
0n,
|
|
1509
|
-
ZERO_ADDRESS
|
|
1510
|
-
]
|
|
1511
|
-
});
|
|
1512
|
-
}
|
|
1513
|
-
function deriveCapxulOrgAddress(input) {
|
|
1514
|
-
const orgHandle = validateOrgHandle(input.orgHandle);
|
|
1515
|
-
const initializer = buildCapxulOrgInitializer({ founderPersonalSafe: input.founderPersonalSafe });
|
|
1516
|
-
const saltNonce = computeCapxulOrgSaltNonce({
|
|
1517
|
-
email: input.email,
|
|
1518
|
-
orgHandle
|
|
1519
|
-
});
|
|
1520
|
-
return getContractAddress({
|
|
1521
|
-
opcode: "CREATE2",
|
|
1522
|
-
from: SAFE_PROXY_FACTORY,
|
|
1523
|
-
salt: keccak256(encodePacked(["bytes32", "uint256"], [keccak256(initializer), saltNonce])),
|
|
1524
|
-
bytecodeHash: keccak256(concat([SAFE_PROXY_CREATION_CODE, encodeAbiParameters([{ type: "uint256" }], [BigInt(SAFE_L2_SINGLETON)])]))
|
|
1525
|
-
}).toLowerCase();
|
|
1526
|
-
}
|
|
1527
|
-
//#endregion
|
|
1528
|
-
//#region ../../packages/config/src/role-dsl.ts
|
|
1529
|
-
const USD_DECIMALS = 6;
|
|
1530
|
-
const USD_SCALE = 10n ** BigInt(USD_DECIMALS);
|
|
1531
|
-
const USD_DISPLAY_RE = /^\d+(?:\.\d{1,6})?$/;
|
|
1532
|
-
const USD_BASE_UNIT_RE = /^\d+$/;
|
|
1533
|
-
const EXEC_TRANSACTION_WITH_ROLE$1 = "zodiac.roles.execTransactionWithRole";
|
|
1534
|
-
const ASSIGN_ROLES = "zodiac.roles.assignRoles";
|
|
1535
|
-
const SCOPE_TARGET = "zodiac.roles.scopeTarget";
|
|
1536
|
-
const OWNER_ROLE_LABEL = "Owner";
|
|
1537
|
-
const MARKETING_SUB_ACCOUNT_ID = "subaccount_marketing";
|
|
1538
|
-
const PAYROLL_SUB_ACCOUNT_ID = "subaccount_payroll";
|
|
1539
|
-
function usd(value) {
|
|
1540
|
-
return {
|
|
1541
|
-
currency: "USD",
|
|
1542
|
-
value: usdDisplayToBaseUnits(value),
|
|
1543
|
-
decimals: USD_DECIMALS
|
|
1544
|
-
};
|
|
1545
|
-
}
|
|
1546
|
-
function usdDisplayToBaseUnits(value) {
|
|
1547
|
-
if (value.trim() !== value || !USD_DISPLAY_RE.test(value)) throw Errors.invalidInput("role.spend", "USD caps must be unsigned decimal strings with at most 6 fractional digits");
|
|
1548
|
-
const parts = value.split(".");
|
|
1549
|
-
const whole = parts[0] ?? "0";
|
|
1550
|
-
const fraction = parts[1] ?? "";
|
|
1551
|
-
return (BigInt(whole) * USD_SCALE + BigInt(fraction.padEnd(USD_DECIMALS, "0"))).toString();
|
|
1552
|
-
}
|
|
1553
|
-
function normalizeOrgRoleMoney(money, field) {
|
|
1554
|
-
if (money.currency !== "USD" || money.decimals !== USD_DECIMALS || !USD_BASE_UNIT_RE.test(money.value)) throw Errors.invalidInput(field, `must be USD base units with ${USD_DECIMALS} decimals`);
|
|
1555
|
-
return money;
|
|
1556
|
-
}
|
|
1557
|
-
function normalizeOrgRoleSpendCap(spend) {
|
|
1558
|
-
if (spend === void 0) return void 0;
|
|
1559
|
-
return {
|
|
1560
|
-
...spend.perTx === void 0 ? {} : { perTx: normalizeOrgRoleMoney(spend.perTx, "roles.spend.perTx") },
|
|
1561
|
-
...spend.perDay === void 0 ? {} : { perDay: normalizeOrgRoleMoney(spend.perDay, "roles.spend.perDay") },
|
|
1562
|
-
...spend.toRecipients === void 0 ? {} : { toRecipients: spend.toRecipients }
|
|
1563
|
-
};
|
|
1564
|
-
}
|
|
1565
|
-
function normalizeOrgRoleLabel(label) {
|
|
1566
|
-
const normalized = label.trim().replace(/\s+/g, " ");
|
|
1567
|
-
if (normalized.length === 0) throw Errors.invalidInput("role.label", "must be a non-empty role label");
|
|
1568
|
-
return normalized;
|
|
1569
|
-
}
|
|
1570
|
-
function orgRoleKeyForLabel(label) {
|
|
1571
|
-
return keccak256(toBytes(normalizeOrgRoleLabel(label).toLowerCase()));
|
|
1572
|
-
}
|
|
1573
|
-
function soloOrgRoleTemplate() {
|
|
1574
|
-
return [{
|
|
1575
|
-
label: "Owner",
|
|
1576
|
-
subAccounts: { scope: "all" },
|
|
1577
|
-
canManageMembers: true,
|
|
1578
|
-
canManageRoles: true
|
|
1579
|
-
}];
|
|
1580
|
-
}
|
|
1581
|
-
function startupOrgRoleTemplate() {
|
|
1582
|
-
return [
|
|
1583
|
-
...soloOrgRoleTemplate(),
|
|
1584
|
-
{
|
|
1585
|
-
label: "Finance Manager",
|
|
1586
|
-
spend: {
|
|
1587
|
-
perTx: usd("25000"),
|
|
1588
|
-
perDay: usd("100000"),
|
|
1589
|
-
toRecipients: "anyone"
|
|
1590
|
-
},
|
|
1591
|
-
subAccounts: { scope: [MARKETING_SUB_ACCOUNT_ID] }
|
|
1592
|
-
},
|
|
1593
|
-
{
|
|
1594
|
-
label: "Team Lead",
|
|
1595
|
-
spend: {
|
|
1596
|
-
perTx: usd("5000"),
|
|
1597
|
-
perDay: usd("15000"),
|
|
1598
|
-
toRecipients: "anyone"
|
|
1599
|
-
},
|
|
1600
|
-
subAccounts: { scope: [PAYROLL_SUB_ACCOUNT_ID] }
|
|
1601
|
-
}
|
|
1602
|
-
];
|
|
1603
|
-
}
|
|
1604
|
-
function orgRoleTemplateDefinitions(template, customRoles = []) {
|
|
1605
|
-
switch (template) {
|
|
1606
|
-
case "Solo": return soloOrgRoleTemplate();
|
|
1607
|
-
case "Startup": return startupOrgRoleTemplate();
|
|
1608
|
-
case "Custom": return customRoles.length === 0 ? soloOrgRoleTemplate() : customRoles;
|
|
1609
|
-
default: return template;
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
function compileOrgRoleDefinitions(definitions) {
|
|
1613
|
-
if (definitions.length === 0) throw Errors.invalidInput("roles", "must include at least one role");
|
|
1614
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1615
|
-
const roles = definitions.map((definition) => {
|
|
1616
|
-
const label = normalizeOrgRoleLabel(definition.label);
|
|
1617
|
-
const roleKey = orgRoleKeyForLabel(label);
|
|
1618
|
-
if (seen.has(roleKey)) throw Errors.invalidInput("roles", `duplicate role label: ${label}`);
|
|
1619
|
-
seen.add(roleKey);
|
|
1620
|
-
const spend = normalizeOrgRoleSpendCap(definition.spend);
|
|
1621
|
-
const permissions = [];
|
|
1622
|
-
if (spend !== void 0 || label === OWNER_ROLE_LABEL) permissions.push(EXEC_TRANSACTION_WITH_ROLE$1);
|
|
1623
|
-
if (definition.canManageMembers === true) permissions.push(ASSIGN_ROLES);
|
|
1624
|
-
if (definition.canManageRoles === true) permissions.push(SCOPE_TARGET);
|
|
1625
|
-
return {
|
|
1626
|
-
label,
|
|
1627
|
-
roleKey,
|
|
1628
|
-
definition: {
|
|
1629
|
-
...definition,
|
|
1630
|
-
label,
|
|
1631
|
-
...spend === void 0 ? {} : { spend }
|
|
1632
|
-
},
|
|
1633
|
-
permissions,
|
|
1634
|
-
allowance: spend ?? null
|
|
1635
|
-
};
|
|
1636
|
-
});
|
|
1637
|
-
const manager = roles.find((role) => role.definition.canManageMembers === true);
|
|
1638
|
-
if (manager === void 0) throw Errors.invalidInput("roles.canManageMembers", "at least one role must compile to the on-chain member-management permission");
|
|
1639
|
-
return {
|
|
1640
|
-
roles,
|
|
1641
|
-
memberManagementRole: {
|
|
1642
|
-
roleKey: manager.roleKey,
|
|
1643
|
-
permission: ASSIGN_ROLES
|
|
1644
|
-
}
|
|
1645
|
-
};
|
|
1646
|
-
}
|
|
1647
|
-
//#endregion
|
|
1648
|
-
//#region ../../packages/config/src/org-zodiac.ts
|
|
1649
|
-
const MODULE_PROXY_FACTORY_ABI = [{
|
|
1650
|
-
type: "function",
|
|
1651
|
-
name: "deployModule",
|
|
1652
|
-
stateMutability: "nonpayable",
|
|
1653
|
-
inputs: [
|
|
1654
|
-
{
|
|
1655
|
-
name: "masterCopy",
|
|
1656
|
-
type: "address"
|
|
1657
|
-
},
|
|
1658
|
-
{
|
|
1659
|
-
name: "initializer",
|
|
1660
|
-
type: "bytes"
|
|
1661
|
-
},
|
|
1662
|
-
{
|
|
1663
|
-
name: "saltNonce",
|
|
1664
|
-
type: "uint256"
|
|
1665
|
-
}
|
|
1666
|
-
],
|
|
1667
|
-
outputs: [{
|
|
1668
|
-
name: "proxy",
|
|
1669
|
-
type: "address"
|
|
1670
|
-
}]
|
|
1671
|
-
}];
|
|
1672
|
-
const SAFE_ENABLE_MODULE_ABI = [{
|
|
1673
|
-
type: "function",
|
|
1674
|
-
name: "enableModule",
|
|
1675
|
-
stateMutability: "nonpayable",
|
|
1676
|
-
inputs: [{
|
|
1677
|
-
name: "module",
|
|
1678
|
-
type: "address"
|
|
1679
|
-
}],
|
|
1680
|
-
outputs: []
|
|
1681
|
-
}];
|
|
1682
|
-
const ROLES_SET_UP_ABI = [{
|
|
1683
|
-
type: "function",
|
|
1684
|
-
name: "setUp",
|
|
1685
|
-
stateMutability: "nonpayable",
|
|
1686
|
-
inputs: [{
|
|
1687
|
-
name: "initParams",
|
|
1688
|
-
type: "bytes"
|
|
1689
|
-
}],
|
|
1690
|
-
outputs: []
|
|
1691
|
-
}];
|
|
1692
|
-
const ROLES_SET_ALLOWANCE_ABI = [{
|
|
1693
|
-
type: "function",
|
|
1694
|
-
name: "setAllowance",
|
|
1695
|
-
stateMutability: "nonpayable",
|
|
1696
|
-
inputs: [
|
|
1697
|
-
{
|
|
1698
|
-
name: "key",
|
|
1699
|
-
type: "bytes32"
|
|
1700
|
-
},
|
|
1701
|
-
{
|
|
1702
|
-
name: "balance",
|
|
1703
|
-
type: "uint128"
|
|
1704
|
-
},
|
|
1705
|
-
{
|
|
1706
|
-
name: "maxRefill",
|
|
1707
|
-
type: "uint128"
|
|
1708
|
-
},
|
|
1709
|
-
{
|
|
1710
|
-
name: "refill",
|
|
1711
|
-
type: "uint128"
|
|
1712
|
-
},
|
|
1713
|
-
{
|
|
1714
|
-
name: "period",
|
|
1715
|
-
type: "uint64"
|
|
1716
|
-
},
|
|
1717
|
-
{
|
|
1718
|
-
name: "timestamp",
|
|
1719
|
-
type: "uint64"
|
|
1720
|
-
}
|
|
1721
|
-
],
|
|
1722
|
-
outputs: []
|
|
1723
|
-
}];
|
|
1724
|
-
const ROLES_SET_TRANSACTION_UNWRAPPER_ABI = [{
|
|
1725
|
-
type: "function",
|
|
1726
|
-
name: "setTransactionUnwrapper",
|
|
1727
|
-
stateMutability: "nonpayable",
|
|
1728
|
-
inputs: [
|
|
1729
|
-
{
|
|
1730
|
-
name: "target",
|
|
1731
|
-
type: "address"
|
|
1732
|
-
},
|
|
1733
|
-
{
|
|
1734
|
-
name: "selector",
|
|
1735
|
-
type: "bytes4"
|
|
1736
|
-
},
|
|
1737
|
-
{
|
|
1738
|
-
name: "adapter",
|
|
1739
|
-
type: "address"
|
|
1740
|
-
}
|
|
1741
|
-
],
|
|
1742
|
-
outputs: []
|
|
1743
|
-
}];
|
|
1744
|
-
const ROLES_ASSIGN_ROLES_ABI = [{
|
|
1745
|
-
type: "function",
|
|
1746
|
-
name: "assignRoles",
|
|
1747
|
-
stateMutability: "nonpayable",
|
|
1748
|
-
inputs: [
|
|
1749
|
-
{
|
|
1750
|
-
name: "module",
|
|
1751
|
-
type: "address"
|
|
1752
|
-
},
|
|
1753
|
-
{
|
|
1754
|
-
name: "roleKeys",
|
|
1755
|
-
type: "bytes32[]"
|
|
1756
|
-
},
|
|
1757
|
-
{
|
|
1758
|
-
name: "memberOf",
|
|
1759
|
-
type: "bool[]"
|
|
1760
|
-
}
|
|
1761
|
-
],
|
|
1762
|
-
outputs: []
|
|
1763
|
-
}];
|
|
1764
|
-
const ROLES_EXEC_TRANSACTION_WITH_ROLE_ABI = [{
|
|
1765
|
-
type: "function",
|
|
1766
|
-
name: "execTransactionWithRole",
|
|
1767
|
-
stateMutability: "nonpayable",
|
|
1768
|
-
inputs: [
|
|
1769
|
-
{
|
|
1770
|
-
name: "to",
|
|
1771
|
-
type: "address"
|
|
1772
|
-
},
|
|
1773
|
-
{
|
|
1774
|
-
name: "value",
|
|
1775
|
-
type: "uint256"
|
|
1776
|
-
},
|
|
1777
|
-
{
|
|
1778
|
-
name: "data",
|
|
1779
|
-
type: "bytes"
|
|
1780
|
-
},
|
|
1781
|
-
{
|
|
1782
|
-
name: "operation",
|
|
1783
|
-
type: "uint8"
|
|
1784
|
-
},
|
|
1785
|
-
{
|
|
1786
|
-
name: "roleKey",
|
|
1787
|
-
type: "bytes32"
|
|
1788
|
-
},
|
|
1789
|
-
{
|
|
1790
|
-
name: "shouldRevert",
|
|
1791
|
-
type: "bool"
|
|
1792
|
-
}
|
|
1793
|
-
],
|
|
1794
|
-
outputs: [{
|
|
1795
|
-
name: "success",
|
|
1796
|
-
type: "bool"
|
|
1797
|
-
}]
|
|
1798
|
-
}];
|
|
1799
|
-
const ORG_ROLE_ALLOWANCE_KEYS = {
|
|
1800
|
-
financeManagerDaily: padHex(stringToHex("FM_DAILY"), {
|
|
1801
|
-
size: 32,
|
|
1802
|
-
dir: "right"
|
|
1803
|
-
}),
|
|
1804
|
-
teamLeadDaily: padHex(stringToHex("TL_DAILY"), {
|
|
1805
|
-
size: 32,
|
|
1806
|
-
dir: "right"
|
|
1807
|
-
})
|
|
1808
|
-
};
|
|
1809
|
-
const MULTI_SEND_SELECTOR = "0x8d80ff0a";
|
|
1810
|
-
padHex(concat([MULTI_SEND_CALL_ONLY, MULTI_SEND_SELECTOR]), {
|
|
1811
|
-
dir: "right",
|
|
1812
|
-
size: 32
|
|
1813
|
-
});
|
|
1814
|
-
const ONE_DAY_SECONDS = 86400n;
|
|
1815
|
-
const ZODIAC_OPERATION_CALL = 0;
|
|
1816
|
-
const EXEC_TRANSACTION_WITH_ROLE = "zodiac.roles.execTransactionWithRole";
|
|
1817
|
-
const ROLE_MANAGEMENT_SIGNATURES = [
|
|
1818
|
-
"allowTarget(bytes32,address,uint8)",
|
|
1819
|
-
"scopeTarget(bytes32,address)",
|
|
1820
|
-
"revokeTarget(bytes32,address)",
|
|
1821
|
-
"allowFunction(bytes32,address,bytes4,uint8)",
|
|
1822
|
-
"scopeFunction(bytes32,address,bytes4,(uint8,uint8,uint8,bytes)[],uint8)",
|
|
1823
|
-
"revokeFunction(bytes32,address,bytes4)",
|
|
1824
|
-
"setAllowance(bytes32,uint128,uint128,uint128,uint64,uint64)"
|
|
1825
|
-
];
|
|
1826
|
-
const PARAMETER_TYPE = {
|
|
1827
|
-
none: 0,
|
|
1828
|
-
static: 1,
|
|
1829
|
-
calldata: 5
|
|
1830
|
-
};
|
|
1831
|
-
const OPERATOR = {
|
|
1832
|
-
pass: 0,
|
|
1833
|
-
and: 1,
|
|
1834
|
-
or: 2,
|
|
1835
|
-
matches: 5,
|
|
1836
|
-
equalTo: 16,
|
|
1837
|
-
lessThan: 18,
|
|
1838
|
-
withinAllowance: 28
|
|
1839
|
-
};
|
|
1840
|
-
function normalizeHexAddress(address) {
|
|
1841
|
-
return address.toLowerCase();
|
|
1842
|
-
}
|
|
1843
|
-
function orgRoleAllowanceKeyForLabel(label) {
|
|
1844
|
-
const normalized = normalizeOrgRoleLabel(label);
|
|
1845
|
-
switch (normalized) {
|
|
1846
|
-
case "Finance Manager": return ORG_ROLE_ALLOWANCE_KEYS.financeManagerDaily;
|
|
1847
|
-
case "Team Lead": return ORG_ROLE_ALLOWANCE_KEYS.teamLeadDaily;
|
|
1848
|
-
default: return keccak256(stringToHex(`CAPXUL_ORG_DAILY_ALLOWANCE:${normalized.toLowerCase()}`));
|
|
1849
|
-
}
|
|
1850
|
-
}
|
|
1851
|
-
function passStatic() {
|
|
1852
|
-
return {
|
|
1853
|
-
paramType: PARAMETER_TYPE.static,
|
|
1854
|
-
operator: OPERATOR.pass
|
|
1855
|
-
};
|
|
1856
|
-
}
|
|
1857
|
-
function equalAddress(address) {
|
|
1858
|
-
return {
|
|
1859
|
-
paramType: PARAMETER_TYPE.static,
|
|
1860
|
-
operator: OPERATOR.equalTo,
|
|
1861
|
-
compValue: encodeAbiParameters([{ type: "address" }], [address])
|
|
1862
|
-
};
|
|
1863
|
-
}
|
|
1864
|
-
function lteUint256(value) {
|
|
1865
|
-
return {
|
|
1866
|
-
paramType: PARAMETER_TYPE.static,
|
|
1867
|
-
operator: OPERATOR.lessThan,
|
|
1868
|
-
compValue: encodeAbiParameters([{ type: "uint256" }], [BigInt(value) + 1n])
|
|
1869
|
-
};
|
|
1870
|
-
}
|
|
1871
|
-
function withinAllowance(allowanceKey) {
|
|
1872
|
-
return {
|
|
1873
|
-
paramType: PARAMETER_TYPE.static,
|
|
1874
|
-
operator: OPERATOR.withinAllowance,
|
|
1875
|
-
compValue: encodeAbiParameters([{ type: "bytes32" }], [allowanceKey])
|
|
1876
|
-
};
|
|
1877
|
-
}
|
|
1878
|
-
function and(...children) {
|
|
1879
|
-
return {
|
|
1880
|
-
paramType: PARAMETER_TYPE.none,
|
|
1881
|
-
operator: OPERATOR.and,
|
|
1882
|
-
children
|
|
1883
|
-
};
|
|
1884
|
-
}
|
|
1885
|
-
function calldataMatches(children) {
|
|
1886
|
-
return {
|
|
1887
|
-
paramType: PARAMETER_TYPE.calldata,
|
|
1888
|
-
operator: OPERATOR.matches,
|
|
1889
|
-
children
|
|
1890
|
-
};
|
|
1891
|
-
}
|
|
1892
|
-
/**
|
|
1893
|
-
* The on-chain recipient condition for a role's `toRecipients` scope. `"anyone"`
|
|
1894
|
-
* (or an empty/undefined set) leaves the recipient param unconstrained on-chain
|
|
1895
|
-
* (`passStatic` — recipient validation is the Level-2 off-chain guard). A FIXED
|
|
1896
|
-
* recipient set compiles to an `Or` over per-address equality so the on-chain
|
|
1897
|
-
* Roles modifier itself refuses any recipient outside the set — this is the
|
|
1898
|
-
* treasury-drain boundary for createCommitment / redirect, not just `send`.
|
|
1899
|
-
*/
|
|
1900
|
-
function recipientCondition(toRecipients) {
|
|
1901
|
-
if (toRecipients === void 0 || toRecipients === "anyone" || toRecipients.length === 0) return passStatic();
|
|
1902
|
-
const equals = toRecipients.map((address) => equalAddress(normalizeHexAddress(address)));
|
|
1903
|
-
return equals.length === 1 ? equals[0] : orMatch(equals);
|
|
1904
|
-
}
|
|
1905
|
-
function orMatch(children) {
|
|
1906
|
-
return {
|
|
1907
|
-
paramType: PARAMETER_TYPE.none,
|
|
1908
|
-
operator: OPERATOR.or,
|
|
1909
|
-
children
|
|
1910
|
-
};
|
|
1911
|
-
}
|
|
1912
|
-
function encodeRolesSetUpCall(input) {
|
|
1913
|
-
return encodeFunctionData({
|
|
1914
|
-
abi: ROLES_SET_UP_ABI,
|
|
1915
|
-
functionName: "setUp",
|
|
1916
|
-
args: [encodeAbiParameters(parseAbiParameters("address, address, address"), [
|
|
1917
|
-
input.owner,
|
|
1918
|
-
input.avatar,
|
|
1919
|
-
input.target
|
|
1920
|
-
])]
|
|
1921
|
-
});
|
|
1922
|
-
}
|
|
1923
|
-
function computeOrgRolesModuleAddress(input) {
|
|
1924
|
-
const saltNonce = input.saltNonce ?? 0n;
|
|
1925
|
-
const proxyInitCode = "0x602d8060093d393df3363d3d373d3d3d363d73" + ROLES_MASTERCOPY.slice(2).toLowerCase() + "5af43d82803e903d91602b57fd5bf3";
|
|
1926
|
-
return normalizeHexAddress(getContractAddress({
|
|
1927
|
-
opcode: "CREATE2",
|
|
1928
|
-
from: ZODIAC_MODULE_PROXY_FACTORY,
|
|
1929
|
-
salt: keccak256(keccak256(encodeRolesSetUpCall(input)) + encodeAbiParameters(parseAbiParameters("uint256"), [saltNonce]).slice(2)),
|
|
1930
|
-
bytecodeHash: keccak256(proxyInitCode)
|
|
1931
|
-
}));
|
|
1932
|
-
}
|
|
1933
|
-
function buildDeployModuleCall(input) {
|
|
1934
|
-
return {
|
|
1935
|
-
to: ZODIAC_MODULE_PROXY_FACTORY,
|
|
1936
|
-
data: encodeFunctionData({
|
|
1937
|
-
abi: MODULE_PROXY_FACTORY_ABI,
|
|
1938
|
-
functionName: "deployModule",
|
|
1939
|
-
args: [
|
|
1940
|
-
ROLES_MASTERCOPY,
|
|
1941
|
-
encodeRolesSetUpCall({
|
|
1942
|
-
owner: input.safeAddress,
|
|
1943
|
-
avatar: input.safeAddress,
|
|
1944
|
-
target: input.safeAddress
|
|
1945
|
-
}),
|
|
1946
|
-
input.saltNonce
|
|
1947
|
-
]
|
|
1948
|
-
}),
|
|
1949
|
-
value: 0n
|
|
1950
|
-
};
|
|
1951
|
-
}
|
|
1952
|
-
function buildEnableModuleCall(input) {
|
|
1953
|
-
return {
|
|
1954
|
-
to: input.safeAddress,
|
|
1955
|
-
data: encodeFunctionData({
|
|
1956
|
-
abi: SAFE_ENABLE_MODULE_ABI,
|
|
1957
|
-
functionName: "enableModule",
|
|
1958
|
-
args: [input.rolesModuleAddress]
|
|
1959
|
-
}),
|
|
1960
|
-
value: 0n
|
|
1961
|
-
};
|
|
1962
|
-
}
|
|
1963
|
-
function buildSetUnwrapperCall(rolesModuleAddress) {
|
|
1964
|
-
return {
|
|
1965
|
-
to: rolesModuleAddress,
|
|
1966
|
-
data: encodeFunctionData({
|
|
1967
|
-
abi: ROLES_SET_TRANSACTION_UNWRAPPER_ABI,
|
|
1968
|
-
functionName: "setTransactionUnwrapper",
|
|
1969
|
-
args: [
|
|
1970
|
-
MULTI_SEND_CALL_ONLY,
|
|
1971
|
-
MULTI_SEND_SELECTOR,
|
|
1972
|
-
ZODIAC_MULTI_SEND_UNWRAPPER
|
|
1973
|
-
]
|
|
1974
|
-
}),
|
|
1975
|
-
value: 0n
|
|
1976
|
-
};
|
|
1977
|
-
}
|
|
1978
|
-
function buildSetAllowanceCall(input) {
|
|
1979
|
-
const dailyCap = BigInt(input.dailyCap);
|
|
1980
|
-
return {
|
|
1981
|
-
to: input.rolesModuleAddress,
|
|
1982
|
-
data: encodeFunctionData({
|
|
1983
|
-
abi: ROLES_SET_ALLOWANCE_ABI,
|
|
1984
|
-
functionName: "setAllowance",
|
|
1985
|
-
args: [
|
|
1986
|
-
input.allowanceKey,
|
|
1987
|
-
dailyCap,
|
|
1988
|
-
dailyCap,
|
|
1989
|
-
dailyCap,
|
|
1990
|
-
ONE_DAY_SECONDS,
|
|
1991
|
-
0n
|
|
1992
|
-
]
|
|
1993
|
-
}),
|
|
1994
|
-
value: 0n
|
|
1995
|
-
};
|
|
1996
|
-
}
|
|
1997
|
-
function buildTemplateAllowanceCalls(input) {
|
|
1998
|
-
return input.roles.flatMap((role) => {
|
|
1999
|
-
const dailyCap = role?.allowance?.perDay?.value;
|
|
2000
|
-
return dailyCap === void 0 ? [] : [buildSetAllowanceCall({
|
|
2001
|
-
rolesModuleAddress: input.rolesModuleAddress,
|
|
2002
|
-
allowanceKey: orgRoleAllowanceKeyForLabel(role.label),
|
|
2003
|
-
dailyCap
|
|
2004
|
-
})];
|
|
2005
|
-
});
|
|
2006
|
-
}
|
|
2007
|
-
const CREATE_COMMITMENT_SIGNATURE = "createCommitment(address,address,uint256,uint48,uint48,uint48,bytes32,uint8)";
|
|
2008
|
-
const CANCEL_SIGNATURE = "cancel(uint256,bytes32)";
|
|
2009
|
-
const REDIRECT_SIGNATURE = "redirect(uint256,address,bytes32)";
|
|
2010
|
-
function approvePermission() {
|
|
2011
|
-
return {
|
|
2012
|
-
targetAddress: USDX_ADDRESS_BASE_SEPOLIA,
|
|
2013
|
-
signature: "approve(address,uint256)",
|
|
2014
|
-
condition: calldataMatches([equalAddress(CAPXUL_PAYMENTS_ADDRESS), passStatic()])
|
|
2015
|
-
};
|
|
2016
|
-
}
|
|
2017
|
-
function paymentPermissions(input) {
|
|
2018
|
-
return [approvePermission(), {
|
|
2019
|
-
targetAddress: CAPXUL_PAYMENTS_ADDRESS,
|
|
2020
|
-
signature: "send(address,address,uint256,bytes32,uint8)",
|
|
2021
|
-
condition: calldataMatches([
|
|
2022
|
-
equalAddress(USDX_ADDRESS_BASE_SEPOLIA),
|
|
2023
|
-
input.recipient,
|
|
2024
|
-
and(lteUint256(input.perTxCap), withinAllowance(input.allowanceKey)),
|
|
2025
|
-
passStatic(),
|
|
2026
|
-
passStatic()
|
|
2027
|
-
])
|
|
2028
|
-
}];
|
|
2029
|
-
}
|
|
2030
|
-
function uncappedPaymentPermissions() {
|
|
2031
|
-
return [approvePermission(), {
|
|
2032
|
-
targetAddress: CAPXUL_PAYMENTS_ADDRESS,
|
|
2033
|
-
signature: "send(address,address,uint256,bytes32,uint8)",
|
|
2034
|
-
condition: calldataMatches([
|
|
2035
|
-
equalAddress(USDX_ADDRESS_BASE_SEPOLIA),
|
|
2036
|
-
passStatic(),
|
|
2037
|
-
passStatic(),
|
|
2038
|
-
passStatic(),
|
|
2039
|
-
passStatic()
|
|
2040
|
-
])
|
|
2041
|
-
}];
|
|
2042
|
-
}
|
|
2043
|
-
/**
|
|
2044
|
-
* Commitment-verb permissions for a CAPPED role (#488 / G4 #547). `createCommitment`
|
|
2045
|
-
* carries the SAME on-chain conditions as `send`: token == USDX, the recipient
|
|
2046
|
-
* is in the role's allowed set, and the escrowed `totalAmount` is `<= perTx cap`
|
|
2047
|
-
* AND `withinAllowance(perDay key)`. `redirect` re-pins `newRecipient` to the
|
|
2048
|
-
* same allowed set (it changes who receives, so it is a recipient-boundary op).
|
|
2049
|
-
* `cancel` only reclaims unvested funds from a commitment the role created and
|
|
2050
|
-
* carries no recipient/amount, so it is allow-listed by selector with no comp
|
|
2051
|
-
* value. `claim` is NEVER emitted — it is recipient-side, not treasury authority.
|
|
2052
|
-
*/
|
|
2053
|
-
function commitmentPermissions(input) {
|
|
2054
|
-
return [
|
|
2055
|
-
{
|
|
2056
|
-
targetAddress: CAPXUL_PAYMENTS_ADDRESS,
|
|
2057
|
-
signature: CREATE_COMMITMENT_SIGNATURE,
|
|
2058
|
-
condition: calldataMatches([
|
|
2059
|
-
equalAddress(USDX_ADDRESS_BASE_SEPOLIA),
|
|
2060
|
-
input.recipient,
|
|
2061
|
-
and(lteUint256(input.perTxCap), withinAllowance(input.allowanceKey)),
|
|
2062
|
-
passStatic(),
|
|
2063
|
-
passStatic(),
|
|
2064
|
-
passStatic(),
|
|
2065
|
-
passStatic(),
|
|
2066
|
-
passStatic()
|
|
2067
|
-
])
|
|
2068
|
-
},
|
|
2069
|
-
{
|
|
2070
|
-
targetAddress: CAPXUL_PAYMENTS_ADDRESS,
|
|
2071
|
-
signature: REDIRECT_SIGNATURE,
|
|
2072
|
-
condition: calldataMatches([
|
|
2073
|
-
passStatic(),
|
|
2074
|
-
input.recipient,
|
|
2075
|
-
passStatic()
|
|
2076
|
-
])
|
|
2077
|
-
},
|
|
2078
|
-
{
|
|
2079
|
-
targetAddress: CAPXUL_PAYMENTS_ADDRESS,
|
|
2080
|
-
signature: CANCEL_SIGNATURE,
|
|
2081
|
-
condition: calldataMatches([passStatic(), passStatic()])
|
|
2082
|
-
}
|
|
2083
|
-
];
|
|
2084
|
-
}
|
|
2085
|
-
/** Uncapped commitment permissions for the Owner role (no per-tx/recipient cap). */
|
|
2086
|
-
function uncappedCommitmentPermissions() {
|
|
2087
|
-
return [
|
|
2088
|
-
{
|
|
2089
|
-
targetAddress: CAPXUL_PAYMENTS_ADDRESS,
|
|
2090
|
-
signature: CREATE_COMMITMENT_SIGNATURE,
|
|
2091
|
-
condition: calldataMatches([
|
|
2092
|
-
equalAddress(USDX_ADDRESS_BASE_SEPOLIA),
|
|
2093
|
-
passStatic(),
|
|
2094
|
-
passStatic(),
|
|
2095
|
-
passStatic(),
|
|
2096
|
-
passStatic(),
|
|
2097
|
-
passStatic(),
|
|
2098
|
-
passStatic(),
|
|
2099
|
-
passStatic()
|
|
2100
|
-
])
|
|
2101
|
-
},
|
|
2102
|
-
{
|
|
2103
|
-
targetAddress: CAPXUL_PAYMENTS_ADDRESS,
|
|
2104
|
-
signature: REDIRECT_SIGNATURE,
|
|
2105
|
-
condition: calldataMatches([
|
|
2106
|
-
passStatic(),
|
|
2107
|
-
passStatic(),
|
|
2108
|
-
passStatic()
|
|
2109
|
-
])
|
|
2110
|
-
},
|
|
2111
|
-
{
|
|
2112
|
-
targetAddress: CAPXUL_PAYMENTS_ADDRESS,
|
|
2113
|
-
signature: CANCEL_SIGNATURE,
|
|
2114
|
-
condition: calldataMatches([passStatic(), passStatic()])
|
|
2115
|
-
}
|
|
2116
|
-
];
|
|
2117
|
-
}
|
|
2118
|
-
function rolePermissions(input) {
|
|
2119
|
-
const permissions = [];
|
|
2120
|
-
if (input.role.definition.canManageMembers === true) permissions.push({
|
|
2121
|
-
targetAddress: input.rolesModuleAddress,
|
|
2122
|
-
signature: "assignRoles(address,bytes32[],bool[])"
|
|
2123
|
-
});
|
|
2124
|
-
if (input.role.definition.canManageRoles === true) permissions.push(...ROLE_MANAGEMENT_SIGNATURES.map((signature) => ({
|
|
2125
|
-
targetAddress: input.rolesModuleAddress,
|
|
2126
|
-
signature
|
|
2127
|
-
})));
|
|
2128
|
-
if (input.role.allowance === null && input.role.permissions.includes(EXEC_TRANSACTION_WITH_ROLE)) permissions.push(...uncappedPaymentPermissions(), ...uncappedCommitmentPermissions());
|
|
2129
|
-
if (input.role.allowance?.perTx !== void 0 && input.role.allowance.perDay !== void 0) {
|
|
2130
|
-
const allowanceKey = orgRoleAllowanceKeyForLabel(input.role.label);
|
|
2131
|
-
const perTxCap = input.role.allowance.perTx.value;
|
|
2132
|
-
const recipient = recipientCondition(input.role.allowance.toRecipients);
|
|
2133
|
-
permissions.push(...paymentPermissions({
|
|
2134
|
-
allowanceKey,
|
|
2135
|
-
perTxCap,
|
|
2136
|
-
recipient
|
|
2137
|
-
}), ...commitmentPermissions({
|
|
2138
|
-
allowanceKey,
|
|
2139
|
-
perTxCap,
|
|
2140
|
-
recipient
|
|
2141
|
-
}));
|
|
2142
|
-
}
|
|
2143
|
-
return permissions;
|
|
2144
|
-
}
|
|
2145
|
-
async function getZodiacSdk() {
|
|
2146
|
-
return await import("./src-Iv70gRG_.mjs");
|
|
2147
|
-
}
|
|
2148
|
-
async function buildRoleSetupCalls(input) {
|
|
2149
|
-
const managerRoleKey = input.managerRoleKey.toLowerCase();
|
|
2150
|
-
const roles = input.roles.map((role) => ({
|
|
2151
|
-
key: role.roleKey,
|
|
2152
|
-
members: role.roleKey.toLowerCase() === managerRoleKey ? [input.ownerAddress] : [],
|
|
2153
|
-
permissions: rolePermissions({
|
|
2154
|
-
role,
|
|
2155
|
-
rolesModuleAddress: input.rolesModuleAddress
|
|
2156
|
-
})
|
|
2157
|
-
}));
|
|
2158
|
-
return (await getZodiacSdk()).setUpRoles({
|
|
2159
|
-
address: input.rolesModuleAddress,
|
|
2160
|
-
roles
|
|
2161
|
-
}).map((call) => ({
|
|
2162
|
-
to: normalizeHexAddress(call.to),
|
|
2163
|
-
data: call.data,
|
|
2164
|
-
value: BigInt(call.value)
|
|
2165
|
-
}));
|
|
2166
|
-
}
|
|
2167
|
-
async function buildOrgRolesDeployCalls(input) {
|
|
2168
|
-
const safeAddress = normalizeHexAddress(input.safeAddress);
|
|
2169
|
-
const ownerAddress = normalizeHexAddress(input.ownerAddress);
|
|
2170
|
-
const saltNonce = input.saltNonce ?? 0n;
|
|
2171
|
-
const compiled = compileOrgRoleDefinitions(input.roleDefinitions ?? startupOrgRoleTemplate());
|
|
2172
|
-
const rolesModuleAddress = computeOrgRolesModuleAddress({
|
|
2173
|
-
owner: safeAddress,
|
|
2174
|
-
avatar: safeAddress,
|
|
2175
|
-
target: safeAddress,
|
|
2176
|
-
saltNonce
|
|
2177
|
-
});
|
|
2178
|
-
return {
|
|
2179
|
-
rolesModuleAddress,
|
|
2180
|
-
calls: [
|
|
2181
|
-
buildDeployModuleCall({
|
|
2182
|
-
safeAddress,
|
|
2183
|
-
saltNonce
|
|
2184
|
-
}),
|
|
2185
|
-
buildEnableModuleCall({
|
|
2186
|
-
safeAddress,
|
|
2187
|
-
rolesModuleAddress
|
|
2188
|
-
}),
|
|
2189
|
-
buildSetUnwrapperCall(rolesModuleAddress),
|
|
2190
|
-
...buildTemplateAllowanceCalls({
|
|
2191
|
-
rolesModuleAddress,
|
|
2192
|
-
roles: compiled.roles
|
|
2193
|
-
}),
|
|
2194
|
-
...await buildRoleSetupCalls({
|
|
2195
|
-
rolesModuleAddress,
|
|
2196
|
-
ownerAddress,
|
|
2197
|
-
roles: compiled.roles,
|
|
2198
|
-
managerRoleKey: compiled.memberManagementRole.roleKey
|
|
2199
|
-
})
|
|
2200
|
-
]
|
|
2201
|
-
};
|
|
2202
|
-
}
|
|
2203
|
-
function buildOrgRoleAssignmentCall(input) {
|
|
2204
|
-
const rolesModuleAddress = normalizeHexAddress(input.rolesModuleAddress);
|
|
2205
|
-
const memberAddress = normalizeHexAddress(input.memberAddress);
|
|
2206
|
-
const roleKey = input.roleKey.toLowerCase();
|
|
2207
|
-
const managerRoleKey = input.managerRoleKey.toLowerCase();
|
|
2208
|
-
return {
|
|
2209
|
-
to: rolesModuleAddress,
|
|
2210
|
-
data: encodeFunctionData({
|
|
2211
|
-
abi: ROLES_EXEC_TRANSACTION_WITH_ROLE_ABI,
|
|
2212
|
-
functionName: "execTransactionWithRole",
|
|
2213
|
-
args: [
|
|
2214
|
-
rolesModuleAddress,
|
|
2215
|
-
0n,
|
|
2216
|
-
encodeFunctionData({
|
|
2217
|
-
abi: ROLES_ASSIGN_ROLES_ABI,
|
|
2218
|
-
functionName: "assignRoles",
|
|
2219
|
-
args: [
|
|
2220
|
-
memberAddress,
|
|
2221
|
-
[roleKey],
|
|
2222
|
-
[input.memberOf]
|
|
2223
|
-
]
|
|
2224
|
-
}),
|
|
2225
|
-
ZODIAC_OPERATION_CALL,
|
|
2226
|
-
managerRoleKey,
|
|
2227
|
-
true
|
|
2228
|
-
]
|
|
2229
|
-
}),
|
|
2230
|
-
value: 0n
|
|
2231
|
-
};
|
|
2232
|
-
}
|
|
2233
|
-
new Map([
|
|
2234
|
-
["assignRoles(address,bytes32[],bool[])", "AssignRoles(address,bytes32[],bool[])"],
|
|
2235
|
-
["allowTarget(bytes32,address,uint8)", "AllowTarget(bytes32,address,uint8)"],
|
|
2236
|
-
["scopeTarget(bytes32,address)", "ScopeTarget(bytes32,address)"],
|
|
2237
|
-
["revokeTarget(bytes32,address)", "RevokeTarget(bytes32,address)"],
|
|
2238
|
-
["allowFunction(bytes32,address,bytes4,uint8)", "AllowFunction(bytes32,address,bytes4,uint8)"],
|
|
2239
|
-
["scopeFunction(bytes32,address,bytes4,(uint8,uint8,uint8,bytes)[],uint8)", "ScopeFunction(bytes32,address,bytes4,(uint8,uint8,uint8,bytes)[],uint8)"],
|
|
2240
|
-
["revokeFunction(bytes32,address,bytes4)", "RevokeFunction(bytes32,address,bytes4)"],
|
|
2241
|
-
["setAllowance(bytes32,uint128,uint128,uint128,uint64,uint64)", "SetAllowance(bytes32,uint128,uint128,uint128,uint64,uint64)"]
|
|
2242
|
-
].map(([functionSignature, eventSignature]) => [toFunctionSelector(functionSignature), toEventSelector(eventSignature)]));
|
|
2243
|
-
//#endregion
|
|
2244
|
-
export { buildCapxulCommitmentRedirectCallData as $, SAFE_MODULE_SETUP as A, safe4337PaymasterAndData as B, BASE_SEPOLIA_CHAIN_ID as C, MULTI_SEND as D, ENTRY_POINT_07_ADDRESS as E, deriveCapxulSafeAddress as F, CAPXUL_PAYMENTS_SEND_ABI as G, safe4337StubSignature as H, deriveCapxulSafeAddressForOwner as I, ROLES_MASTERCOPY as J, ERC20_APPROVE_ABI as K, normalizeSafeSaltEmail as L, SAFE_PROXY_FACTORY as M, buildSafeMultiSendExecTransactionCall as N, SAFE_4337_MODULE as O, computeCapxulSafeSaltNonce as P, buildCapxulCommitmentClaimCallData as Q, packSafe4337OwnerSignature as R, normalizeBindingEmail as S, CAPXUL_SAFE_SALT_NAMESPACE as T, CAPXUL_PAYMENTS_ADDRESS as U, safe4337SafeOpDigest as V, CAPXUL_PAYMENTS_COMMITMENT_ABI as W, ZODIAC_MULTI_SEND_UNWRAPPER as X, ZODIAC_MODULE_PROXY_FACTORY as Y, buildCapxulCommitmentCancelCallData as Z, normalizeOrgHandle as _, computeOrgRolesModuleAddress as a, buildOrgRoleSpendPersonalCallData as at, USDX_BASE_SEPOLIA_TOKEN as b, normalizeOrgRoleLabel as c, isExactTransferTokenAllowed as ct, soloOrgRoleTemplate as d, EXPECTED_OPERATION_OUTCOMES as dt, buildCapxulCreateCommitmentPersonalCallData as et, startupOrgRoleTemplate as f, Errors as ft, deriveCapxulOrgAddress as g, computeCapxulOrgSaltNonce as h, buildOrgRolesDeployCalls as i, buildOrgPersonalMultiCallData as it, SAFE_PROXY_CREATION_CODE as j, SAFE_L2_SINGLETON as k, orgRoleKeyForLabel as l, decodeConvexError as lt, buildCapxulOrgInitializer as m, isCapxulError as mt, ORG_ROLE_ALLOWANCE_KEYS as n, buildCapxulPaymentsRoleBatchSpendCall as nt, orgRoleAllowanceKeyForLabel as o, EXACT_TRANSFER_TOKEN_ALLOWLIST as ot, CAPXUL_ORG_SALT_NAMESPACE as p, deserializeCapxulError as pt, MULTI_SEND_CALL_ONLY as q, buildOrgRoleAssignmentCall as r, buildCapxulPaymentsSendCalls as rt, compileOrgRoleDefinitions as s, USDX_ADDRESS_BASE_SEPOLIA as st, MULTI_SEND_SELECTOR as t, buildCapxulPaymentsPersonalSendCallData as tt, orgRoleTemplateDefinitions as u, CapxulError as ut, validateOrgHandle as v, CAPXUL_BOOTSTRAP_OWNER as w, CAPXUL_BINDING_EMAIL_NAMESPACE as x, DIRECT_BASE_ROUTE as y, safe4337InitCode as z };
|