@capxul/mcp 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/main.mjs +363 -523
  2. package/package.json +5 -5
package/dist/main.mjs CHANGED
@@ -240,7 +240,7 @@ function normalizeEmail(email) {
240
240
  }
241
241
  //#endregion
242
242
  //#region package.json
243
- var version$2 = "2.1.0";
243
+ var version$2 = "2.1.1";
244
244
  //#endregion
245
245
  //#region ../../packages/errors/src/errors.ts
246
246
  const CAPXUL_ERROR_CODES = [
@@ -492,8 +492,6 @@ function isExactTransferTokenAllowed(tokenAddress) {
492
492
  //#region ../../packages/config/src/org-payments.ts
493
493
  /** Zodiac MultiSendCallOnly module on Base Sepolia. */
494
494
  const MULTI_SEND_CALL_ONLY = "0x9641d764fc13c8b624c04430c7356c1c7c8102e2";
495
- /** CapxulPayments proxy on Base Sepolia. */
496
- const CAPXUL_PAYMENTS_ADDRESS = "0xe740ea65521edc9bef0ea75d30b5334711db99f4";
497
495
  const SAFE4337_EXECUTE_USEROP_ABI = [{
498
496
  type: "function",
499
497
  name: "executeUserOpWithErrorString",
@@ -523,12 +521,7 @@ function normalizeAddress(address, field) {
523
521
  if (!isAddress(address)) throw new RangeError(`${field} must be a valid EVM address`);
524
522
  return address.toLowerCase();
525
523
  }
526
- /**
527
- * Wrap an org Roles `execTransactionWithRole` call (from `*RoleSpendCall` /
528
- * `*RoleBatchSpendCall`) into the member Safe's `executeUserOpWithErrorString`
529
- * (operation = CALL into the Roles module) — the full Safe callData a sponsored
530
- * UserOp from the member's personal Safe carries (G4 · #547).
531
- */
524
+ /** Wrap a Zodiac Roles call for a member Safe. */
532
525
  function buildOrgRoleSpendPersonalCallData(roleSpendCall) {
533
526
  return encodeFunctionData({
534
527
  abi: SAFE4337_EXECUTE_USEROP_ABI,
@@ -541,162 +534,6 @@ function buildOrgRoleSpendPersonalCallData(roleSpendCall) {
541
534
  ]
542
535
  });
543
536
  }
544
- const CAPXUL_PAYMENTS_COMMITMENT_ABI = [
545
- {
546
- type: "function",
547
- name: "createCommitment",
548
- stateMutability: "nonpayable",
549
- inputs: [
550
- {
551
- name: "token",
552
- type: "address"
553
- },
554
- {
555
- name: "recipient",
556
- type: "address"
557
- },
558
- {
559
- name: "totalAmount",
560
- type: "uint256"
561
- },
562
- {
563
- name: "startTime",
564
- type: "uint48"
565
- },
566
- {
567
- name: "cliffTime",
568
- type: "uint48"
569
- },
570
- {
571
- name: "endTime",
572
- type: "uint48"
573
- },
574
- {
575
- name: "documentHash",
576
- type: "bytes32"
577
- },
578
- {
579
- name: "paymentType",
580
- type: "uint8"
581
- }
582
- ],
583
- outputs: [{
584
- name: "commitmentId",
585
- type: "uint256"
586
- }]
587
- },
588
- {
589
- type: "function",
590
- name: "claim",
591
- stateMutability: "nonpayable",
592
- inputs: [{
593
- name: "commitmentId",
594
- type: "uint256"
595
- }],
596
- outputs: []
597
- },
598
- {
599
- type: "function",
600
- name: "cancel",
601
- stateMutability: "nonpayable",
602
- inputs: [{
603
- name: "commitmentId",
604
- type: "uint256"
605
- }, {
606
- name: "documentHash",
607
- type: "bytes32"
608
- }],
609
- outputs: []
610
- },
611
- {
612
- type: "function",
613
- name: "redirect",
614
- stateMutability: "nonpayable",
615
- inputs: [
616
- {
617
- name: "commitmentId",
618
- type: "uint256"
619
- },
620
- {
621
- name: "newRecipient",
622
- type: "address"
623
- },
624
- {
625
- name: "newDocumentHash",
626
- type: "bytes32"
627
- }
628
- ],
629
- outputs: []
630
- },
631
- {
632
- type: "function",
633
- name: "claimableAmount",
634
- stateMutability: "view",
635
- inputs: [{
636
- name: "commitmentId",
637
- type: "uint256"
638
- }],
639
- outputs: [{
640
- name: "",
641
- type: "uint256"
642
- }]
643
- },
644
- {
645
- type: "function",
646
- name: "commitments",
647
- stateMutability: "view",
648
- inputs: [{
649
- name: "",
650
- type: "uint256"
651
- }],
652
- outputs: [
653
- {
654
- name: "creator",
655
- type: "address"
656
- },
657
- {
658
- name: "token",
659
- type: "address"
660
- },
661
- {
662
- name: "recipient",
663
- type: "address"
664
- },
665
- {
666
- name: "totalAmount",
667
- type: "uint256"
668
- },
669
- {
670
- name: "claimed",
671
- type: "uint256"
672
- },
673
- {
674
- name: "startTime",
675
- type: "uint48"
676
- },
677
- {
678
- name: "cliffTime",
679
- type: "uint48"
680
- },
681
- {
682
- name: "endTime",
683
- type: "uint48"
684
- },
685
- {
686
- name: "documentHash",
687
- type: "bytes32"
688
- },
689
- {
690
- name: "paymentType",
691
- type: "uint8"
692
- },
693
- {
694
- name: "cancelled",
695
- type: "bool"
696
- }
697
- ]
698
- }
699
- ];
700
537
  //#endregion
701
538
  //#region ../../packages/config/src/safe.ts
702
539
  const BASE_SEPOLIA_CHAIN_ID = 84532;
@@ -1048,348 +885,6 @@ function normalizeBindingEmail(email) {
1048
885
  return normalizeSafeSaltEmail(email);
1049
886
  }
1050
887
  //#endregion
1051
- //#region ../../packages/config/src/route.ts
1052
- /** USDX on Base Sepolia — the only settlement token in v1. */
1053
- const USDX_BASE_SEPOLIA_TOKEN = {
1054
- chainId: BASE_SEPOLIA_CHAIN_ID,
1055
- address: USDX_ADDRESS_BASE_SEPOLIA,
1056
- decimals: 6
1057
- };
1058
- /**
1059
- * The `direct-base` settlement route: USDX on Base Sepolia, settled directly
1060
- * through the `CapxulPayments` contract. This is the ONLY route implemented in
1061
- * D1; the `Route` shape is the seam future provider routes slot into.
1062
- */
1063
- const DIRECT_BASE_ROUTE = {
1064
- kind: "direct-base",
1065
- token: USDX_BASE_SEPOLIA_TOKEN,
1066
- chainId: USDX_BASE_SEPOLIA_TOKEN.chainId,
1067
- verifyingContract: CAPXUL_PAYMENTS_ADDRESS
1068
- };
1069
- USDX_BASE_SEPOLIA_TOKEN.chainId;
1070
- const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
1071
- const ORG_HANDLE_REGEX = /^[a-z0-9-]{3,32}$/;
1072
- const ADDRESS_REGEX = /^0x[0-9a-f]{40}$/;
1073
- const safeSetupAbi = [{
1074
- type: "function",
1075
- name: "setup",
1076
- stateMutability: "nonpayable",
1077
- inputs: [
1078
- {
1079
- name: "_owners",
1080
- type: "address[]"
1081
- },
1082
- {
1083
- name: "_threshold",
1084
- type: "uint256"
1085
- },
1086
- {
1087
- name: "to",
1088
- type: "address"
1089
- },
1090
- {
1091
- name: "data",
1092
- type: "bytes"
1093
- },
1094
- {
1095
- name: "fallbackHandler",
1096
- type: "address"
1097
- },
1098
- {
1099
- name: "paymentToken",
1100
- type: "address"
1101
- },
1102
- {
1103
- name: "payment",
1104
- type: "uint256"
1105
- },
1106
- {
1107
- name: "paymentReceiver",
1108
- type: "address"
1109
- }
1110
- ],
1111
- outputs: []
1112
- }];
1113
- const enableModulesAbi$1 = [{
1114
- type: "function",
1115
- name: "enableModules",
1116
- stateMutability: "nonpayable",
1117
- inputs: [{
1118
- name: "modules",
1119
- type: "address[]"
1120
- }],
1121
- outputs: []
1122
- }];
1123
- const multiSendAbi$1 = [{
1124
- type: "function",
1125
- name: "multiSend",
1126
- stateMutability: "payable",
1127
- inputs: [{
1128
- name: "transactions",
1129
- type: "bytes"
1130
- }],
1131
- outputs: []
1132
- }];
1133
- /**
1134
- * Normalize an org handle for both salting and storage (D10a — trim +
1135
- * lowercase). Idempotent: `normalizeOrgHandle(normalizeOrgHandle(x)) ===
1136
- * normalizeOrgHandle(x)`.
1137
- *
1138
- * @param handle - The raw org handle
1139
- * @returns The trimmed, lowercased handle
1140
- */
1141
- function normalizeOrgHandle(handle) {
1142
- return handle.trim().toLowerCase();
1143
- }
1144
- /**
1145
- * Validate an org handle against the D10a rule `^[a-z0-9-]{3,32}$` over its
1146
- * NORMALIZED form. Returns the normalized handle on success; throws a typed
1147
- * `INVALID_INPUT` `CapxulError` (field `orgHandle`) on failure — never a raw
1148
- * `Error`, so SDK / backend boundary handlers can route on the code.
1149
- *
1150
- * @param handle - The raw org handle
1151
- * @returns The normalized, validated handle
1152
- */
1153
- function validateOrgHandle(handle) {
1154
- const normalized = normalizeOrgHandle(handle);
1155
- if (!ORG_HANDLE_REGEX.test(normalized)) throw Errors.invalidInput("orgHandle", `must match ^[a-z0-9-]{3,32}$ after trim+lowercase, got ${handle}`);
1156
- return normalized;
1157
- }
1158
- /**
1159
- * Compute the deterministic Org Safe salt nonce for a `(namespace, email,
1160
- * orgHandle)` triple (D10a). The salt nonce is the `bigint` reading of
1161
- * `keccak256(namespace + ":" + normalizeSafeSaltEmail(email) + ":" +
1162
- * normalizeOrgHandle(orgHandle))`.
1163
- *
1164
- * Keyed on email + handle, NOT the signer — so the Org address survives signer
1165
- * rotation (D7). Namespace defaults to `CAPXUL_ORG_SALT_NAMESPACE`.
1166
- *
1167
- * @param input.email - The founder email to derive the salt nonce from
1168
- * @param input.orgHandle - The org handle (normalized internally)
1169
- * @param input.namespace - Optional namespace override
1170
- * @returns The Capxul-namespaced Org salt nonce as a `bigint`
1171
- */
1172
- function computeCapxulOrgSaltNonce(input) {
1173
- const namespace = input.namespace ?? "capxul:org:v1";
1174
- const normalizedEmail = normalizeSafeSaltEmail(input.email);
1175
- const normalizedHandle = normalizeOrgHandle(input.orgHandle);
1176
- return BigInt(keccak256(toBytes(`${namespace}:${normalizedEmail}:${normalizedHandle}`)));
1177
- }
1178
- /**
1179
- * Pure derivation of the Org Safe v1.4.1 (SafeL2) + 4337-module-enabled
1180
- * counterfactual address for a Capxul `(founderPersonalSafe, email, orgHandle)`
1181
- * triple (D10a). Mirrors `deriveCapxulSafeAddress` byte-for-byte except the salt
1182
- * nonce (Org-namespaced, keyed on email+handle) and the initializer owner
1183
- * (the founder's PERSONAL Safe address, passed in directly — D7).
1184
- *
1185
- * Returns the lowercased `0x` + 40 hex string (raw — no brand applied; callers
1186
- * brand at their own boundary). Throws a typed `INVALID_INPUT` `CapxulError`
1187
- * (field `orgHandle`) if the handle is malformed.
1188
- *
1189
- * Canonical conformance: `packages/config/tests/org-safe-address-conformance.test.ts`
1190
- * pins the matrix against Safes actually deployed on Base Sepolia.
1191
- */
1192
- /**
1193
- * Build the EXACT Org Safe `setup()` initializer calldata (D10a). This is the
1194
- * single source of truth for the initializer bytes: `deriveCapxulOrgAddress`
1195
- * hashes it into the CREATE2 salt, and the live Org deploy adapter passes the
1196
- * IDENTICAL bytes to `SafeProxyFactory.createProxyWithNonce` — so the deployed
1197
- * address provably equals the counterfactual byte-for-byte.
1198
- *
1199
- * `setup([founderPersonalSafe], 1, MULTI_SEND, <enableModules([SAFE_4337_MODULE])
1200
- * MultiSend>, SAFE_4337_MODULE, 0, 0, 0)` — owner is the founder's PERSONAL Safe
1201
- * (D7), the 4337 module is enabled via the same MultiSend lane as the personal
1202
- * Safe. NO Zodiac Roles / Allowance at setup() (S1 decision A — those land in S2).
1203
- *
1204
- * Validates (and lowercases) `founderPersonalSafe`; throws a typed INVALID_INPUT
1205
- * (`founderPersonalSafe`) on a malformed address.
1206
- *
1207
- * @param input.founderPersonalSafe - The founder's personal Safe address (owner)
1208
- * @returns The `0x`-prefixed `setup()` calldata
1209
- */
1210
- function buildCapxulOrgInitializer(input) {
1211
- const founderPersonalSafe = input.founderPersonalSafe.toLowerCase();
1212
- if (!ADDRESS_REGEX.test(founderPersonalSafe)) throw Errors.invalidInput("founderPersonalSafe", `must be 0x + 40 hex chars, got ${input.founderPersonalSafe}`);
1213
- const enableModulesCall = encodeFunctionData({
1214
- abi: enableModulesAbi$1,
1215
- functionName: "enableModules",
1216
- args: [[SAFE_4337_MODULE]]
1217
- });
1218
- const setupData = encodeFunctionData({
1219
- abi: multiSendAbi$1,
1220
- functionName: "multiSend",
1221
- args: [encodePacked([
1222
- "uint8",
1223
- "address",
1224
- "uint256",
1225
- "uint256",
1226
- "bytes"
1227
- ], [
1228
- 1,
1229
- SAFE_MODULE_SETUP,
1230
- 0n,
1231
- BigInt((enableModulesCall.length - 2) / 2),
1232
- enableModulesCall
1233
- ])]
1234
- });
1235
- return encodeFunctionData({
1236
- abi: safeSetupAbi,
1237
- functionName: "setup",
1238
- args: [
1239
- [founderPersonalSafe],
1240
- 1n,
1241
- MULTI_SEND,
1242
- setupData,
1243
- SAFE_4337_MODULE,
1244
- ZERO_ADDRESS,
1245
- 0n,
1246
- ZERO_ADDRESS
1247
- ]
1248
- });
1249
- }
1250
- function deriveCapxulOrgAddress(input) {
1251
- const orgHandle = validateOrgHandle(input.orgHandle);
1252
- const initializer = buildCapxulOrgInitializer({ founderPersonalSafe: input.founderPersonalSafe });
1253
- const saltNonce = computeCapxulOrgSaltNonce({
1254
- email: input.email,
1255
- orgHandle
1256
- });
1257
- return getContractAddress({
1258
- opcode: "CREATE2",
1259
- from: SAFE_PROXY_FACTORY,
1260
- salt: keccak256(encodePacked(["bytes32", "uint256"], [keccak256(initializer), saltNonce])),
1261
- bytecodeHash: keccak256(concat([SAFE_PROXY_CREATION_CODE, encodeAbiParameters([{ type: "uint256" }], [BigInt(SAFE_L2_SINGLETON)])]))
1262
- }).toLowerCase();
1263
- }
1264
- //#endregion
1265
- //#region ../../packages/config/src/role-dsl.ts
1266
- const USD_DECIMALS = 6;
1267
- const USD_SCALE = 10n ** BigInt(USD_DECIMALS);
1268
- const USD_DISPLAY_RE = /^\d+(?:\.\d{1,6})?$/;
1269
- const USD_BASE_UNIT_RE = /^\d+$/;
1270
- const EXEC_TRANSACTION_WITH_ROLE = "zodiac.roles.execTransactionWithRole";
1271
- const ASSIGN_ROLES = "zodiac.roles.assignRoles";
1272
- const SCOPE_TARGET = "zodiac.roles.scopeTarget";
1273
- const OWNER_ROLE_LABEL = "Owner";
1274
- const FOUNDER_BUDGET_ROLE_LABEL = "Founder Budget";
1275
- const FOUNDER_BUDGET_LIMIT = {
1276
- currency: "USD",
1277
- value: "1000000000000",
1278
- decimals: 6
1279
- };
1280
- function usd(value) {
1281
- return {
1282
- currency: "USD",
1283
- value: usdDisplayToBaseUnits(value),
1284
- decimals: USD_DECIMALS
1285
- };
1286
- }
1287
- function usdDisplayToBaseUnits(value) {
1288
- 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");
1289
- const parts = value.split(".");
1290
- const whole = parts[0] ?? "0";
1291
- const fraction = parts[1] ?? "";
1292
- return (BigInt(whole) * USD_SCALE + BigInt(fraction.padEnd(USD_DECIMALS, "0"))).toString();
1293
- }
1294
- function normalizeOrgRoleMoney(money, field) {
1295
- 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`);
1296
- return money;
1297
- }
1298
- function normalizeOrgRoleSpendCap(spend) {
1299
- if (spend === void 0) return void 0;
1300
- return {
1301
- ...spend.perTx === void 0 ? {} : { perTx: normalizeOrgRoleMoney(spend.perTx, "roles.spend.perTx") },
1302
- ...spend.perDay === void 0 ? {} : { perDay: normalizeOrgRoleMoney(spend.perDay, "roles.spend.perDay") },
1303
- ...spend.toRecipients === void 0 ? {} : { toRecipients: spend.toRecipients }
1304
- };
1305
- }
1306
- function normalizeOrgRoleLabel(label) {
1307
- const normalized = label.trim().replace(/\s+/g, " ");
1308
- if (normalized.length === 0) throw Errors.invalidInput("role.label", "must be a non-empty role label");
1309
- return normalized;
1310
- }
1311
- function orgRoleKeyForLabel(label) {
1312
- return keccak256(toBytes(normalizeOrgRoleLabel(label).toLowerCase()));
1313
- }
1314
- function soloOrgRoleTemplate() {
1315
- return [{
1316
- label: "Owner",
1317
- canManageMembers: true,
1318
- canManageRoles: true
1319
- }, {
1320
- label: FOUNDER_BUDGET_ROLE_LABEL,
1321
- spend: {
1322
- perTx: FOUNDER_BUDGET_LIMIT,
1323
- perDay: FOUNDER_BUDGET_LIMIT,
1324
- toRecipients: "anyone"
1325
- }
1326
- }];
1327
- }
1328
- function startupOrgRoleTemplate() {
1329
- return [
1330
- ...soloOrgRoleTemplate(),
1331
- {
1332
- label: "Finance Manager",
1333
- spend: {
1334
- perTx: usd("25000"),
1335
- perDay: usd("100000"),
1336
- toRecipients: "anyone"
1337
- }
1338
- },
1339
- {
1340
- label: "Team Lead",
1341
- spend: {
1342
- perTx: usd("5000"),
1343
- perDay: usd("15000"),
1344
- toRecipients: "anyone"
1345
- }
1346
- }
1347
- ];
1348
- }
1349
- function orgRoleTemplateDefinitions(template, customRoles = []) {
1350
- switch (template) {
1351
- case "Solo": return soloOrgRoleTemplate();
1352
- case "Startup": return startupOrgRoleTemplate();
1353
- case "Custom": return customRoles.length === 0 ? soloOrgRoleTemplate() : customRoles;
1354
- default: return template;
1355
- }
1356
- }
1357
- function compileOrgRoleDefinitions(definitions) {
1358
- if (definitions.length === 0) throw Errors.invalidInput("roles", "must include at least one role");
1359
- const seen = /* @__PURE__ */ new Set();
1360
- const roles = definitions.map((definition) => {
1361
- const label = normalizeOrgRoleLabel(definition.label);
1362
- const roleKey = orgRoleKeyForLabel(label);
1363
- if (seen.has(roleKey)) throw Errors.invalidInput("roles", `duplicate role label: ${label}`);
1364
- seen.add(roleKey);
1365
- const spend = normalizeOrgRoleSpendCap(definition.spend);
1366
- const permissions = [];
1367
- if (spend !== void 0 || label === OWNER_ROLE_LABEL) permissions.push(EXEC_TRANSACTION_WITH_ROLE);
1368
- if (definition.canManageMembers === true) permissions.push(ASSIGN_ROLES);
1369
- if (definition.canManageRoles === true) permissions.push(SCOPE_TARGET);
1370
- return {
1371
- label,
1372
- roleKey,
1373
- definition: {
1374
- ...definition,
1375
- label,
1376
- ...spend === void 0 ? {} : { spend }
1377
- },
1378
- permissions,
1379
- allowance: spend ?? null
1380
- };
1381
- });
1382
- const manager = roles.find((role) => role.definition.canManageMembers === true);
1383
- if (manager === void 0) throw Errors.invalidInput("roles.canManageMembers", "at least one role must compile to the on-chain member-management permission");
1384
- return {
1385
- roles,
1386
- memberManagementRole: {
1387
- roleKey: manager.roleKey,
1388
- permission: ASSIGN_ROLES
1389
- }
1390
- };
1391
- }
1392
- //#endregion
1393
888
  //#region ../../packages/config/src/capxul-payments-v2.ts
1394
889
  /** The exact compiled CapxulPaymentsV2 ABI. */
1395
890
  const CAPXUL_PAYMENTS_V2_ABI = [
@@ -2015,6 +1510,350 @@ const CAPXUL_PAYMENTS_V2_ABI = [
2015
1510
  inputs: []
2016
1511
  }
2017
1512
  ];
1513
+ /** Immutable CapxulPaymentsV2 deployment on Base Sepolia. */
1514
+ const CAPXUL_PAYMENTS_V2_ADDRESS = "0xA3ACDD016f706eD432A9a0545C45F0943f996b60";
1515
+ //#endregion
1516
+ //#region ../../packages/config/src/route.ts
1517
+ /** USDX on Base Sepolia — the only settlement token in v1. */
1518
+ const USDX_BASE_SEPOLIA_TOKEN = {
1519
+ chainId: BASE_SEPOLIA_CHAIN_ID,
1520
+ address: USDX_ADDRESS_BASE_SEPOLIA,
1521
+ decimals: 6
1522
+ };
1523
+ /**
1524
+ * The `direct-base` settlement route: USDX on Base Sepolia, settled directly
1525
+ * through the `CapxulPayments` contract. This is the ONLY route implemented in
1526
+ * D1; the `Route` shape is the seam future provider routes slot into.
1527
+ */
1528
+ const DIRECT_BASE_ROUTE = {
1529
+ kind: "direct-base",
1530
+ token: USDX_BASE_SEPOLIA_TOKEN,
1531
+ chainId: USDX_BASE_SEPOLIA_TOKEN.chainId,
1532
+ verifyingContract: CAPXUL_PAYMENTS_V2_ADDRESS
1533
+ };
1534
+ USDX_BASE_SEPOLIA_TOKEN.chainId;
1535
+ const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
1536
+ const ORG_HANDLE_REGEX = /^[a-z0-9-]{3,32}$/;
1537
+ const ADDRESS_REGEX = /^0x[0-9a-f]{40}$/;
1538
+ const safeSetupAbi = [{
1539
+ type: "function",
1540
+ name: "setup",
1541
+ stateMutability: "nonpayable",
1542
+ inputs: [
1543
+ {
1544
+ name: "_owners",
1545
+ type: "address[]"
1546
+ },
1547
+ {
1548
+ name: "_threshold",
1549
+ type: "uint256"
1550
+ },
1551
+ {
1552
+ name: "to",
1553
+ type: "address"
1554
+ },
1555
+ {
1556
+ name: "data",
1557
+ type: "bytes"
1558
+ },
1559
+ {
1560
+ name: "fallbackHandler",
1561
+ type: "address"
1562
+ },
1563
+ {
1564
+ name: "paymentToken",
1565
+ type: "address"
1566
+ },
1567
+ {
1568
+ name: "payment",
1569
+ type: "uint256"
1570
+ },
1571
+ {
1572
+ name: "paymentReceiver",
1573
+ type: "address"
1574
+ }
1575
+ ],
1576
+ outputs: []
1577
+ }];
1578
+ const enableModulesAbi$1 = [{
1579
+ type: "function",
1580
+ name: "enableModules",
1581
+ stateMutability: "nonpayable",
1582
+ inputs: [{
1583
+ name: "modules",
1584
+ type: "address[]"
1585
+ }],
1586
+ outputs: []
1587
+ }];
1588
+ const multiSendAbi$1 = [{
1589
+ type: "function",
1590
+ name: "multiSend",
1591
+ stateMutability: "payable",
1592
+ inputs: [{
1593
+ name: "transactions",
1594
+ type: "bytes"
1595
+ }],
1596
+ outputs: []
1597
+ }];
1598
+ /**
1599
+ * Normalize an org handle for both salting and storage (D10a — trim +
1600
+ * lowercase). Idempotent: `normalizeOrgHandle(normalizeOrgHandle(x)) ===
1601
+ * normalizeOrgHandle(x)`.
1602
+ *
1603
+ * @param handle - The raw org handle
1604
+ * @returns The trimmed, lowercased handle
1605
+ */
1606
+ function normalizeOrgHandle(handle) {
1607
+ return handle.trim().toLowerCase();
1608
+ }
1609
+ /**
1610
+ * Validate an org handle against the D10a rule `^[a-z0-9-]{3,32}$` over its
1611
+ * NORMALIZED form. Returns the normalized handle on success; throws a typed
1612
+ * `INVALID_INPUT` `CapxulError` (field `orgHandle`) on failure — never a raw
1613
+ * `Error`, so SDK / backend boundary handlers can route on the code.
1614
+ *
1615
+ * @param handle - The raw org handle
1616
+ * @returns The normalized, validated handle
1617
+ */
1618
+ function validateOrgHandle(handle) {
1619
+ const normalized = normalizeOrgHandle(handle);
1620
+ if (!ORG_HANDLE_REGEX.test(normalized)) throw Errors.invalidInput("orgHandle", `must match ^[a-z0-9-]{3,32}$ after trim+lowercase, got ${handle}`);
1621
+ return normalized;
1622
+ }
1623
+ /**
1624
+ * Compute the deterministic Org Safe salt nonce for a `(namespace, email,
1625
+ * orgHandle)` triple (D10a). The salt nonce is the `bigint` reading of
1626
+ * `keccak256(namespace + ":" + normalizeSafeSaltEmail(email) + ":" +
1627
+ * normalizeOrgHandle(orgHandle))`.
1628
+ *
1629
+ * Keyed on email + handle, NOT the signer — so the Org address survives signer
1630
+ * rotation (D7). Namespace defaults to `CAPXUL_ORG_SALT_NAMESPACE`.
1631
+ *
1632
+ * @param input.email - The founder email to derive the salt nonce from
1633
+ * @param input.orgHandle - The org handle (normalized internally)
1634
+ * @param input.namespace - Optional namespace override
1635
+ * @returns The Capxul-namespaced Org salt nonce as a `bigint`
1636
+ */
1637
+ function computeCapxulOrgSaltNonce(input) {
1638
+ const namespace = input.namespace ?? "capxul:org:v1";
1639
+ const normalizedEmail = normalizeSafeSaltEmail(input.email);
1640
+ const normalizedHandle = normalizeOrgHandle(input.orgHandle);
1641
+ return BigInt(keccak256(toBytes(`${namespace}:${normalizedEmail}:${normalizedHandle}`)));
1642
+ }
1643
+ /**
1644
+ * Pure derivation of the Org Safe v1.4.1 (SafeL2) + 4337-module-enabled
1645
+ * counterfactual address for a Capxul `(founderPersonalSafe, email, orgHandle)`
1646
+ * triple (D10a). Mirrors `deriveCapxulSafeAddress` byte-for-byte except the salt
1647
+ * nonce (Org-namespaced, keyed on email+handle) and the initializer owner
1648
+ * (the founder's PERSONAL Safe address, passed in directly — D7).
1649
+ *
1650
+ * Returns the lowercased `0x` + 40 hex string (raw — no brand applied; callers
1651
+ * brand at their own boundary). Throws a typed `INVALID_INPUT` `CapxulError`
1652
+ * (field `orgHandle`) if the handle is malformed.
1653
+ *
1654
+ * Canonical conformance: `packages/config/tests/org-safe-address-conformance.test.ts`
1655
+ * pins the matrix against Safes actually deployed on Base Sepolia.
1656
+ */
1657
+ /**
1658
+ * Build the EXACT Org Safe `setup()` initializer calldata (D10a). This is the
1659
+ * single source of truth for the initializer bytes: `deriveCapxulOrgAddress`
1660
+ * hashes it into the CREATE2 salt, and the live Org deploy adapter passes the
1661
+ * IDENTICAL bytes to `SafeProxyFactory.createProxyWithNonce` — so the deployed
1662
+ * address provably equals the counterfactual byte-for-byte.
1663
+ *
1664
+ * `setup([founderPersonalSafe], 1, MULTI_SEND, <enableModules([SAFE_4337_MODULE])
1665
+ * MultiSend>, SAFE_4337_MODULE, 0, 0, 0)` — owner is the founder's PERSONAL Safe
1666
+ * (D7), the 4337 module is enabled via the same MultiSend lane as the personal
1667
+ * Safe. NO Zodiac Roles / Allowance at setup() (S1 decision A — those land in S2).
1668
+ *
1669
+ * Validates (and lowercases) `founderPersonalSafe`; throws a typed INVALID_INPUT
1670
+ * (`founderPersonalSafe`) on a malformed address.
1671
+ *
1672
+ * @param input.founderPersonalSafe - The founder's personal Safe address (owner)
1673
+ * @returns The `0x`-prefixed `setup()` calldata
1674
+ */
1675
+ function buildCapxulOrgInitializer(input) {
1676
+ const founderPersonalSafe = input.founderPersonalSafe.toLowerCase();
1677
+ if (!ADDRESS_REGEX.test(founderPersonalSafe)) throw Errors.invalidInput("founderPersonalSafe", `must be 0x + 40 hex chars, got ${input.founderPersonalSafe}`);
1678
+ const enableModulesCall = encodeFunctionData({
1679
+ abi: enableModulesAbi$1,
1680
+ functionName: "enableModules",
1681
+ args: [[SAFE_4337_MODULE]]
1682
+ });
1683
+ const setupData = encodeFunctionData({
1684
+ abi: multiSendAbi$1,
1685
+ functionName: "multiSend",
1686
+ args: [encodePacked([
1687
+ "uint8",
1688
+ "address",
1689
+ "uint256",
1690
+ "uint256",
1691
+ "bytes"
1692
+ ], [
1693
+ 1,
1694
+ SAFE_MODULE_SETUP,
1695
+ 0n,
1696
+ BigInt((enableModulesCall.length - 2) / 2),
1697
+ enableModulesCall
1698
+ ])]
1699
+ });
1700
+ return encodeFunctionData({
1701
+ abi: safeSetupAbi,
1702
+ functionName: "setup",
1703
+ args: [
1704
+ [founderPersonalSafe],
1705
+ 1n,
1706
+ MULTI_SEND,
1707
+ setupData,
1708
+ SAFE_4337_MODULE,
1709
+ ZERO_ADDRESS,
1710
+ 0n,
1711
+ ZERO_ADDRESS
1712
+ ]
1713
+ });
1714
+ }
1715
+ function deriveCapxulOrgAddress(input) {
1716
+ const orgHandle = validateOrgHandle(input.orgHandle);
1717
+ const initializer = buildCapxulOrgInitializer({ founderPersonalSafe: input.founderPersonalSafe });
1718
+ const saltNonce = computeCapxulOrgSaltNonce({
1719
+ email: input.email,
1720
+ orgHandle
1721
+ });
1722
+ return getContractAddress({
1723
+ opcode: "CREATE2",
1724
+ from: SAFE_PROXY_FACTORY,
1725
+ salt: keccak256(encodePacked(["bytes32", "uint256"], [keccak256(initializer), saltNonce])),
1726
+ bytecodeHash: keccak256(concat([SAFE_PROXY_CREATION_CODE, encodeAbiParameters([{ type: "uint256" }], [BigInt(SAFE_L2_SINGLETON)])]))
1727
+ }).toLowerCase();
1728
+ }
1729
+ //#endregion
1730
+ //#region ../../packages/config/src/role-dsl.ts
1731
+ const USD_DECIMALS = 6;
1732
+ const USD_SCALE = 10n ** BigInt(USD_DECIMALS);
1733
+ const USD_DISPLAY_RE = /^\d+(?:\.\d{1,6})?$/;
1734
+ const USD_BASE_UNIT_RE = /^\d+$/;
1735
+ const EXEC_TRANSACTION_WITH_ROLE = "zodiac.roles.execTransactionWithRole";
1736
+ const ASSIGN_ROLES = "zodiac.roles.assignRoles";
1737
+ const SCOPE_TARGET = "zodiac.roles.scopeTarget";
1738
+ const OWNER_ROLE_LABEL = "Owner";
1739
+ const FOUNDER_BUDGET_ROLE_LABEL = "Founder Budget";
1740
+ const FOUNDER_BUDGET_LIMIT = {
1741
+ currency: "USD",
1742
+ value: "1000000000000",
1743
+ decimals: 6
1744
+ };
1745
+ function usd(value) {
1746
+ return {
1747
+ currency: "USD",
1748
+ value: usdDisplayToBaseUnits(value),
1749
+ decimals: USD_DECIMALS
1750
+ };
1751
+ }
1752
+ function usdDisplayToBaseUnits(value) {
1753
+ 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");
1754
+ const parts = value.split(".");
1755
+ const whole = parts[0] ?? "0";
1756
+ const fraction = parts[1] ?? "";
1757
+ return (BigInt(whole) * USD_SCALE + BigInt(fraction.padEnd(USD_DECIMALS, "0"))).toString();
1758
+ }
1759
+ function normalizeOrgRoleMoney(money, field) {
1760
+ 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`);
1761
+ return money;
1762
+ }
1763
+ function normalizeOrgRoleSpendCap(spend) {
1764
+ if (spend === void 0) return void 0;
1765
+ return {
1766
+ ...spend.perTx === void 0 ? {} : { perTx: normalizeOrgRoleMoney(spend.perTx, "roles.spend.perTx") },
1767
+ ...spend.perDay === void 0 ? {} : { perDay: normalizeOrgRoleMoney(spend.perDay, "roles.spend.perDay") },
1768
+ ...spend.toRecipients === void 0 ? {} : { toRecipients: spend.toRecipients }
1769
+ };
1770
+ }
1771
+ function normalizeOrgRoleLabel(label) {
1772
+ const normalized = label.trim().replace(/\s+/g, " ");
1773
+ if (normalized.length === 0) throw Errors.invalidInput("role.label", "must be a non-empty role label");
1774
+ return normalized;
1775
+ }
1776
+ function orgRoleKeyForLabel(label) {
1777
+ return keccak256(toBytes(normalizeOrgRoleLabel(label).toLowerCase()));
1778
+ }
1779
+ function soloOrgRoleTemplate() {
1780
+ return [{
1781
+ label: "Owner",
1782
+ canManageMembers: true,
1783
+ canManageRoles: true
1784
+ }, {
1785
+ label: FOUNDER_BUDGET_ROLE_LABEL,
1786
+ spend: {
1787
+ perTx: FOUNDER_BUDGET_LIMIT,
1788
+ perDay: FOUNDER_BUDGET_LIMIT,
1789
+ toRecipients: "anyone"
1790
+ }
1791
+ }];
1792
+ }
1793
+ function startupOrgRoleTemplate() {
1794
+ return [
1795
+ ...soloOrgRoleTemplate(),
1796
+ {
1797
+ label: "Finance Manager",
1798
+ spend: {
1799
+ perTx: usd("25000"),
1800
+ perDay: usd("100000"),
1801
+ toRecipients: "anyone"
1802
+ }
1803
+ },
1804
+ {
1805
+ label: "Team Lead",
1806
+ spend: {
1807
+ perTx: usd("5000"),
1808
+ perDay: usd("15000"),
1809
+ toRecipients: "anyone"
1810
+ }
1811
+ }
1812
+ ];
1813
+ }
1814
+ function orgRoleTemplateDefinitions(template, customRoles = []) {
1815
+ switch (template) {
1816
+ case "Solo": return soloOrgRoleTemplate();
1817
+ case "Startup": return startupOrgRoleTemplate();
1818
+ case "Custom": return customRoles.length === 0 ? soloOrgRoleTemplate() : customRoles;
1819
+ default: return template;
1820
+ }
1821
+ }
1822
+ function compileOrgRoleDefinitions(definitions) {
1823
+ if (definitions.length === 0) throw Errors.invalidInput("roles", "must include at least one role");
1824
+ const seen = /* @__PURE__ */ new Set();
1825
+ const roles = definitions.map((definition) => {
1826
+ const label = normalizeOrgRoleLabel(definition.label);
1827
+ const roleKey = orgRoleKeyForLabel(label);
1828
+ if (seen.has(roleKey)) throw Errors.invalidInput("roles", `duplicate role label: ${label}`);
1829
+ seen.add(roleKey);
1830
+ const spend = normalizeOrgRoleSpendCap(definition.spend);
1831
+ const permissions = [];
1832
+ if (spend !== void 0 || label === OWNER_ROLE_LABEL) permissions.push(EXEC_TRANSACTION_WITH_ROLE);
1833
+ if (definition.canManageMembers === true) permissions.push(ASSIGN_ROLES);
1834
+ if (definition.canManageRoles === true) permissions.push(SCOPE_TARGET);
1835
+ return {
1836
+ label,
1837
+ roleKey,
1838
+ definition: {
1839
+ ...definition,
1840
+ label,
1841
+ ...spend === void 0 ? {} : { spend }
1842
+ },
1843
+ permissions,
1844
+ allowance: spend ?? null
1845
+ };
1846
+ });
1847
+ const manager = roles.find((role) => role.definition.canManageMembers === true);
1848
+ if (manager === void 0) throw Errors.invalidInput("roles.canManageMembers", "at least one role must compile to the on-chain member-management permission");
1849
+ return {
1850
+ roles,
1851
+ memberManagementRole: {
1852
+ roleKey: manager.roleKey,
1853
+ permission: ASSIGN_ROLES
1854
+ }
1855
+ };
1856
+ }
2018
1857
  padHex(stringToHex("FM_DAILY"), {
2019
1858
  size: 32,
2020
1859
  dir: "right"
@@ -3027,7 +2866,7 @@ const EVM_ADDRESS_RE = /^0x[a-fA-F0-9]{40}$/;
3027
2866
  * envelopes carrying it — so it MUST stay byte-identical across both. Exported
3028
2867
  * once here to remove the drift risk of a mirrored declaration.
3029
2868
  */
3030
- const PAYMENT_DOCUMENT_VERIFYING_CONTRACT = "0xe740ea65521edc9bef0ea75d30b5334711db99f4";
2869
+ const PAYMENT_DOCUMENT_VERIFYING_CONTRACT = "0xA3ACDD016f706eD432A9a0545C45F0943f996b60";
3031
2870
  const PAYMENT_ID_RE = /^payment_[0-9A-Za-z]+$/;
3032
2871
  const PAYEE_ID_RE = /^payee_[0-9A-Za-z]+$/;
3033
2872
  const ORG_ID_RE = /^org_[0-9A-Za-z]+$/;
@@ -8216,6 +8055,12 @@ function signerFailure(operation, cause) {
8216
8055
  error: cause instanceof CapxulError ? cause : Errors.providerError("wallet-signer", operation, cause)
8217
8056
  };
8218
8057
  }
8058
+ /** Return one stable fingerprint for one JSON payment intent. */
8059
+ async function fingerprintPaymentIntent(intent) {
8060
+ const canonical = JSON.stringify(intent, (_key, value) => value !== null && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.entries(value).sort(([left], [right]) => left.localeCompare(right))) : value);
8061
+ if (canonical === void 0) throw new TypeError("Payment intent must be JSON data");
8062
+ return keccak256(toBytes(canonical));
8063
+ }
8219
8064
  async function executePrepared(deps, prepare, expectedRequest, signal) {
8220
8065
  if (isAborted$1(signal)) return {
8221
8066
  ok: false,
@@ -8234,7 +8079,7 @@ async function executePrepared(deps, prepare, expectedRequest, signal) {
8234
8079
  }
8235
8080
  const prepared = await prepare(signerAddress);
8236
8081
  if (!prepared.ok) return prepared;
8237
- if (JSON.stringify(prepared.value.request) !== JSON.stringify(expectedRequest)) return {
8082
+ if (await fingerprintPaymentIntent(prepared.value.request) !== await fingerprintPaymentIntent(expectedRequest)) return {
8238
8083
  ok: false,
8239
8084
  error: Errors.invalidInput("payment", "prepared command mismatch")
8240
8085
  };
@@ -8458,12 +8303,6 @@ async function waitForPaymentSubmission(submission, signal, operation, onCancel
8458
8303
  });
8459
8304
  });
8460
8305
  }
8461
- /** Return one stable fingerprint for one JSON payment intent. */
8462
- async function fingerprintPaymentIntent(intent) {
8463
- const canonical = JSON.stringify(intent, (_key, value) => value !== null && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.entries(value).sort(([left], [right]) => left.localeCompare(right))) : value);
8464
- if (canonical === void 0) throw new TypeError("Payment intent must be JSON data");
8465
- return keccak256(toBytes(canonical));
8466
- }
8467
8306
  function paymentExecutionIntent(input) {
8468
8307
  if (actorReferenceToBackend(input.actor)?.kind === "org") return {
8469
8308
  ok: false,
@@ -9190,7 +9029,7 @@ async function recoverRawDigestSigner(input) {
9190
9029
  }
9191
9030
  //#endregion
9192
9031
  //#region ../../packages/sdk/package.json
9193
- var version = "2.1.0";
9032
+ var version = "2.1.1";
9194
9033
  //#endregion
9195
9034
  //#region ../../packages/observability/src/engineering.ts
9196
9035
  const SAFE_TRACED_HEADER_NAMES = [
@@ -42936,7 +42775,7 @@ function hexToSafeInteger(hex, op) {
42936
42775
  return n;
42937
42776
  }
42938
42777
  /**
42939
- * Read the on-chain `commitments(id)` struct from CapxulPayments via `eth_call`.
42778
+ * Read the on-chain `commitments(id)` struct from CapxulPaymentsV2 via `eth_call`.
42940
42779
  * Used to bind lifecycle evidence (claim/cancel/redirect) to the actual on-chain
42941
42780
  * STATE — `requireSuccessfulUserOp` proves a UserOp succeeded from the expected
42942
42781
  * Safe, but only this state read proves the UserOp performed the expected op on
@@ -42945,12 +42784,12 @@ function hexToSafeInteger(hex, op) {
42945
42784
  */
42946
42785
  async function fetchCommitmentState(args) {
42947
42786
  const data = encodeFunctionData({
42948
- abi: CAPXUL_PAYMENTS_COMMITMENT_ABI,
42787
+ abi: CAPXUL_PAYMENTS_V2_ABI,
42949
42788
  functionName: "commitments",
42950
42789
  args: [args.onchainCommitmentId]
42951
42790
  });
42952
42791
  const raw = await alchemyRpc(args.chainId, "eth_call", [{
42953
- to: CAPXUL_PAYMENTS_ADDRESS,
42792
+ to: CAPXUL_PAYMENTS_V2_ADDRESS,
42954
42793
  data
42955
42794
  }, "latest"]);
42956
42795
  if (typeof raw !== "string" || !raw.startsWith("0x")) throw Errors.providerError("alchemy", "eth_call commitments", `unexpected shape: ${String(raw)}`);
@@ -42958,25 +42797,26 @@ async function fetchCommitmentState(args) {
42958
42797
  let decoded;
42959
42798
  try {
42960
42799
  decoded = decodeFunctionResult({
42961
- abi: CAPXUL_PAYMENTS_COMMITMENT_ABI,
42800
+ abi: CAPXUL_PAYMENTS_V2_ABI,
42962
42801
  functionName: "commitments",
42963
42802
  data: raw
42964
42803
  });
42965
42804
  } catch (cause) {
42966
42805
  throw Errors.providerError("alchemy", "eth_call commitments", `decode failed: ${String(cause)}`);
42967
42806
  }
42968
- const [creator, token, recipient, totalAmount, claimed, startTime, cliffTime, endTime, documentHash, paymentType, cancelled] = decoded;
42807
+ const [settlementId, creator, recipient, token, totalAmount, claimed, startTime, cliffTime, endTime, kind, documentHash, cancelled] = decoded;
42969
42808
  return {
42809
+ settlementId,
42970
42810
  creator,
42971
- token,
42972
42811
  recipient,
42812
+ token,
42973
42813
  totalAmount,
42974
42814
  claimed,
42975
42815
  startTime: Number(startTime),
42976
42816
  cliffTime: Number(cliffTime),
42977
42817
  endTime: Number(endTime),
42978
42818
  documentHash,
42979
- paymentType: Number(paymentType),
42819
+ kind: Number(kind),
42980
42820
  cancelled
42981
42821
  };
42982
42822
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capxul/mcp",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "private": false,
5
5
  "description": "Capxul MCP server for auth, Account readiness, identity, Organizations, relationships, requests, destinations, and testnet funding over Streamable HTTP.",
6
6
  "keywords": [
@@ -47,12 +47,12 @@
47
47
  "typescript": "npm:@typescript/typescript6@6.0.2",
48
48
  "vite": "npm:@voidzero-dev/vite-plus-core@0.1.23",
49
49
  "vite-plus": "0.1.23",
50
- "@capxul/backend": "0.2.0",
51
- "@capxul/config": "0.1.1",
52
- "@capxul/sdk": "2.1.0",
50
+ "@capxul/backend": "0.2.1",
51
+ "@capxul/config": "0.2.0",
52
+ "@capxul/sdk": "2.1.1",
53
53
  "@capxul/types": "0.1.0",
54
54
  "@capxul/typescript-config": "0.0.0",
55
- "@capxul/wire": "0.2.0"
55
+ "@capxul/wire": "0.3.0"
56
56
  },
57
57
  "scripts": {
58
58
  "dev": "vp exec tsx src/main.ts serve",