@ocap/tx-pipeline 1.30.25 → 1.31.0
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/esm/appchain-sovereign-hub.d.mts +160 -0
- package/esm/appchain-sovereign-hub.mjs +348 -0
- package/esm/arcvault-external-adapter.d.mts +166 -0
- package/esm/arcvault-external-adapter.mjs +376 -0
- package/esm/encrypted-nft-envelope.d.mts +172 -0
- package/esm/encrypted-nft-envelope.mjs +458 -0
- package/esm/evm-simplified-bridge.d.mts +1370 -0
- package/esm/evm-simplified-bridge.mjs +3875 -0
- package/esm/give-to-mint-karma.d.mts +472 -0
- package/esm/give-to-mint-karma.mjs +1057 -0
- package/esm/helpers/replay-guard.d.mts +15 -0
- package/esm/helpers/replay-guard.mjs +23 -0
- package/esm/index.d.mts +10 -5
- package/esm/index.mjs +14 -10
- package/esm/legacy-protocol-sunset.d.mts +251 -0
- package/esm/legacy-protocol-sunset.mjs +1519 -0
- package/esm/library.d.mts +16 -0
- package/esm/library.mjs +17 -0
- package/esm/native-abt-exchange.d.mts +2055 -0
- package/esm/native-abt-exchange.mjs +7250 -0
- package/esm/ofac-screening.d.mts +17 -0
- package/esm/ofac-screening.mjs +39 -0
- package/esm/pipes/anti-land-attack.mjs +1 -1
- package/esm/pipes/decode-itx.mjs +43 -4
- package/esm/pipes/decode-tx.d.mts +2 -3
- package/esm/pipes/decode-tx.mjs +53 -115
- package/esm/pipes/extract-signer.mjs +2 -2
- package/esm/pipes/extract-state.mjs +14 -3
- package/esm/pipes/post-execution-invariant-gate.d.mts +61 -0
- package/esm/pipes/post-execution-invariant-gate.mjs +789 -0
- package/esm/pipes/pre-flight-waf.d.mts +34 -0
- package/esm/pipes/pre-flight-waf.mjs +603 -0
- package/esm/pipes/take-state-snapshot.mjs +3 -2
- package/esm/pipes/update-owner.mjs +39 -4
- package/esm/pipes/verify-account-migration.mjs +14 -4
- package/esm/pipes/verify-blocked.mjs +1 -1
- package/esm/pipes/verify-delegation.d.mts +22 -3
- package/esm/pipes/verify-delegation.mjs +259 -36
- package/esm/pipes/verify-list-size.mjs +1 -1
- package/esm/pipes/verify-multisig-v2.mjs +15 -7
- package/esm/pipes/verify-multisig.mjs +15 -7
- package/esm/pipes/verify-sender.mjs +1 -1
- package/esm/pipes/verify-signature.mjs +35 -6
- package/esm/pipes/verify-signer.mjs +2 -2
- package/esm/pipes/verify-state-diff.mjs +3 -3
- package/esm/pipes/verify-token-access.mjs +1 -1
- package/esm/pipes/verify-token-balance.mjs +13 -5
- package/esm/pipes/verify-transferrable.d.mts +8 -1
- package/esm/pipes/verify-transferrable.mjs +3 -3
- package/esm/pipes/verify-tx-input.mjs +2 -2
- package/esm/pipes/verify-tx-size.mjs +46 -2
- package/esm/pipes/verify-tx.mjs +5 -7
- package/esm/pipes/verify-updater.mjs +1 -1
- package/esm/social-economy-factories.d.mts +346 -0
- package/esm/social-economy-factories.mjs +845 -0
- package/esm/super-suites-foundation.d.mts +513 -0
- package/esm/super-suites-foundation.mjs +1241 -0
- package/esm/transaction-block.d.mts +471 -0
- package/esm/transaction-block.mjs +1906 -0
- package/esm/uniswap-erc7683-solver.d.mts +201 -0
- package/esm/uniswap-erc7683-solver.mjs +321 -0
- package/esm/uniswap-lp-copilot.d.mts +113 -0
- package/esm/uniswap-lp-copilot.mjs +320 -0
- package/esm/uniswap-router.d.mts +335 -0
- package/esm/uniswap-router.mjs +578 -0
- package/esm/uniswap-token-factory-graduation.d.mts +187 -0
- package/esm/uniswap-token-factory-graduation.mjs +426 -0
- package/esm/uniswap-v4-hook.d.mts +173 -0
- package/esm/uniswap-v4-hook.mjs +517 -0
- package/lib/appchain-sovereign-hub.cjs +352 -0
- package/lib/appchain-sovereign-hub.d.cts +160 -0
- package/lib/arcvault-external-adapter.cjs +383 -0
- package/lib/arcvault-external-adapter.d.cts +166 -0
- package/lib/encrypted-nft-envelope.cjs +477 -0
- package/lib/encrypted-nft-envelope.d.cts +172 -0
- package/lib/evm-simplified-bridge.cjs +3943 -0
- package/lib/evm-simplified-bridge.d.cts +1370 -0
- package/lib/give-to-mint-karma.cjs +1084 -0
- package/lib/give-to-mint-karma.d.cts +472 -0
- package/lib/helpers/replay-guard.cjs +27 -0
- package/lib/helpers/replay-guard.d.cts +15 -0
- package/lib/index.cjs +49 -16
- package/lib/index.d.cts +10 -5
- package/lib/legacy-protocol-sunset.cjs +1543 -0
- package/lib/legacy-protocol-sunset.d.cts +251 -0
- package/lib/library.cjs +303 -0
- package/lib/library.d.cts +16 -0
- package/lib/native-abt-exchange.cjs +7322 -0
- package/lib/native-abt-exchange.d.cts +2055 -0
- package/lib/ofac-screening.cjs +42 -0
- package/lib/ofac-screening.d.cts +17 -0
- package/lib/pipes/anti-land-attack.cjs +2 -2
- package/lib/pipes/decode-itx.cjs +43 -4
- package/lib/pipes/decode-itx.d.cts +1 -1
- package/lib/pipes/decode-tx.cjs +52 -116
- package/lib/pipes/decode-tx.d.cts +3 -4
- package/lib/pipes/extract-signer.cjs +2 -2
- package/lib/pipes/extract-state.cjs +14 -3
- package/lib/pipes/post-execution-invariant-gate.cjs +800 -0
- package/lib/pipes/post-execution-invariant-gate.d.cts +61 -0
- package/lib/pipes/pre-flight-waf.cjs +616 -0
- package/lib/pipes/pre-flight-waf.d.cts +34 -0
- package/lib/pipes/take-state-snapshot.cjs +3 -2
- package/lib/pipes/update-owner.cjs +40 -5
- package/lib/pipes/update-owner.d.cts +1 -1
- package/lib/pipes/verify-account-migration.cjs +14 -4
- package/lib/pipes/verify-blocked.cjs +1 -1
- package/lib/pipes/verify-delegation.cjs +259 -36
- package/lib/pipes/verify-delegation.d.cts +22 -3
- package/lib/pipes/verify-list-size.cjs +1 -1
- package/lib/pipes/verify-multisig-v2.cjs +15 -7
- package/lib/pipes/verify-multisig.cjs +15 -7
- package/lib/pipes/verify-sender.cjs +1 -1
- package/lib/pipes/verify-service-fee.d.cts +1 -1
- package/lib/pipes/verify-signature.cjs +35 -6
- package/lib/pipes/verify-signature.d.cts +1 -1
- package/lib/pipes/verify-signer.cjs +2 -2
- package/lib/pipes/verify-state-diff.cjs +4 -4
- package/lib/pipes/verify-token-access.cjs +2 -2
- package/lib/pipes/verify-token-balance.cjs +13 -5
- package/lib/pipes/verify-transferrable.cjs +3 -3
- package/lib/pipes/verify-transferrable.d.cts +8 -1
- package/lib/pipes/verify-tx-input.cjs +3 -3
- package/lib/pipes/verify-tx-size.cjs +46 -2
- package/lib/pipes/verify-tx-size.d.cts +1 -1
- package/lib/pipes/verify-tx.cjs +6 -8
- package/lib/pipes/verify-tx.d.cts +1 -1
- package/lib/pipes/verify-updater.cjs +1 -1
- package/lib/social-economy-factories.cjs +852 -0
- package/lib/social-economy-factories.d.cts +346 -0
- package/lib/super-suites-foundation.cjs +1257 -0
- package/lib/super-suites-foundation.d.cts +513 -0
- package/lib/transaction-block.cjs +1941 -0
- package/lib/transaction-block.d.cts +471 -0
- package/lib/uniswap-erc7683-solver.cjs +327 -0
- package/lib/uniswap-erc7683-solver.d.cts +201 -0
- package/lib/uniswap-lp-copilot.cjs +328 -0
- package/lib/uniswap-lp-copilot.d.cts +113 -0
- package/lib/uniswap-router.cjs +593 -0
- package/lib/uniswap-router.d.cts +335 -0
- package/lib/uniswap-token-factory-graduation.cjs +431 -0
- package/lib/uniswap-token-factory-graduation.d.cts +187 -0
- package/lib/uniswap-v4-hook.cjs +527 -0
- package/lib/uniswap-v4-hook.d.cts +173 -0
- package/package.json +11 -10
- package/esm/helpers/dedup-height.d.mts +0 -16
- package/esm/helpers/dedup-height.mjs +0 -61
- package/lib/helpers/dedup-height.cjs +0 -72
- package/lib/helpers/dedup-height.d.cts +0 -16
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_ofac_screening = require('./ofac-screening.cjs');
|
|
3
|
+
require('./uniswap-router.cjs');
|
|
4
|
+
let _ocap_mcrypto = require("@ocap/mcrypto");
|
|
5
|
+
let _ocap_util = require("@ocap/util");
|
|
6
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
7
|
+
let _arcblock_did = require("@arcblock/did");
|
|
8
|
+
let _ocap_wallet = require("@ocap/wallet");
|
|
9
|
+
|
|
10
|
+
//#region src/uniswap-v4-hook.ts
|
|
11
|
+
/**
|
|
12
|
+
* Maximum allowed TTL for stateless edge-signed Hook tickets (15 minutes = 900 seconds).
|
|
13
|
+
*/
|
|
14
|
+
const MAX_HOOK_TICKET_TTL_SECONDS = 900;
|
|
15
|
+
/**
|
|
16
|
+
* Default minimum continuous holding blocks on OCAP to prevent flash-borrow VIP ticket abuse.
|
|
17
|
+
*/
|
|
18
|
+
const DEFAULT_MIN_HOLDING_BLOCKS = 300;
|
|
19
|
+
/**
|
|
20
|
+
* Minimum percentage of MEV penalty surcharge that MUST be returned to Uniswap V4 LPs (80% = 8000 bps).
|
|
21
|
+
*/
|
|
22
|
+
const MIN_LP_MEV_REBATE_SHARE_BPS = 8e3;
|
|
23
|
+
/**
|
|
24
|
+
* Maximum dynamic LP fee override in Uniswap V4 (5.00% = 500 bps).
|
|
25
|
+
*/
|
|
26
|
+
const MAX_V4_DYNAMIC_FEE_BPS = 500;
|
|
27
|
+
const FORBIDDEN_KEYS = new Set([
|
|
28
|
+
"__proto__",
|
|
29
|
+
"constructor",
|
|
30
|
+
"prototype"
|
|
31
|
+
]);
|
|
32
|
+
const CANONICAL_UINT_REGEX = /^\d+$/;
|
|
33
|
+
const EVM_HEX_ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/;
|
|
34
|
+
const BYTES32_HEX_REGEX = /^0x[0-9a-fA-F]{64}$/;
|
|
35
|
+
const VALID_HOOK_TIERS = new Set([
|
|
36
|
+
"VIP_LOYALTY",
|
|
37
|
+
"ABT_STAKER",
|
|
38
|
+
"VERIFIED_DID",
|
|
39
|
+
"STANDARD_RETAIL",
|
|
40
|
+
"MEV_SURCHARGE"
|
|
41
|
+
]);
|
|
42
|
+
/**
|
|
43
|
+
* Normalized lowercase PII key tokens and substrings that must NEVER appear in any ticket
|
|
44
|
+
* or on-chain hookData (GDPR Safe Harbor).
|
|
45
|
+
*/
|
|
46
|
+
const FORBIDDEN_NORMALIZED_PII_KEYS = new Set([
|
|
47
|
+
"name",
|
|
48
|
+
"fullname",
|
|
49
|
+
"firstname",
|
|
50
|
+
"lastname",
|
|
51
|
+
"email",
|
|
52
|
+
"emailaddress",
|
|
53
|
+
"useremail",
|
|
54
|
+
"phone",
|
|
55
|
+
"phonenumber",
|
|
56
|
+
"passport",
|
|
57
|
+
"passportnumber",
|
|
58
|
+
"ssn",
|
|
59
|
+
"socialsecurity",
|
|
60
|
+
"socialsecuritynumber",
|
|
61
|
+
"taxid",
|
|
62
|
+
"nationalid",
|
|
63
|
+
"driverlicense",
|
|
64
|
+
"dateofbirth",
|
|
65
|
+
"dob",
|
|
66
|
+
"birthdate",
|
|
67
|
+
"physicaladdress",
|
|
68
|
+
"residentialaddress",
|
|
69
|
+
"homeaddress",
|
|
70
|
+
"ipaddress"
|
|
71
|
+
]);
|
|
72
|
+
const FORBIDDEN_PII_SUBSTRINGS = [
|
|
73
|
+
"passport",
|
|
74
|
+
"ssn",
|
|
75
|
+
"socialsecurity",
|
|
76
|
+
"taxid",
|
|
77
|
+
"nationalid",
|
|
78
|
+
"driverlicense",
|
|
79
|
+
"dateofbirth",
|
|
80
|
+
"email",
|
|
81
|
+
"phonenumber",
|
|
82
|
+
"residentialaddress",
|
|
83
|
+
"physicaladdress",
|
|
84
|
+
"ipaddress"
|
|
85
|
+
];
|
|
86
|
+
function assertSafeString(val, label) {
|
|
87
|
+
if (typeof val !== "string") throw new _ocap_util_lib_error.CustomError("INVALID_V4_HOOK", `${label} must be a non-empty string`);
|
|
88
|
+
const trimmed = val.trim();
|
|
89
|
+
if (!trimmed || FORBIDDEN_KEYS.has(trimmed)) throw new _ocap_util_lib_error.CustomError("INVALID_V4_HOOK", `Unsafe or empty ${label}`);
|
|
90
|
+
return trimmed;
|
|
91
|
+
}
|
|
92
|
+
function assertEvmAddr(val, label) {
|
|
93
|
+
if (typeof val !== "string" || !EVM_HEX_ADDRESS_REGEX.test(val)) throw new _ocap_util_lib_error.CustomError("INVALID_V4_HOOK", `${label} must be a valid 20-byte 0x EVM address`);
|
|
94
|
+
return val.toLowerCase();
|
|
95
|
+
}
|
|
96
|
+
function assertPoolId(val) {
|
|
97
|
+
if (typeof val !== "string" || !BYTES32_HEX_REGEX.test(val)) throw new _ocap_util_lib_error.CustomError("INVALID_V4_HOOK", "poolId must be a 32-byte 0x hex string");
|
|
98
|
+
return val.toLowerCase();
|
|
99
|
+
}
|
|
100
|
+
function parsePositiveBn(val, label) {
|
|
101
|
+
if (typeof val !== "string" || !CANONICAL_UINT_REGEX.test(val)) throw new _ocap_util_lib_error.CustomError("INVALID_V4_HOOK", `${label} must be a canonical non-negative integer string`);
|
|
102
|
+
const bn = new _ocap_util.BN(val, 10);
|
|
103
|
+
if (bn.lte(new _ocap_util.BN(0))) throw new _ocap_util_lib_error.CustomError("INVALID_V4_HOOK", `${label} must be strictly positive`);
|
|
104
|
+
return bn;
|
|
105
|
+
}
|
|
106
|
+
function assertValidTimestamp(ts, label = "currentTimestamp") {
|
|
107
|
+
if (typeof ts !== "number" || !Number.isSafeInteger(ts) || ts < 0) throw new _ocap_util_lib_error.CustomError("INVALID_V4_HOOK", `${label} must be a non-negative safe integer`);
|
|
108
|
+
return ts;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Recursively scans an object or array for any forbidden PII field names (case/snake/hyphen-insensitive)
|
|
112
|
+
* and enforces a strict maximum nesting depth of 8 to guarantee Zero-PII On-Chain (GDPR Safe Harbor).
|
|
113
|
+
*/
|
|
114
|
+
function assertZeroPiiInHookData(payload, depth = 0) {
|
|
115
|
+
if (depth > 8) throw new _ocap_util_lib_error.CustomError("MAX_HOOK_DATA_DEPTH_EXCEEDED", "Hook data nesting depth exceeds maximum allowed (8)");
|
|
116
|
+
if (!payload || typeof payload !== "object") return;
|
|
117
|
+
if (Array.isArray(payload)) {
|
|
118
|
+
for (const item of payload) assertZeroPiiInHookData(item, depth + 1);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
for (const [k, v] of Object.entries(payload)) {
|
|
122
|
+
if (FORBIDDEN_KEYS.has(k)) throw new _ocap_util_lib_error.CustomError("INVALID_V4_HOOK", `Forbidden prototype key ${k}`);
|
|
123
|
+
const normalizedKey = k.replace(/[_-\s]/g, "").toLowerCase();
|
|
124
|
+
if (FORBIDDEN_NORMALIZED_PII_KEYS.has(normalizedKey) || FORBIDDEN_PII_SUBSTRINGS.some((sub) => normalizedKey.includes(sub))) throw new _ocap_util_lib_error.CustomError("GDPR_PII_PROHIBITED", `Plaintext PII field '${k}' is strictly prohibited in on-chain Hook tickets (Zero-PII Safe Harbor)`);
|
|
125
|
+
if (v && typeof v === "object") assertZeroPiiInHookData(v, depth + 1);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Computes the canonical digest for an OCAP Uniswap V4 Hook attestation ticket.
|
|
130
|
+
*/
|
|
131
|
+
function computeOcapHookTicketDigest(claims) {
|
|
132
|
+
assertZeroPiiInHookData(claims);
|
|
133
|
+
const chainId = assertSafeString(claims.chainId, "claims.chainId");
|
|
134
|
+
const poolId = assertPoolId(claims.poolId);
|
|
135
|
+
const hookAddress = assertEvmAddr(claims.hookAddress, "claims.hookAddress");
|
|
136
|
+
const traderAddress = assertEvmAddr(claims.traderAddress, "claims.traderAddress");
|
|
137
|
+
const holderDid = require_ofac_screening.normalizeScreeningAddress(assertSafeString(claims.holderDid, "claims.holderDid"));
|
|
138
|
+
const maxAmountIn = parsePositiveBn(claims.maxAmountIn, "claims.maxAmountIn");
|
|
139
|
+
const nonce = assertSafeString(claims.nonce, "claims.nonce");
|
|
140
|
+
if (!VALID_HOOK_TIERS.has(claims.tier)) throw new _ocap_util_lib_error.CustomError("INVALID_V4_HOOK", `Unsupported HookFeeTierName: ${String(claims.tier)}`);
|
|
141
|
+
if (typeof claims.feeBpsOverride !== "number" || !Number.isSafeInteger(claims.feeBpsOverride) || claims.feeBpsOverride < 0 || claims.feeBpsOverride > MAX_V4_DYNAMIC_FEE_BPS) throw new _ocap_util_lib_error.CustomError("INVALID_V4_HOOK", `claims.feeBpsOverride must be an integer between 0 and ${MAX_V4_DYNAMIC_FEE_BPS}`);
|
|
142
|
+
if (typeof claims.holdingBlocks !== "number" || !Number.isSafeInteger(claims.holdingBlocks) || claims.holdingBlocks < 0) throw new _ocap_util_lib_error.CustomError("INVALID_V4_HOOK", "claims.holdingBlocks must be a non-negative integer");
|
|
143
|
+
if (typeof claims.issuedAt !== "number" || !Number.isSafeInteger(claims.issuedAt) || typeof claims.validUntil !== "number" || !Number.isSafeInteger(claims.validUntil) || claims.validUntil <= claims.issuedAt) throw new _ocap_util_lib_error.CustomError("INVALID_V4_HOOK", "claims.validUntil must be strictly greater than claims.issuedAt");
|
|
144
|
+
if (claims.validUntil - claims.issuedAt > MAX_HOOK_TICKET_TTL_SECONDS) throw new _ocap_util_lib_error.CustomError("HOOK_TICKET_TTL_EXCEEDED", `Ticket TTL (${claims.validUntil - claims.issuedAt}s) exceeds maximum allowed ${MAX_HOOK_TICKET_TTL_SECONDS}s`);
|
|
145
|
+
const kycIssuerDid = claims.kycIssuerDid ? require_ofac_screening.normalizeScreeningAddress(assertSafeString(claims.kycIssuerDid, "claims.kycIssuerDid")) : "";
|
|
146
|
+
const canonical = JSON.stringify({
|
|
147
|
+
domain: "OCAP_UNISWAP_V4_VERIFIED_HOOK_V1",
|
|
148
|
+
chainId,
|
|
149
|
+
poolId,
|
|
150
|
+
hookAddress,
|
|
151
|
+
traderAddress,
|
|
152
|
+
holderDid,
|
|
153
|
+
tier: claims.tier,
|
|
154
|
+
feeBpsOverride: claims.feeBpsOverride,
|
|
155
|
+
maxAmountIn: maxAmountIn.toString(10),
|
|
156
|
+
holdingBlocks: claims.holdingBlocks,
|
|
157
|
+
kycVerified: Boolean(claims.kycVerified),
|
|
158
|
+
kycIssuerDid,
|
|
159
|
+
issuedAt: claims.issuedAt,
|
|
160
|
+
validUntil: claims.validUntil,
|
|
161
|
+
nonce
|
|
162
|
+
});
|
|
163
|
+
return _ocap_mcrypto.Hasher.SHA3.hash256(Buffer.from(canonical, "utf8"));
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Edge Attestation Signer: Issues a short-lived, stateless Hook ticket from an OCAP Read-Replica.
|
|
167
|
+
* Enforces:
|
|
168
|
+
* - Zero PII on-chain (GDPR Safe Harbor)
|
|
169
|
+
* - Time-weighted holding guard (`holdingBlocks >= minHoldingBlocks`) to block flash-borrow VIP abuse
|
|
170
|
+
* - Maximum TTL cap (`<= 900` seconds)
|
|
171
|
+
* - OFAC sanctions screening
|
|
172
|
+
*/
|
|
173
|
+
async function issueOcapHookTicket(claimsInput, signerWallet, options) {
|
|
174
|
+
assertZeroPiiInHookData(claimsInput);
|
|
175
|
+
if (!VALID_HOOK_TIERS.has(claimsInput.tier)) throw new _ocap_util_lib_error.CustomError("INVALID_V4_HOOK", `Unsupported HookFeeTierName: ${String(claimsInput.tier)}`);
|
|
176
|
+
const minHoldingBlocks = options?.minHoldingBlocks ?? DEFAULT_MIN_HOLDING_BLOCKS;
|
|
177
|
+
if ((claimsInput.tier === "VIP_LOYALTY" || claimsInput.tier === "ABT_STAKER") && claimsInput.holdingBlocks < minHoldingBlocks) throw new _ocap_util_lib_error.CustomError("FLASH_BORROW_HOLDING_TOO_SHORT", `Tier ${claimsInput.tier} requires at least ${minHoldingBlocks} continuous holding blocks on OCAP (actual: ${claimsInput.holdingBlocks})`);
|
|
178
|
+
if (claimsInput.kycVerified) {
|
|
179
|
+
if (!claimsInput.kycIssuerDid || !claimsInput.kycIssuerDid.trim()) throw new _ocap_util_lib_error.CustomError("INVALID_V4_HOOK", "kycVerified ticket must specify kycIssuerDid");
|
|
180
|
+
if (options?.trustedKycIssuerDids && options.trustedKycIssuerDids.length > 0) {
|
|
181
|
+
const normalizedTrusted = new Set(options.trustedKycIssuerDids.map((d) => require_ofac_screening.normalizeScreeningAddress(d)));
|
|
182
|
+
const normalizedIssuer = require_ofac_screening.normalizeScreeningAddress(claimsInput.kycIssuerDid);
|
|
183
|
+
if (!normalizedTrusted.has(normalizedIssuer)) throw new _ocap_util_lib_error.CustomError("UNTRUSTED_KYC_ISSUER", `KYC issuer ${claimsInput.kycIssuerDid} is not in trusted list`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
require_ofac_screening.assertNotOfacSanctioned([
|
|
187
|
+
claimsInput.traderAddress,
|
|
188
|
+
claimsInput.holderDid,
|
|
189
|
+
claimsInput.kycIssuerDid,
|
|
190
|
+
signerWallet.address
|
|
191
|
+
], options?.ofacBlocklist);
|
|
192
|
+
const normalizedClaims = {
|
|
193
|
+
...claimsInput,
|
|
194
|
+
chainId: assertSafeString(claimsInput.chainId, "claims.chainId"),
|
|
195
|
+
poolId: assertPoolId(claimsInput.poolId),
|
|
196
|
+
hookAddress: assertEvmAddr(claimsInput.hookAddress, "claims.hookAddress"),
|
|
197
|
+
traderAddress: assertEvmAddr(claimsInput.traderAddress, "claims.traderAddress"),
|
|
198
|
+
holderDid: require_ofac_screening.normalizeScreeningAddress(assertSafeString(claimsInput.holderDid, "claims.holderDid")),
|
|
199
|
+
kycIssuerDid: claimsInput.kycIssuerDid ? require_ofac_screening.normalizeScreeningAddress(assertSafeString(claimsInput.kycIssuerDid, "claims.kycIssuerDid")) : void 0,
|
|
200
|
+
nonce: assertSafeString(claimsInput.nonce, "claims.nonce")
|
|
201
|
+
};
|
|
202
|
+
const digest = computeOcapHookTicketDigest(normalizedClaims);
|
|
203
|
+
const sig = await signerWallet.sign(Buffer.from(digest.replace(/^0x/, ""), "hex"), false);
|
|
204
|
+
return {
|
|
205
|
+
claims: normalizedClaims,
|
|
206
|
+
signerDid: require_ofac_screening.normalizeScreeningAddress(signerWallet.address),
|
|
207
|
+
signerPk: signerWallet.publicKey,
|
|
208
|
+
signature: sig,
|
|
209
|
+
digest
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Verifies a signed OcapHookTicket purely from its cryptographic signature and claims
|
|
214
|
+
* (0 synchronous network/RPC calls to OCAP nodes).
|
|
215
|
+
*/
|
|
216
|
+
async function verifyOcapHookTicketSignature(ticket) {
|
|
217
|
+
if (!ticket || typeof ticket !== "object" || !ticket.claims) return false;
|
|
218
|
+
assertZeroPiiInHookData(ticket);
|
|
219
|
+
const signerDid = require_ofac_screening.normalizeScreeningAddress(assertSafeString(ticket.signerDid, "ticket.signerDid"));
|
|
220
|
+
const signerPk = assertSafeString(ticket.signerPk, "ticket.signerPk");
|
|
221
|
+
const signature = assertSafeString(ticket.signature, "ticket.signature");
|
|
222
|
+
if (!(0, _arcblock_did.isFromPublicKey)(signerDid, signerPk)) return false;
|
|
223
|
+
const expectedDigest = computeOcapHookTicketDigest(ticket.claims);
|
|
224
|
+
if (ticket.digest && ticket.digest !== expectedDigest) return false;
|
|
225
|
+
const verifier = (0, _ocap_wallet.fromPublicKey)(signerPk, (0, _arcblock_did.toTypeInfo)(signerDid));
|
|
226
|
+
const msgBytes = Buffer.from(expectedDigest.replace(/^0x/, ""), "hex");
|
|
227
|
+
return Boolean(await verifier.verify(msgBytes, signature, false));
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Deterministic `OcapVerifiedHook` Engine modeling the on-chain Uniswap V4 Hook lifecycle:
|
|
231
|
+
* - `beforeInitialize`: Protects pool creation against tick-sniping front-running
|
|
232
|
+
* - `beforeAddLiquidity`: Enforces OFAC sanctions screening + RWA KYC permissioning
|
|
233
|
+
* - `beforeSwap`: Purely stateless ticket verification + graceful router-friendly fallback + anti-MEV LP rebate split
|
|
234
|
+
*/
|
|
235
|
+
var OcapVerifiedHookEngine = class {
|
|
236
|
+
constructor(config) {
|
|
237
|
+
this.consumedNonces = /* @__PURE__ */ new Map();
|
|
238
|
+
this.rwaAllowlistCache = /* @__PURE__ */ new Map();
|
|
239
|
+
if (!config || typeof config !== "object") throw new _ocap_util_lib_error.CustomError("INVALID_V4_HOOK", "Missing V4PoolHookConfig");
|
|
240
|
+
const lpRebateBps = config.lpMevRebateShareBps ?? MIN_LP_MEV_REBATE_SHARE_BPS;
|
|
241
|
+
if (typeof lpRebateBps !== "number" || !Number.isSafeInteger(lpRebateBps) || lpRebateBps < MIN_LP_MEV_REBATE_SHARE_BPS || lpRebateBps > 1e4) throw new _ocap_util_lib_error.CustomError("VAMPIRE_FEE_SKIMMING_PROHIBITED", `lpMevRebateShareBps (${lpRebateBps}) must be between ${MIN_LP_MEV_REBATE_SHARE_BPS} (80%) and 10000 (100%) to align with Uniswap LPs`);
|
|
242
|
+
if (!Array.isArray(config.authorizedSignerDids) || config.authorizedSignerDids.length === 0) throw new _ocap_util_lib_error.CustomError("INVALID_V4_HOOK", "authorizedSignerDids must contain at least one OCAP signer DID");
|
|
243
|
+
if (config.poolMode !== "LOYALTY_PUBLIC" && config.poolMode !== "PERMISSIONED_RWA") throw new _ocap_util_lib_error.CustomError("INVALID_V4_HOOK", `Unsupported poolMode: ${String(config.poolMode)}`);
|
|
244
|
+
if (config.poolMode === "PERMISSIONED_RWA" && (!Array.isArray(config.trustedKycIssuerDids) || config.trustedKycIssuerDids.length === 0)) throw new _ocap_util_lib_error.CustomError("INVALID_V4_HOOK", "PERMISSIONED_RWA poolMode requires at least one trustedKycIssuerDid");
|
|
245
|
+
for (const fee of [
|
|
246
|
+
config.baseFeeBps,
|
|
247
|
+
config.vipFeeBps,
|
|
248
|
+
config.abtStakerFeeBps,
|
|
249
|
+
config.verifiedDidFeeBps,
|
|
250
|
+
config.mevPenaltyFeeBps
|
|
251
|
+
]) if (typeof fee !== "number" || !Number.isSafeInteger(fee) || fee < 0 || fee > MAX_V4_DYNAMIC_FEE_BPS) throw new _ocap_util_lib_error.CustomError("INVALID_V4_HOOK", `Invalid fee tier bps: ${String(fee)}`);
|
|
252
|
+
if (config.vipFeeBps > config.abtStakerFeeBps || config.abtStakerFeeBps > config.verifiedDidFeeBps || config.verifiedDidFeeBps > config.baseFeeBps || config.baseFeeBps > config.mevPenaltyFeeBps) throw new _ocap_util_lib_error.CustomError("INVALID_V4_HOOK", "Fee tiers must satisfy vipFeeBps <= abtStakerFeeBps <= verifiedDidFeeBps <= baseFeeBps <= mevPenaltyFeeBps");
|
|
253
|
+
parsePositiveBn(config.unverifiedMevThresholdAmountIn, "config.unverifiedMevThresholdAmountIn");
|
|
254
|
+
this.config = {
|
|
255
|
+
...config,
|
|
256
|
+
chainId: assertSafeString(config.chainId, "config.chainId"),
|
|
257
|
+
poolId: assertPoolId(config.poolId),
|
|
258
|
+
hookAddress: assertEvmAddr(config.hookAddress, "config.hookAddress"),
|
|
259
|
+
authorizedSignerDids: config.authorizedSignerDids.map((d) => require_ofac_screening.normalizeScreeningAddress(assertSafeString(d, "authorizedSignerDid"))),
|
|
260
|
+
trustedKycIssuerDids: config.trustedKycIssuerDids?.map((d) => require_ofac_screening.normalizeScreeningAddress(assertSafeString(d, "trustedKycIssuerDid"))),
|
|
261
|
+
authorizedPoolCreator: config.authorizedPoolCreator ? assertEvmAddr(config.authorizedPoolCreator, "config.authorizedPoolCreator") : void 0,
|
|
262
|
+
minHoldingBlocks: config.minHoldingBlocks ?? DEFAULT_MIN_HOLDING_BLOCKS,
|
|
263
|
+
lpMevRebateShareBps: lpRebateBps
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
pruneExpiredCaches(currentTimestamp) {
|
|
267
|
+
for (const [k, exp] of this.consumedNonces.entries()) if (exp < currentTimestamp) this.consumedNonces.delete(k);
|
|
268
|
+
for (const [addr, entry] of this.rwaAllowlistCache.entries()) if (entry.validUntil <= currentTimestamp) this.rwaAllowlistCache.delete(addr);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* `beforeInitialize`: Protects newly graduating or official pools from front-running bots
|
|
272
|
+
* initializing the same V4 PoolKey at a manipulated initial tick/sqrtPriceX96.
|
|
273
|
+
*/
|
|
274
|
+
beforeInitialize(params) {
|
|
275
|
+
const caller = assertEvmAddr(params.callerAddress, "callerAddress");
|
|
276
|
+
require_ofac_screening.assertNotOfacSanctioned([caller], this.config.ofacBlocklist);
|
|
277
|
+
if (this.config.authorizedPoolCreator && caller !== this.config.authorizedPoolCreator) throw new _ocap_util_lib_error.CustomError("UNAUTHORIZED_POOL_INITIALIZER", `Caller ${caller} is not authorized to initialize pool ${this.config.poolId} (expected ${this.config.authorizedPoolCreator})`);
|
|
278
|
+
return { allowed: true };
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* `beforeAddLiquidity`: Screens LPs against OFAC sanctions and enforces KYC VC for PERMISSIONED_RWA pools.
|
|
282
|
+
*/
|
|
283
|
+
async beforeAddLiquidity(params) {
|
|
284
|
+
const lpAddress = assertEvmAddr(params.lpAddress, "lpAddress");
|
|
285
|
+
const currentTimestamp = assertValidTimestamp(params.currentTimestamp, "currentTimestamp");
|
|
286
|
+
this.pruneExpiredCaches(currentTimestamp);
|
|
287
|
+
require_ofac_screening.assertNotOfacSanctioned([
|
|
288
|
+
lpAddress,
|
|
289
|
+
params.ticket?.claims?.holderDid,
|
|
290
|
+
params.ticket?.claims?.kycIssuerDid,
|
|
291
|
+
params.ticket?.signerDid
|
|
292
|
+
], this.config.ofacBlocklist);
|
|
293
|
+
if (this.config.poolMode === "LOYALTY_PUBLIC") {
|
|
294
|
+
if (params.ticket) assertZeroPiiInHookData(params.ticket);
|
|
295
|
+
return { allowed: true };
|
|
296
|
+
}
|
|
297
|
+
if (!params.ticket) {
|
|
298
|
+
const cached = this.rwaAllowlistCache.get(lpAddress);
|
|
299
|
+
if (cached && cached.validUntil > currentTimestamp) return {
|
|
300
|
+
allowed: true,
|
|
301
|
+
cachedRwaValidUntil: cached.validUntil
|
|
302
|
+
};
|
|
303
|
+
throw new _ocap_util_lib_error.CustomError("RWA_KYC_REQUIRED", `Pool ${this.config.poolId} is in PERMISSIONED_RWA mode and requires a valid KYC-verified OCAP ticket`);
|
|
304
|
+
}
|
|
305
|
+
const validation = await this.validateTicketInternal(params.ticket, lpAddress, "1", currentTimestamp, true);
|
|
306
|
+
if (!validation.valid || !params.ticket.claims.kycVerified) throw new _ocap_util_lib_error.CustomError("RWA_KYC_REQUIRED", `Pool ${this.config.poolId} is in PERMISSIONED_RWA mode and requires a valid KYC-verified OCAP ticket (${validation.reason || "missing kycVerified"})`);
|
|
307
|
+
this.rwaAllowlistCache.set(lpAddress, {
|
|
308
|
+
validUntil: params.ticket.claims.validUntil,
|
|
309
|
+
maxAmountIn: params.ticket.claims.maxAmountIn
|
|
310
|
+
});
|
|
311
|
+
return {
|
|
312
|
+
allowed: true,
|
|
313
|
+
cachedRwaValidUntil: params.ticket.claims.validUntil
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* `beforeSwap`: Evaluates swap permissions, dynamic fee overrides, and anti-MEV LP rebates.
|
|
318
|
+
*
|
|
319
|
+
* Key Guarantees:
|
|
320
|
+
* 1. Zero synchronous cross-chain RPC calls (`synchronousCrossChainRpcCalls: 0`).
|
|
321
|
+
* 2. Hard-reverts ONLY on OFAC sanctions, GDPR PII violations, or unverified callers in `PERMISSIONED_RWA` pools.
|
|
322
|
+
* 3. In `LOYALTY_PUBLIC` pools, missing/expired/invalid tickets NEVER revert standard router swaps —
|
|
323
|
+
* they gracefully fall back to `baseFeeBps` (or `mevPenaltyFeeBps` for large unverified arbitrage orders).
|
|
324
|
+
*/
|
|
325
|
+
async beforeSwap(params) {
|
|
326
|
+
const traderAddress = assertEvmAddr(params.traderAddress, "traderAddress");
|
|
327
|
+
const amountInBn = parsePositiveBn(params.amountIn, "amountIn");
|
|
328
|
+
const currentTimestamp = assertValidTimestamp(params.currentTimestamp, "currentTimestamp");
|
|
329
|
+
this.pruneExpiredCaches(currentTimestamp);
|
|
330
|
+
require_ofac_screening.assertNotOfacSanctioned([
|
|
331
|
+
traderAddress,
|
|
332
|
+
params.ticket?.claims?.holderDid,
|
|
333
|
+
params.ticket?.claims?.kycIssuerDid,
|
|
334
|
+
params.ticket?.signerDid
|
|
335
|
+
], this.config.ofacBlocklist);
|
|
336
|
+
const validation = await this.validateTicketInternal(params.ticket, traderAddress, amountInBn.toString(10), currentTimestamp, true);
|
|
337
|
+
if (this.config.poolMode === "PERMISSIONED_RWA") if (params.ticket) {
|
|
338
|
+
if (!validation.valid || !params.ticket.claims.kycVerified) throw new _ocap_util_lib_error.CustomError("RWA_KYC_REQUIRED", `Swap rejected in PERMISSIONED_RWA pool: ${validation.reason || "ticket lacks kycVerified"}`);
|
|
339
|
+
this.rwaAllowlistCache.set(traderAddress, {
|
|
340
|
+
validUntil: params.ticket.claims.validUntil,
|
|
341
|
+
maxAmountIn: params.ticket.claims.maxAmountIn
|
|
342
|
+
});
|
|
343
|
+
} else {
|
|
344
|
+
const cached = this.rwaAllowlistCache.get(traderAddress);
|
|
345
|
+
if (!cached || cached.validUntil <= currentTimestamp) throw new _ocap_util_lib_error.CustomError("RWA_KYC_REQUIRED", `Swap rejected in PERMISSIONED_RWA pool: ${validation.reason || "unverified trader"}`);
|
|
346
|
+
const cachedMaxBn = parsePositiveBn(cached.maxAmountIn, "cached.maxAmountIn");
|
|
347
|
+
if (amountInBn.gt(cachedMaxBn)) throw new _ocap_util_lib_error.CustomError("RWA_KYC_REQUIRED", `Swap amount ${amountInBn.toString(10)} exceeds cached RWA KYC cap ${cachedMaxBn.toString(10)}`);
|
|
348
|
+
const remainingAllowanceBn = cachedMaxBn.sub(amountInBn);
|
|
349
|
+
if (remainingAllowanceBn.isZero()) this.rwaAllowlistCache.delete(traderAddress);
|
|
350
|
+
else this.rwaAllowlistCache.set(traderAddress, {
|
|
351
|
+
validUntil: cached.validUntil,
|
|
352
|
+
maxAmountIn: remainingAllowanceBn.toString(10)
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
let appliedTier = "STANDARD_RETAIL";
|
|
356
|
+
let lpFeeBpsOverride = this.config.baseFeeBps;
|
|
357
|
+
let usedFallbackBaseFee = false;
|
|
358
|
+
let fallbackReason;
|
|
359
|
+
if (validation.valid && params.ticket) {
|
|
360
|
+
appliedTier = params.ticket.claims.tier;
|
|
361
|
+
lpFeeBpsOverride = params.ticket.claims.feeBpsOverride;
|
|
362
|
+
} else {
|
|
363
|
+
usedFallbackBaseFee = true;
|
|
364
|
+
fallbackReason = validation.reason;
|
|
365
|
+
const mevThresholdBn = parsePositiveBn(this.config.unverifiedMevThresholdAmountIn, "unverifiedMevThresholdAmountIn");
|
|
366
|
+
if (amountInBn.gte(mevThresholdBn)) {
|
|
367
|
+
appliedTier = "MEV_SURCHARGE";
|
|
368
|
+
lpFeeBpsOverride = this.config.mevPenaltyFeeBps;
|
|
369
|
+
} else {
|
|
370
|
+
appliedTier = "STANDARD_RETAIL";
|
|
371
|
+
lpFeeBpsOverride = this.config.baseFeeBps;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
const totalFeeAmount = amountInBn.mul(new _ocap_util.BN(lpFeeBpsOverride)).div(new _ocap_util.BN(1e4));
|
|
375
|
+
let baseLpFeeAmount = totalFeeAmount;
|
|
376
|
+
let mevSurchargeAmount = new _ocap_util.BN(0);
|
|
377
|
+
let lpMevRebateAmount = new _ocap_util.BN(0);
|
|
378
|
+
let protocolEcosystemShareAmount = new _ocap_util.BN(0);
|
|
379
|
+
if (lpFeeBpsOverride > this.config.baseFeeBps) {
|
|
380
|
+
baseLpFeeAmount = amountInBn.mul(new _ocap_util.BN(this.config.baseFeeBps)).div(new _ocap_util.BN(1e4));
|
|
381
|
+
mevSurchargeAmount = totalFeeAmount.sub(baseLpFeeAmount);
|
|
382
|
+
lpMevRebateAmount = mevSurchargeAmount.mul(new _ocap_util.BN(this.config.lpMevRebateShareBps)).div(new _ocap_util.BN(1e4));
|
|
383
|
+
protocolEcosystemShareAmount = mevSurchargeAmount.sub(lpMevRebateAmount);
|
|
384
|
+
}
|
|
385
|
+
return {
|
|
386
|
+
allowed: true,
|
|
387
|
+
appliedTier,
|
|
388
|
+
lpFeeBpsOverride,
|
|
389
|
+
usedFallbackBaseFee,
|
|
390
|
+
synchronousCrossChainRpcCalls: 0,
|
|
391
|
+
feeBreakdown: {
|
|
392
|
+
totalFeeAmount: totalFeeAmount.toString(10),
|
|
393
|
+
baseLpFeeAmount: baseLpFeeAmount.toString(10),
|
|
394
|
+
mevSurchargeAmount: mevSurchargeAmount.toString(10),
|
|
395
|
+
lpMevRebateAmount: lpMevRebateAmount.toString(10),
|
|
396
|
+
protocolEcosystemShareAmount: protocolEcosystemShareAmount.toString(10),
|
|
397
|
+
lpMevRebateShareBps: this.config.lpMevRebateShareBps
|
|
398
|
+
},
|
|
399
|
+
...fallbackReason ? { fallbackReason } : {}
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
async validateTicketInternal(ticket, expectedTrader, amountInStr, currentTimestamp, consumeNonce) {
|
|
403
|
+
assertValidTimestamp(currentTimestamp, "currentTimestamp");
|
|
404
|
+
if (!ticket) return {
|
|
405
|
+
valid: false,
|
|
406
|
+
reason: "NO_TICKET_PROVIDED"
|
|
407
|
+
};
|
|
408
|
+
assertZeroPiiInHookData(ticket);
|
|
409
|
+
try {
|
|
410
|
+
const { claims } = ticket;
|
|
411
|
+
if (!claims || typeof claims !== "object") return {
|
|
412
|
+
valid: false,
|
|
413
|
+
reason: "MALFORMED_CLAIMS"
|
|
414
|
+
};
|
|
415
|
+
if (typeof claims.chainId !== "string" || typeof claims.poolId !== "string" || typeof claims.hookAddress !== "string" || typeof claims.traderAddress !== "string" || typeof claims.holderDid !== "string" || typeof claims.nonce !== "string" || typeof ticket.signerDid !== "string") return {
|
|
416
|
+
valid: false,
|
|
417
|
+
reason: "MALFORMED_CLAIMS"
|
|
418
|
+
};
|
|
419
|
+
const holderDidNorm = require_ofac_screening.normalizeScreeningAddress(assertSafeString(claims.holderDid, "claims.holderDid"));
|
|
420
|
+
const nonceSafe = assertSafeString(claims.nonce, "claims.nonce");
|
|
421
|
+
if (!VALID_HOOK_TIERS.has(claims.tier)) return {
|
|
422
|
+
valid: false,
|
|
423
|
+
reason: "UNSUPPORTED_FEE_TIER"
|
|
424
|
+
};
|
|
425
|
+
if (claims.chainId !== this.config.chainId) return {
|
|
426
|
+
valid: false,
|
|
427
|
+
reason: "CHAIN_ID_MISMATCH"
|
|
428
|
+
};
|
|
429
|
+
if (claims.poolId.toLowerCase() !== this.config.poolId) return {
|
|
430
|
+
valid: false,
|
|
431
|
+
reason: "POOL_ID_MISMATCH"
|
|
432
|
+
};
|
|
433
|
+
if (claims.hookAddress.toLowerCase() !== this.config.hookAddress) return {
|
|
434
|
+
valid: false,
|
|
435
|
+
reason: "HOOK_ADDRESS_MISMATCH"
|
|
436
|
+
};
|
|
437
|
+
if (claims.traderAddress.toLowerCase() !== expectedTrader) return {
|
|
438
|
+
valid: false,
|
|
439
|
+
reason: "TRADER_ADDRESS_MISMATCH"
|
|
440
|
+
};
|
|
441
|
+
if (typeof claims.issuedAt !== "number" || !Number.isSafeInteger(claims.issuedAt) || typeof claims.validUntil !== "number" || !Number.isSafeInteger(claims.validUntil) || claims.validUntil <= claims.issuedAt) return {
|
|
442
|
+
valid: false,
|
|
443
|
+
reason: "MALFORMED_CLAIMS"
|
|
444
|
+
};
|
|
445
|
+
if (currentTimestamp < claims.issuedAt || currentTimestamp > claims.validUntil) return {
|
|
446
|
+
valid: false,
|
|
447
|
+
reason: "TICKET_EXPIRED_OR_NOT_YET_VALID"
|
|
448
|
+
};
|
|
449
|
+
if (claims.validUntil - claims.issuedAt > MAX_HOOK_TICKET_TTL_SECONDS) return {
|
|
450
|
+
valid: false,
|
|
451
|
+
reason: "TICKET_TTL_EXCEEDED"
|
|
452
|
+
};
|
|
453
|
+
const nonceKey = `${expectedTrader}:${holderDidNorm}:${nonceSafe}`;
|
|
454
|
+
if (this.consumedNonces.has(nonceKey)) return {
|
|
455
|
+
valid: false,
|
|
456
|
+
reason: "TICKET_NONCE_ALREADY_USED"
|
|
457
|
+
};
|
|
458
|
+
const maxAmountBn = parsePositiveBn(claims.maxAmountIn, "claims.maxAmountIn");
|
|
459
|
+
if (parsePositiveBn(amountInStr, "amountIn").gt(maxAmountBn)) return {
|
|
460
|
+
valid: false,
|
|
461
|
+
reason: "AMOUNT_EXCEEDS_TICKET_CAP"
|
|
462
|
+
};
|
|
463
|
+
const minHoldingBlocks = this.config.minHoldingBlocks ?? DEFAULT_MIN_HOLDING_BLOCKS;
|
|
464
|
+
if ((claims.tier === "VIP_LOYALTY" || claims.tier === "ABT_STAKER") && claims.holdingBlocks < minHoldingBlocks) return {
|
|
465
|
+
valid: false,
|
|
466
|
+
reason: "HOLDING_DURATION_TOO_SHORT"
|
|
467
|
+
};
|
|
468
|
+
const expectedTierFee = claims.tier === "VIP_LOYALTY" ? this.config.vipFeeBps : claims.tier === "ABT_STAKER" ? this.config.abtStakerFeeBps : claims.tier === "VERIFIED_DID" ? this.config.verifiedDidFeeBps : claims.tier === "MEV_SURCHARGE" ? this.config.mevPenaltyFeeBps : this.config.baseFeeBps;
|
|
469
|
+
if (claims.feeBpsOverride < expectedTierFee) return {
|
|
470
|
+
valid: false,
|
|
471
|
+
reason: "FEE_OVERRIDE_BELOW_TIER_FLOOR"
|
|
472
|
+
};
|
|
473
|
+
if (claims.kycVerified) {
|
|
474
|
+
const issuerNorm = require_ofac_screening.normalizeScreeningAddress(claims.kycIssuerDid || "");
|
|
475
|
+
if (!issuerNorm) return {
|
|
476
|
+
valid: false,
|
|
477
|
+
reason: "MISSING_KYC_ISSUER"
|
|
478
|
+
};
|
|
479
|
+
if (this.config.trustedKycIssuerDids && this.config.trustedKycIssuerDids.length > 0) {
|
|
480
|
+
if (!this.config.trustedKycIssuerDids.includes(issuerNorm)) return {
|
|
481
|
+
valid: false,
|
|
482
|
+
reason: "UNTRUSTED_KYC_ISSUER"
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
const normalizedSigner = require_ofac_screening.normalizeScreeningAddress(ticket.signerDid);
|
|
487
|
+
if (!this.config.authorizedSignerDids.includes(normalizedSigner)) return {
|
|
488
|
+
valid: false,
|
|
489
|
+
reason: "UNAUTHORIZED_TICKET_SIGNER"
|
|
490
|
+
};
|
|
491
|
+
if (!await verifyOcapHookTicketSignature(ticket)) return {
|
|
492
|
+
valid: false,
|
|
493
|
+
reason: "INVALID_TICKET_SIGNATURE"
|
|
494
|
+
};
|
|
495
|
+
if (consumeNonce) this.consumedNonces.set(nonceKey, claims.validUntil);
|
|
496
|
+
return { valid: true };
|
|
497
|
+
} catch {
|
|
498
|
+
return {
|
|
499
|
+
valid: false,
|
|
500
|
+
reason: "MALFORMED_CLAIMS"
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
const OCAP_VERIFIED_HOOK_SOLIDITY_SPEC = {
|
|
506
|
+
contractName: "OcapVerifiedHook",
|
|
507
|
+
uniswapVersion: "v4-core",
|
|
508
|
+
implementedHooks: [
|
|
509
|
+
"beforeInitialize",
|
|
510
|
+
"beforeAddLiquidity",
|
|
511
|
+
"beforeSwap"
|
|
512
|
+
],
|
|
513
|
+
ofacOracleAddress: require_ofac_screening.CHAINALYSIS_OFAC_ORACLE_ADDRESS,
|
|
514
|
+
synchronousCrossChainRpcDependency: false
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
//#endregion
|
|
518
|
+
exports.DEFAULT_MIN_HOLDING_BLOCKS = DEFAULT_MIN_HOLDING_BLOCKS;
|
|
519
|
+
exports.MAX_HOOK_TICKET_TTL_SECONDS = MAX_HOOK_TICKET_TTL_SECONDS;
|
|
520
|
+
exports.MAX_V4_DYNAMIC_FEE_BPS = MAX_V4_DYNAMIC_FEE_BPS;
|
|
521
|
+
exports.MIN_LP_MEV_REBATE_SHARE_BPS = MIN_LP_MEV_REBATE_SHARE_BPS;
|
|
522
|
+
exports.OCAP_VERIFIED_HOOK_SOLIDITY_SPEC = OCAP_VERIFIED_HOOK_SOLIDITY_SPEC;
|
|
523
|
+
exports.OcapVerifiedHookEngine = OcapVerifiedHookEngine;
|
|
524
|
+
exports.assertZeroPiiInHookData = assertZeroPiiInHookData;
|
|
525
|
+
exports.computeOcapHookTicketDigest = computeOcapHookTicketDigest;
|
|
526
|
+
exports.issueOcapHookTicket = issueOcapHookTicket;
|
|
527
|
+
exports.verifyOcapHookTicketSignature = verifyOcapHookTicketSignature;
|