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,162 @@
|
|
|
1
|
+
import { decodeEventLog, decodeFunctionData, parseAbi } from 'viem';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { canonicalJson, deepFreeze, lpAddress, lpHash, lpUint, LP_V3_BASE as B } from './lp-v3-contract.js';
|
|
4
|
+
import { LP_V3_COLLECT_GUARD_ABI, lpV3AtomicChainEvidenceSchema } from './lp-v3-atomic-contract.js';
|
|
5
|
+
import { requireLpV3AtomicSettlementContext } from './lp-v3-atomic-plan.js';
|
|
6
|
+
const ZERO = '0x0000000000000000000000000000000000000000';
|
|
7
|
+
const NPM_EVENTS = parseAbi([
|
|
8
|
+
'event Approval(address indexed owner,address indexed approved,uint256 indexed tokenId)',
|
|
9
|
+
'event Transfer(address indexed from,address indexed to,uint256 indexed tokenId)',
|
|
10
|
+
'event IncreaseLiquidity(uint256 indexed tokenId,uint128 liquidity,uint256 amount0,uint256 amount1)',
|
|
11
|
+
'event Collect(uint256 indexed tokenId,address recipient,uint256 amount0,uint256 amount1)',
|
|
12
|
+
]);
|
|
13
|
+
const TOKEN_ABI = parseAbi([
|
|
14
|
+
'function approve(address spender,uint256 amount) returns (bool)',
|
|
15
|
+
'event Approval(address indexed owner,address indexed spender,uint256 value)',
|
|
16
|
+
'event Transfer(address indexed from,address indexed to,uint256 value)',
|
|
17
|
+
]);
|
|
18
|
+
const logSchema = z.object({ address: lpAddress, topics: z.array(z.string().regex(/^0x[0-9a-f]{64}$/)).min(1).max(4), data: z.string().regex(/^0x(?:[0-9a-f]{2})*$/), logIndex: z.number().int().nonnegative() }).strict();
|
|
19
|
+
const receiptSchema = z.object({
|
|
20
|
+
chainId: z.literal(8453), transactionHash: lpHash, blockHash: lpHash, blockNumber: lpUint(),
|
|
21
|
+
blockTimestamp: z.number().int().positive().safe(), transactionIndex: z.number().int().nonnegative(),
|
|
22
|
+
canonical: z.literal(true), status: z.literal('success'), from: lpAddress, to: lpAddress,
|
|
23
|
+
input: z.string().regex(/^0x[0-9a-f]+$/), value: z.literal('0'), logs: z.array(logSchema),
|
|
24
|
+
}).strict();
|
|
25
|
+
export const lpV3AtomicSettlementEvidenceSchema = z.object({
|
|
26
|
+
schemaVersion: z.literal(2), planCommitment: lpHash,
|
|
27
|
+
receipts: z.array(receiptSchema).min(2).max(5), post: lpV3AtomicChainEvidenceSchema,
|
|
28
|
+
}).strict();
|
|
29
|
+
const decodeNpm = (l) => decodeEventLog({ abi: NPM_EVENTS, topics: l.topics, data: l.data, strict: true });
|
|
30
|
+
const decodeToken = (l) => decodeEventLog({ abi: TOKEN_ABI, topics: l.topics, data: l.data, strict: true });
|
|
31
|
+
const raw = (pair) => [pair[0].toString(), pair[1].toString()];
|
|
32
|
+
/** The protected host supplies independently collected, journal-bound transactions
|
|
33
|
+
* and canonical logs/post-state. No client assertion is a receipt or finality proof.
|
|
34
|
+
*/
|
|
35
|
+
export function verifyLpV3AtomicSettlement(context, input, policy, options = {}) {
|
|
36
|
+
requireLpV3AtomicSettlementContext(context, policy);
|
|
37
|
+
const evidence = lpV3AtomicSettlementEvidenceSchema.parse(input), { plan, evidence: before } = context;
|
|
38
|
+
const intent = plan.intent, post = evidence.post, now = (options.now ?? (() => Math.floor(Date.now() / 1000)))();
|
|
39
|
+
if (!Number.isSafeInteger(now) || now <= 0)
|
|
40
|
+
throw new Error('LP_ATOMIC_INVALID_CLOCK');
|
|
41
|
+
if (evidence.planCommitment !== plan.planCommitment || evidence.receipts.length !== plan.calls.length)
|
|
42
|
+
throw new Error('LP_ATOMIC_INCOMPLETE_OPERATION');
|
|
43
|
+
// Historical reconciliation may read a finalized historical post-block today.
|
|
44
|
+
// Its canonical observation must still be fresh, and the context cannot sign.
|
|
45
|
+
if (post.observedAt > now || now - post.observedAt > 30 || post.blockTimestamp > post.observedAt || (context.purpose === 'execute' && now - post.blockTimestamp > 60))
|
|
46
|
+
throw new Error('LP_ATOMIC_STALE_SETTLEMENT');
|
|
47
|
+
const p = post.position;
|
|
48
|
+
if (post.account !== intent.account || post.pool !== intent.pool || post.factoryPool !== intent.pool || post.fee !== intent.fee || post.allowances.some(v => v !== '0') || p.tokenId !== intent.tokenId || p.owner !== intent.account || p.token0 !== intent.token0 || p.token1 !== intent.token1 || p.fee !== intent.fee || p.tickLower !== intent.tickLower || p.tickUpper !== intent.tickUpper || p.approved !== ZERO)
|
|
49
|
+
throw new Error('LP_ATOMIC_POST_IDENTITY_OR_APPROVAL_MISMATCH');
|
|
50
|
+
if (intent.action === 'increase') {
|
|
51
|
+
if (post.guard !== null)
|
|
52
|
+
throw new Error('LP_ATOMIC_UNEXPECTED_GUARD');
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const a = before.guard, b = post.guard, deployment = plan.guardDeployment;
|
|
56
|
+
if (!a || !b || !deployment || b.address !== deployment.address || b.runtimeCodeHash !== deployment.runtimeCodeHash || b.configurationHash !== deployment.configurationHash || canonicalJson(b.tokenBalances) !== canonicalJson(a.tokenBalances))
|
|
57
|
+
throw new Error('LP_ATOMIC_GUARD_POST_STATE_MISMATCH');
|
|
58
|
+
}
|
|
59
|
+
const hashes = new Set();
|
|
60
|
+
let previous;
|
|
61
|
+
for (const [index, r] of evidence.receipts.entries()) {
|
|
62
|
+
const call = plan.calls[index];
|
|
63
|
+
if (r.from !== call.from || r.to !== call.to || r.input !== call.data || r.value !== call.value || hashes.has(r.transactionHash))
|
|
64
|
+
throw new Error('LP_ATOMIC_RECEIPT_CALL_MISMATCH');
|
|
65
|
+
hashes.add(r.transactionHash);
|
|
66
|
+
if (r.blockTimestamp < context.verifiedAt || r.blockTimestamp > post.blockTimestamp || BigInt(r.blockNumber) < BigInt(before.blockNumber) || BigInt(r.blockNumber) > BigInt(post.blockNumber))
|
|
67
|
+
throw new Error('LP_ATOMIC_RECEIPT_BLOCK_MISMATCH');
|
|
68
|
+
if ((r.blockNumber === before.blockNumber && r.blockHash !== before.blockHash) || (r.blockNumber === post.blockNumber && r.blockHash !== post.blockHash))
|
|
69
|
+
throw new Error('LP_ATOMIC_RECEIPT_BLOCK_MISMATCH');
|
|
70
|
+
if (previous && (BigInt(r.blockNumber) < BigInt(previous.blockNumber) || (r.blockNumber === previous.blockNumber && (r.blockHash !== previous.blockHash || r.transactionIndex <= previous.transactionIndex))))
|
|
71
|
+
throw new Error('LP_ATOMIC_RECEIPT_ORDER_MISMATCH');
|
|
72
|
+
previous = r;
|
|
73
|
+
if (call.step !== 'erc20-cleanup' && r.blockTimestamp > intent.deadline)
|
|
74
|
+
throw new Error('LP_ATOMIC_LATE_OPERATION');
|
|
75
|
+
if (r.logs.some((l, i) => i > 0 && l.logIndex <= r.logs[i - 1].logIndex))
|
|
76
|
+
throw new Error('LP_ATOMIC_LOG_ORDER_MISMATCH');
|
|
77
|
+
if (call.step !== 'mutation') {
|
|
78
|
+
const npm = r.logs.filter(l => l.address === B.manager).map(decodeNpm);
|
|
79
|
+
const tokens = r.logs.filter(l => l.address === B.token0 || l.address === B.token1).map(l => ({ log: l, event: decodeToken(l) }));
|
|
80
|
+
if (tokens.some(t => t.event.eventName === 'Transfer') || r.logs.some(l => l.address === plan.guardDeployment?.address))
|
|
81
|
+
throw new Error('LP_ATOMIC_UNEXPECTED_APPROVAL_TRANSFER');
|
|
82
|
+
if (call.step === 'nft-approve') {
|
|
83
|
+
if (npm.length !== 1 || npm[0].eventName !== 'Approval' || npm[0].args.owner.toLowerCase() !== intent.account || npm[0].args.approved.toLowerCase() !== plan.guardDeployment.address || npm[0].args.tokenId.toString() !== intent.tokenId || tokens.length !== 0)
|
|
84
|
+
throw new Error('LP_ATOMIC_NFT_APPROVAL_RECEIPT_MISMATCH');
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
const decoded = decodeFunctionData({ abi: TOKEN_ABI, data: call.data });
|
|
88
|
+
if (npm.length || tokens.length !== 1 || tokens[0].log.address !== call.to || tokens[0].event.eventName !== 'Approval' || tokens[0].event.args.owner.toLowerCase() !== intent.account || tokens[0].event.args.spender.toLowerCase() !== B.manager || tokens[0].event.args.value !== decoded.args[1])
|
|
89
|
+
throw new Error('LP_ATOMIC_ERC20_APPROVAL_RECEIPT_MISMATCH');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const receipt = evidence.receipts[plan.calls.findIndex(c => c.step === 'mutation')];
|
|
94
|
+
const npmLogs = receipt.logs.filter(l => l.address === B.manager), npm = npmLogs.map(decodeNpm);
|
|
95
|
+
const names = npm.map(e => e.eventName);
|
|
96
|
+
const expected = intent.action === 'increase' ? ['Approval', 'Transfer', 'IncreaseLiquidity', 'Approval', 'Transfer'] : ['Collect', 'Approval', 'Transfer'];
|
|
97
|
+
if (canonicalJson(names) !== canonicalJson(expected))
|
|
98
|
+
throw new Error('LP_ATOMIC_NFT_GUARD_EVENT_SEQUENCE_MISMATCH');
|
|
99
|
+
for (const e of npm) {
|
|
100
|
+
if (e.args.tokenId.toString() !== intent.tokenId)
|
|
101
|
+
throw new Error('LP_ATOMIC_EVENT_NFT_MISMATCH');
|
|
102
|
+
if (e.eventName === 'Approval' && (e.args.owner.toLowerCase() !== intent.account || e.args.approved !== ZERO))
|
|
103
|
+
throw new Error('LP_ATOMIC_NFT_CLEANUP_UNPROVEN');
|
|
104
|
+
if (e.eventName === 'Transfer' && (e.args.from.toLowerCase() !== intent.account || e.args.to.toLowerCase() !== intent.account))
|
|
105
|
+
throw new Error('LP_ATOMIC_OWNER_GUARD_UNPROVEN');
|
|
106
|
+
}
|
|
107
|
+
const spent = [0n, 0n], received = [0n, 0n];
|
|
108
|
+
for (const l of receipt.logs) {
|
|
109
|
+
const i = l.address === B.token0 ? 0 : l.address === B.token1 ? 1 : null;
|
|
110
|
+
if (i === null)
|
|
111
|
+
continue;
|
|
112
|
+
const e = decodeToken(l);
|
|
113
|
+
if (e.eventName !== 'Transfer')
|
|
114
|
+
throw new Error('LP_ATOMIC_UNEXPECTED_TOKEN_APPROVAL');
|
|
115
|
+
const from = e.args.from.toLowerCase(), to = e.args.to.toLowerCase();
|
|
116
|
+
if (from === intent.account) {
|
|
117
|
+
if (to !== intent.pool)
|
|
118
|
+
throw new Error('LP_ATOMIC_UNEXPECTED_TOKEN_DESTINATION');
|
|
119
|
+
spent[i] += e.args.value;
|
|
120
|
+
}
|
|
121
|
+
if (to === intent.account) {
|
|
122
|
+
if (from !== intent.pool)
|
|
123
|
+
throw new Error('LP_ATOMIC_UNEXPECTED_TOKEN_SOURCE');
|
|
124
|
+
received[i] += e.args.value;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
let liquidityDelta = 0n;
|
|
128
|
+
if (intent.action === 'increase') {
|
|
129
|
+
const e = npm[2];
|
|
130
|
+
if (e.eventName !== 'IncreaseLiquidity' || e.args.liquidity <= 0n)
|
|
131
|
+
throw new Error('LP_ATOMIC_LIQUIDITY_INCREASE_UNPROVEN');
|
|
132
|
+
liquidityDelta = e.args.liquidity;
|
|
133
|
+
const amounts = [e.args.amount0, e.args.amount1];
|
|
134
|
+
for (const i of [0, 1])
|
|
135
|
+
if (amounts[i] !== spent[i] || received[i] !== 0n || spent[i] < BigInt(intent.amountMin[i]) || spent[i] > BigInt(intent.amountDesired[i]) || BigInt(p.tokensOwed[i]) < BigInt(before.position.tokensOwed[i]))
|
|
136
|
+
throw new Error('LP_ATOMIC_DEPOSIT_RECONCILIATION_FAILED');
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
const e = npm[0];
|
|
140
|
+
const guards = receipt.logs.filter(l => l.address === plan.guardDeployment.address);
|
|
141
|
+
if (e.eventName !== 'Collect' || e.args.recipient.toLowerCase() !== intent.account || guards.length !== 1 || guards[0].logIndex <= npmLogs.at(-1).logIndex)
|
|
142
|
+
throw new Error('LP_ATOMIC_COLLECTION_EVENT_MISMATCH');
|
|
143
|
+
const g = decodeEventLog({ abi: LP_V3_COLLECT_GUARD_ABI, topics: guards[0].topics, data: guards[0].data, strict: true });
|
|
144
|
+
if (g.args.owner.toLowerCase() !== intent.account || g.args.pool.toLowerCase() !== intent.pool || g.args.tokenId.toString() !== intent.tokenId)
|
|
145
|
+
throw new Error('LP_ATOMIC_COLLECTION_BINDING_MISMATCH');
|
|
146
|
+
const actual = [g.args.amount0, g.args.amount1], owedCollection = [e.args.amount0, e.args.amount1];
|
|
147
|
+
for (const i of [0, 1]) {
|
|
148
|
+
if (spent[i] !== 0n || received[i] !== actual[i] || actual[i] < BigInt(intent.amountMin[i]) || actual[i] > BigInt(intent.amountMax[i]) || owedCollection[i] < actual[i] || owedCollection[i] > BigInt(intent.amountMax[i]))
|
|
149
|
+
throw new Error('LP_ATOMIC_COLLECTION_RECONCILIATION_FAILED');
|
|
150
|
+
const priorOwed = BigInt(before.position.tokensOwed[i]), remaining = priorOwed - owedCollection[i];
|
|
151
|
+
if (before.position.liquidity === '0' ? remaining < 0n || BigInt(p.tokensOwed[i]) !== remaining : BigInt(p.tokensOwed[i]) < (remaining > 0n ? remaining : 0n))
|
|
152
|
+
throw new Error('LP_ATOMIC_OWED_BALANCE_MISMATCH');
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (BigInt(p.liquidity) !== BigInt(before.position.liquidity) + liquidityDelta)
|
|
156
|
+
throw new Error('LP_ATOMIC_POST_LIQUIDITY_MISMATCH');
|
|
157
|
+
for (const i of [0, 1])
|
|
158
|
+
if (BigInt(post.balances[i]) !== BigInt(before.balances[i]) - spent[i] + received[i])
|
|
159
|
+
throw new Error('LP_ATOMIC_POST_BALANCE_MISMATCH');
|
|
160
|
+
return deepFreeze({ status: 'SETTLED', action: intent.action, planCommitment: plan.planCommitment, tokenId: intent.tokenId, depositedRaw: raw(spent), collectedRaw: raw(received), liquidityDelta: liquidityDelta.toString(), erc20AllowancesCleared: true, nftTokenApprovalCleared: true, profitClassification: 'UNKNOWN', distributableProfitRaw: null });
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=lp-v3-atomic-settlement.js.map
|