otto-intel-mcp 0.1.2 → 0.1.4

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 (239) hide show
  1. package/README.md +76 -18
  2. package/dist/account-userop-policy-definition.d.ts +14 -0
  3. package/dist/account-userop-policy-definition.js +12 -0
  4. package/dist/account-userop-policy-relation.d.ts +371 -0
  5. package/dist/account-userop-policy-relation.js +87 -0
  6. package/dist/adapter/cdp-signer.d.ts +76 -9
  7. package/dist/adapter/cdp-signer.js +274 -33
  8. package/dist/adapter/evm-call-failure.d.ts +29 -0
  9. package/dist/adapter/evm-call-failure.js +109 -0
  10. package/dist/adapter/refusal.d.ts +1 -1
  11. package/dist/adapter/refusal.js +13 -0
  12. package/dist/adapter/route-simulator.d.ts +91 -0
  13. package/dist/adapter/route-simulator.js +143 -0
  14. package/dist/adapter-cdp-index.d.ts +1 -1
  15. package/dist/executable-equities.d.ts +55 -0
  16. package/dist/executable-equities.js +116 -0
  17. package/dist/executable-yield-markets.d.ts +261 -0
  18. package/dist/executable-yield-markets.js +154 -0
  19. package/dist/execution-account-gas-quote.d.ts +141 -0
  20. package/dist/execution-account-gas-quote.js +443 -0
  21. package/dist/execution-account-gas-review.d.ts +123 -0
  22. package/dist/execution-account-gas-review.js +104 -0
  23. package/dist/execution-account-gas-runtime.d.ts +33 -0
  24. package/dist/execution-account-gas-runtime.js +131 -0
  25. package/dist/execution-account-gas-view.d.ts +936 -0
  26. package/dist/execution-account-gas-view.js +56 -0
  27. package/dist/execution-config.d.ts +3 -0
  28. package/dist/execution-config.js +4 -0
  29. package/dist/execution-delegated-definition.d.ts +7 -6
  30. package/dist/execution-delegated-definition.js +13 -2
  31. package/dist/execution-delegation-admin-definition.d.ts +127 -5
  32. package/dist/execution-delegation-admin-definition.js +155 -5
  33. package/dist/execution-delegation-admin.d.ts +48 -2
  34. package/dist/execution-delegation-admin.js +422 -12
  35. package/dist/execution-delegation-cap-store.d.ts +386 -0
  36. package/dist/execution-delegation-cap-store.js +1150 -0
  37. package/dist/execution-delegation-exit-definition.d.ts +309 -0
  38. package/dist/execution-delegation-exit-definition.js +204 -0
  39. package/dist/execution-delegation-exit-store.d.ts +114 -0
  40. package/dist/execution-delegation-exit-store.js +671 -0
  41. package/dist/execution-delegation-exit.d.ts +4 -0
  42. package/dist/execution-delegation-exit.js +614 -0
  43. package/dist/execution-delegation-finality.d.ts +22 -0
  44. package/dist/execution-delegation-finality.js +90 -0
  45. package/dist/execution-delegation-operation-store.d.ts +129 -0
  46. package/dist/execution-delegation-operation-store.js +1107 -0
  47. package/dist/execution-delegation-operations-definition.d.ts +282 -0
  48. package/dist/execution-delegation-operations-definition.js +117 -0
  49. package/dist/execution-delegation-operations.d.ts +6 -0
  50. package/dist/execution-delegation-operations.js +282 -0
  51. package/dist/execution-delegation-policy.d.ts +154 -8
  52. package/dist/execution-delegation-policy.js +273 -40
  53. package/dist/execution-delegation.d.ts +51 -0
  54. package/dist/execution-delegation.js +441 -31
  55. package/dist/execution-errors.d.ts +1 -1
  56. package/dist/execution-errors.js +122 -0
  57. package/dist/execution-index.d.ts +7 -2
  58. package/dist/execution-index.js +7 -2
  59. package/dist/execution-journal-schema.d.ts +96 -0
  60. package/dist/execution-journal-schema.js +368 -0
  61. package/dist/execution-journal-tables.d.ts +14 -0
  62. package/dist/execution-journal-tables.js +227 -0
  63. package/dist/execution-policy-compatibility.d.ts +34 -0
  64. package/dist/execution-policy-compatibility.js +76 -0
  65. package/dist/execution-registration.d.ts +54 -2
  66. package/dist/execution-registration.js +151 -5
  67. package/dist/execution-sponsored-account-profile.d.ts +32 -0
  68. package/dist/execution-sponsored-account-profile.js +59 -0
  69. package/dist/execution-sponsored-account.d.ts +1519 -0
  70. package/dist/execution-sponsored-account.js +222 -0
  71. package/dist/execution-sponsored-definition.d.ts +1713 -0
  72. package/dist/execution-sponsored-definition.js +185 -0
  73. package/dist/execution-sponsored-gas-policy.d.ts +27 -0
  74. package/dist/execution-sponsored-gas-policy.js +110 -0
  75. package/dist/execution-sponsored-hosted.d.ts +3 -0
  76. package/dist/execution-sponsored-hosted.js +71 -0
  77. package/dist/execution-sponsored-index.d.ts +1322 -0
  78. package/dist/execution-sponsored-index.js +102 -0
  79. package/dist/execution-sponsored-mcp-definition.d.ts +1662 -0
  80. package/dist/execution-sponsored-mcp-definition.js +94 -0
  81. package/dist/execution-sponsored-receipt.d.ts +47 -0
  82. package/dist/execution-sponsored-receipt.js +74 -0
  83. package/dist/execution-sponsored-registration.d.ts +14 -0
  84. package/dist/execution-sponsored-registration.js +77 -0
  85. package/dist/execution-sponsored-runtime.d.ts +84 -0
  86. package/dist/execution-sponsored-runtime.js +149 -0
  87. package/dist/execution-sponsored-settlement.d.ts +15 -0
  88. package/dist/execution-sponsored-settlement.js +88 -0
  89. package/dist/execution-sponsored-store.d.ts +67 -0
  90. package/dist/execution-sponsored-store.js +517 -0
  91. package/dist/execution-sponsored-transport.d.ts +90 -0
  92. package/dist/execution-sponsored-transport.js +180 -0
  93. package/dist/execution-tool-definitions.d.ts +21 -21
  94. package/dist/execution-tool-definitions.js +0 -7
  95. package/dist/execution-tools.d.ts +53 -1
  96. package/dist/execution-tools.js +171 -13
  97. package/dist/execution-worker-guard.d.ts +28 -0
  98. package/dist/execution-worker-guard.js +124 -0
  99. package/dist/hybrid-yield-index.d.ts +10 -0
  100. package/dist/hybrid-yield-index.js +11 -0
  101. package/dist/hybrid-yield-markets.d.ts +96 -0
  102. package/dist/hybrid-yield-markets.js +124 -0
  103. package/dist/hybrid-yield.d.ts +411 -0
  104. package/dist/hybrid-yield.js +155 -0
  105. package/dist/hyperliquid-order-builder.js +4 -0
  106. package/dist/lifi-execution-client.d.ts +6 -0
  107. package/dist/lifi-execution-client.js +3 -0
  108. package/dist/lp-userop-account.d.ts +461 -0
  109. package/dist/lp-userop-account.js +417 -0
  110. package/dist/lp-userop-authority.d.ts +49 -0
  111. package/dist/lp-userop-authority.js +211 -0
  112. package/dist/lp-userop-definition.d.ts +233 -0
  113. package/dist/lp-userop-definition.js +85 -0
  114. package/dist/lp-userop-hosted.d.ts +3 -0
  115. package/dist/lp-userop-hosted.js +73 -0
  116. package/dist/lp-userop-index.d.ts +1569 -0
  117. package/dist/lp-userop-index.js +112 -0
  118. package/dist/lp-userop-mcp-definition.d.ts +1220 -0
  119. package/dist/lp-userop-mcp-definition.js +46 -0
  120. package/dist/lp-userop-operation.d.ts +1230 -0
  121. package/dist/lp-userop-operation.js +140 -0
  122. package/dist/lp-userop-registration.d.ts +14 -0
  123. package/dist/lp-userop-registration.js +70 -0
  124. package/dist/lp-userop-settlement.d.ts +89 -0
  125. package/dist/lp-userop-settlement.js +184 -0
  126. package/dist/lp-userop.d.ts +643 -0
  127. package/dist/lp-userop.js +343 -0
  128. package/dist/native-yield-account-definition.d.ts +1192 -0
  129. package/dist/native-yield-account-definition.js +232 -0
  130. package/dist/native-yield-account-gas.d.ts +58 -0
  131. package/dist/native-yield-account-gas.js +228 -0
  132. package/dist/native-yield-account-index.d.ts +23 -0
  133. package/dist/native-yield-account-index.js +28 -0
  134. package/dist/native-yield-account-policy.d.ts +168 -0
  135. package/dist/native-yield-account-policy.js +525 -0
  136. package/dist/native-yield-account-rpc.d.ts +8 -0
  137. package/dist/native-yield-account-rpc.js +128 -0
  138. package/dist/native-yield-account-runtime.d.ts +71 -0
  139. package/dist/native-yield-account-runtime.js +125 -0
  140. package/dist/native-yield-account-store.d.ts +40 -0
  141. package/dist/native-yield-account-store.js +307 -0
  142. package/dist/native-yield-account.d.ts +662 -0
  143. package/dist/native-yield-account.js +371 -0
  144. package/dist/native-yield-consent-store.d.ts +20 -0
  145. package/dist/native-yield-consent-store.js +317 -0
  146. package/dist/native-yield-definition.d.ts +288 -0
  147. package/dist/native-yield-definition.js +105 -0
  148. package/dist/native-yield-reader.d.ts +4 -0
  149. package/dist/native-yield-reader.js +137 -0
  150. package/dist/native-yield-settlement.d.ts +48 -0
  151. package/dist/native-yield-settlement.js +167 -0
  152. package/dist/native-yield-simulation.d.ts +18 -0
  153. package/dist/native-yield-simulation.js +45 -0
  154. package/dist/native-yield-userop-account.d.ts +675 -0
  155. package/dist/native-yield-userop-account.js +357 -0
  156. package/dist/native-yield-userop-authority.d.ts +214 -0
  157. package/dist/native-yield-userop-authority.js +296 -0
  158. package/dist/native-yield-userop-definition.d.ts +331 -0
  159. package/dist/native-yield-userop-definition.js +105 -0
  160. package/dist/native-yield-userop-hosted.d.ts +3 -0
  161. package/dist/native-yield-userop-hosted.js +71 -0
  162. package/dist/native-yield-userop-index.d.ts +1522 -0
  163. package/dist/native-yield-userop-index.js +142 -0
  164. package/dist/native-yield-userop-mcp-definition.d.ts +1356 -0
  165. package/dist/native-yield-userop-mcp-definition.js +50 -0
  166. package/dist/native-yield-userop-operation.d.ts +845 -0
  167. package/dist/native-yield-userop-operation.js +127 -0
  168. package/dist/native-yield-userop-policy.d.ts +23 -0
  169. package/dist/native-yield-userop-policy.js +25 -0
  170. package/dist/native-yield-userop-registration.d.ts +17 -0
  171. package/dist/native-yield-userop-registration.js +76 -0
  172. package/dist/native-yield-userop-settlement.d.ts +8 -0
  173. package/dist/native-yield-userop-settlement.js +79 -0
  174. package/dist/native-yield-userop-simulation.d.ts +18 -0
  175. package/dist/native-yield-userop-simulation.js +34 -0
  176. package/dist/native-yield-userop.d.ts +35 -0
  177. package/dist/native-yield-userop.js +156 -0
  178. package/dist/native-yield-verify.d.ts +30 -0
  179. package/dist/native-yield-verify.js +141 -0
  180. package/dist/native-yield.d.ts +17 -0
  181. package/dist/native-yield.js +119 -0
  182. package/dist/stdio-main.js +0 -0
  183. package/dist/stock-buy-definition.d.ts +338 -0
  184. package/dist/stock-buy-definition.js +127 -0
  185. package/dist/stock-buy-oracle.d.ts +8 -0
  186. package/dist/stock-buy-oracle.js +22 -0
  187. package/dist/stock-buy.d.ts +17 -0
  188. package/dist/stock-buy.js +164 -0
  189. package/dist/tool-definitions.d.ts +3 -1
  190. package/dist/tool-definitions.js +55 -2
  191. package/dist/vendor/lp-v3/lp-v3-atomic-contract.d.ts +445 -0
  192. package/dist/vendor/lp-v3/lp-v3-atomic-contract.js +90 -0
  193. package/dist/vendor/lp-v3/lp-v3-atomic-evidence.d.ts +14 -0
  194. package/dist/vendor/lp-v3/lp-v3-atomic-evidence.js +82 -0
  195. package/dist/vendor/lp-v3/lp-v3-atomic-index.d.ts +80 -0
  196. package/dist/vendor/lp-v3/lp-v3-atomic-index.js +19 -0
  197. package/dist/vendor/lp-v3/lp-v3-atomic-plan.d.ts +43 -0
  198. package/dist/vendor/lp-v3/lp-v3-atomic-plan.js +112 -0
  199. package/dist/vendor/lp-v3/lp-v3-atomic-read-contract.d.ts +312 -0
  200. package/dist/vendor/lp-v3/lp-v3-atomic-read-contract.js +41 -0
  201. package/dist/vendor/lp-v3/lp-v3-atomic-read-index.d.ts +3 -0
  202. package/dist/vendor/lp-v3/lp-v3-atomic-read-index.js +3 -0
  203. package/dist/vendor/lp-v3/lp-v3-atomic-read-rpc.d.ts +49 -0
  204. package/dist/vendor/lp-v3/lp-v3-atomic-read-rpc.js +88 -0
  205. package/dist/vendor/lp-v3/lp-v3-atomic-read.d.ts +17 -0
  206. package/dist/vendor/lp-v3/lp-v3-atomic-read.js +232 -0
  207. package/dist/vendor/lp-v3/lp-v3-atomic-settlement.d.ts +105 -0
  208. package/dist/vendor/lp-v3/lp-v3-atomic-settlement.js +162 -0
  209. package/dist/vendor/lp-v3/lp-v3-collect-protocol-contract.d.ts +606 -0
  210. package/dist/vendor/lp-v3/lp-v3-collect-protocol-contract.js +59 -0
  211. package/dist/vendor/lp-v3/lp-v3-collect-protocol-index.d.ts +168 -0
  212. package/dist/vendor/lp-v3/lp-v3-collect-protocol-index.js +23 -0
  213. package/dist/vendor/lp-v3/lp-v3-collect-protocol-observation.d.ts +32 -0
  214. package/dist/vendor/lp-v3/lp-v3-collect-protocol-observation.js +228 -0
  215. package/dist/vendor/lp-v3/lp-v3-collect-protocol-plan.d.ts +11 -0
  216. package/dist/vendor/lp-v3/lp-v3-collect-protocol-plan.js +91 -0
  217. package/dist/vendor/lp-v3/lp-v3-collect-protocol-reconcile.d.ts +9 -0
  218. package/dist/vendor/lp-v3/lp-v3-collect-protocol-reconcile.js +124 -0
  219. package/dist/vendor/lp-v3/lp-v3-contract.d.ts +538 -0
  220. package/dist/vendor/lp-v3/lp-v3-contract.js +137 -0
  221. package/dist/vendor/lp-v3/lp-v3-evidence.d.ts +25 -0
  222. package/dist/vendor/lp-v3/lp-v3-evidence.js +168 -0
  223. package/dist/vendor/lp-v3/lp-v3-plan.d.ts +22 -0
  224. package/dist/vendor/lp-v3/lp-v3-plan.js +135 -0
  225. package/dist/vendor/lp-v3/types.d.ts +131 -0
  226. package/dist/vendor/lp-v3/types.js +6 -0
  227. package/dist/vendor/lp-v3/v4-math.d.ts +18 -0
  228. package/dist/vendor/lp-v3/v4-math.js +90 -0
  229. package/dist/yield-deposit-definition.d.ts +374 -0
  230. package/dist/yield-deposit-definition.js +123 -0
  231. package/dist/yield-deposit.d.ts +16 -0
  232. package/dist/yield-deposit.js +149 -0
  233. package/dist/yield-route-semantics.d.ts +27 -0
  234. package/dist/yield-route-semantics.js +71 -0
  235. package/dist/yield-withdraw-definition.d.ts +357 -0
  236. package/dist/yield-withdraw-definition.js +90 -0
  237. package/dist/yield-withdraw.d.ts +11 -0
  238. package/dist/yield-withdraw.js +122 -0
  239. package/package.json +239 -7
