@ocap/tx-pipeline 1.30.26 → 1.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/esm/appchain-sovereign-hub.d.mts +160 -0
  2. package/esm/appchain-sovereign-hub.mjs +348 -0
  3. package/esm/arcvault-external-adapter.d.mts +166 -0
  4. package/esm/arcvault-external-adapter.mjs +376 -0
  5. package/esm/encrypted-nft-envelope.d.mts +172 -0
  6. package/esm/encrypted-nft-envelope.mjs +458 -0
  7. package/esm/evm-simplified-bridge.d.mts +1370 -0
  8. package/esm/evm-simplified-bridge.mjs +3875 -0
  9. package/esm/give-to-mint-karma.d.mts +472 -0
  10. package/esm/give-to-mint-karma.mjs +1057 -0
  11. package/esm/helpers/replay-guard.d.mts +15 -0
  12. package/esm/helpers/replay-guard.mjs +23 -0
  13. package/esm/index.d.mts +10 -5
  14. package/esm/index.mjs +14 -10
  15. package/esm/legacy-protocol-sunset.d.mts +251 -0
  16. package/esm/legacy-protocol-sunset.mjs +1519 -0
  17. package/esm/library.d.mts +16 -0
  18. package/esm/library.mjs +17 -0
  19. package/esm/native-abt-exchange.d.mts +2055 -0
  20. package/esm/native-abt-exchange.mjs +7250 -0
  21. package/esm/ofac-screening.d.mts +17 -0
  22. package/esm/ofac-screening.mjs +39 -0
  23. package/esm/pipes/anti-land-attack.mjs +1 -1
  24. package/esm/pipes/decode-itx.mjs +43 -4
  25. package/esm/pipes/decode-tx.d.mts +2 -3
  26. package/esm/pipes/decode-tx.mjs +53 -115
  27. package/esm/pipes/extract-signer.mjs +2 -2
  28. package/esm/pipes/extract-state.mjs +14 -3
  29. package/esm/pipes/post-execution-invariant-gate.d.mts +61 -0
  30. package/esm/pipes/post-execution-invariant-gate.mjs +789 -0
  31. package/esm/pipes/pre-flight-waf.d.mts +34 -0
  32. package/esm/pipes/pre-flight-waf.mjs +603 -0
  33. package/esm/pipes/take-state-snapshot.mjs +3 -2
  34. package/esm/pipes/update-owner.mjs +39 -4
  35. package/esm/pipes/verify-account-migration.mjs +14 -4
  36. package/esm/pipes/verify-blocked.mjs +1 -1
  37. package/esm/pipes/verify-delegation.d.mts +22 -3
  38. package/esm/pipes/verify-delegation.mjs +259 -36
  39. package/esm/pipes/verify-list-size.mjs +1 -1
  40. package/esm/pipes/verify-multisig-v2.mjs +15 -7
  41. package/esm/pipes/verify-multisig.mjs +15 -7
  42. package/esm/pipes/verify-sender.mjs +1 -1
  43. package/esm/pipes/verify-signature.mjs +35 -6
  44. package/esm/pipes/verify-signer.mjs +2 -2
  45. package/esm/pipes/verify-state-diff.mjs +3 -3
  46. package/esm/pipes/verify-token-access.mjs +1 -1
  47. package/esm/pipes/verify-token-balance.mjs +13 -5
  48. package/esm/pipes/verify-transferrable.d.mts +8 -1
  49. package/esm/pipes/verify-transferrable.mjs +3 -3
  50. package/esm/pipes/verify-tx-input.mjs +2 -2
  51. package/esm/pipes/verify-tx-size.mjs +46 -2
  52. package/esm/pipes/verify-tx.mjs +5 -7
  53. package/esm/pipes/verify-updater.mjs +1 -1
  54. package/esm/social-economy-factories.d.mts +346 -0
  55. package/esm/social-economy-factories.mjs +845 -0
  56. package/esm/super-suites-foundation.d.mts +513 -0
  57. package/esm/super-suites-foundation.mjs +1241 -0
  58. package/esm/transaction-block.d.mts +471 -0
  59. package/esm/transaction-block.mjs +1906 -0
  60. package/esm/uniswap-erc7683-solver.d.mts +201 -0
  61. package/esm/uniswap-erc7683-solver.mjs +321 -0
  62. package/esm/uniswap-lp-copilot.d.mts +113 -0
  63. package/esm/uniswap-lp-copilot.mjs +320 -0
  64. package/esm/uniswap-router.d.mts +335 -0
  65. package/esm/uniswap-router.mjs +578 -0
  66. package/esm/uniswap-token-factory-graduation.d.mts +187 -0
  67. package/esm/uniswap-token-factory-graduation.mjs +426 -0
  68. package/esm/uniswap-v4-hook.d.mts +173 -0
  69. package/esm/uniswap-v4-hook.mjs +517 -0
  70. package/lib/appchain-sovereign-hub.cjs +352 -0
  71. package/lib/appchain-sovereign-hub.d.cts +160 -0
  72. package/lib/arcvault-external-adapter.cjs +383 -0
  73. package/lib/arcvault-external-adapter.d.cts +166 -0
  74. package/lib/encrypted-nft-envelope.cjs +477 -0
  75. package/lib/encrypted-nft-envelope.d.cts +172 -0
  76. package/lib/evm-simplified-bridge.cjs +3943 -0
  77. package/lib/evm-simplified-bridge.d.cts +1370 -0
  78. package/lib/give-to-mint-karma.cjs +1084 -0
  79. package/lib/give-to-mint-karma.d.cts +472 -0
  80. package/lib/helpers/replay-guard.cjs +27 -0
  81. package/lib/helpers/replay-guard.d.cts +15 -0
  82. package/lib/index.cjs +49 -16
  83. package/lib/index.d.cts +10 -5
  84. package/lib/legacy-protocol-sunset.cjs +1543 -0
  85. package/lib/legacy-protocol-sunset.d.cts +251 -0
  86. package/lib/library.cjs +303 -0
  87. package/lib/library.d.cts +16 -0
  88. package/lib/native-abt-exchange.cjs +7322 -0
  89. package/lib/native-abt-exchange.d.cts +2055 -0
  90. package/lib/ofac-screening.cjs +42 -0
  91. package/lib/ofac-screening.d.cts +17 -0
  92. package/lib/pipes/anti-land-attack.cjs +2 -2
  93. package/lib/pipes/decode-itx.cjs +43 -4
  94. package/lib/pipes/decode-itx.d.cts +1 -1
  95. package/lib/pipes/decode-tx.cjs +52 -116
  96. package/lib/pipes/decode-tx.d.cts +3 -4
  97. package/lib/pipes/extract-signer.cjs +2 -2
  98. package/lib/pipes/extract-state.cjs +14 -3
  99. package/lib/pipes/post-execution-invariant-gate.cjs +800 -0
  100. package/lib/pipes/post-execution-invariant-gate.d.cts +61 -0
  101. package/lib/pipes/pre-flight-waf.cjs +616 -0
  102. package/lib/pipes/pre-flight-waf.d.cts +34 -0
  103. package/lib/pipes/take-state-snapshot.cjs +3 -2
  104. package/lib/pipes/update-owner.cjs +40 -5
  105. package/lib/pipes/update-owner.d.cts +1 -1
  106. package/lib/pipes/verify-account-migration.cjs +14 -4
  107. package/lib/pipes/verify-blocked.cjs +1 -1
  108. package/lib/pipes/verify-delegation.cjs +259 -36
  109. package/lib/pipes/verify-delegation.d.cts +22 -3
  110. package/lib/pipes/verify-list-size.cjs +1 -1
  111. package/lib/pipes/verify-multisig-v2.cjs +15 -7
  112. package/lib/pipes/verify-multisig.cjs +15 -7
  113. package/lib/pipes/verify-sender.cjs +1 -1
  114. package/lib/pipes/verify-service-fee.d.cts +1 -1
  115. package/lib/pipes/verify-signature.cjs +35 -6
  116. package/lib/pipes/verify-signature.d.cts +1 -1
  117. package/lib/pipes/verify-signer.cjs +2 -2
  118. package/lib/pipes/verify-state-diff.cjs +4 -4
  119. package/lib/pipes/verify-token-access.cjs +2 -2
  120. package/lib/pipes/verify-token-balance.cjs +13 -5
  121. package/lib/pipes/verify-transferrable.cjs +3 -3
  122. package/lib/pipes/verify-transferrable.d.cts +8 -1
  123. package/lib/pipes/verify-tx-input.cjs +3 -3
  124. package/lib/pipes/verify-tx-size.cjs +46 -2
  125. package/lib/pipes/verify-tx-size.d.cts +1 -1
  126. package/lib/pipes/verify-tx.cjs +6 -8
  127. package/lib/pipes/verify-tx.d.cts +1 -1
  128. package/lib/pipes/verify-updater.cjs +1 -1
  129. package/lib/social-economy-factories.cjs +852 -0
  130. package/lib/social-economy-factories.d.cts +346 -0
  131. package/lib/super-suites-foundation.cjs +1257 -0
  132. package/lib/super-suites-foundation.d.cts +513 -0
  133. package/lib/transaction-block.cjs +1941 -0
  134. package/lib/transaction-block.d.cts +471 -0
  135. package/lib/uniswap-erc7683-solver.cjs +327 -0
  136. package/lib/uniswap-erc7683-solver.d.cts +201 -0
  137. package/lib/uniswap-lp-copilot.cjs +328 -0
  138. package/lib/uniswap-lp-copilot.d.cts +113 -0
  139. package/lib/uniswap-router.cjs +593 -0
  140. package/lib/uniswap-router.d.cts +335 -0
  141. package/lib/uniswap-token-factory-graduation.cjs +431 -0
  142. package/lib/uniswap-token-factory-graduation.d.cts +187 -0
  143. package/lib/uniswap-v4-hook.cjs +527 -0
  144. package/lib/uniswap-v4-hook.d.cts +173 -0
  145. package/package.json +11 -10
  146. package/esm/helpers/dedup-height.d.mts +0 -16
  147. package/esm/helpers/dedup-height.mjs +0 -61
  148. package/lib/helpers/dedup-height.cjs +0 -72
  149. package/lib/helpers/dedup-height.d.cts +0 -16
