[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-uniswap-v4-security-foundations":3,"mdc--nb7mvs-key":36,"related-repo-uniswap-v4-security-foundations":3838,"related-org-uniswap-v4-security-foundations":3933},{"slug":4,"name":4,"fn":5,"description":6,"org":7,"tags":11,"stars":25,"repoUrl":26,"updatedAt":27,"license":28,"forks":29,"topics":30,"repo":31,"sourceUrl":34,"mdContent":35},"v4-security-foundations","develop secure Uniswap v4 hooks","Security-first Uniswap v4 hook development. Use when user mentions \"v4 hooks\", \"hook security\", \"PoolManager\", \"beforeSwap\", \"afterSwap\", or asks about V4 hook best practices, vulnerabilities, or audit requirements.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},"uniswap","Uniswap","https:\u002F\u002Fpexgzepcugksgbtrxkhf.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Forg-logos\u002Funiswap.png",[12,16,19,22],{"name":13,"slug":14,"type":15},"Security","security","tag",{"name":17,"slug":18,"type":15},"Web3","web3",{"name":20,"slug":21,"type":15},"Smart Contracts","smart-contracts",{"name":23,"slug":24,"type":15},"Ethereum","ethereum",215,"https:\u002F\u002Fgithub.com\u002FUniswap\u002Funiswap-ai","2026-07-17T06:05:37.50324","MIT",35,[],{"repoUrl":26,"stars":25,"forks":29,"topics":32,"description":33},[],"AI tools for building on Uniswap — skills, plugins, and agents for any coding agent.","https:\u002F\u002Fgithub.com\u002FUniswap\u002Funiswap-ai\u002Ftree\u002FHEAD\u002Fpackages\u002Fplugins\u002Funiswap-hooks\u002Fskills\u002Fv4-security-foundations","---\nname: v4-security-foundations\ndescription: Security-first Uniswap v4 hook development. Use when user mentions \"v4 hooks\", \"hook security\", \"PoolManager\", \"beforeSwap\", \"afterSwap\", or asks about V4 hook best practices, vulnerabilities, or audit requirements.\nallowed-tools: Read, Glob, Grep, WebFetch, Task(subagent_type:Explore)\nmodel: opus\nlicense: MIT\nmetadata:\n  author: uniswap\n  version: '1.1.0'\n---\n\n# v4 Hook Security Foundations\n\nSecurity-first guide for building Uniswap v4 hooks. Hook vulnerabilities can drain user funds—understand these concepts before writing any hook code.\n\n## Threat Model\n\nBefore writing code, understand the v4 security context:\n\n| Threat Area             | Description                                                | Mitigation                                     |\n| ----------------------- | ---------------------------------------------------------- | ---------------------------------------------- |\n| **Caller Verification** | Only `PoolManager` should invoke hook functions            | Verify `msg.sender == address(poolManager)`    |\n| **Sender Identity**     | `msg.sender` always equals PoolManager, never the end user | Use `sender` parameter for user identity       |\n| **Router Context**      | The `sender` parameter identifies the router, not the user | Implement router allowlisting                  |\n| **State Exposure**      | Hook state is readable during mid-transaction execution    | Avoid storing sensitive data on-chain          |\n| **Reentrancy Surface**  | External calls from hooks can enable reentrancy            | Use reentrancy guards; minimize external calls |\n\n## Permission Flags Risk Matrix\n\nAll 14 hook permissions with associated risk levels:\n\n| Permission Flag                   | Risk Level | Description                 | Security Notes                |\n| --------------------------------- | ---------- | --------------------------- | ----------------------------- |\n| `beforeInitialize`                | LOW        | Called before pool creation | Validate pool parameters      |\n| `afterInitialize`                 | LOW        | Called after pool creation  | Safe for state initialization |\n| `beforeAddLiquidity`              | MEDIUM     | Before LP deposits          | Can block legitimate LPs      |\n| `afterAddLiquidity`               | LOW        | After LP deposits           | Safe for tracking\u002Frewards     |\n| `beforeRemoveLiquidity`           | HIGH       | Before LP withdrawals       | Can trap user funds           |\n| `afterRemoveLiquidity`            | LOW        | After LP withdrawals        | Safe for tracking             |\n| `beforeSwap`                      | HIGH       | Before swap execution       | Can manipulate prices         |\n| `afterSwap`                       | MEDIUM     | After swap execution        | Can observe final state       |\n| `beforeDonate`                    | LOW        | Before donations            | Access control only           |\n| `afterDonate`                     | LOW        | After donations             | Safe for tracking             |\n| `beforeSwapReturnDelta`           | CRITICAL   | Returns custom swap amounts | **NoOp attack vector**        |\n| `afterSwapReturnDelta`            | HIGH       | Modifies post-swap amounts  | Can extract value             |\n| `afterAddLiquidityReturnDelta`    | HIGH       | Modifies LP token amounts   | Can shortchange LPs           |\n| `afterRemoveLiquidityReturnDelta` | HIGH       | Modifies withdrawal amounts | Can steal funds               |\n\n### Risk Thresholds\n\n- **LOW**: Unlikely to cause fund loss\n- **MEDIUM**: Requires careful implementation\n- **HIGH**: Can cause fund loss if misimplemented\n- **CRITICAL**: Can enable complete fund theft\n\n## CRITICAL: NoOp Rug Pull Attack\n\nThe `BEFORE_SWAP_RETURNS_DELTA` permission (bit 10) is the most dangerous hook permission. A malicious hook can:\n\n1. Return a delta claiming it handled the entire swap\n2. PoolManager accepts this and settles the trade\n3. Hook keeps all input tokens without providing output\n4. User loses entire swap amount\n\n### Attack Pattern\n\n```solidity\n\u002F\u002F MALICIOUS - DO NOT USE\nfunction beforeSwap(\n    address,\n    PoolKey calldata,\n    IPoolManager.SwapParams calldata params,\n    bytes calldata\n) external override returns (bytes4, BeforeSwapDelta, uint24) {\n    \u002F\u002F Claim to handle the swap but steal tokens\n    int128 amountSpecified = int128(params.amountSpecified);\n    BeforeSwapDelta delta = toBeforeSwapDelta(amountSpecified, 0);\n    return (BaseHook.beforeSwap.selector, delta, 0);\n}\n```\n\n### Detection\n\nBefore interacting with ANY hook that has `beforeSwapReturnDelta: true`:\n\n1. **Audit the hook code** - Verify legitimate use case\n2. **Check ownership** - Is it upgradeable? By whom?\n3. **Verify track record** - Has it been audited by reputable firms?\n4. **Start small** - Test with minimal amounts first\n\n### Legitimate Uses\n\nNoOp patterns are valid for:\n\n- Just-in-time liquidity (JIT)\n- Custom AMM curves\n- Intent-based trading systems\n- RFQ\u002FPMM integrations\n\nBut each requires careful implementation and audit.\n\n## Delta Accounting Fundamentals\n\nv4 uses a credit\u002Fdebit system through the PoolManager:\n\n### Core Invariant\n\n```text\nFor every transaction: sum(deltas) == 0\n```\n\nThe PoolManager tracks what each address owes or is owed. At transaction end, all debts must be settled.\n\n### Key Functions\n\n| Function                     | Purpose                             | Direction              |\n| ---------------------------- | ----------------------------------- | ---------------------- |\n| `take(currency, to, amount)` | Withdraw tokens from PoolManager    | You receive tokens     |\n| `settle(currency)`           | Pay tokens to PoolManager           | You send tokens        |\n| `sync(currency)`             | Update PoolManager balance tracking | Preparation for settle |\n\n### Settlement Pattern\n\n```solidity\n\u002F\u002F Correct pattern: sync before settle\npoolManager.sync(currency);\ncurrency.transfer(address(poolManager), amount);\npoolManager.settle(currency);\n```\n\n### Common Mistakes\n\n1. **Forgetting sync**: Settlement fails without sync\n2. **Wrong order**: Must sync → transfer → settle\n3. **Partial settlement**: Leaves transaction in invalid state\n4. **Double settlement**: Causes accounting errors\n\n## Access Control Patterns\n\n### PoolManager Verification\n\nEvery hook callback MUST verify the caller:\n\n```solidity\nmodifier onlyPoolManager() {\n    require(msg.sender == address(poolManager), \"Not PoolManager\");\n    _;\n}\n\nfunction beforeSwap(\n    address sender,\n    PoolKey calldata key,\n    IPoolManager.SwapParams calldata params,\n    bytes calldata hookData\n) external override onlyPoolManager returns (bytes4, BeforeSwapDelta, uint24) {\n    \u002F\u002F Safe to proceed\n}\n```\n\n### Why This Matters\n\nWithout this check:\n\n- Anyone can call hook functions directly\n- Attackers can manipulate hook state\n- Funds can be drained through fake callbacks\n\n## Router Verification Patterns\n\nThe `sender` parameter is the router, not the end user. For hooks that need user identity:\n\n### Allowlisting Pattern\n\n```solidity\nmapping(address => bool) public allowedRouters;\n\nfunction beforeSwap(\n    address sender,  \u002F\u002F This is the router\n    PoolKey calldata key,\n    IPoolManager.SwapParams calldata params,\n    bytes calldata hookData\n) external override onlyPoolManager returns (bytes4, BeforeSwapDelta, uint24) {\n    require(allowedRouters[sender], \"Router not allowed\");\n    \u002F\u002F Proceed with swap\n}\n```\n\n### User Identity via hookData\n\n```solidity\nfunction beforeSwap(\n    address sender,\n    PoolKey calldata key,\n    IPoolManager.SwapParams calldata params,\n    bytes calldata hookData\n) external override onlyPoolManager returns (bytes4, BeforeSwapDelta, uint24) {\n    \u002F\u002F Decode user address from hookData (router must include it)\n    address user = abi.decode(hookData, (address));\n    \u002F\u002F CAUTION: Router must be trusted to provide accurate user\n}\n```\n\n### msg.sender Trap\n\n```solidity\n\u002F\u002F WRONG - msg.sender is always PoolManager in hooks\nfunction beforeSwap(...) external {\n    require(msg.sender == someUser); \u002F\u002F Always fails or wrong\n}\n\n\u002F\u002F CORRECT - Use sender parameter\nfunction beforeSwap(address sender, ...) external {\n    require(allowedRouters[sender], \"Invalid router\");\n}\n```\n\n## Token Handling Hazards\n\nNot all tokens behave like standard ERC-20s:\n\n| Token Type          | Hazard                               | Mitigation                          |\n| ------------------- | ------------------------------------ | ----------------------------------- |\n| **Fee-on-transfer** | Received amount \u003C sent amount        | Measure actual balance changes      |\n| **Rebasing**        | Balance changes without transfers    | Avoid storing raw balances          |\n| **ERC-777**         | Transfer callbacks enable reentrancy | Use reentrancy guards               |\n| **Pausable**        | Transfers can be blocked             | Handle transfer failures gracefully |\n| **Blocklist**       | Specific addresses blocked           | Test with production addresses      |\n| **Low decimals**    | Precision loss in calculations       | Use appropriate scaling             |\n\n### Safe Balance Check Pattern\n\n```solidity\nfunction safeTransferIn(\n    IERC20 token,\n    address from,\n    uint256 amount\n) internal returns (uint256 received) {\n    uint256 balanceBefore = token.balanceOf(address(this));\n    token.safeTransferFrom(from, address(this), amount);\n    received = token.balanceOf(address(this)) - balanceBefore;\n}\n```\n\n## Base Hook Template\n\nStart with all permissions disabled. Enable only what you need:\n\n```solidity\n\u002F\u002F SPDX-License-Identifier: MIT\npragma solidity ^0.8.24;\n\nimport {BaseHook} from \"v4-periphery\u002Fsrc\u002Fbase\u002Fhooks\u002FBaseHook.sol\";\nimport {Hooks} from \"v4-core\u002Fsrc\u002Flibraries\u002FHooks.sol\";\nimport {IPoolManager} from \"v4-core\u002Fsrc\u002Finterfaces\u002FIPoolManager.sol\";\nimport {PoolKey} from \"v4-core\u002Fsrc\u002Ftypes\u002FPoolKey.sol\";\nimport {BeforeSwapDelta, BeforeSwapDeltaLibrary} from \"v4-core\u002Fsrc\u002Ftypes\u002FBeforeSwapDelta.sol\";\n\ncontract SecureHook is BaseHook {\n    constructor(IPoolManager _poolManager) BaseHook(_poolManager) {}\n\n    function getHookPermissions() public pure override returns (Hooks.Permissions memory) {\n        return Hooks.Permissions({\n            beforeInitialize: false,\n            afterInitialize: false,\n            beforeAddLiquidity: false,\n            afterAddLiquidity: false,\n            beforeRemoveLiquidity: false,\n            afterRemoveLiquidity: false,\n            beforeSwap: false,           \u002F\u002F Enable only if needed\n            afterSwap: false,            \u002F\u002F Enable only if needed\n            beforeDonate: false,\n            afterDonate: false,\n            beforeSwapReturnDelta: false,      \u002F\u002F DANGER: NoOp attack vector\n            afterSwapReturnDelta: false,       \u002F\u002F DANGER: Can extract value\n            afterAddLiquidityReturnDelta: false,\n            afterRemoveLiquidityReturnDelta: false\n        });\n    }\n\n    \u002F\u002F Implement only the callbacks you enabled above\n}\n```\n\nSee [references\u002Fbase-hook-template.md](references\u002Fbase-hook-template.md) for a complete implementation template.\n\n## Security Checklist\n\nBefore deploying any hook:\n\n| #   | Check                                                 | Status |\n| --- | ----------------------------------------------------- | ------ |\n| 1   | All hook callbacks verify `msg.sender == poolManager` | [ ]    |\n| 2   | Router allowlisting implemented if needed             | [ ]    |\n| 3   | No unbounded loops that can cause OOG                 | [ ]    |\n| 4   | Reentrancy guards on external calls                   | [ ]    |\n| 5   | Delta accounting sums to zero                         | [ ]    |\n| 6   | Fee-on-transfer tokens handled                        | [ ]    |\n| 7   | No hardcoded addresses                                | [ ]    |\n| 8   | Slippage parameters respected                         | [ ]    |\n| 9   | No sensitive data stored on-chain                     | [ ]    |\n| 10  | Upgrade mechanisms secured (if applicable)            | [ ]    |\n| 11  | `beforeSwapReturnDelta` justified if enabled          | [ ]    |\n| 12  | Fuzz testing completed                                | [ ]    |\n| 13  | Invariant testing completed                           | [ ]    |\n\n## Gas Budget Guidelines\n\nHook callbacks execute inside the PoolManager's transaction context. Excessive gas consumption can make swaps revert or become economically unviable.\n\n### Gas Budgets by Callback\n\n| Callback                      | Target Budget | Hard Ceiling | Notes                         |\n| ----------------------------- | ------------- | ------------ | ----------------------------- |\n| `beforeSwap`                  | \u003C 50,000 gas  | 150,000 gas  | Runs on every swap; keep lean |\n| `afterSwap`                   | \u003C 30,000 gas  | 100,000 gas  | Analytics\u002Ftracking only       |\n| `beforeAddLiquidity`          | \u003C 50,000 gas  | 200,000 gas  | May include access control    |\n| `afterAddLiquidity`           | \u003C 30,000 gas  | 100,000 gas  | Reward tracking               |\n| `beforeRemoveLiquidity`       | \u003C 50,000 gas  | 200,000 gas  | Lock validation               |\n| `afterRemoveLiquidity`        | \u003C 30,000 gas  | 100,000 gas  | Tracking\u002Faccounting           |\n| Callbacks with external calls | \u003C 100,000 gas | 300,000 gas  | External DEX routing, oracles |\n\n### Common Gas Pitfalls\n\n1. **Unbounded loops**: Iterating over dynamic arrays (e.g., all active positions) can exceed block gas limits. Cap array sizes or use pagination.\n2. **SSTORE in hot paths**: Each new storage slot costs ~20,000 gas. Prefer transient storage (`tstore`\u002F`tload`) for data that doesn't persist beyond the transaction. Requires Solidity >= 0.8.24 with EVM target set to `cancun` or later.\n3. **External calls**: Each cross-contract call adds ~2,600 gas base cost plus the callee's execution. Batch calls where possible.\n4. **String operations**: Avoid `string` manipulation in callbacks; use `bytes32` for identifiers.\n5. **Redundant reads**: Cache `poolManager` calls — repeated `getSlot0()` or `getLiquidity()` reads cost gas each time.\n\n### Measuring Gas\n\n```bash\n# Profile a specific hook callback with Foundry\nforge test --match-test test_beforeSwapGas --gas-report\n\n# Snapshot gas usage across all tests\nforge snapshot --match-contract MyHookTest\n```\n\n---\n\n## Risk Scoring System\n\nCalculate your hook's risk score (0-33):\n\n| Category              | Points | Criteria                                 |\n| --------------------- | ------ | ---------------------------------------- |\n| **Permissions**       | 0-14   | Sum of enabled permission risk levels    |\n| **External Calls**    | 0-5    | Number and type of external interactions |\n| **State Complexity**  | 0-5    | Amount of mutable state                  |\n| **Upgrade Mechanism** | 0-5    | Proxy, admin functions, etc.             |\n| **Token Handling**    | 0-4    | Non-standard token support               |\n\n### Audit Tier Recommendations\n\n| Score | Risk Level | Recommendation                 |\n| ----- | ---------- | ------------------------------ |\n| 0-5   | Low        | Self-audit + peer review       |\n| 6-12  | Medium     | Professional audit recommended |\n| 13-20 | High       | Professional audit required    |\n| 21-33 | Critical   | Multiple audits required       |\n\n## Absolute Prohibitions\n\n**Never do these things in a hook:**\n\n1. **Never trust `msg.sender` for user identity** - It's always PoolManager\n2. **Never enable `beforeSwapReturnDelta` without understanding NoOp attacks**\n3. **Never store passwords, keys, or PII on-chain**\n4. **Never use `transfer()` for ETH** - Use `call{value:}(\"\")`\n5. **Never assume token decimals** - Always query the token\n6. **Never use `block.timestamp` for randomness**\n7. **Never hardcode gas limits in calls**\n8. **Never ignore return values from external calls**\n9. **Never use `tx.origin` for authorization** - It's a phishing vector; malicious contracts can relay calls with the original user's `tx.origin`\n\n## Pre-Deployment Audit Checklist\n\n| #   | Item                                      | Required For             |\n| --- | ----------------------------------------- | ------------------------ |\n| 1   | Code review by security-focused developer | All hooks                |\n| 2   | Unit tests for all callbacks              | All hooks                |\n| 3   | Fuzz testing with Foundry                 | All hooks                |\n| 4   | Invariant testing                         | Hooks with delta returns |\n| 5   | Fork testing on mainnet                   | All hooks                |\n| 6   | Gas profiling                             | All hooks                |\n| 7   | Formal verification                       | Critical hooks           |\n| 8   | Slither\u002FMythril analysis                  | All hooks                |\n| 9   | External audit                            | Medium+ risk hooks       |\n| 10  | Bug bounty program                        | High+ risk hooks         |\n| 11  | Monitoring\u002Falerting setup                 | All production hooks     |\n\nSee [references\u002Faudit-checklist.md](references\u002Faudit-checklist.md) for detailed audit requirements.\n\n## Production Hook References\n\nLearn from audited, production hooks:\n\n| Project        | Description           | Notable Security Features     |\n| -------------- | --------------------- | ----------------------------- |\n| **Flaunch**    | Token launch platform | Multi-sig admin, timelocks    |\n| **EulerSwap**  | Lending integration   | Isolated risk per market      |\n| **Zaha TWAMM** | Time-weighted AMM     | Gradual execution reduces MEV |\n| **Bunni**      | LP management         | Concentrated liquidity guards |\n\n## External Resources\n\n### Official Documentation\n\n- [v4-core Repository](https:\u002F\u002Fgithub.com\u002FUniswap\u002Fv4-core)\n- [v4-periphery Repository](https:\u002F\u002Fgithub.com\u002FUniswap\u002Fv4-periphery)\n- [Uniswap v4 Docs](https:\u002F\u002Fdocs.uniswap.org\u002Fcontracts\u002Fv4\u002Foverview)\n- [Hook Permissions Guide](https:\u002F\u002Fdocs.uniswap.org\u002Fcontracts\u002Fv4\u002Fconcepts\u002Fhooks)\n\n### Security Resources\n\n- [Trail of Bits Audits](https:\u002F\u002Fgithub.com\u002Ftrailofbits\u002Fpublications)\n- [Certora v4 Analysis](https:\u002F\u002Fwww.certora.com\u002F)\n- [ABDK Consulting](https:\u002F\u002Fabdk.consulting\u002F)\n\n### Community\n\n- [v4-hooks-skill by @igoryuzo](https:\u002F\u002Fgithub.com\u002Figoryuzo\u002FuniswapV4-hooks-skill) - Community skill that inspired this guide\n- [v4hooks.dev](https:\u002F\u002Fwww.v4hooks.dev) - Community hook resources\n\n---\n\n## Additional References\n\n- [Base Hook Template](references\u002Fbase-hook-template.md) - Complete implementation starter\n- [Vulnerabilities Catalog](references\u002Fvulnerabilities-catalog.md) - Common patterns and mitigations\n- [Audit Checklist](references\u002Faudit-checklist.md) - Detailed pre-deployment checklist\n",{"data":37,"body":42},{"name":4,"description":6,"allowed-tools":38,"model":39,"license":28,"metadata":40},"Read, Glob, Grep, WebFetch, Task(subagent_type:Explore)","opus",{"author":8,"version":41},"1.1.0",{"type":43,"children":44},"root",[45,54,60,67,72,247,253,258,659,666,707,713,725,749,755,876,882,895,938,944,949,972,977,983,988,994,1004,1009,1015,1108,1114,1153,1159,1202,1208,1214,1219,1328,1334,1339,1357,1363,1374,1380,1468,1474,1554,1560,1636,1642,1647,1799,1805,1883,1889,1894,2180,2193,2199,2204,2489,2495,2500,2506,2710,2716,2833,2839,2924,2928,2934,2939,3069,3075,3172,3178,3186,3316,3322,3530,3541,3547,3552,3662,3668,3674,3718,3724,3757,3763,3790,3793,3799,3832],{"type":46,"tag":47,"props":48,"children":50},"element","h1",{"id":49},"v4-hook-security-foundations",[51],{"type":52,"value":53},"text","v4 Hook Security Foundations",{"type":46,"tag":55,"props":56,"children":57},"p",{},[58],{"type":52,"value":59},"Security-first guide for building Uniswap v4 hooks. Hook vulnerabilities can drain user funds—understand these concepts before writing any hook code.",{"type":46,"tag":61,"props":62,"children":64},"h2",{"id":63},"threat-model",[65],{"type":52,"value":66},"Threat Model",{"type":46,"tag":55,"props":68,"children":69},{},[70],{"type":52,"value":71},"Before writing code, understand the v4 security context:",{"type":46,"tag":73,"props":74,"children":75},"table",{},[76,100],{"type":46,"tag":77,"props":78,"children":79},"thead",{},[80],{"type":46,"tag":81,"props":82,"children":83},"tr",{},[84,90,95],{"type":46,"tag":85,"props":86,"children":87},"th",{},[88],{"type":52,"value":89},"Threat Area",{"type":46,"tag":85,"props":91,"children":92},{},[93],{"type":52,"value":94},"Description",{"type":46,"tag":85,"props":96,"children":97},{},[98],{"type":52,"value":99},"Mitigation",{"type":46,"tag":101,"props":102,"children":103},"tbody",{},[104,142,177,205,226],{"type":46,"tag":81,"props":105,"children":106},{},[107,117,131],{"type":46,"tag":108,"props":109,"children":110},"td",{},[111],{"type":46,"tag":112,"props":113,"children":114},"strong",{},[115],{"type":52,"value":116},"Caller Verification",{"type":46,"tag":108,"props":118,"children":119},{},[120,122,129],{"type":52,"value":121},"Only ",{"type":46,"tag":123,"props":124,"children":126},"code",{"className":125},[],[127],{"type":52,"value":128},"PoolManager",{"type":52,"value":130}," should invoke hook functions",{"type":46,"tag":108,"props":132,"children":133},{},[134,136],{"type":52,"value":135},"Verify ",{"type":46,"tag":123,"props":137,"children":139},{"className":138},[],[140],{"type":52,"value":141},"msg.sender == address(poolManager)",{"type":46,"tag":81,"props":143,"children":144},{},[145,153,164],{"type":46,"tag":108,"props":146,"children":147},{},[148],{"type":46,"tag":112,"props":149,"children":150},{},[151],{"type":52,"value":152},"Sender Identity",{"type":46,"tag":108,"props":154,"children":155},{},[156,162],{"type":46,"tag":123,"props":157,"children":159},{"className":158},[],[160],{"type":52,"value":161},"msg.sender",{"type":52,"value":163}," always equals PoolManager, never the end user",{"type":46,"tag":108,"props":165,"children":166},{},[167,169,175],{"type":52,"value":168},"Use ",{"type":46,"tag":123,"props":170,"children":172},{"className":171},[],[173],{"type":52,"value":174},"sender",{"type":52,"value":176}," parameter for user identity",{"type":46,"tag":81,"props":178,"children":179},{},[180,188,200],{"type":46,"tag":108,"props":181,"children":182},{},[183],{"type":46,"tag":112,"props":184,"children":185},{},[186],{"type":52,"value":187},"Router Context",{"type":46,"tag":108,"props":189,"children":190},{},[191,193,198],{"type":52,"value":192},"The ",{"type":46,"tag":123,"props":194,"children":196},{"className":195},[],[197],{"type":52,"value":174},{"type":52,"value":199}," parameter identifies the router, not the user",{"type":46,"tag":108,"props":201,"children":202},{},[203],{"type":52,"value":204},"Implement router allowlisting",{"type":46,"tag":81,"props":206,"children":207},{},[208,216,221],{"type":46,"tag":108,"props":209,"children":210},{},[211],{"type":46,"tag":112,"props":212,"children":213},{},[214],{"type":52,"value":215},"State Exposure",{"type":46,"tag":108,"props":217,"children":218},{},[219],{"type":52,"value":220},"Hook state is readable during mid-transaction execution",{"type":46,"tag":108,"props":222,"children":223},{},[224],{"type":52,"value":225},"Avoid storing sensitive data on-chain",{"type":46,"tag":81,"props":227,"children":228},{},[229,237,242],{"type":46,"tag":108,"props":230,"children":231},{},[232],{"type":46,"tag":112,"props":233,"children":234},{},[235],{"type":52,"value":236},"Reentrancy Surface",{"type":46,"tag":108,"props":238,"children":239},{},[240],{"type":52,"value":241},"External calls from hooks can enable reentrancy",{"type":46,"tag":108,"props":243,"children":244},{},[245],{"type":52,"value":246},"Use reentrancy guards; minimize external calls",{"type":46,"tag":61,"props":248,"children":250},{"id":249},"permission-flags-risk-matrix",[251],{"type":52,"value":252},"Permission Flags Risk Matrix",{"type":46,"tag":55,"props":254,"children":255},{},[256],{"type":52,"value":257},"All 14 hook permissions with associated risk levels:",{"type":46,"tag":73,"props":259,"children":260},{},[261,286],{"type":46,"tag":77,"props":262,"children":263},{},[264],{"type":46,"tag":81,"props":265,"children":266},{},[267,272,277,281],{"type":46,"tag":85,"props":268,"children":269},{},[270],{"type":52,"value":271},"Permission Flag",{"type":46,"tag":85,"props":273,"children":274},{},[275],{"type":52,"value":276},"Risk Level",{"type":46,"tag":85,"props":278,"children":279},{},[280],{"type":52,"value":94},{"type":46,"tag":85,"props":282,"children":283},{},[284],{"type":52,"value":285},"Security Notes",{"type":46,"tag":101,"props":287,"children":288},{},[289,316,342,369,395,422,448,474,500,526,551,581,607,633],{"type":46,"tag":81,"props":290,"children":291},{},[292,301,306,311],{"type":46,"tag":108,"props":293,"children":294},{},[295],{"type":46,"tag":123,"props":296,"children":298},{"className":297},[],[299],{"type":52,"value":300},"beforeInitialize",{"type":46,"tag":108,"props":302,"children":303},{},[304],{"type":52,"value":305},"LOW",{"type":46,"tag":108,"props":307,"children":308},{},[309],{"type":52,"value":310},"Called before pool creation",{"type":46,"tag":108,"props":312,"children":313},{},[314],{"type":52,"value":315},"Validate pool parameters",{"type":46,"tag":81,"props":317,"children":318},{},[319,328,332,337],{"type":46,"tag":108,"props":320,"children":321},{},[322],{"type":46,"tag":123,"props":323,"children":325},{"className":324},[],[326],{"type":52,"value":327},"afterInitialize",{"type":46,"tag":108,"props":329,"children":330},{},[331],{"type":52,"value":305},{"type":46,"tag":108,"props":333,"children":334},{},[335],{"type":52,"value":336},"Called after pool creation",{"type":46,"tag":108,"props":338,"children":339},{},[340],{"type":52,"value":341},"Safe for state initialization",{"type":46,"tag":81,"props":343,"children":344},{},[345,354,359,364],{"type":46,"tag":108,"props":346,"children":347},{},[348],{"type":46,"tag":123,"props":349,"children":351},{"className":350},[],[352],{"type":52,"value":353},"beforeAddLiquidity",{"type":46,"tag":108,"props":355,"children":356},{},[357],{"type":52,"value":358},"MEDIUM",{"type":46,"tag":108,"props":360,"children":361},{},[362],{"type":52,"value":363},"Before LP deposits",{"type":46,"tag":108,"props":365,"children":366},{},[367],{"type":52,"value":368},"Can block legitimate LPs",{"type":46,"tag":81,"props":370,"children":371},{},[372,381,385,390],{"type":46,"tag":108,"props":373,"children":374},{},[375],{"type":46,"tag":123,"props":376,"children":378},{"className":377},[],[379],{"type":52,"value":380},"afterAddLiquidity",{"type":46,"tag":108,"props":382,"children":383},{},[384],{"type":52,"value":305},{"type":46,"tag":108,"props":386,"children":387},{},[388],{"type":52,"value":389},"After LP deposits",{"type":46,"tag":108,"props":391,"children":392},{},[393],{"type":52,"value":394},"Safe for tracking\u002Frewards",{"type":46,"tag":81,"props":396,"children":397},{},[398,407,412,417],{"type":46,"tag":108,"props":399,"children":400},{},[401],{"type":46,"tag":123,"props":402,"children":404},{"className":403},[],[405],{"type":52,"value":406},"beforeRemoveLiquidity",{"type":46,"tag":108,"props":408,"children":409},{},[410],{"type":52,"value":411},"HIGH",{"type":46,"tag":108,"props":413,"children":414},{},[415],{"type":52,"value":416},"Before LP withdrawals",{"type":46,"tag":108,"props":418,"children":419},{},[420],{"type":52,"value":421},"Can trap user funds",{"type":46,"tag":81,"props":423,"children":424},{},[425,434,438,443],{"type":46,"tag":108,"props":426,"children":427},{},[428],{"type":46,"tag":123,"props":429,"children":431},{"className":430},[],[432],{"type":52,"value":433},"afterRemoveLiquidity",{"type":46,"tag":108,"props":435,"children":436},{},[437],{"type":52,"value":305},{"type":46,"tag":108,"props":439,"children":440},{},[441],{"type":52,"value":442},"After LP withdrawals",{"type":46,"tag":108,"props":444,"children":445},{},[446],{"type":52,"value":447},"Safe for tracking",{"type":46,"tag":81,"props":449,"children":450},{},[451,460,464,469],{"type":46,"tag":108,"props":452,"children":453},{},[454],{"type":46,"tag":123,"props":455,"children":457},{"className":456},[],[458],{"type":52,"value":459},"beforeSwap",{"type":46,"tag":108,"props":461,"children":462},{},[463],{"type":52,"value":411},{"type":46,"tag":108,"props":465,"children":466},{},[467],{"type":52,"value":468},"Before swap execution",{"type":46,"tag":108,"props":470,"children":471},{},[472],{"type":52,"value":473},"Can manipulate prices",{"type":46,"tag":81,"props":475,"children":476},{},[477,486,490,495],{"type":46,"tag":108,"props":478,"children":479},{},[480],{"type":46,"tag":123,"props":481,"children":483},{"className":482},[],[484],{"type":52,"value":485},"afterSwap",{"type":46,"tag":108,"props":487,"children":488},{},[489],{"type":52,"value":358},{"type":46,"tag":108,"props":491,"children":492},{},[493],{"type":52,"value":494},"After swap execution",{"type":46,"tag":108,"props":496,"children":497},{},[498],{"type":52,"value":499},"Can observe final state",{"type":46,"tag":81,"props":501,"children":502},{},[503,512,516,521],{"type":46,"tag":108,"props":504,"children":505},{},[506],{"type":46,"tag":123,"props":507,"children":509},{"className":508},[],[510],{"type":52,"value":511},"beforeDonate",{"type":46,"tag":108,"props":513,"children":514},{},[515],{"type":52,"value":305},{"type":46,"tag":108,"props":517,"children":518},{},[519],{"type":52,"value":520},"Before donations",{"type":46,"tag":108,"props":522,"children":523},{},[524],{"type":52,"value":525},"Access control only",{"type":46,"tag":81,"props":527,"children":528},{},[529,538,542,547],{"type":46,"tag":108,"props":530,"children":531},{},[532],{"type":46,"tag":123,"props":533,"children":535},{"className":534},[],[536],{"type":52,"value":537},"afterDonate",{"type":46,"tag":108,"props":539,"children":540},{},[541],{"type":52,"value":305},{"type":46,"tag":108,"props":543,"children":544},{},[545],{"type":52,"value":546},"After donations",{"type":46,"tag":108,"props":548,"children":549},{},[550],{"type":52,"value":447},{"type":46,"tag":81,"props":552,"children":553},{},[554,563,568,573],{"type":46,"tag":108,"props":555,"children":556},{},[557],{"type":46,"tag":123,"props":558,"children":560},{"className":559},[],[561],{"type":52,"value":562},"beforeSwapReturnDelta",{"type":46,"tag":108,"props":564,"children":565},{},[566],{"type":52,"value":567},"CRITICAL",{"type":46,"tag":108,"props":569,"children":570},{},[571],{"type":52,"value":572},"Returns custom swap amounts",{"type":46,"tag":108,"props":574,"children":575},{},[576],{"type":46,"tag":112,"props":577,"children":578},{},[579],{"type":52,"value":580},"NoOp attack vector",{"type":46,"tag":81,"props":582,"children":583},{},[584,593,597,602],{"type":46,"tag":108,"props":585,"children":586},{},[587],{"type":46,"tag":123,"props":588,"children":590},{"className":589},[],[591],{"type":52,"value":592},"afterSwapReturnDelta",{"type":46,"tag":108,"props":594,"children":595},{},[596],{"type":52,"value":411},{"type":46,"tag":108,"props":598,"children":599},{},[600],{"type":52,"value":601},"Modifies post-swap amounts",{"type":46,"tag":108,"props":603,"children":604},{},[605],{"type":52,"value":606},"Can extract value",{"type":46,"tag":81,"props":608,"children":609},{},[610,619,623,628],{"type":46,"tag":108,"props":611,"children":612},{},[613],{"type":46,"tag":123,"props":614,"children":616},{"className":615},[],[617],{"type":52,"value":618},"afterAddLiquidityReturnDelta",{"type":46,"tag":108,"props":620,"children":621},{},[622],{"type":52,"value":411},{"type":46,"tag":108,"props":624,"children":625},{},[626],{"type":52,"value":627},"Modifies LP token amounts",{"type":46,"tag":108,"props":629,"children":630},{},[631],{"type":52,"value":632},"Can shortchange LPs",{"type":46,"tag":81,"props":634,"children":635},{},[636,645,649,654],{"type":46,"tag":108,"props":637,"children":638},{},[639],{"type":46,"tag":123,"props":640,"children":642},{"className":641},[],[643],{"type":52,"value":644},"afterRemoveLiquidityReturnDelta",{"type":46,"tag":108,"props":646,"children":647},{},[648],{"type":52,"value":411},{"type":46,"tag":108,"props":650,"children":651},{},[652],{"type":52,"value":653},"Modifies withdrawal amounts",{"type":46,"tag":108,"props":655,"children":656},{},[657],{"type":52,"value":658},"Can steal funds",{"type":46,"tag":660,"props":661,"children":663},"h3",{"id":662},"risk-thresholds",[664],{"type":52,"value":665},"Risk Thresholds",{"type":46,"tag":667,"props":668,"children":669},"ul",{},[670,680,689,698],{"type":46,"tag":671,"props":672,"children":673},"li",{},[674,678],{"type":46,"tag":112,"props":675,"children":676},{},[677],{"type":52,"value":305},{"type":52,"value":679},": Unlikely to cause fund loss",{"type":46,"tag":671,"props":681,"children":682},{},[683,687],{"type":46,"tag":112,"props":684,"children":685},{},[686],{"type":52,"value":358},{"type":52,"value":688},": Requires careful implementation",{"type":46,"tag":671,"props":690,"children":691},{},[692,696],{"type":46,"tag":112,"props":693,"children":694},{},[695],{"type":52,"value":411},{"type":52,"value":697},": Can cause fund loss if misimplemented",{"type":46,"tag":671,"props":699,"children":700},{},[701,705],{"type":46,"tag":112,"props":702,"children":703},{},[704],{"type":52,"value":567},{"type":52,"value":706},": Can enable complete fund theft",{"type":46,"tag":61,"props":708,"children":710},{"id":709},"critical-noop-rug-pull-attack",[711],{"type":52,"value":712},"CRITICAL: NoOp Rug Pull Attack",{"type":46,"tag":55,"props":714,"children":715},{},[716,717,723],{"type":52,"value":192},{"type":46,"tag":123,"props":718,"children":720},{"className":719},[],[721],{"type":52,"value":722},"BEFORE_SWAP_RETURNS_DELTA",{"type":52,"value":724}," permission (bit 10) is the most dangerous hook permission. A malicious hook can:",{"type":46,"tag":726,"props":727,"children":728},"ol",{},[729,734,739,744],{"type":46,"tag":671,"props":730,"children":731},{},[732],{"type":52,"value":733},"Return a delta claiming it handled the entire swap",{"type":46,"tag":671,"props":735,"children":736},{},[737],{"type":52,"value":738},"PoolManager accepts this and settles the trade",{"type":46,"tag":671,"props":740,"children":741},{},[742],{"type":52,"value":743},"Hook keeps all input tokens without providing output",{"type":46,"tag":671,"props":745,"children":746},{},[747],{"type":52,"value":748},"User loses entire swap amount",{"type":46,"tag":660,"props":750,"children":752},{"id":751},"attack-pattern",[753],{"type":52,"value":754},"Attack Pattern",{"type":46,"tag":756,"props":757,"children":762},"pre",{"className":758,"code":759,"language":760,"meta":761,"style":761},"language-solidity shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","\u002F\u002F MALICIOUS - DO NOT USE\nfunction beforeSwap(\n    address,\n    PoolKey calldata,\n    IPoolManager.SwapParams calldata params,\n    bytes calldata\n) external override returns (bytes4, BeforeSwapDelta, uint24) {\n    \u002F\u002F Claim to handle the swap but steal tokens\n    int128 amountSpecified = int128(params.amountSpecified);\n    BeforeSwapDelta delta = toBeforeSwapDelta(amountSpecified, 0);\n    return (BaseHook.beforeSwap.selector, delta, 0);\n}\n","solidity","",[763],{"type":46,"tag":123,"props":764,"children":765},{"__ignoreMap":761},[766,777,786,795,804,813,822,831,840,849,858,867],{"type":46,"tag":767,"props":768,"children":771},"span",{"class":769,"line":770},"line",1,[772],{"type":46,"tag":767,"props":773,"children":774},{},[775],{"type":52,"value":776},"\u002F\u002F MALICIOUS - DO NOT USE\n",{"type":46,"tag":767,"props":778,"children":780},{"class":769,"line":779},2,[781],{"type":46,"tag":767,"props":782,"children":783},{},[784],{"type":52,"value":785},"function beforeSwap(\n",{"type":46,"tag":767,"props":787,"children":789},{"class":769,"line":788},3,[790],{"type":46,"tag":767,"props":791,"children":792},{},[793],{"type":52,"value":794},"    address,\n",{"type":46,"tag":767,"props":796,"children":798},{"class":769,"line":797},4,[799],{"type":46,"tag":767,"props":800,"children":801},{},[802],{"type":52,"value":803},"    PoolKey calldata,\n",{"type":46,"tag":767,"props":805,"children":807},{"class":769,"line":806},5,[808],{"type":46,"tag":767,"props":809,"children":810},{},[811],{"type":52,"value":812},"    IPoolManager.SwapParams calldata params,\n",{"type":46,"tag":767,"props":814,"children":816},{"class":769,"line":815},6,[817],{"type":46,"tag":767,"props":818,"children":819},{},[820],{"type":52,"value":821},"    bytes calldata\n",{"type":46,"tag":767,"props":823,"children":825},{"class":769,"line":824},7,[826],{"type":46,"tag":767,"props":827,"children":828},{},[829],{"type":52,"value":830},") external override returns (bytes4, BeforeSwapDelta, uint24) {\n",{"type":46,"tag":767,"props":832,"children":834},{"class":769,"line":833},8,[835],{"type":46,"tag":767,"props":836,"children":837},{},[838],{"type":52,"value":839},"    \u002F\u002F Claim to handle the swap but steal tokens\n",{"type":46,"tag":767,"props":841,"children":843},{"class":769,"line":842},9,[844],{"type":46,"tag":767,"props":845,"children":846},{},[847],{"type":52,"value":848},"    int128 amountSpecified = int128(params.amountSpecified);\n",{"type":46,"tag":767,"props":850,"children":852},{"class":769,"line":851},10,[853],{"type":46,"tag":767,"props":854,"children":855},{},[856],{"type":52,"value":857},"    BeforeSwapDelta delta = toBeforeSwapDelta(amountSpecified, 0);\n",{"type":46,"tag":767,"props":859,"children":861},{"class":769,"line":860},11,[862],{"type":46,"tag":767,"props":863,"children":864},{},[865],{"type":52,"value":866},"    return (BaseHook.beforeSwap.selector, delta, 0);\n",{"type":46,"tag":767,"props":868,"children":870},{"class":769,"line":869},12,[871],{"type":46,"tag":767,"props":872,"children":873},{},[874],{"type":52,"value":875},"}\n",{"type":46,"tag":660,"props":877,"children":879},{"id":878},"detection",[880],{"type":52,"value":881},"Detection",{"type":46,"tag":55,"props":883,"children":884},{},[885,887,893],{"type":52,"value":886},"Before interacting with ANY hook that has ",{"type":46,"tag":123,"props":888,"children":890},{"className":889},[],[891],{"type":52,"value":892},"beforeSwapReturnDelta: true",{"type":52,"value":894},":",{"type":46,"tag":726,"props":896,"children":897},{},[898,908,918,928],{"type":46,"tag":671,"props":899,"children":900},{},[901,906],{"type":46,"tag":112,"props":902,"children":903},{},[904],{"type":52,"value":905},"Audit the hook code",{"type":52,"value":907}," - Verify legitimate use case",{"type":46,"tag":671,"props":909,"children":910},{},[911,916],{"type":46,"tag":112,"props":912,"children":913},{},[914],{"type":52,"value":915},"Check ownership",{"type":52,"value":917}," - Is it upgradeable? By whom?",{"type":46,"tag":671,"props":919,"children":920},{},[921,926],{"type":46,"tag":112,"props":922,"children":923},{},[924],{"type":52,"value":925},"Verify track record",{"type":52,"value":927}," - Has it been audited by reputable firms?",{"type":46,"tag":671,"props":929,"children":930},{},[931,936],{"type":46,"tag":112,"props":932,"children":933},{},[934],{"type":52,"value":935},"Start small",{"type":52,"value":937}," - Test with minimal amounts first",{"type":46,"tag":660,"props":939,"children":941},{"id":940},"legitimate-uses",[942],{"type":52,"value":943},"Legitimate Uses",{"type":46,"tag":55,"props":945,"children":946},{},[947],{"type":52,"value":948},"NoOp patterns are valid for:",{"type":46,"tag":667,"props":950,"children":951},{},[952,957,962,967],{"type":46,"tag":671,"props":953,"children":954},{},[955],{"type":52,"value":956},"Just-in-time liquidity (JIT)",{"type":46,"tag":671,"props":958,"children":959},{},[960],{"type":52,"value":961},"Custom AMM curves",{"type":46,"tag":671,"props":963,"children":964},{},[965],{"type":52,"value":966},"Intent-based trading systems",{"type":46,"tag":671,"props":968,"children":969},{},[970],{"type":52,"value":971},"RFQ\u002FPMM integrations",{"type":46,"tag":55,"props":973,"children":974},{},[975],{"type":52,"value":976},"But each requires careful implementation and audit.",{"type":46,"tag":61,"props":978,"children":980},{"id":979},"delta-accounting-fundamentals",[981],{"type":52,"value":982},"Delta Accounting Fundamentals",{"type":46,"tag":55,"props":984,"children":985},{},[986],{"type":52,"value":987},"v4 uses a credit\u002Fdebit system through the PoolManager:",{"type":46,"tag":660,"props":989,"children":991},{"id":990},"core-invariant",[992],{"type":52,"value":993},"Core Invariant",{"type":46,"tag":756,"props":995,"children":999},{"className":996,"code":998,"language":52,"meta":761},[997],"language-text","For every transaction: sum(deltas) == 0\n",[1000],{"type":46,"tag":123,"props":1001,"children":1002},{"__ignoreMap":761},[1003],{"type":52,"value":998},{"type":46,"tag":55,"props":1005,"children":1006},{},[1007],{"type":52,"value":1008},"The PoolManager tracks what each address owes or is owed. At transaction end, all debts must be settled.",{"type":46,"tag":660,"props":1010,"children":1012},{"id":1011},"key-functions",[1013],{"type":52,"value":1014},"Key Functions",{"type":46,"tag":73,"props":1016,"children":1017},{},[1018,1039],{"type":46,"tag":77,"props":1019,"children":1020},{},[1021],{"type":46,"tag":81,"props":1022,"children":1023},{},[1024,1029,1034],{"type":46,"tag":85,"props":1025,"children":1026},{},[1027],{"type":52,"value":1028},"Function",{"type":46,"tag":85,"props":1030,"children":1031},{},[1032],{"type":52,"value":1033},"Purpose",{"type":46,"tag":85,"props":1035,"children":1036},{},[1037],{"type":52,"value":1038},"Direction",{"type":46,"tag":101,"props":1040,"children":1041},{},[1042,1064,1086],{"type":46,"tag":81,"props":1043,"children":1044},{},[1045,1054,1059],{"type":46,"tag":108,"props":1046,"children":1047},{},[1048],{"type":46,"tag":123,"props":1049,"children":1051},{"className":1050},[],[1052],{"type":52,"value":1053},"take(currency, to, amount)",{"type":46,"tag":108,"props":1055,"children":1056},{},[1057],{"type":52,"value":1058},"Withdraw tokens from PoolManager",{"type":46,"tag":108,"props":1060,"children":1061},{},[1062],{"type":52,"value":1063},"You receive tokens",{"type":46,"tag":81,"props":1065,"children":1066},{},[1067,1076,1081],{"type":46,"tag":108,"props":1068,"children":1069},{},[1070],{"type":46,"tag":123,"props":1071,"children":1073},{"className":1072},[],[1074],{"type":52,"value":1075},"settle(currency)",{"type":46,"tag":108,"props":1077,"children":1078},{},[1079],{"type":52,"value":1080},"Pay tokens to PoolManager",{"type":46,"tag":108,"props":1082,"children":1083},{},[1084],{"type":52,"value":1085},"You send tokens",{"type":46,"tag":81,"props":1087,"children":1088},{},[1089,1098,1103],{"type":46,"tag":108,"props":1090,"children":1091},{},[1092],{"type":46,"tag":123,"props":1093,"children":1095},{"className":1094},[],[1096],{"type":52,"value":1097},"sync(currency)",{"type":46,"tag":108,"props":1099,"children":1100},{},[1101],{"type":52,"value":1102},"Update PoolManager balance tracking",{"type":46,"tag":108,"props":1104,"children":1105},{},[1106],{"type":52,"value":1107},"Preparation for settle",{"type":46,"tag":660,"props":1109,"children":1111},{"id":1110},"settlement-pattern",[1112],{"type":52,"value":1113},"Settlement Pattern",{"type":46,"tag":756,"props":1115,"children":1117},{"className":758,"code":1116,"language":760,"meta":761,"style":761},"\u002F\u002F Correct pattern: sync before settle\npoolManager.sync(currency);\ncurrency.transfer(address(poolManager), amount);\npoolManager.settle(currency);\n",[1118],{"type":46,"tag":123,"props":1119,"children":1120},{"__ignoreMap":761},[1121,1129,1137,1145],{"type":46,"tag":767,"props":1122,"children":1123},{"class":769,"line":770},[1124],{"type":46,"tag":767,"props":1125,"children":1126},{},[1127],{"type":52,"value":1128},"\u002F\u002F Correct pattern: sync before settle\n",{"type":46,"tag":767,"props":1130,"children":1131},{"class":769,"line":779},[1132],{"type":46,"tag":767,"props":1133,"children":1134},{},[1135],{"type":52,"value":1136},"poolManager.sync(currency);\n",{"type":46,"tag":767,"props":1138,"children":1139},{"class":769,"line":788},[1140],{"type":46,"tag":767,"props":1141,"children":1142},{},[1143],{"type":52,"value":1144},"currency.transfer(address(poolManager), amount);\n",{"type":46,"tag":767,"props":1146,"children":1147},{"class":769,"line":797},[1148],{"type":46,"tag":767,"props":1149,"children":1150},{},[1151],{"type":52,"value":1152},"poolManager.settle(currency);\n",{"type":46,"tag":660,"props":1154,"children":1156},{"id":1155},"common-mistakes",[1157],{"type":52,"value":1158},"Common Mistakes",{"type":46,"tag":726,"props":1160,"children":1161},{},[1162,1172,1182,1192],{"type":46,"tag":671,"props":1163,"children":1164},{},[1165,1170],{"type":46,"tag":112,"props":1166,"children":1167},{},[1168],{"type":52,"value":1169},"Forgetting sync",{"type":52,"value":1171},": Settlement fails without sync",{"type":46,"tag":671,"props":1173,"children":1174},{},[1175,1180],{"type":46,"tag":112,"props":1176,"children":1177},{},[1178],{"type":52,"value":1179},"Wrong order",{"type":52,"value":1181},": Must sync → transfer → settle",{"type":46,"tag":671,"props":1183,"children":1184},{},[1185,1190],{"type":46,"tag":112,"props":1186,"children":1187},{},[1188],{"type":52,"value":1189},"Partial settlement",{"type":52,"value":1191},": Leaves transaction in invalid state",{"type":46,"tag":671,"props":1193,"children":1194},{},[1195,1200],{"type":46,"tag":112,"props":1196,"children":1197},{},[1198],{"type":52,"value":1199},"Double settlement",{"type":52,"value":1201},": Causes accounting errors",{"type":46,"tag":61,"props":1203,"children":1205},{"id":1204},"access-control-patterns",[1206],{"type":52,"value":1207},"Access Control Patterns",{"type":46,"tag":660,"props":1209,"children":1211},{"id":1210},"poolmanager-verification",[1212],{"type":52,"value":1213},"PoolManager Verification",{"type":46,"tag":55,"props":1215,"children":1216},{},[1217],{"type":52,"value":1218},"Every hook callback MUST verify the caller:",{"type":46,"tag":756,"props":1220,"children":1222},{"className":758,"code":1221,"language":760,"meta":761,"style":761},"modifier onlyPoolManager() {\n    require(msg.sender == address(poolManager), \"Not PoolManager\");\n    _;\n}\n\nfunction beforeSwap(\n    address sender,\n    PoolKey calldata key,\n    IPoolManager.SwapParams calldata params,\n    bytes calldata hookData\n) external override onlyPoolManager returns (bytes4, BeforeSwapDelta, uint24) {\n    \u002F\u002F Safe to proceed\n}\n",[1223],{"type":46,"tag":123,"props":1224,"children":1225},{"__ignoreMap":761},[1226,1234,1242,1250,1257,1266,1273,1281,1289,1296,1304,1312,1320],{"type":46,"tag":767,"props":1227,"children":1228},{"class":769,"line":770},[1229],{"type":46,"tag":767,"props":1230,"children":1231},{},[1232],{"type":52,"value":1233},"modifier onlyPoolManager() {\n",{"type":46,"tag":767,"props":1235,"children":1236},{"class":769,"line":779},[1237],{"type":46,"tag":767,"props":1238,"children":1239},{},[1240],{"type":52,"value":1241},"    require(msg.sender == address(poolManager), \"Not PoolManager\");\n",{"type":46,"tag":767,"props":1243,"children":1244},{"class":769,"line":788},[1245],{"type":46,"tag":767,"props":1246,"children":1247},{},[1248],{"type":52,"value":1249},"    _;\n",{"type":46,"tag":767,"props":1251,"children":1252},{"class":769,"line":797},[1253],{"type":46,"tag":767,"props":1254,"children":1255},{},[1256],{"type":52,"value":875},{"type":46,"tag":767,"props":1258,"children":1259},{"class":769,"line":806},[1260],{"type":46,"tag":767,"props":1261,"children":1263},{"emptyLinePlaceholder":1262},true,[1264],{"type":52,"value":1265},"\n",{"type":46,"tag":767,"props":1267,"children":1268},{"class":769,"line":815},[1269],{"type":46,"tag":767,"props":1270,"children":1271},{},[1272],{"type":52,"value":785},{"type":46,"tag":767,"props":1274,"children":1275},{"class":769,"line":824},[1276],{"type":46,"tag":767,"props":1277,"children":1278},{},[1279],{"type":52,"value":1280},"    address sender,\n",{"type":46,"tag":767,"props":1282,"children":1283},{"class":769,"line":833},[1284],{"type":46,"tag":767,"props":1285,"children":1286},{},[1287],{"type":52,"value":1288},"    PoolKey calldata key,\n",{"type":46,"tag":767,"props":1290,"children":1291},{"class":769,"line":842},[1292],{"type":46,"tag":767,"props":1293,"children":1294},{},[1295],{"type":52,"value":812},{"type":46,"tag":767,"props":1297,"children":1298},{"class":769,"line":851},[1299],{"type":46,"tag":767,"props":1300,"children":1301},{},[1302],{"type":52,"value":1303},"    bytes calldata hookData\n",{"type":46,"tag":767,"props":1305,"children":1306},{"class":769,"line":860},[1307],{"type":46,"tag":767,"props":1308,"children":1309},{},[1310],{"type":52,"value":1311},") external override onlyPoolManager returns (bytes4, BeforeSwapDelta, uint24) {\n",{"type":46,"tag":767,"props":1313,"children":1314},{"class":769,"line":869},[1315],{"type":46,"tag":767,"props":1316,"children":1317},{},[1318],{"type":52,"value":1319},"    \u002F\u002F Safe to proceed\n",{"type":46,"tag":767,"props":1321,"children":1323},{"class":769,"line":1322},13,[1324],{"type":46,"tag":767,"props":1325,"children":1326},{},[1327],{"type":52,"value":875},{"type":46,"tag":660,"props":1329,"children":1331},{"id":1330},"why-this-matters",[1332],{"type":52,"value":1333},"Why This Matters",{"type":46,"tag":55,"props":1335,"children":1336},{},[1337],{"type":52,"value":1338},"Without this check:",{"type":46,"tag":667,"props":1340,"children":1341},{},[1342,1347,1352],{"type":46,"tag":671,"props":1343,"children":1344},{},[1345],{"type":52,"value":1346},"Anyone can call hook functions directly",{"type":46,"tag":671,"props":1348,"children":1349},{},[1350],{"type":52,"value":1351},"Attackers can manipulate hook state",{"type":46,"tag":671,"props":1353,"children":1354},{},[1355],{"type":52,"value":1356},"Funds can be drained through fake callbacks",{"type":46,"tag":61,"props":1358,"children":1360},{"id":1359},"router-verification-patterns",[1361],{"type":52,"value":1362},"Router Verification Patterns",{"type":46,"tag":55,"props":1364,"children":1365},{},[1366,1367,1372],{"type":52,"value":192},{"type":46,"tag":123,"props":1368,"children":1370},{"className":1369},[],[1371],{"type":52,"value":174},{"type":52,"value":1373}," parameter is the router, not the end user. For hooks that need user identity:",{"type":46,"tag":660,"props":1375,"children":1377},{"id":1376},"allowlisting-pattern",[1378],{"type":52,"value":1379},"Allowlisting Pattern",{"type":46,"tag":756,"props":1381,"children":1383},{"className":758,"code":1382,"language":760,"meta":761,"style":761},"mapping(address => bool) public allowedRouters;\n\nfunction beforeSwap(\n    address sender,  \u002F\u002F This is the router\n    PoolKey calldata key,\n    IPoolManager.SwapParams calldata params,\n    bytes calldata hookData\n) external override onlyPoolManager returns (bytes4, BeforeSwapDelta, uint24) {\n    require(allowedRouters[sender], \"Router not allowed\");\n    \u002F\u002F Proceed with swap\n}\n",[1384],{"type":46,"tag":123,"props":1385,"children":1386},{"__ignoreMap":761},[1387,1395,1402,1409,1417,1424,1431,1438,1445,1453,1461],{"type":46,"tag":767,"props":1388,"children":1389},{"class":769,"line":770},[1390],{"type":46,"tag":767,"props":1391,"children":1392},{},[1393],{"type":52,"value":1394},"mapping(address => bool) public allowedRouters;\n",{"type":46,"tag":767,"props":1396,"children":1397},{"class":769,"line":779},[1398],{"type":46,"tag":767,"props":1399,"children":1400},{"emptyLinePlaceholder":1262},[1401],{"type":52,"value":1265},{"type":46,"tag":767,"props":1403,"children":1404},{"class":769,"line":788},[1405],{"type":46,"tag":767,"props":1406,"children":1407},{},[1408],{"type":52,"value":785},{"type":46,"tag":767,"props":1410,"children":1411},{"class":769,"line":797},[1412],{"type":46,"tag":767,"props":1413,"children":1414},{},[1415],{"type":52,"value":1416},"    address sender,  \u002F\u002F This is the router\n",{"type":46,"tag":767,"props":1418,"children":1419},{"class":769,"line":806},[1420],{"type":46,"tag":767,"props":1421,"children":1422},{},[1423],{"type":52,"value":1288},{"type":46,"tag":767,"props":1425,"children":1426},{"class":769,"line":815},[1427],{"type":46,"tag":767,"props":1428,"children":1429},{},[1430],{"type":52,"value":812},{"type":46,"tag":767,"props":1432,"children":1433},{"class":769,"line":824},[1434],{"type":46,"tag":767,"props":1435,"children":1436},{},[1437],{"type":52,"value":1303},{"type":46,"tag":767,"props":1439,"children":1440},{"class":769,"line":833},[1441],{"type":46,"tag":767,"props":1442,"children":1443},{},[1444],{"type":52,"value":1311},{"type":46,"tag":767,"props":1446,"children":1447},{"class":769,"line":842},[1448],{"type":46,"tag":767,"props":1449,"children":1450},{},[1451],{"type":52,"value":1452},"    require(allowedRouters[sender], \"Router not allowed\");\n",{"type":46,"tag":767,"props":1454,"children":1455},{"class":769,"line":851},[1456],{"type":46,"tag":767,"props":1457,"children":1458},{},[1459],{"type":52,"value":1460},"    \u002F\u002F Proceed with swap\n",{"type":46,"tag":767,"props":1462,"children":1463},{"class":769,"line":860},[1464],{"type":46,"tag":767,"props":1465,"children":1466},{},[1467],{"type":52,"value":875},{"type":46,"tag":660,"props":1469,"children":1471},{"id":1470},"user-identity-via-hookdata",[1472],{"type":52,"value":1473},"User Identity via hookData",{"type":46,"tag":756,"props":1475,"children":1477},{"className":758,"code":1476,"language":760,"meta":761,"style":761},"function beforeSwap(\n    address sender,\n    PoolKey calldata key,\n    IPoolManager.SwapParams calldata params,\n    bytes calldata hookData\n) external override onlyPoolManager returns (bytes4, BeforeSwapDelta, uint24) {\n    \u002F\u002F Decode user address from hookData (router must include it)\n    address user = abi.decode(hookData, (address));\n    \u002F\u002F CAUTION: Router must be trusted to provide accurate user\n}\n",[1478],{"type":46,"tag":123,"props":1479,"children":1480},{"__ignoreMap":761},[1481,1488,1495,1502,1509,1516,1523,1531,1539,1547],{"type":46,"tag":767,"props":1482,"children":1483},{"class":769,"line":770},[1484],{"type":46,"tag":767,"props":1485,"children":1486},{},[1487],{"type":52,"value":785},{"type":46,"tag":767,"props":1489,"children":1490},{"class":769,"line":779},[1491],{"type":46,"tag":767,"props":1492,"children":1493},{},[1494],{"type":52,"value":1280},{"type":46,"tag":767,"props":1496,"children":1497},{"class":769,"line":788},[1498],{"type":46,"tag":767,"props":1499,"children":1500},{},[1501],{"type":52,"value":1288},{"type":46,"tag":767,"props":1503,"children":1504},{"class":769,"line":797},[1505],{"type":46,"tag":767,"props":1506,"children":1507},{},[1508],{"type":52,"value":812},{"type":46,"tag":767,"props":1510,"children":1511},{"class":769,"line":806},[1512],{"type":46,"tag":767,"props":1513,"children":1514},{},[1515],{"type":52,"value":1303},{"type":46,"tag":767,"props":1517,"children":1518},{"class":769,"line":815},[1519],{"type":46,"tag":767,"props":1520,"children":1521},{},[1522],{"type":52,"value":1311},{"type":46,"tag":767,"props":1524,"children":1525},{"class":769,"line":824},[1526],{"type":46,"tag":767,"props":1527,"children":1528},{},[1529],{"type":52,"value":1530},"    \u002F\u002F Decode user address from hookData (router must include it)\n",{"type":46,"tag":767,"props":1532,"children":1533},{"class":769,"line":833},[1534],{"type":46,"tag":767,"props":1535,"children":1536},{},[1537],{"type":52,"value":1538},"    address user = abi.decode(hookData, (address));\n",{"type":46,"tag":767,"props":1540,"children":1541},{"class":769,"line":842},[1542],{"type":46,"tag":767,"props":1543,"children":1544},{},[1545],{"type":52,"value":1546},"    \u002F\u002F CAUTION: Router must be trusted to provide accurate user\n",{"type":46,"tag":767,"props":1548,"children":1549},{"class":769,"line":851},[1550],{"type":46,"tag":767,"props":1551,"children":1552},{},[1553],{"type":52,"value":875},{"type":46,"tag":660,"props":1555,"children":1557},{"id":1556},"msgsender-trap",[1558],{"type":52,"value":1559},"msg.sender Trap",{"type":46,"tag":756,"props":1561,"children":1563},{"className":758,"code":1562,"language":760,"meta":761,"style":761},"\u002F\u002F WRONG - msg.sender is always PoolManager in hooks\nfunction beforeSwap(...) external {\n    require(msg.sender == someUser); \u002F\u002F Always fails or wrong\n}\n\n\u002F\u002F CORRECT - Use sender parameter\nfunction beforeSwap(address sender, ...) external {\n    require(allowedRouters[sender], \"Invalid router\");\n}\n",[1564],{"type":46,"tag":123,"props":1565,"children":1566},{"__ignoreMap":761},[1567,1575,1583,1591,1598,1605,1613,1621,1629],{"type":46,"tag":767,"props":1568,"children":1569},{"class":769,"line":770},[1570],{"type":46,"tag":767,"props":1571,"children":1572},{},[1573],{"type":52,"value":1574},"\u002F\u002F WRONG - msg.sender is always PoolManager in hooks\n",{"type":46,"tag":767,"props":1576,"children":1577},{"class":769,"line":779},[1578],{"type":46,"tag":767,"props":1579,"children":1580},{},[1581],{"type":52,"value":1582},"function beforeSwap(...) external {\n",{"type":46,"tag":767,"props":1584,"children":1585},{"class":769,"line":788},[1586],{"type":46,"tag":767,"props":1587,"children":1588},{},[1589],{"type":52,"value":1590},"    require(msg.sender == someUser); \u002F\u002F Always fails or wrong\n",{"type":46,"tag":767,"props":1592,"children":1593},{"class":769,"line":797},[1594],{"type":46,"tag":767,"props":1595,"children":1596},{},[1597],{"type":52,"value":875},{"type":46,"tag":767,"props":1599,"children":1600},{"class":769,"line":806},[1601],{"type":46,"tag":767,"props":1602,"children":1603},{"emptyLinePlaceholder":1262},[1604],{"type":52,"value":1265},{"type":46,"tag":767,"props":1606,"children":1607},{"class":769,"line":815},[1608],{"type":46,"tag":767,"props":1609,"children":1610},{},[1611],{"type":52,"value":1612},"\u002F\u002F CORRECT - Use sender parameter\n",{"type":46,"tag":767,"props":1614,"children":1615},{"class":769,"line":824},[1616],{"type":46,"tag":767,"props":1617,"children":1618},{},[1619],{"type":52,"value":1620},"function beforeSwap(address sender, ...) external {\n",{"type":46,"tag":767,"props":1622,"children":1623},{"class":769,"line":833},[1624],{"type":46,"tag":767,"props":1625,"children":1626},{},[1627],{"type":52,"value":1628},"    require(allowedRouters[sender], \"Invalid router\");\n",{"type":46,"tag":767,"props":1630,"children":1631},{"class":769,"line":842},[1632],{"type":46,"tag":767,"props":1633,"children":1634},{},[1635],{"type":52,"value":875},{"type":46,"tag":61,"props":1637,"children":1639},{"id":1638},"token-handling-hazards",[1640],{"type":52,"value":1641},"Token Handling Hazards",{"type":46,"tag":55,"props":1643,"children":1644},{},[1645],{"type":52,"value":1646},"Not all tokens behave like standard ERC-20s:",{"type":46,"tag":73,"props":1648,"children":1649},{},[1650,1670],{"type":46,"tag":77,"props":1651,"children":1652},{},[1653],{"type":46,"tag":81,"props":1654,"children":1655},{},[1656,1661,1666],{"type":46,"tag":85,"props":1657,"children":1658},{},[1659],{"type":52,"value":1660},"Token Type",{"type":46,"tag":85,"props":1662,"children":1663},{},[1664],{"type":52,"value":1665},"Hazard",{"type":46,"tag":85,"props":1667,"children":1668},{},[1669],{"type":52,"value":99},{"type":46,"tag":101,"props":1671,"children":1672},{},[1673,1694,1715,1736,1757,1778],{"type":46,"tag":81,"props":1674,"children":1675},{},[1676,1684,1689],{"type":46,"tag":108,"props":1677,"children":1678},{},[1679],{"type":46,"tag":112,"props":1680,"children":1681},{},[1682],{"type":52,"value":1683},"Fee-on-transfer",{"type":46,"tag":108,"props":1685,"children":1686},{},[1687],{"type":52,"value":1688},"Received amount \u003C sent amount",{"type":46,"tag":108,"props":1690,"children":1691},{},[1692],{"type":52,"value":1693},"Measure actual balance changes",{"type":46,"tag":81,"props":1695,"children":1696},{},[1697,1705,1710],{"type":46,"tag":108,"props":1698,"children":1699},{},[1700],{"type":46,"tag":112,"props":1701,"children":1702},{},[1703],{"type":52,"value":1704},"Rebasing",{"type":46,"tag":108,"props":1706,"children":1707},{},[1708],{"type":52,"value":1709},"Balance changes without transfers",{"type":46,"tag":108,"props":1711,"children":1712},{},[1713],{"type":52,"value":1714},"Avoid storing raw balances",{"type":46,"tag":81,"props":1716,"children":1717},{},[1718,1726,1731],{"type":46,"tag":108,"props":1719,"children":1720},{},[1721],{"type":46,"tag":112,"props":1722,"children":1723},{},[1724],{"type":52,"value":1725},"ERC-777",{"type":46,"tag":108,"props":1727,"children":1728},{},[1729],{"type":52,"value":1730},"Transfer callbacks enable reentrancy",{"type":46,"tag":108,"props":1732,"children":1733},{},[1734],{"type":52,"value":1735},"Use reentrancy guards",{"type":46,"tag":81,"props":1737,"children":1738},{},[1739,1747,1752],{"type":46,"tag":108,"props":1740,"children":1741},{},[1742],{"type":46,"tag":112,"props":1743,"children":1744},{},[1745],{"type":52,"value":1746},"Pausable",{"type":46,"tag":108,"props":1748,"children":1749},{},[1750],{"type":52,"value":1751},"Transfers can be blocked",{"type":46,"tag":108,"props":1753,"children":1754},{},[1755],{"type":52,"value":1756},"Handle transfer failures gracefully",{"type":46,"tag":81,"props":1758,"children":1759},{},[1760,1768,1773],{"type":46,"tag":108,"props":1761,"children":1762},{},[1763],{"type":46,"tag":112,"props":1764,"children":1765},{},[1766],{"type":52,"value":1767},"Blocklist",{"type":46,"tag":108,"props":1769,"children":1770},{},[1771],{"type":52,"value":1772},"Specific addresses blocked",{"type":46,"tag":108,"props":1774,"children":1775},{},[1776],{"type":52,"value":1777},"Test with production addresses",{"type":46,"tag":81,"props":1779,"children":1780},{},[1781,1789,1794],{"type":46,"tag":108,"props":1782,"children":1783},{},[1784],{"type":46,"tag":112,"props":1785,"children":1786},{},[1787],{"type":52,"value":1788},"Low decimals",{"type":46,"tag":108,"props":1790,"children":1791},{},[1792],{"type":52,"value":1793},"Precision loss in calculations",{"type":46,"tag":108,"props":1795,"children":1796},{},[1797],{"type":52,"value":1798},"Use appropriate scaling",{"type":46,"tag":660,"props":1800,"children":1802},{"id":1801},"safe-balance-check-pattern",[1803],{"type":52,"value":1804},"Safe Balance Check Pattern",{"type":46,"tag":756,"props":1806,"children":1808},{"className":758,"code":1807,"language":760,"meta":761,"style":761},"function safeTransferIn(\n    IERC20 token,\n    address from,\n    uint256 amount\n) internal returns (uint256 received) {\n    uint256 balanceBefore = token.balanceOf(address(this));\n    token.safeTransferFrom(from, address(this), amount);\n    received = token.balanceOf(address(this)) - balanceBefore;\n}\n",[1809],{"type":46,"tag":123,"props":1810,"children":1811},{"__ignoreMap":761},[1812,1820,1828,1836,1844,1852,1860,1868,1876],{"type":46,"tag":767,"props":1813,"children":1814},{"class":769,"line":770},[1815],{"type":46,"tag":767,"props":1816,"children":1817},{},[1818],{"type":52,"value":1819},"function safeTransferIn(\n",{"type":46,"tag":767,"props":1821,"children":1822},{"class":769,"line":779},[1823],{"type":46,"tag":767,"props":1824,"children":1825},{},[1826],{"type":52,"value":1827},"    IERC20 token,\n",{"type":46,"tag":767,"props":1829,"children":1830},{"class":769,"line":788},[1831],{"type":46,"tag":767,"props":1832,"children":1833},{},[1834],{"type":52,"value":1835},"    address from,\n",{"type":46,"tag":767,"props":1837,"children":1838},{"class":769,"line":797},[1839],{"type":46,"tag":767,"props":1840,"children":1841},{},[1842],{"type":52,"value":1843},"    uint256 amount\n",{"type":46,"tag":767,"props":1845,"children":1846},{"class":769,"line":806},[1847],{"type":46,"tag":767,"props":1848,"children":1849},{},[1850],{"type":52,"value":1851},") internal returns (uint256 received) {\n",{"type":46,"tag":767,"props":1853,"children":1854},{"class":769,"line":815},[1855],{"type":46,"tag":767,"props":1856,"children":1857},{},[1858],{"type":52,"value":1859},"    uint256 balanceBefore = token.balanceOf(address(this));\n",{"type":46,"tag":767,"props":1861,"children":1862},{"class":769,"line":824},[1863],{"type":46,"tag":767,"props":1864,"children":1865},{},[1866],{"type":52,"value":1867},"    token.safeTransferFrom(from, address(this), amount);\n",{"type":46,"tag":767,"props":1869,"children":1870},{"class":769,"line":833},[1871],{"type":46,"tag":767,"props":1872,"children":1873},{},[1874],{"type":52,"value":1875},"    received = token.balanceOf(address(this)) - balanceBefore;\n",{"type":46,"tag":767,"props":1877,"children":1878},{"class":769,"line":842},[1879],{"type":46,"tag":767,"props":1880,"children":1881},{},[1882],{"type":52,"value":875},{"type":46,"tag":61,"props":1884,"children":1886},{"id":1885},"base-hook-template",[1887],{"type":52,"value":1888},"Base Hook Template",{"type":46,"tag":55,"props":1890,"children":1891},{},[1892],{"type":52,"value":1893},"Start with all permissions disabled. Enable only what you need:",{"type":46,"tag":756,"props":1895,"children":1897},{"className":758,"code":1896,"language":760,"meta":761,"style":761},"\u002F\u002F SPDX-License-Identifier: MIT\npragma solidity ^0.8.24;\n\nimport {BaseHook} from \"v4-periphery\u002Fsrc\u002Fbase\u002Fhooks\u002FBaseHook.sol\";\nimport {Hooks} from \"v4-core\u002Fsrc\u002Flibraries\u002FHooks.sol\";\nimport {IPoolManager} from \"v4-core\u002Fsrc\u002Finterfaces\u002FIPoolManager.sol\";\nimport {PoolKey} from \"v4-core\u002Fsrc\u002Ftypes\u002FPoolKey.sol\";\nimport {BeforeSwapDelta, BeforeSwapDeltaLibrary} from \"v4-core\u002Fsrc\u002Ftypes\u002FBeforeSwapDelta.sol\";\n\ncontract SecureHook is BaseHook {\n    constructor(IPoolManager _poolManager) BaseHook(_poolManager) {}\n\n    function getHookPermissions() public pure override returns (Hooks.Permissions memory) {\n        return Hooks.Permissions({\n            beforeInitialize: false,\n            afterInitialize: false,\n            beforeAddLiquidity: false,\n            afterAddLiquidity: false,\n            beforeRemoveLiquidity: false,\n            afterRemoveLiquidity: false,\n            beforeSwap: false,           \u002F\u002F Enable only if needed\n            afterSwap: false,            \u002F\u002F Enable only if needed\n            beforeDonate: false,\n            afterDonate: false,\n            beforeSwapReturnDelta: false,      \u002F\u002F DANGER: NoOp attack vector\n            afterSwapReturnDelta: false,       \u002F\u002F DANGER: Can extract value\n            afterAddLiquidityReturnDelta: false,\n            afterRemoveLiquidityReturnDelta: false\n        });\n    }\n\n    \u002F\u002F Implement only the callbacks you enabled above\n}\n",[1898],{"type":46,"tag":123,"props":1899,"children":1900},{"__ignoreMap":761},[1901,1909,1917,1924,1932,1940,1948,1956,1964,1971,1979,1987,1994,2002,2011,2020,2029,2038,2047,2056,2065,2074,2083,2092,2101,2110,2119,2128,2137,2146,2155,2163,2172],{"type":46,"tag":767,"props":1902,"children":1903},{"class":769,"line":770},[1904],{"type":46,"tag":767,"props":1905,"children":1906},{},[1907],{"type":52,"value":1908},"\u002F\u002F SPDX-License-Identifier: MIT\n",{"type":46,"tag":767,"props":1910,"children":1911},{"class":769,"line":779},[1912],{"type":46,"tag":767,"props":1913,"children":1914},{},[1915],{"type":52,"value":1916},"pragma solidity ^0.8.24;\n",{"type":46,"tag":767,"props":1918,"children":1919},{"class":769,"line":788},[1920],{"type":46,"tag":767,"props":1921,"children":1922},{"emptyLinePlaceholder":1262},[1923],{"type":52,"value":1265},{"type":46,"tag":767,"props":1925,"children":1926},{"class":769,"line":797},[1927],{"type":46,"tag":767,"props":1928,"children":1929},{},[1930],{"type":52,"value":1931},"import {BaseHook} from \"v4-periphery\u002Fsrc\u002Fbase\u002Fhooks\u002FBaseHook.sol\";\n",{"type":46,"tag":767,"props":1933,"children":1934},{"class":769,"line":806},[1935],{"type":46,"tag":767,"props":1936,"children":1937},{},[1938],{"type":52,"value":1939},"import {Hooks} from \"v4-core\u002Fsrc\u002Flibraries\u002FHooks.sol\";\n",{"type":46,"tag":767,"props":1941,"children":1942},{"class":769,"line":815},[1943],{"type":46,"tag":767,"props":1944,"children":1945},{},[1946],{"type":52,"value":1947},"import {IPoolManager} from \"v4-core\u002Fsrc\u002Finterfaces\u002FIPoolManager.sol\";\n",{"type":46,"tag":767,"props":1949,"children":1950},{"class":769,"line":824},[1951],{"type":46,"tag":767,"props":1952,"children":1953},{},[1954],{"type":52,"value":1955},"import {PoolKey} from \"v4-core\u002Fsrc\u002Ftypes\u002FPoolKey.sol\";\n",{"type":46,"tag":767,"props":1957,"children":1958},{"class":769,"line":833},[1959],{"type":46,"tag":767,"props":1960,"children":1961},{},[1962],{"type":52,"value":1963},"import {BeforeSwapDelta, BeforeSwapDeltaLibrary} from \"v4-core\u002Fsrc\u002Ftypes\u002FBeforeSwapDelta.sol\";\n",{"type":46,"tag":767,"props":1965,"children":1966},{"class":769,"line":842},[1967],{"type":46,"tag":767,"props":1968,"children":1969},{"emptyLinePlaceholder":1262},[1970],{"type":52,"value":1265},{"type":46,"tag":767,"props":1972,"children":1973},{"class":769,"line":851},[1974],{"type":46,"tag":767,"props":1975,"children":1976},{},[1977],{"type":52,"value":1978},"contract SecureHook is BaseHook {\n",{"type":46,"tag":767,"props":1980,"children":1981},{"class":769,"line":860},[1982],{"type":46,"tag":767,"props":1983,"children":1984},{},[1985],{"type":52,"value":1986},"    constructor(IPoolManager _poolManager) BaseHook(_poolManager) {}\n",{"type":46,"tag":767,"props":1988,"children":1989},{"class":769,"line":869},[1990],{"type":46,"tag":767,"props":1991,"children":1992},{"emptyLinePlaceholder":1262},[1993],{"type":52,"value":1265},{"type":46,"tag":767,"props":1995,"children":1996},{"class":769,"line":1322},[1997],{"type":46,"tag":767,"props":1998,"children":1999},{},[2000],{"type":52,"value":2001},"    function getHookPermissions() public pure override returns (Hooks.Permissions memory) {\n",{"type":46,"tag":767,"props":2003,"children":2005},{"class":769,"line":2004},14,[2006],{"type":46,"tag":767,"props":2007,"children":2008},{},[2009],{"type":52,"value":2010},"        return Hooks.Permissions({\n",{"type":46,"tag":767,"props":2012,"children":2014},{"class":769,"line":2013},15,[2015],{"type":46,"tag":767,"props":2016,"children":2017},{},[2018],{"type":52,"value":2019},"            beforeInitialize: false,\n",{"type":46,"tag":767,"props":2021,"children":2023},{"class":769,"line":2022},16,[2024],{"type":46,"tag":767,"props":2025,"children":2026},{},[2027],{"type":52,"value":2028},"            afterInitialize: false,\n",{"type":46,"tag":767,"props":2030,"children":2032},{"class":769,"line":2031},17,[2033],{"type":46,"tag":767,"props":2034,"children":2035},{},[2036],{"type":52,"value":2037},"            beforeAddLiquidity: false,\n",{"type":46,"tag":767,"props":2039,"children":2041},{"class":769,"line":2040},18,[2042],{"type":46,"tag":767,"props":2043,"children":2044},{},[2045],{"type":52,"value":2046},"            afterAddLiquidity: false,\n",{"type":46,"tag":767,"props":2048,"children":2050},{"class":769,"line":2049},19,[2051],{"type":46,"tag":767,"props":2052,"children":2053},{},[2054],{"type":52,"value":2055},"            beforeRemoveLiquidity: false,\n",{"type":46,"tag":767,"props":2057,"children":2059},{"class":769,"line":2058},20,[2060],{"type":46,"tag":767,"props":2061,"children":2062},{},[2063],{"type":52,"value":2064},"            afterRemoveLiquidity: false,\n",{"type":46,"tag":767,"props":2066,"children":2068},{"class":769,"line":2067},21,[2069],{"type":46,"tag":767,"props":2070,"children":2071},{},[2072],{"type":52,"value":2073},"            beforeSwap: false,           \u002F\u002F Enable only if needed\n",{"type":46,"tag":767,"props":2075,"children":2077},{"class":769,"line":2076},22,[2078],{"type":46,"tag":767,"props":2079,"children":2080},{},[2081],{"type":52,"value":2082},"            afterSwap: false,            \u002F\u002F Enable only if needed\n",{"type":46,"tag":767,"props":2084,"children":2086},{"class":769,"line":2085},23,[2087],{"type":46,"tag":767,"props":2088,"children":2089},{},[2090],{"type":52,"value":2091},"            beforeDonate: false,\n",{"type":46,"tag":767,"props":2093,"children":2095},{"class":769,"line":2094},24,[2096],{"type":46,"tag":767,"props":2097,"children":2098},{},[2099],{"type":52,"value":2100},"            afterDonate: false,\n",{"type":46,"tag":767,"props":2102,"children":2104},{"class":769,"line":2103},25,[2105],{"type":46,"tag":767,"props":2106,"children":2107},{},[2108],{"type":52,"value":2109},"            beforeSwapReturnDelta: false,      \u002F\u002F DANGER: NoOp attack vector\n",{"type":46,"tag":767,"props":2111,"children":2113},{"class":769,"line":2112},26,[2114],{"type":46,"tag":767,"props":2115,"children":2116},{},[2117],{"type":52,"value":2118},"            afterSwapReturnDelta: false,       \u002F\u002F DANGER: Can extract value\n",{"type":46,"tag":767,"props":2120,"children":2122},{"class":769,"line":2121},27,[2123],{"type":46,"tag":767,"props":2124,"children":2125},{},[2126],{"type":52,"value":2127},"            afterAddLiquidityReturnDelta: false,\n",{"type":46,"tag":767,"props":2129,"children":2131},{"class":769,"line":2130},28,[2132],{"type":46,"tag":767,"props":2133,"children":2134},{},[2135],{"type":52,"value":2136},"            afterRemoveLiquidityReturnDelta: false\n",{"type":46,"tag":767,"props":2138,"children":2140},{"class":769,"line":2139},29,[2141],{"type":46,"tag":767,"props":2142,"children":2143},{},[2144],{"type":52,"value":2145},"        });\n",{"type":46,"tag":767,"props":2147,"children":2149},{"class":769,"line":2148},30,[2150],{"type":46,"tag":767,"props":2151,"children":2152},{},[2153],{"type":52,"value":2154},"    }\n",{"type":46,"tag":767,"props":2156,"children":2158},{"class":769,"line":2157},31,[2159],{"type":46,"tag":767,"props":2160,"children":2161},{"emptyLinePlaceholder":1262},[2162],{"type":52,"value":1265},{"type":46,"tag":767,"props":2164,"children":2166},{"class":769,"line":2165},32,[2167],{"type":46,"tag":767,"props":2168,"children":2169},{},[2170],{"type":52,"value":2171},"    \u002F\u002F Implement only the callbacks you enabled above\n",{"type":46,"tag":767,"props":2173,"children":2175},{"class":769,"line":2174},33,[2176],{"type":46,"tag":767,"props":2177,"children":2178},{},[2179],{"type":52,"value":875},{"type":46,"tag":55,"props":2181,"children":2182},{},[2183,2185,2191],{"type":52,"value":2184},"See ",{"type":46,"tag":2186,"props":2187,"children":2189},"a",{"href":2188},"references\u002Fbase-hook-template.md",[2190],{"type":52,"value":2188},{"type":52,"value":2192}," for a complete implementation template.",{"type":46,"tag":61,"props":2194,"children":2196},{"id":2195},"security-checklist",[2197],{"type":52,"value":2198},"Security Checklist",{"type":46,"tag":55,"props":2200,"children":2201},{},[2202],{"type":52,"value":2203},"Before deploying any hook:",{"type":46,"tag":73,"props":2205,"children":2206},{},[2207,2228],{"type":46,"tag":77,"props":2208,"children":2209},{},[2210],{"type":46,"tag":81,"props":2211,"children":2212},{},[2213,2218,2223],{"type":46,"tag":85,"props":2214,"children":2215},{},[2216],{"type":52,"value":2217},"#",{"type":46,"tag":85,"props":2219,"children":2220},{},[2221],{"type":52,"value":2222},"Check",{"type":46,"tag":85,"props":2224,"children":2225},{},[2226],{"type":52,"value":2227},"Status",{"type":46,"tag":101,"props":2229,"children":2230},{},[2231,2256,2275,2294,2313,2332,2351,2370,2389,2408,2427,2451,2470],{"type":46,"tag":81,"props":2232,"children":2233},{},[2234,2239,2250],{"type":46,"tag":108,"props":2235,"children":2236},{},[2237],{"type":52,"value":2238},"1",{"type":46,"tag":108,"props":2240,"children":2241},{},[2242,2244],{"type":52,"value":2243},"All hook callbacks verify ",{"type":46,"tag":123,"props":2245,"children":2247},{"className":2246},[],[2248],{"type":52,"value":2249},"msg.sender == poolManager",{"type":46,"tag":108,"props":2251,"children":2252},{},[2253],{"type":46,"tag":767,"props":2254,"children":2255},{},[],{"type":46,"tag":81,"props":2257,"children":2258},{},[2259,2264,2269],{"type":46,"tag":108,"props":2260,"children":2261},{},[2262],{"type":52,"value":2263},"2",{"type":46,"tag":108,"props":2265,"children":2266},{},[2267],{"type":52,"value":2268},"Router allowlisting implemented if needed",{"type":46,"tag":108,"props":2270,"children":2271},{},[2272],{"type":46,"tag":767,"props":2273,"children":2274},{},[],{"type":46,"tag":81,"props":2276,"children":2277},{},[2278,2283,2288],{"type":46,"tag":108,"props":2279,"children":2280},{},[2281],{"type":52,"value":2282},"3",{"type":46,"tag":108,"props":2284,"children":2285},{},[2286],{"type":52,"value":2287},"No unbounded loops that can cause OOG",{"type":46,"tag":108,"props":2289,"children":2290},{},[2291],{"type":46,"tag":767,"props":2292,"children":2293},{},[],{"type":46,"tag":81,"props":2295,"children":2296},{},[2297,2302,2307],{"type":46,"tag":108,"props":2298,"children":2299},{},[2300],{"type":52,"value":2301},"4",{"type":46,"tag":108,"props":2303,"children":2304},{},[2305],{"type":52,"value":2306},"Reentrancy guards on external calls",{"type":46,"tag":108,"props":2308,"children":2309},{},[2310],{"type":46,"tag":767,"props":2311,"children":2312},{},[],{"type":46,"tag":81,"props":2314,"children":2315},{},[2316,2321,2326],{"type":46,"tag":108,"props":2317,"children":2318},{},[2319],{"type":52,"value":2320},"5",{"type":46,"tag":108,"props":2322,"children":2323},{},[2324],{"type":52,"value":2325},"Delta accounting sums to zero",{"type":46,"tag":108,"props":2327,"children":2328},{},[2329],{"type":46,"tag":767,"props":2330,"children":2331},{},[],{"type":46,"tag":81,"props":2333,"children":2334},{},[2335,2340,2345],{"type":46,"tag":108,"props":2336,"children":2337},{},[2338],{"type":52,"value":2339},"6",{"type":46,"tag":108,"props":2341,"children":2342},{},[2343],{"type":52,"value":2344},"Fee-on-transfer tokens handled",{"type":46,"tag":108,"props":2346,"children":2347},{},[2348],{"type":46,"tag":767,"props":2349,"children":2350},{},[],{"type":46,"tag":81,"props":2352,"children":2353},{},[2354,2359,2364],{"type":46,"tag":108,"props":2355,"children":2356},{},[2357],{"type":52,"value":2358},"7",{"type":46,"tag":108,"props":2360,"children":2361},{},[2362],{"type":52,"value":2363},"No hardcoded addresses",{"type":46,"tag":108,"props":2365,"children":2366},{},[2367],{"type":46,"tag":767,"props":2368,"children":2369},{},[],{"type":46,"tag":81,"props":2371,"children":2372},{},[2373,2378,2383],{"type":46,"tag":108,"props":2374,"children":2375},{},[2376],{"type":52,"value":2377},"8",{"type":46,"tag":108,"props":2379,"children":2380},{},[2381],{"type":52,"value":2382},"Slippage parameters respected",{"type":46,"tag":108,"props":2384,"children":2385},{},[2386],{"type":46,"tag":767,"props":2387,"children":2388},{},[],{"type":46,"tag":81,"props":2390,"children":2391},{},[2392,2397,2402],{"type":46,"tag":108,"props":2393,"children":2394},{},[2395],{"type":52,"value":2396},"9",{"type":46,"tag":108,"props":2398,"children":2399},{},[2400],{"type":52,"value":2401},"No sensitive data stored on-chain",{"type":46,"tag":108,"props":2403,"children":2404},{},[2405],{"type":46,"tag":767,"props":2406,"children":2407},{},[],{"type":46,"tag":81,"props":2409,"children":2410},{},[2411,2416,2421],{"type":46,"tag":108,"props":2412,"children":2413},{},[2414],{"type":52,"value":2415},"10",{"type":46,"tag":108,"props":2417,"children":2418},{},[2419],{"type":52,"value":2420},"Upgrade mechanisms secured (if applicable)",{"type":46,"tag":108,"props":2422,"children":2423},{},[2424],{"type":46,"tag":767,"props":2425,"children":2426},{},[],{"type":46,"tag":81,"props":2428,"children":2429},{},[2430,2435,2445],{"type":46,"tag":108,"props":2431,"children":2432},{},[2433],{"type":52,"value":2434},"11",{"type":46,"tag":108,"props":2436,"children":2437},{},[2438,2443],{"type":46,"tag":123,"props":2439,"children":2441},{"className":2440},[],[2442],{"type":52,"value":562},{"type":52,"value":2444}," justified if enabled",{"type":46,"tag":108,"props":2446,"children":2447},{},[2448],{"type":46,"tag":767,"props":2449,"children":2450},{},[],{"type":46,"tag":81,"props":2452,"children":2453},{},[2454,2459,2464],{"type":46,"tag":108,"props":2455,"children":2456},{},[2457],{"type":52,"value":2458},"12",{"type":46,"tag":108,"props":2460,"children":2461},{},[2462],{"type":52,"value":2463},"Fuzz testing completed",{"type":46,"tag":108,"props":2465,"children":2466},{},[2467],{"type":46,"tag":767,"props":2468,"children":2469},{},[],{"type":46,"tag":81,"props":2471,"children":2472},{},[2473,2478,2483],{"type":46,"tag":108,"props":2474,"children":2475},{},[2476],{"type":52,"value":2477},"13",{"type":46,"tag":108,"props":2479,"children":2480},{},[2481],{"type":52,"value":2482},"Invariant testing completed",{"type":46,"tag":108,"props":2484,"children":2485},{},[2486],{"type":46,"tag":767,"props":2487,"children":2488},{},[],{"type":46,"tag":61,"props":2490,"children":2492},{"id":2491},"gas-budget-guidelines",[2493],{"type":52,"value":2494},"Gas Budget Guidelines",{"type":46,"tag":55,"props":2496,"children":2497},{},[2498],{"type":52,"value":2499},"Hook callbacks execute inside the PoolManager's transaction context. Excessive gas consumption can make swaps revert or become economically unviable.",{"type":46,"tag":660,"props":2501,"children":2503},{"id":2502},"gas-budgets-by-callback",[2504],{"type":52,"value":2505},"Gas Budgets by Callback",{"type":46,"tag":73,"props":2507,"children":2508},{},[2509,2535],{"type":46,"tag":77,"props":2510,"children":2511},{},[2512],{"type":46,"tag":81,"props":2513,"children":2514},{},[2515,2520,2525,2530],{"type":46,"tag":85,"props":2516,"children":2517},{},[2518],{"type":52,"value":2519},"Callback",{"type":46,"tag":85,"props":2521,"children":2522},{},[2523],{"type":52,"value":2524},"Target Budget",{"type":46,"tag":85,"props":2526,"children":2527},{},[2528],{"type":52,"value":2529},"Hard Ceiling",{"type":46,"tag":85,"props":2531,"children":2532},{},[2533],{"type":52,"value":2534},"Notes",{"type":46,"tag":101,"props":2536,"children":2537},{},[2538,2564,2590,2615,2639,2663,2687],{"type":46,"tag":81,"props":2539,"children":2540},{},[2541,2549,2554,2559],{"type":46,"tag":108,"props":2542,"children":2543},{},[2544],{"type":46,"tag":123,"props":2545,"children":2547},{"className":2546},[],[2548],{"type":52,"value":459},{"type":46,"tag":108,"props":2550,"children":2551},{},[2552],{"type":52,"value":2553},"\u003C 50,000 gas",{"type":46,"tag":108,"props":2555,"children":2556},{},[2557],{"type":52,"value":2558},"150,000 gas",{"type":46,"tag":108,"props":2560,"children":2561},{},[2562],{"type":52,"value":2563},"Runs on every swap; keep lean",{"type":46,"tag":81,"props":2565,"children":2566},{},[2567,2575,2580,2585],{"type":46,"tag":108,"props":2568,"children":2569},{},[2570],{"type":46,"tag":123,"props":2571,"children":2573},{"className":2572},[],[2574],{"type":52,"value":485},{"type":46,"tag":108,"props":2576,"children":2577},{},[2578],{"type":52,"value":2579},"\u003C 30,000 gas",{"type":46,"tag":108,"props":2581,"children":2582},{},[2583],{"type":52,"value":2584},"100,000 gas",{"type":46,"tag":108,"props":2586,"children":2587},{},[2588],{"type":52,"value":2589},"Analytics\u002Ftracking only",{"type":46,"tag":81,"props":2591,"children":2592},{},[2593,2601,2605,2610],{"type":46,"tag":108,"props":2594,"children":2595},{},[2596],{"type":46,"tag":123,"props":2597,"children":2599},{"className":2598},[],[2600],{"type":52,"value":353},{"type":46,"tag":108,"props":2602,"children":2603},{},[2604],{"type":52,"value":2553},{"type":46,"tag":108,"props":2606,"children":2607},{},[2608],{"type":52,"value":2609},"200,000 gas",{"type":46,"tag":108,"props":2611,"children":2612},{},[2613],{"type":52,"value":2614},"May include access control",{"type":46,"tag":81,"props":2616,"children":2617},{},[2618,2626,2630,2634],{"type":46,"tag":108,"props":2619,"children":2620},{},[2621],{"type":46,"tag":123,"props":2622,"children":2624},{"className":2623},[],[2625],{"type":52,"value":380},{"type":46,"tag":108,"props":2627,"children":2628},{},[2629],{"type":52,"value":2579},{"type":46,"tag":108,"props":2631,"children":2632},{},[2633],{"type":52,"value":2584},{"type":46,"tag":108,"props":2635,"children":2636},{},[2637],{"type":52,"value":2638},"Reward tracking",{"type":46,"tag":81,"props":2640,"children":2641},{},[2642,2650,2654,2658],{"type":46,"tag":108,"props":2643,"children":2644},{},[2645],{"type":46,"tag":123,"props":2646,"children":2648},{"className":2647},[],[2649],{"type":52,"value":406},{"type":46,"tag":108,"props":2651,"children":2652},{},[2653],{"type":52,"value":2553},{"type":46,"tag":108,"props":2655,"children":2656},{},[2657],{"type":52,"value":2609},{"type":46,"tag":108,"props":2659,"children":2660},{},[2661],{"type":52,"value":2662},"Lock validation",{"type":46,"tag":81,"props":2664,"children":2665},{},[2666,2674,2678,2682],{"type":46,"tag":108,"props":2667,"children":2668},{},[2669],{"type":46,"tag":123,"props":2670,"children":2672},{"className":2671},[],[2673],{"type":52,"value":433},{"type":46,"tag":108,"props":2675,"children":2676},{},[2677],{"type":52,"value":2579},{"type":46,"tag":108,"props":2679,"children":2680},{},[2681],{"type":52,"value":2584},{"type":46,"tag":108,"props":2683,"children":2684},{},[2685],{"type":52,"value":2686},"Tracking\u002Faccounting",{"type":46,"tag":81,"props":2688,"children":2689},{},[2690,2695,2700,2705],{"type":46,"tag":108,"props":2691,"children":2692},{},[2693],{"type":52,"value":2694},"Callbacks with external calls",{"type":46,"tag":108,"props":2696,"children":2697},{},[2698],{"type":52,"value":2699},"\u003C 100,000 gas",{"type":46,"tag":108,"props":2701,"children":2702},{},[2703],{"type":52,"value":2704},"300,000 gas",{"type":46,"tag":108,"props":2706,"children":2707},{},[2708],{"type":52,"value":2709},"External DEX routing, oracles",{"type":46,"tag":660,"props":2711,"children":2713},{"id":2712},"common-gas-pitfalls",[2714],{"type":52,"value":2715},"Common Gas Pitfalls",{"type":46,"tag":726,"props":2717,"children":2718},{},[2719,2729,2763,2773,2799],{"type":46,"tag":671,"props":2720,"children":2721},{},[2722,2727],{"type":46,"tag":112,"props":2723,"children":2724},{},[2725],{"type":52,"value":2726},"Unbounded loops",{"type":52,"value":2728},": Iterating over dynamic arrays (e.g., all active positions) can exceed block gas limits. Cap array sizes or use pagination.",{"type":46,"tag":671,"props":2730,"children":2731},{},[2732,2737,2739,2745,2747,2753,2755,2761],{"type":46,"tag":112,"props":2733,"children":2734},{},[2735],{"type":52,"value":2736},"SSTORE in hot paths",{"type":52,"value":2738},": Each new storage slot costs ~20,000 gas. Prefer transient storage (",{"type":46,"tag":123,"props":2740,"children":2742},{"className":2741},[],[2743],{"type":52,"value":2744},"tstore",{"type":52,"value":2746},"\u002F",{"type":46,"tag":123,"props":2748,"children":2750},{"className":2749},[],[2751],{"type":52,"value":2752},"tload",{"type":52,"value":2754},") for data that doesn't persist beyond the transaction. Requires Solidity >= 0.8.24 with EVM target set to ",{"type":46,"tag":123,"props":2756,"children":2758},{"className":2757},[],[2759],{"type":52,"value":2760},"cancun",{"type":52,"value":2762}," or later.",{"type":46,"tag":671,"props":2764,"children":2765},{},[2766,2771],{"type":46,"tag":112,"props":2767,"children":2768},{},[2769],{"type":52,"value":2770},"External calls",{"type":52,"value":2772},": Each cross-contract call adds ~2,600 gas base cost plus the callee's execution. Batch calls where possible.",{"type":46,"tag":671,"props":2774,"children":2775},{},[2776,2781,2783,2789,2791,2797],{"type":46,"tag":112,"props":2777,"children":2778},{},[2779],{"type":52,"value":2780},"String operations",{"type":52,"value":2782},": Avoid ",{"type":46,"tag":123,"props":2784,"children":2786},{"className":2785},[],[2787],{"type":52,"value":2788},"string",{"type":52,"value":2790}," manipulation in callbacks; use ",{"type":46,"tag":123,"props":2792,"children":2794},{"className":2793},[],[2795],{"type":52,"value":2796},"bytes32",{"type":52,"value":2798}," for identifiers.",{"type":46,"tag":671,"props":2800,"children":2801},{},[2802,2807,2809,2815,2817,2823,2825,2831],{"type":46,"tag":112,"props":2803,"children":2804},{},[2805],{"type":52,"value":2806},"Redundant reads",{"type":52,"value":2808},": Cache ",{"type":46,"tag":123,"props":2810,"children":2812},{"className":2811},[],[2813],{"type":52,"value":2814},"poolManager",{"type":52,"value":2816}," calls — repeated ",{"type":46,"tag":123,"props":2818,"children":2820},{"className":2819},[],[2821],{"type":52,"value":2822},"getSlot0()",{"type":52,"value":2824}," or ",{"type":46,"tag":123,"props":2826,"children":2828},{"className":2827},[],[2829],{"type":52,"value":2830},"getLiquidity()",{"type":52,"value":2832}," reads cost gas each time.",{"type":46,"tag":660,"props":2834,"children":2836},{"id":2835},"measuring-gas",[2837],{"type":52,"value":2838},"Measuring Gas",{"type":46,"tag":756,"props":2840,"children":2844},{"className":2841,"code":2842,"language":2843,"meta":761,"style":761},"language-bash shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","# Profile a specific hook callback with Foundry\nforge test --match-test test_beforeSwapGas --gas-report\n\n# Snapshot gas usage across all tests\nforge snapshot --match-contract MyHookTest\n","bash",[2845],{"type":46,"tag":123,"props":2846,"children":2847},{"__ignoreMap":761},[2848,2857,2887,2894,2902],{"type":46,"tag":767,"props":2849,"children":2850},{"class":769,"line":770},[2851],{"type":46,"tag":767,"props":2852,"children":2854},{"style":2853},"--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic",[2855],{"type":52,"value":2856},"# Profile a specific hook callback with Foundry\n",{"type":46,"tag":767,"props":2858,"children":2859},{"class":769,"line":779},[2860,2866,2872,2877,2882],{"type":46,"tag":767,"props":2861,"children":2863},{"style":2862},"--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B",[2864],{"type":52,"value":2865},"forge",{"type":46,"tag":767,"props":2867,"children":2869},{"style":2868},"--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D",[2870],{"type":52,"value":2871}," test",{"type":46,"tag":767,"props":2873,"children":2874},{"style":2868},[2875],{"type":52,"value":2876}," --match-test",{"type":46,"tag":767,"props":2878,"children":2879},{"style":2868},[2880],{"type":52,"value":2881}," test_beforeSwapGas",{"type":46,"tag":767,"props":2883,"children":2884},{"style":2868},[2885],{"type":52,"value":2886}," --gas-report\n",{"type":46,"tag":767,"props":2888,"children":2889},{"class":769,"line":788},[2890],{"type":46,"tag":767,"props":2891,"children":2892},{"emptyLinePlaceholder":1262},[2893],{"type":52,"value":1265},{"type":46,"tag":767,"props":2895,"children":2896},{"class":769,"line":797},[2897],{"type":46,"tag":767,"props":2898,"children":2899},{"style":2853},[2900],{"type":52,"value":2901},"# Snapshot gas usage across all tests\n",{"type":46,"tag":767,"props":2903,"children":2904},{"class":769,"line":806},[2905,2909,2914,2919],{"type":46,"tag":767,"props":2906,"children":2907},{"style":2862},[2908],{"type":52,"value":2865},{"type":46,"tag":767,"props":2910,"children":2911},{"style":2868},[2912],{"type":52,"value":2913}," snapshot",{"type":46,"tag":767,"props":2915,"children":2916},{"style":2868},[2917],{"type":52,"value":2918}," --match-contract",{"type":46,"tag":767,"props":2920,"children":2921},{"style":2868},[2922],{"type":52,"value":2923}," MyHookTest\n",{"type":46,"tag":2925,"props":2926,"children":2927},"hr",{},[],{"type":46,"tag":61,"props":2929,"children":2931},{"id":2930},"risk-scoring-system",[2932],{"type":52,"value":2933},"Risk Scoring System",{"type":46,"tag":55,"props":2935,"children":2936},{},[2937],{"type":52,"value":2938},"Calculate your hook's risk score (0-33):",{"type":46,"tag":73,"props":2940,"children":2941},{},[2942,2963],{"type":46,"tag":77,"props":2943,"children":2944},{},[2945],{"type":46,"tag":81,"props":2946,"children":2947},{},[2948,2953,2958],{"type":46,"tag":85,"props":2949,"children":2950},{},[2951],{"type":52,"value":2952},"Category",{"type":46,"tag":85,"props":2954,"children":2955},{},[2956],{"type":52,"value":2957},"Points",{"type":46,"tag":85,"props":2959,"children":2960},{},[2961],{"type":52,"value":2962},"Criteria",{"type":46,"tag":101,"props":2964,"children":2965},{},[2966,2987,3008,3028,3048],{"type":46,"tag":81,"props":2967,"children":2968},{},[2969,2977,2982],{"type":46,"tag":108,"props":2970,"children":2971},{},[2972],{"type":46,"tag":112,"props":2973,"children":2974},{},[2975],{"type":52,"value":2976},"Permissions",{"type":46,"tag":108,"props":2978,"children":2979},{},[2980],{"type":52,"value":2981},"0-14",{"type":46,"tag":108,"props":2983,"children":2984},{},[2985],{"type":52,"value":2986},"Sum of enabled permission risk levels",{"type":46,"tag":81,"props":2988,"children":2989},{},[2990,2998,3003],{"type":46,"tag":108,"props":2991,"children":2992},{},[2993],{"type":46,"tag":112,"props":2994,"children":2995},{},[2996],{"type":52,"value":2997},"External Calls",{"type":46,"tag":108,"props":2999,"children":3000},{},[3001],{"type":52,"value":3002},"0-5",{"type":46,"tag":108,"props":3004,"children":3005},{},[3006],{"type":52,"value":3007},"Number and type of external interactions",{"type":46,"tag":81,"props":3009,"children":3010},{},[3011,3019,3023],{"type":46,"tag":108,"props":3012,"children":3013},{},[3014],{"type":46,"tag":112,"props":3015,"children":3016},{},[3017],{"type":52,"value":3018},"State Complexity",{"type":46,"tag":108,"props":3020,"children":3021},{},[3022],{"type":52,"value":3002},{"type":46,"tag":108,"props":3024,"children":3025},{},[3026],{"type":52,"value":3027},"Amount of mutable state",{"type":46,"tag":81,"props":3029,"children":3030},{},[3031,3039,3043],{"type":46,"tag":108,"props":3032,"children":3033},{},[3034],{"type":46,"tag":112,"props":3035,"children":3036},{},[3037],{"type":52,"value":3038},"Upgrade Mechanism",{"type":46,"tag":108,"props":3040,"children":3041},{},[3042],{"type":52,"value":3002},{"type":46,"tag":108,"props":3044,"children":3045},{},[3046],{"type":52,"value":3047},"Proxy, admin functions, etc.",{"type":46,"tag":81,"props":3049,"children":3050},{},[3051,3059,3064],{"type":46,"tag":108,"props":3052,"children":3053},{},[3054],{"type":46,"tag":112,"props":3055,"children":3056},{},[3057],{"type":52,"value":3058},"Token Handling",{"type":46,"tag":108,"props":3060,"children":3061},{},[3062],{"type":52,"value":3063},"0-4",{"type":46,"tag":108,"props":3065,"children":3066},{},[3067],{"type":52,"value":3068},"Non-standard token support",{"type":46,"tag":660,"props":3070,"children":3072},{"id":3071},"audit-tier-recommendations",[3073],{"type":52,"value":3074},"Audit Tier Recommendations",{"type":46,"tag":73,"props":3076,"children":3077},{},[3078,3098],{"type":46,"tag":77,"props":3079,"children":3080},{},[3081],{"type":46,"tag":81,"props":3082,"children":3083},{},[3084,3089,3093],{"type":46,"tag":85,"props":3085,"children":3086},{},[3087],{"type":52,"value":3088},"Score",{"type":46,"tag":85,"props":3090,"children":3091},{},[3092],{"type":52,"value":276},{"type":46,"tag":85,"props":3094,"children":3095},{},[3096],{"type":52,"value":3097},"Recommendation",{"type":46,"tag":101,"props":3099,"children":3100},{},[3101,3118,3136,3154],{"type":46,"tag":81,"props":3102,"children":3103},{},[3104,3108,3113],{"type":46,"tag":108,"props":3105,"children":3106},{},[3107],{"type":52,"value":3002},{"type":46,"tag":108,"props":3109,"children":3110},{},[3111],{"type":52,"value":3112},"Low",{"type":46,"tag":108,"props":3114,"children":3115},{},[3116],{"type":52,"value":3117},"Self-audit + peer review",{"type":46,"tag":81,"props":3119,"children":3120},{},[3121,3126,3131],{"type":46,"tag":108,"props":3122,"children":3123},{},[3124],{"type":52,"value":3125},"6-12",{"type":46,"tag":108,"props":3127,"children":3128},{},[3129],{"type":52,"value":3130},"Medium",{"type":46,"tag":108,"props":3132,"children":3133},{},[3134],{"type":52,"value":3135},"Professional audit recommended",{"type":46,"tag":81,"props":3137,"children":3138},{},[3139,3144,3149],{"type":46,"tag":108,"props":3140,"children":3141},{},[3142],{"type":52,"value":3143},"13-20",{"type":46,"tag":108,"props":3145,"children":3146},{},[3147],{"type":52,"value":3148},"High",{"type":46,"tag":108,"props":3150,"children":3151},{},[3152],{"type":52,"value":3153},"Professional audit required",{"type":46,"tag":81,"props":3155,"children":3156},{},[3157,3162,3167],{"type":46,"tag":108,"props":3158,"children":3159},{},[3160],{"type":52,"value":3161},"21-33",{"type":46,"tag":108,"props":3163,"children":3164},{},[3165],{"type":52,"value":3166},"Critical",{"type":46,"tag":108,"props":3168,"children":3169},{},[3170],{"type":52,"value":3171},"Multiple audits required",{"type":46,"tag":61,"props":3173,"children":3175},{"id":3174},"absolute-prohibitions",[3176],{"type":52,"value":3177},"Absolute Prohibitions",{"type":46,"tag":55,"props":3179,"children":3180},{},[3181],{"type":46,"tag":112,"props":3182,"children":3183},{},[3184],{"type":52,"value":3185},"Never do these things in a hook:",{"type":46,"tag":726,"props":3187,"children":3188},{},[3189,3206,3221,3229,3253,3263,3278,3286,3294],{"type":46,"tag":671,"props":3190,"children":3191},{},[3192,3204],{"type":46,"tag":112,"props":3193,"children":3194},{},[3195,3197,3202],{"type":52,"value":3196},"Never trust ",{"type":46,"tag":123,"props":3198,"children":3200},{"className":3199},[],[3201],{"type":52,"value":161},{"type":52,"value":3203}," for user identity",{"type":52,"value":3205}," - It's always PoolManager",{"type":46,"tag":671,"props":3207,"children":3208},{},[3209],{"type":46,"tag":112,"props":3210,"children":3211},{},[3212,3214,3219],{"type":52,"value":3213},"Never enable ",{"type":46,"tag":123,"props":3215,"children":3217},{"className":3216},[],[3218],{"type":52,"value":562},{"type":52,"value":3220}," without understanding NoOp attacks",{"type":46,"tag":671,"props":3222,"children":3223},{},[3224],{"type":46,"tag":112,"props":3225,"children":3226},{},[3227],{"type":52,"value":3228},"Never store passwords, keys, or PII on-chain",{"type":46,"tag":671,"props":3230,"children":3231},{},[3232,3245,3247],{"type":46,"tag":112,"props":3233,"children":3234},{},[3235,3237,3243],{"type":52,"value":3236},"Never use ",{"type":46,"tag":123,"props":3238,"children":3240},{"className":3239},[],[3241],{"type":52,"value":3242},"transfer()",{"type":52,"value":3244}," for ETH",{"type":52,"value":3246}," - Use ",{"type":46,"tag":123,"props":3248,"children":3250},{"className":3249},[],[3251],{"type":52,"value":3252},"call{value:}(\"\")",{"type":46,"tag":671,"props":3254,"children":3255},{},[3256,3261],{"type":46,"tag":112,"props":3257,"children":3258},{},[3259],{"type":52,"value":3260},"Never assume token decimals",{"type":52,"value":3262}," - Always query the token",{"type":46,"tag":671,"props":3264,"children":3265},{},[3266],{"type":46,"tag":112,"props":3267,"children":3268},{},[3269,3270,3276],{"type":52,"value":3236},{"type":46,"tag":123,"props":3271,"children":3273},{"className":3272},[],[3274],{"type":52,"value":3275},"block.timestamp",{"type":52,"value":3277}," for randomness",{"type":46,"tag":671,"props":3279,"children":3280},{},[3281],{"type":46,"tag":112,"props":3282,"children":3283},{},[3284],{"type":52,"value":3285},"Never hardcode gas limits in calls",{"type":46,"tag":671,"props":3287,"children":3288},{},[3289],{"type":46,"tag":112,"props":3290,"children":3291},{},[3292],{"type":52,"value":3293},"Never ignore return values from external calls",{"type":46,"tag":671,"props":3295,"children":3296},{},[3297,3309,3311],{"type":46,"tag":112,"props":3298,"children":3299},{},[3300,3301,3307],{"type":52,"value":3236},{"type":46,"tag":123,"props":3302,"children":3304},{"className":3303},[],[3305],{"type":52,"value":3306},"tx.origin",{"type":52,"value":3308}," for authorization",{"type":52,"value":3310}," - It's a phishing vector; malicious contracts can relay calls with the original user's ",{"type":46,"tag":123,"props":3312,"children":3314},{"className":3313},[],[3315],{"type":52,"value":3306},{"type":46,"tag":61,"props":3317,"children":3319},{"id":3318},"pre-deployment-audit-checklist",[3320],{"type":52,"value":3321},"Pre-Deployment Audit Checklist",{"type":46,"tag":73,"props":3323,"children":3324},{},[3325,3345],{"type":46,"tag":77,"props":3326,"children":3327},{},[3328],{"type":46,"tag":81,"props":3329,"children":3330},{},[3331,3335,3340],{"type":46,"tag":85,"props":3332,"children":3333},{},[3334],{"type":52,"value":2217},{"type":46,"tag":85,"props":3336,"children":3337},{},[3338],{"type":52,"value":3339},"Item",{"type":46,"tag":85,"props":3341,"children":3342},{},[3343],{"type":52,"value":3344},"Required For",{"type":46,"tag":101,"props":3346,"children":3347},{},[3348,3365,3381,3397,3414,3430,3446,3463,3479,3496,3513],{"type":46,"tag":81,"props":3349,"children":3350},{},[3351,3355,3360],{"type":46,"tag":108,"props":3352,"children":3353},{},[3354],{"type":52,"value":2238},{"type":46,"tag":108,"props":3356,"children":3357},{},[3358],{"type":52,"value":3359},"Code review by security-focused developer",{"type":46,"tag":108,"props":3361,"children":3362},{},[3363],{"type":52,"value":3364},"All hooks",{"type":46,"tag":81,"props":3366,"children":3367},{},[3368,3372,3377],{"type":46,"tag":108,"props":3369,"children":3370},{},[3371],{"type":52,"value":2263},{"type":46,"tag":108,"props":3373,"children":3374},{},[3375],{"type":52,"value":3376},"Unit tests for all callbacks",{"type":46,"tag":108,"props":3378,"children":3379},{},[3380],{"type":52,"value":3364},{"type":46,"tag":81,"props":3382,"children":3383},{},[3384,3388,3393],{"type":46,"tag":108,"props":3385,"children":3386},{},[3387],{"type":52,"value":2282},{"type":46,"tag":108,"props":3389,"children":3390},{},[3391],{"type":52,"value":3392},"Fuzz testing with Foundry",{"type":46,"tag":108,"props":3394,"children":3395},{},[3396],{"type":52,"value":3364},{"type":46,"tag":81,"props":3398,"children":3399},{},[3400,3404,3409],{"type":46,"tag":108,"props":3401,"children":3402},{},[3403],{"type":52,"value":2301},{"type":46,"tag":108,"props":3405,"children":3406},{},[3407],{"type":52,"value":3408},"Invariant testing",{"type":46,"tag":108,"props":3410,"children":3411},{},[3412],{"type":52,"value":3413},"Hooks with delta returns",{"type":46,"tag":81,"props":3415,"children":3416},{},[3417,3421,3426],{"type":46,"tag":108,"props":3418,"children":3419},{},[3420],{"type":52,"value":2320},{"type":46,"tag":108,"props":3422,"children":3423},{},[3424],{"type":52,"value":3425},"Fork testing on mainnet",{"type":46,"tag":108,"props":3427,"children":3428},{},[3429],{"type":52,"value":3364},{"type":46,"tag":81,"props":3431,"children":3432},{},[3433,3437,3442],{"type":46,"tag":108,"props":3434,"children":3435},{},[3436],{"type":52,"value":2339},{"type":46,"tag":108,"props":3438,"children":3439},{},[3440],{"type":52,"value":3441},"Gas profiling",{"type":46,"tag":108,"props":3443,"children":3444},{},[3445],{"type":52,"value":3364},{"type":46,"tag":81,"props":3447,"children":3448},{},[3449,3453,3458],{"type":46,"tag":108,"props":3450,"children":3451},{},[3452],{"type":52,"value":2358},{"type":46,"tag":108,"props":3454,"children":3455},{},[3456],{"type":52,"value":3457},"Formal verification",{"type":46,"tag":108,"props":3459,"children":3460},{},[3461],{"type":52,"value":3462},"Critical hooks",{"type":46,"tag":81,"props":3464,"children":3465},{},[3466,3470,3475],{"type":46,"tag":108,"props":3467,"children":3468},{},[3469],{"type":52,"value":2377},{"type":46,"tag":108,"props":3471,"children":3472},{},[3473],{"type":52,"value":3474},"Slither\u002FMythril analysis",{"type":46,"tag":108,"props":3476,"children":3477},{},[3478],{"type":52,"value":3364},{"type":46,"tag":81,"props":3480,"children":3481},{},[3482,3486,3491],{"type":46,"tag":108,"props":3483,"children":3484},{},[3485],{"type":52,"value":2396},{"type":46,"tag":108,"props":3487,"children":3488},{},[3489],{"type":52,"value":3490},"External audit",{"type":46,"tag":108,"props":3492,"children":3493},{},[3494],{"type":52,"value":3495},"Medium+ risk hooks",{"type":46,"tag":81,"props":3497,"children":3498},{},[3499,3503,3508],{"type":46,"tag":108,"props":3500,"children":3501},{},[3502],{"type":52,"value":2415},{"type":46,"tag":108,"props":3504,"children":3505},{},[3506],{"type":52,"value":3507},"Bug bounty program",{"type":46,"tag":108,"props":3509,"children":3510},{},[3511],{"type":52,"value":3512},"High+ risk hooks",{"type":46,"tag":81,"props":3514,"children":3515},{},[3516,3520,3525],{"type":46,"tag":108,"props":3517,"children":3518},{},[3519],{"type":52,"value":2434},{"type":46,"tag":108,"props":3521,"children":3522},{},[3523],{"type":52,"value":3524},"Monitoring\u002Falerting setup",{"type":46,"tag":108,"props":3526,"children":3527},{},[3528],{"type":52,"value":3529},"All production hooks",{"type":46,"tag":55,"props":3531,"children":3532},{},[3533,3534,3539],{"type":52,"value":2184},{"type":46,"tag":2186,"props":3535,"children":3537},{"href":3536},"references\u002Faudit-checklist.md",[3538],{"type":52,"value":3536},{"type":52,"value":3540}," for detailed audit requirements.",{"type":46,"tag":61,"props":3542,"children":3544},{"id":3543},"production-hook-references",[3545],{"type":52,"value":3546},"Production Hook References",{"type":46,"tag":55,"props":3548,"children":3549},{},[3550],{"type":52,"value":3551},"Learn from audited, production hooks:",{"type":46,"tag":73,"props":3553,"children":3554},{},[3555,3575],{"type":46,"tag":77,"props":3556,"children":3557},{},[3558],{"type":46,"tag":81,"props":3559,"children":3560},{},[3561,3566,3570],{"type":46,"tag":85,"props":3562,"children":3563},{},[3564],{"type":52,"value":3565},"Project",{"type":46,"tag":85,"props":3567,"children":3568},{},[3569],{"type":52,"value":94},{"type":46,"tag":85,"props":3571,"children":3572},{},[3573],{"type":52,"value":3574},"Notable Security Features",{"type":46,"tag":101,"props":3576,"children":3577},{},[3578,3599,3620,3641],{"type":46,"tag":81,"props":3579,"children":3580},{},[3581,3589,3594],{"type":46,"tag":108,"props":3582,"children":3583},{},[3584],{"type":46,"tag":112,"props":3585,"children":3586},{},[3587],{"type":52,"value":3588},"Flaunch",{"type":46,"tag":108,"props":3590,"children":3591},{},[3592],{"type":52,"value":3593},"Token launch platform",{"type":46,"tag":108,"props":3595,"children":3596},{},[3597],{"type":52,"value":3598},"Multi-sig admin, timelocks",{"type":46,"tag":81,"props":3600,"children":3601},{},[3602,3610,3615],{"type":46,"tag":108,"props":3603,"children":3604},{},[3605],{"type":46,"tag":112,"props":3606,"children":3607},{},[3608],{"type":52,"value":3609},"EulerSwap",{"type":46,"tag":108,"props":3611,"children":3612},{},[3613],{"type":52,"value":3614},"Lending integration",{"type":46,"tag":108,"props":3616,"children":3617},{},[3618],{"type":52,"value":3619},"Isolated risk per market",{"type":46,"tag":81,"props":3621,"children":3622},{},[3623,3631,3636],{"type":46,"tag":108,"props":3624,"children":3625},{},[3626],{"type":46,"tag":112,"props":3627,"children":3628},{},[3629],{"type":52,"value":3630},"Zaha TWAMM",{"type":46,"tag":108,"props":3632,"children":3633},{},[3634],{"type":52,"value":3635},"Time-weighted AMM",{"type":46,"tag":108,"props":3637,"children":3638},{},[3639],{"type":52,"value":3640},"Gradual execution reduces MEV",{"type":46,"tag":81,"props":3642,"children":3643},{},[3644,3652,3657],{"type":46,"tag":108,"props":3645,"children":3646},{},[3647],{"type":46,"tag":112,"props":3648,"children":3649},{},[3650],{"type":52,"value":3651},"Bunni",{"type":46,"tag":108,"props":3653,"children":3654},{},[3655],{"type":52,"value":3656},"LP management",{"type":46,"tag":108,"props":3658,"children":3659},{},[3660],{"type":52,"value":3661},"Concentrated liquidity guards",{"type":46,"tag":61,"props":3663,"children":3665},{"id":3664},"external-resources",[3666],{"type":52,"value":3667},"External Resources",{"type":46,"tag":660,"props":3669,"children":3671},{"id":3670},"official-documentation",[3672],{"type":52,"value":3673},"Official Documentation",{"type":46,"tag":667,"props":3675,"children":3676},{},[3677,3688,3698,3708],{"type":46,"tag":671,"props":3678,"children":3679},{},[3680],{"type":46,"tag":2186,"props":3681,"children":3685},{"href":3682,"rel":3683},"https:\u002F\u002Fgithub.com\u002FUniswap\u002Fv4-core",[3684],"nofollow",[3686],{"type":52,"value":3687},"v4-core Repository",{"type":46,"tag":671,"props":3689,"children":3690},{},[3691],{"type":46,"tag":2186,"props":3692,"children":3695},{"href":3693,"rel":3694},"https:\u002F\u002Fgithub.com\u002FUniswap\u002Fv4-periphery",[3684],[3696],{"type":52,"value":3697},"v4-periphery Repository",{"type":46,"tag":671,"props":3699,"children":3700},{},[3701],{"type":46,"tag":2186,"props":3702,"children":3705},{"href":3703,"rel":3704},"https:\u002F\u002Fdocs.uniswap.org\u002Fcontracts\u002Fv4\u002Foverview",[3684],[3706],{"type":52,"value":3707},"Uniswap v4 Docs",{"type":46,"tag":671,"props":3709,"children":3710},{},[3711],{"type":46,"tag":2186,"props":3712,"children":3715},{"href":3713,"rel":3714},"https:\u002F\u002Fdocs.uniswap.org\u002Fcontracts\u002Fv4\u002Fconcepts\u002Fhooks",[3684],[3716],{"type":52,"value":3717},"Hook Permissions Guide",{"type":46,"tag":660,"props":3719,"children":3721},{"id":3720},"security-resources",[3722],{"type":52,"value":3723},"Security Resources",{"type":46,"tag":667,"props":3725,"children":3726},{},[3727,3737,3747],{"type":46,"tag":671,"props":3728,"children":3729},{},[3730],{"type":46,"tag":2186,"props":3731,"children":3734},{"href":3732,"rel":3733},"https:\u002F\u002Fgithub.com\u002Ftrailofbits\u002Fpublications",[3684],[3735],{"type":52,"value":3736},"Trail of Bits Audits",{"type":46,"tag":671,"props":3738,"children":3739},{},[3740],{"type":46,"tag":2186,"props":3741,"children":3744},{"href":3742,"rel":3743},"https:\u002F\u002Fwww.certora.com\u002F",[3684],[3745],{"type":52,"value":3746},"Certora v4 Analysis",{"type":46,"tag":671,"props":3748,"children":3749},{},[3750],{"type":46,"tag":2186,"props":3751,"children":3754},{"href":3752,"rel":3753},"https:\u002F\u002Fabdk.consulting\u002F",[3684],[3755],{"type":52,"value":3756},"ABDK Consulting",{"type":46,"tag":660,"props":3758,"children":3760},{"id":3759},"community",[3761],{"type":52,"value":3762},"Community",{"type":46,"tag":667,"props":3764,"children":3765},{},[3766,3778],{"type":46,"tag":671,"props":3767,"children":3768},{},[3769,3776],{"type":46,"tag":2186,"props":3770,"children":3773},{"href":3771,"rel":3772},"https:\u002F\u002Fgithub.com\u002Figoryuzo\u002FuniswapV4-hooks-skill",[3684],[3774],{"type":52,"value":3775},"v4-hooks-skill by @igoryuzo",{"type":52,"value":3777}," - Community skill that inspired this guide",{"type":46,"tag":671,"props":3779,"children":3780},{},[3781,3788],{"type":46,"tag":2186,"props":3782,"children":3785},{"href":3783,"rel":3784},"https:\u002F\u002Fwww.v4hooks.dev",[3684],[3786],{"type":52,"value":3787},"v4hooks.dev",{"type":52,"value":3789}," - Community hook resources",{"type":46,"tag":2925,"props":3791,"children":3792},{},[],{"type":46,"tag":61,"props":3794,"children":3796},{"id":3795},"additional-references",[3797],{"type":52,"value":3798},"Additional References",{"type":46,"tag":667,"props":3800,"children":3801},{},[3802,3811,3822],{"type":46,"tag":671,"props":3803,"children":3804},{},[3805,3809],{"type":46,"tag":2186,"props":3806,"children":3807},{"href":2188},[3808],{"type":52,"value":1888},{"type":52,"value":3810}," - Complete implementation starter",{"type":46,"tag":671,"props":3812,"children":3813},{},[3814,3820],{"type":46,"tag":2186,"props":3815,"children":3817},{"href":3816},"references\u002Fvulnerabilities-catalog.md",[3818],{"type":52,"value":3819},"Vulnerabilities Catalog",{"type":52,"value":3821}," - Common patterns and mitigations",{"type":46,"tag":671,"props":3823,"children":3824},{},[3825,3830],{"type":46,"tag":2186,"props":3826,"children":3827},{"href":3536},[3828],{"type":52,"value":3829},"Audit Checklist",{"type":52,"value":3831}," - Detailed pre-deployment checklist",{"type":46,"tag":3833,"props":3834,"children":3835},"style",{},[3836],{"type":52,"value":3837},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"items":3839,"total":2013},[3840,3853,3868,3881,3894,3907,3920],{"slug":3841,"name":3841,"fn":3842,"description":3843,"org":3844,"tags":3845,"stars":25,"repoUrl":26,"updatedAt":3852},"configurator","configure auction smart contract parameters","Configure CCA (Continuous Clearing Auction) smart contract parameters through an interactive bulk form flow. Use when user says \"configure auction\", \"cca auction\", \"setup token auction\", \"auction configuration\", \"continuous auction\", or mentions CCA contracts.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[3846,3849,3850,3851],{"name":3847,"slug":3848,"type":15},"Configuration","configuration",{"name":23,"slug":24,"type":15},{"name":20,"slug":21,"type":15},{"name":17,"slug":18,"type":15},"2026-07-17T06:08:08.974641",{"slug":3854,"name":3854,"fn":3855,"description":3856,"org":3857,"tags":3858,"stars":25,"repoUrl":26,"updatedAt":3867},"copy-trade","copy trades from crypto wallets","This skill should be used when the user asks to \"copy trades from\" a wallet, \"mirror a wallet\", \"follow this address\", set up \"copy trading\", \"track and replicate a trader\", or mirror another account's swaps bounded by guardrails. Watches a target wallet and mirrors its trades, filtered by chain, asset match, position size, and the follower's own portfolio state.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[3859,3862,3863,3866],{"name":3860,"slug":3861,"type":15},"Automation","automation",{"name":23,"slug":24,"type":15},{"name":3864,"slug":3865,"type":15},"Trading","trading",{"name":17,"slug":18,"type":15},"2026-07-17T06:04:21.974052",{"slug":3869,"name":3869,"fn":3870,"description":3871,"org":3872,"tags":3873,"stars":25,"repoUrl":26,"updatedAt":3880},"dca-bot","automate dollar cost average token purchases","This skill should be used when the user wants to \"dca into\" a token, \"buy X every day\", set up a \"recurring buy\", \"dollar cost average\" into an asset, \"schedule a buy\", or \"auto-buy on a dip\". Buys a fixed amount into a token on a schedule, optionally only when a condition holds (for example only when ETH is below a price threshold). The host agent's scheduler wakes the skill on a cadence; each wake is one self-contained run.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[3874,3875,3878,3879],{"name":3860,"slug":3861,"type":15},{"name":3876,"slug":3877,"type":15},"DeFi","defi",{"name":3864,"slug":3865,"type":15},{"name":17,"slug":18,"type":15},"2026-07-17T06:05:37.160647",{"slug":3882,"name":3882,"fn":3883,"description":3884,"org":3885,"tags":3886,"stars":25,"repoUrl":26,"updatedAt":3893},"deployer","deploy Uniswap CCA smart contracts","Deploy CCA (Continuous Clearing Auction) smart contracts using the Factory pattern. Use when user says \"deploy auction\", \"deploy cca\", \"factory deployment\", or wants to deploy a configured auction.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[3887,3890,3891,3892],{"name":3888,"slug":3889,"type":15},"Deployment","deployment",{"name":23,"slug":24,"type":15},{"name":20,"slug":21,"type":15},{"name":17,"slug":18,"type":15},"2026-07-17T06:08:09.661977",{"slug":3895,"name":3895,"fn":3896,"description":3897,"org":3898,"tags":3899,"stars":25,"repoUrl":26,"updatedAt":3906},"index-bot","create and rebalance asset portfolios","This skill should be used when the user asks to \"create an index\", \"build a basket of top assets\", \"buy a weighted basket\", \"make a portfolio of assets\", \"equal-weight basket\", \"rebalance my portfolio\", \"track the top N tokens\", or wants an automated, weighted multi-asset basket that buys in one pass and rebalances on a cadence. Builds the basket spec, delegates each buy and rebalance swap to the swap-integration Trading API flow, and records target weights in state.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[3900,3901,3904,3905],{"name":23,"slug":24,"type":15},{"name":3902,"slug":3903,"type":15},"Portfolio Management","portfolio-management",{"name":3864,"slug":3865,"type":15},{"name":17,"slug":18,"type":15},"2026-07-17T06:04:22.328253",{"slug":3908,"name":3908,"fn":3909,"description":3910,"org":3911,"tags":3912,"stars":25,"repoUrl":26,"updatedAt":3919},"liquidity-planner","plan and create liquidity positions","This skill should be used when the user asks to \"provide liquidity\", \"create LP position\", \"add liquidity to pool\", \"become a liquidity provider\", \"create v3 position\", \"create v4 position\", \"concentrated liquidity\", \"set price range\", or mentions providing liquidity, LP positions, or liquidity pools on Uniswap. Generates deep links to create positions in the Uniswap interface.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[3913,3914,3915,3918],{"name":3876,"slug":3877,"type":15},{"name":23,"slug":24,"type":15},{"name":3916,"slug":3917,"type":15},"Liquidity","liquidity",{"name":17,"slug":18,"type":15},"2026-07-17T06:08:09.315325",{"slug":3921,"name":3921,"fn":3922,"description":3923,"org":3924,"tags":3925,"stars":25,"repoUrl":26,"updatedAt":3932},"lp-integration","integrate Uniswap liquidity provisioning","Integrate Uniswap liquidity provisioning (LP) into applications via the LP REST API. Use when the user says \"LP API\", \"liquidity provisioning API\", \"provide liquidity programmatically\", \"create LP position via API\", \"add liquidity via API\", \"increase liquidity\", \"decrease liquidity\", \"remove liquidity\", \"claim LP fees\", \"collect LP fees\", \"manage LP positions in code\", or mentions building a backend, bot, or frontend that creates or manages Uniswap v2\u002Fv3\u002Fv4 liquidity positions through an API. Also use when debugging LP API calls (e.g. \u002Flp\u002Fcreate, \u002Flp\u002Fcheck_approval, \u002Flp\u002Fincrease, \u002Flp\u002Fdecrease, \u002Flp\u002Fclaim_fees), unexpected response fields, the approval or EIP-712 permit flow, or transaction-building errors for liquidity positions. For generating deep links to the Uniswap web app instead of calling the API, use the liquidity-planner skill; for using the Uniswap v4 SDK directly rather than the REST API, use the v4-sdk-integration skill.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[3926,3929,3930,3931],{"name":3927,"slug":3928,"type":15},"API Development","api-development",{"name":3876,"slug":3877,"type":15},{"name":3916,"slug":3917,"type":15},{"name":17,"slug":18,"type":15},"2026-07-17T06:08:13.704465",{"items":3934,"total":2049},[3935,3942,3949,3956,3963,3970,3977,3984,3998,4009,4020,4031],{"slug":3841,"name":3841,"fn":3842,"description":3843,"org":3936,"tags":3937,"stars":25,"repoUrl":26,"updatedAt":3852},{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[3938,3939,3940,3941],{"name":3847,"slug":3848,"type":15},{"name":23,"slug":24,"type":15},{"name":20,"slug":21,"type":15},{"name":17,"slug":18,"type":15},{"slug":3854,"name":3854,"fn":3855,"description":3856,"org":3943,"tags":3944,"stars":25,"repoUrl":26,"updatedAt":3867},{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[3945,3946,3947,3948],{"name":3860,"slug":3861,"type":15},{"name":23,"slug":24,"type":15},{"name":3864,"slug":3865,"type":15},{"name":17,"slug":18,"type":15},{"slug":3869,"name":3869,"fn":3870,"description":3871,"org":3950,"tags":3951,"stars":25,"repoUrl":26,"updatedAt":3880},{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[3952,3953,3954,3955],{"name":3860,"slug":3861,"type":15},{"name":3876,"slug":3877,"type":15},{"name":3864,"slug":3865,"type":15},{"name":17,"slug":18,"type":15},{"slug":3882,"name":3882,"fn":3883,"description":3884,"org":3957,"tags":3958,"stars":25,"repoUrl":26,"updatedAt":3893},{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[3959,3960,3961,3962],{"name":3888,"slug":3889,"type":15},{"name":23,"slug":24,"type":15},{"name":20,"slug":21,"type":15},{"name":17,"slug":18,"type":15},{"slug":3895,"name":3895,"fn":3896,"description":3897,"org":3964,"tags":3965,"stars":25,"repoUrl":26,"updatedAt":3906},{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[3966,3967,3968,3969],{"name":23,"slug":24,"type":15},{"name":3902,"slug":3903,"type":15},{"name":3864,"slug":3865,"type":15},{"name":17,"slug":18,"type":15},{"slug":3908,"name":3908,"fn":3909,"description":3910,"org":3971,"tags":3972,"stars":25,"repoUrl":26,"updatedAt":3919},{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[3973,3974,3975,3976],{"name":3876,"slug":3877,"type":15},{"name":23,"slug":24,"type":15},{"name":3916,"slug":3917,"type":15},{"name":17,"slug":18,"type":15},{"slug":3921,"name":3921,"fn":3922,"description":3923,"org":3978,"tags":3979,"stars":25,"repoUrl":26,"updatedAt":3932},{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[3980,3981,3982,3983],{"name":3927,"slug":3928,"type":15},{"name":3876,"slug":3877,"type":15},{"name":3916,"slug":3917,"type":15},{"name":17,"slug":18,"type":15},{"slug":3985,"name":3985,"fn":3986,"description":3987,"org":3988,"tags":3989,"stars":25,"repoUrl":26,"updatedAt":3997},"pay-with-any-token","pay HTTP 402 challenges with Uniswap","Pay HTTP 402 payment challenges using tokens via the Tempo CLI and Uniswap Trading API. Use when the user encounters a 402 Payment Required response, needs to fulfill a machine payment, mentions \"MPP\", \"Tempo payment\", \"pay for API access\", \"HTTP 402\", \"x402\", \"machine payment protocol\", \"pay-with-any-token\", \"use tempo\", \"tempo request\", or \"tempo wallet\".\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[3990,3991,3994,3995],{"name":3876,"slug":3877,"type":15},{"name":3992,"slug":3993,"type":15},"Payments","payments",{"name":3864,"slug":3865,"type":15},{"name":3996,"slug":3996,"type":15},"x402","2026-07-17T06:04:29.756086",{"slug":3999,"name":3999,"fn":4000,"description":4001,"org":4002,"tags":4003,"stars":25,"repoUrl":26,"updatedAt":4008},"pay-with-app","pay 402 payment challenges","Pay HTTP 402 payment challenges issued by OKX's Agent Payments Protocol (APP) on X Layer using tokens from any chain via the Uniswap Trading API. Use this skill whenever the user encounters a 402 challenge whose network resolves to X Layer (chain 196), mentions \"APP\", \"Agent Payments Protocol\", \"OKX agent payment\", \"OKX Onchain OS\", \"OKX agentic wallet\", \"x402 on X Layer\", \"USDT0\", \"x42\", \"Instant Payment\", \"Batch Payment\", \"pay for X Layer API\", or wants to pay an OKX-backed merchant. Even when the user does not explicitly say APP, prefer this skill for any 402 challenge whose network resolves to X Layer (chain 196). For 402 challenges on other chains (Ethereum, Base, Arbitrum, Tempo) use pay-with-any-token instead.\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[4004,4005,4006,4007],{"name":3927,"slug":3928,"type":15},{"name":3992,"slug":3993,"type":15},{"name":17,"slug":18,"type":15},{"name":3996,"slug":3996,"type":15},"2026-07-17T06:07:38.795043",{"slug":4010,"name":4010,"fn":4011,"description":4012,"org":4013,"tags":4014,"stars":25,"repoUrl":26,"updatedAt":4019},"swap-integration","integrate Uniswap swap functionality","Integrate Uniswap swaps into applications. Use when user says \"integrate swaps\", \"uniswap\", \"trading api\", \"add swap functionality\", \"build a swap frontend\", \"create a swap script\", \"smart contract swap integration\", \"use Universal Router\", \"Trading API\", or mentions swapping tokens via Uniswap.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[4015,4016,4017,4018],{"name":3927,"slug":3928,"type":15},{"name":3876,"slug":3877,"type":15},{"name":3864,"slug":3865,"type":15},{"name":17,"slug":18,"type":15},"2026-07-17T06:08:10.354222",{"slug":4021,"name":4021,"fn":4022,"description":4023,"org":4024,"tags":4025,"stars":25,"repoUrl":26,"updatedAt":4030},"swap-planner","plan and execute token swaps","This skill should be used when the user asks to \"swap tokens\", \"trade ETH for USDC\", \"exchange tokens on Uniswap\", \"buy tokens\", \"sell tokens\", \"convert ETH to stablecoins\", \"find memecoins\", \"discover tokens\", \"research tokens\", \"tokens to buy\", \"find tokens to swap\", \"what should I buy\", or mentions swapping, trading, researching, discovering, buying, or exchanging tokens on any Uniswap-supported chain. Supports both known token swaps and token discovery workflows (discovery uses keyword search and web search — there is no live \"trending\" feed). Generates deep links to execute swaps in the Uniswap interface.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[4026,4027,4028,4029],{"name":3876,"slug":3877,"type":15},{"name":3916,"slug":3917,"type":15},{"name":3864,"slug":3865,"type":15},{"name":17,"slug":18,"type":15},"2026-07-17T06:08:10.008152",{"slug":4032,"name":4032,"fn":4033,"description":4034,"org":4035,"tags":4036,"stars":25,"repoUrl":26,"updatedAt":4040},"v4-hook-generator","generate Uniswap v4 hook contracts","Generate Uniswap v4 hook contracts via OpenZeppelin MCP. Use when building custom swap logic, async swaps, hook-owned liquidity, custom curves, dynamic fees, MEV protection, limit orders, or oracle hooks.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":9},[4037,4038,4039],{"name":23,"slug":24,"type":15},{"name":20,"slug":21,"type":15},{"name":17,"slug":18,"type":15},"2026-07-17T06:04:19.17669"]