@@ -0,0 +1,517 @@
1
+ import { ACCOUNT_GAS_FAILURE_SCHEMA } from './execution-account-gas-view.js';
2
+ import { accountGasCallsCommitment } from './execution-account-gas-quote.js';
3
+ import { nativeYieldUserOpRecordedCalls } from './native-yield-userop.js';
4
+ import { lpUserOpRecordedCalls } from './lp-userop.js';
5
+ import { ACCOUNT_GAS_REVIEW_SCHEMA } from './execution-account-gas-review.js';
6
+ import { SPONSORED_OPERATION_SCHEMA as SPONSORED_STORAGE_SCHEMA, assertExecutionStorageSchema, assertDeclaredExecutionStorage } from './execution-journal-tables.js';
7
+ /** Sponsored reviews and operations share the existing cross-rail claim database. */
8
+ import { randomUUID } from 'node:crypto';
9
+ import { access } from 'node:fs/promises';
10
+ import { join } from 'node:path';
11
+ import { pathToFileURL } from 'node:url';
12
+ import { sqliteWalRuntimeIsSafe } from './execution-delegation-operation-store.js';
13
+ import { assertExecutionJournalCompatible, claimSponsoredExecution, releaseSponsoredExecutionClaim, readUserExecutionClaim, readExecutionJournalStatus, requireSponsoredExecutionJournalReady, requireNativeUserOpJournalReady, requireLpUserOpJournalReady } from './execution-journal-schema.js';
14
+ import { SPONSORED_OPERATION_SCHEMA, SPONSORED_CONTEXT_SCHEMA, SPONSORED_STORED_REQUEST_SCHEMA, SPONSORED_RECEIPT_SCHEMA, SPONSORED_SETTLEMENT_SCHEMA, sponsoredDigest, sponsoredReviewCommitment, sponsoredPlan, sponsoredCalls, sponsoredChainTerms, SPONSORED_USDC, } from './execution-sponsored-definition.js';
15
+ import { SPONSORED_CDP_NETWORKS } from './execution-sponsored-transport.js';
16
+ import { NATIVE_USEROP_CONTEXT_SCHEMA, assertNativeUserOpContext, validateNativeUserOpOperation, nativeUserOpReviewCommitment } from './native-yield-userop-operation.js';
17
+ import { NATIVE_YIELD_USEROP_SETTLEMENT_SCHEMA } from './native-yield-userop-definition.js';
18
+ import { LP_USEROP_CONTEXT_SCHEMA, assertLpUserOpContext, validateLpUserOpOperation, lpUserOpReviewCommitment } from './lp-userop-operation.js';
19
+ import { LP_USEROP_SETTLEMENT_SCHEMA } from './lp-userop-settlement.js';
20
+ import { LP_USEROP_SUBMIT_EVIDENCE_SCHEMA } from './lp-userop.js';
21
+ const handoffProofBrand = Symbol('sponsored-uninvoked-handoff');
22
+ const isNativeContext = (context) => 'kind' in context && context.kind === 'native-yield-userop';
23
+ const isLpContext = (context) => 'kind' in context && context.kind === 'lp-collect-userop';
24
+ function validateSponsoredRecord(raw) {
25
+ if (!raw || typeof raw !== 'object' || !('version' in raw))
26
+ return invalid();
27
+ let op;
28
+ switch (raw.version) {
29
+ case 1:
30
+ op = validateSponsoredOperation(raw);
31
+ break;
32
+ case 2:
33
+ op = validateNativeUserOpOperation(raw);
34
+ break;
35
+ case 3:
36
+ op = validateLpUserOpOperation(raw);
37
+ break;
38
+ default: return invalid();
39
+ }
40
+ if (op.gasReview) {
41
+ const quote = op.gasReview.quote, terms = sponsoredChainTerms(op.context.activation, op.context.chainId);
42
+ const calls = op.version === 1 ? sponsoredCalls(sponsoredPlan(op.context)) : op.version === 2
43
+ ? nativeYieldUserOpRecordedCalls(op.context.envelope) : lpUserOpRecordedCalls(op.context.envelope);
44
+ if (!op.context.activation.gasPaymentReviewEnabled || quote.account.toLowerCase() !== op.context.account.toLowerCase() ||
45
+ quote.chainId !== op.context.chainId || quote.entryPoint.toLowerCase() !== terms.entryPoint.toLowerCase() ||
46
+ quote.callsCommitment !== accountGasCallsCommitment(calls))
47
+ invalid();
48
+ }
49
+ return op;
50
+ }
51
+ function artifactKey(context) {
52
+ return isNativeContext(context) || isLpContext(context) ? context.envelope.commitment : context.envelope.submission.artifact_digest;
53
+ }
54
+ function assertFreshContext(context, now) {
55
+ if (isNativeContext(context))
56
+ assertNativeUserOpContext(context, true, now);
57
+ else if (isLpContext(context))
58
+ assertLpUserOpContext(context, true, now);
59
+ else
60
+ sponsoredPlan(context, true, now);
61
+ }
62
+ const unresolved = (op) => op.reviewConsumed && !['completed', 'failed'].includes(op.state);
63
+ function invalid() { throw new Error('SPONSOR_JOURNAL_INVALID'); }
64
+ export function validateSponsoredOperation(raw) {
65
+ const op = SPONSORED_OPERATION_SCHEMA.parse(raw), context = op.context;
66
+ if (op.userId !== context.authority.userId || context.account !== context.authority.account ||
67
+ context.authority.activationDigest !== sponsoredDigest(context.activation) ||
68
+ context.authority.policyRulesDigest !== context.activation.policyRulesDigest ||
69
+ op.reviewCommitment !== sponsoredReviewCommitment(op.operationId, context, op.gasReview) ||
70
+ (op.state === 'review') !== !op.reviewConsumed || op.updatedAtMs < op.createdAtMs ||
71
+ context.reviewedAtMs !== op.createdAtMs || context.validUntilMs <= context.reviewedAtMs ||
72
+ context.validUntilMs > Date.parse(context.envelope.valid_until) || context.validUntilMs > context.activation.expiresAtMs)
73
+ invalid();
74
+ const plan = sponsoredPlan(context), terms = sponsoredChainTerms(context.activation, context.chainId);
75
+ if (plan.token !== SPONSORED_USDC[context.chainId] || plan.gross > BigInt(Math.min(context.authority.perSwapCapUsd, context.activation.maxSwapUsdc)) * 1000000n)
76
+ invalid();
77
+ if (op.request) {
78
+ const body = JSON.parse(op.request.body);
79
+ const expectedBody = JSON.stringify({ network: SPONSORED_CDP_NETWORKS[context.chainId], calls: sponsoredCalls(plan),
80
+ useCdpPaymaster: false, ...(op.gasReview?.payer === 'account' ? {} : { paymasterAlias: `pimlico:${context.chainId}`, paymasterContext: { sponsorshipPolicyId: terms.sponsorshipPolicyId } }) });
81
+ if (op.request.userId !== op.userId || op.request.account !== context.account || op.request.chainId !== context.chainId ||
82
+ op.request.idempotencyKey !== op.operationId.slice(3) ||
83
+ op.request.path !== `/platform/v2/embedded-wallet-api/end-users/${op.userId}/evm/smart-accounts/${context.account.toLowerCase()}/send` ||
84
+ op.request.body !== expectedBody ||
85
+ 'paymasterUrl' in body || body.useCdpPaymaster !== false)
86
+ invalid();
87
+ }
88
+ if (op.handoffAttempted && !op.request)
89
+ invalid();
90
+ if (op.state === 'review' && (op.request || op.handoffAttempted || op.userOpHash || op.transactionHash))
91
+ invalid();
92
+ if ((op.userOpHash || op.transactionHash || op.receipt) && !op.handoffAttempted)
93
+ invalid();
94
+ if (op.transactionHash && !op.userOpHash)
95
+ invalid();
96
+ if (op.receipt && (op.receipt.userOpHash.toLowerCase() !== op.userOpHash?.toLowerCase() ||
97
+ op.receipt.transactionHash.toLowerCase() !== op.transactionHash?.toLowerCase() || op.receipt.chainId !== context.chainId ||
98
+ op.receipt.account !== context.account || op.receipt.paymaster !== (op.gasReview?.payer === 'account' ? '0x0000000000000000000000000000000000000000' : terms.paymaster) ||
99
+ (op.gasReview?.payer !== 'account' && BigInt(op.receipt.actualGasCostWei) > BigInt(terms.maxGasCostWei))))
100
+ invalid();
101
+ if (op.gasCapBreach && (op.gasReview?.payer === 'account' || !op.handoffAttempted || op.state !== 'submitted' || op.receipt || op.settlement ||
102
+ op.failureCode !== 'SPONSOR_GAS_CAP_EXCEEDED' ||
103
+ op.gasCapBreach.userOpHash.toLowerCase() !== op.userOpHash?.toLowerCase() ||
104
+ op.gasCapBreach.transactionHash.toLowerCase() !== op.transactionHash?.toLowerCase() ||
105
+ op.gasCapBreach.chainId !== context.chainId || op.gasCapBreach.account !== context.account ||
106
+ op.gasCapBreach.paymaster !== terms.paymaster ||
107
+ BigInt(op.gasCapBreach.actualGasCostWei) <= BigInt(terms.maxGasCostWei)))
108
+ invalid();
109
+ if (op.state === 'completed') {
110
+ const result = op.settlement;
111
+ if (op.receipt?.status !== 'success' || !result || result.userOpHash !== op.userOpHash ||
112
+ result.transactionHash !== op.transactionHash || result.inputToken !== plan.token || result.outputToken !== plan.outputToken ||
113
+ BigInt(result.inputDebited) !== plan.gross || BigInt(result.outputReceived) < plan.minAmountOut ||
114
+ BigInt(result.ottoFeeReceived) < plan.ottoFee)
115
+ invalid();
116
+ }
117
+ else if (op.settlement)
118
+ invalid();
119
+ if (op.state === 'failed' && op.handoffAttempted && op.receipt?.status !== 'reverted')
120
+ invalid();
121
+ if (op.state === 'submitted' && !op.userOpHash)
122
+ invalid();
123
+ return op;
124
+ }
125
+ export class SponsoredOperationStore {
126
+ db;
127
+ now;
128
+ kind;
129
+ handoffProofs = new WeakMap();
130
+ constructor(db, now = Date.now, kind = 'swap') {
131
+ this.db = db;
132
+ this.now = now;
133
+ this.kind = kind;
134
+ assertExecutionJournalCompatible(db, 4);
135
+ assertExecutionStorageSchema(db, SPONSORED_STORAGE_SCHEMA);
136
+ this.transaction(() => {
137
+ const operations = this.all();
138
+ for (const op of operations.filter(unresolved))
139
+ this.requireClaim(op);
140
+ const claims = db.prepare("SELECT user_id,claim_id FROM user_execution_claims WHERE kind='sponsored'").all();
141
+ if (claims.some(c => !operations.some(op => unresolved(op) && op.userId === c.user_id && op.operationId === c.claim_id)))
142
+ invalid();
143
+ });
144
+ }
145
+ /** Typed view of the SAME connection, table, transaction, cross-rail claim and gas budget. */
146
+ forNativeYieldUserOp() {
147
+ return new SponsoredOperationStore(this.db, this.now, 'native-yield-userop');
148
+ }
149
+ forLpV3CollectUserOp() {
150
+ return new SponsoredOperationStore(this.db, this.now, 'lp-collect-userop');
151
+ }
152
+ narrow(op) {
153
+ const version = this.kind === 'swap' ? 1 : this.kind === 'native-yield-userop' ? 2 : 3;
154
+ if (op.version !== version)
155
+ throw new Error('SPONSOR_OPERATION_KIND_MISMATCH');
156
+ return op;
157
+ }
158
+ journalStatus() { assertExecutionJournalCompatible(this.db, 4); return readExecutionJournalStatus(this.db); }
159
+ assertReadyForNewOperations() {
160
+ requireSponsoredExecutionJournalReady(this.db);
161
+ if (this.kind === 'native-yield-userop')
162
+ requireNativeUserOpJournalReady(this.db);
163
+ if (this.kind === 'lp-collect-userop')
164
+ requireLpUserOpJournalReady(this.db);
165
+ }
166
+ transaction(fn) {
167
+ const outer = this.db.isTransaction === true, savepoint = `sponsor_${randomUUID().replaceAll('-', '')}`;
168
+ this.db.exec(outer ? `SAVEPOINT ${savepoint}` : 'BEGIN IMMEDIATE');
169
+ try {
170
+ assertExecutionJournalCompatible(this.db, 4);
171
+ const result = fn();
172
+ this.db.exec(outer ? `RELEASE ${savepoint}` : 'COMMIT');
173
+ return result;
174
+ }
175
+ catch (error) {
176
+ try {
177
+ if (outer) {
178
+ this.db.exec(`ROLLBACK TO ${savepoint}`);
179
+ this.db.exec(`RELEASE ${savepoint}`);
180
+ }
181
+ else
182
+ this.db.exec('ROLLBACK');
183
+ }
184
+ catch { /* preserve refusal */ }
185
+ throw error;
186
+ }
187
+ }
188
+ decode(row) {
189
+ if (!row)
190
+ return undefined;
191
+ const r = row;
192
+ const op = validateSponsoredRecord(JSON.parse(r.record_json));
193
+ const schema = readExecutionJournalStatus(this.db).schemaVersion;
194
+ if ((op.version === 2 && schema < 5) || (op.version === 3 && schema < 6))
195
+ invalid();
196
+ if (op.operationId !== r.operation_id || op.userId !== r.user_id || artifactKey(op.context) !== r.artifact_key)
197
+ invalid();
198
+ return op;
199
+ }
200
+ all() {
201
+ return this.db.prepare('SELECT * FROM sponsored_operations').all().map(row => this.decode(row));
202
+ }
203
+ assertContextBudgetAvailable(context) {
204
+ if (this.all().some(op => op.context.activation.id === context.activation.id &&
205
+ op.context.chainId === context.chainId && op.gasCapBreach))
206
+ throw new Error('SPONSOR_BUDGET_HALTED');
207
+ }
208
+ /** Also checks reviews admitted before another user's proven provider-cap breach. */
209
+ assertBudgetAvailable(userId, operationId) {
210
+ this.assertContextBudgetAvailable(this.read(userId, operationId).context);
211
+ }
212
+ /** Linearize a transport handoff with every durable gas-cap breach. The callback starts
213
+ * fetch synchronously and returns its promise; this transaction never awaits the network. */
214
+ handoff(userId, operationId, start) {
215
+ let pending;
216
+ try {
217
+ return this.transaction(() => {
218
+ const op = this.read(userId, operationId);
219
+ this.requireClaim(op);
220
+ if (!op.handoffAttempted || !op.request || op.state !== 'unknown' || op.userOpHash ||
221
+ (op.version === 3 && !op.submitEvidence))
222
+ invalid();
223
+ this.assertContextBudgetAvailable(op.context);
224
+ assertFreshContext(op.context, this.now());
225
+ if (op.context.validUntilMs <= this.now())
226
+ throw new Error('SPONSOR_REVIEW_EXPIRED');
227
+ pending = start();
228
+ return pending;
229
+ });
230
+ }
231
+ catch (error) {
232
+ // A commit error cannot undo an invoked fetch. Retain its durable attempted claim,
233
+ // and handle a later rejection while the caller reports the original uncertainty.
234
+ void pending?.catch(() => undefined);
235
+ throw error;
236
+ }
237
+ }
238
+ requireClaim(op) {
239
+ const claim = readUserExecutionClaim(this.db, op.userId);
240
+ if (claim?.kind !== 'sponsored' || claim.claimId !== op.operationId)
241
+ invalid();
242
+ }
243
+ read(userId, operationId) {
244
+ assertExecutionJournalCompatible(this.db, 4);
245
+ const op = this.decode(this.db.prepare('SELECT * FROM sponsored_operations WHERE user_id=? AND operation_id=?').get(userId, operationId));
246
+ if (!op)
247
+ throw new Error('SPONSOR_OPERATION_NOT_FOUND');
248
+ if (unresolved(op))
249
+ this.requireClaim(op);
250
+ return this.narrow(op);
251
+ }
252
+ save(op) {
253
+ op.updatedAtMs = this.now();
254
+ validateSponsoredRecord(op);
255
+ const result = this.db.prepare('UPDATE sponsored_operations SET record_json=? WHERE user_id=? AND operation_id=?')
256
+ .run(JSON.stringify(op), op.userId, op.operationId);
257
+ if (Number(result.changes) !== 1)
258
+ invalid();
259
+ return op;
260
+ }
261
+ create(raw) {
262
+ return this.transaction(() => {
263
+ this.assertReadyForNewOperations();
264
+ const context = this.kind === 'native-yield-userop' ? NATIVE_USEROP_CONTEXT_SCHEMA.parse(raw)
265
+ : this.kind === 'lp-collect-userop' ? LP_USEROP_CONTEXT_SCHEMA.parse(raw) : SPONSORED_CONTEXT_SCHEMA.parse(raw);
266
+ const operationId = `sp_${randomUUID()}`, now = this.now();
267
+ this.assertContextBudgetAvailable(context);
268
+ if (readUserExecutionClaim(this.db, context.authority.userId))
269
+ throw new Error('SPONSOR_EXECUTION_BUSY');
270
+ const op = this.narrow(validateSponsoredRecord({ version: this.kind === 'native-yield-userop' ? 2 : this.kind === 'lp-collect-userop' ? 3 : 1, operationId, userId: context.authority.userId, context,
271
+ reviewCommitment: isNativeContext(context) ? nativeUserOpReviewCommitment(operationId, context)
272
+ : isLpContext(context) ? lpUserOpReviewCommitment(operationId, context) : sponsoredReviewCommitment(operationId, context), reviewConsumed: false,
273
+ state: 'review', createdAtMs: context.reviewedAtMs, updatedAtMs: now, handoffAttempted: false }));
274
+ this.db.prepare('INSERT INTO sponsored_operations(operation_id,user_id,artifact_key,record_json) VALUES(?,?,?,?)')
275
+ .run(operationId, op.userId, artifactKey(context), JSON.stringify(op));
276
+ return op;
277
+ });
278
+ }
279
+ /** Re-price only an unconsumed review or an exact, terminal proof that no request started.
280
+ * The same operation ID remains the recovery identity; changed gas terms require new consent. */
281
+ reviewGas(userId, operationId, expectedReviewCommitment, raw) {
282
+ return this.transaction(() => {
283
+ this.assertReadyForNewOperations();
284
+ const op = this.read(userId, operationId);
285
+ if (op.reviewCommitment !== expectedReviewCommitment || op.handoffAttempted || op.userOpHash ||
286
+ op.transactionHash || op.receipt || op.settlement || op.gasCapBreach ||
287
+ (op.state !== 'review' && !(op.state === 'failed' && op.failureCode === 'SPONSOR_NOT_SUBMITTED')) ||
288
+ !op.context.activation.gasPaymentReviewEnabled || op.context.validUntilMs <= this.now() ||
289
+ readUserExecutionClaim(this.db, userId))
290
+ throw new Error('ACCOUNT_GAS_REVIEW_UNAVAILABLE');
291
+ const gasReview = ACCOUNT_GAS_REVIEW_SCHEMA.parse(raw);
292
+ if (gasReview.revision !== (op.gasReview?.revision ?? 0) + 1 ||
293
+ gasReview.quote.account.toLowerCase() !== op.context.account.toLowerCase() || gasReview.quote.chainId !== op.context.chainId)
294
+ throw new Error('ACCOUNT_GAS_REVIEW_INVALID');
295
+ op.gasReview = gasReview;
296
+ op.reviewCommitment = isNativeContext(op.context) ? nativeUserOpReviewCommitment(operationId, op.context, gasReview)
297
+ : isLpContext(op.context) ? lpUserOpReviewCommitment(operationId, op.context, gasReview)
298
+ : sponsoredReviewCommitment(operationId, op.context, gasReview);
299
+ op.state = 'review';
300
+ op.reviewConsumed = false;
301
+ delete op.request;
302
+ delete op.failureCode;
303
+ delete op.gasReviewFailure;
304
+ if ('submitEvidence' in op)
305
+ delete op.submitEvidence;
306
+ return this.save(op);
307
+ });
308
+ }
309
+ recordGasReviewFailure(userId, operationId, failure) {
310
+ return this.transaction(() => {
311
+ const op = this.read(userId, operationId);
312
+ if (op.handoffAttempted || op.userOpHash || op.transactionHash ||
313
+ (op.state !== 'review' && !(op.state === 'failed' && op.failureCode === 'SPONSOR_NOT_SUBMITTED')))
314
+ return op;
315
+ op.gasReviewFailure = ACCOUNT_GAS_FAILURE_SCHEMA.parse(failure);
316
+ return this.save(op);
317
+ });
318
+ }
319
+ begin(userId, operationId, reviewCommitment, authority) {
320
+ return this.transaction(() => {
321
+ this.assertReadyForNewOperations();
322
+ const op = this.read(userId, operationId);
323
+ if (op.state !== 'review' || op.reviewConsumed || op.reviewCommitment !== reviewCommitment ||
324
+ op.context.validUntilMs <= this.now() || sponsoredDigest(authority) !== sponsoredDigest(op.context.authority))
325
+ throw new Error('SPONSOR_REVIEW_REQUIRED');
326
+ this.assertContextBudgetAvailable(op.context);
327
+ const terms = sponsoredChainTerms(op.context.activation, op.context.chainId);
328
+ let total = 0n, user = 0n;
329
+ for (const prior of this.all()) {
330
+ if (prior.gasReview?.payer === 'account' || !prior.reviewConsumed || prior.context.activation.id !== op.context.activation.id || prior.context.chainId !== op.context.chainId)
331
+ continue;
332
+ const cost = prior.receipt ? BigInt(prior.receipt.actualGasCostWei) : prior.state === 'failed' && !prior.handoffAttempted
333
+ ? 0n : BigInt(sponsoredChainTerms(prior.context.activation, prior.context.chainId).maxGasCostWei);
334
+ total += cost;
335
+ if (prior.userId === userId)
336
+ user += cost;
337
+ }
338
+ if (op.gasReview?.payer !== 'account' && (total + BigInt(terms.maxGasCostWei) > BigInt(terms.maxTotalGasCostWei) ||
339
+ user + BigInt(terms.maxGasCostWei) > BigInt(terms.maxUserGasCostWei)))
340
+ throw new Error('SPONSOR_BUDGET_EXHAUSTED');
341
+ if (claimSponsoredExecution(this.db, { userId, operationId }, this.now()).outcome !== 'started')
342
+ throw new Error('SPONSOR_EXECUTION_BUSY');
343
+ op.reviewConsumed = true;
344
+ op.state = 'active';
345
+ return this.save(op);
346
+ });
347
+ }
348
+ prepare(userId, operationId, request) {
349
+ return this.transaction(() => {
350
+ const op = this.read(userId, operationId);
351
+ this.requireClaim(op);
352
+ if (op.state !== 'active' || op.request || op.handoffAttempted)
353
+ invalid();
354
+ op.request = SPONSORED_STORED_REQUEST_SCHEMA.parse(request);
355
+ return this.save(op);
356
+ });
357
+ }
358
+ /** Write the final independent submit baseline once, before the durable attempted stamp and fetch. */
359
+ recordLpVerification(userId, operationId, raw) {
360
+ return this.transaction(() => {
361
+ const op = this.read(userId, operationId);
362
+ this.requireClaim(op);
363
+ if (op.version !== 3 || op.state !== 'active' || op.handoffAttempted || !op.request || op.userOpHash || op.submitEvidence)
364
+ invalid();
365
+ op.submitEvidence = LP_USEROP_SUBMIT_EVIDENCE_SCHEMA.parse(raw);
366
+ return this.save(op);
367
+ });
368
+ }
369
+ attempted(userId, operationId) {
370
+ return this.transaction(() => {
371
+ const op = this.read(userId, operationId);
372
+ this.requireClaim(op);
373
+ if (!op.request || op.handoffAttempted || op.state !== 'active' || (op.version === 3 && !op.submitEvidence))
374
+ invalid();
375
+ op.handoffAttempted = true;
376
+ op.state = 'unknown';
377
+ return this.save(op);
378
+ });
379
+ }
380
+ /** Only a successfully committed standalone stamp can mint this one-use process proof.
381
+ * Losing it on crash/restart deliberately leaves the original attempted claim unresolved. */
382
+ attemptedWithProof(userId, operationId) {
383
+ if (this.db.isTransaction === true)
384
+ invalid();
385
+ const op = this.attempted(userId, operationId);
386
+ const proof = Object.freeze({ [handoffProofBrand]: true });
387
+ this.handoffProofs.set(proof, { userId, operationId, recordDigest: sponsoredDigest(op) });
388
+ return proof;
389
+ }
390
+ uninvokedHandoff(proof) {
391
+ const recorded = proof && this.handoffProofs.get(proof);
392
+ if (!recorded)
393
+ invalid();
394
+ try {
395
+ const op = this.read(recorded.userId, recorded.operationId);
396
+ this.requireClaim(op);
397
+ if (op.state !== 'unknown' || !op.handoffAttempted || !op.request || op.userOpHash || op.transactionHash ||
398
+ op.receipt || op.gasCapBreach || sponsoredDigest(op) !== recorded.recordDigest)
399
+ invalid();
400
+ return op;
401
+ }
402
+ catch (error) {
403
+ // A changed row can never regain this process proof by later restoring old bytes.
404
+ this.handoffProofs.delete(proof);
405
+ throw error;
406
+ }
407
+ }
408
+ /** Called under handoff's writer lock immediately BEFORE the actual provider callback.
409
+ * A synchronous callback throw is therefore ambiguous and can never release the claim. */
410
+ consumeHandoffProof(proof) {
411
+ if (this.db.isTransaction !== true)
412
+ invalid();
413
+ this.uninvokedHandoff(proof);
414
+ this.handoffProofs.delete(proof);
415
+ }
416
+ /** Same-process, exact-row non-invocation is the sole exception to retaining a stamped claim. */
417
+ failUninvokedHandoff(proof) {
418
+ const op = this.transaction(() => {
419
+ const current = this.uninvokedHandoff(proof);
420
+ current.handoffAttempted = false;
421
+ current.state = 'failed';
422
+ current.failureCode = 'SPONSOR_NOT_SUBMITTED';
423
+ this.save(current);
424
+ releaseSponsoredExecutionClaim(this.db, { userId: current.userId, operationId: current.operationId });
425
+ return current;
426
+ });
427
+ this.handoffProofs.delete(proof);
428
+ return op;
429
+ }
430
+ acknowledged(userId, operationId, result) {
431
+ return this.transaction(() => {
432
+ const op = this.read(userId, operationId);
433
+ this.requireClaim(op);
434
+ if (!op.handoffAttempted || (op.userOpHash && op.userOpHash.toLowerCase() !== result.userOpHash.toLowerCase()) ||
435
+ (op.transactionHash && result.transactionHash && op.transactionHash.toLowerCase() !== result.transactionHash.toLowerCase()))
436
+ invalid();
437
+ op.userOpHash = result.userOpHash;
438
+ if (result.transactionHash)
439
+ op.transactionHash = result.transactionHash;
440
+ op.state = 'submitted';
441
+ return this.save(op);
442
+ });
443
+ }
444
+ failBeforeHandoff(userId, operationId) {
445
+ return this.transaction(() => {
446
+ const op = this.read(userId, operationId);
447
+ this.requireClaim(op);
448
+ if (op.handoffAttempted)
449
+ invalid();
450
+ op.state = 'failed';
451
+ op.failureCode = 'SPONSOR_NOT_SUBMITTED';
452
+ this.save(op);
453
+ releaseSponsoredExecutionClaim(this.db, { userId, operationId });
454
+ return op;
455
+ });
456
+ }
457
+ recordGasCapBreach(userId, operationId, receipt) {
458
+ return this.transaction(() => {
459
+ const op = this.read(userId, operationId);
460
+ this.requireClaim(op);
461
+ const proof = SPONSORED_RECEIPT_SCHEMA.parse(receipt);
462
+ if (op.gasCapBreach && sponsoredDigest(op.gasCapBreach) !== sponsoredDigest(proof))
463
+ invalid();
464
+ op.gasCapBreach = proof;
465
+ op.failureCode = 'SPONSOR_GAS_CAP_EXCEEDED';
466
+ // Validation binds the canonical proof to this exact submitted operation and a real cap breach.
467
+ // The original cross-rail claim remains held. There is deliberately no automatic circuit reset.
468
+ return this.save(op);
469
+ });
470
+ }
471
+ finish(userId, operationId, receipt, settlement) {
472
+ return this.transaction(() => {
473
+ const op = this.read(userId, operationId);
474
+ this.requireClaim(op);
475
+ op.receipt = SPONSORED_RECEIPT_SCHEMA.parse(receipt);
476
+ op.state = receipt.status === 'success' ? 'completed' : 'failed';
477
+ if (op.version === 2)
478
+ op.settlement = NATIVE_YIELD_USEROP_SETTLEMENT_SCHEMA.parse(settlement);
479
+ else if (op.version === 3)
480
+ op.settlement = LP_USEROP_SETTLEMENT_SCHEMA.parse(settlement);
481
+ else if (receipt.status === 'success')
482
+ op.settlement = SPONSORED_SETTLEMENT_SCHEMA.parse(settlement);
483
+ if (receipt.status === 'reverted')
484
+ op.failureCode = 'SPONSOR_USER_OPERATION_REVERTED';
485
+ this.save(op);
486
+ releaseSponsoredExecutionClaim(this.db, { userId, operationId });
487
+ return op;
488
+ });
489
+ }
490
+ }
491
+ /** Does not initialize or migrate: the coordinated offline rollout must already have installed v4. */
492
+ export async function openSponsoredOperationStore(root, now = Date.now) {
493
+ const path = join(root, 'operations.db');
494
+ await access(path);
495
+ const specifier = 'node:sqlite';
496
+ const { DatabaseSync } = await import(specifier);
497
+ const uri = pathToFileURL(path);
498
+ uri.searchParams.set('mode', 'rw');
499
+ const db = new DatabaseSync(uri.href);
500
+ try {
501
+ const version = db.prepare('SELECT sqlite_version() AS version').get()?.version;
502
+ if (!sqliteWalRuntimeIsSafe(version))
503
+ throw new Error('SPONSOR_SQLITE_RUNTIME_UNSAFE');
504
+ db.exec('PRAGMA busy_timeout=5000');
505
+ assertExecutionJournalCompatible(db, 4);
506
+ assertDeclaredExecutionStorage(db, readExecutionJournalStatus(db).schemaVersion);
507
+ db.exec('PRAGMA journal_mode=WAL; PRAGMA synchronous=FULL; PRAGMA foreign_keys=ON;');
508
+ if (!db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='operations'").get())
509
+ invalid();
510
+ return new SponsoredOperationStore(db, now);
511
+ }
512
+ catch (error) {
513
+ db.close();
514
+ throw error;
515
+ }
516
+ }
517
+ //# sourceMappingURL=execution-sponsored-store.js.map
@@ -0,0 +1,90 @@
1
+ import { z } from 'zod';
2
+ import { type SponsoredGasPolicyProof } from './execution-sponsored-gas-policy.js';
3
+ /** Self-contained public declarations: inspecting an inactive entry needs no optional SDK. */
4
+ export interface SponsoredCredentials {
5
+ readonly apiKeyId?: string;
6
+ readonly apiKeySecret?: string;
7
+ readonly walletSecret?: string;
8
+ }
9
+ export interface SponsoredAuthOptions extends SponsoredCredentials {
10
+ readonly requestMethod: string;
11
+ readonly requestHost: string;
12
+ readonly requestPath: string;
13
+ readonly requestBody?: unknown;
14
+ readonly source?: string;
15
+ }
16
+ export type SponsoredAuth = (options: SponsoredAuthOptions) => Promise<Record<string, string>>;
17
+ export declare const SPONSORED_CDP_NETWORKS: {
18
+ readonly 1: "ethereum";
19
+ readonly 8453: "base";
20
+ readonly 42161: "arbitrum";
21
+ readonly 10: "optimism";
22
+ readonly 137: "polygon";
23
+ };
24
+ export type SponsoredChainId = keyof typeof SPONSORED_CDP_NETWORKS;
25
+ export type SponsoredGasPayer = 'sponsor' | 'account';
26
+ declare const callSchema: z.ZodObject<{
27
+ to: z.ZodString;
28
+ data: z.ZodString;
29
+ value: z.ZodString;
30
+ }, z.core.$strict>;
31
+ declare const responseSchema: z.ZodObject<{
32
+ network: z.ZodString;
33
+ userOpHash: z.ZodString;
34
+ calls: z.ZodArray<z.ZodObject<{
35
+ to: z.ZodString;
36
+ data: z.ZodString;
37
+ value: z.ZodString;
38
+ }, z.core.$strict>>;
39
+ status: z.ZodEnum<{
40
+ failed: "failed";
41
+ pending: "pending";
42
+ signed: "signed";
43
+ broadcast: "broadcast";
44
+ complete: "complete";
45
+ dropped: "dropped";
46
+ }>;
47
+ transactionHash: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodLiteral<"">]>>;
48
+ }, z.core.$strip>;
49
+ export type SponsoredCall = Readonly<z.infer<typeof callSchema>>;
50
+ export interface SponsoredBinding {
51
+ readonly userId: string;
52
+ readonly account: string;
53
+ readonly chainId: SponsoredChainId;
54
+ readonly idempotencyKey: string;
55
+ }
56
+ export interface SponsoredProviderConfig {
57
+ readonly chainId: SponsoredChainId;
58
+ /** Operator-owned URL; never accepted from an MCP request or exposed in a tool response. */
59
+ readonly paymasterUrl: string;
60
+ readonly sponsorshipPolicyId: string;
61
+ }
62
+ export interface PreparedSponsoredRequest extends SponsoredBinding {
63
+ readonly path: string;
64
+ /** Persistable calls/policy/provider alias. Never contains the paymaster URL or credential. */
65
+ readonly body: string;
66
+ readonly digest: string;
67
+ }
68
+ export interface SponsoredAcknowledgement {
69
+ readonly userOpHash: `0x${string}`;
70
+ readonly status: z.infer<typeof responseSchema>['status'];
71
+ readonly transactionHash?: `0x${string}`;
72
+ }
73
+ export declare class SponsoredTransportError extends Error {
74
+ readonly code: 'SPONSOR_CONFIGURATION_INVALID' | 'SPONSOR_REQUEST_INVALID' | 'SPONSOR_AUTH_UNAVAILABLE' | 'SPONSOR_SUBMISSION_UNCERTAIN';
75
+ constructor(code: 'SPONSOR_CONFIGURATION_INVALID' | 'SPONSOR_REQUEST_INVALID' | 'SPONSOR_AUTH_UNAVAILABLE' | 'SPONSOR_SUBMISSION_UNCERTAIN');
76
+ }
77
+ export declare function createSponsoredCdpTransport(options: {
78
+ readonly providers: readonly SponsoredProviderConfig[];
79
+ readonly credentials: SponsoredCredentials;
80
+ readonly fetch?: typeof fetch;
81
+ readonly auth?: SponsoredAuth;
82
+ readonly now?: () => number;
83
+ readonly monotonic?: () => number;
84
+ }): Readonly<{
85
+ prepare: (binding: SponsoredBinding, calls: readonly SponsoredCall[], payer?: SponsoredGasPayer) => PreparedSponsoredRequest;
86
+ checkGasPolicy: (chainId: SponsoredChainId) => Promise<Readonly<SponsoredGasPolicyProof>>;
87
+ /** Readiness/Stop/capability must be checked by the owning service after auth and immediately before POST. */
88
+ send(request: PreparedSponsoredRequest, beforeHandoff: () => Promise<void>, handoff?: (start: (onInvoke?: (gasPolicy?: SponsoredGasPolicyProof) => void) => Promise<Response>) => Promise<Response>): Promise<SponsoredAcknowledgement>;
89
+ }>;
90
+ export {};