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.
- package/README.md +76 -18
- package/dist/account-userop-policy-definition.d.ts +14 -0
- package/dist/account-userop-policy-definition.js +12 -0
- package/dist/account-userop-policy-relation.d.ts +371 -0
- package/dist/account-userop-policy-relation.js +87 -0
- package/dist/adapter/cdp-signer.d.ts +76 -9
- package/dist/adapter/cdp-signer.js +274 -33
- 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/adapter-cdp-index.d.ts +1 -1
- 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-account-gas-quote.d.ts +141 -0
- package/dist/execution-account-gas-quote.js +443 -0
- package/dist/execution-account-gas-review.d.ts +123 -0
- package/dist/execution-account-gas-review.js +104 -0
- package/dist/execution-account-gas-runtime.d.ts +33 -0
- package/dist/execution-account-gas-runtime.js +131 -0
- package/dist/execution-account-gas-view.d.ts +936 -0
- package/dist/execution-account-gas-view.js +56 -0
- package/dist/execution-config.d.ts +3 -0
- package/dist/execution-config.js +4 -0
- package/dist/execution-delegated-definition.d.ts +7 -6
- package/dist/execution-delegated-definition.js +13 -2
- package/dist/execution-delegation-admin-definition.d.ts +127 -5
- package/dist/execution-delegation-admin-definition.js +155 -5
- package/dist/execution-delegation-admin.d.ts +48 -2
- package/dist/execution-delegation-admin.js +422 -12
- package/dist/execution-delegation-cap-store.d.ts +386 -0
- package/dist/execution-delegation-cap-store.js +1150 -0
- package/dist/execution-delegation-exit-definition.d.ts +309 -0
- package/dist/execution-delegation-exit-definition.js +204 -0
- package/dist/execution-delegation-exit-store.d.ts +114 -0
- package/dist/execution-delegation-exit-store.js +671 -0
- package/dist/execution-delegation-exit.d.ts +4 -0
- package/dist/execution-delegation-exit.js +614 -0
- package/dist/execution-delegation-finality.d.ts +22 -0
- package/dist/execution-delegation-finality.js +90 -0
- package/dist/execution-delegation-operation-store.d.ts +129 -0
- package/dist/execution-delegation-operation-store.js +1107 -0
- package/dist/execution-delegation-operations-definition.d.ts +282 -0
- package/dist/execution-delegation-operations-definition.js +117 -0
- package/dist/execution-delegation-operations.d.ts +6 -0
- package/dist/execution-delegation-operations.js +282 -0
- package/dist/execution-delegation-policy.d.ts +154 -8
- package/dist/execution-delegation-policy.js +273 -40
- package/dist/execution-delegation.d.ts +51 -0
- package/dist/execution-delegation.js +441 -31
- package/dist/execution-errors.d.ts +1 -1
- package/dist/execution-errors.js +122 -0
- package/dist/execution-index.d.ts +7 -2
- package/dist/execution-index.js +7 -2
- package/dist/execution-journal-schema.d.ts +96 -0
- package/dist/execution-journal-schema.js +368 -0
- package/dist/execution-journal-tables.d.ts +14 -0
- package/dist/execution-journal-tables.js +227 -0
- package/dist/execution-policy-compatibility.d.ts +34 -0
- package/dist/execution-policy-compatibility.js +76 -0
- package/dist/execution-registration.d.ts +54 -2
- package/dist/execution-registration.js +151 -5
- package/dist/execution-sponsored-account-profile.d.ts +32 -0
- package/dist/execution-sponsored-account-profile.js +59 -0
- package/dist/execution-sponsored-account.d.ts +1519 -0
- package/dist/execution-sponsored-account.js +222 -0
- package/dist/execution-sponsored-definition.d.ts +1713 -0
- package/dist/execution-sponsored-definition.js +185 -0
- package/dist/execution-sponsored-gas-policy.d.ts +27 -0
- package/dist/execution-sponsored-gas-policy.js +110 -0
- package/dist/execution-sponsored-hosted.d.ts +3 -0
- package/dist/execution-sponsored-hosted.js +71 -0
- package/dist/execution-sponsored-index.d.ts +1322 -0
- package/dist/execution-sponsored-index.js +102 -0
- package/dist/execution-sponsored-mcp-definition.d.ts +1662 -0
- package/dist/execution-sponsored-mcp-definition.js +94 -0
- package/dist/execution-sponsored-receipt.d.ts +47 -0
- package/dist/execution-sponsored-receipt.js +74 -0
- package/dist/execution-sponsored-registration.d.ts +14 -0
- package/dist/execution-sponsored-registration.js +77 -0
- package/dist/execution-sponsored-runtime.d.ts +84 -0
- package/dist/execution-sponsored-runtime.js +149 -0
- package/dist/execution-sponsored-settlement.d.ts +15 -0
- package/dist/execution-sponsored-settlement.js +88 -0
- package/dist/execution-sponsored-store.d.ts +67 -0
- package/dist/execution-sponsored-store.js +517 -0
- package/dist/execution-sponsored-transport.d.ts +90 -0
- package/dist/execution-sponsored-transport.js +180 -0
- package/dist/execution-tool-definitions.d.ts +21 -21
- package/dist/execution-tool-definitions.js +0 -7
- package/dist/execution-tools.d.ts +53 -1
- package/dist/execution-tools.js +171 -13
- package/dist/execution-worker-guard.d.ts +28 -0
- package/dist/execution-worker-guard.js +124 -0
- package/dist/hybrid-yield-index.d.ts +10 -0
- package/dist/hybrid-yield-index.js +11 -0
- package/dist/hybrid-yield-markets.d.ts +96 -0
- package/dist/hybrid-yield-markets.js +124 -0
- package/dist/hybrid-yield.d.ts +411 -0
- package/dist/hybrid-yield.js +155 -0
- package/dist/hyperliquid-order-builder.js +4 -0
- package/dist/lifi-execution-client.d.ts +6 -0
- package/dist/lifi-execution-client.js +3 -0
- package/dist/lp-userop-account.d.ts +461 -0
- package/dist/lp-userop-account.js +417 -0
- package/dist/lp-userop-authority.d.ts +49 -0
- package/dist/lp-userop-authority.js +211 -0
- package/dist/lp-userop-definition.d.ts +233 -0
- package/dist/lp-userop-definition.js +85 -0
- package/dist/lp-userop-hosted.d.ts +3 -0
- package/dist/lp-userop-hosted.js +73 -0
- package/dist/lp-userop-index.d.ts +1569 -0
- package/dist/lp-userop-index.js +112 -0
- package/dist/lp-userop-mcp-definition.d.ts +1220 -0
- package/dist/lp-userop-mcp-definition.js +46 -0
- package/dist/lp-userop-operation.d.ts +1230 -0
- package/dist/lp-userop-operation.js +140 -0
- package/dist/lp-userop-registration.d.ts +14 -0
- package/dist/lp-userop-registration.js +70 -0
- package/dist/lp-userop-settlement.d.ts +89 -0
- package/dist/lp-userop-settlement.js +184 -0
- package/dist/lp-userop.d.ts +643 -0
- package/dist/lp-userop.js +343 -0
- package/dist/native-yield-account-definition.d.ts +1192 -0
- package/dist/native-yield-account-definition.js +232 -0
- package/dist/native-yield-account-gas.d.ts +58 -0
- package/dist/native-yield-account-gas.js +228 -0
- package/dist/native-yield-account-index.d.ts +23 -0
- package/dist/native-yield-account-index.js +28 -0
- package/dist/native-yield-account-policy.d.ts +168 -0
- package/dist/native-yield-account-policy.js +525 -0
- package/dist/native-yield-account-rpc.d.ts +8 -0
- package/dist/native-yield-account-rpc.js +128 -0
- package/dist/native-yield-account-runtime.d.ts +71 -0
- package/dist/native-yield-account-runtime.js +125 -0
- package/dist/native-yield-account-store.d.ts +40 -0
- package/dist/native-yield-account-store.js +307 -0
- package/dist/native-yield-account.d.ts +662 -0
- package/dist/native-yield-account.js +371 -0
- package/dist/native-yield-consent-store.d.ts +20 -0
- package/dist/native-yield-consent-store.js +317 -0
- package/dist/native-yield-definition.d.ts +288 -0
- package/dist/native-yield-definition.js +105 -0
- package/dist/native-yield-reader.d.ts +4 -0
- package/dist/native-yield-reader.js +137 -0
- package/dist/native-yield-settlement.d.ts +48 -0
- package/dist/native-yield-settlement.js +167 -0
- package/dist/native-yield-simulation.d.ts +18 -0
- package/dist/native-yield-simulation.js +45 -0
- package/dist/native-yield-userop-account.d.ts +675 -0
- package/dist/native-yield-userop-account.js +357 -0
- package/dist/native-yield-userop-authority.d.ts +214 -0
- package/dist/native-yield-userop-authority.js +296 -0
- package/dist/native-yield-userop-definition.d.ts +331 -0
- package/dist/native-yield-userop-definition.js +105 -0
- package/dist/native-yield-userop-hosted.d.ts +3 -0
- package/dist/native-yield-userop-hosted.js +71 -0
- package/dist/native-yield-userop-index.d.ts +1522 -0
- package/dist/native-yield-userop-index.js +142 -0
- package/dist/native-yield-userop-mcp-definition.d.ts +1356 -0
- package/dist/native-yield-userop-mcp-definition.js +50 -0
- package/dist/native-yield-userop-operation.d.ts +845 -0
- package/dist/native-yield-userop-operation.js +127 -0
- package/dist/native-yield-userop-policy.d.ts +23 -0
- package/dist/native-yield-userop-policy.js +25 -0
- package/dist/native-yield-userop-registration.d.ts +17 -0
- package/dist/native-yield-userop-registration.js +76 -0
- package/dist/native-yield-userop-settlement.d.ts +8 -0
- package/dist/native-yield-userop-settlement.js +79 -0
- package/dist/native-yield-userop-simulation.d.ts +18 -0
- package/dist/native-yield-userop-simulation.js +34 -0
- package/dist/native-yield-userop.d.ts +35 -0
- package/dist/native-yield-userop.js +156 -0
- package/dist/native-yield-verify.d.ts +30 -0
- package/dist/native-yield-verify.js +141 -0
- package/dist/native-yield.d.ts +17 -0
- package/dist/native-yield.js +119 -0
- package/dist/stdio-main.js +0 -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.d.ts +3 -1
- package/dist/tool-definitions.js +55 -2
- package/dist/vendor/lp-v3/lp-v3-atomic-contract.d.ts +445 -0
- package/dist/vendor/lp-v3/lp-v3-atomic-contract.js +90 -0
- package/dist/vendor/lp-v3/lp-v3-atomic-evidence.d.ts +14 -0
- package/dist/vendor/lp-v3/lp-v3-atomic-evidence.js +82 -0
- package/dist/vendor/lp-v3/lp-v3-atomic-index.d.ts +80 -0
- package/dist/vendor/lp-v3/lp-v3-atomic-index.js +19 -0
- package/dist/vendor/lp-v3/lp-v3-atomic-plan.d.ts +43 -0
- package/dist/vendor/lp-v3/lp-v3-atomic-plan.js +112 -0
- package/dist/vendor/lp-v3/lp-v3-atomic-read-contract.d.ts +312 -0
- package/dist/vendor/lp-v3/lp-v3-atomic-read-contract.js +41 -0
- package/dist/vendor/lp-v3/lp-v3-atomic-read-index.d.ts +3 -0
- package/dist/vendor/lp-v3/lp-v3-atomic-read-index.js +3 -0
- package/dist/vendor/lp-v3/lp-v3-atomic-read-rpc.d.ts +49 -0
- package/dist/vendor/lp-v3/lp-v3-atomic-read-rpc.js +88 -0
- package/dist/vendor/lp-v3/lp-v3-atomic-read.d.ts +17 -0
- package/dist/vendor/lp-v3/lp-v3-atomic-read.js +232 -0
- package/dist/vendor/lp-v3/lp-v3-atomic-settlement.d.ts +105 -0
- package/dist/vendor/lp-v3/lp-v3-atomic-settlement.js +162 -0
- package/dist/vendor/lp-v3/lp-v3-collect-protocol-contract.d.ts +606 -0
- package/dist/vendor/lp-v3/lp-v3-collect-protocol-contract.js +59 -0
- package/dist/vendor/lp-v3/lp-v3-collect-protocol-index.d.ts +168 -0
- package/dist/vendor/lp-v3/lp-v3-collect-protocol-index.js +23 -0
- package/dist/vendor/lp-v3/lp-v3-collect-protocol-observation.d.ts +32 -0
- package/dist/vendor/lp-v3/lp-v3-collect-protocol-observation.js +228 -0
- package/dist/vendor/lp-v3/lp-v3-collect-protocol-plan.d.ts +11 -0
- package/dist/vendor/lp-v3/lp-v3-collect-protocol-plan.js +91 -0
- package/dist/vendor/lp-v3/lp-v3-collect-protocol-reconcile.d.ts +9 -0
- package/dist/vendor/lp-v3/lp-v3-collect-protocol-reconcile.js +124 -0
- package/dist/vendor/lp-v3/lp-v3-contract.d.ts +538 -0
- package/dist/vendor/lp-v3/lp-v3-contract.js +137 -0
- package/dist/vendor/lp-v3/lp-v3-evidence.d.ts +25 -0
- package/dist/vendor/lp-v3/lp-v3-evidence.js +168 -0
- package/dist/vendor/lp-v3/lp-v3-plan.d.ts +22 -0
- package/dist/vendor/lp-v3/lp-v3-plan.js +135 -0
- package/dist/vendor/lp-v3/types.d.ts +131 -0
- package/dist/vendor/lp-v3/types.js +6 -0
- package/dist/vendor/lp-v3/v4-math.d.ts +18 -0
- package/dist/vendor/lp-v3/v4-math.js +90 -0
- package/dist/yield-deposit-definition.d.ts +374 -0
- package/dist/yield-deposit-definition.js +123 -0
- package/dist/yield-deposit.d.ts +16 -0
- package/dist/yield-deposit.js +149 -0
- package/dist/yield-route-semantics.d.ts +27 -0
- package/dist/yield-route-semantics.js +71 -0
- package/dist/yield-withdraw-definition.d.ts +357 -0
- package/dist/yield-withdraw-definition.js +90 -0
- package/dist/yield-withdraw.d.ts +11 -0
- package/dist/yield-withdraw.js +122 -0
- package/package.json +239 -7
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
/** Read-only LP preparation and atomic account-call verification. No sender or authority issuer. */
|
|
2
|
+
import { encodeFunctionData, getAddress, parseAbi } from 'viem';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { hybridYieldCommitment, freezeHybridValue } from './hybrid-yield-markets.js';
|
|
5
|
+
import { LP_USEROP_TERMS_SCHEMA } from './lp-userop-definition.js';
|
|
6
|
+
import { assertSponsoredAccountProfile } from './execution-sponsored-account-profile.js';
|
|
7
|
+
import { LP_V3_BASE, commitment as protocolCommitment } from './vendor/lp-v3/lp-v3-contract.js';
|
|
8
|
+
import { LP_V3_ATOMIC_NPM_ABI, LP_V3_COLLECT_GUARD_ABI, reviewedGuardPolicy, } from './vendor/lp-v3/lp-v3-atomic-contract.js';
|
|
9
|
+
import { lpV3FinalityPolicySchema, } from './vendor/lp-v3/lp-v3-atomic-read-contract.js';
|
|
10
|
+
import { lpV3CollectProtocolIntentSchema, lpV3CollectProtocolPlanSchema, lpV3CollectProtocolObservationSchema, lpV3CollectProtocolCheckSchema, } from './vendor/lp-v3/lp-v3-collect-protocol-contract.js';
|
|
11
|
+
import { createLpV3CollectProtocolLibrary, } from './vendor/lp-v3/lp-v3-collect-protocol-index.js';
|
|
12
|
+
export const LP_USEROP_BATCH_ABI = parseAbi([
|
|
13
|
+
'function executeBatch((address target,uint256 value,bytes data)[] calls) payable',
|
|
14
|
+
]);
|
|
15
|
+
const time = z.number().int().positive().safe();
|
|
16
|
+
export const LP_USEROP_VERIFICATION_EVIDENCE_SCHEMA = z
|
|
17
|
+
.object({
|
|
18
|
+
baseline: lpV3CollectProtocolObservationSchema,
|
|
19
|
+
check: lpV3CollectProtocolCheckSchema,
|
|
20
|
+
verifiedAtMs: time,
|
|
21
|
+
})
|
|
22
|
+
.strict();
|
|
23
|
+
export const LP_USEROP_SUBMIT_EVIDENCE_SCHEMA = LP_USEROP_VERIFICATION_EVIDENCE_SCHEMA;
|
|
24
|
+
export const LP_USEROP_ENVELOPE_SCHEMA = z
|
|
25
|
+
.object({
|
|
26
|
+
version: z.literal(1),
|
|
27
|
+
kind: z.literal('lp-collect-userop'),
|
|
28
|
+
input: lpV3CollectProtocolIntentSchema,
|
|
29
|
+
plan: lpV3CollectProtocolPlanSchema,
|
|
30
|
+
baseline: lpV3CollectProtocolObservationSchema,
|
|
31
|
+
check: lpV3CollectProtocolCheckSchema,
|
|
32
|
+
terms: LP_USEROP_TERMS_SCHEMA,
|
|
33
|
+
finalityPolicy: lpV3FinalityPolicySchema,
|
|
34
|
+
preparedAtMs: time,
|
|
35
|
+
validUntilMs: time,
|
|
36
|
+
commitment: z.string().regex(/^sha256:[0-9a-f]{64}$/),
|
|
37
|
+
})
|
|
38
|
+
.strict();
|
|
39
|
+
const verified = new WeakMap();
|
|
40
|
+
const verifiedReadTime = new WeakMap();
|
|
41
|
+
export class LpUserOpError extends Error {
|
|
42
|
+
code;
|
|
43
|
+
constructor(code) {
|
|
44
|
+
super(code);
|
|
45
|
+
this.code = code;
|
|
46
|
+
this.name = 'LpUserOpError';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export function requireLpUserOp(value, code) {
|
|
50
|
+
if (!value)
|
|
51
|
+
throw new LpUserOpError(code);
|
|
52
|
+
}
|
|
53
|
+
const same = (a, b) => a.toLowerCase() === b.toLowerCase();
|
|
54
|
+
export function lpUserOpNow(runtime) {
|
|
55
|
+
const now = (runtime.nowMs ?? Date.now)();
|
|
56
|
+
requireLpUserOp(Number.isSafeInteger(now) && now > 0, 'LP_USEROP_CLOCK');
|
|
57
|
+
return now;
|
|
58
|
+
}
|
|
59
|
+
/** Preserve the canonical library's EIP-1898 request objects through viem's custom RPC schema. */
|
|
60
|
+
export function lpUserOpProtocolClient(client) {
|
|
61
|
+
return {
|
|
62
|
+
request: (request) => client.request({ method: request.method, params: request.params }),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export function lpUserOpProtocol(runtime, envelope) {
|
|
66
|
+
const policy = reviewedGuardPolicy(runtime.guardDeployments);
|
|
67
|
+
const finality = lpV3FinalityPolicySchema.parse(runtime.finalityPolicy);
|
|
68
|
+
if (envelope)
|
|
69
|
+
requireLpUserOp(hybridYieldCommitment(finality) === hybridYieldCommitment(envelope.finalityPolicy) &&
|
|
70
|
+
policy.some((guard) => protocolCommitment(guard) === protocolCommitment(envelope.terms.guardDeployment)), 'LP_USEROP_HOST_POLICY_CHANGED');
|
|
71
|
+
return createLpV3CollectProtocolLibrary({ guardDeployments: policy });
|
|
72
|
+
}
|
|
73
|
+
function startLpReadSpan(runtime) {
|
|
74
|
+
const monotonicMs = performance.now(), wallMs = lpUserOpNow(runtime);
|
|
75
|
+
requireLpUserOp(Number.isFinite(monotonicMs) && monotonicMs >= 0, 'LP_USEROP_CLOCK');
|
|
76
|
+
return { wallMs, monotonicMs };
|
|
77
|
+
}
|
|
78
|
+
function finishLpReadSpan(runtime, start) {
|
|
79
|
+
const wallMs = lpUserOpNow(runtime), monotonicMs = performance.now();
|
|
80
|
+
requireLpUserOp(wallMs >= start.wallMs && Number.isFinite(monotonicMs) && monotonicMs >= start.monotonicMs, 'LP_USEROP_CLOCK');
|
|
81
|
+
return {
|
|
82
|
+
wallMs,
|
|
83
|
+
monotonicMs,
|
|
84
|
+
effectiveMs: Math.max(wallMs, start.wallMs + monotonicMs - start.monotonicMs),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** Bound every awaited read phase with both clocks; event-loop pauses cannot bypass the timer. */
|
|
88
|
+
export async function boundedLpUserOpRead(runtime, work) {
|
|
89
|
+
const started = startLpReadSpan(runtime), duration = lpV3FinalityPolicySchema.parse(runtime.finalityPolicy).maxReadDurationSeconds * 1000;
|
|
90
|
+
let timer;
|
|
91
|
+
try {
|
|
92
|
+
const result = await Promise.race([
|
|
93
|
+
work(),
|
|
94
|
+
new Promise((_, reject) => {
|
|
95
|
+
timer = setTimeout(() => reject(new LpUserOpError('LP_USEROP_READ_TIMEOUT')), duration);
|
|
96
|
+
}),
|
|
97
|
+
]);
|
|
98
|
+
const finished = finishLpReadSpan(runtime, started);
|
|
99
|
+
requireLpUserOp(finished.effectiveMs - started.wallMs <= duration, 'LP_USEROP_READ_STALE');
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
if (timer)
|
|
104
|
+
clearTimeout(timer);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function recipe(input, terms) {
|
|
108
|
+
return [
|
|
109
|
+
{
|
|
110
|
+
step: 'nft-approve',
|
|
111
|
+
to: input.manager,
|
|
112
|
+
data: encodeFunctionData({
|
|
113
|
+
abi: LP_V3_ATOMIC_NPM_ABI,
|
|
114
|
+
functionName: 'approve',
|
|
115
|
+
args: [getAddress(terms.guardDeployment.address), BigInt(input.tokenId)],
|
|
116
|
+
}),
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
step: 'mutation',
|
|
120
|
+
to: terms.guardDeployment.address,
|
|
121
|
+
data: encodeFunctionData({
|
|
122
|
+
abi: LP_V3_COLLECT_GUARD_ABI,
|
|
123
|
+
functionName: 'collect',
|
|
124
|
+
args: [
|
|
125
|
+
{
|
|
126
|
+
owner: getAddress(input.account),
|
|
127
|
+
pool: getAddress(input.pool),
|
|
128
|
+
tokenId: BigInt(input.tokenId),
|
|
129
|
+
tickLower: input.tickLower,
|
|
130
|
+
tickUpper: input.tickUpper,
|
|
131
|
+
amount0Max: BigInt(input.amountMax[0]),
|
|
132
|
+
amount1Max: BigInt(input.amountMax[1]),
|
|
133
|
+
amount0Min: BigInt(input.amountMin[0]),
|
|
134
|
+
amount1Min: BigInt(input.amountMin[1]),
|
|
135
|
+
deadline: BigInt(input.deadline),
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
}),
|
|
139
|
+
},
|
|
140
|
+
];
|
|
141
|
+
}
|
|
142
|
+
/** Durable-record validation is not freshness, transport, execution or claim-release authority. */
|
|
143
|
+
export function assertLpUserOpEnvelope(raw) {
|
|
144
|
+
const envelope = LP_USEROP_ENVELOPE_SCHEMA.parse(raw);
|
|
145
|
+
const { commitment, ...core } = envelope, { input, plan, terms, baseline, check } = envelope;
|
|
146
|
+
requireLpUserOp(hybridYieldCommitment(core) === commitment, 'LP_USEROP_TAMPERED');
|
|
147
|
+
requireLpUserOp(protocolCommitment(envelope.finalityPolicy) === protocolCommitment(terms.finalityPolicy), 'LP_USEROP_FINALITY_POLICY');
|
|
148
|
+
const { planCommitment, ...planCore } = plan, { checkCommitment, ...checkCore } = check;
|
|
149
|
+
requireLpUserOp(protocolCommitment(planCore) === planCommitment &&
|
|
150
|
+
protocolCommitment(checkCore) === checkCommitment, 'LP_USEROP_PROTOCOL_SEAL');
|
|
151
|
+
requireLpUserOp(protocolCommitment(input) === terms.intentCommitment &&
|
|
152
|
+
terms.intentCommitment === plan.intentCommitment &&
|
|
153
|
+
protocolCommitment(input) === protocolCommitment(plan.intent) &&
|
|
154
|
+
same(input.account, terms.account) &&
|
|
155
|
+
input.recipient === input.account &&
|
|
156
|
+
protocolCommitment(plan.guardDeployment) === protocolCommitment(terms.guardDeployment) &&
|
|
157
|
+
input.guardDeploymentId === terms.guardDeployment.id &&
|
|
158
|
+
input.chainId === terms.chainId &&
|
|
159
|
+
input.amountMax.every((amount, i) => BigInt(amount) <= BigInt(terms.maximumCollectAtomic[i])) &&
|
|
160
|
+
check.planCommitment === plan.planCommitment &&
|
|
161
|
+
check.intentCommitment === plan.intentCommitment &&
|
|
162
|
+
check.policyCommitment === plan.policyCommitment &&
|
|
163
|
+
check.baselineCommitment === protocolCommitment(baseline) &&
|
|
164
|
+
plan.preparedObservationCommitment === protocolCommitment(baseline) &&
|
|
165
|
+
plan.preparedBlock.number === baseline.blockNumber &&
|
|
166
|
+
plan.preparedBlock.hash === baseline.blockHash &&
|
|
167
|
+
check.checkedAt === Math.floor(envelope.preparedAtMs / 1000) &&
|
|
168
|
+
envelope.preparedAtMs >= terms.reviewCreatedAtMs &&
|
|
169
|
+
envelope.validUntilMs === Math.min(input.deadline * 1000, terms.reviewExpiresAtMs) &&
|
|
170
|
+
envelope.validUntilMs > envelope.preparedAtMs &&
|
|
171
|
+
baseline.position.approved === terms.initialNftApproval, 'LP_USEROP_BINDING');
|
|
172
|
+
const expected = recipe(input, terms);
|
|
173
|
+
requireLpUserOp(plan.calls.every((call, i) => call.step === expected[i].step &&
|
|
174
|
+
call.tokenIndex === null &&
|
|
175
|
+
call.chainId === terms.chainId &&
|
|
176
|
+
same(call.from, terms.account) &&
|
|
177
|
+
same(call.to, expected[i].to) &&
|
|
178
|
+
call.value === '0' &&
|
|
179
|
+
same(call.data, expected[i].data)), 'LP_USEROP_RECIPE');
|
|
180
|
+
// Replaying the record's policy proves integrity only. Fresh verification separately requires HOST policy.
|
|
181
|
+
const restored = createLpV3CollectProtocolLibrary({
|
|
182
|
+
guardDeployments: [terms.guardDeployment],
|
|
183
|
+
}).validatePrepared(plan, input, baseline, { now: () => check.checkedAt });
|
|
184
|
+
requireLpUserOp(protocolCommitment(restored) === protocolCommitment(check), 'LP_USEROP_PROTOCOL_CHECK');
|
|
185
|
+
return freezeHybridValue(envelope);
|
|
186
|
+
}
|
|
187
|
+
export async function assertLpUserOpAccountState(runtime, terms, blockNumber, blockHash) {
|
|
188
|
+
await assertSponsoredAccountProfile(runtime.client, LP_USEROP_TERMS_SCHEMA.parse(terms), blockNumber, blockHash, [
|
|
189
|
+
{
|
|
190
|
+
address: getAddress(terms.guardDeployment.address),
|
|
191
|
+
codeHash: terms.guardDeployment.runtimeCodeHash,
|
|
192
|
+
},
|
|
193
|
+
...['factory', 'manager', 'token0', 'token1', 'usdcImplementation'].map((key) => ({
|
|
194
|
+
address: getAddress(LP_V3_BASE[key]),
|
|
195
|
+
codeHash: LP_V3_BASE[`${key}CodeHash`],
|
|
196
|
+
})),
|
|
197
|
+
]);
|
|
198
|
+
}
|
|
199
|
+
function assertFresh(envelope, now) {
|
|
200
|
+
requireLpUserOp(now >= envelope.terms.reviewCreatedAtMs &&
|
|
201
|
+
now >= envelope.preparedAtMs &&
|
|
202
|
+
now < envelope.validUntilMs, 'LP_USEROP_EXPIRED');
|
|
203
|
+
}
|
|
204
|
+
export async function prepareLpUserOp(runtime, rawInput, independentTerms) {
|
|
205
|
+
return boundedLpUserOpRead(runtime, async () => {
|
|
206
|
+
const input = lpV3CollectProtocolIntentSchema.parse(rawInput), terms = LP_USEROP_TERMS_SCHEMA.parse(independentTerms);
|
|
207
|
+
const now = lpUserOpNow(runtime), finalityPolicy = lpV3FinalityPolicySchema.parse(runtime.finalityPolicy);
|
|
208
|
+
requireLpUserOp(now >= terms.reviewCreatedAtMs &&
|
|
209
|
+
now < terms.reviewExpiresAtMs &&
|
|
210
|
+
protocolCommitment(input) === terms.intentCommitment, 'LP_USEROP_REVIEW');
|
|
211
|
+
const protocol = lpUserOpProtocol(runtime);
|
|
212
|
+
const baseline = await protocol.collectProtocolEvidence(input, {
|
|
213
|
+
client: lpUserOpProtocolClient(runtime.client),
|
|
214
|
+
nowSeconds: () => Math.floor(lpUserOpNow(runtime) / 1000),
|
|
215
|
+
maxBlockAgeSeconds: finalityPolicy.maxHeadAgeSeconds,
|
|
216
|
+
maxReadDurationSeconds: finalityPolicy.maxReadDurationSeconds,
|
|
217
|
+
});
|
|
218
|
+
await assertLpUserOpAccountState(runtime, terms, BigInt(baseline.blockNumber), baseline.blockHash);
|
|
219
|
+
const preparedAtMs = lpUserOpNow(runtime), options = { now: () => Math.floor(preparedAtMs / 1000) };
|
|
220
|
+
const plan = protocol.prepare(input, baseline, options);
|
|
221
|
+
const check = protocol.validatePrepared(plan, input, baseline, options);
|
|
222
|
+
const core = {
|
|
223
|
+
version: 1,
|
|
224
|
+
kind: 'lp-collect-userop',
|
|
225
|
+
input,
|
|
226
|
+
plan,
|
|
227
|
+
baseline,
|
|
228
|
+
check,
|
|
229
|
+
terms,
|
|
230
|
+
finalityPolicy,
|
|
231
|
+
preparedAtMs,
|
|
232
|
+
validUntilMs: Math.min(input.deadline * 1000, terms.reviewExpiresAtMs),
|
|
233
|
+
};
|
|
234
|
+
const envelope = assertLpUserOpEnvelope({ ...core, commitment: hybridYieldCommitment(core) });
|
|
235
|
+
lpUserOpProtocol(runtime, envelope);
|
|
236
|
+
assertFresh(envelope, lpUserOpNow(runtime));
|
|
237
|
+
return envelope;
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
export async function verifyLpUserOp(runtime, rawEnvelope, independentTerms) {
|
|
241
|
+
return boundedLpUserOpRead(runtime, async () => {
|
|
242
|
+
const envelope = assertLpUserOpEnvelope(rawEnvelope), terms = LP_USEROP_TERMS_SCHEMA.parse(independentTerms);
|
|
243
|
+
requireLpUserOp(hybridYieldCommitment(terms) === hybridYieldCommitment(envelope.terms), 'LP_USEROP_REVIEW_CHANGED');
|
|
244
|
+
assertFresh(envelope, lpUserOpNow(runtime));
|
|
245
|
+
const readSpan = startLpReadSpan(runtime);
|
|
246
|
+
const protocol = lpUserOpProtocol(runtime, envelope), policy = envelope.finalityPolicy;
|
|
247
|
+
const baseline = await protocol.collectProtocolEvidence(envelope.input, {
|
|
248
|
+
client: lpUserOpProtocolClient(runtime.client),
|
|
249
|
+
nowSeconds: () => Math.floor(lpUserOpNow(runtime) / 1000),
|
|
250
|
+
maxBlockAgeSeconds: policy.maxHeadAgeSeconds,
|
|
251
|
+
maxReadDurationSeconds: policy.maxReadDurationSeconds,
|
|
252
|
+
});
|
|
253
|
+
await assertLpUserOpAccountState(runtime, terms, BigInt(baseline.blockNumber), baseline.blockHash);
|
|
254
|
+
// Preserve elapsed protocol/profile read time even when the wall clock stalls.
|
|
255
|
+
const finished = finishLpReadSpan(runtime, readSpan), verifiedAtMs = finished.wallMs;
|
|
256
|
+
const check = protocol.validatePrepared(envelope.plan, envelope.input, baseline, {
|
|
257
|
+
now: () => Math.floor(verifiedAtMs / 1000),
|
|
258
|
+
});
|
|
259
|
+
assertFresh(envelope, finished.effectiveMs);
|
|
260
|
+
const result = freezeHybridValue({ envelope, verificationOnly: true });
|
|
261
|
+
verified.set(result, freezeHybridValue(LP_USEROP_VERIFICATION_EVIDENCE_SCHEMA.parse({ baseline, check, verifiedAtMs })));
|
|
262
|
+
verifiedReadTime.set(result, {
|
|
263
|
+
monotonicAtMs: finished.monotonicMs,
|
|
264
|
+
effectiveAtMs: finished.effectiveMs,
|
|
265
|
+
});
|
|
266
|
+
assertFreshVerifiedLpUserOp(result, verifiedAtMs);
|
|
267
|
+
return result;
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
export function assertVerifiedLpUserOp(value) {
|
|
271
|
+
requireLpUserOp(value && verified.has(value) && Object.isFrozen(value), 'LP_USEROP_UNVERIFIED');
|
|
272
|
+
return value.envelope;
|
|
273
|
+
}
|
|
274
|
+
/** Final read-age boundary after every blocking writer lock and immediately before provider start. */
|
|
275
|
+
export function assertFreshVerifiedLpUserOp(value, nowMs) {
|
|
276
|
+
const envelope = assertVerifiedLpUserOp(value), evidence = verified.get(value);
|
|
277
|
+
const facts = verifiedReadTime.get(value), monotonicNow = performance.now();
|
|
278
|
+
requireLpUserOp(Number.isSafeInteger(nowMs) &&
|
|
279
|
+
nowMs >= evidence.verifiedAtMs &&
|
|
280
|
+
facts !== undefined &&
|
|
281
|
+
Number.isFinite(facts.monotonicAtMs) &&
|
|
282
|
+
Number.isFinite(monotonicNow) &&
|
|
283
|
+
monotonicNow >= facts.monotonicAtMs, 'LP_USEROP_CLOCK');
|
|
284
|
+
const current = Math.max(nowMs, facts.effectiveAtMs + monotonicNow - facts.monotonicAtMs);
|
|
285
|
+
assertFresh(envelope, current);
|
|
286
|
+
const observedAtMs = evidence.baseline.observedAt * 1000, blockTimestampMs = evidence.baseline.blockTimestamp * 1000;
|
|
287
|
+
const maxHeadAgeMs = envelope.finalityPolicy.maxHeadAgeSeconds * 1000;
|
|
288
|
+
// The canonical protocol limits observation age to 30 seconds; host policy may tighten block age further.
|
|
289
|
+
requireLpUserOp(Number.isSafeInteger(observedAtMs) &&
|
|
290
|
+
Number.isSafeInteger(blockTimestampMs) &&
|
|
291
|
+
blockTimestampMs <= observedAtMs &&
|
|
292
|
+
observedAtMs <= evidence.verifiedAtMs &&
|
|
293
|
+
current - observedAtMs <= Math.min(30_000, maxHeadAgeMs) &&
|
|
294
|
+
current - blockTimestampMs <= maxHeadAgeMs, 'LP_USEROP_READ_STALE');
|
|
295
|
+
}
|
|
296
|
+
export function lpUserOpVerificationEvidence(value) {
|
|
297
|
+
assertVerifiedLpUserOp(value);
|
|
298
|
+
return verified.get(value);
|
|
299
|
+
}
|
|
300
|
+
export function lpUserOpCalls(value) {
|
|
301
|
+
return lpUserOpRecordedCalls(assertVerifiedLpUserOp(value));
|
|
302
|
+
}
|
|
303
|
+
/** Exact persisted request reconstruction after Stop or expiry; conveys no new sending authority. */
|
|
304
|
+
export function lpUserOpRecordedCalls(rawEnvelope) {
|
|
305
|
+
return freezeHybridValue(assertLpUserOpEnvelope(rawEnvelope).plan.calls.map((call) => ({
|
|
306
|
+
to: call.to.toLowerCase(),
|
|
307
|
+
data: call.data.toLowerCase(),
|
|
308
|
+
value: '0',
|
|
309
|
+
})));
|
|
310
|
+
}
|
|
311
|
+
export function lpUserOpBatchData(envelope) {
|
|
312
|
+
return encodeFunctionData({
|
|
313
|
+
abi: LP_USEROP_BATCH_ABI,
|
|
314
|
+
functionName: 'executeBatch',
|
|
315
|
+
args: [
|
|
316
|
+
lpUserOpRecordedCalls(envelope).map((call) => ({
|
|
317
|
+
target: getAddress(call.to),
|
|
318
|
+
value: 0n,
|
|
319
|
+
data: call.data,
|
|
320
|
+
})),
|
|
321
|
+
],
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
/** Entire reviewed executeBatch, called from the EntryPoint at the verified block, without overrides. */
|
|
325
|
+
export async function simulateLpUserOp(runtime, envelope, independentTerms) {
|
|
326
|
+
return boundedLpUserOpRead(runtime, async () => {
|
|
327
|
+
const before = await verifyLpUserOp(runtime, envelope, independentTerms), evidence = lpUserOpVerificationEvidence(before);
|
|
328
|
+
const reviewed = assertVerifiedLpUserOp(before);
|
|
329
|
+
await runtime.client.call({
|
|
330
|
+
account: reviewed.terms.entryPoint,
|
|
331
|
+
to: reviewed.terms.account,
|
|
332
|
+
value: 0n,
|
|
333
|
+
data: lpUserOpBatchData(reviewed),
|
|
334
|
+
blockNumber: BigInt(evidence.baseline.blockNumber),
|
|
335
|
+
});
|
|
336
|
+
requireLpUserOp((await runtime.client.getBlock({ blockNumber: BigInt(evidence.baseline.blockNumber) }))
|
|
337
|
+
.hash === evidence.baseline.blockHash, 'LP_USEROP_SIMULATION_REORG');
|
|
338
|
+
const after = await verifyLpUserOp(runtime, reviewed, reviewed.terms);
|
|
339
|
+
requireLpUserOp(lpUserOpVerificationEvidence(after).baseline.blockHash === evidence.baseline.blockHash, 'LP_USEROP_SIMULATION_STATE_CHANGED');
|
|
340
|
+
return after;
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
//# sourceMappingURL=lp-userop.js.map
|