otto-intel-mcp 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/adapter/cdp-signer.d.ts +44 -5
- package/dist/adapter/cdp-signer.js +168 -18
- package/dist/adapter/evm-call-failure.d.ts +29 -0
- package/dist/adapter/evm-call-failure.js +109 -0
- package/dist/adapter/refusal.d.ts +1 -1
- package/dist/adapter/refusal.js +13 -0
- package/dist/adapter/route-simulator.d.ts +91 -0
- package/dist/adapter/route-simulator.js +143 -0
- package/dist/executable-equities.d.ts +55 -0
- package/dist/executable-equities.js +116 -0
- package/dist/executable-yield-markets.d.ts +261 -0
- package/dist/executable-yield-markets.js +154 -0
- package/dist/execution-delegated-definition.d.ts +1 -0
- package/dist/execution-delegated-definition.js +13 -2
- package/dist/execution-delegation-admin-definition.d.ts +126 -5
- package/dist/execution-delegation-admin-definition.js +154 -5
- package/dist/execution-delegation-admin.d.ts +48 -2
- package/dist/execution-delegation-admin.js +314 -12
- package/dist/execution-delegation-cap-store.d.ts +369 -0
- package/dist/execution-delegation-cap-store.js +1083 -0
- package/dist/execution-delegation-policy.d.ts +153 -6
- package/dist/execution-delegation-policy.js +260 -16
- package/dist/execution-delegation.d.ts +35 -0
- package/dist/execution-delegation.js +224 -9
- package/dist/execution-errors.d.ts +1 -1
- package/dist/execution-errors.js +98 -0
- package/dist/execution-index.d.ts +3 -2
- package/dist/execution-index.js +3 -2
- package/dist/execution-registration.d.ts +51 -2
- package/dist/execution-registration.js +45 -2
- package/dist/execution-tools.d.ts +44 -1
- package/dist/execution-tools.js +157 -13
- package/dist/lifi-execution-client.d.ts +6 -0
- package/dist/lifi-execution-client.js +3 -0
- package/dist/stock-buy-definition.d.ts +338 -0
- package/dist/stock-buy-definition.js +127 -0
- package/dist/stock-buy-oracle.d.ts +8 -0
- package/dist/stock-buy-oracle.js +22 -0
- package/dist/stock-buy.d.ts +17 -0
- package/dist/stock-buy.js +164 -0
- package/dist/tool-definitions.js +1 -1
- package/dist/yield-deposit-definition.d.ts +323 -0
- package/dist/yield-deposit-definition.js +121 -0
- package/dist/yield-deposit.d.ts +16 -0
- package/dist/yield-deposit.js +141 -0
- package/dist/yield-withdraw-definition.d.ts +306 -0
- package/dist/yield-withdraw-definition.js +88 -0
- package/dist/yield-withdraw.d.ts +21 -0
- package/dist/yield-withdraw.js +120 -0
- package/package.json +28 -4
|
@@ -37,10 +37,30 @@ import { type Address } from 'viem';
|
|
|
37
37
|
* the prefix in the middle, a suffix, no description — is foreign and is never touched.
|
|
38
38
|
*/
|
|
39
39
|
export declare const MODEL_B_POLICY_LINEAGE_PREFIX = "OTTO model b swap fence";
|
|
40
|
-
/**
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
/**
|
|
41
|
+
* This binary's fence version. Bump it whenever the rules change shape or caps.
|
|
42
|
+
*
|
|
43
|
+
* 🔴 v2 (Founder word `fence v2`, pending — Yield Copilot withdraw, 2026-09-03). v2 ADDS to v1: an approve
|
|
44
|
+
* rule per registry Morpho share token (spender = the diamond only, bounded by
|
|
45
|
+
* `MODEL_B_WITHDRAW_SHARE_CAP_ATOMIC`) so a delegated vault WITHDRAW can route shares → USDC through the
|
|
46
|
+
* same fenced GenericSwapV3 entry, and a sign-only accept rule for a USDC `transfer` (see
|
|
47
|
+
* `modelBProjectPolicyRules`). The router rule is UNCHANGED and still carries no receiver condition — that
|
|
48
|
+
* is the person's only way to move value out of an Otto/CDP wallet today (ws-7, 2026-09-03), and the
|
|
49
|
+
* receiver pin lives in Otto's delegated verifier.
|
|
50
|
+
*
|
|
51
|
+
* TRANSITION: a v2 binary ACCEPTS a v1 fence (swaps and deposits keep working; a withdraw under v1 is
|
|
52
|
+
* refused by name) and the fence tool upgrades v1 → v2 in place only when it is run — deploying this code
|
|
53
|
+
* writes nothing to the CDP project.
|
|
54
|
+
*/
|
|
55
|
+
export declare const MODEL_B_POLICY_VERSION: 2;
|
|
56
|
+
/** The v1 match key — the fence every permission before `fence v2` was minted under; still accepted for swaps and deposits. */
|
|
57
|
+
export declare const MODEL_B_POLICY_NAME_V1: "OTTO model b swap fence v1";
|
|
58
|
+
/** The v2 match key — what the fence tool writes; the only fence that admits a delegated Yield Copilot withdraw. */
|
|
59
|
+
export declare const MODEL_B_POLICY_NAME_V2: string;
|
|
60
|
+
/** The CURRENT match key (v2). */
|
|
61
|
+
export declare const MODEL_B_POLICY_NAME: string;
|
|
62
|
+
/** Every lineage version this binary accepts on read-back, oldest first. */
|
|
63
|
+
export declare const MODEL_B_POLICY_ACCEPTED_VERSIONS: readonly (1 | 2)[];
|
|
44
64
|
/** The lineage version N of a policy description, or undefined when the description is not of our lineage. */
|
|
45
65
|
export declare function modelBLineageVersion(description: unknown): number | undefined;
|
|
46
66
|
export declare const MODEL_B_POLICY_NETWORK: "base";
|
|
@@ -53,19 +73,63 @@ export declare const MODEL_B_CHAIN_ID: 8453;
|
|
|
53
73
|
*/
|
|
54
74
|
export declare const MODEL_B_DELEGATION_EXPIRY_DEFAULT_DAYS: 90;
|
|
55
75
|
export declare const MODEL_B_DELEGATION_EXPIRY_MAX_DAYS: 180;
|
|
56
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* The floor `boundedDelegationExpiry` has always enforced, NAMED — it was a literal `1` inside the bound,
|
|
78
|
+
* so the reserve schema could not state the range it accepts without hand-copying the number, and a
|
|
79
|
+
* hand-copied bound is a bound that drifts. Mirrors `MODEL_B_DELEGATION_EXPIRY_MIN_DAYS` in the dApp.
|
|
80
|
+
*/
|
|
81
|
+
export declare const MODEL_B_DELEGATION_EXPIRY_MIN_DAYS: 1;
|
|
82
|
+
/**
|
|
83
|
+
* A requested expiry, bounded: a hostile, absent or over-long value never reaches the mint.
|
|
84
|
+
*
|
|
85
|
+
* 🔴 THE RESULT LANDS ON A WHOLE SECOND (round 3). CDP stores `expiresAt` at whole-second granularity and
|
|
86
|
+
* truncates milliseconds toward zero — verified live on the dev project 2026-09-02 (`…:46.137Z` came back
|
|
87
|
+
* as `…:46Z` from `createDelegation` AND from `getDelegationForEndUser`; `…:45.999Z` came back as
|
|
88
|
+
* `…:45Z`, so it truncates rather than rounds). Everything downstream — the reservation, the durable row
|
|
89
|
+
* and every enforcement read — keys on that second, so the bound produces it directly rather than leaving
|
|
90
|
+
* a millisecond remainder for one of them to drop and another to keep.
|
|
91
|
+
*/
|
|
57
92
|
export declare function boundedDelegationExpiry(requestedDays: unknown, nowMs: number): {
|
|
58
93
|
readonly days: number;
|
|
59
94
|
readonly expiresAt: string;
|
|
60
95
|
};
|
|
96
|
+
/**
|
|
97
|
+
* The mint-expiry helpers live with the store that owns the reserved second; re-exported here because
|
|
98
|
+
* this is the module every consumer of the Model-B numbers already imports.
|
|
99
|
+
*/
|
|
100
|
+
export { MINT_EXPIRY_FILLER_MS as MODEL_B_MINT_EXPIRY_FILLER_MS } from './execution-delegation-cap-store.js';
|
|
101
|
+
export { mintExpiryForSecond as mintExpiryFor } from './execution-delegation-cap-store.js';
|
|
102
|
+
export { MODEL_B_CAP_RULESET_VERSION } from './execution-delegation-cap-store.js';
|
|
61
103
|
/**
|
|
62
104
|
* The per-swap cap in USD — the Founder's number (word `fence cap 5000`, 2026-08-29). It bounds ONE swap:
|
|
63
105
|
* the engine carries no daily or total limit, and no copy may imply one. Changing it = a new fence version.
|
|
64
106
|
* Engine conditions are on raw calldata, so the cap is expressed per allowed input token: v1 allows USDC
|
|
65
107
|
* only, where the mapping is exact (5,000 USD = 5,000,000,000 atomic on the approve amount, which is what
|
|
66
108
|
* bounds the swap's `fromAmount` on-chain).
|
|
109
|
+
*
|
|
110
|
+
* 🔴 THIS IS THE CEILING, SHARED BY EVERY DELEGATED USER — NOT ANY ONE PERSON'S CAP (Founder word
|
|
111
|
+
* `delegate cap choice`, 2026-09-02). Coinbase's engine offers end-user accounts exactly one fence, the
|
|
112
|
+
* project-scope policy, so the number compiled into those rules is the same for everybody and CANNOT be
|
|
113
|
+
* narrowed per user by the engine. A person who wants a lower number — "try it with $10" — gets it from
|
|
114
|
+
* Otto's own server: their choice is recorded against their grant (`execution-delegation-cap-store.ts`)
|
|
115
|
+
* and enforced on every delegated send, on top of this ceiling and never above it.
|
|
67
116
|
*/
|
|
68
117
|
export declare const MODEL_B_PER_SWAP_CAP_USD: 5000;
|
|
118
|
+
/**
|
|
119
|
+
* The floor of the range a person may choose. One whole dollar: the smallest cap that can still pass a
|
|
120
|
+
* real swap, and low enough that "try it with $10" is nowhere near it.
|
|
121
|
+
*/
|
|
122
|
+
export declare const MODEL_B_PER_SWAP_CAP_MIN_USD: 1;
|
|
123
|
+
/**
|
|
124
|
+
* A requested per-swap cap, bounded — the same shape as `boundedDelegationExpiry`, and the ONLY place a
|
|
125
|
+
* requested number becomes a cap.
|
|
126
|
+
*
|
|
127
|
+
* 🔴 IT REFUSES; IT NEVER CLAMPS. A hostile 50,000 is not silently turned into 5,000: a caller that asked
|
|
128
|
+
* for a number outside the range is a caller whose intent this server does not know, and quietly
|
|
129
|
+
* substituting one would make "the cap you chose" a claim nobody could check. Absent means the ceiling —
|
|
130
|
+
* the terms every grant already carried before a choice existed.
|
|
131
|
+
*/
|
|
132
|
+
export declare function boundedPerSwapCap(requestedUsd: unknown): number;
|
|
69
133
|
export interface ModelBInputToken {
|
|
70
134
|
readonly symbol: string;
|
|
71
135
|
readonly address: Address;
|
|
@@ -80,6 +144,28 @@ export declare const BASE_USDC: Address;
|
|
|
80
144
|
*/
|
|
81
145
|
export declare const MODEL_B_INPUT_TOKENS_V1: readonly ModelBInputToken[];
|
|
82
146
|
export declare function modelBInputToken(token: Address): ModelBInputToken | undefined;
|
|
147
|
+
/**
|
|
148
|
+
* 🔴 v2 — the share tokens a delegated Yield Copilot WITHDRAW may approve to the diamond: exactly the
|
|
149
|
+
* registry's executable Morpho vaults (ERC-4626 shares, 18 decimals), derived from the registry so a vault
|
|
150
|
+
* added or removed there changes the fence shape (= a new digest) rather than drifting past it.
|
|
151
|
+
*/
|
|
152
|
+
export interface ModelBWithdrawToken {
|
|
153
|
+
readonly symbol: string;
|
|
154
|
+
readonly address: Address;
|
|
155
|
+
readonly decimals: 18;
|
|
156
|
+
readonly marketId: string;
|
|
157
|
+
}
|
|
158
|
+
export declare const MODEL_B_WITHDRAW_TOKENS_V2: readonly ModelBWithdrawToken[];
|
|
159
|
+
export declare function modelBWithdrawToken(token: Address): ModelBWithdrawToken | undefined;
|
|
160
|
+
/**
|
|
161
|
+
* The engine-side bound on ONE withdraw's approve, in share atomic units: 5,000 shares. A USDC vault's
|
|
162
|
+
* share is worth ≥ 1 USDC by construction at inception and accrues from there (gtUSDCp ≈ 1.107 USDC on
|
|
163
|
+
* 2026-09-03), so 5,000 shares ≈ the 5,000 USD per-swap ceiling at par and somewhat more as yield accrues;
|
|
164
|
+
* after a vault loss the bound only tightens. It is the residual bound for a re-pointed withdraw, the same
|
|
165
|
+
* class as the swap rule's; the person's own cap does NOT apply to a withdraw (see the send gate: a withdraw
|
|
166
|
+
* returns the person's own assets to the person and never increases exposure).
|
|
167
|
+
*/
|
|
168
|
+
export declare const MODEL_B_WITHDRAW_SHARE_CAP_ATOMIC: bigint;
|
|
83
169
|
/** The cap in the token's atomic units. */
|
|
84
170
|
export declare function modelBPerSwapCapAtomic(token: ModelBInputToken, capUsd?: number): bigint;
|
|
85
171
|
/** The two GenericSwapV3 ERC20→ERC20 entry points a same-chain swap plan may call. */
|
|
@@ -206,10 +292,26 @@ export type DelegationPolicyCriterion = {
|
|
|
206
292
|
};
|
|
207
293
|
export interface DelegationPolicyRule {
|
|
208
294
|
readonly action: 'accept';
|
|
209
|
-
|
|
295
|
+
/** `sendEndUserEvmTransaction` = the delegated send; `signEndUserEvmTransaction` (v2) = sign-only, the client broadcasts. */
|
|
296
|
+
readonly operation: 'sendEndUserEvmTransaction' | 'signEndUserEvmTransaction';
|
|
210
297
|
readonly criteria: readonly DelegationPolicyCriterion[];
|
|
211
298
|
}
|
|
212
299
|
/** The static v1 rules: one approve rule per allow-listed input token, one router rule. */
|
|
300
|
+
/** The v1 rules, frozen as history: USDC approve to the diamond up to the cap + the router rule. */
|
|
301
|
+
export declare function modelBProjectPolicyRulesV1(capUsd?: number): readonly DelegationPolicyRule[];
|
|
302
|
+
/**
|
|
303
|
+
* The v2 rules = v1 + (a) one approve rule per registry Morpho share token, spender = the diamond only,
|
|
304
|
+
* value ≤ `MODEL_B_WITHDRAW_SHARE_CAP_ATOMIC`, ethValue 0 — the delegated withdraw's allowance leg; the
|
|
305
|
+
* router rule is UNCHANGED (no receiver condition; the person's exit path); (b) a SIGN-ONLY accept rule
|
|
306
|
+
* (`signEndUserEvmTransaction`) for a USDC `transfer(to, value)` with value ≤ the per-swap cap and NO
|
|
307
|
+
* recipient condition — the person's own USDC exit without a swap, signed in their browser and broadcast
|
|
308
|
+
* by the page. The CDP policy schema carries no initiator/session criterion, so the engine cannot tell a
|
|
309
|
+
* user-signed send from a delegated one on the SAME operation; what it can do is fence a DIFFERENT
|
|
310
|
+
* operation, and Otto's delegated signer only ever calls the send operation (`adapter/cdp-signer.ts`).
|
|
311
|
+
* Stated residual: the developer-side end-user client also exposes `signEvmTransaction`, so under a
|
|
312
|
+
* delegation a compromised Otto could sign a USDC transfer to any address up to the cap — the same
|
|
313
|
+
* class and bound as the router rule's missing receiver condition, not a new one.
|
|
314
|
+
*/
|
|
213
315
|
export declare function modelBProjectPolicyRules(capUsd?: number): readonly DelegationPolicyRule[];
|
|
214
316
|
/** The body PR-2's installer creates or updates: scope, versioned description, the v1 rules. */
|
|
215
317
|
export declare function modelBProjectPolicyBody(): {
|
|
@@ -220,6 +322,14 @@ export declare function modelBProjectPolicyBody(): {
|
|
|
220
322
|
/** SHA-256 over the canonical JSON of a rule list — the fence's integrity check at read-back. */
|
|
221
323
|
export declare function policyRulesDigest(rules: unknown): string;
|
|
222
324
|
export declare const MODEL_B_POLICY_DIGEST_V1: string;
|
|
325
|
+
export declare const MODEL_B_POLICY_DIGEST_V2: string;
|
|
326
|
+
/** The CURRENT digest (v2). */
|
|
327
|
+
export declare const MODEL_B_POLICY_DIGEST: string;
|
|
328
|
+
/** name → {version, digest} for every accepted lineage version. */
|
|
329
|
+
export declare const MODEL_B_POLICY_DIGEST_BY_NAME: ReadonlyMap<string, {
|
|
330
|
+
readonly version: 1 | 2;
|
|
331
|
+
readonly digest: string;
|
|
332
|
+
}>;
|
|
223
333
|
/** What the server reads back from `cdp.policies.listPolicies({ scope: 'project' })`, structurally. */
|
|
224
334
|
export interface DelegationPolicyRecord {
|
|
225
335
|
readonly id: string;
|
|
@@ -231,6 +341,9 @@ export type ModelBFenceReadBack = {
|
|
|
231
341
|
readonly present: true;
|
|
232
342
|
readonly id: string;
|
|
233
343
|
readonly rulesDigest: string;
|
|
344
|
+
/** Which accepted lineage version reads back; a delegated withdraw needs 2. */
|
|
345
|
+
readonly version: 1 | 2;
|
|
346
|
+
readonly name: string;
|
|
234
347
|
} | {
|
|
235
348
|
readonly present: false;
|
|
236
349
|
readonly reason: 'absent' | 'ambiguous' | 'name_mismatch' | 'digest_mismatch';
|
|
@@ -243,6 +356,8 @@ export type ModelBFenceReadBack = {
|
|
|
243
356
|
* "absent" — including a policy of the right name whose rules drifted.
|
|
244
357
|
*/
|
|
245
358
|
export declare function readBackModelBFence(policies: readonly DelegationPolicyRecord[]): ModelBFenceReadBack;
|
|
359
|
+
/** True when the read-back is THIS binary's fence version — what the fence tool leaves alone. */
|
|
360
|
+
export declare function fenceIsCurrent(readBack: ModelBFenceReadBack): boolean;
|
|
246
361
|
/**
|
|
247
362
|
* The same bound the engine enforces, checked server-side BEFORE the first step is sent: a plan the
|
|
248
363
|
* engine would refuse is refused here without spending an allowance reset on it.
|
|
@@ -255,3 +370,35 @@ export declare function assertWithinModelBFence(plan: {
|
|
|
255
370
|
readonly token: ModelBInputToken;
|
|
256
371
|
readonly capAtomic: bigint;
|
|
257
372
|
};
|
|
373
|
+
/**
|
|
374
|
+
* 🔴 v2 — the delegated WITHDRAW's fence: the approve token must be a registry share token, the spender the
|
|
375
|
+
* diamond, the approve amount within the share cap, and the OUTPUT token USDC (a withdraw is "shares → the
|
|
376
|
+
* person's USDC", never a swap into something else under the withdraw's cap-free rule). The receiver pin
|
|
377
|
+
* (== the signing account) is the verifier's, already applied before this runs.
|
|
378
|
+
*/
|
|
379
|
+
export declare function assertWithdrawWithinModelBFence(plan: {
|
|
380
|
+
readonly token: Address;
|
|
381
|
+
readonly spender: Address;
|
|
382
|
+
readonly gross: bigint;
|
|
383
|
+
readonly outputToken: Address;
|
|
384
|
+
}): {
|
|
385
|
+
readonly token: ModelBWithdrawToken;
|
|
386
|
+
};
|
|
387
|
+
/**
|
|
388
|
+
* THE PERSON'S OWN CAP, enforced after the engine's (Founder word `delegate cap choice`, 2026-09-02).
|
|
389
|
+
*
|
|
390
|
+
* 🔴 WHY THIS IS A SEPARATE CHECK AND A SEPARATE CODE. `assertWithinModelBFence` above answers "would
|
|
391
|
+
* Coinbase's engine have signed this?" — it is the shared ceiling and it is also enforced on-chain by the
|
|
392
|
+
* project policy, so a plan past it never reaches a signature whatever this server does. THIS check
|
|
393
|
+
* answers a different question: "is it inside the number THIS PERSON chose when they minted?" The engine
|
|
394
|
+
* cannot ask it (one project policy, shared by every delegated user), so Otto's server is the only place
|
|
395
|
+
* it can be asked, and a plan that fails it is one the engine WOULD have signed.
|
|
396
|
+
*
|
|
397
|
+
* Folding the two into one call with a smaller number would pass every shape-level test while making the
|
|
398
|
+
* two facts indistinguishable in the refusal, in the logs and in the tests. They are kept apart so a
|
|
399
|
+
* mutation that drops the user's cap reddens on its own named code rather than hiding behind the ceiling.
|
|
400
|
+
*/
|
|
401
|
+
export declare function assertWithinUserPerSwapCap(grossAtomic: bigint, capUsd: number, token: ModelBInputToken): {
|
|
402
|
+
readonly capUsd: number;
|
|
403
|
+
readonly capAtomic: bigint;
|
|
404
|
+
};
|
|
@@ -33,6 +33,7 @@ import { createHash } from 'node:crypto';
|
|
|
33
33
|
import { getAddress } from 'viem';
|
|
34
34
|
import { refuse } from './execution-errors.js';
|
|
35
35
|
import { LIFI_DIAMOND_ADDRESS } from './execution-config.js';
|
|
36
|
+
import { EXECUTABLE_YIELD_MARKETS } from './executable-yield-markets.js';
|
|
36
37
|
/**
|
|
37
38
|
* The LINEAGE: a project policy is Otto's own only when its description matches the ANCHORED pattern
|
|
38
39
|
* `^OTTO model b swap fence v<N>$` (`modelBLineageVersion` returns N). The fence tool updates a lineage policy
|
|
@@ -40,10 +41,30 @@ import { LIFI_DIAMOND_ADDRESS } from './execution-config.js';
|
|
|
40
41
|
* the prefix in the middle, a suffix, no description — is foreign and is never touched.
|
|
41
42
|
*/
|
|
42
43
|
export const MODEL_B_POLICY_LINEAGE_PREFIX = 'OTTO model b swap fence';
|
|
43
|
-
/**
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
/**
|
|
45
|
+
* This binary's fence version. Bump it whenever the rules change shape or caps.
|
|
46
|
+
*
|
|
47
|
+
* 🔴 v2 (Founder word `fence v2`, pending — Yield Copilot withdraw, 2026-09-03). v2 ADDS to v1: an approve
|
|
48
|
+
* rule per registry Morpho share token (spender = the diamond only, bounded by
|
|
49
|
+
* `MODEL_B_WITHDRAW_SHARE_CAP_ATOMIC`) so a delegated vault WITHDRAW can route shares → USDC through the
|
|
50
|
+
* same fenced GenericSwapV3 entry, and a sign-only accept rule for a USDC `transfer` (see
|
|
51
|
+
* `modelBProjectPolicyRules`). The router rule is UNCHANGED and still carries no receiver condition — that
|
|
52
|
+
* is the person's only way to move value out of an Otto/CDP wallet today (ws-7, 2026-09-03), and the
|
|
53
|
+
* receiver pin lives in Otto's delegated verifier.
|
|
54
|
+
*
|
|
55
|
+
* TRANSITION: a v2 binary ACCEPTS a v1 fence (swaps and deposits keep working; a withdraw under v1 is
|
|
56
|
+
* refused by name) and the fence tool upgrades v1 → v2 in place only when it is run — deploying this code
|
|
57
|
+
* writes nothing to the CDP project.
|
|
58
|
+
*/
|
|
59
|
+
export const MODEL_B_POLICY_VERSION = 2;
|
|
60
|
+
/** The v1 match key — the fence every permission before `fence v2` was minted under; still accepted for swaps and deposits. */
|
|
61
|
+
export const MODEL_B_POLICY_NAME_V1 = `${MODEL_B_POLICY_LINEAGE_PREFIX} v1`;
|
|
62
|
+
/** The v2 match key — what the fence tool writes; the only fence that admits a delegated Yield Copilot withdraw. */
|
|
63
|
+
export const MODEL_B_POLICY_NAME_V2 = `${MODEL_B_POLICY_LINEAGE_PREFIX} v${MODEL_B_POLICY_VERSION}`;
|
|
64
|
+
/** The CURRENT match key (v2). */
|
|
65
|
+
export const MODEL_B_POLICY_NAME = MODEL_B_POLICY_NAME_V2;
|
|
66
|
+
/** Every lineage version this binary accepts on read-back, oldest first. */
|
|
67
|
+
export const MODEL_B_POLICY_ACCEPTED_VERSIONS = Object.freeze([1, 2]);
|
|
47
68
|
const MODEL_B_LINEAGE_PATTERN = new RegExp(`^${MODEL_B_POLICY_LINEAGE_PREFIX.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')} v(\\d+)$`);
|
|
48
69
|
/** The lineage version N of a policy description, or undefined when the description is not of our lineage. */
|
|
49
70
|
export function modelBLineageVersion(description) {
|
|
@@ -62,24 +83,81 @@ export const MODEL_B_CHAIN_ID = 8453;
|
|
|
62
83
|
*/
|
|
63
84
|
export const MODEL_B_DELEGATION_EXPIRY_DEFAULT_DAYS = 90;
|
|
64
85
|
export const MODEL_B_DELEGATION_EXPIRY_MAX_DAYS = 180;
|
|
65
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* The floor `boundedDelegationExpiry` has always enforced, NAMED — it was a literal `1` inside the bound,
|
|
88
|
+
* so the reserve schema could not state the range it accepts without hand-copying the number, and a
|
|
89
|
+
* hand-copied bound is a bound that drifts. Mirrors `MODEL_B_DELEGATION_EXPIRY_MIN_DAYS` in the dApp.
|
|
90
|
+
*/
|
|
91
|
+
export const MODEL_B_DELEGATION_EXPIRY_MIN_DAYS = 1;
|
|
92
|
+
/**
|
|
93
|
+
* A requested expiry, bounded: a hostile, absent or over-long value never reaches the mint.
|
|
94
|
+
*
|
|
95
|
+
* 🔴 THE RESULT LANDS ON A WHOLE SECOND (round 3). CDP stores `expiresAt` at whole-second granularity and
|
|
96
|
+
* truncates milliseconds toward zero — verified live on the dev project 2026-09-02 (`…:46.137Z` came back
|
|
97
|
+
* as `…:46Z` from `createDelegation` AND from `getDelegationForEndUser`; `…:45.999Z` came back as
|
|
98
|
+
* `…:45Z`, so it truncates rather than rounds). Everything downstream — the reservation, the durable row
|
|
99
|
+
* and every enforcement read — keys on that second, so the bound produces it directly rather than leaving
|
|
100
|
+
* a millisecond remainder for one of them to drop and another to keep.
|
|
101
|
+
*/
|
|
66
102
|
export function boundedDelegationExpiry(requestedDays, nowMs) {
|
|
67
103
|
const days = requestedDays === undefined || requestedDays === null
|
|
68
104
|
? MODEL_B_DELEGATION_EXPIRY_DEFAULT_DAYS
|
|
69
105
|
: Number(requestedDays);
|
|
70
|
-
if (!Number.isInteger(days) ||
|
|
71
|
-
|
|
106
|
+
if (!Number.isInteger(days) ||
|
|
107
|
+
days < MODEL_B_DELEGATION_EXPIRY_MIN_DAYS ||
|
|
108
|
+
days > MODEL_B_DELEGATION_EXPIRY_MAX_DAYS) {
|
|
109
|
+
throw new Error(`delegation expiry must be a whole number of days between ${MODEL_B_DELEGATION_EXPIRY_MIN_DAYS} and ${MODEL_B_DELEGATION_EXPIRY_MAX_DAYS}`);
|
|
72
110
|
}
|
|
73
|
-
|
|
111
|
+
const wholeSecond = Math.floor((nowMs + days * 86_400_000) / 1000) * 1000;
|
|
112
|
+
return Object.freeze({ days, expiresAt: new Date(wholeSecond).toISOString() });
|
|
74
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* The mint-expiry helpers live with the store that owns the reserved second; re-exported here because
|
|
116
|
+
* this is the module every consumer of the Model-B numbers already imports.
|
|
117
|
+
*/
|
|
118
|
+
export { MINT_EXPIRY_FILLER_MS as MODEL_B_MINT_EXPIRY_FILLER_MS } from './execution-delegation-cap-store.js';
|
|
119
|
+
export { mintExpiryForSecond as mintExpiryFor } from './execution-delegation-cap-store.js';
|
|
120
|
+
export { MODEL_B_CAP_RULESET_VERSION } from './execution-delegation-cap-store.js';
|
|
75
121
|
/**
|
|
76
122
|
* The per-swap cap in USD — the Founder's number (word `fence cap 5000`, 2026-08-29). It bounds ONE swap:
|
|
77
123
|
* the engine carries no daily or total limit, and no copy may imply one. Changing it = a new fence version.
|
|
78
124
|
* Engine conditions are on raw calldata, so the cap is expressed per allowed input token: v1 allows USDC
|
|
79
125
|
* only, where the mapping is exact (5,000 USD = 5,000,000,000 atomic on the approve amount, which is what
|
|
80
126
|
* bounds the swap's `fromAmount` on-chain).
|
|
127
|
+
*
|
|
128
|
+
* 🔴 THIS IS THE CEILING, SHARED BY EVERY DELEGATED USER — NOT ANY ONE PERSON'S CAP (Founder word
|
|
129
|
+
* `delegate cap choice`, 2026-09-02). Coinbase's engine offers end-user accounts exactly one fence, the
|
|
130
|
+
* project-scope policy, so the number compiled into those rules is the same for everybody and CANNOT be
|
|
131
|
+
* narrowed per user by the engine. A person who wants a lower number — "try it with $10" — gets it from
|
|
132
|
+
* Otto's own server: their choice is recorded against their grant (`execution-delegation-cap-store.ts`)
|
|
133
|
+
* and enforced on every delegated send, on top of this ceiling and never above it.
|
|
81
134
|
*/
|
|
82
135
|
export const MODEL_B_PER_SWAP_CAP_USD = 5000;
|
|
136
|
+
/**
|
|
137
|
+
* The floor of the range a person may choose. One whole dollar: the smallest cap that can still pass a
|
|
138
|
+
* real swap, and low enough that "try it with $10" is nowhere near it.
|
|
139
|
+
*/
|
|
140
|
+
export const MODEL_B_PER_SWAP_CAP_MIN_USD = 1;
|
|
141
|
+
/**
|
|
142
|
+
* A requested per-swap cap, bounded — the same shape as `boundedDelegationExpiry`, and the ONLY place a
|
|
143
|
+
* requested number becomes a cap.
|
|
144
|
+
*
|
|
145
|
+
* 🔴 IT REFUSES; IT NEVER CLAMPS. A hostile 50,000 is not silently turned into 5,000: a caller that asked
|
|
146
|
+
* for a number outside the range is a caller whose intent this server does not know, and quietly
|
|
147
|
+
* substituting one would make "the cap you chose" a claim nobody could check. Absent means the ceiling —
|
|
148
|
+
* the terms every grant already carried before a choice existed.
|
|
149
|
+
*/
|
|
150
|
+
export function boundedPerSwapCap(requestedUsd) {
|
|
151
|
+
if (requestedUsd === undefined || requestedUsd === null)
|
|
152
|
+
return MODEL_B_PER_SWAP_CAP_USD;
|
|
153
|
+
const capUsd = Number(requestedUsd);
|
|
154
|
+
if (!Number.isInteger(capUsd) ||
|
|
155
|
+
capUsd < MODEL_B_PER_SWAP_CAP_MIN_USD ||
|
|
156
|
+
capUsd > MODEL_B_PER_SWAP_CAP_USD) {
|
|
157
|
+
throw new Error(`per-swap cap must be a whole number of USD between ${MODEL_B_PER_SWAP_CAP_MIN_USD} and ${MODEL_B_PER_SWAP_CAP_USD}`);
|
|
158
|
+
}
|
|
159
|
+
return capUsd;
|
|
160
|
+
}
|
|
83
161
|
export const BASE_USDC = getAddress('0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913');
|
|
84
162
|
/**
|
|
85
163
|
* The input tokens a delegated swap may spend, v1: USDC only — the one token whose USD cap is exact.
|
|
@@ -92,6 +170,25 @@ export function modelBInputToken(token) {
|
|
|
92
170
|
const target = getAddress(token);
|
|
93
171
|
return MODEL_B_INPUT_TOKENS_V1.find((entry) => entry.address === target);
|
|
94
172
|
}
|
|
173
|
+
export const MODEL_B_WITHDRAW_TOKENS_V2 = Object.freeze(EXECUTABLE_YIELD_MARKETS.filter((market) => market.protocol === 'MORPHO').map((market) => Object.freeze({
|
|
174
|
+
symbol: `${market.venue} shares`,
|
|
175
|
+
address: getAddress(market.vaultAddress),
|
|
176
|
+
decimals: 18,
|
|
177
|
+
marketId: market.id,
|
|
178
|
+
})));
|
|
179
|
+
export function modelBWithdrawToken(token) {
|
|
180
|
+
const target = getAddress(token);
|
|
181
|
+
return MODEL_B_WITHDRAW_TOKENS_V2.find((entry) => entry.address === target);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* The engine-side bound on ONE withdraw's approve, in share atomic units: 5,000 shares. A USDC vault's
|
|
185
|
+
* share is worth ≥ 1 USDC by construction at inception and accrues from there (gtUSDCp ≈ 1.107 USDC on
|
|
186
|
+
* 2026-09-03), so 5,000 shares ≈ the 5,000 USD per-swap ceiling at par and somewhat more as yield accrues;
|
|
187
|
+
* after a vault loss the bound only tightens. It is the residual bound for a re-pointed withdraw, the same
|
|
188
|
+
* class as the swap rule's; the person's own cap does NOT apply to a withdraw (see the send gate: a withdraw
|
|
189
|
+
* returns the person's own assets to the person and never increases exposure).
|
|
190
|
+
*/
|
|
191
|
+
export const MODEL_B_WITHDRAW_SHARE_CAP_ATOMIC = 5000n * 10n ** 18n;
|
|
95
192
|
/** The cap in the token's atomic units. */
|
|
96
193
|
export function modelBPerSwapCapAtomic(token, capUsd = MODEL_B_PER_SWAP_CAP_USD) {
|
|
97
194
|
if (!Number.isSafeInteger(capUsd) || capUsd <= 0)
|
|
@@ -140,7 +237,8 @@ export const GENERIC_SWAP_V3_ABI = [
|
|
|
140
237
|
},
|
|
141
238
|
];
|
|
142
239
|
/** The static v1 rules: one approve rule per allow-listed input token, one router rule. */
|
|
143
|
-
|
|
240
|
+
/** The v1 rules, frozen as history: USDC approve to the diamond up to the cap + the router rule. */
|
|
241
|
+
export function modelBProjectPolicyRulesV1(capUsd = MODEL_B_PER_SWAP_CAP_USD) {
|
|
144
242
|
const approveRules = MODEL_B_INPUT_TOKENS_V1.map((token) => ({
|
|
145
243
|
action: 'accept',
|
|
146
244
|
operation: 'sendEndUserEvmTransaction',
|
|
@@ -186,11 +284,87 @@ export function modelBProjectPolicyRules(capUsd = MODEL_B_PER_SWAP_CAP_USD) {
|
|
|
186
284
|
};
|
|
187
285
|
return Object.freeze([...approveRules, routerRule]);
|
|
188
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* The v2 rules = v1 + (a) one approve rule per registry Morpho share token, spender = the diamond only,
|
|
289
|
+
* value ≤ `MODEL_B_WITHDRAW_SHARE_CAP_ATOMIC`, ethValue 0 — the delegated withdraw's allowance leg; the
|
|
290
|
+
* router rule is UNCHANGED (no receiver condition; the person's exit path); (b) a SIGN-ONLY accept rule
|
|
291
|
+
* (`signEndUserEvmTransaction`) for a USDC `transfer(to, value)` with value ≤ the per-swap cap and NO
|
|
292
|
+
* recipient condition — the person's own USDC exit without a swap, signed in their browser and broadcast
|
|
293
|
+
* by the page. The CDP policy schema carries no initiator/session criterion, so the engine cannot tell a
|
|
294
|
+
* user-signed send from a delegated one on the SAME operation; what it can do is fence a DIFFERENT
|
|
295
|
+
* operation, and Otto's delegated signer only ever calls the send operation (`adapter/cdp-signer.ts`).
|
|
296
|
+
* Stated residual: the developer-side end-user client also exposes `signEvmTransaction`, so under a
|
|
297
|
+
* delegation a compromised Otto could sign a USDC transfer to any address up to the cap — the same
|
|
298
|
+
* class and bound as the router rule's missing receiver condition, not a new one.
|
|
299
|
+
*/
|
|
300
|
+
export function modelBProjectPolicyRules(capUsd = MODEL_B_PER_SWAP_CAP_USD) {
|
|
301
|
+
const v1 = modelBProjectPolicyRulesV1(capUsd);
|
|
302
|
+
const routerRule = v1[v1.length - 1];
|
|
303
|
+
const inputApproveRules = v1.slice(0, -1);
|
|
304
|
+
const shareApproveRules = MODEL_B_WITHDRAW_TOKENS_V2.map((token) => ({
|
|
305
|
+
action: 'accept',
|
|
306
|
+
operation: 'sendEndUserEvmTransaction',
|
|
307
|
+
criteria: [
|
|
308
|
+
{ type: 'evmNetwork', networks: [MODEL_B_POLICY_NETWORK], operator: 'in' },
|
|
309
|
+
{ type: 'evmAddress', addresses: [token.address], operator: 'in' },
|
|
310
|
+
{ type: 'ethValue', ethValue: '0', operator: '<=' },
|
|
311
|
+
{
|
|
312
|
+
type: 'evmData',
|
|
313
|
+
abi: 'erc20',
|
|
314
|
+
conditions: [
|
|
315
|
+
{
|
|
316
|
+
function: 'approve',
|
|
317
|
+
params: [
|
|
318
|
+
{ name: 'spender', operator: 'in', values: [LIFI_DIAMOND_ADDRESS] },
|
|
319
|
+
{ name: 'value', operator: '<=', value: MODEL_B_WITHDRAW_SHARE_CAP_ATOMIC.toString() },
|
|
320
|
+
],
|
|
321
|
+
},
|
|
322
|
+
],
|
|
323
|
+
},
|
|
324
|
+
],
|
|
325
|
+
}));
|
|
326
|
+
/**
|
|
327
|
+
* 🔴 NO NETWORK CRITERION ON THE SIGN RULE — by the SDK's schema, not by choice (codex gate r1 HIGH 1):
|
|
328
|
+
* `signEndUserEvmTransaction` admits only `ethValue | evmAddress | netUSDChange | evmData`
|
|
329
|
+
* (`@coinbase/cdp-sdk/_types/policies/evmSchema.d.ts`); `evmNetwork` is a discriminator only the SEND
|
|
330
|
+
* operation accepts, and the SDK's create/update parse throws on it BEFORE any write. So this rule is
|
|
331
|
+
* pinned by the USDC contract ADDRESS (Base USDC lives at that address on Base alone) and by the amount,
|
|
332
|
+
* not by a network name. Stated residual: the same address on another network would be signable up to
|
|
333
|
+
* the cap — a broader statement than v1's, recorded in the PR for the Founder. A test parses the whole
|
|
334
|
+
* body through the SDK's own CreatePolicyBodySchema/UpdatePolicyBodySchema so this can never regress.
|
|
335
|
+
*/
|
|
336
|
+
const userSignedUsdcTransferRules = MODEL_B_INPUT_TOKENS_V1.map((token) => ({
|
|
337
|
+
action: 'accept',
|
|
338
|
+
operation: 'signEndUserEvmTransaction',
|
|
339
|
+
criteria: [
|
|
340
|
+
{ type: 'evmAddress', addresses: [token.address], operator: 'in' },
|
|
341
|
+
{ type: 'ethValue', ethValue: '0', operator: '<=' },
|
|
342
|
+
{
|
|
343
|
+
type: 'evmData',
|
|
344
|
+
abi: 'erc20',
|
|
345
|
+
conditions: [
|
|
346
|
+
{
|
|
347
|
+
function: 'transfer',
|
|
348
|
+
params: [
|
|
349
|
+
{ name: 'value', operator: '<=', value: modelBPerSwapCapAtomic(token, capUsd).toString() },
|
|
350
|
+
],
|
|
351
|
+
},
|
|
352
|
+
],
|
|
353
|
+
},
|
|
354
|
+
],
|
|
355
|
+
}));
|
|
356
|
+
return Object.freeze([
|
|
357
|
+
...inputApproveRules,
|
|
358
|
+
...shareApproveRules,
|
|
359
|
+
routerRule,
|
|
360
|
+
...userSignedUsdcTransferRules,
|
|
361
|
+
]);
|
|
362
|
+
}
|
|
189
363
|
/** The body PR-2's installer creates or updates: scope, versioned description, the v1 rules. */
|
|
190
364
|
export function modelBProjectPolicyBody() {
|
|
191
365
|
return Object.freeze({
|
|
192
366
|
scope: 'project',
|
|
193
|
-
description:
|
|
367
|
+
description: MODEL_B_POLICY_NAME,
|
|
194
368
|
rules: modelBProjectPolicyRules(),
|
|
195
369
|
});
|
|
196
370
|
}
|
|
@@ -217,7 +391,15 @@ export function policyRulesDigest(rules) {
|
|
|
217
391
|
.update(JSON.stringify(canonical(rules)))
|
|
218
392
|
.digest('hex');
|
|
219
393
|
}
|
|
220
|
-
export const MODEL_B_POLICY_DIGEST_V1 = policyRulesDigest(
|
|
394
|
+
export const MODEL_B_POLICY_DIGEST_V1 = policyRulesDigest(modelBProjectPolicyRulesV1());
|
|
395
|
+
export const MODEL_B_POLICY_DIGEST_V2 = policyRulesDigest(modelBProjectPolicyRules());
|
|
396
|
+
/** The CURRENT digest (v2). */
|
|
397
|
+
export const MODEL_B_POLICY_DIGEST = MODEL_B_POLICY_DIGEST_V2;
|
|
398
|
+
/** name → {version, digest} for every accepted lineage version. */
|
|
399
|
+
export const MODEL_B_POLICY_DIGEST_BY_NAME = new Map([
|
|
400
|
+
[MODEL_B_POLICY_NAME_V1, { version: 1, digest: MODEL_B_POLICY_DIGEST_V1 }],
|
|
401
|
+
[MODEL_B_POLICY_NAME_V2, { version: 2, digest: MODEL_B_POLICY_DIGEST_V2 }],
|
|
402
|
+
]);
|
|
221
403
|
/**
|
|
222
404
|
* The fence check the delegated-send path runs BEFORE any send: EXACTLY ONE project-scope policy reads back
|
|
223
405
|
* (Coinbase allows one; more is an anomalous snapshot and never blessed on the strength of "one of them
|
|
@@ -240,22 +422,35 @@ export function readBackModelBFence(policies) {
|
|
|
240
422
|
};
|
|
241
423
|
}
|
|
242
424
|
const named = project[0];
|
|
243
|
-
|
|
425
|
+
const known = typeof named.description === 'string'
|
|
426
|
+
? MODEL_B_POLICY_DIGEST_BY_NAME.get(named.description)
|
|
427
|
+
: undefined;
|
|
428
|
+
if (!known) {
|
|
244
429
|
return {
|
|
245
430
|
present: false,
|
|
246
431
|
reason: 'name_mismatch',
|
|
247
|
-
detail: `the project policy is not "${MODEL_B_POLICY_NAME_V1}"`,
|
|
432
|
+
detail: `the project policy is not "${MODEL_B_POLICY_NAME_V1}" or "${MODEL_B_POLICY_NAME_V2}"`,
|
|
248
433
|
};
|
|
249
434
|
}
|
|
250
435
|
const rulesDigest = policyRulesDigest(named.rules);
|
|
251
|
-
if (rulesDigest !==
|
|
436
|
+
if (rulesDigest !== known.digest) {
|
|
252
437
|
return {
|
|
253
438
|
present: false,
|
|
254
439
|
reason: 'digest_mismatch',
|
|
255
|
-
detail: `the project policy "${
|
|
440
|
+
detail: `the project policy "${named.description}" carries rules that do not digest to v${known.version} (${rulesDigest.slice(0, 16)}… ≠ ${known.digest.slice(0, 16)}…)`,
|
|
256
441
|
};
|
|
257
442
|
}
|
|
258
|
-
return {
|
|
443
|
+
return {
|
|
444
|
+
present: true,
|
|
445
|
+
id: named.id,
|
|
446
|
+
rulesDigest,
|
|
447
|
+
version: known.version,
|
|
448
|
+
name: named.description,
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
/** True when the read-back is THIS binary's fence version — what the fence tool leaves alone. */
|
|
452
|
+
export function fenceIsCurrent(readBack) {
|
|
453
|
+
return readBack.present && readBack.version === MODEL_B_POLICY_VERSION;
|
|
259
454
|
}
|
|
260
455
|
/**
|
|
261
456
|
* The same bound the engine enforces, checked server-side BEFORE the first step is sent: a plan the
|
|
@@ -276,4 +471,53 @@ export function assertWithinModelBFence(plan, capUsd = MODEL_B_PER_SWAP_CAP_USD,
|
|
|
276
471
|
}
|
|
277
472
|
return { token, capAtomic };
|
|
278
473
|
}
|
|
474
|
+
/**
|
|
475
|
+
* 🔴 v2 — the delegated WITHDRAW's fence: the approve token must be a registry share token, the spender the
|
|
476
|
+
* diamond, the approve amount within the share cap, and the OUTPUT token USDC (a withdraw is "shares → the
|
|
477
|
+
* person's USDC", never a swap into something else under the withdraw's cap-free rule). The receiver pin
|
|
478
|
+
* (== the signing account) is the verifier's, already applied before this runs.
|
|
479
|
+
*/
|
|
480
|
+
export function assertWithdrawWithinModelBFence(plan) {
|
|
481
|
+
const token = modelBWithdrawToken(plan.token);
|
|
482
|
+
if (!token) {
|
|
483
|
+
return refuse('DELEGATION_OUTSIDE_FENCE', `input token ${plan.token} is neither an allow-listed delegated input nor a registry vault share token`);
|
|
484
|
+
}
|
|
485
|
+
if (getAddress(plan.spender) !== LIFI_DIAMOND_ADDRESS) {
|
|
486
|
+
return refuse('DELEGATION_OUTSIDE_FENCE', `approval spender ${plan.spender} is not the reviewed LI.FI diamond`);
|
|
487
|
+
}
|
|
488
|
+
if (getAddress(plan.outputToken) !== BASE_USDC) {
|
|
489
|
+
return refuse('DELEGATION_OUTSIDE_FENCE', `a delegated withdraw must deliver USDC to the signing account; this route delivers ${plan.outputToken}`);
|
|
490
|
+
}
|
|
491
|
+
if (plan.gross > MODEL_B_WITHDRAW_SHARE_CAP_ATOMIC) {
|
|
492
|
+
return refuse('DELEGATION_OUTSIDE_FENCE', `withdraw of ${plan.gross} share atomic units exceeds the engine bound ${MODEL_B_WITHDRAW_SHARE_CAP_ATOMIC}`);
|
|
493
|
+
}
|
|
494
|
+
return { token };
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* THE PERSON'S OWN CAP, enforced after the engine's (Founder word `delegate cap choice`, 2026-09-02).
|
|
498
|
+
*
|
|
499
|
+
* 🔴 WHY THIS IS A SEPARATE CHECK AND A SEPARATE CODE. `assertWithinModelBFence` above answers "would
|
|
500
|
+
* Coinbase's engine have signed this?" — it is the shared ceiling and it is also enforced on-chain by the
|
|
501
|
+
* project policy, so a plan past it never reaches a signature whatever this server does. THIS check
|
|
502
|
+
* answers a different question: "is it inside the number THIS PERSON chose when they minted?" The engine
|
|
503
|
+
* cannot ask it (one project policy, shared by every delegated user), so Otto's server is the only place
|
|
504
|
+
* it can be asked, and a plan that fails it is one the engine WOULD have signed.
|
|
505
|
+
*
|
|
506
|
+
* Folding the two into one call with a smaller number would pass every shape-level test while making the
|
|
507
|
+
* two facts indistinguishable in the refusal, in the logs and in the tests. They are kept apart so a
|
|
508
|
+
* mutation that drops the user's cap reddens on its own named code rather than hiding behind the ceiling.
|
|
509
|
+
*/
|
|
510
|
+
export function assertWithinUserPerSwapCap(grossAtomic, capUsd, token) {
|
|
511
|
+
if (!Number.isInteger(capUsd) ||
|
|
512
|
+
capUsd < MODEL_B_PER_SWAP_CAP_MIN_USD ||
|
|
513
|
+
capUsd > MODEL_B_PER_SWAP_CAP_USD) {
|
|
514
|
+
// A recorded cap outside the range is a corrupted record, not a permission. Fail closed.
|
|
515
|
+
return refuse('DELEGATION_CAP_UNRECORDED', `the recorded per-swap cap (${String(capUsd)}) is not a whole number of USD between ${MODEL_B_PER_SWAP_CAP_MIN_USD} and ${MODEL_B_PER_SWAP_CAP_USD}; nothing is submitted`);
|
|
516
|
+
}
|
|
517
|
+
const capAtomic = modelBPerSwapCapAtomic(token, capUsd);
|
|
518
|
+
if (grossAtomic > capAtomic) {
|
|
519
|
+
return refuse('DELEGATION_ABOVE_USER_CAP', `gross ${grossAtomic} ${token.symbol} atomic exceeds the ${capUsd} USD per-swap cap recorded for this delegation (${capAtomic} atomic)`);
|
|
520
|
+
}
|
|
521
|
+
return { capUsd, capAtomic };
|
|
522
|
+
}
|
|
279
523
|
//# sourceMappingURL=execution-delegation-policy.js.map
|
|
@@ -31,12 +31,27 @@
|
|
|
31
31
|
*
|
|
32
32
|
* Nothing here logs the header, the secret, or a credential. Refusals are machine-readable codes; upstream
|
|
33
33
|
* error bodies are never relayed.
|
|
34
|
+
*
|
|
35
|
+
* ══════════════════════════════════════════════════════════════════════════════════════════════════
|
|
36
|
+
* 🔴 THE THREAT MODEL THE PER-SWAP CAP GATE (step 5b) ENFORCES (Founder ruling, 2026-09-03, verbatim)
|
|
37
|
+
* ══════════════════════════════════════════════════════════════════════════════════════════════════
|
|
38
|
+
* "The per-person delegation cap protects every delegated send that goes through Otto's page
|
|
39
|
+
* (/app/delegate) and Otto's CLI (otto-execute delegate). A permission a person mints or revokes
|
|
40
|
+
* directly against Coinbase with their own login, outside Otto's page and CLI, is OUT OF SCOPE: Otto
|
|
41
|
+
* cannot distinguish it (CDP returns no grant identity, only an expiry) and does not defend against it;
|
|
42
|
+
* the CDP project-scope $5,000 ceiling remains the hard backstop for every permission. The delegated
|
|
43
|
+
* agent never holds the person's login."
|
|
44
|
+
*
|
|
45
|
+
* Note the direction that holds even out of the model: a grant Otto has no CONFIRMED record for
|
|
46
|
+
* authorises NOTHING here — it is refused by name, never admitted at the shared ceiling. An
|
|
47
|
+
* out-of-model actor can therefore shorten what Otto may do for them, never widen it.
|
|
34
48
|
*/
|
|
35
49
|
import { type Address, type PublicClient } from 'viem';
|
|
36
50
|
import type { SealedWaitOptions } from './adapter/chain.js';
|
|
37
51
|
import { DelegatedPlanHaltedError, type CdpDeveloperCredentials, type CdpRig, type DelegatedHaltCause } from './adapter/cdp-signer.js';
|
|
38
52
|
import { type DelegatedSendResult } from './execution-delegated-definition.js';
|
|
39
53
|
import { type DelegationPolicyRecord, type ModelBInputToken } from './execution-delegation-policy.js';
|
|
54
|
+
import { type DelegationCapStore } from './execution-delegation-cap-store.js';
|
|
40
55
|
import { ExecutionRefusal } from './execution-errors.js';
|
|
41
56
|
import type { ExecutionToolRuntime } from './execution-tools.js';
|
|
42
57
|
export declare const DELEGATION_ENV_NAMES: readonly ["CDP_API_KEY_ID", "CDP_API_KEY_SECRET", "CDP_WALLET_SECRET", "OTTO_DELEGATION_SERVER_SECRET", "BASE_RPC_URL"];
|
|
@@ -156,6 +171,12 @@ export interface DelegationCdpClient {
|
|
|
156
171
|
export declare function createDelegationRig(cdp: DelegationCdpClient, pub: PublicClient): DelegationRig;
|
|
157
172
|
export interface DelegationServices {
|
|
158
173
|
readonly rig: DelegationRig;
|
|
174
|
+
/**
|
|
175
|
+
* The Base public client the rig was built on — exposed so the constructor can SIMULATE a quoted route
|
|
176
|
+
* from the executing account before preparing it (`adapter/route-simulator.ts`). Absent in tests that
|
|
177
|
+
* build a rig without one; the constructor then prepares without a simulation and says so.
|
|
178
|
+
*/
|
|
179
|
+
readonly pub?: PublicClient;
|
|
159
180
|
/** The server-to-server secret the caller must present in `x-otto-delegation-auth`. Never logged. */
|
|
160
181
|
readonly serverSecret: string;
|
|
161
182
|
/** Otto's PUBLIC CDP project id (a UUID) the fence-status tool publishes; undefined disables that tool. */
|
|
@@ -171,6 +192,20 @@ export interface DelegationServices {
|
|
|
171
192
|
readonly perSwapCapUsd?: number;
|
|
172
193
|
readonly inputTokens?: readonly ModelBInputToken[];
|
|
173
194
|
};
|
|
195
|
+
/**
|
|
196
|
+
* Where the per-swap cap each person CHOSE when they minted is recorded, keyed by their grant
|
|
197
|
+
* (Founder word `delegate cap choice`, 2026-09-02). Durable across redeploys — see
|
|
198
|
+
* `execution-delegation-cap-store.ts` for why a Map would not do. A send whose grant has no record
|
|
199
|
+
* here refuses; an UNAVAILABLE store refuses everything, by name.
|
|
200
|
+
*/
|
|
201
|
+
readonly capStore: DelegationCapStore;
|
|
202
|
+
/**
|
|
203
|
+
* 🔴 THE STAGED-DEPLOY GATE. False (the default in code) means no NEW permission can be reserved on
|
|
204
|
+
* this worker — see `DELEGATION_MINT_ENABLED` in `execution-delegation-cap-store.ts` for why the first
|
|
205
|
+
* rollout cannot be fenced by the ruleset handshake alone. It gates CREATION only: a send under a
|
|
206
|
+
* permission that is already confirmed still runs under its own cap, and REVOKE always works.
|
|
207
|
+
*/
|
|
208
|
+
readonly mintEnabled: boolean;
|
|
174
209
|
}
|
|
175
210
|
export interface DelegationCaller {
|
|
176
211
|
/** The header value as presented, or undefined when absent. Never logged. */
|