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,317 @@
1
+ import { NATIVE_CONSENT_SCHEMA, assertExecutionStorageSchema } from './execution-journal-tables.js';
2
+ /** Explicit native scope consent. This store holds no token, signer, or transaction submission authority. */
3
+ import { createHash, randomUUID } from 'node:crypto';
4
+ import { getAddress } from 'viem';
5
+ import { z } from 'zod';
6
+ import { NATIVE_ACCOUNT_ADDRESS, NATIVE_ACCOUNT_AUTHORITY_SCHEMA, NATIVE_ACCOUNT_COMMITMENT, NATIVE_ACCOUNT_CONSENT_SCHEMA, NATIVE_ACCOUNT_CONSENT_TTL_MS, NATIVE_ACCOUNT_ID, NATIVE_ACCOUNT_SCOPES, NATIVE_ACCOUNT_TIME, NATIVE_ACCOUNT_USER, } from './native-yield-account-definition.js';
7
+ import { assertExecutionJournalCompatible, readUserExecutionClaim, requireExecutionJournalReady, } from './execution-journal-schema.js';
8
+ const DOMAIN = 'otto.native-yield.account-consent.v1';
9
+ const CONFIRM_INPUT = z.object({
10
+ userId: NATIVE_ACCOUNT_USER,
11
+ consentId: NATIVE_ACCOUNT_ID.refine((id) => id.startsWith('nc_')),
12
+ consentCommitment: NATIVE_ACCOUNT_COMMITMENT,
13
+ }).strict();
14
+ function refuse(detail) { throw new Error(`native yield consent refused: ${detail}`); }
15
+ function canonical(value) {
16
+ if (Array.isArray(value))
17
+ return `[${value.map(canonical).join(',')}]`;
18
+ if (value !== null && typeof value === 'object')
19
+ return `{${Object.entries(value)
20
+ .sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0)
21
+ .map(([key, entry]) => `${JSON.stringify(key)}:${canonical(entry)}`).join(',')}}`;
22
+ return JSON.stringify(value);
23
+ }
24
+ function immutable(value) {
25
+ if (value !== null && typeof value === 'object') {
26
+ for (const entry of Object.values(value))
27
+ immutable(entry);
28
+ Object.freeze(value);
29
+ }
30
+ return value;
31
+ }
32
+ function accountAddress(account) {
33
+ const parsed = getAddress(NATIVE_ACCOUNT_ADDRESS.parse(account));
34
+ if (parsed === '0x0000000000000000000000000000000000000000')
35
+ return refuse('the account is zero');
36
+ return parsed;
37
+ }
38
+ function time(nowMs) { return NATIVE_ACCOUNT_TIME.parse(nowMs); }
39
+ function authorityTerms(input) {
40
+ const parsed = NATIVE_ACCOUNT_AUTHORITY_SCHEMA.parse(input);
41
+ if (parsed.scopes.some((scope, index) => scope !== NATIVE_ACCOUNT_SCOPES[index]))
42
+ return refuse('scopes must be unique and in the reviewed order');
43
+ return {
44
+ ...parsed,
45
+ account: accountAddress(parsed.account),
46
+ grantExpiresAt: new Date(parsed.grantExpiresAt).toISOString(),
47
+ };
48
+ }
49
+ function assertGrantValid(authority, nowMs) {
50
+ if (Date.parse(authority.grantExpiresAt) <= nowMs)
51
+ refuse('the grant has expired');
52
+ }
53
+ function commitment(record) {
54
+ return `sha256:${createHash('sha256').update(canonical({ domain: DOMAIN, ...record })).digest('hex')}`;
55
+ }
56
+ function consentCommitment(record) {
57
+ return commitment({
58
+ consentId: record.consentId, authority: record.authority, generation: record.generation,
59
+ createdAtMs: record.createdAtMs, challengeExpiresAtMs: record.challengeExpiresAtMs,
60
+ });
61
+ }
62
+ /** Nested mutations use a savepoint, so a caught refusal cannot leave part of a consent transition. */
63
+ function transaction(db, write, body) {
64
+ if (typeof db.isTransaction !== 'boolean')
65
+ return refuse('the database transaction state is unavailable');
66
+ const own = !db.isTransaction;
67
+ const savepoint = !own && write ? `ny_consent_${randomUUID().replace(/-/g, '')}` : undefined;
68
+ if (own)
69
+ db.exec(write ? 'BEGIN IMMEDIATE' : 'BEGIN');
70
+ else if (savepoint)
71
+ db.exec(`SAVEPOINT ${savepoint}`);
72
+ try {
73
+ assertExecutionJournalCompatible(db, 3);
74
+ const result = body();
75
+ if (own)
76
+ db.exec('COMMIT');
77
+ else if (savepoint)
78
+ db.exec(`RELEASE SAVEPOINT ${savepoint}`);
79
+ return result;
80
+ }
81
+ catch (error) {
82
+ try {
83
+ if (own)
84
+ db.exec('ROLLBACK');
85
+ else if (savepoint) {
86
+ db.exec(`ROLLBACK TO SAVEPOINT ${savepoint}`);
87
+ db.exec(`RELEASE SAVEPOINT ${savepoint}`);
88
+ }
89
+ }
90
+ catch { /* preserve the original refusal */ }
91
+ throw error;
92
+ }
93
+ }
94
+ function readSubject(db, userId, account) {
95
+ const row = db.prepare('SELECT * FROM native_yield_consent_subjects WHERE user_id=? AND account=?')
96
+ .get(userId, account);
97
+ if (!row)
98
+ return undefined;
99
+ if (row.user_id !== userId || row.account !== account || !Number.isSafeInteger(row.generation) ||
100
+ Number(row.generation) < 0 || !Number.isSafeInteger(row.updated_at_ms) || Number(row.updated_at_ms) < 0 ||
101
+ (row.active_consent_id !== null && (typeof row.active_consent_id !== 'string' || !row.active_consent_id.startsWith('nc_') ||
102
+ !NATIVE_ACCOUNT_ID.safeParse(row.active_consent_id).success)))
103
+ return refuse('the subject counter is corrupt');
104
+ return { userId, account, generation: row.generation, activeConsentId: row.active_consent_id,
105
+ updatedAtMs: row.updated_at_ms };
106
+ }
107
+ function parseRecord(row) {
108
+ if (row === undefined)
109
+ return undefined;
110
+ if (!row || typeof row !== 'object')
111
+ return refuse('the stored challenge is corrupt');
112
+ const item = row;
113
+ if (typeof item.authority_json !== 'string')
114
+ return refuse('the stored authority is corrupt');
115
+ let authority;
116
+ try {
117
+ authority = authorityTerms(JSON.parse(item.authority_json));
118
+ }
119
+ catch {
120
+ return refuse('the stored authority is corrupt');
121
+ }
122
+ if (canonical(authority) !== item.authority_json || authority.userId !== item.user_id || authority.account !== item.account)
123
+ return refuse('the stored authority subject or encoding changed');
124
+ const record = NATIVE_ACCOUNT_CONSENT_SCHEMA.parse({
125
+ consentId: item.consent_id, authority, consentCommitment: item.consent_commitment, state: item.state,
126
+ generation: item.generation, createdAtMs: item.created_at_ms, challengeExpiresAtMs: item.challenge_expires_at_ms,
127
+ confirmedAtMs: item.confirmed_at_ms,
128
+ });
129
+ if (!record.consentId.startsWith('nc_') || record.generation < 1 ||
130
+ record.challengeExpiresAtMs !== record.createdAtMs + NATIVE_ACCOUNT_CONSENT_TTL_MS ||
131
+ Date.parse(authority.grantExpiresAt) <= record.challengeExpiresAtMs || consentCommitment(record) !== record.consentCommitment)
132
+ return refuse('the stored immutable challenge terms changed');
133
+ if (record.state === 'confirmed' && record.confirmedAtMs === null)
134
+ return refuse('confirmation evidence is missing');
135
+ if (record.state === 'challenge' && record.confirmedAtMs !== null)
136
+ return refuse('an unconfirmed challenge carries confirmation evidence');
137
+ if (record.confirmedAtMs !== null && (record.confirmedAtMs < record.createdAtMs || record.confirmedAtMs >= record.challengeExpiresAtMs))
138
+ return refuse('confirmation time is outside the challenge window');
139
+ return immutable(record);
140
+ }
141
+ function readRecord(db, consentId) {
142
+ return parseRecord(db.prepare('SELECT * FROM native_yield_consents WHERE consent_id=?').get(consentId));
143
+ }
144
+ function assertSubjectCoherent(db, subject) {
145
+ const confirmed = db.prepare("SELECT * FROM native_yield_consents WHERE user_id=? AND account=? AND state='confirmed'")
146
+ .all(subject.userId, subject.account);
147
+ if (subject.activeConsentId === null) {
148
+ if (confirmed.length !== 0)
149
+ return refuse('a confirmed consent has no active pointer');
150
+ return undefined;
151
+ }
152
+ if (confirmed.length !== 1)
153
+ return refuse('the active consent is missing or ambiguous');
154
+ const record = parseRecord(confirmed[0]);
155
+ if (record.consentId !== subject.activeConsentId || record.generation !== subject.generation)
156
+ return refuse('the active consent generation changed');
157
+ return record;
158
+ }
159
+ function assertNoExecutionClaim(db, userId) {
160
+ if (readUserExecutionClaim(db, userId))
161
+ refuse('an unresolved user operation prevents a new consent');
162
+ }
163
+ function nextGeneration(subject) {
164
+ if (subject.generation >= Number.MAX_SAFE_INTEGER)
165
+ return refuse('the consent counter cannot advance');
166
+ return subject.generation + 1;
167
+ }
168
+ export function initializeNativeYieldConsents(db) {
169
+ transaction(db, true, () => {
170
+ assertExecutionStorageSchema(db, NATIVE_CONSENT_SCHEMA);
171
+ const subjects = db.prepare('SELECT user_id,account FROM native_yield_consent_subjects').all();
172
+ for (const item of subjects) {
173
+ const userId = NATIVE_ACCOUNT_USER.parse(item.user_id);
174
+ const account = accountAddress(NATIVE_ACCOUNT_ADDRESS.parse(item.account));
175
+ if (account !== item.account)
176
+ refuse('a stored account is not canonical');
177
+ assertSubjectCoherent(db, readSubject(db, userId, account));
178
+ }
179
+ const records = db.prepare('SELECT * FROM native_yield_consents').all();
180
+ for (const row of records) {
181
+ const record = parseRecord(row);
182
+ const subject = readSubject(db, record.authority.userId, record.authority.account);
183
+ if (!subject || record.generation > subject.generation + 1)
184
+ refuse('a challenge has no valid subject counter');
185
+ if (record.state === 'challenge' && record.generation !== subject.generation + 1)
186
+ refuse('a pending challenge is stale without an invalidation record');
187
+ }
188
+ });
189
+ }
190
+ /** Authenticated subject lookup for challenge review/confirmation. History is evidence, not authority. */
191
+ export function readNativeYieldConsent(db, userId, consentId) {
192
+ NATIVE_ACCOUNT_USER.parse(userId);
193
+ NATIVE_ACCOUNT_ID.refine((id) => id.startsWith('nc_')).parse(consentId);
194
+ return transaction(db, false, () => parseRecord(db.prepare('SELECT * FROM native_yield_consents WHERE user_id=? AND consent_id=?').get(userId, consentId)));
195
+ }
196
+ export function createNativeYieldConsent(db, inputAuthority, nowMs) {
197
+ time(nowMs);
198
+ const authority = authorityTerms(inputAuthority);
199
+ const expires = time(nowMs + NATIVE_ACCOUNT_CONSENT_TTL_MS);
200
+ if (Date.parse(authority.grantExpiresAt) <= expires)
201
+ return refuse('the grant does not outlive the five-minute challenge');
202
+ return transaction(db, true, () => {
203
+ requireExecutionJournalReady(db);
204
+ assertNoExecutionClaim(db, authority.userId);
205
+ db.prepare(`INSERT OR IGNORE INTO native_yield_consent_subjects
206
+ (user_id,account,generation,active_consent_id,updated_at_ms) VALUES (?,?,0,NULL,?)`)
207
+ .run(authority.userId, authority.account, nowMs);
208
+ const subject = readSubject(db, authority.userId, authority.account);
209
+ assertSubjectCoherent(db, subject);
210
+ if (nowMs < subject.updatedAtMs)
211
+ return refuse('the clock predates the current consent generation');
212
+ const terms = {
213
+ consentId: `nc_${randomUUID()}`, authority, generation: nextGeneration(subject),
214
+ createdAtMs: nowMs, challengeExpiresAtMs: expires,
215
+ };
216
+ const record = NATIVE_ACCOUNT_CONSENT_SCHEMA.parse({ ...terms, consentCommitment: commitment(terms), state: 'challenge', confirmedAtMs: null });
217
+ db.prepare(`INSERT INTO native_yield_consents
218
+ (consent_id,user_id,account,authority_json,consent_commitment,generation,state,created_at_ms,challenge_expires_at_ms,confirmed_at_ms)
219
+ VALUES (?,?,?,?,?,?,'challenge',?,?,NULL)`)
220
+ .run(record.consentId, authority.userId, authority.account, canonical(authority), record.consentCommitment, record.generation, nowMs, expires);
221
+ return immutable(record);
222
+ });
223
+ }
224
+ export function confirmNativeYieldConsent(db, rawInput, inputAuthority, nowMs) {
225
+ time(nowMs);
226
+ const input = CONFIRM_INPUT.parse(rawInput);
227
+ const authority = authorityTerms(inputAuthority);
228
+ if (input.userId !== authority.userId)
229
+ return refuse('the confirmation belongs to another subject');
230
+ assertGrantValid(authority, nowMs);
231
+ return transaction(db, true, () => {
232
+ requireExecutionJournalReady(db);
233
+ assertNoExecutionClaim(db, authority.userId);
234
+ const record = readRecord(db, input.consentId);
235
+ if (!record || record.authority.userId !== input.userId || record.authority.account !== authority.account ||
236
+ record.consentCommitment !== input.consentCommitment || canonical(record.authority) !== canonical(authority))
237
+ return refuse('the confirmation does not match the reviewed owner and authority');
238
+ const subject = readSubject(db, authority.userId, authority.account);
239
+ if (!subject)
240
+ return refuse('the challenge subject is missing');
241
+ const active = assertSubjectCoherent(db, subject);
242
+ if (nowMs < subject.updatedAtMs || nowMs < record.createdAtMs)
243
+ return refuse('the clock predates the consent');
244
+ if (record.state === 'confirmed') {
245
+ if (active?.consentId !== record.consentId)
246
+ return refuse('the consent is no longer active');
247
+ return record;
248
+ }
249
+ if (record.state !== 'challenge' || record.generation !== nextGeneration(subject))
250
+ return refuse('the challenge was superseded or revoked');
251
+ if (nowMs >= record.challengeExpiresAtMs)
252
+ return refuse('the five-minute challenge has expired');
253
+ if (active)
254
+ db.prepare("UPDATE native_yield_consents SET state='superseded' WHERE consent_id=? AND state='confirmed'").run(active.consentId);
255
+ const confirmed = db.prepare("UPDATE native_yield_consents SET state='confirmed',confirmed_at_ms=? WHERE consent_id=? AND state='challenge'")
256
+ .run(nowMs, record.consentId);
257
+ if (Number(confirmed.changes) !== 1)
258
+ return refuse('the challenge changed during confirmation');
259
+ db.prepare("UPDATE native_yield_consents SET state='superseded' WHERE user_id=? AND account=? AND state='challenge' AND generation<=?")
260
+ .run(authority.userId, authority.account, record.generation);
261
+ const changed = db.prepare(`UPDATE native_yield_consent_subjects SET generation=?,active_consent_id=?,updated_at_ms=?
262
+ WHERE user_id=? AND account=? AND generation=? AND active_consent_id IS ?`)
263
+ .run(record.generation, record.consentId, nowMs, authority.userId, authority.account, subject.generation, subject.activeConsentId);
264
+ if (Number(changed.changes) !== 1)
265
+ return refuse('the consent generation changed during confirmation');
266
+ return readRecord(db, record.consentId);
267
+ });
268
+ }
269
+ export function readConfirmedNativeYieldConsent(db, userId, account, nowMs) {
270
+ NATIVE_ACCOUNT_USER.parse(userId);
271
+ time(nowMs);
272
+ const address = accountAddress(account);
273
+ return transaction(db, false, () => {
274
+ const subject = readSubject(db, userId, address);
275
+ if (!subject)
276
+ return undefined;
277
+ const record = assertSubjectCoherent(db, subject);
278
+ if (!record || nowMs < subject.updatedAtMs || Date.parse(record.authority.grantExpiresAt) <= nowMs)
279
+ return undefined;
280
+ return record;
281
+ });
282
+ }
283
+ /** Read-only: safe inside the operation's claim transaction and again immediately before handoff. */
284
+ export function assertCurrentNativeYieldConsent(db, inputRecord, inputAuthority, nowMs) {
285
+ time(nowMs);
286
+ const record = NATIVE_ACCOUNT_CONSENT_SCHEMA.parse(inputRecord);
287
+ const authority = authorityTerms(inputAuthority);
288
+ assertGrantValid(authority, nowMs);
289
+ transaction(db, false, () => {
290
+ const active = readConfirmedNativeYieldConsent(db, authority.userId, authority.account, nowMs);
291
+ if (!active || record.state !== 'confirmed' || canonical(active) !== canonical(record) ||
292
+ canonical(active.authority) !== canonical(authority) || consentCommitment(record) !== record.consentCommitment)
293
+ refuse('the reviewed consent is no longer current for this owner and authority');
294
+ });
295
+ }
296
+ /** Stop remains available while a money operation is unresolved; it never releases that operation's claim. */
297
+ export function revokeNativeYieldConsent(db, userId, account, nowMs) {
298
+ NATIVE_ACCOUNT_USER.parse(userId);
299
+ time(nowMs);
300
+ const address = accountAddress(account);
301
+ transaction(db, true, () => {
302
+ db.prepare(`INSERT OR IGNORE INTO native_yield_consent_subjects
303
+ (user_id,account,generation,active_consent_id,updated_at_ms) VALUES (?,?,0,NULL,?)`).run(userId, address, nowMs);
304
+ const subject = readSubject(db, userId, address);
305
+ assertSubjectCoherent(db, subject);
306
+ if (nowMs < subject.updatedAtMs)
307
+ return refuse('the clock predates the current consent generation');
308
+ db.prepare("UPDATE native_yield_consents SET state='revoked' WHERE user_id=? AND account=? AND state IN ('challenge','confirmed')")
309
+ .run(userId, address);
310
+ const changed = db.prepare(`UPDATE native_yield_consent_subjects SET generation=?,active_consent_id=NULL,updated_at_ms=?
311
+ WHERE user_id=? AND account=? AND generation=? AND active_consent_id IS ?`)
312
+ .run(nextGeneration(subject), nowMs, userId, address, subject.generation, subject.activeConsentId);
313
+ if (Number(changed.changes) !== 1)
314
+ return refuse('the consent generation changed during revocation');
315
+ });
316
+ }
317
+ //# sourceMappingURL=native-yield-consent-store.js.map
@@ -0,0 +1,288 @@
1
+ /** Native yield contracts; separate from the existing LI.FI delegation envelope. */
2
+ import { z } from 'zod';
3
+ import { type Address, type Hex } from 'viem';
4
+ import type { HybridYieldMarket, HybridYieldChainId } from './hybrid-yield-markets.js';
5
+ export declare const NATIVE_YIELD_FEE_BPS: 10;
6
+ export declare const NATIVE_YIELD_FEE_RECIPIENT: `0x${string}`;
7
+ export declare const NATIVE_YIELD_FEE_VERSION = "native-yield-10bps-floor-v1";
8
+ export declare const NATIVE_YIELD_TTL_SECONDS = 180;
9
+ export declare const NATIVE_YIELD_STATE_MAX_AGE_MS = 60000;
10
+ export declare const NATIVE_YIELD_ROUTER_ABI: readonly [{
11
+ readonly name: "execute";
12
+ readonly type: "function";
13
+ readonly stateMutability: "nonpayable";
14
+ readonly inputs: readonly [{
15
+ readonly type: "bytes32";
16
+ readonly name: "marketId";
17
+ }, {
18
+ readonly type: "bool";
19
+ readonly name: "isDeposit";
20
+ }, {
21
+ readonly type: "uint256";
22
+ readonly name: "amount";
23
+ }, {
24
+ readonly type: "uint256";
25
+ readonly name: "minOutput";
26
+ }, {
27
+ readonly type: "uint256";
28
+ readonly name: "nonce";
29
+ }, {
30
+ readonly type: "uint256";
31
+ readonly name: "deadline";
32
+ }];
33
+ readonly outputs: readonly [{
34
+ readonly type: "uint256";
35
+ readonly name: "outputAmount";
36
+ }];
37
+ }, {
38
+ readonly name: "nonces";
39
+ readonly type: "function";
40
+ readonly stateMutability: "view";
41
+ readonly inputs: readonly [{
42
+ readonly type: "address";
43
+ readonly name: "owner";
44
+ }];
45
+ readonly outputs: readonly [{
46
+ readonly type: "uint256";
47
+ }];
48
+ }, {
49
+ readonly name: "marketConfig";
50
+ readonly type: "function";
51
+ readonly stateMutability: "view";
52
+ readonly inputs: readonly [{
53
+ readonly type: "bytes32";
54
+ readonly name: "marketId";
55
+ }];
56
+ readonly outputs: readonly [{
57
+ readonly type: "uint8";
58
+ readonly name: "protocol";
59
+ }, {
60
+ readonly type: "address";
61
+ readonly name: "asset";
62
+ }, {
63
+ readonly type: "address";
64
+ readonly name: "position";
65
+ }, {
66
+ readonly type: "address";
67
+ readonly name: "target";
68
+ }, {
69
+ readonly type: "bool";
70
+ readonly name: "depositEnabled";
71
+ }];
72
+ }, {
73
+ readonly name: "YieldExecuted";
74
+ readonly type: "event";
75
+ readonly inputs: readonly [{
76
+ readonly type: "address";
77
+ readonly name: "owner";
78
+ readonly indexed: true;
79
+ }, {
80
+ readonly type: "bytes32";
81
+ readonly name: "marketId";
82
+ readonly indexed: true;
83
+ }, {
84
+ readonly type: "uint256";
85
+ readonly name: "nonce";
86
+ readonly indexed: true;
87
+ }, {
88
+ readonly type: "bool";
89
+ readonly name: "isDeposit";
90
+ }, {
91
+ readonly type: "uint256";
92
+ readonly name: "inputAmount";
93
+ }, {
94
+ readonly type: "uint256";
95
+ readonly name: "outputAmount";
96
+ }, {
97
+ readonly type: "uint256";
98
+ readonly name: "feeAmount";
99
+ }];
100
+ }];
101
+ export declare const NATIVE_YIELD_ERC20_ABI: readonly [{
102
+ readonly name: "approve";
103
+ readonly type: "function";
104
+ readonly stateMutability: "nonpayable";
105
+ readonly inputs: readonly [{
106
+ readonly type: "address";
107
+ readonly name: "spender";
108
+ }, {
109
+ readonly type: "uint256";
110
+ readonly name: "amount";
111
+ }];
112
+ readonly outputs: readonly [{
113
+ readonly type: "bool";
114
+ }];
115
+ }, {
116
+ readonly name: "allowance";
117
+ readonly type: "function";
118
+ readonly stateMutability: "view";
119
+ readonly inputs: readonly [{
120
+ readonly type: "address";
121
+ readonly name: "owner";
122
+ }, {
123
+ readonly type: "address";
124
+ readonly name: "spender";
125
+ }];
126
+ readonly outputs: readonly [{
127
+ readonly type: "uint256";
128
+ }];
129
+ }, {
130
+ readonly name: "balanceOf";
131
+ readonly type: "function";
132
+ readonly stateMutability: "view";
133
+ readonly inputs: readonly [{
134
+ readonly type: "address";
135
+ readonly name: "owner";
136
+ }];
137
+ readonly outputs: readonly [{
138
+ readonly type: "uint256";
139
+ }];
140
+ }, {
141
+ readonly name: "decimals";
142
+ readonly type: "function";
143
+ readonly stateMutability: "view";
144
+ readonly inputs: readonly [];
145
+ readonly outputs: readonly [{
146
+ readonly type: "uint8";
147
+ }];
148
+ }, {
149
+ readonly name: "totalSupply";
150
+ readonly type: "function";
151
+ readonly stateMutability: "view";
152
+ readonly inputs: readonly [];
153
+ readonly outputs: readonly [{
154
+ readonly type: "uint256";
155
+ }];
156
+ }, {
157
+ readonly name: "Transfer";
158
+ readonly type: "event";
159
+ readonly inputs: readonly [{
160
+ readonly type: "address";
161
+ readonly name: "from";
162
+ readonly indexed: true;
163
+ }, {
164
+ readonly type: "address";
165
+ readonly name: "to";
166
+ readonly indexed: true;
167
+ }, {
168
+ readonly type: "uint256";
169
+ readonly name: "value";
170
+ }];
171
+ }];
172
+ export declare const PREPARE_NATIVE_YIELD_INPUT_SCHEMA: z.ZodObject<{
173
+ accountProfile: z.ZodObject<{
174
+ kind: z.ZodLiteral<"eoa">;
175
+ address: z.ZodString;
176
+ chainId: z.ZodUnion<readonly [z.ZodLiteral<8453>, z.ZodLiteral<42161>]>;
177
+ }, z.core.$strict>;
178
+ marketId: z.ZodString;
179
+ registryCommitment: z.ZodString;
180
+ action: z.ZodEnum<{
181
+ deposit: "deposit";
182
+ withdraw: "withdraw";
183
+ }>;
184
+ amount: z.ZodString;
185
+ slippage: z.ZodObject<{
186
+ maxBps: z.ZodNumber;
187
+ minOutput: z.ZodOptional<z.ZodString>;
188
+ }, z.core.$strict>;
189
+ clientRef: z.ZodOptional<z.ZodString>;
190
+ }, z.core.$strict>;
191
+ export type PrepareNativeYieldInput = z.infer<typeof PREPARE_NATIVE_YIELD_INPUT_SCHEMA>;
192
+ export declare const NATIVE_YIELD_DEPLOYMENT_SCHEMA: z.ZodObject<{
193
+ chainId: z.ZodUnion<readonly [z.ZodLiteral<8453>, z.ZodLiteral<42161>]>;
194
+ address: z.ZodString;
195
+ runtimeCodeHash: z.ZodString;
196
+ version: z.ZodLiteral<"native-yield-router-v1">;
197
+ reviewId: z.ZodString;
198
+ }, z.core.$strict>;
199
+ export type NativeYieldDeployment = z.infer<typeof NATIVE_YIELD_DEPLOYMENT_SCHEMA>;
200
+ /**
201
+ * Deliberately empty. No address/environment variable can activate a new spend
202
+ * target. Fill only in a separately approved exact-deployment review.
203
+ */
204
+ export declare const NATIVE_YIELD_DEPLOYMENTS: readonly NativeYieldDeployment[];
205
+ export interface NativeYieldState {
206
+ readonly chainId: HybridYieldChainId;
207
+ readonly marketId: string;
208
+ readonly owner: Address;
209
+ readonly blockNumber: bigint;
210
+ readonly blockHash: Hex;
211
+ readonly blockTimestampMs: number;
212
+ readonly observedAtMs: number;
213
+ readonly routerNonce: bigint;
214
+ readonly inputBalance: bigint;
215
+ readonly inputAllowance: bigint;
216
+ readonly positionBalance: bigint;
217
+ readonly assetBalance: bigint;
218
+ readonly nativeBalance: bigint;
219
+ readonly maxInput: bigint;
220
+ /** Deposit: net aToken/shares after fee. Withdraw: gross underlying before fee. */
221
+ readonly protocolOutput: bigint;
222
+ }
223
+ export interface NativeYieldReader {
224
+ read(market: HybridYieldMarket, owner: Address, action: 'deposit' | 'withdraw', amount: bigint, deployment: NativeYieldDeployment): Promise<NativeYieldState>;
225
+ }
226
+ export declare const NATIVE_YIELD_PLAN_SCHEMA: z.ZodObject<{
227
+ schemaVersion: z.ZodLiteral<"1">;
228
+ kind: z.ZodLiteral<"native-yield-plan">;
229
+ transport: z.ZodLiteral<"native-protocol">;
230
+ marketId: z.ZodString;
231
+ registryCommitment: z.ZodString;
232
+ owner: z.ZodString;
233
+ chainId: z.ZodUnion<readonly [z.ZodLiteral<8453>, z.ZodLiteral<42161>]>;
234
+ action: z.ZodEnum<{
235
+ deposit: "deposit";
236
+ withdraw: "withdraw";
237
+ }>;
238
+ amount: z.ZodString;
239
+ inputToken: z.ZodString;
240
+ outputToken: z.ZodString;
241
+ expectedOutput: z.ZodString;
242
+ minimumOutput: z.ZodString;
243
+ protocolOutput: z.ZodString;
244
+ fee: z.ZodObject<{
245
+ bps: z.ZodLiteral<10>;
246
+ recipient: z.ZodString;
247
+ token: z.ZodString;
248
+ amount: z.ZodString;
249
+ version: z.ZodLiteral<"native-yield-10bps-floor-v1">;
250
+ rounding: z.ZodLiteral<"floor">;
251
+ }, z.core.$strict>;
252
+ nonce: z.ZodString;
253
+ deadline: z.ZodNumber;
254
+ preparedAtMs: z.ZodNumber;
255
+ snapshot: z.ZodObject<{
256
+ blockNumber: z.ZodString;
257
+ blockHash: z.ZodString;
258
+ observedAtMs: z.ZodNumber;
259
+ }, z.core.$strict>;
260
+ deployment: z.ZodObject<{
261
+ chainId: z.ZodUnion<readonly [z.ZodLiteral<8453>, z.ZodLiteral<42161>]>;
262
+ address: z.ZodString;
263
+ runtimeCodeHash: z.ZodString;
264
+ version: z.ZodLiteral<"native-yield-router-v1">;
265
+ reviewId: z.ZodString;
266
+ }, z.core.$strict>;
267
+ steps: z.ZodArray<z.ZodObject<{
268
+ kind: z.ZodEnum<{
269
+ approve: "approve";
270
+ approve_reset: "approve_reset";
271
+ call: "call";
272
+ }>;
273
+ to: z.ZodString;
274
+ value: z.ZodLiteral<"0">;
275
+ data: z.ZodString;
276
+ }, z.core.$strict>>;
277
+ authorization: z.ZodLiteral<"requires-separate-account-authority">;
278
+ allowanceRecovery: z.ZodLiteral<"approval-is-separate-and-may-remain-after-failure">;
279
+ intentCommitment: z.ZodString;
280
+ planCommitment: z.ZodString;
281
+ }, z.core.$strict>;
282
+ export type NativeYieldPlan = z.infer<typeof NATIVE_YIELD_PLAN_SCHEMA>;
283
+ export declare function nativeYieldFee(gross: bigint): bigint;
284
+ export declare class NativeYieldRefusal extends Error {
285
+ readonly code: string;
286
+ constructor(code: string, message: string);
287
+ }
288
+ export declare function refuseNative(code: string, message: string): never;