@@ -0,0 +1,1241 @@
1
+ import { CustomError } from "@ocap/util/lib/error";
2
+ import { createHash } from "node:crypto";
3
+
4
+ //#region src/super-suites-foundation.ts
5
+ const ErrorCode = {
6
+ InvalidSuperSuite: "INVALID_SUPER_SUITE_PRIMITIVE",
7
+ ForbiddenSuperSuite: "FORBIDDEN_SUPER_SUITE_OPERATION",
8
+ ConservationViolation: "CONSERVATION_INVARIANT_VIOLATION"
9
+ };
10
+ const DEFAULT_ABT_TOKEN_ADDRESS = "z35n6UoHSi9s4232bd3832948239482394823";
11
+ const IBO_DIVIDEND_PRECISION = 10n ** 18n;
12
+ const BPS_DENOMINATOR = 10000n;
13
+ const MAX_PREPAID_CARD_ALLOWED_PROVIDERS = 64;
14
+ const MAX_IBO_TOTAL_FEE_SPLIT_BPS = 9e3;
15
+ const MAX_ARCADE_HOUSE_SPLIT_BPS = 5e3;
16
+ const MIN_ARCADE_HOUSE_SPLIT_BPS = 100;
17
+ const MAX_ARCADE_WINNERS_PER_ROUND = 50;
18
+ const MAX_STICKER_ROYALTY_BPS = 2500;
19
+ const MAX_SPACE_DISPLAYED_STICKERS = 100;
20
+ const MAX_SPACE_PLACED_MACHINES = 32;
21
+ const MIN_ATTENTION_STAMP_ABT = 1000000000000000n;
22
+ const MAX_ATTENTION_STAMP_TTL_EPOCHS = 90;
23
+ const BYTES32_HEX_REGEX = /^0x[0-9a-fA-F]{64}$/;
24
+ const FORBIDDEN_IDS = new Set([
25
+ "__proto__",
26
+ "constructor",
27
+ "prototype"
28
+ ]);
29
+ function assertCleanDidOrId(value, label) {
30
+ if (typeof value !== "string" || value.trim().length === 0) throw new CustomError(ErrorCode.InvalidSuperSuite, `SuperSuites: ${label} must be a non-empty string`);
31
+ const trimmed = value.trim();
32
+ if (trimmed !== value || FORBIDDEN_IDS.has(trimmed) || /[\s/\\?#%]|::|->/.test(trimmed)) throw new CustomError(ErrorCode.InvalidSuperSuite, `SuperSuites: ${label} contains unsafe characters`);
33
+ return trimmed;
34
+ }
35
+ function assertPositiveBigInt(value, label) {
36
+ if (typeof value !== "bigint" || value <= 0n) throw new CustomError(ErrorCode.InvalidSuperSuite, `SuperSuites: ${label} must be a positive bigint`);
37
+ return value;
38
+ }
39
+ function assertNonNegativeBigInt(value, label) {
40
+ if (typeof value !== "bigint" || value < 0n) throw new CustomError(ErrorCode.InvalidSuperSuite, `SuperSuites: ${label} must be a non-negative bigint`);
41
+ return value;
42
+ }
43
+ function assertValidEpoch(epochIndex, label = "epochIndex") {
44
+ if (typeof epochIndex !== "number" || !Number.isSafeInteger(epochIndex) || epochIndex < 0) throw new CustomError(ErrorCode.InvalidSuperSuite, `SuperSuites: ${label} must be a non-negative safe integer`);
45
+ return epochIndex;
46
+ }
47
+ function assertValidBps(bps, label, maxBps = 1e4) {
48
+ if (typeof bps !== "number" || !Number.isSafeInteger(bps) || bps < 0 || bps > maxBps) throw new CustomError(ErrorCode.InvalidSuperSuite, `SuperSuites: ${label} must be an integer between 0 and ${maxBps}`);
49
+ return bps;
50
+ }
51
+ function assertBytes32Hex(value, label) {
52
+ if (typeof value !== "string" || !BYTES32_HEX_REGEX.test(value)) throw new CustomError(ErrorCode.InvalidSuperSuite, `SuperSuites: ${label} must be a 32-byte 0x hex digest`);
53
+ return value.toLowerCase();
54
+ }
55
+ function sha256Hex(payload) {
56
+ return `0x${createHash("sha256").update(payload, "utf8").digest("hex")}`;
57
+ }
58
+ /**
59
+ * Compute deterministic 32-byte Merkle/manifest commitment for an ArcSpace room (#1277).
60
+ */
61
+ function computeSpaceManifestRootDigest(input) {
62
+ return sha256Hex(JSON.stringify({
63
+ domain: "OCAP_ARCSPACE_ROOM_MANIFEST_V1",
64
+ spaceDid: input.spaceDid,
65
+ roomOwnerDid: input.roomOwnerDid,
66
+ version: input.version,
67
+ displayedStickerDids: [...input.displayedStickerDids],
68
+ placedMachineDids: [...input.placedMachineDids],
69
+ offChainLayoutCommitmentDigest: input.offChainLayoutCommitmentDigest.toLowerCase(),
70
+ epochIndex: input.epochIndex
71
+ }));
72
+ }
73
+ /**
74
+ * Compute deterministic commit-reveal digest for an ArcadeMachine instant jackpot round (#1276).
75
+ */
76
+ function computeArcadeCommitDigest(houseSecretHex, roundId, machineDid) {
77
+ const cleanSecret = assertBytes32Hex(houseSecretHex, "houseSecretHex");
78
+ const cleanRound = assertCleanDidOrId(roundId, "roundId");
79
+ return sha256Hex(`OCAP_ARCADE_COMMIT_V1:${assertCleanDidOrId(machineDid, "machineDid")}:${cleanRound}:${cleanSecret}`);
80
+ }
81
+ /**
82
+ * Master Engine implementing Issues #1273, #1275, #1276, and #1277 (closing Master Epic #1272):
83
+ * - #1273: Lazy Shared `SponsorBudgetPool` & `PrepaidBudgetCard` NFT
84
+ * - #1275: `IboPartnerEngine` (`ArcKey` equity decoupled from flat consumer ticket + tiered holder commission + O(1) dividend pool)
85
+ * - #1276: `(A,B,C,n,m)` `ArcadeMachinePool` conservation engine + 10 ABT `StickerOfferAndRoyalty` escrow
86
+ * - #1277: `SpaceManifestAnchor` ownership/delegation verifier + `AttentionStampEscrow` anti-spam micro-ABT stamp
87
+ */
88
+ var OcapSuperSuitesFoundationEngine = class {
89
+ constructor() {
90
+ this.sponsorPools = /* @__PURE__ */ new Map();
91
+ this.prepaidCards = /* @__PURE__ */ new Map();
92
+ this.consumedRedemptionIds = /* @__PURE__ */ new Set();
93
+ this.iboOrgs = /* @__PURE__ */ new Map();
94
+ this.iboPositions = /* @__PURE__ */ new Map();
95
+ this.consumedCheckoutIds = /* @__PURE__ */ new Set();
96
+ this.arcadeMachines = /* @__PURE__ */ new Map();
97
+ this.arcadeRoundPlayers = /* @__PURE__ */ new Map();
98
+ this.arcadeRoundCommits = /* @__PURE__ */ new Map();
99
+ this.settledArcadeRounds = /* @__PURE__ */ new Set();
100
+ this.consumedPlayIds = /* @__PURE__ */ new Set();
101
+ this.stickers = /* @__PURE__ */ new Map();
102
+ this.stickerOffers = /* @__PURE__ */ new Map();
103
+ this.spaceDelegations = /* @__PURE__ */ new Map();
104
+ this.spaceManifests = /* @__PURE__ */ new Map();
105
+ this.attentionStamps = /* @__PURE__ */ new Map();
106
+ }
107
+ createSponsorBudgetPool(input) {
108
+ if (!input || typeof input !== "object") throw new CustomError(ErrorCode.InvalidSuperSuite, "Missing createSponsorBudgetPool input");
109
+ const poolDid = assertCleanDidOrId(input.poolDid, "poolDid");
110
+ const sponsorDid = assertCleanDidOrId(input.sponsorDid, "sponsorDid");
111
+ const tokenAddress = assertCleanDidOrId(input.tokenAddress ?? DEFAULT_ABT_TOKEN_ADDRESS, "tokenAddress");
112
+ const initialFundedAbt = assertPositiveBigInt(input.initialFundedAbt, "initialFundedAbt");
113
+ const epochIndex = assertValidEpoch(input.epochIndex);
114
+ if (this.sponsorPools.has(poolDid)) throw new CustomError(ErrorCode.InvalidSuperSuite, `SponsorBudgetPool ${poolDid} already exists`);
115
+ const state = {
116
+ poolDid,
117
+ sponsorDid,
118
+ tokenAddress,
119
+ totalFundedAbt: initialFundedAbt,
120
+ totalDrainedAbt: 0n,
121
+ totalReclaimedAbt: 0n,
122
+ availableBalanceAbt: initialFundedAbt,
123
+ issuedCardCount: 0,
124
+ active: true,
125
+ createdAtEpoch: epochIndex
126
+ };
127
+ this.sponsorPools.set(poolDid, state);
128
+ return { ...state };
129
+ }
130
+ topUpSponsorBudgetPool(poolDid, callerDid, addAmountAbt) {
131
+ const cleanPoolDid = assertCleanDidOrId(poolDid, "poolDid");
132
+ const cleanCallerDid = assertCleanDidOrId(callerDid, "callerDid");
133
+ const amount = assertPositiveBigInt(addAmountAbt, "addAmountAbt");
134
+ const pool = this.sponsorPools.get(cleanPoolDid);
135
+ if (!pool) throw new CustomError(ErrorCode.InvalidSuperSuite, `Unknown SponsorBudgetPool: ${cleanPoolDid}`);
136
+ if (pool.sponsorDid !== cleanCallerDid) throw new CustomError(ErrorCode.ForbiddenSuperSuite, "Only pool sponsorDid can top up SponsorBudgetPool");
137
+ pool.totalFundedAbt += amount;
138
+ pool.availableBalanceAbt += amount;
139
+ pool.active = true;
140
+ return { ...pool };
141
+ }
142
+ reclaimUnusedSponsorBudgetPool(poolDid, callerDid, reclaimAmountAbt) {
143
+ const cleanPoolDid = assertCleanDidOrId(poolDid, "poolDid");
144
+ const cleanCallerDid = assertCleanDidOrId(callerDid, "callerDid");
145
+ const amount = assertPositiveBigInt(reclaimAmountAbt, "reclaimAmountAbt");
146
+ const pool = this.sponsorPools.get(cleanPoolDid);
147
+ if (!pool) throw new CustomError(ErrorCode.InvalidSuperSuite, `Unknown SponsorBudgetPool: ${cleanPoolDid}`);
148
+ if (pool.sponsorDid !== cleanCallerDid) throw new CustomError(ErrorCode.ForbiddenSuperSuite, "Only pool sponsorDid can reclaim unused SponsorBudgetPool balance");
149
+ if (amount > pool.availableBalanceAbt) throw new CustomError(ErrorCode.InvalidSuperSuite, `Reclaim amount (${amount}) exceeds available pool balance (${pool.availableBalanceAbt})`);
150
+ pool.availableBalanceAbt -= amount;
151
+ pool.totalReclaimedAbt += amount;
152
+ return { ...pool };
153
+ }
154
+ issuePrepaidBudgetCard(input) {
155
+ if (!input || typeof input !== "object") throw new CustomError(ErrorCode.InvalidSuperSuite, "Missing issuePrepaidBudgetCard input");
156
+ const cardDid = assertCleanDidOrId(input.cardDid, "cardDid");
157
+ const poolDid = assertCleanDidOrId(input.poolDid, "poolDid");
158
+ const callerDid = assertCleanDidOrId(input.callerDid, "callerDid");
159
+ const recipientHolderDid = assertCleanDidOrId(input.recipientHolderDid, "recipientHolderDid");
160
+ const maxAllowanceAbt = assertPositiveBigInt(input.maxAllowanceAbt, "maxAllowanceAbt");
161
+ const dailyLimitAbt = assertPositiveBigInt(input.dailyLimitAbt, "dailyLimitAbt");
162
+ const issuedAtEpoch = assertValidEpoch(input.issuedAtEpoch, "issuedAtEpoch");
163
+ const expiresAtEpoch = assertValidEpoch(input.expiresAtEpoch, "expiresAtEpoch");
164
+ if (this.prepaidCards.has(cardDid)) throw new CustomError(ErrorCode.InvalidSuperSuite, `PrepaidBudgetCard ${cardDid} already exists`);
165
+ if (dailyLimitAbt > maxAllowanceAbt) throw new CustomError(ErrorCode.InvalidSuperSuite, "dailyLimitAbt cannot exceed maxAllowanceAbt");
166
+ if (expiresAtEpoch < issuedAtEpoch) throw new CustomError(ErrorCode.InvalidSuperSuite, "expiresAtEpoch must be >= issuedAtEpoch");
167
+ const pool = this.sponsorPools.get(poolDid);
168
+ if (!pool || !pool.active) throw new CustomError(ErrorCode.InvalidSuperSuite, `SponsorBudgetPool ${poolDid} does not exist or is inactive`);
169
+ if (pool.sponsorDid !== callerDid) throw new CustomError(ErrorCode.ForbiddenSuperSuite, "Only the SponsorBudgetPool owner can issue PrepaidBudgetCard NFTs");
170
+ if (recipientHolderDid === pool.sponsorDid) throw new CustomError(ErrorCode.InvalidSuperSuite, "recipientHolderDid must be distinct from sponsorDid to prevent circular wash redemptions");
171
+ if (!Array.isArray(input.allowedProviderDids) || input.allowedProviderDids.length === 0 || input.allowedProviderDids.length > MAX_PREPAID_CARD_ALLOWED_PROVIDERS) throw new CustomError(ErrorCode.InvalidSuperSuite, `allowedProviderDids must contain 1..${MAX_PREPAID_CARD_ALLOWED_PROVIDERS} whitelisted service provider DIDs`);
172
+ const dedupProviders = Array.from(new Set(input.allowedProviderDids.map((p, idx) => assertCleanDidOrId(p, `allowedProviderDids[${idx}]`))));
173
+ for (const pDid of dedupProviders) if (pDid === recipientHolderDid || pDid === pool.sponsorDid) throw new CustomError(ErrorCode.ForbiddenSuperSuite, "allowedProviderDids cannot include recipientHolderDid or sponsorDid (cashout prohibition)");
174
+ pool.issuedCardCount += 1;
175
+ const card = {
176
+ cardDid,
177
+ poolDid,
178
+ sponsorDid: pool.sponsorDid,
179
+ holderDid: recipientHolderDid,
180
+ maxAllowanceAbt,
181
+ consumedAbt: 0n,
182
+ dailyLimitAbt,
183
+ dailyConsumedByDay: {},
184
+ allowedProviderDids: dedupProviders,
185
+ issuedAtEpoch,
186
+ expiresAtEpoch,
187
+ transferable: false,
188
+ cashoutAllowed: false,
189
+ revoked: false
190
+ };
191
+ this.prepaidCards.set(cardDid, card);
192
+ return {
193
+ ...card,
194
+ dailyConsumedByDay: { ...card.dailyConsumedByDay },
195
+ allowedProviderDids: [...card.allowedProviderDids]
196
+ };
197
+ }
198
+ redeemPrepaidBudgetCard(input) {
199
+ if (!input || typeof input !== "object") throw new CustomError(ErrorCode.InvalidSuperSuite, "Missing redeemPrepaidBudgetCard input");
200
+ const redemptionId = assertCleanDidOrId(input.redemptionId, "redemptionId");
201
+ const cardDid = assertCleanDidOrId(input.cardDid, "cardDid");
202
+ const callerDid = assertCleanDidOrId(input.callerDid, "callerDid");
203
+ const providerDid = assertCleanDidOrId(input.providerDid, "providerDid");
204
+ const serviceRefId = assertCleanDidOrId(input.serviceRefId, "serviceRefId");
205
+ const redeemAmountAbt = assertPositiveBigInt(input.redeemAmountAbt, "redeemAmountAbt");
206
+ const epochIndex = assertValidEpoch(input.epochIndex, "epochIndex");
207
+ const dayIndex = input.dayIndex !== void 0 ? assertValidEpoch(input.dayIndex, "dayIndex") : epochIndex;
208
+ if (dayIndex !== epochIndex) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `dayIndex (${dayIndex}) must match canonical epochIndex (${epochIndex}) to prevent dailyLimitAbt bypass`);
209
+ if (this.consumedRedemptionIds.has(redemptionId)) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `Duplicate prepaid card redemptionId: ${redemptionId}`);
210
+ const card = this.prepaidCards.get(cardDid);
211
+ if (!card) throw new CustomError(ErrorCode.InvalidSuperSuite, `Unknown PrepaidBudgetCard: ${cardDid}`);
212
+ if (card.holderDid !== callerDid) throw new CustomError(ErrorCode.ForbiddenSuperSuite, "PrepaidBudgetCard is non-transferable and can only be redeemed by its holderDid");
213
+ if (card.revoked) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `PrepaidBudgetCard ${cardDid} has been revoked`);
214
+ if (epochIndex < card.issuedAtEpoch || epochIndex > card.expiresAtEpoch) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `PrepaidBudgetCard ${cardDid} is outside valid epoch window (${card.issuedAtEpoch}..${card.expiresAtEpoch}) at epoch ${epochIndex}`);
215
+ if (providerDid === card.holderDid || providerDid === card.sponsorDid) throw new CustomError(ErrorCode.ForbiddenSuperSuite, "PrepaidBudgetCard cannot be redeemed to holderDid or sponsorDid (cashout forbidden)");
216
+ if (!card.allowedProviderDids.includes(providerDid)) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `Provider ${providerDid} is not whitelisted on PrepaidBudgetCard ${cardDid}`);
217
+ const remainingCardAllowance = card.maxAllowanceAbt - card.consumedAbt;
218
+ if (redeemAmountAbt > remainingCardAllowance) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `Redemption (${redeemAmountAbt}) exceeds remaining card allowance (${remainingCardAllowance})`);
219
+ const consumedToday = card.dailyConsumedByDay[dayIndex] ?? 0n;
220
+ const remainingDailyAllowance = card.dailyLimitAbt - consumedToday;
221
+ if (redeemAmountAbt > remainingDailyAllowance) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `Redemption (${redeemAmountAbt}) exceeds remaining daily limit (${remainingDailyAllowance}) for day ${dayIndex}`);
222
+ const pool = this.sponsorPools.get(card.poolDid);
223
+ if (!pool || !pool.active) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `SponsorBudgetPool ${card.poolDid} is inactive`);
224
+ if (redeemAmountAbt > pool.availableBalanceAbt) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `SponsorBudgetPool ${card.poolDid} has insufficient available ABT (${pool.availableBalanceAbt} < ${redeemAmountAbt})`);
225
+ this.consumedRedemptionIds.add(redemptionId);
226
+ card.consumedAbt += redeemAmountAbt;
227
+ card.dailyConsumedByDay[dayIndex] = consumedToday + redeemAmountAbt;
228
+ pool.availableBalanceAbt -= redeemAmountAbt;
229
+ pool.totalDrainedAbt += redeemAmountAbt;
230
+ const statements = [{
231
+ type: "transfer_v3",
232
+ typeUrl: "fg:t:transfer_v3",
233
+ from: pool.poolDid,
234
+ itx: {
235
+ to: providerDid,
236
+ tokens: [{
237
+ address: pool.tokenAddress,
238
+ value: redeemAmountAbt.toString(10)
239
+ }],
240
+ data: {
241
+ type: "json",
242
+ value: JSON.stringify({
243
+ primitive: "PREPAID_BUDGET_CARD_REDEMPTION",
244
+ redemptionId,
245
+ cardDid,
246
+ holderDid: card.holderDid,
247
+ serviceRefId,
248
+ epochIndex,
249
+ dayIndex
250
+ })
251
+ }
252
+ }
253
+ }];
254
+ const postConditions = {
255
+ signer: pool.poolDid,
256
+ maxTokenOutflow: { [pool.tokenAddress]: redeemAmountAbt.toString(10) },
257
+ strictZeroUnlistedOutflow: true
258
+ };
259
+ return {
260
+ redemptionId,
261
+ cardDid,
262
+ poolDid: pool.poolDid,
263
+ holderDid: card.holderDid,
264
+ providerDid,
265
+ serviceRefId,
266
+ drainedAbt: redeemAmountAbt,
267
+ remainingCardAllowanceAbt: card.maxAllowanceAbt - card.consumedAbt,
268
+ remainingDailyAllowanceAbt: card.dailyLimitAbt - card.dailyConsumedByDay[dayIndex],
269
+ remainingPoolAvailableAbt: pool.availableBalanceAbt,
270
+ capitalFrozenAtMintAbt: 0n,
271
+ statements,
272
+ postConditions
273
+ };
274
+ }
275
+ getSponsorBudgetPool(poolDid) {
276
+ const p = this.sponsorPools.get(poolDid);
277
+ return p ? { ...p } : void 0;
278
+ }
279
+ getPrepaidBudgetCard(cardDid) {
280
+ const c = this.prepaidCards.get(cardDid);
281
+ return c ? {
282
+ ...c,
283
+ dailyConsumedByDay: { ...c.dailyConsumedByDay },
284
+ allowedProviderDids: [...c.allowedProviderDids]
285
+ } : void 0;
286
+ }
287
+ registerIboOrganization(input) {
288
+ if (!input || typeof input !== "object") throw new CustomError(ErrorCode.InvalidSuperSuite, "Missing registerIboOrganization input");
289
+ const orgDid = assertCleanDidOrId(input.orgDid, "orgDid");
290
+ const creatorDid = assertCleanDidOrId(input.creatorDid, "creatorDid");
291
+ const computeProviderDid = assertCleanDidOrId(input.computeProviderDid, "computeProviderDid");
292
+ const tokenAddress = assertCleanDidOrId(input.tokenAddress ?? DEFAULT_ABT_TOKEN_ADDRESS, "tokenAddress");
293
+ const baseAffiliateBps = assertValidBps(input.baseAffiliateBps, "baseAffiliateBps", 5e3);
294
+ const holderAffiliateBps = assertValidBps(input.holderAffiliateBps, "holderAffiliateBps", 5e3);
295
+ const dividendPoolBps = assertValidBps(input.dividendPoolBps, "dividendPoolBps", 5e3);
296
+ const computeSplitBps = assertValidBps(input.computeSplitBps, "computeSplitBps", 5e3);
297
+ const minPartnerKeyBalance = assertPositiveBigInt(input.minPartnerKeyBalance, "minPartnerKeyBalance");
298
+ const epochIndex = assertValidEpoch(input.epochIndex);
299
+ if (this.iboOrgs.has(orgDid)) throw new CustomError(ErrorCode.InvalidSuperSuite, `IBO Organization ${orgDid} already exists`);
300
+ if (holderAffiliateBps < baseAffiliateBps) throw new CustomError(ErrorCode.InvalidSuperSuite, "holderAffiliateBps must be >= baseAffiliateBps to incentivize ArcKey partner ownership");
301
+ const maxNonCreatorBps = holderAffiliateBps + dividendPoolBps + computeSplitBps;
302
+ if (maxNonCreatorBps > MAX_IBO_TOTAL_FEE_SPLIT_BPS) throw new CustomError(ErrorCode.InvalidSuperSuite, `holderAffiliateBps + dividendPoolBps + computeSplitBps (${maxNonCreatorBps}) cannot exceed ${MAX_IBO_TOTAL_FEE_SPLIT_BPS} bps`);
303
+ const posMap = /* @__PURE__ */ new Map();
304
+ let totalKeys = 0n;
305
+ if (Array.isArray(input.initialPartners)) for (let i = 0; i < input.initialPartners.length; i += 1) {
306
+ const entry = input.initialPartners[i];
307
+ const partnerDid = assertCleanDidOrId(entry.partnerDid, `initialPartners[${i}].partnerDid`);
308
+ const keyBalance = assertPositiveBigInt(entry.keyBalance, `initialPartners[${i}].keyBalance`);
309
+ if (posMap.has(partnerDid)) throw new CustomError(ErrorCode.InvalidSuperSuite, `Duplicate initial partnerDid: ${partnerDid}`);
310
+ posMap.set(partnerDid, {
311
+ orgDid,
312
+ partnerDid,
313
+ keyBalance,
314
+ rewardDebtScaled: 0n,
315
+ pendingUnclaimedAbt: 0n,
316
+ cumulativeClaimedAbt: 0n
317
+ });
318
+ totalKeys += keyBalance;
319
+ }
320
+ const state = {
321
+ orgDid,
322
+ creatorDid,
323
+ computeProviderDid,
324
+ tokenAddress,
325
+ baseAffiliateBps,
326
+ holderAffiliateBps,
327
+ dividendPoolBps,
328
+ computeSplitBps,
329
+ minPartnerKeyBalance,
330
+ totalPartnerKeysSupply: totalKeys,
331
+ accDividendPerKeyScaled: 0n,
332
+ undistributedDividendRemainderScaled: 0n,
333
+ totalGrossVolumeAbt: 0n,
334
+ totalAffiliatePaidAbt: 0n,
335
+ totalDividendsDistributedAbt: 0n,
336
+ totalDividendClaimedAbt: 0n,
337
+ totalComputePaidAbt: 0n,
338
+ totalCreatorNetAbt: 0n,
339
+ createdAtEpoch: epochIndex
340
+ };
341
+ this.iboOrgs.set(orgDid, state);
342
+ this.iboPositions.set(orgDid, posMap);
343
+ return { ...state };
344
+ }
345
+ settlePartnerPendingReward(org, pos) {
346
+ const accumulatedScaled = pos.keyBalance * org.accDividendPerKeyScaled;
347
+ if (accumulatedScaled > pos.rewardDebtScaled) {
348
+ const newlyEarnedAbt = (accumulatedScaled - pos.rewardDebtScaled) / IBO_DIVIDEND_PRECISION;
349
+ pos.pendingUnclaimedAbt += newlyEarnedAbt;
350
+ }
351
+ pos.rewardDebtScaled = pos.keyBalance * org.accDividendPerKeyScaled;
352
+ }
353
+ updatePartnerKeyBalance(orgDid, callerDid, partnerDid, newKeyBalance) {
354
+ const cleanOrgDid = assertCleanDidOrId(orgDid, "orgDid");
355
+ const cleanCallerDid = assertCleanDidOrId(callerDid, "callerDid");
356
+ const cleanPartnerDid = assertCleanDidOrId(partnerDid, "partnerDid");
357
+ const balance = assertNonNegativeBigInt(newKeyBalance, "newKeyBalance");
358
+ const org = this.iboOrgs.get(cleanOrgDid);
359
+ const posMap = this.iboPositions.get(cleanOrgDid);
360
+ if (!org || !posMap) throw new CustomError(ErrorCode.InvalidSuperSuite, `Unknown IBO Organization: ${cleanOrgDid}`);
361
+ if (cleanCallerDid !== org.creatorDid) throw new CustomError(ErrorCode.ForbiddenSuperSuite, "Only IBO Organization creatorDid is authorized to update partner key balances");
362
+ let pos = posMap.get(cleanPartnerDid);
363
+ if (!pos) {
364
+ pos = {
365
+ orgDid: cleanOrgDid,
366
+ partnerDid: cleanPartnerDid,
367
+ keyBalance: 0n,
368
+ rewardDebtScaled: 0n,
369
+ pendingUnclaimedAbt: 0n,
370
+ cumulativeClaimedAbt: 0n
371
+ };
372
+ posMap.set(cleanPartnerDid, pos);
373
+ } else this.settlePartnerPendingReward(org, pos);
374
+ org.totalPartnerKeysSupply = org.totalPartnerKeysSupply - pos.keyBalance + balance;
375
+ pos.keyBalance = balance;
376
+ pos.rewardDebtScaled = pos.keyBalance * org.accDividendPerKeyScaled;
377
+ return { ...pos };
378
+ }
379
+ settleIboServiceCheckout(input) {
380
+ if (!input || typeof input !== "object") throw new CustomError(ErrorCode.InvalidSuperSuite, "Missing settleIboServiceCheckout input");
381
+ const checkoutId = assertCleanDidOrId(input.checkoutId, "checkoutId");
382
+ const orgDid = assertCleanDidOrId(input.orgDid, "orgDid");
383
+ const buyerDid = assertCleanDidOrId(input.buyerDid, "buyerDid");
384
+ const serviceId = assertCleanDidOrId(input.serviceId, "serviceId");
385
+ const ticketPriceAbt = assertPositiveBigInt(input.ticketPriceAbt, "ticketPriceAbt");
386
+ const epochIndex = assertValidEpoch(input.epochIndex);
387
+ if (this.consumedCheckoutIds.has(checkoutId)) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `Duplicate IBO checkoutId: ${checkoutId}`);
388
+ const org = this.iboOrgs.get(orgDid);
389
+ const posMap = this.iboPositions.get(orgDid);
390
+ if (!org || !posMap) throw new CustomError(ErrorCode.InvalidSuperSuite, `Unknown IBO Organization: ${orgDid}`);
391
+ let referrerDid;
392
+ let referrerIsPartnerHolder = false;
393
+ let appliedAffiliateBps = 0;
394
+ if (input.referrerDid !== void 0) {
395
+ referrerDid = assertCleanDidOrId(input.referrerDid, "referrerDid");
396
+ if (referrerDid === buyerDid) throw new CustomError(ErrorCode.ForbiddenSuperSuite, "Self-referral is strictly forbidden in IBO checkout (referrerDid === buyerDid)");
397
+ const refPos = posMap.get(referrerDid);
398
+ referrerIsPartnerHolder = (refPos ? refPos.keyBalance : 0n) >= org.minPartnerKeyBalance;
399
+ appliedAffiliateBps = referrerIsPartnerHolder ? org.holderAffiliateBps : org.baseAffiliateBps;
400
+ }
401
+ let payerDid = buyerDid;
402
+ let fundedViaPrepaidCardDid;
403
+ if (input.prepaidCardRedemption) {
404
+ if (referrerDid !== void 0) throw new CustomError(ErrorCode.ForbiddenSuperSuite, "PrepaidBudgetCard redemptions cannot pay external affiliate commissions (cashout prohibition)");
405
+ const cleanCardDid = assertCleanDidOrId(input.prepaidCardRedemption.cardDid, "prepaidCardRedemption.cardDid");
406
+ const card = this.prepaidCards.get(cleanCardDid);
407
+ if (!card) throw new CustomError(ErrorCode.InvalidSuperSuite, `Unknown PrepaidBudgetCard: ${cleanCardDid}`);
408
+ if (buyerDid === org.creatorDid || buyerDid === org.computeProviderDid || card.sponsorDid === org.creatorDid || card.sponsorDid === org.computeProviderDid || (posMap.get(buyerDid)?.keyBalance ?? 0n) > 0n || (posMap.get(card.sponsorDid)?.keyBalance ?? 0n) > 0n) throw new CustomError(ErrorCode.ForbiddenSuperSuite, "PrepaidBudgetCard holder or sponsor cannot be IBO creator, compute provider, or ArcKey partner (wash-cashout prohibition)");
409
+ if (!card.allowedProviderDids.includes(orgDid) || !card.allowedProviderDids.includes(org.creatorDid) || org.computeSplitBps > 0 && !card.allowedProviderDids.includes(org.computeProviderDid)) throw new CustomError(ErrorCode.ForbiddenSuperSuite, "All IBO checkout split recipients (orgDid, creatorDid, computeProviderDid) must be whitelisted in PrepaidBudgetCard allowedProviderDids");
410
+ const cardRedeem = this.redeemPrepaidBudgetCard({
411
+ redemptionId: `ibo-redeem-${checkoutId}`,
412
+ cardDid: cleanCardDid,
413
+ callerDid: buyerDid,
414
+ providerDid: orgDid,
415
+ serviceRefId: serviceId,
416
+ redeemAmountAbt: ticketPriceAbt,
417
+ epochIndex,
418
+ dayIndex: input.prepaidCardRedemption.dayIndex
419
+ });
420
+ payerDid = cardRedeem.poolDid;
421
+ fundedViaPrepaidCardDid = cardRedeem.cardDid;
422
+ }
423
+ this.consumedCheckoutIds.add(checkoutId);
424
+ const affiliateAbt = ticketPriceAbt * BigInt(appliedAffiliateBps) / BPS_DENOMINATOR;
425
+ const dividendAbt = org.totalPartnerKeysSupply > 0n ? ticketPriceAbt * BigInt(org.dividendPoolBps) / BPS_DENOMINATOR : 0n;
426
+ const computeAbt = ticketPriceAbt * BigInt(org.computeSplitBps) / BPS_DENOMINATOR;
427
+ const creatorNetAbt = ticketPriceAbt - affiliateAbt - dividendAbt - computeAbt;
428
+ if (affiliateAbt + dividendAbt + computeAbt + creatorNetAbt !== ticketPriceAbt || creatorNetAbt < 0n) throw new CustomError(ErrorCode.ConservationViolation, "IBO checkout split failed conservation check");
429
+ if (dividendAbt > 0n && org.totalPartnerKeysSupply > 0n) {
430
+ const totalScaledDividend = dividendAbt * IBO_DIVIDEND_PRECISION + org.undistributedDividendRemainderScaled;
431
+ const deltaPerKeyScaled = totalScaledDividend / org.totalPartnerKeysSupply;
432
+ org.accDividendPerKeyScaled += deltaPerKeyScaled;
433
+ org.undistributedDividendRemainderScaled = totalScaledDividend % org.totalPartnerKeysSupply;
434
+ }
435
+ org.totalGrossVolumeAbt += ticketPriceAbt;
436
+ org.totalAffiliatePaidAbt += affiliateAbt;
437
+ org.totalDividendsDistributedAbt += dividendAbt;
438
+ org.totalComputePaidAbt += computeAbt;
439
+ org.totalCreatorNetAbt += creatorNetAbt;
440
+ const statements = [];
441
+ const pushSplitTransfer = (toDid, amount, splitRole) => {
442
+ if (amount <= 0n) return;
443
+ statements.push({
444
+ type: "transfer_v3",
445
+ typeUrl: "fg:t:transfer_v3",
446
+ from: payerDid,
447
+ itx: {
448
+ to: toDid,
449
+ tokens: [{
450
+ address: org.tokenAddress,
451
+ value: amount.toString(10)
452
+ }],
453
+ data: {
454
+ type: "json",
455
+ value: JSON.stringify({
456
+ primitive: "IBO_SERVICE_CHECKOUT_SPLIT",
457
+ checkoutId,
458
+ orgDid,
459
+ buyerDid,
460
+ serviceId,
461
+ splitRole,
462
+ fundedViaPrepaidCardDid
463
+ })
464
+ }
465
+ }
466
+ });
467
+ };
468
+ if (referrerDid && affiliateAbt > 0n) pushSplitTransfer(referrerDid, affiliateAbt, referrerIsPartnerHolder ? "PARTNER_HOLDER_AFFILIATE" : "BASE_AFFILIATE");
469
+ pushSplitTransfer(orgDid, dividendAbt, "IBO_PARTNER_DIVIDEND_POOL");
470
+ pushSplitTransfer(org.computeProviderDid, computeAbt, "ARC_COMPUTE_SPLIT");
471
+ pushSplitTransfer(org.creatorDid, creatorNetAbt, "CREATOR_NET_REVENUE");
472
+ const postConditions = {
473
+ signer: payerDid,
474
+ maxTokenOutflow: { [org.tokenAddress]: ticketPriceAbt.toString(10) },
475
+ strictZeroUnlistedOutflow: true
476
+ };
477
+ return {
478
+ checkoutId,
479
+ orgDid,
480
+ buyerDid,
481
+ payerDid,
482
+ fundedViaPrepaidCardDid,
483
+ ticketPriceAbt,
484
+ referrerDid,
485
+ referrerIsPartnerHolder,
486
+ appliedAffiliateBps,
487
+ affiliateAbt,
488
+ dividendAbt,
489
+ computeAbt,
490
+ creatorNetAbt,
491
+ conservationVerified: true,
492
+ statements,
493
+ postConditions
494
+ };
495
+ }
496
+ claimIboPartnerDividend(orgDid, partnerDid) {
497
+ const cleanOrgDid = assertCleanDidOrId(orgDid, "orgDid");
498
+ const cleanPartnerDid = assertCleanDidOrId(partnerDid, "partnerDid");
499
+ const org = this.iboOrgs.get(cleanOrgDid);
500
+ const posMap = this.iboPositions.get(cleanOrgDid);
501
+ if (!org || !posMap) throw new CustomError(ErrorCode.InvalidSuperSuite, `Unknown IBO Organization: ${cleanOrgDid}`);
502
+ const pos = posMap.get(cleanPartnerDid);
503
+ if (!pos) throw new CustomError(ErrorCode.InvalidSuperSuite, `Partner ${cleanPartnerDid} has no position in ${cleanOrgDid}`);
504
+ this.settlePartnerPendingReward(org, pos);
505
+ const claimable = pos.pendingUnclaimedAbt;
506
+ if (claimable <= 0n) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `Partner ${cleanPartnerDid} has 0 claimable dividend ABT`);
507
+ if (claimable > org.totalDividendsDistributedAbt - org.totalDividendClaimedAbt) throw new CustomError(ErrorCode.ConservationViolation, "Dividend claim exceeds available IBO dividend pool");
508
+ pos.pendingUnclaimedAbt = 0n;
509
+ pos.cumulativeClaimedAbt += claimable;
510
+ org.totalDividendClaimedAbt += claimable;
511
+ return {
512
+ orgDid: cleanOrgDid,
513
+ partnerDid: cleanPartnerDid,
514
+ claimedAbt: claimable,
515
+ cumulativeClaimedAbt: pos.cumulativeClaimedAbt,
516
+ statements: [{
517
+ type: "transfer_v3",
518
+ typeUrl: "fg:t:transfer_v3",
519
+ from: cleanOrgDid,
520
+ itx: {
521
+ to: cleanPartnerDid,
522
+ tokens: [{
523
+ address: org.tokenAddress,
524
+ value: claimable.toString(10)
525
+ }],
526
+ data: {
527
+ type: "json",
528
+ value: JSON.stringify({
529
+ primitive: "IBO_PARTNER_DIVIDEND_CLAIM",
530
+ orgDid: cleanOrgDid,
531
+ partnerDid: cleanPartnerDid
532
+ })
533
+ }
534
+ }
535
+ }]
536
+ };
537
+ }
538
+ getIboOrganization(orgDid) {
539
+ const o = this.iboOrgs.get(orgDid);
540
+ return o ? { ...o } : void 0;
541
+ }
542
+ registerArcadeMachine(input) {
543
+ if (!input || typeof input !== "object") throw new CustomError(ErrorCode.InvalidSuperSuite, "Missing registerArcadeMachine input");
544
+ const machineDid = assertCleanDidOrId(input.machineDid, "machineDid");
545
+ const gameCreatorDid = assertCleanDidOrId(input.gameCreatorDid, "gameCreatorDid");
546
+ const stickerArtistDid = assertCleanDidOrId(input.stickerArtistDid, "stickerArtistDid");
547
+ const roomHostDid = assertCleanDidOrId(input.roomHostDid, "roomHostDid");
548
+ const protocolTreasuryDid = assertCleanDidOrId(input.protocolTreasuryDid, "protocolTreasuryDid");
549
+ const tokenAddress = assertCleanDidOrId(input.tokenAddress ?? DEFAULT_ABT_TOKEN_ADDRESS, "tokenAddress");
550
+ const ticketPriceAbt = assertPositiveBigInt(input.ticketPriceAbt, "ticketPriceAbt");
551
+ const epochIndex = assertValidEpoch(input.epochIndex);
552
+ if (this.arcadeMachines.has(machineDid)) throw new CustomError(ErrorCode.InvalidSuperSuite, `ArcadeMachine ${machineDid} already exists`);
553
+ const creatorSplitBps = assertValidBps(input.creatorSplitBps, "creatorSplitBps", MAX_ARCADE_HOUSE_SPLIT_BPS);
554
+ const artistSplitBps = assertValidBps(input.artistSplitBps, "artistSplitBps", MAX_ARCADE_HOUSE_SPLIT_BPS);
555
+ const roomHostSplitBps = assertValidBps(input.roomHostSplitBps, "roomHostSplitBps", MAX_ARCADE_HOUSE_SPLIT_BPS);
556
+ const referrerSplitBps = assertValidBps(input.referrerSplitBps, "referrerSplitBps", MAX_ARCADE_HOUSE_SPLIT_BPS);
557
+ const protocolSplitBps = assertValidBps(input.protocolSplitBps, "protocolSplitBps", MAX_ARCADE_HOUSE_SPLIT_BPS);
558
+ const totalHouseSplitBps = creatorSplitBps + artistSplitBps + roomHostSplitBps + referrerSplitBps + protocolSplitBps;
559
+ if (totalHouseSplitBps < MIN_ARCADE_HOUSE_SPLIT_BPS || totalHouseSplitBps > MAX_ARCADE_HOUSE_SPLIT_BPS) throw new CustomError(ErrorCode.InvalidSuperSuite, `Total house split B (${totalHouseSplitBps} bps) must be between ${MIN_ARCADE_HOUSE_SPLIT_BPS} and ${MAX_ARCADE_HOUSE_SPLIT_BPS} bps so Pool C receives >= 50%`);
560
+ if (input.settlementMode !== "COMMIT_REVEAL_INSTANT_JACKPOT" && input.settlementMode !== "TABLE_MATCH_SETTLEMENT" && input.settlementMode !== "EPOCH_HIGH_SCORE_LEADERBOARD") throw new CustomError(ErrorCode.InvalidSuperSuite, `Unsupported settlementMode: ${String(input.settlementMode)}`);
561
+ const state = {
562
+ machineDid,
563
+ gameCreatorDid,
564
+ stickerArtistDid,
565
+ roomHostDid,
566
+ protocolTreasuryDid,
567
+ tokenAddress,
568
+ ticketPriceAbt,
569
+ creatorSplitBps,
570
+ artistSplitBps,
571
+ roomHostSplitBps,
572
+ referrerSplitBps,
573
+ protocolSplitBps,
574
+ totalHouseSplitBps,
575
+ prizePoolContributionBps: 1e4 - totalHouseSplitBps,
576
+ settlementMode: input.settlementMode,
577
+ poolBalanceAbt: 0n,
578
+ totalTicketsPlayed: 0,
579
+ totalGrossInflowAbt: 0n,
580
+ totalSplitBPaidAbt: 0n,
581
+ totalPoolCAddedAbt: 0n,
582
+ totalPayoutsDistributedAbt: 0n,
583
+ createdAtEpoch: epochIndex
584
+ };
585
+ this.arcadeMachines.set(machineDid, state);
586
+ return { ...state };
587
+ }
588
+ playArcadeMachineTicket(input) {
589
+ if (!input || typeof input !== "object") throw new CustomError(ErrorCode.InvalidSuperSuite, "Missing playArcadeMachineTicket input");
590
+ const playId = assertCleanDidOrId(input.playId, "playId");
591
+ const roundId = assertCleanDidOrId(input.roundId, "roundId");
592
+ const machineDid = assertCleanDidOrId(input.machineDid, "machineDid");
593
+ const playerDid = assertCleanDidOrId(input.playerDid, "playerDid");
594
+ assertValidEpoch(input.epochIndex);
595
+ if (this.consumedPlayIds.has(playId)) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `Duplicate arcade playId: ${playId}`);
596
+ const machine = this.arcadeMachines.get(machineDid);
597
+ if (!machine) throw new CustomError(ErrorCode.InvalidSuperSuite, `Unknown ArcadeMachine: ${machineDid}`);
598
+ const roundKey = `${machineDid}::${roundId}`;
599
+ if (this.settledArcadeRounds.has(roundKey)) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `Arcade round ${roundKey} has already been settled`);
600
+ let validatedCommitDigest;
601
+ if (machine.settlementMode === "COMMIT_REVEAL_INSTANT_JACKPOT") {
602
+ validatedCommitDigest = assertBytes32Hex(input.houseCommitDigest ?? "", "houseCommitDigest");
603
+ const existingCommit = this.arcadeRoundCommits.get(roundKey);
604
+ if (existingCommit && existingCommit !== validatedCommitDigest) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `Conflicting houseCommitDigest for round ${roundKey}`);
605
+ }
606
+ let referrerDid;
607
+ if (input.referrerDid !== void 0) {
608
+ referrerDid = assertCleanDidOrId(input.referrerDid, "referrerDid");
609
+ if (referrerDid === playerDid) throw new CustomError(ErrorCode.ForbiddenSuperSuite, "Self-referral is strictly forbidden in ArcadeMachine play (referrerDid === playerDid)");
610
+ }
611
+ const payerDid = playerDid;
612
+ const fundedViaPrepaidCardDid = void 0;
613
+ if (input.prepaidCardRedemption) throw new CustomError(ErrorCode.ForbiddenSuperSuite, "PrepaidBudgetCard (cashoutAllowed: false) cannot fund cash-payout ArcadeMachine tickets");
614
+ if (validatedCommitDigest) this.arcadeRoundCommits.set(roundKey, validatedCommitDigest);
615
+ this.consumedPlayIds.add(playId);
616
+ let playersInRound = this.arcadeRoundPlayers.get(roundKey);
617
+ if (!playersInRound) {
618
+ playersInRound = /* @__PURE__ */ new Set();
619
+ this.arcadeRoundPlayers.set(roundKey, playersInRound);
620
+ }
621
+ playersInRound.add(playerDid);
622
+ const A = machine.ticketPriceAbt;
623
+ const creatorAbt = A * BigInt(machine.creatorSplitBps) / BPS_DENOMINATOR;
624
+ const artistAbt = A * BigInt(machine.artistSplitBps) / BPS_DENOMINATOR;
625
+ const roomHostAbt = A * BigInt(machine.roomHostSplitBps) / BPS_DENOMINATOR;
626
+ const referrerAbt = referrerDid ? A * BigInt(machine.referrerSplitBps) / BPS_DENOMINATOR : 0n;
627
+ const protocolAbt = A * BigInt(machine.protocolSplitBps) / BPS_DENOMINATOR;
628
+ const totalBAbt = creatorAbt + artistAbt + roomHostAbt + referrerAbt + protocolAbt;
629
+ const poolCAddedAbt = A - totalBAbt;
630
+ if (totalBAbt + poolCAddedAbt !== A || poolCAddedAbt <= 0n) throw new CustomError(ErrorCode.ConservationViolation, "ArcadeMachine (A = B + C) conservation equation violated");
631
+ machine.poolBalanceAbt += poolCAddedAbt;
632
+ machine.totalTicketsPlayed += 1;
633
+ machine.totalGrossInflowAbt += A;
634
+ machine.totalSplitBPaidAbt += totalBAbt;
635
+ machine.totalPoolCAddedAbt += poolCAddedAbt;
636
+ const statements = [];
637
+ const pushSplit = (toDid, amount, role) => {
638
+ if (amount <= 0n) return;
639
+ statements.push({
640
+ type: "transfer_v3",
641
+ typeUrl: "fg:t:transfer_v3",
642
+ from: payerDid,
643
+ itx: {
644
+ to: toDid,
645
+ tokens: [{
646
+ address: machine.tokenAddress,
647
+ value: amount.toString(10)
648
+ }],
649
+ data: {
650
+ type: "json",
651
+ value: JSON.stringify({
652
+ primitive: "ARCADE_MACHINE_TICKET_SPLIT",
653
+ playId,
654
+ roundId,
655
+ machineDid,
656
+ playerDid,
657
+ role
658
+ })
659
+ }
660
+ }
661
+ });
662
+ };
663
+ pushSplit(machine.gameCreatorDid, creatorAbt, "B_GAME_CREATOR");
664
+ pushSplit(machine.stickerArtistDid, artistAbt, "B_STICKER_ARTIST");
665
+ pushSplit(machine.roomHostDid, roomHostAbt, "B_SANDBOX_ROOM_HOST");
666
+ if (referrerDid && referrerAbt > 0n) pushSplit(referrerDid, referrerAbt, "B_REFERRER");
667
+ pushSplit(machine.protocolTreasuryDid, protocolAbt, "B_PROTOCOL_FEE");
668
+ pushSplit(machineDid, poolCAddedAbt, "C_CONSERVATION_PRIZE_POOL");
669
+ const postConditions = {
670
+ signer: payerDid,
671
+ maxTokenOutflow: { [machine.tokenAddress]: A.toString(10) },
672
+ strictZeroUnlistedOutflow: true
673
+ };
674
+ return {
675
+ playId,
676
+ roundId,
677
+ machineDid,
678
+ playerDid,
679
+ payerDid,
680
+ fundedViaPrepaidCardDid,
681
+ ticketPriceAbt: A,
682
+ splitB: {
683
+ creatorAbt,
684
+ artistAbt,
685
+ roomHostAbt,
686
+ referrerAbt,
687
+ protocolAbt,
688
+ totalBAbt
689
+ },
690
+ poolCAddedAbt,
691
+ newPoolBalanceAbt: machine.poolBalanceAbt,
692
+ conservationVerified: true,
693
+ statements,
694
+ postConditions
695
+ };
696
+ }
697
+ settleArcadeMachineWinners(input) {
698
+ if (!input || typeof input !== "object") throw new CustomError(ErrorCode.InvalidSuperSuite, "Missing settleArcadeMachineWinners input");
699
+ const settlementId = assertCleanDidOrId(input.settlementId, "settlementId");
700
+ const roundId = assertCleanDidOrId(input.roundId, "roundId");
701
+ const machineDid = assertCleanDidOrId(input.machineDid, "machineDid");
702
+ const callerDid = assertCleanDidOrId(input.callerDid, "callerDid");
703
+ assertValidEpoch(input.epochIndex);
704
+ const machine = this.arcadeMachines.get(machineDid);
705
+ if (!machine) throw new CustomError(ErrorCode.InvalidSuperSuite, `Unknown ArcadeMachine: ${machineDid}`);
706
+ if (callerDid !== machine.gameCreatorDid && callerDid !== machine.roomHostDid) throw new CustomError(ErrorCode.ForbiddenSuperSuite, "Only gameCreatorDid or roomHostDid can trigger ArcadeMachine round settlement");
707
+ if (input.mode !== machine.settlementMode) throw new CustomError(ErrorCode.InvalidSuperSuite, `Settlement mode (${input.mode}) does not match machine mode (${machine.settlementMode})`);
708
+ const roundKey = `${machineDid}::${roundId}`;
709
+ if (this.settledArcadeRounds.has(roundKey)) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `Arcade round ${roundKey} is already settled`);
710
+ const playersInRound = this.arcadeRoundPlayers.get(roundKey);
711
+ if (!playersInRound || playersInRound.size === 0) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `No ticket plays recorded for round ${roundKey}`);
712
+ if (!Array.isArray(input.winners) || input.winners.length === 0 || input.winners.length > MAX_ARCADE_WINNERS_PER_ROUND) throw new CustomError(ErrorCode.InvalidSuperSuite, `winners must contain 1..${MAX_ARCADE_WINNERS_PER_ROUND} entries`);
713
+ let deterministicRollBps;
714
+ if (input.mode === "COMMIT_REVEAL_INSTANT_JACKPOT") {
715
+ if (!input.commitRevealProof) throw new CustomError(ErrorCode.InvalidSuperSuite, "Missing commitRevealProof for instant jackpot mode");
716
+ const expectedCommit = this.arcadeRoundCommits.get(roundKey);
717
+ const recomputedCommit = computeArcadeCommitDigest(input.commitRevealProof.houseSecretHex, roundId, machineDid);
718
+ if (!expectedCommit || expectedCommit !== recomputedCommit) throw new CustomError(ErrorCode.ForbiddenSuperSuite, "Commit-reveal preimage does not match committed houseCommitDigest");
719
+ const playerSeed = assertBytes32Hex(input.commitRevealProof.playerSeedHex, "playerSeedHex");
720
+ const thresholdBps = assertValidBps(input.commitRevealProof.winningThresholdRollBps, "winningThresholdRollBps", 1e4);
721
+ const combinedHash = sha256Hex(`${recomputedCommit}:${playerSeed}:${roundId}`);
722
+ const rollInt = Number(BigInt(combinedHash) % BPS_DENOMINATOR);
723
+ deterministicRollBps = rollInt;
724
+ if (rollInt >= thresholdBps) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `Deterministic roll (${rollInt} bps) did not beat winningThresholdRollBps (${thresholdBps} bps)`);
725
+ } else assertBytes32Hex(input.replayVerificationDigest ?? "", "replayVerificationDigest");
726
+ const poolBalanceBeforeAbt = machine.poolBalanceAbt;
727
+ if (poolBalanceBeforeAbt <= 0n) throw new CustomError(ErrorCode.ForbiddenSuperSuite, "ArcadeMachine Pool C has 0 balance");
728
+ let totalShareBps = 0;
729
+ const seenWinners = /* @__PURE__ */ new Set();
730
+ const winnerPayouts = [];
731
+ let totalPayoutAbt = 0n;
732
+ for (let i = 0; i < input.winners.length; i += 1) {
733
+ const w = input.winners[i];
734
+ const winnerDid = assertCleanDidOrId(w.winnerDid, `winners[${i}].winnerDid`);
735
+ const shareBps = assertValidBps(w.payoutShareOfPoolBps, `winners[${i}].payoutShareOfPoolBps`, 1e4);
736
+ if (shareBps <= 0) throw new CustomError(ErrorCode.InvalidSuperSuite, "payoutShareOfPoolBps must be > 0");
737
+ if (seenWinners.has(winnerDid)) throw new CustomError(ErrorCode.InvalidSuperSuite, `Duplicate winnerDid in round settlement: ${winnerDid}`);
738
+ if (!playersInRound.has(winnerDid)) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `Winner ${winnerDid} did not purchase a ticket in round ${roundKey}`);
739
+ seenWinners.add(winnerDid);
740
+ totalShareBps += shareBps;
741
+ const amountAbt = poolBalanceBeforeAbt * BigInt(shareBps) / BPS_DENOMINATOR;
742
+ winnerPayouts.push({
743
+ winnerDid,
744
+ amountAbt
745
+ });
746
+ totalPayoutAbt += amountAbt;
747
+ }
748
+ if (totalShareBps > 1e4 || totalPayoutAbt > poolBalanceBeforeAbt) throw new CustomError(ErrorCode.ConservationViolation, `Total winner payout (${totalPayoutAbt}) cannot exceed Pool C balance (${poolBalanceBeforeAbt})`);
749
+ this.settledArcadeRounds.add(roundKey);
750
+ machine.poolBalanceAbt -= totalPayoutAbt;
751
+ machine.totalPayoutsDistributedAbt += totalPayoutAbt;
752
+ const statements = winnerPayouts.filter((w) => w.amountAbt > 0n).map((w) => ({
753
+ type: "transfer_v3",
754
+ typeUrl: "fg:t:transfer_v3",
755
+ from: machineDid,
756
+ itx: {
757
+ to: w.winnerDid,
758
+ tokens: [{
759
+ address: machine.tokenAddress,
760
+ value: w.amountAbt.toString(10)
761
+ }],
762
+ data: {
763
+ type: "json",
764
+ value: JSON.stringify({
765
+ primitive: "ARCADE_MACHINE_POOL_C_PAYOUT",
766
+ settlementId,
767
+ roundId,
768
+ machineDid,
769
+ mode: input.mode
770
+ })
771
+ }
772
+ }
773
+ }));
774
+ const postConditions = {
775
+ signer: machineDid,
776
+ maxTokenOutflow: { [machine.tokenAddress]: totalPayoutAbt.toString(10) },
777
+ strictZeroUnlistedOutflow: true
778
+ };
779
+ return {
780
+ settlementId,
781
+ roundId,
782
+ machineDid,
783
+ mode: input.mode,
784
+ poolBalanceBeforeAbt,
785
+ totalPayoutAbt,
786
+ poolBalanceAfterAbt: machine.poolBalanceAbt,
787
+ winnerPayouts,
788
+ deterministicRollBps,
789
+ zeroPonziMintingVerified: true,
790
+ statements,
791
+ postConditions
792
+ };
793
+ }
794
+ getArcadeMachine(machineDid) {
795
+ const m = this.arcadeMachines.get(machineDid);
796
+ return m ? { ...m } : void 0;
797
+ }
798
+ registerStickerNft(input) {
799
+ if (!input || typeof input !== "object") throw new CustomError(ErrorCode.InvalidSuperSuite, "Missing registerStickerNft input");
800
+ const stickerDid = assertCleanDidOrId(input.stickerDid, "stickerDid");
801
+ const creatorDid = assertCleanDidOrId(input.creatorDid, "creatorDid");
802
+ const initialHolderDid = assertCleanDidOrId(input.initialHolderDid, "initialHolderDid");
803
+ const primaryPriceAbt = assertPositiveBigInt(input.primaryPriceAbt, "primaryPriceAbt");
804
+ const royaltyBps = assertValidBps(input.royaltyBps, "royaltyBps", MAX_STICKER_ROYALTY_BPS);
805
+ const payloadCommitmentDigest = assertBytes32Hex(input.payloadCommitmentDigest, "payloadCommitmentDigest");
806
+ const epochIndex = assertValidEpoch(input.epochIndex);
807
+ if (this.stickers.has(stickerDid)) throw new CustomError(ErrorCode.InvalidSuperSuite, `Sticker NFT ${stickerDid} already exists`);
808
+ let iboOrgDid;
809
+ let iboRoyaltyShareBps = 0;
810
+ if (input.iboOrgDid !== void 0) {
811
+ iboOrgDid = assertCleanDidOrId(input.iboOrgDid, "iboOrgDid");
812
+ if (!this.iboOrgs.has(iboOrgDid)) throw new CustomError(ErrorCode.InvalidSuperSuite, `Referenced iboOrgDid ${iboOrgDid} does not exist`);
813
+ iboRoyaltyShareBps = assertValidBps(input.iboRoyaltyShareBps ?? 5e3, "iboRoyaltyShareBps", 1e4);
814
+ }
815
+ const record = {
816
+ stickerDid,
817
+ creatorDid,
818
+ holderDid: initialHolderDid,
819
+ primaryPriceAbt,
820
+ royaltyBps,
821
+ iboOrgDid,
822
+ iboRoyaltyShareBps,
823
+ payloadCommitmentDigest,
824
+ totalSecondarySalesCount: 0,
825
+ totalSecondaryVolumeAbt: 0n,
826
+ createdAtEpoch: epochIndex
827
+ };
828
+ this.stickers.set(stickerDid, record);
829
+ return { ...record };
830
+ }
831
+ makeStickerOffer(input) {
832
+ if (!input || typeof input !== "object") throw new CustomError(ErrorCode.InvalidSuperSuite, "Missing makeStickerOffer input");
833
+ const offerId = assertCleanDidOrId(input.offerId, "offerId");
834
+ const stickerDid = assertCleanDidOrId(input.stickerDid, "stickerDid");
835
+ const buyerDid = assertCleanDidOrId(input.buyerDid, "buyerDid");
836
+ const offerAmountAbt = assertPositiveBigInt(input.offerAmountAbt, "offerAmountAbt");
837
+ const epochIndex = assertValidEpoch(input.epochIndex);
838
+ const expiresAtEpoch = assertValidEpoch(input.expiresAtEpoch, "expiresAtEpoch");
839
+ if (this.stickerOffers.has(offerId)) throw new CustomError(ErrorCode.InvalidSuperSuite, `Sticker offer ${offerId} already exists`);
840
+ if (expiresAtEpoch <= epochIndex) throw new CustomError(ErrorCode.InvalidSuperSuite, "expiresAtEpoch must be strictly after epochIndex");
841
+ const sticker = this.stickers.get(stickerDid);
842
+ if (!sticker) throw new CustomError(ErrorCode.InvalidSuperSuite, `Unknown Sticker NFT: ${stickerDid}`);
843
+ if (sticker.holderDid === buyerDid) throw new CustomError(ErrorCode.ForbiddenSuperSuite, "Current sticker holder cannot bid on their own sticker");
844
+ const offer = {
845
+ offerId,
846
+ stickerDid,
847
+ buyerDid,
848
+ offerAmountAbt,
849
+ createdAtEpoch: epochIndex,
850
+ expiresAtEpoch,
851
+ status: "OPEN_ESCROWED"
852
+ };
853
+ this.stickerOffers.set(offerId, offer);
854
+ return { ...offer };
855
+ }
856
+ cancelStickerOffer(offerId, callerDid) {
857
+ const cleanOfferId = assertCleanDidOrId(offerId, "offerId");
858
+ const cleanCaller = assertCleanDidOrId(callerDid, "callerDid");
859
+ const offer = this.stickerOffers.get(cleanOfferId);
860
+ if (!offer) throw new CustomError(ErrorCode.InvalidSuperSuite, `Unknown Sticker offer: ${cleanOfferId}`);
861
+ if (offer.buyerDid !== cleanCaller) throw new CustomError(ErrorCode.ForbiddenSuperSuite, "Only offer buyerDid can cancel their escrowed offer");
862
+ if (offer.status !== "OPEN_ESCROWED") throw new CustomError(ErrorCode.ForbiddenSuperSuite, `Sticker offer ${cleanOfferId} is not OPEN_ESCROWED`);
863
+ offer.status = "CANCELLED_REFUNDED";
864
+ return { ...offer };
865
+ }
866
+ acceptStickerOffer(input) {
867
+ if (!input || typeof input !== "object") throw new CustomError(ErrorCode.InvalidSuperSuite, "Missing acceptStickerOffer input");
868
+ const offerId = assertCleanDidOrId(input.offerId, "offerId");
869
+ const sellerDid = assertCleanDidOrId(input.sellerDid, "sellerDid");
870
+ const epochIndex = assertValidEpoch(input.epochIndex);
871
+ const offer = this.stickerOffers.get(offerId);
872
+ if (!offer) throw new CustomError(ErrorCode.InvalidSuperSuite, `Unknown Sticker offer: ${offerId}`);
873
+ if (offer.status !== "OPEN_ESCROWED") throw new CustomError(ErrorCode.ForbiddenSuperSuite, `Sticker offer ${offerId} is no longer OPEN_ESCROWED`);
874
+ if (epochIndex > offer.expiresAtEpoch) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `Sticker offer ${offerId} expired at epoch ${offer.expiresAtEpoch}`);
875
+ const sticker = this.stickers.get(offer.stickerDid);
876
+ if (!sticker) throw new CustomError(ErrorCode.InvalidSuperSuite, `Unknown Sticker NFT: ${offer.stickerDid}`);
877
+ if (sticker.holderDid !== sellerDid) throw new CustomError(ErrorCode.ForbiddenSuperSuite, "Only current sticker holderDid can accept an offer");
878
+ if (offer.buyerDid === sellerDid) throw new CustomError(ErrorCode.ForbiddenSuperSuite, "Cannot accept self-offer");
879
+ const grossOfferAbt = offer.offerAmountAbt;
880
+ const totalRoyaltyAbt = grossOfferAbt * BigInt(sticker.royaltyBps) / BPS_DENOMINATOR;
881
+ let iboDividendRoyaltyAbt = 0n;
882
+ if (sticker.iboOrgDid && totalRoyaltyAbt > 0n) {
883
+ const iboOrg = this.iboOrgs.get(sticker.iboOrgDid);
884
+ if (iboOrg && iboOrg.totalPartnerKeysSupply > 0n) {
885
+ iboDividendRoyaltyAbt = totalRoyaltyAbt * BigInt(sticker.iboRoyaltyShareBps) / BPS_DENOMINATOR;
886
+ if (iboDividendRoyaltyAbt > 0n) {
887
+ const totalScaled = iboDividendRoyaltyAbt * IBO_DIVIDEND_PRECISION + iboOrg.undistributedDividendRemainderScaled;
888
+ iboOrg.accDividendPerKeyScaled += totalScaled / iboOrg.totalPartnerKeysSupply;
889
+ iboOrg.undistributedDividendRemainderScaled = totalScaled % iboOrg.totalPartnerKeysSupply;
890
+ iboOrg.totalDividendsDistributedAbt += iboDividendRoyaltyAbt;
891
+ }
892
+ }
893
+ }
894
+ const creatorRoyaltyAbt = totalRoyaltyAbt - iboDividendRoyaltyAbt;
895
+ const sellerNetAbt = grossOfferAbt - creatorRoyaltyAbt - iboDividendRoyaltyAbt;
896
+ if (creatorRoyaltyAbt + iboDividendRoyaltyAbt + sellerNetAbt !== grossOfferAbt || sellerNetAbt < 0n) throw new CustomError(ErrorCode.ConservationViolation, "Sticker offer settlement failed conservation check");
897
+ offer.status = "ACCEPTED";
898
+ sticker.holderDid = offer.buyerDid;
899
+ sticker.totalSecondarySalesCount += 1;
900
+ sticker.totalSecondaryVolumeAbt += grossOfferAbt;
901
+ const statements = [{
902
+ type: "transfer_v3",
903
+ typeUrl: "fg:t:transfer_v3",
904
+ from: sellerDid,
905
+ itx: {
906
+ to: offer.buyerDid,
907
+ assets: [sticker.stickerDid]
908
+ }
909
+ }, {
910
+ type: "transfer_v3",
911
+ typeUrl: "fg:t:transfer_v3",
912
+ from: offer.buyerDid,
913
+ itx: {
914
+ to: sellerDid,
915
+ tokens: [{
916
+ address: DEFAULT_ABT_TOKEN_ADDRESS,
917
+ value: sellerNetAbt.toString(10)
918
+ }]
919
+ }
920
+ }];
921
+ if (creatorRoyaltyAbt > 0n) statements.push({
922
+ type: "transfer_v3",
923
+ typeUrl: "fg:t:transfer_v3",
924
+ from: offer.buyerDid,
925
+ itx: {
926
+ to: sticker.creatorDid,
927
+ tokens: [{
928
+ address: DEFAULT_ABT_TOKEN_ADDRESS,
929
+ value: creatorRoyaltyAbt.toString(10)
930
+ }]
931
+ }
932
+ });
933
+ if (sticker.iboOrgDid && iboDividendRoyaltyAbt > 0n) statements.push({
934
+ type: "transfer_v3",
935
+ typeUrl: "fg:t:transfer_v3",
936
+ from: offer.buyerDid,
937
+ itx: {
938
+ to: sticker.iboOrgDid,
939
+ tokens: [{
940
+ address: DEFAULT_ABT_TOKEN_ADDRESS,
941
+ value: iboDividendRoyaltyAbt.toString(10)
942
+ }]
943
+ }
944
+ });
945
+ const postConditions = {
946
+ signer: offer.buyerDid,
947
+ maxTokenOutflow: { [DEFAULT_ABT_TOKEN_ADDRESS]: grossOfferAbt.toString(10) },
948
+ mustOwnAssetsAfter: { [offer.buyerDid]: [sticker.stickerDid] },
949
+ strictZeroUnlistedOutflow: true
950
+ };
951
+ return {
952
+ offerId,
953
+ stickerDid: sticker.stickerDid,
954
+ sellerDid,
955
+ buyerDid: offer.buyerDid,
956
+ grossOfferAbt,
957
+ creatorRoyaltyAbt,
958
+ iboDividendRoyaltyAbt,
959
+ sellerNetAbt,
960
+ conservationVerified: true,
961
+ statements,
962
+ postConditions
963
+ };
964
+ }
965
+ getStickerNft(stickerDid) {
966
+ const s = this.stickers.get(stickerDid);
967
+ return s ? { ...s } : void 0;
968
+ }
969
+ grantSpaceAssetDelegation(input) {
970
+ if (!input || typeof input !== "object") throw new CustomError(ErrorCode.InvalidSuperSuite, "Missing grantSpaceAssetDelegation input");
971
+ const grantId = assertCleanDidOrId(input.grantId, "grantId");
972
+ const assetDid = assertCleanDidOrId(input.assetDid, "assetDid");
973
+ const ownerDid = assertCleanDidOrId(input.ownerDid, "ownerDid");
974
+ const delegateRoomOwnerDid = assertCleanDidOrId(input.delegateRoomOwnerDid, "delegateRoomOwnerDid");
975
+ const epochIndex = assertValidEpoch(input.epochIndex);
976
+ const expiresAtEpoch = assertValidEpoch(input.expiresAtEpoch, "expiresAtEpoch");
977
+ if (this.spaceDelegations.has(grantId)) throw new CustomError(ErrorCode.InvalidSuperSuite, `Delegation grant ${grantId} already exists`);
978
+ if (expiresAtEpoch <= epochIndex) throw new CustomError(ErrorCode.InvalidSuperSuite, "expiresAtEpoch must be strictly after epochIndex");
979
+ if (input.assetKind === "STICKER_NFT") {
980
+ const sticker = this.stickers.get(assetDid);
981
+ if (!sticker || sticker.holderDid !== ownerDid) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `Caller ${ownerDid} does not own Sticker ${assetDid}`);
982
+ } else if (input.assetKind === "ARCADE_MACHINE") {
983
+ const machine = this.arcadeMachines.get(assetDid);
984
+ if (!machine || machine.roomHostDid !== ownerDid && machine.gameCreatorDid !== ownerDid) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `Caller ${ownerDid} does not control ArcadeMachine ${assetDid}`);
985
+ } else throw new CustomError(ErrorCode.InvalidSuperSuite, `Invalid assetKind: ${String(input.assetKind)}`);
986
+ const grant = {
987
+ grantId,
988
+ assetDid,
989
+ assetKind: input.assetKind,
990
+ ownerDid,
991
+ delegateRoomOwnerDid,
992
+ grantedAtEpoch: epochIndex,
993
+ expiresAtEpoch,
994
+ revoked: false
995
+ };
996
+ this.spaceDelegations.set(grantId, grant);
997
+ return { ...grant };
998
+ }
999
+ hasActiveSpaceAssetAuthorization(roomOwnerDid, assetDid, assetKind, epochIndex) {
1000
+ if (assetKind === "STICKER_NFT") {
1001
+ const sticker = this.stickers.get(assetDid);
1002
+ if (!sticker) return false;
1003
+ if (sticker.holderDid === roomOwnerDid) return true;
1004
+ for (const grant of this.spaceDelegations.values()) if (!grant.revoked && grant.assetKind === "STICKER_NFT" && grant.assetDid === assetDid && grant.ownerDid === sticker.holderDid && grant.delegateRoomOwnerDid === roomOwnerDid && epochIndex >= grant.grantedAtEpoch && epochIndex <= grant.expiresAtEpoch) return true;
1005
+ return false;
1006
+ }
1007
+ const machine = this.arcadeMachines.get(assetDid);
1008
+ if (!machine) return false;
1009
+ if (machine.roomHostDid === roomOwnerDid || machine.gameCreatorDid === roomOwnerDid) return true;
1010
+ for (const grant of this.spaceDelegations.values()) if (!grant.revoked && grant.assetKind === "ARCADE_MACHINE" && grant.assetDid === assetDid && (grant.ownerDid === machine.roomHostDid || grant.ownerDid === machine.gameCreatorDid) && grant.delegateRoomOwnerDid === roomOwnerDid && epochIndex >= grant.grantedAtEpoch && epochIndex <= grant.expiresAtEpoch) return true;
1011
+ return false;
1012
+ }
1013
+ anchorSpaceManifest(input) {
1014
+ if (!input || typeof input !== "object") throw new CustomError(ErrorCode.InvalidSuperSuite, "Missing anchorSpaceManifest input");
1015
+ const spaceDid = assertCleanDidOrId(input.spaceDid, "spaceDid");
1016
+ const roomOwnerDid = assertCleanDidOrId(input.roomOwnerDid, "roomOwnerDid");
1017
+ const offChainLayoutCommitmentDigest = assertBytes32Hex(input.offChainLayoutCommitmentDigest, "offChainLayoutCommitmentDigest");
1018
+ const epochIndex = assertValidEpoch(input.epochIndex);
1019
+ if (!Array.isArray(input.displayedStickerDids) || input.displayedStickerDids.length > MAX_SPACE_DISPLAYED_STICKERS) throw new CustomError(ErrorCode.InvalidSuperSuite, `displayedStickerDids must be an array of at most ${MAX_SPACE_DISPLAYED_STICKERS} Sticker DIDs`);
1020
+ if (!Array.isArray(input.placedMachineDids) || input.placedMachineDids.length > MAX_SPACE_PLACED_MACHINES) throw new CustomError(ErrorCode.InvalidSuperSuite, `placedMachineDids must be an array of at most ${MAX_SPACE_PLACED_MACHINES} ArcadeMachine DIDs`);
1021
+ const cleanStickers = input.displayedStickerDids.map((s, i) => assertCleanDidOrId(s, `displayedStickerDids[${i}]`));
1022
+ if (new Set(cleanStickers).size !== cleanStickers.length) throw new CustomError(ErrorCode.InvalidSuperSuite, "displayedStickerDids cannot contain duplicate Sticker DIDs");
1023
+ const cleanMachines = input.placedMachineDids.map((m, i) => assertCleanDidOrId(m, `placedMachineDids[${i}]`));
1024
+ if (new Set(cleanMachines).size !== cleanMachines.length) throw new CustomError(ErrorCode.InvalidSuperSuite, "placedMachineDids cannot contain duplicate ArcadeMachine DIDs");
1025
+ for (const stickerDid of cleanStickers) if (!this.hasActiveSpaceAssetAuthorization(roomOwnerDid, stickerDid, "STICKER_NFT", epochIndex)) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `UNAUTHORIZED_SPACE_ASSET_MOUNT: Room owner ${roomOwnerDid} neither owns nor holds an active delegation for Sticker ${stickerDid}`);
1026
+ for (const machineDid of cleanMachines) if (!this.hasActiveSpaceAssetAuthorization(roomOwnerDid, machineDid, "ARCADE_MACHINE", epochIndex)) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `UNAUTHORIZED_SPACE_ASSET_MOUNT: Room owner ${roomOwnerDid} neither controls nor holds an active delegation for ArcadeMachine ${machineDid}`);
1027
+ const existing = this.spaceManifests.get(spaceDid);
1028
+ if (existing && existing.roomOwnerDid !== roomOwnerDid) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `Space ${spaceDid} is owned by ${existing.roomOwnerDid}`);
1029
+ const nextVersion = existing ? existing.version + 1 : 1;
1030
+ const record = {
1031
+ spaceDid,
1032
+ roomOwnerDid,
1033
+ version: nextVersion,
1034
+ displayedStickerDids: cleanStickers,
1035
+ placedMachineDids: cleanMachines,
1036
+ offChainLayoutCommitmentDigest,
1037
+ manifestRootDigest: computeSpaceManifestRootDigest({
1038
+ spaceDid,
1039
+ roomOwnerDid,
1040
+ version: nextVersion,
1041
+ displayedStickerDids: cleanStickers,
1042
+ placedMachineDids: cleanMachines,
1043
+ offChainLayoutCommitmentDigest,
1044
+ epochIndex
1045
+ }),
1046
+ anchoredAtEpoch: epochIndex,
1047
+ onChainPayloadFootprint: "PROOF_ONLY_32B"
1048
+ };
1049
+ this.spaceManifests.set(spaceDid, record);
1050
+ return {
1051
+ ...record,
1052
+ displayedStickerDids: [...record.displayedStickerDids],
1053
+ placedMachineDids: [...record.placedMachineDids]
1054
+ };
1055
+ }
1056
+ lockAttentionStamp(input) {
1057
+ if (!input || typeof input !== "object") throw new CustomError(ErrorCode.InvalidSuperSuite, "Missing lockAttentionStamp input");
1058
+ const stampId = assertCleanDidOrId(input.stampId, "stampId");
1059
+ const senderDid = assertCleanDidOrId(input.senderDid, "senderDid");
1060
+ const recipientDid = assertCleanDidOrId(input.recipientDid, "recipientDid");
1061
+ const spamSinkDid = assertCleanDidOrId(input.spamSinkDid, "spamSinkDid");
1062
+ const stampAmountAbt = assertPositiveBigInt(input.stampAmountAbt, "stampAmountAbt");
1063
+ const messageCommitmentDigest = assertBytes32Hex(input.messageCommitmentDigest, "messageCommitmentDigest");
1064
+ const epochIndex = assertValidEpoch(input.epochIndex);
1065
+ const expiresAtEpoch = assertValidEpoch(input.expiresAtEpoch, "expiresAtEpoch");
1066
+ if (this.attentionStamps.has(stampId)) throw new CustomError(ErrorCode.InvalidSuperSuite, `AttentionStamp ${stampId} already exists`);
1067
+ if (senderDid === recipientDid) throw new CustomError(ErrorCode.InvalidSuperSuite, "senderDid and recipientDid must be distinct");
1068
+ if (spamSinkDid === senderDid || spamSinkDid === recipientDid) throw new CustomError(ErrorCode.InvalidSuperSuite, "spamSinkDid must be an independent public-goods/treasury sink distinct from senderDid and recipientDid");
1069
+ if (stampAmountAbt < MIN_ATTENTION_STAMP_ABT) throw new CustomError(ErrorCode.InvalidSuperSuite, `stampAmountAbt (${stampAmountAbt}) is below MIN_ATTENTION_STAMP_ABT (${MIN_ATTENTION_STAMP_ABT})`);
1070
+ if (expiresAtEpoch <= epochIndex || expiresAtEpoch - epochIndex > MAX_ATTENTION_STAMP_TTL_EPOCHS) throw new CustomError(ErrorCode.InvalidSuperSuite, `expiresAtEpoch must be within 1..${MAX_ATTENTION_STAMP_TTL_EPOCHS} epochs after epochIndex`);
1071
+ let referrerDid;
1072
+ let referrerBps = 0;
1073
+ if (input.referrerDid !== void 0) {
1074
+ referrerDid = assertCleanDidOrId(input.referrerDid, "referrerDid");
1075
+ if (referrerDid === senderDid) throw new CustomError(ErrorCode.ForbiddenSuperSuite, "referrerDid cannot be senderDid");
1076
+ referrerBps = assertValidBps(input.referrerBps ?? 1e3, "referrerBps", 5e3);
1077
+ }
1078
+ let protocolTreasuryDid;
1079
+ let protocolFeeBps = 0;
1080
+ if (input.protocolTreasuryDid !== void 0) {
1081
+ protocolTreasuryDid = assertCleanDidOrId(input.protocolTreasuryDid, "protocolTreasuryDid");
1082
+ protocolFeeBps = assertValidBps(input.protocolFeeBps ?? 500, "protocolFeeBps", 2e3);
1083
+ }
1084
+ const record = {
1085
+ stampId,
1086
+ senderDid,
1087
+ recipientDid,
1088
+ stampAmountAbt,
1089
+ messageCommitmentDigest,
1090
+ referrerDid,
1091
+ referrerBps,
1092
+ protocolTreasuryDid,
1093
+ protocolFeeBps,
1094
+ spamSinkDid,
1095
+ createdAtEpoch: epochIndex,
1096
+ expiresAtEpoch,
1097
+ status: "ESCROWED"
1098
+ };
1099
+ this.attentionStamps.set(stampId, record);
1100
+ return { ...record };
1101
+ }
1102
+ resolveAttentionStamp(input) {
1103
+ if (!input || typeof input !== "object") throw new CustomError(ErrorCode.InvalidSuperSuite, "Missing resolveAttentionStamp input");
1104
+ const stampId = assertCleanDidOrId(input.stampId, "stampId");
1105
+ const callerDid = assertCleanDidOrId(input.callerDid, "callerDid");
1106
+ const replyOrSpamEvidenceDigest = assertBytes32Hex(input.replyOrSpamEvidenceDigest, "replyOrSpamEvidenceDigest");
1107
+ const epochIndex = assertValidEpoch(input.epochIndex);
1108
+ const stamp = this.attentionStamps.get(stampId);
1109
+ if (!stamp) throw new CustomError(ErrorCode.InvalidSuperSuite, `Unknown AttentionStamp: ${stampId}`);
1110
+ if (stamp.status !== "ESCROWED") throw new CustomError(ErrorCode.ForbiddenSuperSuite, `AttentionStamp ${stampId} is already resolved (${stamp.status})`);
1111
+ if (stamp.recipientDid !== callerDid) throw new CustomError(ErrorCode.ForbiddenSuperSuite, "Only recipientDid can resolve an AttentionStamp");
1112
+ if (epochIndex > stamp.expiresAtEpoch) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `AttentionStamp ${stampId} has already expired`);
1113
+ let senderRefundAbt = 0n;
1114
+ let recipientNetAbt = 0n;
1115
+ let referrerAbt = 0n;
1116
+ let protocolFeeAbt = 0n;
1117
+ let spamSinkAbt = 0n;
1118
+ const statements = [];
1119
+ if (input.mode === "REFUND_ON_READ_OR_REPLY") {
1120
+ senderRefundAbt = stamp.stampAmountAbt;
1121
+ stamp.status = "REFUNDED_ON_REPLY";
1122
+ statements.push({
1123
+ type: "transfer_v3",
1124
+ typeUrl: "fg:t:transfer_v3",
1125
+ from: stampId,
1126
+ itx: {
1127
+ to: stamp.senderDid,
1128
+ tokens: [{
1129
+ address: DEFAULT_ABT_TOKEN_ADDRESS,
1130
+ value: senderRefundAbt.toString(10)
1131
+ }],
1132
+ data: {
1133
+ type: "json",
1134
+ value: JSON.stringify({
1135
+ primitive: "ATTENTION_STAMP_REFUND_ON_REPLY",
1136
+ stampId,
1137
+ evidence: replyOrSpamEvidenceDigest
1138
+ })
1139
+ }
1140
+ }
1141
+ });
1142
+ } else if (input.mode === "CLAIM_AS_PAID_CONSULTATION") {
1143
+ if (stamp.referrerDid && stamp.referrerBps > 0) referrerAbt = stamp.stampAmountAbt * BigInt(stamp.referrerBps) / BPS_DENOMINATOR;
1144
+ if (stamp.protocolTreasuryDid && stamp.protocolFeeBps > 0) protocolFeeAbt = stamp.stampAmountAbt * BigInt(stamp.protocolFeeBps) / BPS_DENOMINATOR;
1145
+ recipientNetAbt = stamp.stampAmountAbt - referrerAbt - protocolFeeAbt;
1146
+ stamp.status = "CLAIMED_CONSULTATION";
1147
+ statements.push({
1148
+ type: "transfer_v3",
1149
+ typeUrl: "fg:t:transfer_v3",
1150
+ from: stampId,
1151
+ itx: {
1152
+ to: stamp.recipientDid,
1153
+ tokens: [{
1154
+ address: DEFAULT_ABT_TOKEN_ADDRESS,
1155
+ value: recipientNetAbt.toString(10)
1156
+ }]
1157
+ }
1158
+ });
1159
+ if (stamp.referrerDid && referrerAbt > 0n) statements.push({
1160
+ type: "transfer_v3",
1161
+ typeUrl: "fg:t:transfer_v3",
1162
+ from: stampId,
1163
+ itx: {
1164
+ to: stamp.referrerDid,
1165
+ tokens: [{
1166
+ address: DEFAULT_ABT_TOKEN_ADDRESS,
1167
+ value: referrerAbt.toString(10)
1168
+ }]
1169
+ }
1170
+ });
1171
+ if (stamp.protocolTreasuryDid && protocolFeeAbt > 0n) statements.push({
1172
+ type: "transfer_v3",
1173
+ typeUrl: "fg:t:transfer_v3",
1174
+ from: stampId,
1175
+ itx: {
1176
+ to: stamp.protocolTreasuryDid,
1177
+ tokens: [{
1178
+ address: DEFAULT_ABT_TOKEN_ADDRESS,
1179
+ value: protocolFeeAbt.toString(10)
1180
+ }]
1181
+ }
1182
+ });
1183
+ } else if (input.mode === "SLASH_ON_SPAM") {
1184
+ spamSinkAbt = stamp.stampAmountAbt;
1185
+ stamp.status = "SLASHED_TO_SPAM_SINK";
1186
+ statements.push({
1187
+ type: "transfer_v3",
1188
+ typeUrl: "fg:t:transfer_v3",
1189
+ from: stampId,
1190
+ itx: {
1191
+ to: stamp.spamSinkDid,
1192
+ tokens: [{
1193
+ address: DEFAULT_ABT_TOKEN_ADDRESS,
1194
+ value: spamSinkAbt.toString(10)
1195
+ }],
1196
+ data: {
1197
+ type: "json",
1198
+ value: JSON.stringify({
1199
+ primitive: "ATTENTION_STAMP_SLASH_SPAM",
1200
+ stampId,
1201
+ evidence: replyOrSpamEvidenceDigest
1202
+ })
1203
+ }
1204
+ }
1205
+ });
1206
+ } else throw new CustomError(ErrorCode.InvalidSuperSuite, `Unsupported resolution mode: ${String(input.mode)}`);
1207
+ if (senderRefundAbt + recipientNetAbt + referrerAbt + protocolFeeAbt + spamSinkAbt !== stamp.stampAmountAbt) throw new CustomError(ErrorCode.ConservationViolation, "AttentionStamp resolution violated ABT conservation");
1208
+ const postConditions = {
1209
+ signer: stampId,
1210
+ maxTokenOutflow: { [DEFAULT_ABT_TOKEN_ADDRESS]: stamp.stampAmountAbt.toString(10) },
1211
+ strictZeroUnlistedOutflow: true
1212
+ };
1213
+ return {
1214
+ stampId,
1215
+ mode: input.mode,
1216
+ senderRefundAbt,
1217
+ recipientNetAbt,
1218
+ referrerAbt,
1219
+ protocolFeeAbt,
1220
+ spamSinkAbt,
1221
+ conservationVerified: true,
1222
+ statements,
1223
+ postConditions
1224
+ };
1225
+ }
1226
+ reclaimExpiredAttentionStamp(stampId, callerDid, epochIndex) {
1227
+ const cleanStampId = assertCleanDidOrId(stampId, "stampId");
1228
+ const cleanCaller = assertCleanDidOrId(callerDid, "callerDid");
1229
+ const epoch = assertValidEpoch(epochIndex);
1230
+ const stamp = this.attentionStamps.get(cleanStampId);
1231
+ if (!stamp) throw new CustomError(ErrorCode.InvalidSuperSuite, `Unknown AttentionStamp: ${cleanStampId}`);
1232
+ if (stamp.senderDid !== cleanCaller) throw new CustomError(ErrorCode.ForbiddenSuperSuite, "Only senderDid can reclaim an expired AttentionStamp");
1233
+ if (stamp.status !== "ESCROWED") throw new CustomError(ErrorCode.ForbiddenSuperSuite, `AttentionStamp ${cleanStampId} is not ESCROWED`);
1234
+ if (epoch <= stamp.expiresAtEpoch) throw new CustomError(ErrorCode.ForbiddenSuperSuite, `AttentionStamp ${cleanStampId} has not expired yet (expiresAtEpoch: ${stamp.expiresAtEpoch})`);
1235
+ stamp.status = "EXPIRED_RECLAIMED";
1236
+ return { ...stamp };
1237
+ }
1238
+ };
1239
+
1240
+ //#endregion
1241
+ export { BPS_DENOMINATOR, DEFAULT_ABT_TOKEN_ADDRESS, IBO_DIVIDEND_PRECISION, MAX_ARCADE_HOUSE_SPLIT_BPS, MAX_ARCADE_WINNERS_PER_ROUND, MAX_ATTENTION_STAMP_TTL_EPOCHS, MAX_IBO_TOTAL_FEE_SPLIT_BPS, MAX_PREPAID_CARD_ALLOWED_PROVIDERS, MAX_SPACE_DISPLAYED_STICKERS, MAX_SPACE_PLACED_MACHINES, MAX_STICKER_ROYALTY_BPS, MIN_ARCADE_HOUSE_SPLIT_BPS, MIN_ATTENTION_STAMP_ABT, OcapSuperSuitesFoundationEngine, computeArcadeCommitDigest, computeSpaceManifestRootDigest };