diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..83c48d0b7 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "lib/uniswap-hooks"] + path = lib/uniswap-hooks + url = https://github.com/openzeppelin/uniswap-hooks + branch = master diff --git a/packages/core/solidity/src/contract.test.ts.md b/packages/core/solidity/src/contract.test.ts.md index f0f01afb2..cc82a66d6 100644 --- a/packages/core/solidity/src/contract.test.ts.md +++ b/packages/core/solidity/src/contract.test.ts.md @@ -9,7 +9,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Foo {␊ @@ -21,7 +21,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Footec {␊ @@ -33,7 +33,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ import {Bar} from "./Bar.sol";␊ @@ -47,7 +47,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ import {Bar} from "./Bar.sol";␊ @@ -62,7 +62,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ import {Bar} from "./Bar.sol";␊ @@ -77,7 +77,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ import {Bar} from "./Bar.sol";␊ @@ -93,7 +93,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Foo {␊ @@ -105,7 +105,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Foo {␊ @@ -125,7 +125,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Foo {␊ @@ -149,7 +149,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Foo {␊ @@ -162,7 +162,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Foo {␊ @@ -177,7 +177,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Foo {␊ @@ -192,7 +192,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ import {Bar} from "./Bar.sol";␊ @@ -209,7 +209,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Foo {␊ @@ -224,7 +224,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Foo {␊ @@ -240,7 +240,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Foo {␊ @@ -253,7 +253,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Foo {␊ @@ -267,7 +267,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract FooBarBaz {␊ @@ -279,7 +279,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ /// @custom:security-contact security@example.com␊ diff --git a/packages/core/solidity/src/contract.test.ts.snap b/packages/core/solidity/src/contract.test.ts.snap index f14822349..29fafce04 100644 Binary files a/packages/core/solidity/src/contract.test.ts.snap and b/packages/core/solidity/src/contract.test.ts.snap differ diff --git a/packages/core/solidity/src/contract.ts b/packages/core/solidity/src/contract.ts index 6ed276124..13659536a 100644 --- a/packages/core/solidity/src/contract.ts +++ b/packages/core/solidity/src/contract.ts @@ -5,6 +5,7 @@ export interface Contract { license: string; parents: Parent[]; natspecTags: NatspecTag[]; + libraries: Library[]; imports: ImportContract[]; functions: ContractFunction[]; constructorCode: string[]; @@ -19,6 +20,7 @@ export interface Parent { contract: ImportContract; params: Value[]; importOnly?: boolean; + constructionOnly?: boolean; } export interface ImportContract extends ReferencedContract { @@ -30,9 +32,9 @@ export interface ReferencedContract { transpiled?: boolean; } -export interface Using { +export interface Library { library: ImportContract; - usingFor: string; + usingFor: Set; } export interface BaseFunction { @@ -52,7 +54,7 @@ export interface ContractFunction extends BaseFunction { comments: string[]; } -export type FunctionKind = 'internal' | 'public'; +export type FunctionKind = 'private' | 'internal' | 'public' | 'external'; export type FunctionMutability = (typeof mutabilityRank)[number]; // Order is important @@ -77,7 +79,6 @@ export class ContractBuilder implements Contract { license: string = 'MIT'; upgradeable = false; - readonly using: Using[] = []; readonly natspecTags: NatspecTag[] = []; readonly constructorArgs: FunctionArgument[] = []; @@ -85,7 +86,8 @@ export class ContractBuilder implements Contract { readonly variableSet: Set = new Set(); private parentMap: Map = new Map(); - private functionMap: Map = new Map(); + private functionMap: Map = new Map(); + private libraryMap: Map = new Map(); constructor(name: string) { this.name = toIdentifier(name, true); @@ -106,7 +108,13 @@ export class ContractBuilder implements Contract { } get imports(): ImportContract[] { - return [...[...this.parentMap.values()].map(p => p.contract), ...this.using.map(u => u.library)]; + const parents = [...this.parentMap.values()].map(p => p.contract); + const libraries = [...this.libraryMap.values()].map(l => l.library); + return [...parents, ...libraries]; + } + + get libraries(): Library[] { + return [...this.libraryMap.values()]; } get functions(): ContractFunction[] { @@ -133,6 +141,27 @@ export class ContractBuilder implements Contract { return !present; } + addConstructionOnly(contract: ImportContract, params: Value[] = []): boolean { + const present = this.parentMap.has(contract.name); + this.parentMap.set(contract.name, { contract, params, constructionOnly: true }); + return !present; + } + + addLibrary(library: ImportContract, usingFor: string[]): boolean { + let modified = false; + if (this.libraryMap.has(library.name)) { + const existing = this.libraryMap.get(library.name)!; + const initialSize = existing.usingFor.size; + usingFor.forEach(type => existing.usingFor.add(type)); + modified = existing.usingFor.size > initialSize; + } else { + this.libraryMap.set(library.name, { library, usingFor: new Set(usingFor) }); + modified = true; + } + + return modified; + } + addOverride(parent: ReferencedContract, baseFn: BaseFunction, mutability?: FunctionMutability) { const fn = this.addFunction(baseFn); fn.override.add(parent); diff --git a/packages/core/solidity/src/custom.test.ts.md b/packages/core/solidity/src/custom.test.ts.md index 7906d5648..d8ce01993 100644 --- a/packages/core/solidity/src/custom.test.ts.md +++ b/packages/core/solidity/src/custom.test.ts.md @@ -9,7 +9,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract MyContract {␊ @@ -21,7 +21,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract Contract {␊ @@ -106,7 +106,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract MyContract {␊ diff --git a/packages/core/solidity/src/custom.test.ts.snap b/packages/core/solidity/src/custom.test.ts.snap index 6e45868eb..7a976e2dd 100644 Binary files a/packages/core/solidity/src/custom.test.ts.snap and b/packages/core/solidity/src/custom.test.ts.snap differ diff --git a/packages/core/solidity/src/index.ts b/packages/core/solidity/src/index.ts index 209c432c3..681317359 100644 --- a/packages/core/solidity/src/index.ts +++ b/packages/core/solidity/src/index.ts @@ -1,7 +1,9 @@ export type { GenericOptions, KindedOptions } from './build-generic'; export { buildGeneric } from './build-generic'; -export type { Contract } from './contract'; +export { generateAlternatives } from './generate/alternatives'; + +export type { Contract, BaseFunction, Value, ReferencedContract } from './contract'; export { ContractBuilder } from './contract'; export { printContract } from './print'; @@ -11,7 +13,9 @@ export type { Upgradeable } from './set-upgradeable'; export type { Info } from './set-info'; export { premintPattern, chainIdPattern } from './erc20'; -export { defaults as infoDefaults } from './set-info'; +export { defaults as infoDefaults, infoOptions, setInfo } from './set-info'; +export { accessOptions, setAccessControl } from './set-access-control'; +export { addPausable } from './add-pausable'; export type { OptionsErrorMessages } from './error'; export { OptionsError } from './error'; @@ -20,8 +24,15 @@ export type { Kind } from './kind'; export { sanitizeKind } from './kind'; export { erc20, erc721, erc1155, stablecoin, realWorldAsset, account, governor, custom } from './api'; +export type { WizardContractAPI, AccessControlAPI } from './api'; export { compatibleContractsSemver } from './utils/version'; +export { findCover } from './utils/find-cover'; +export { defineFunctions } from './utils/define-functions'; + +export type { CommonOptions } from './common-options'; +export { withCommonDefaults, defaults as commonDefaults } from './common-options'; +export { supportsInterface } from './common-functions'; export type { ERC20Options } from './erc20'; export type { ERC721Options } from './erc721'; diff --git a/packages/core/solidity/src/options.ts b/packages/core/solidity/src/options.ts index 9a1606490..b6f4f54bd 100644 --- a/packages/core/solidity/src/options.ts +++ b/packages/core/solidity/src/options.ts @@ -27,6 +27,10 @@ export function upgradeableImport(p: ImportContract): ImportContract { export interface Options { transformImport?: (parent: ImportContract) => ImportContract; + /** + * Add additional libraries to the compatibility banner printed at the top of the contract. + */ + additionalCompatibleLibraries?: { name: string; path: string; version: string }[]; } export interface Helpers extends Required { @@ -45,5 +49,6 @@ export function withHelpers(contract: Contract, opts: Options = {}): Helpers { const p2 = contractUpgradeable && inferTranspiled(p1) ? upgradeableImport(p1) : p1; return opts.transformImport?.(p2) ?? p2; }, + additionalCompatibleLibraries: opts.additionalCompatibleLibraries ?? [], }; } diff --git a/packages/core/solidity/src/print.ts b/packages/core/solidity/src/print.ts index bc6202d7d..d68676de5 100644 --- a/packages/core/solidity/src/print.ts +++ b/packages/core/solidity/src/print.ts @@ -17,7 +17,7 @@ import SOLIDITY_VERSION from './solidity-version.json'; import { inferTranspiled } from './infer-transpiled'; import { compatibleContractsSemver } from './utils/version'; import { stringifyUnicodeSafe } from './utils/sanitize'; -import { importsCommunityContracts } from './utils/imports-libraries'; +import { importsLibrary } from './utils/imports-libraries'; import { getCommunityContractsGitCommit } from './utils/community-contracts-git-commit'; export function printContract(contract: Contract, opts?: Options): string { @@ -31,7 +31,7 @@ export function printContract(contract: Contract, opts?: Options): string { ...spaceBetween( [ `// SPDX-License-Identifier: ${contract.license}`, - printCompatibleLibraryVersions(contract), + printCompatibleLibraryVersions(contract, opts), `pragma solidity ^${SOLIDITY_VERSION};`, ], @@ -42,6 +42,7 @@ export function printContract(contract: Contract, opts?: Options): string { [`contract ${contract.name}`, ...printInheritance(contract, helpers), '{'].join(' '), spaceBetween( + printLibraries(contract, helpers), contract.variables, printConstructor(contract, helpers), ...fns.code, @@ -56,22 +57,41 @@ export function printContract(contract: Contract, opts?: Options): string { ); } -function printCompatibleLibraryVersions(contract: Contract): string { - let result = `// Compatible with OpenZeppelin Contracts ${compatibleContractsSemver}`; - if (importsCommunityContracts(contract)) { +function printCompatibleLibraryVersions(contract: Contract, opts?: Options): string { + const libraries: string[] = []; + if (importsLibrary(contract, '@openzeppelin/contracts')) { + libraries.push(`OpenZeppelin Contracts ${compatibleContractsSemver}`); + } + if (importsLibrary(contract, '@openzeppelin/community-contracts')) { try { const commit = getCommunityContractsGitCommit(); - result += ` and Community Contracts commit ${commit}`; + libraries.push(`Community Contracts commit ${commit}`); } catch (e) { console.error(e); } } - return result; + if (opts?.additionalCompatibleLibraries) { + for (const library of opts.additionalCompatibleLibraries) { + if (importsLibrary(contract, library.path)) { + libraries.push(`${library.name} ${library.version}`); + } + } + } + + if (libraries.length === 0) return ''; + if (libraries.length === 1) return `// Compatible with ${libraries[0]}`; + return `// Compatible with ${libraries.slice(0, -1).join(', ')} and ${libraries.slice(-1)}`; } function printInheritance(contract: Contract, { transformName }: Helpers): [] | [string] { if (contract.parents.length > 0) { - return ['is ' + contract.parents.map(p => transformName(p.contract)).join(', ')]; + return [ + 'is ' + + contract.parents + .filter(p => !p.constructionOnly) + .map(p => transformName(p.contract)) + .join(', '), + ]; } else { return []; } @@ -293,3 +313,14 @@ function printImports(imports: ImportContract[], helpers: Helpers): string[] { return lines; } + +function printLibraries(contract: Contract, { transformName }: Helpers): string[] { + if (!contract.libraries || contract.libraries.length === 0) return []; + + return contract.libraries + .sort((a, b) => a.library.name.localeCompare(b.library.name)) // Sort by library name + .map(lib => { + const sortedTypes = Array.from(lib.usingFor).sort((a, b) => a.localeCompare(b)); // Sort types + return `using ${transformName(lib.library)} for ${sortedTypes.join(', ')};`; + }); +} diff --git a/packages/core/solidity/src/utils/imports-libraries.ts b/packages/core/solidity/src/utils/imports-libraries.ts index 7ffc8e2c6..1892762a2 100644 --- a/packages/core/solidity/src/utils/imports-libraries.ts +++ b/packages/core/solidity/src/utils/imports-libraries.ts @@ -1,5 +1,5 @@ import type { Contract } from '../contract'; -export function importsCommunityContracts(contract: Contract) { - return contract.imports.some(i => i.path.startsWith('@openzeppelin/community-contracts/')); +export function importsLibrary(contract: Contract, library: string) { + return contract.imports.some(i => i.path.startsWith(library)); } diff --git a/packages/core/solidity/src/zip-foundry.test.ts.md b/packages/core/solidity/src/zip-foundry.test.ts.md index f3f4dfc1f..b1fb57487 100644 --- a/packages/core/solidity/src/zip-foundry.test.ts.md +++ b/packages/core/solidity/src/zip-foundry.test.ts.md @@ -1588,7 +1588,7 @@ Generated by [AVA](https://avajs.dev). }␊ `, `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract MyContract {␊ diff --git a/packages/core/solidity/src/zip-foundry.test.ts.snap b/packages/core/solidity/src/zip-foundry.test.ts.snap index 7debb3adf..e484d2ef1 100644 Binary files a/packages/core/solidity/src/zip-foundry.test.ts.snap and b/packages/core/solidity/src/zip-foundry.test.ts.snap differ diff --git a/packages/core/solidity/src/zip-hardhat.test.ts.md b/packages/core/solidity/src/zip-hardhat.test.ts.md index 745b178b5..9c82cebb1 100644 --- a/packages/core/solidity/src/zip-hardhat.test.ts.md +++ b/packages/core/solidity/src/zip-hardhat.test.ts.md @@ -677,7 +677,7 @@ Generated by [AVA](https://avajs.dev). [ `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + ␊ pragma solidity ^0.8.27;␊ ␊ contract MyContract {␊ diff --git a/packages/core/solidity/src/zip-hardhat.test.ts.snap b/packages/core/solidity/src/zip-hardhat.test.ts.snap index 29d2250f4..169079780 100644 Binary files a/packages/core/solidity/src/zip-hardhat.test.ts.snap and b/packages/core/solidity/src/zip-hardhat.test.ts.snap differ diff --git a/packages/core/uniswap-hooks/.gitignore b/packages/core/uniswap-hooks/.gitignore new file mode 100644 index 000000000..017fefa2d --- /dev/null +++ b/packages/core/uniswap-hooks/.gitignore @@ -0,0 +1,4 @@ +/cache +/artifacts +/contracts/generated +/openzeppelin-contracts.json diff --git a/packages/core/uniswap-hooks/CHANGELOG.md b/packages/core/uniswap-hooks/CHANGELOG.md new file mode 100644 index 000000000..e69de29bb diff --git a/packages/core/uniswap-hooks/LICENSE b/packages/core/uniswap-hooks/LICENSE new file mode 100644 index 000000000..be3f7b28e --- /dev/null +++ b/packages/core/uniswap-hooks/LICENSE @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff --git a/packages/core/uniswap-hooks/NOTICE b/packages/core/uniswap-hooks/NOTICE new file mode 100644 index 000000000..7a7686aaf --- /dev/null +++ b/packages/core/uniswap-hooks/NOTICE @@ -0,0 +1,8 @@ +OpenZeppelin Contracts Wizard +Copyright (C) 2021-2025 Zeppelin Group Ltd + +This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License along with this program. If not, see . diff --git a/packages/core/uniswap-hooks/README.md b/packages/core/uniswap-hooks/README.md new file mode 100644 index 000000000..854324f36 --- /dev/null +++ b/packages/core/uniswap-hooks/README.md @@ -0,0 +1 @@ +# OpenZeppelin Contracts Wizard for Uniswap Hooks \ No newline at end of file diff --git a/packages/core/uniswap-hooks/ava.config.js b/packages/core/uniswap-hooks/ava.config.js new file mode 100644 index 000000000..e39146f7a --- /dev/null +++ b/packages/core/uniswap-hooks/ava.config.js @@ -0,0 +1,9 @@ +module.exports = { + extensions: ['ts'], + require: ['ts-node/register'], + watchmode: { + ignoreChanges: ['contracts', 'artifacts', 'cache'], + }, + timeout: '10m', + workerThreads: false, +}; diff --git a/packages/core/uniswap-hooks/hardhat.config.js b/packages/core/uniswap-hooks/hardhat.config.js new file mode 100644 index 000000000..e456ab1e1 --- /dev/null +++ b/packages/core/uniswap-hooks/hardhat.config.js @@ -0,0 +1,76 @@ +const fs = require('fs'); +const { task } = require('hardhat/config'); +const { HardhatError } = require('hardhat/internal/core/errors'); +const { ERRORS } = require('hardhat/internal/core/errors-list'); +const { + TASK_COMPILE_SOLIDITY_CHECK_ERRORS, + TASK_COMPILE_SOLIDITY_LOG_COMPILATION_ERRORS, + TASK_COMPILE_SOLIDITY_MERGE_COMPILATION_JOBS, + TASK_COMPILE_GET_REMAPPINGS, +} = require('hardhat/builtin-tasks/task-names'); + +const SOLIDITY_VERSION = require('./src/.solidity-version.json'); + +// Keep parity with solidity package: treat warnings as errors except these codes. +const WARN_UNUSED_PARAMETER = '5667'; +const WARN_CODE_SIZE = '5574'; +const WARN_TRANSIENT_STORAGE = '2394'; +const IGNORED_WARNINGS = [WARN_UNUSED_PARAMETER, WARN_CODE_SIZE, WARN_TRANSIENT_STORAGE]; + +// Overriding this task so that warnings are considered errors. +task(TASK_COMPILE_SOLIDITY_CHECK_ERRORS, async ({ output, quiet }, { run }) => { + const errors = (output.errors && output.errors.filter(e => !IGNORED_WARNINGS.includes(e.errorCode))) || []; + + await run(TASK_COMPILE_SOLIDITY_LOG_COMPILATION_ERRORS, { + output: { ...output, errors }, + quiet, + }); + + if (errors.length > 0) { + throw new HardhatError(ERRORS.BUILTIN_TASKS.COMPILE_FAILURE); + } +}); + +// Chunk merging to reduce memory pressure if you generate many files. +task(TASK_COMPILE_SOLIDITY_MERGE_COMPILATION_JOBS, async ({ compilationJobs }, _, runSuper) => { + const CHUNK_SIZE = 100; + const chunks = []; + for (let i = 0; i < compilationJobs.length - 1; i += CHUNK_SIZE) { + chunks.push(compilationJobs.slice(i, i + CHUNK_SIZE)); + } + const mergedChunks = await Promise.all(chunks.map(cj => runSuper({ compilationJobs: cj }))); + return mergedChunks.flat(); +}); + +// Optional remappings (guarded so file absence doesn’t crash) +task(TASK_COMPILE_GET_REMAPPINGS).setAction((_, __, runSuper) => + runSuper().then(remappings => + Object.assign( + remappings, + Object.fromEntries( + fs + .readFileSync('remappings.txt', 'utf-8') + .split('\n') + .filter(Boolean) + .map(line => line.trim().split('=')), + ), + ), + ), +); + +/** + * @type import('hardhat/config').HardhatUserConfig + */ +module.exports = { + solidity: { + compilers: [ + { + version: SOLIDITY_VERSION, + settings: { + evmVersion: 'cancun', + optimizer: { enabled: true, runs: 200 }, + }, + }, + ], + }, +}; diff --git a/packages/core/uniswap-hooks/package.json b/packages/core/uniswap-hooks/package.json new file mode 100644 index 000000000..cdb2df692 --- /dev/null +++ b/packages/core/uniswap-hooks/package.json @@ -0,0 +1,39 @@ +{ + "name": "@openzeppelin/wizard-uniswap-hooks", + "version": "0.0.1-alpha.0", + "description": "A boilerplate generator to get started with OpenZeppelin Contracts for Uniswap Hooks", + "license": "AGPL-3.0-only", + "repository": "https://github.com/OpenZeppelin/contracts-wizard", + "main": "dist/index.js", + "ts:main": "src/index.ts", + "files": [ + "LICENSE", + "NOTICE", + "/dist", + "/src", + "!**/*.test.*" + ], + "scripts": { + "prepare": "tsc", + "prepublish": "rimraf dist *.tsbuildinfo && hardhat clean", + "test": "ava", + "test:compile": "npm test -- src/test.ts", + "test:update-snapshots": "ava --update-snapshots", + "test:watch": "ava --watch" + }, + "devDependencies": { + "@openzeppelin/contracts": "^5.4.0", + "@openzeppelin/uniswap-hooks": "github:openzeppelin/uniswap-hooks#master", + "@types/node": "^20.0.0", + "@types/semver": "^7.5.7", + "@uniswap/v4-core": "^1.0.2", + "@uniswap/v4-periphery": "^1.0.3", + "ava": "^6.0.0", + "hardhat": "^2.22.11", + "rimraf": "^5.0.0", + "semver": "^7.6.0", + "solidity-ast": "^0.4.18", + "ts-node": "^10.4.0", + "typescript": "^5.0.0" + } +} diff --git a/packages/core/uniswap-hooks/remappings.txt b/packages/core/uniswap-hooks/remappings.txt new file mode 100644 index 000000000..2173b79a6 --- /dev/null +++ b/packages/core/uniswap-hooks/remappings.txt @@ -0,0 +1,4 @@ +@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/ +@uniswap/v4-core/=node_modules/@uniswap/v4-core/ +@uniswap/v4-periphery/=node_modules/@uniswap/v4-periphery/ +@openzeppelin/uniswap-hooks/=node_modules/@openzeppelin/uniswap-hooks/src/ \ No newline at end of file diff --git a/packages/core/uniswap-hooks/src/.solidity-version.json b/packages/core/uniswap-hooks/src/.solidity-version.json new file mode 100644 index 000000000..12b321f91 --- /dev/null +++ b/packages/core/uniswap-hooks/src/.solidity-version.json @@ -0,0 +1 @@ +"0.8.27" diff --git a/packages/core/uniswap-hooks/src/api.ts b/packages/core/uniswap-hooks/src/api.ts new file mode 100644 index 000000000..f0f2edef5 --- /dev/null +++ b/packages/core/uniswap-hooks/src/api.ts @@ -0,0 +1,15 @@ +import type { WizardContractAPI, AccessControlAPI } from '@openzeppelin/wizard'; +import { + printHooks, + defaults as hooksDefaults, + isAccessControlRequired as hooksIsAccessControlRequired, + type HooksOptions, +} from './hooks'; + +export type Hooks = WizardContractAPI & AccessControlAPI; + +export const hooks: Hooks = { + print: printHooks, + defaults: hooksDefaults, + isAccessControlRequired: hooksIsAccessControlRequired, +}; diff --git a/packages/core/uniswap-hooks/src/build-generic.ts b/packages/core/uniswap-hooks/src/build-generic.ts new file mode 100644 index 000000000..51e02dc90 --- /dev/null +++ b/packages/core/uniswap-hooks/src/build-generic.ts @@ -0,0 +1,15 @@ +import type { Contract } from '@openzeppelin/wizard'; +import { buildHooks, type HooksOptions } from './hooks'; + +export interface KindedOptions { + Hooks: { kind: 'Hooks' } & HooksOptions; +} + +export type GenericOptions = KindedOptions[keyof KindedOptions]; + +export function buildGeneric(opts: GenericOptions): Contract { + switch (opts.kind) { + case 'Hooks': + return buildHooks(opts); + } +} diff --git a/packages/core/uniswap-hooks/src/generate/hooks.ts b/packages/core/uniswap-hooks/src/generate/hooks.ts new file mode 100644 index 000000000..9c68ff668 --- /dev/null +++ b/packages/core/uniswap-hooks/src/generate/hooks.ts @@ -0,0 +1,51 @@ +import { infoOptions, accessOptions, generateAlternatives } from '@openzeppelin/wizard'; +import type { HooksOptions } from '../hooks'; +import { HOOKS, PERMISSIONS, type HookName, type Shares, type Permissions } from '../hooks/index'; + +const booleanOptions = [true, false]; + +const sharesOptions: Shares[] = [ + { options: false, name: 'MyShares', symbol: 'MSH' }, + { options: 'ERC20', name: 'MyShares', symbol: 'MSH' }, + { options: 'ERC6909', name: 'MyShares', symbol: 'MSH' }, +] as const; + +// Generate some permission combinations. Note that generating all would result in 2^14 combinations. +const permissionsOptions: Permissions[] = [generateMixedPermissions(), generateMixedInversedPermissions()] as const; + +const hooksOptions: HookName[] = Object.keys(HOOKS) as HookName[]; + +const inputsOptions = [{ blockNumberOffset: 10 }]; + +const blueprint = { + hook: hooksOptions as readonly HookName[], + name: ['MyHook'] as const, + pausable: booleanOptions, + access: accessOptions, + info: infoOptions, + shares: sharesOptions, + permissions: permissionsOptions, + // Hooks are not upgradeable yet; fix to false + upgradeable: [false] as const, + // Keep utility libraries marked as true to keep combinations manageable + currencySettler: [true], + safeCast: [true], + transientStorage: [true], + inputs: inputsOptions, +}; + +export function* generateHooksOptions(): Generator> { + yield* generateAlternatives(blueprint); +} + +export function generateMixedPermissions(): Permissions { + return Object.fromEntries(PERMISSIONS.map((key, idx) => [key, idx % 2 === 0])) as Permissions; +} + +export function generateMixedInversedPermissions(): Permissions { + return Object.fromEntries(PERMISSIONS.map((key, idx) => [key, idx % 2 !== 0])) as Permissions; +} + +export function generateAllPermissions(): Permissions { + return Object.fromEntries(PERMISSIONS.map(key => [key, true])) as Permissions; +} diff --git a/packages/core/uniswap-hooks/src/generate/sources.ts b/packages/core/uniswap-hooks/src/generate/sources.ts new file mode 100644 index 000000000..8835bd135 --- /dev/null +++ b/packages/core/uniswap-hooks/src/generate/sources.ts @@ -0,0 +1,69 @@ +import { promises as fs } from 'fs'; +import path from 'path'; +import crypto from 'crypto'; +import { printContract, OptionsError, findCover, type Contract } from '@openzeppelin/wizard'; +import { generateHooksOptions } from './hooks'; +import { buildGeneric, type GenericOptions, type KindedOptions } from '../build-generic'; + +type Subset = 'all' | 'minimal-cover'; + +type Kind = keyof KindedOptions; + +export function* generateOptions(kind?: Kind): Generator { + if (!kind || kind === 'Hooks') { + for (const kindOpts of generateHooksOptions()) { + yield { kind: 'Hooks', ...kindOpts }; + } + } +} + +interface GeneratedContract { + id: string; + options: GenericOptions; + contract: Contract; +} + +export interface GeneratedSource extends GeneratedContract { + source: string; +} + +function generateContractSubset(subset: Subset, kind?: Kind): GeneratedContract[] { + const contracts = []; + + for (const options of generateOptions(kind)) { + const id = crypto.createHash('sha1').update(JSON.stringify(options)).digest().toString('hex'); + + try { + const contract = buildGeneric(options); + contracts.push({ id, options, contract }); + } catch (e: unknown) { + if (e instanceof OptionsError) { + continue; + } else { + throw e; + } + } + } + + if (subset === 'all') { + return contracts; + } else { + const getParents = (c: GeneratedContract) => c.contract.parents.map(p => p.contract.path); + return [...findCover(contracts, getParents)]; + } +} + +export function* generateSources(subset: Subset, kind?: Kind): Generator { + for (const c of generateContractSubset(subset, kind)) { + const source = printContract(c.contract); + yield { ...c, source }; + } +} + +export async function writeGeneratedSources(dir: string, subset: Subset, kind?: Kind): Promise { + await fs.mkdir(dir, { recursive: true }); + + for (const { id, source } of generateSources(subset, kind)) { + await fs.writeFile(path.format({ dir, name: id, ext: '.sol' }), source); + } +} diff --git a/packages/core/uniswap-hooks/src/hooks.test.ts b/packages/core/uniswap-hooks/src/hooks.test.ts new file mode 100644 index 000000000..c5275035b --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks.test.ts @@ -0,0 +1,59 @@ +import test from 'ava'; +import { hooks } from './api'; +import { buildHooks, type HooksOptions } from './hooks'; +import { HOOKS } from './hooks/'; +import { printContract } from './print'; +import { generateAllPermissions, generateMixedInversedPermissions, generateMixedPermissions } from './generate/hooks'; + +function testHooks(title: string, opts: Partial) { + test(title, t => { + const c = buildHooks({ + ...hooks.defaults, + ...opts, + }); + t.snapshot(printContract(c)); + }); +} + +for (const key in HOOKS) { + const hook = HOOKS[key as keyof typeof HOOKS]; + testHooks(`basic ${hook.name}`, { hook: hook.name }); + + testHooks(`mixed permissions ${hook.name}`, { hook: hook.name, permissions: generateMixedPermissions() }); + + testHooks(`inversed mixed permissions ${hook.name}`, { + hook: hook.name, + permissions: generateMixedInversedPermissions(), + }); + + testHooks(`all permissions ${hook.name}`, { hook: hook.name, permissions: generateAllPermissions() }); + + testHooks(`currency settler ${hook.name}`, { hook: hook.name, currencySettler: true }); + + testHooks(`safeCast ${hook.name}`, { hook: hook.name, safeCast: true }); + + testHooks(`transient storage ${hook.name}`, { hook: hook.name, transientStorage: true }); + + testHooks(`access control (ownable) ${hook.name}`, { hook: hook.name, access: 'ownable' }); + + testHooks(`access control (roles) ${hook.name}`, { hook: hook.name, access: 'roles' }); + + testHooks(`access control (managed) ${hook.name}`, { hook: hook.name, access: 'managed' }); + + testHooks(`pausable ${hook.name}`, { hook: hook.name, pausable: true }); + + testHooks(`shares erc20 ${hook.name}`, { + hook: hook.name, + shares: { options: 'ERC20', name: 'MyShares', symbol: 'MSH' }, + }); + + testHooks(`shares erc1155 ${hook.name}`, { + hook: hook.name, + shares: { options: 'ERC1155', uri: 'https://example.com/metadata/{id}.json' }, + }); + + testHooks(`shares erc6909 ${hook.name}`, { + hook: hook.name, + shares: { options: 'ERC6909' }, + }); +} diff --git a/packages/core/uniswap-hooks/src/hooks.test.ts.md b/packages/core/uniswap-hooks/src/hooks.test.ts.md new file mode 100644 index 000000000..b9c793f14 --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks.test.ts.md @@ -0,0 +1,16429 @@ +# Snapshot report for `src/hooks.test.ts` + +The actual snapshot is saved in `hooks.test.ts.snap`. + +Generated by [AVA](https://avajs.dev). + +## basic BaseHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + ␊ + contract MyHook is BaseHook {␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: false,␊ + afterSwap: false,␊ + beforeDonate: false,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## mixed permissions BaseHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseHook {␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## inversed mixed permissions BaseHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseHook {␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: true,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: false,␊ + afterSwap: true,␊ + beforeDonate: false,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## all permissions BaseHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseHook {␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## currency settler BaseHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {CurrencySettler} from "@openzeppelin/uniswap-hooks/utils/CurrencySettler.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + ␊ + contract MyHook is BaseHook {␊ + using CurrencySettler for Currency;␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: false,␊ + afterSwap: false,␊ + beforeDonate: false,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## safeCast BaseHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";␊ + ␊ + contract MyHook is BaseHook {␊ + using SafeCast for *;␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: false,␊ + afterSwap: false,␊ + beforeDonate: false,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## transient storage BaseHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {SlotDerivation} from "@openzeppelin/contracts/utils/SlotDerivation.sol";␊ + import {TransientSlot} from "@openzeppelin/contracts/utils/TransientSlot.sol";␊ + ␊ + contract MyHook is BaseHook {␊ + using SlotDerivation for bytes32;␊ + using TransientSlot for bytes32;␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: false,␊ + afterSwap: false,␊ + beforeDonate: false,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (ownable) BaseHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + ␊ + contract MyHook is BaseHook, Ownable {␊ + constructor(address initialOwner) Ownable(initialOwner) {}␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: false,␊ + afterSwap: false,␊ + beforeDonate: false,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (roles) BaseHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + ␊ + contract MyHook is BaseHook, AccessControl {␊ + constructor(address defaultAdmin) {␊ + _grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: false,␊ + afterSwap: false,␊ + beforeDonate: false,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (managed) BaseHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol";␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + ␊ + contract MyHook is BaseHook, AccessManaged {␊ + constructor(address initialAuthority) AccessManaged(initialAuthority) {}␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: false,␊ + afterSwap: false,␊ + beforeDonate: false,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## pausable BaseHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseHook, Pausable, Ownable {␊ + constructor(address initialOwner) Ownable(initialOwner) {}␊ + ␊ + function pause() public onlyOwner {␊ + _pause();␊ + }␊ + ␊ + function unpause() public onlyOwner {␊ + _unpause();␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeAddLiquidity(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeRemoveLiquidity(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + return super._beforeSwap(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeDonate(sender, key, amount0, amount1, hookData);␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc20 BaseHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseHook, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc1155 BaseHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseHook, ERC1155 {␊ + constructor() ERC1155("https://example.com/metadata/{id}.json") {}␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc6909 BaseHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseHook} from "@openzeppelin/uniswap-hooks/base/BaseHook.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC6909} from "@openzeppelin/contracts/token/ERC6909/draft-ERC6909.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseHook, ERC6909 {␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## basic BaseAsyncSwap + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseAsyncSwap} from "@openzeppelin/uniswap-hooks/base/BaseAsyncSwap.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + ␊ + contract MyHook is BaseAsyncSwap {␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## mixed permissions BaseAsyncSwap + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseAsyncSwap} from "@openzeppelin/uniswap-hooks/base/BaseAsyncSwap.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + ␊ + contract MyHook is BaseAsyncSwap {␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## inversed mixed permissions BaseAsyncSwap + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseAsyncSwap} from "@openzeppelin/uniswap-hooks/base/BaseAsyncSwap.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseAsyncSwap {␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: true,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: false,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## all permissions BaseAsyncSwap + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseAsyncSwap} from "@openzeppelin/uniswap-hooks/base/BaseAsyncSwap.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseAsyncSwap {␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## currency settler BaseAsyncSwap + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseAsyncSwap} from "@openzeppelin/uniswap-hooks/base/BaseAsyncSwap.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {CurrencySettler} from "@openzeppelin/uniswap-hooks/utils/CurrencySettler.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + ␊ + contract MyHook is BaseAsyncSwap {␊ + using CurrencySettler for Currency;␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## safeCast BaseAsyncSwap + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseAsyncSwap} from "@openzeppelin/uniswap-hooks/base/BaseAsyncSwap.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";␊ + ␊ + contract MyHook is BaseAsyncSwap {␊ + using SafeCast for *;␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## transient storage BaseAsyncSwap + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseAsyncSwap} from "@openzeppelin/uniswap-hooks/base/BaseAsyncSwap.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SlotDerivation} from "@openzeppelin/contracts/utils/SlotDerivation.sol";␊ + import {TransientSlot} from "@openzeppelin/contracts/utils/TransientSlot.sol";␊ + ␊ + contract MyHook is BaseAsyncSwap {␊ + using SlotDerivation for bytes32;␊ + using TransientSlot for bytes32;␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (ownable) BaseAsyncSwap + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseAsyncSwap} from "@openzeppelin/uniswap-hooks/base/BaseAsyncSwap.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + ␊ + contract MyHook is BaseAsyncSwap, Ownable {␊ + constructor(address initialOwner) Ownable(initialOwner) {}␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (roles) BaseAsyncSwap + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";␊ + import {BaseAsyncSwap} from "@openzeppelin/uniswap-hooks/base/BaseAsyncSwap.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + ␊ + contract MyHook is BaseAsyncSwap, AccessControl {␊ + constructor(address defaultAdmin) {␊ + _grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (managed) BaseAsyncSwap + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol";␊ + import {BaseAsyncSwap} from "@openzeppelin/uniswap-hooks/base/BaseAsyncSwap.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + ␊ + contract MyHook is BaseAsyncSwap, AccessManaged {␊ + constructor(address initialAuthority) AccessManaged(initialAuthority) {}␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## pausable BaseAsyncSwap + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseAsyncSwap} from "@openzeppelin/uniswap-hooks/base/BaseAsyncSwap.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseAsyncSwap, Pausable, Ownable {␊ + constructor(address initialOwner) Ownable(initialOwner) {}␊ + ␊ + function pause() public onlyOwner {␊ + _pause();␊ + }␊ + ␊ + function unpause() public onlyOwner {␊ + _unpause();␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeAddLiquidity(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeRemoveLiquidity(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + return super._beforeSwap(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeDonate(sender, key, amount0, amount1, hookData);␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc20 BaseAsyncSwap + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseAsyncSwap} from "@openzeppelin/uniswap-hooks/base/BaseAsyncSwap.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + ␊ + contract MyHook is BaseAsyncSwap, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc1155 BaseAsyncSwap + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseAsyncSwap} from "@openzeppelin/uniswap-hooks/base/BaseAsyncSwap.sol";␊ + import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + ␊ + contract MyHook is BaseAsyncSwap, ERC1155 {␊ + constructor() ERC1155("https://example.com/metadata/{id}.json") {}␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc6909 BaseAsyncSwap + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseAsyncSwap} from "@openzeppelin/uniswap-hooks/base/BaseAsyncSwap.sol";␊ + import {ERC6909} from "@openzeppelin/contracts/token/ERC6909/draft-ERC6909.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + ␊ + contract MyHook is BaseAsyncSwap, ERC6909 {␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## basic BaseCustomAccounting + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomAccounting} from "@openzeppelin/uniswap-hooks/base/BaseCustomAccounting.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomAccounting, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getAddLiquidity(uint160 sqrtPriceX96, AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity additions and minted shares are computed␊ + }␊ + ␊ + function _getRemoveLiquidity(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity removals and burned shares are computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## mixed permissions BaseCustomAccounting + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomAccounting} from "@openzeppelin/uniswap-hooks/base/BaseCustomAccounting.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomAccounting, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getAddLiquidity(uint160 sqrtPriceX96, AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity additions and minted shares are computed␊ + }␊ + ␊ + function _getRemoveLiquidity(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity removals and burned shares are computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## inversed mixed permissions BaseCustomAccounting + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomAccounting} from "@openzeppelin/uniswap-hooks/base/BaseCustomAccounting.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomAccounting, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getAddLiquidity(uint160 sqrtPriceX96, AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity additions and minted shares are computed␊ + }␊ + ␊ + function _getRemoveLiquidity(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity removals and burned shares are computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: false,␊ + afterSwap: true,␊ + beforeDonate: false,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## all permissions BaseCustomAccounting + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomAccounting} from "@openzeppelin/uniswap-hooks/base/BaseCustomAccounting.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomAccounting, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getAddLiquidity(uint160 sqrtPriceX96, AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity additions and minted shares are computed␊ + }␊ + ␊ + function _getRemoveLiquidity(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity removals and burned shares are computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## currency settler BaseCustomAccounting + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomAccounting} from "@openzeppelin/uniswap-hooks/base/BaseCustomAccounting.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {CurrencySettler} from "@openzeppelin/uniswap-hooks/utils/CurrencySettler.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomAccounting, ERC20 {␊ + using CurrencySettler for Currency;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getAddLiquidity(uint160 sqrtPriceX96, AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity additions and minted shares are computed␊ + }␊ + ␊ + function _getRemoveLiquidity(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity removals and burned shares are computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## safeCast BaseCustomAccounting + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomAccounting} from "@openzeppelin/uniswap-hooks/base/BaseCustomAccounting.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomAccounting, ERC20 {␊ + using SafeCast for *;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getAddLiquidity(uint160 sqrtPriceX96, AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity additions and minted shares are computed␊ + }␊ + ␊ + function _getRemoveLiquidity(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity removals and burned shares are computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## transient storage BaseCustomAccounting + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomAccounting} from "@openzeppelin/uniswap-hooks/base/BaseCustomAccounting.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SlotDerivation} from "@openzeppelin/contracts/utils/SlotDerivation.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {TransientSlot} from "@openzeppelin/contracts/utils/TransientSlot.sol";␊ + ␊ + contract MyHook is BaseCustomAccounting, ERC20 {␊ + using SlotDerivation for bytes32;␊ + using TransientSlot for bytes32;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getAddLiquidity(uint160 sqrtPriceX96, AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity additions and minted shares are computed␊ + }␊ + ␊ + function _getRemoveLiquidity(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity removals and burned shares are computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (ownable) BaseCustomAccounting + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomAccounting} from "@openzeppelin/uniswap-hooks/base/BaseCustomAccounting.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomAccounting, Ownable, ERC20 {␊ + constructor(address initialOwner)␊ + Ownable(initialOwner)␊ + ERC20("MyShares", "MSH")␊ + {}␊ + ␊ + function _getAddLiquidity(uint160 sqrtPriceX96, AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity additions and minted shares are computed␊ + }␊ + ␊ + function _getRemoveLiquidity(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity removals and burned shares are computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (roles) BaseCustomAccounting + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomAccounting} from "@openzeppelin/uniswap-hooks/base/BaseCustomAccounting.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomAccounting, AccessControl, ERC20 {␊ + constructor(address defaultAdmin) ERC20("MyShares", "MSH") {␊ + _grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);␊ + }␊ + ␊ + function _getAddLiquidity(uint160 sqrtPriceX96, AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity additions and minted shares are computed␊ + }␊ + ␊ + function _getRemoveLiquidity(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity removals and burned shares are computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (managed) BaseCustomAccounting + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomAccounting} from "@openzeppelin/uniswap-hooks/base/BaseCustomAccounting.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomAccounting, AccessManaged, ERC20 {␊ + constructor(address initialAuthority)␊ + AccessManaged(initialAuthority)␊ + ERC20("MyShares", "MSH")␊ + {}␊ + ␊ + function _getAddLiquidity(uint160 sqrtPriceX96, AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity additions and minted shares are computed␊ + }␊ + ␊ + function _getRemoveLiquidity(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity removals and burned shares are computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## pausable BaseCustomAccounting + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomAccounting} from "@openzeppelin/uniswap-hooks/base/BaseCustomAccounting.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomAccounting, ERC20, Pausable, Ownable {␊ + constructor(address initialOwner)␊ + ERC20("MyShares", "MSH")␊ + Ownable(initialOwner)␊ + {}␊ + ␊ + function _getAddLiquidity(uint160 sqrtPriceX96, AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity additions and minted shares are computed␊ + }␊ + ␊ + function _getRemoveLiquidity(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity removals and burned shares are computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function pause() public onlyOwner {␊ + _pause();␊ + }␊ + ␊ + function unpause() public onlyOwner {␊ + _unpause();␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + return super._beforeSwap(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeDonate(sender, key, amount0, amount1, hookData);␊ + }␊ + ␊ + function addLiquidity(AddLiquidityParams calldata params)␊ + public␊ + payable␊ + override␊ + whenNotPaused␊ + returns (BalanceDelta)␊ + {␊ + return super.addLiquidity(params);␊ + }␊ + ␊ + function removeLiquidity(RemoveLiquidityParams calldata params)␊ + public␊ + override␊ + whenNotPaused␊ + returns (BalanceDelta)␊ + {␊ + return super.removeLiquidity(params);␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc20 BaseCustomAccounting + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomAccounting} from "@openzeppelin/uniswap-hooks/base/BaseCustomAccounting.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomAccounting, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getAddLiquidity(uint160 sqrtPriceX96, AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity additions and minted shares are computed␊ + }␊ + ␊ + function _getRemoveLiquidity(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity removals and burned shares are computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc1155 BaseCustomAccounting + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomAccounting} from "@openzeppelin/uniswap-hooks/base/BaseCustomAccounting.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomAccounting, ERC1155 {␊ + constructor() ERC1155("https://example.com/metadata/{id}.json") {}␊ + ␊ + function _getAddLiquidity(uint160 sqrtPriceX96, AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity additions and minted shares are computed␊ + }␊ + ␊ + function _getRemoveLiquidity(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity removals and burned shares are computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc6909 BaseCustomAccounting + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomAccounting} from "@openzeppelin/uniswap-hooks/base/BaseCustomAccounting.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC6909} from "@openzeppelin/contracts/token/ERC6909/draft-ERC6909.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomAccounting, ERC6909 {␊ + function _getAddLiquidity(uint160 sqrtPriceX96, AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity additions and minted shares are computed␊ + }␊ + ␊ + function _getRemoveLiquidity(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (bytes memory, uint256)␊ + {␊ + // Implement how liquidity removals and burned shares are computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## basic BaseCustomCurve + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomCurve} from "@openzeppelin/uniswap-hooks/base/BaseCustomCurve.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomCurve, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getUnspecifiedAmount(SwapParams calldata params)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the unspecified currency amount is computed␊ + }␊ + ␊ + function _getSwapFeeAmount(SwapParams calldata params, uint256 unspecifiedAmount)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the LPs fees amount is computed␊ + }␊ + ␊ + function _getAmountOut(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount out of the swap is computed␊ + }␊ + ␊ + function _getAmountIn(AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount in of the swap is computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## mixed permissions BaseCustomCurve + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomCurve} from "@openzeppelin/uniswap-hooks/base/BaseCustomCurve.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomCurve, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getUnspecifiedAmount(SwapParams calldata params)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the unspecified currency amount is computed␊ + }␊ + ␊ + function _getSwapFeeAmount(SwapParams calldata params, uint256 unspecifiedAmount)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the LPs fees amount is computed␊ + }␊ + ␊ + function _getAmountOut(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount out of the swap is computed␊ + }␊ + ␊ + function _getAmountIn(AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount in of the swap is computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## inversed mixed permissions BaseCustomCurve + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomCurve} from "@openzeppelin/uniswap-hooks/base/BaseCustomCurve.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomCurve, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getUnspecifiedAmount(SwapParams calldata params)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the unspecified currency amount is computed␊ + }␊ + ␊ + function _getSwapFeeAmount(SwapParams calldata params, uint256 unspecifiedAmount)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the LPs fees amount is computed␊ + }␊ + ␊ + function _getAmountOut(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount out of the swap is computed␊ + }␊ + ␊ + function _getAmountIn(AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount in of the swap is computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: false,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## all permissions BaseCustomCurve + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomCurve} from "@openzeppelin/uniswap-hooks/base/BaseCustomCurve.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomCurve, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getUnspecifiedAmount(SwapParams calldata params)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the unspecified currency amount is computed␊ + }␊ + ␊ + function _getSwapFeeAmount(SwapParams calldata params, uint256 unspecifiedAmount)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the LPs fees amount is computed␊ + }␊ + ␊ + function _getAmountOut(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount out of the swap is computed␊ + }␊ + ␊ + function _getAmountIn(AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount in of the swap is computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## currency settler BaseCustomCurve + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomCurve} from "@openzeppelin/uniswap-hooks/base/BaseCustomCurve.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {CurrencySettler} from "@openzeppelin/uniswap-hooks/utils/CurrencySettler.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomCurve, ERC20 {␊ + using CurrencySettler for Currency;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getUnspecifiedAmount(SwapParams calldata params)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the unspecified currency amount is computed␊ + }␊ + ␊ + function _getSwapFeeAmount(SwapParams calldata params, uint256 unspecifiedAmount)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the LPs fees amount is computed␊ + }␊ + ␊ + function _getAmountOut(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount out of the swap is computed␊ + }␊ + ␊ + function _getAmountIn(AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount in of the swap is computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## safeCast BaseCustomCurve + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomCurve} from "@openzeppelin/uniswap-hooks/base/BaseCustomCurve.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomCurve, ERC20 {␊ + using SafeCast for *;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getUnspecifiedAmount(SwapParams calldata params)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the unspecified currency amount is computed␊ + }␊ + ␊ + function _getSwapFeeAmount(SwapParams calldata params, uint256 unspecifiedAmount)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the LPs fees amount is computed␊ + }␊ + ␊ + function _getAmountOut(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount out of the swap is computed␊ + }␊ + ␊ + function _getAmountIn(AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount in of the swap is computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## transient storage BaseCustomCurve + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomCurve} from "@openzeppelin/uniswap-hooks/base/BaseCustomCurve.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SlotDerivation} from "@openzeppelin/contracts/utils/SlotDerivation.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {TransientSlot} from "@openzeppelin/contracts/utils/TransientSlot.sol";␊ + ␊ + contract MyHook is BaseCustomCurve, ERC20 {␊ + using SlotDerivation for bytes32;␊ + using TransientSlot for bytes32;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getUnspecifiedAmount(SwapParams calldata params)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the unspecified currency amount is computed␊ + }␊ + ␊ + function _getSwapFeeAmount(SwapParams calldata params, uint256 unspecifiedAmount)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the LPs fees amount is computed␊ + }␊ + ␊ + function _getAmountOut(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount out of the swap is computed␊ + }␊ + ␊ + function _getAmountIn(AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount in of the swap is computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (ownable) BaseCustomCurve + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomCurve} from "@openzeppelin/uniswap-hooks/base/BaseCustomCurve.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomCurve, Ownable, ERC20 {␊ + constructor(address initialOwner)␊ + Ownable(initialOwner)␊ + ERC20("MyShares", "MSH")␊ + {}␊ + ␊ + function _getUnspecifiedAmount(SwapParams calldata params)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the unspecified currency amount is computed␊ + }␊ + ␊ + function _getSwapFeeAmount(SwapParams calldata params, uint256 unspecifiedAmount)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the LPs fees amount is computed␊ + }␊ + ␊ + function _getAmountOut(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount out of the swap is computed␊ + }␊ + ␊ + function _getAmountIn(AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount in of the swap is computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (roles) BaseCustomCurve + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomCurve} from "@openzeppelin/uniswap-hooks/base/BaseCustomCurve.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomCurve, AccessControl, ERC20 {␊ + constructor(address defaultAdmin) ERC20("MyShares", "MSH") {␊ + _grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);␊ + }␊ + ␊ + function _getUnspecifiedAmount(SwapParams calldata params)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the unspecified currency amount is computed␊ + }␊ + ␊ + function _getSwapFeeAmount(SwapParams calldata params, uint256 unspecifiedAmount)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the LPs fees amount is computed␊ + }␊ + ␊ + function _getAmountOut(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount out of the swap is computed␊ + }␊ + ␊ + function _getAmountIn(AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount in of the swap is computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (managed) BaseCustomCurve + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomCurve} from "@openzeppelin/uniswap-hooks/base/BaseCustomCurve.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomCurve, AccessManaged, ERC20 {␊ + constructor(address initialAuthority)␊ + AccessManaged(initialAuthority)␊ + ERC20("MyShares", "MSH")␊ + {}␊ + ␊ + function _getUnspecifiedAmount(SwapParams calldata params)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the unspecified currency amount is computed␊ + }␊ + ␊ + function _getSwapFeeAmount(SwapParams calldata params, uint256 unspecifiedAmount)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the LPs fees amount is computed␊ + }␊ + ␊ + function _getAmountOut(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount out of the swap is computed␊ + }␊ + ␊ + function _getAmountIn(AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount in of the swap is computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## pausable BaseCustomCurve + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomCurve} from "@openzeppelin/uniswap-hooks/base/BaseCustomCurve.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomCurve, ERC20, Pausable, Ownable {␊ + constructor(address initialOwner)␊ + ERC20("MyShares", "MSH")␊ + Ownable(initialOwner)␊ + {}␊ + ␊ + function _getUnspecifiedAmount(SwapParams calldata params)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the unspecified currency amount is computed␊ + }␊ + ␊ + function _getSwapFeeAmount(SwapParams calldata params, uint256 unspecifiedAmount)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the LPs fees amount is computed␊ + }␊ + ␊ + function _getAmountOut(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount out of the swap is computed␊ + }␊ + ␊ + function _getAmountIn(AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount in of the swap is computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function pause() public onlyOwner {␊ + _pause();␊ + }␊ + ␊ + function unpause() public onlyOwner {␊ + _unpause();␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + return super._beforeSwap(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeDonate(sender, key, amount0, amount1, hookData);␊ + }␊ + ␊ + function addLiquidity(AddLiquidityParams calldata params)␊ + public␊ + payable␊ + override␊ + whenNotPaused␊ + returns (BalanceDelta)␊ + {␊ + return super.addLiquidity(params);␊ + }␊ + ␊ + function removeLiquidity(RemoveLiquidityParams calldata params)␊ + public␊ + override␊ + whenNotPaused␊ + returns (BalanceDelta)␊ + {␊ + return super.removeLiquidity(params);␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc20 BaseCustomCurve + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomCurve} from "@openzeppelin/uniswap-hooks/base/BaseCustomCurve.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomCurve, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getUnspecifiedAmount(SwapParams calldata params)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the unspecified currency amount is computed␊ + }␊ + ␊ + function _getSwapFeeAmount(SwapParams calldata params, uint256 unspecifiedAmount)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the LPs fees amount is computed␊ + }␊ + ␊ + function _getAmountOut(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount out of the swap is computed␊ + }␊ + ␊ + function _getAmountIn(AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount in of the swap is computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc1155 BaseCustomCurve + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomCurve} from "@openzeppelin/uniswap-hooks/base/BaseCustomCurve.sol";␊ + import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomCurve, ERC1155 {␊ + constructor() ERC1155("https://example.com/metadata/{id}.json") {}␊ + ␊ + function _getUnspecifiedAmount(SwapParams calldata params)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the unspecified currency amount is computed␊ + }␊ + ␊ + function _getSwapFeeAmount(SwapParams calldata params, uint256 unspecifiedAmount)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the LPs fees amount is computed␊ + }␊ + ␊ + function _getAmountOut(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount out of the swap is computed␊ + }␊ + ␊ + function _getAmountIn(AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount in of the swap is computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc6909 BaseCustomCurve + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseCustomCurve} from "@openzeppelin/uniswap-hooks/base/BaseCustomCurve.sol";␊ + import {ERC6909} from "@openzeppelin/contracts/token/ERC6909/draft-ERC6909.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseCustomCurve, ERC6909 {␊ + function _getUnspecifiedAmount(SwapParams calldata params)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the unspecified currency amount is computed␊ + }␊ + ␊ + function _getSwapFeeAmount(SwapParams calldata params, uint256 unspecifiedAmount)␊ + internal␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the LPs fees amount is computed␊ + }␊ + ␊ + function _getAmountOut(RemoveLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount out of the swap is computed␊ + }␊ + ␊ + function _getAmountIn(AddLiquidityParams memory params)␊ + internal␊ + override␊ + returns (uint256, uint256, uint256)␊ + {␊ + // Implement how the amount in of the swap is computed␊ + }␊ + ␊ + function _mint(AddLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are minted␊ + }␊ + ␊ + function _burn(RemoveLiquidityParams memory params, BalanceDelta callerDelta, BalanceDelta feesAccrued, uint256 shares)␊ + internal␊ + override␊ + {␊ + // Implement how shares are burned␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## basic BaseDynamicFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseDynamicFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicFee, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getFee(PoolKey calldata key) internal override returns (uint24) {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## mixed permissions BaseDynamicFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseDynamicFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicFee, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getFee(PoolKey calldata key) internal override returns (uint24) {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## inversed mixed permissions BaseDynamicFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseDynamicFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicFee.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicFee, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getFee(PoolKey calldata key) internal override returns (uint24) {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: true,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: false,␊ + afterSwap: true,␊ + beforeDonate: false,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## all permissions BaseDynamicFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseDynamicFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicFee, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getFee(PoolKey calldata key) internal override returns (uint24) {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## currency settler BaseDynamicFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseDynamicFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {CurrencySettler} from "@openzeppelin/uniswap-hooks/utils/CurrencySettler.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicFee, ERC20 {␊ + using CurrencySettler for Currency;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getFee(PoolKey calldata key) internal override returns (uint24) {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## safeCast BaseDynamicFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseDynamicFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicFee, ERC20 {␊ + using SafeCast for *;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getFee(PoolKey calldata key) internal override returns (uint24) {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## transient storage BaseDynamicFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseDynamicFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SlotDerivation} from "@openzeppelin/contracts/utils/SlotDerivation.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {TransientSlot} from "@openzeppelin/contracts/utils/TransientSlot.sol";␊ + ␊ + contract MyHook is BaseDynamicFee, ERC20 {␊ + using SlotDerivation for bytes32;␊ + using TransientSlot for bytes32;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getFee(PoolKey calldata key) internal override returns (uint24) {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (ownable) BaseDynamicFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseDynamicFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicFee, Ownable, ERC20 {␊ + constructor(address initialOwner)␊ + Ownable(initialOwner)␊ + ERC20("MyShares", "MSH")␊ + {}␊ + ␊ + function _getFee(PoolKey calldata key) internal override returns (uint24) {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (roles) BaseDynamicFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";␊ + import {BaseDynamicFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicFee, AccessControl, ERC20 {␊ + constructor(address defaultAdmin) ERC20("MyShares", "MSH") {␊ + _grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);␊ + }␊ + ␊ + function _getFee(PoolKey calldata key) internal override returns (uint24) {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (managed) BaseDynamicFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol";␊ + import {BaseDynamicFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicFee, AccessManaged, ERC20 {␊ + constructor(address initialAuthority)␊ + AccessManaged(initialAuthority)␊ + ERC20("MyShares", "MSH")␊ + {}␊ + ␊ + function _getFee(PoolKey calldata key) internal override returns (uint24) {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## pausable BaseDynamicFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseDynamicFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicFee, ERC20, Pausable, Ownable {␊ + constructor(address initialOwner)␊ + ERC20("MyShares", "MSH")␊ + Ownable(initialOwner)␊ + {}␊ + ␊ + function _getFee(PoolKey calldata key) internal override returns (uint24) {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function pause() public onlyOwner {␊ + _pause();␊ + }␊ + ␊ + function unpause() public onlyOwner {␊ + _unpause();␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeAddLiquidity(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeRemoveLiquidity(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + return super._beforeSwap(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeDonate(sender, key, amount0, amount1, hookData);␊ + }␊ + ␊ + function poke(PoolKey calldata key) public override whenNotPaused {␊ + return super.poke(key);␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc20 BaseDynamicFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseDynamicFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicFee, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getFee(PoolKey calldata key) internal override returns (uint24) {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc1155 BaseDynamicFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseDynamicFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicFee, ERC1155 {␊ + constructor() ERC1155("https://example.com/metadata/{id}.json") {}␊ + ␊ + function _getFee(PoolKey calldata key) internal override returns (uint24) {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc6909 BaseDynamicFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseDynamicFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC6909} from "@openzeppelin/contracts/token/ERC6909/draft-ERC6909.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicFee, ERC6909 {␊ + function _getFee(PoolKey calldata key) internal override returns (uint24) {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## basic BaseOverrideFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseOverrideFee} from "@openzeppelin/uniswap-hooks/fee/BaseOverrideFee.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseOverrideFee, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getFee(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## mixed permissions BaseOverrideFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseOverrideFee} from "@openzeppelin/uniswap-hooks/fee/BaseOverrideFee.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseOverrideFee, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getFee(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## inversed mixed permissions BaseOverrideFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseOverrideFee} from "@openzeppelin/uniswap-hooks/fee/BaseOverrideFee.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseOverrideFee, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getFee(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: false,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## all permissions BaseOverrideFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseOverrideFee} from "@openzeppelin/uniswap-hooks/fee/BaseOverrideFee.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseOverrideFee, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getFee(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## currency settler BaseOverrideFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseOverrideFee} from "@openzeppelin/uniswap-hooks/fee/BaseOverrideFee.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {CurrencySettler} from "@openzeppelin/uniswap-hooks/utils/CurrencySettler.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseOverrideFee, ERC20 {␊ + using CurrencySettler for Currency;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getFee(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## safeCast BaseOverrideFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseOverrideFee} from "@openzeppelin/uniswap-hooks/fee/BaseOverrideFee.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseOverrideFee, ERC20 {␊ + using SafeCast for *;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getFee(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## transient storage BaseOverrideFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseOverrideFee} from "@openzeppelin/uniswap-hooks/fee/BaseOverrideFee.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SlotDerivation} from "@openzeppelin/contracts/utils/SlotDerivation.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {TransientSlot} from "@openzeppelin/contracts/utils/TransientSlot.sol";␊ + ␊ + contract MyHook is BaseOverrideFee, ERC20 {␊ + using SlotDerivation for bytes32;␊ + using TransientSlot for bytes32;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getFee(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (ownable) BaseOverrideFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseOverrideFee} from "@openzeppelin/uniswap-hooks/fee/BaseOverrideFee.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseOverrideFee, Ownable, ERC20 {␊ + constructor(address initialOwner)␊ + Ownable(initialOwner)␊ + ERC20("MyShares", "MSH")␊ + {}␊ + ␊ + function _getFee(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (roles) BaseOverrideFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";␊ + import {BaseOverrideFee} from "@openzeppelin/uniswap-hooks/fee/BaseOverrideFee.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseOverrideFee, AccessControl, ERC20 {␊ + constructor(address defaultAdmin) ERC20("MyShares", "MSH") {␊ + _grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);␊ + }␊ + ␊ + function _getFee(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (managed) BaseOverrideFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol";␊ + import {BaseOverrideFee} from "@openzeppelin/uniswap-hooks/fee/BaseOverrideFee.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseOverrideFee, AccessManaged, ERC20 {␊ + constructor(address initialAuthority)␊ + AccessManaged(initialAuthority)␊ + ERC20("MyShares", "MSH")␊ + {}␊ + ␊ + function _getFee(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## pausable BaseOverrideFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseOverrideFee} from "@openzeppelin/uniswap-hooks/fee/BaseOverrideFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseOverrideFee, ERC20, Pausable, Ownable {␊ + constructor(address initialOwner)␊ + ERC20("MyShares", "MSH")␊ + Ownable(initialOwner)␊ + {}␊ + ␊ + function _getFee(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function pause() public onlyOwner {␊ + _pause();␊ + }␊ + ␊ + function unpause() public onlyOwner {␊ + _unpause();␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeAddLiquidity(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeRemoveLiquidity(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + return super._beforeSwap(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeDonate(sender, key, amount0, amount1, hookData);␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc20 BaseOverrideFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseOverrideFee} from "@openzeppelin/uniswap-hooks/fee/BaseOverrideFee.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseOverrideFee, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getFee(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc1155 BaseOverrideFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseOverrideFee} from "@openzeppelin/uniswap-hooks/fee/BaseOverrideFee.sol";␊ + import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseOverrideFee, ERC1155 {␊ + constructor() ERC1155("https://example.com/metadata/{id}.json") {}␊ + ␊ + function _getFee(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc6909 BaseOverrideFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BaseOverrideFee} from "@openzeppelin/uniswap-hooks/fee/BaseOverrideFee.sol";␊ + import {ERC6909} from "@openzeppelin/contracts/token/ERC6909/draft-ERC6909.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseOverrideFee, ERC6909 {␊ + function _getFee(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the LP fee is computed␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## basic BaseDynamicAfterFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseDynamicAfterFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicAfterFee.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicAfterFee, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getTargetUnspecified(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint256, bool)␊ + {␊ + // Implement how the target unspecified amount is computed␊ + }␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## mixed permissions BaseDynamicAfterFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseDynamicAfterFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicAfterFee.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicAfterFee, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getTargetUnspecified(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint256, bool)␊ + {␊ + // Implement how the target unspecified amount is computed␊ + }␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## inversed mixed permissions BaseDynamicAfterFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseDynamicAfterFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicAfterFee.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicAfterFee, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getTargetUnspecified(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint256, bool)␊ + {␊ + // Implement how the target unspecified amount is computed␊ + }␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees are handled after swaps␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: true,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: false,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## all permissions BaseDynamicAfterFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseDynamicAfterFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicAfterFee.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicAfterFee, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getTargetUnspecified(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint256, bool)␊ + {␊ + // Implement how the target unspecified amount is computed␊ + }␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## currency settler BaseDynamicAfterFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseDynamicAfterFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicAfterFee.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {CurrencySettler} from "@openzeppelin/uniswap-hooks/utils/CurrencySettler.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicAfterFee, ERC20 {␊ + using CurrencySettler for Currency;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getTargetUnspecified(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint256, bool)␊ + {␊ + // Implement how the target unspecified amount is computed␊ + }␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## safeCast BaseDynamicAfterFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseDynamicAfterFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicAfterFee.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicAfterFee, ERC20 {␊ + using SafeCast for *;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getTargetUnspecified(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint256, bool)␊ + {␊ + // Implement how the target unspecified amount is computed␊ + }␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## transient storage BaseDynamicAfterFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseDynamicAfterFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicAfterFee.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SlotDerivation} from "@openzeppelin/contracts/utils/SlotDerivation.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {TransientSlot} from "@openzeppelin/contracts/utils/TransientSlot.sol";␊ + ␊ + contract MyHook is BaseDynamicAfterFee, ERC20 {␊ + using SlotDerivation for bytes32;␊ + using TransientSlot for bytes32;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getTargetUnspecified(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint256, bool)␊ + {␊ + // Implement how the target unspecified amount is computed␊ + }␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (ownable) BaseDynamicAfterFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseDynamicAfterFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicAfterFee.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicAfterFee, Ownable, ERC20 {␊ + constructor(address initialOwner)␊ + Ownable(initialOwner)␊ + ERC20("MyShares", "MSH")␊ + {}␊ + ␊ + function _getTargetUnspecified(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint256, bool)␊ + {␊ + // Implement how the target unspecified amount is computed␊ + }␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (roles) BaseDynamicAfterFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseDynamicAfterFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicAfterFee.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicAfterFee, AccessControl, ERC20 {␊ + constructor(address defaultAdmin) ERC20("MyShares", "MSH") {␊ + _grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);␊ + }␊ + ␊ + function _getTargetUnspecified(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint256, bool)␊ + {␊ + // Implement how the target unspecified amount is computed␊ + }␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (managed) BaseDynamicAfterFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseDynamicAfterFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicAfterFee.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicAfterFee, AccessManaged, ERC20 {␊ + constructor(address initialAuthority)␊ + AccessManaged(initialAuthority)␊ + ERC20("MyShares", "MSH")␊ + {}␊ + ␊ + function _getTargetUnspecified(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint256, bool)␊ + {␊ + // Implement how the target unspecified amount is computed␊ + }␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## pausable BaseDynamicAfterFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseDynamicAfterFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicAfterFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicAfterFee, ERC20, Pausable, Ownable {␊ + constructor(address initialOwner)␊ + ERC20("MyShares", "MSH")␊ + Ownable(initialOwner)␊ + {}␊ + ␊ + function _getTargetUnspecified(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint256, bool)␊ + {␊ + // Implement how the target unspecified amount is computed␊ + }␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees are handled after swaps␊ + }␊ + ␊ + function pause() public onlyOwner {␊ + _pause();␊ + }␊ + ␊ + function unpause() public onlyOwner {␊ + _unpause();␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeAddLiquidity(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeRemoveLiquidity(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + return super._beforeSwap(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeDonate(sender, key, amount0, amount1, hookData);␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc20 BaseDynamicAfterFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseDynamicAfterFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicAfterFee.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicAfterFee, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getTargetUnspecified(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint256, bool)␊ + {␊ + // Implement how the target unspecified amount is computed␊ + }␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc1155 BaseDynamicAfterFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseDynamicAfterFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicAfterFee.sol";␊ + import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicAfterFee, ERC1155 {␊ + constructor() ERC1155("https://example.com/metadata/{id}.json") {}␊ + ␊ + function _getTargetUnspecified(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint256, bool)␊ + {␊ + // Implement how the target unspecified amount is computed␊ + }␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc6909 BaseDynamicAfterFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseDynamicAfterFee} from "@openzeppelin/uniswap-hooks/fee/BaseDynamicAfterFee.sol";␊ + import {ERC6909} from "@openzeppelin/contracts/token/ERC6909/draft-ERC6909.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseDynamicAfterFee, ERC6909 {␊ + function _getTargetUnspecified(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (uint256, bool)␊ + {␊ + // Implement how the target unspecified amount is computed␊ + }␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## basic BaseHookFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseHookFee} from "@openzeppelin/uniswap-hooks/fee/BaseHookFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseHookFee, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getHookFee(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + view␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the Hook fee is computed␊ + }␊ + ␊ + function handleHookFees(Currency[] memory currencies) public override {␊ + // Implement how the accumulated hook fees are handled␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## mixed permissions BaseHookFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseHookFee} from "@openzeppelin/uniswap-hooks/fee/BaseHookFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseHookFee, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getHookFee(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + view␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the Hook fee is computed␊ + }␊ + ␊ + function handleHookFees(Currency[] memory currencies) public override {␊ + // Implement how the accumulated hook fees are handled␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## inversed mixed permissions BaseHookFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseHookFee} from "@openzeppelin/uniswap-hooks/fee/BaseHookFee.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseHookFee, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getHookFee(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + view␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the Hook fee is computed␊ + }␊ + ␊ + function handleHookFees(Currency[] memory currencies) public override {␊ + // Implement how the accumulated hook fees are handled␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: true,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: false,␊ + afterSwap: true,␊ + beforeDonate: false,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## all permissions BaseHookFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseHookFee} from "@openzeppelin/uniswap-hooks/fee/BaseHookFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseHookFee, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getHookFee(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + view␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the Hook fee is computed␊ + }␊ + ␊ + function handleHookFees(Currency[] memory currencies) public override {␊ + // Implement how the accumulated hook fees are handled␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## currency settler BaseHookFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseHookFee} from "@openzeppelin/uniswap-hooks/fee/BaseHookFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {CurrencySettler} from "@openzeppelin/uniswap-hooks/utils/CurrencySettler.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseHookFee, ERC20 {␊ + using CurrencySettler for Currency;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getHookFee(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + view␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the Hook fee is computed␊ + }␊ + ␊ + function handleHookFees(Currency[] memory currencies) public override {␊ + // Implement how the accumulated hook fees are handled␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## safeCast BaseHookFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseHookFee} from "@openzeppelin/uniswap-hooks/fee/BaseHookFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseHookFee, ERC20 {␊ + using SafeCast for *;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getHookFee(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + view␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the Hook fee is computed␊ + }␊ + ␊ + function handleHookFees(Currency[] memory currencies) public override {␊ + // Implement how the accumulated hook fees are handled␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## transient storage BaseHookFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseHookFee} from "@openzeppelin/uniswap-hooks/fee/BaseHookFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SlotDerivation} from "@openzeppelin/contracts/utils/SlotDerivation.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {TransientSlot} from "@openzeppelin/contracts/utils/TransientSlot.sol";␊ + ␊ + contract MyHook is BaseHookFee, ERC20 {␊ + using SlotDerivation for bytes32;␊ + using TransientSlot for bytes32;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getHookFee(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + view␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the Hook fee is computed␊ + }␊ + ␊ + function handleHookFees(Currency[] memory currencies) public override {␊ + // Implement how the accumulated hook fees are handled␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (ownable) BaseHookFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseHookFee} from "@openzeppelin/uniswap-hooks/fee/BaseHookFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseHookFee, Ownable, ERC20 {␊ + constructor(address initialOwner)␊ + Ownable(initialOwner)␊ + ERC20("MyShares", "MSH")␊ + {}␊ + ␊ + function _getHookFee(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + view␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the Hook fee is computed␊ + }␊ + ␊ + function handleHookFees(Currency[] memory currencies) public override {␊ + // Implement how the accumulated hook fees are handled␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (roles) BaseHookFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseHookFee} from "@openzeppelin/uniswap-hooks/fee/BaseHookFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseHookFee, AccessControl, ERC20 {␊ + constructor(address defaultAdmin) ERC20("MyShares", "MSH") {␊ + _grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);␊ + }␊ + ␊ + function _getHookFee(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + view␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the Hook fee is computed␊ + }␊ + ␊ + function handleHookFees(Currency[] memory currencies) public override {␊ + // Implement how the accumulated hook fees are handled␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (managed) BaseHookFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseHookFee} from "@openzeppelin/uniswap-hooks/fee/BaseHookFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseHookFee, AccessManaged, ERC20 {␊ + constructor(address initialAuthority)␊ + AccessManaged(initialAuthority)␊ + ERC20("MyShares", "MSH")␊ + {}␊ + ␊ + function _getHookFee(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + view␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the Hook fee is computed␊ + }␊ + ␊ + function handleHookFees(Currency[] memory currencies) public override {␊ + // Implement how the accumulated hook fees are handled␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## pausable BaseHookFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseHookFee} from "@openzeppelin/uniswap-hooks/fee/BaseHookFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseHookFee, ERC20, Pausable, Ownable {␊ + constructor(address initialOwner)␊ + ERC20("MyShares", "MSH")␊ + Ownable(initialOwner)␊ + {}␊ + ␊ + function _getHookFee(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + view␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the Hook fee is computed␊ + }␊ + ␊ + function handleHookFees(Currency[] memory currencies)␊ + public␊ + override␊ + whenNotPaused␊ + {␊ + // Implement how the accumulated hook fees are handled␊ + }␊ + ␊ + function pause() public onlyOwner {␊ + _pause();␊ + }␊ + ␊ + function unpause() public onlyOwner {␊ + _unpause();␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeAddLiquidity(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeRemoveLiquidity(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + return super._beforeSwap(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeDonate(sender, key, amount0, amount1, hookData);␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc20 BaseHookFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseHookFee} from "@openzeppelin/uniswap-hooks/fee/BaseHookFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseHookFee, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _getHookFee(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + view␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the Hook fee is computed␊ + }␊ + ␊ + function handleHookFees(Currency[] memory currencies) public override {␊ + // Implement how the accumulated hook fees are handled␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc1155 BaseHookFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseHookFee} from "@openzeppelin/uniswap-hooks/fee/BaseHookFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseHookFee, ERC1155 {␊ + constructor() ERC1155("https://example.com/metadata/{id}.json") {}␊ + ␊ + function _getHookFee(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + view␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the Hook fee is computed␊ + }␊ + ␊ + function handleHookFees(Currency[] memory currencies) public override {␊ + // Implement how the accumulated hook fees are handled␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc6909 BaseHookFee + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BaseHookFee} from "@openzeppelin/uniswap-hooks/fee/BaseHookFee.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC6909} from "@openzeppelin/contracts/token/ERC6909/draft-ERC6909.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is BaseHookFee, ERC6909 {␊ + function _getHookFee(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + view␊ + override␊ + returns (uint24)␊ + {␊ + // Implement how the Hook fee is computed␊ + }␊ + ␊ + function handleHookFees(Currency[] memory currencies) public override {␊ + // Implement how the accumulated hook fees are handled␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## basic AntiSandwichHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AntiSandwichHook} from "@openzeppelin/uniswap-hooks/general/AntiSandwichHook.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is AntiSandwichHook, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees from sandwich attacks are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## mixed permissions AntiSandwichHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AntiSandwichHook} from "@openzeppelin/uniswap-hooks/general/AntiSandwichHook.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is AntiSandwichHook, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees from sandwich attacks are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## inversed mixed permissions AntiSandwichHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AntiSandwichHook} from "@openzeppelin/uniswap-hooks/general/AntiSandwichHook.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is AntiSandwichHook, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees from sandwich attacks are handled after swaps␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: true,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: false,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## all permissions AntiSandwichHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AntiSandwichHook} from "@openzeppelin/uniswap-hooks/general/AntiSandwichHook.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is AntiSandwichHook, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees from sandwich attacks are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## currency settler AntiSandwichHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AntiSandwichHook} from "@openzeppelin/uniswap-hooks/general/AntiSandwichHook.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {CurrencySettler} from "@openzeppelin/uniswap-hooks/utils/CurrencySettler.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is AntiSandwichHook, ERC20 {␊ + using CurrencySettler for Currency;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees from sandwich attacks are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## safeCast AntiSandwichHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AntiSandwichHook} from "@openzeppelin/uniswap-hooks/general/AntiSandwichHook.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is AntiSandwichHook, ERC20 {␊ + using SafeCast for *;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees from sandwich attacks are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## transient storage AntiSandwichHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AntiSandwichHook} from "@openzeppelin/uniswap-hooks/general/AntiSandwichHook.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SlotDerivation} from "@openzeppelin/contracts/utils/SlotDerivation.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {TransientSlot} from "@openzeppelin/contracts/utils/TransientSlot.sol";␊ + ␊ + contract MyHook is AntiSandwichHook, ERC20 {␊ + using SlotDerivation for bytes32;␊ + using TransientSlot for bytes32;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees from sandwich attacks are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (ownable) AntiSandwichHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AntiSandwichHook} from "@openzeppelin/uniswap-hooks/general/AntiSandwichHook.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is AntiSandwichHook, Ownable, ERC20 {␊ + constructor(address initialOwner)␊ + Ownable(initialOwner)␊ + ERC20("MyShares", "MSH")␊ + {}␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees from sandwich attacks are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (roles) AntiSandwichHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";␊ + import {AntiSandwichHook} from "@openzeppelin/uniswap-hooks/general/AntiSandwichHook.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is AntiSandwichHook, AccessControl, ERC20 {␊ + constructor(address defaultAdmin) ERC20("MyShares", "MSH") {␊ + _grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);␊ + }␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees from sandwich attacks are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## access control (managed) AntiSandwichHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol";␊ + import {AntiSandwichHook} from "@openzeppelin/uniswap-hooks/general/AntiSandwichHook.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is AntiSandwichHook, AccessManaged, ERC20 {␊ + constructor(address initialAuthority)␊ + AccessManaged(initialAuthority)␊ + ERC20("MyShares", "MSH")␊ + {}␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees from sandwich attacks are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## pausable AntiSandwichHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AntiSandwichHook} from "@openzeppelin/uniswap-hooks/general/AntiSandwichHook.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is AntiSandwichHook, ERC20, Pausable, Ownable {␊ + constructor(address initialOwner)␊ + ERC20("MyShares", "MSH")␊ + Ownable(initialOwner)␊ + {}␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees from sandwich attacks are handled after swaps␊ + }␊ + ␊ + function pause() public onlyOwner {␊ + _pause();␊ + }␊ + ␊ + function unpause() public onlyOwner {␊ + _unpause();␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeAddLiquidity(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeRemoveLiquidity(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + return super._beforeSwap(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeDonate(sender, key, amount0, amount1, hookData);␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc20 AntiSandwichHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AntiSandwichHook} from "@openzeppelin/uniswap-hooks/general/AntiSandwichHook.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is AntiSandwichHook, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees from sandwich attacks are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc1155 AntiSandwichHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AntiSandwichHook} from "@openzeppelin/uniswap-hooks/general/AntiSandwichHook.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is AntiSandwichHook, ERC1155 {␊ + constructor() ERC1155("https://example.com/metadata/{id}.json") {}␊ + ␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees from sandwich attacks are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## shares erc6909 AntiSandwichHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AntiSandwichHook} from "@openzeppelin/uniswap-hooks/general/AntiSandwichHook.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {ERC6909} from "@openzeppelin/contracts/token/ERC6909/draft-ERC6909.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is AntiSandwichHook, ERC6909 {␊ + function _afterSwapHandler(PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, uint256 targetUnspecifiedAmount, uint256 feeAmount)␊ + internal␊ + override␊ + {␊ + // Implement how the accumulated penalty fees from sandwich attacks are handled after swaps␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## basic LiquidityPenaltyHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LiquidityPenaltyHook} from "@openzeppelin/uniswap-hooks/general/LiquidityPenaltyHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LiquidityPenaltyHook, ERC20 {␊ + constructor() LiquidityPenaltyHook(10) ERC20("MyShares", "MSH") {}␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## mixed permissions LiquidityPenaltyHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LiquidityPenaltyHook} from "@openzeppelin/uniswap-hooks/general/LiquidityPenaltyHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LiquidityPenaltyHook, ERC20 {␊ + constructor() LiquidityPenaltyHook(10) ERC20("MyShares", "MSH") {}␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: false,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## inversed mixed permissions LiquidityPenaltyHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LiquidityPenaltyHook} from "@openzeppelin/uniswap-hooks/general/LiquidityPenaltyHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LiquidityPenaltyHook, ERC20 {␊ + constructor() LiquidityPenaltyHook(10) ERC20("MyShares", "MSH") {}␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: true,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: false,␊ + afterSwap: true,␊ + beforeDonate: false,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## all permissions LiquidityPenaltyHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LiquidityPenaltyHook} from "@openzeppelin/uniswap-hooks/general/LiquidityPenaltyHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LiquidityPenaltyHook, ERC20 {␊ + constructor() LiquidityPenaltyHook(10) ERC20("MyShares", "MSH") {}␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## currency settler LiquidityPenaltyHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {CurrencySettler} from "@openzeppelin/uniswap-hooks/utils/CurrencySettler.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LiquidityPenaltyHook} from "@openzeppelin/uniswap-hooks/general/LiquidityPenaltyHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LiquidityPenaltyHook, ERC20 {␊ + using CurrencySettler for Currency;␊ + ␊ + constructor() LiquidityPenaltyHook(10) ERC20("MyShares", "MSH") {}␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## safeCast LiquidityPenaltyHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LiquidityPenaltyHook} from "@openzeppelin/uniswap-hooks/general/LiquidityPenaltyHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LiquidityPenaltyHook, ERC20 {␊ + using SafeCast for *;␊ + ␊ + constructor() LiquidityPenaltyHook(10) ERC20("MyShares", "MSH") {}␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## transient storage LiquidityPenaltyHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LiquidityPenaltyHook} from "@openzeppelin/uniswap-hooks/general/LiquidityPenaltyHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SlotDerivation} from "@openzeppelin/contracts/utils/SlotDerivation.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {TransientSlot} from "@openzeppelin/contracts/utils/TransientSlot.sol";␊ + ␊ + contract MyHook is LiquidityPenaltyHook, ERC20 {␊ + using SlotDerivation for bytes32;␊ + using TransientSlot for bytes32;␊ + ␊ + constructor() LiquidityPenaltyHook(10) ERC20("MyShares", "MSH") {}␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## access control (ownable) LiquidityPenaltyHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LiquidityPenaltyHook} from "@openzeppelin/uniswap-hooks/general/LiquidityPenaltyHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LiquidityPenaltyHook, Ownable, ERC20 {␊ + constructor(address initialOwner)␊ + LiquidityPenaltyHook(10)␊ + Ownable(initialOwner)␊ + ERC20("MyShares", "MSH")␊ + {}␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## access control (roles) LiquidityPenaltyHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LiquidityPenaltyHook} from "@openzeppelin/uniswap-hooks/general/LiquidityPenaltyHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LiquidityPenaltyHook, AccessControl, ERC20 {␊ + constructor(address defaultAdmin)␊ + LiquidityPenaltyHook(10)␊ + ERC20("MyShares", "MSH")␊ + {␊ + _grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## access control (managed) LiquidityPenaltyHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LiquidityPenaltyHook} from "@openzeppelin/uniswap-hooks/general/LiquidityPenaltyHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LiquidityPenaltyHook, AccessManaged, ERC20 {␊ + constructor(address initialAuthority)␊ + LiquidityPenaltyHook(10)␊ + AccessManaged(initialAuthority)␊ + ERC20("MyShares", "MSH")␊ + {}␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## pausable LiquidityPenaltyHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LiquidityPenaltyHook} from "@openzeppelin/uniswap-hooks/general/LiquidityPenaltyHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LiquidityPenaltyHook, ERC20, Pausable, Ownable {␊ + constructor(address initialOwner)␊ + LiquidityPenaltyHook(10)␊ + ERC20("MyShares", "MSH")␊ + Ownable(initialOwner)␊ + {}␊ + ␊ + function pause() public onlyOwner {␊ + _pause();␊ + }␊ + ␊ + function unpause() public onlyOwner {␊ + _unpause();␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeAddLiquidity(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeRemoveLiquidity(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + return super._beforeSwap(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeDonate(sender, key, amount0, amount1, hookData);␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## shares erc20 LiquidityPenaltyHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LiquidityPenaltyHook} from "@openzeppelin/uniswap-hooks/general/LiquidityPenaltyHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LiquidityPenaltyHook, ERC20 {␊ + constructor() LiquidityPenaltyHook(10) ERC20("MyShares", "MSH") {}␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## shares erc1155 LiquidityPenaltyHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LiquidityPenaltyHook} from "@openzeppelin/uniswap-hooks/general/LiquidityPenaltyHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LiquidityPenaltyHook, ERC1155 {␊ + constructor()␊ + LiquidityPenaltyHook(10)␊ + ERC1155("https://example.com/metadata/{id}.json")␊ + {}␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## shares erc6909 LiquidityPenaltyHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC6909} from "@openzeppelin/contracts/token/ERC6909/draft-ERC6909.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LiquidityPenaltyHook} from "@openzeppelin/uniswap-hooks/general/LiquidityPenaltyHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LiquidityPenaltyHook, ERC6909 {␊ + constructor() LiquidityPenaltyHook(10) {}␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _afterSwap(address sender, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, int128)␊ + {␊ + // Implement __afterSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## basic LimitOrderHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LimitOrderHook} from "@openzeppelin/uniswap-hooks/general/LimitOrderHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LimitOrderHook, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## mixed permissions LimitOrderHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LimitOrderHook} from "@openzeppelin/uniswap-hooks/general/LimitOrderHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LimitOrderHook, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## inversed mixed permissions LimitOrderHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LimitOrderHook} from "@openzeppelin/uniswap-hooks/general/LimitOrderHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + ␊ + contract MyHook is LimitOrderHook, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: false,␊ + afterInitialize: true,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: false,␊ + afterSwap: true,␊ + beforeDonate: false,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## all permissions LimitOrderHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LimitOrderHook} from "@openzeppelin/uniswap-hooks/general/LimitOrderHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LimitOrderHook, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## currency settler LimitOrderHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {CurrencySettler} from "@openzeppelin/uniswap-hooks/utils/CurrencySettler.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LimitOrderHook} from "@openzeppelin/uniswap-hooks/general/LimitOrderHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LimitOrderHook, ERC20 {␊ + using CurrencySettler for Currency;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## safeCast LimitOrderHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LimitOrderHook} from "@openzeppelin/uniswap-hooks/general/LimitOrderHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LimitOrderHook, ERC20 {␊ + using SafeCast for *;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## transient storage LimitOrderHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LimitOrderHook} from "@openzeppelin/uniswap-hooks/general/LimitOrderHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SlotDerivation} from "@openzeppelin/contracts/utils/SlotDerivation.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {TransientSlot} from "@openzeppelin/contracts/utils/TransientSlot.sol";␊ + ␊ + contract MyHook is LimitOrderHook, ERC20 {␊ + using SlotDerivation for bytes32;␊ + using TransientSlot for bytes32;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## access control (ownable) LimitOrderHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LimitOrderHook} from "@openzeppelin/uniswap-hooks/general/LimitOrderHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LimitOrderHook, Ownable, ERC20 {␊ + constructor(address initialOwner)␊ + Ownable(initialOwner)␊ + ERC20("MyShares", "MSH")␊ + {}␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## access control (roles) LimitOrderHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LimitOrderHook} from "@openzeppelin/uniswap-hooks/general/LimitOrderHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LimitOrderHook, AccessControl, ERC20 {␊ + constructor(address defaultAdmin) ERC20("MyShares", "MSH") {␊ + _grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## access control (managed) LimitOrderHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LimitOrderHook} from "@openzeppelin/uniswap-hooks/general/LimitOrderHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LimitOrderHook, AccessManaged, ERC20 {␊ + constructor(address initialAuthority)␊ + AccessManaged(initialAuthority)␊ + ERC20("MyShares", "MSH")␊ + {}␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## pausable LimitOrderHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LimitOrderHook} from "@openzeppelin/uniswap-hooks/general/LimitOrderHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {OrderIdLibrary} from "@openzeppelin/uniswap-hooks/general/LimitOrderHook.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LimitOrderHook, ERC20, Pausable, Ownable {␊ + constructor(address initialOwner)␊ + ERC20("MyShares", "MSH")␊ + Ownable(initialOwner)␊ + {}␊ + ␊ + function pause() public onlyOwner {␊ + _pause();␊ + }␊ + ␊ + function unpause() public onlyOwner {␊ + _unpause();␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeAddLiquidity(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeRemoveLiquidity(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + return super._beforeSwap(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeDonate(sender, key, amount0, amount1, hookData);␊ + }␊ + ␊ + function placeOrder(PoolKey calldata key, int24 tick, bool zeroForOne, uint128 liquidity)␊ + public␊ + override␊ + whenNotPaused␊ + {␊ + return super.placeOrder(key, tick, zeroForOne, liquidity);␊ + }␊ + ␊ + function cancelOrder(PoolKey calldata key, int24 tickLower, bool zeroForOne, address to)␊ + public␊ + override␊ + whenNotPaused␊ + {␊ + return super.cancelOrder(key, tickLower, zeroForOne, to);␊ + }␊ + ␊ + function withdraw(OrderIdLibrary.OrderId orderId, address to)␊ + public␊ + override␊ + whenNotPaused␊ + returns (uint256, uint256)␊ + {␊ + return super.withdraw(orderId, to);␊ + }␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## shares erc20 LimitOrderHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LimitOrderHook} from "@openzeppelin/uniswap-hooks/general/LimitOrderHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LimitOrderHook, ERC20 {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## shares erc1155 LimitOrderHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LimitOrderHook} from "@openzeppelin/uniswap-hooks/general/LimitOrderHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LimitOrderHook, ERC1155 {␊ + constructor() ERC1155("https://example.com/metadata/{id}.json") {}␊ + ␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## shares erc6909 LimitOrderHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {ERC6909} from "@openzeppelin/contracts/token/ERC6909/draft-ERC6909.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {LimitOrderHook} from "@openzeppelin/uniswap-hooks/general/LimitOrderHook.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is LimitOrderHook, ERC6909 {␊ + function _beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + // Implement __beforeSwap␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## basic ReHypothecationHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {ReHypothecationHook} from "@openzeppelin/uniswap-hooks/general/ReHypothecationHook.sol";␊ + ␊ + contract MyHook is ReHypothecationHook {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function getCurrencyYieldSource(Currency currency)␊ + public␊ + view␊ + override␊ + returns (address)␊ + {␊ + // Implement how the yield source address is computed for a given currency␊ + }␊ + ␊ + function _depositToYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is deposited to it's corresponding yield source␊ + }␊ + ␊ + function _withdrawFromYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is withdrawn from it's corresponding yield source␊ + }␊ + ␊ + function _getAmountInYieldSource(Currency currency)␊ + internal␊ + view␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the hook's balance of a given currency in it's corresponding yield source is obtained␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## mixed permissions ReHypothecationHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {ReHypothecationHook} from "@openzeppelin/uniswap-hooks/general/ReHypothecationHook.sol";␊ + ␊ + contract MyHook is ReHypothecationHook {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function getCurrencyYieldSource(Currency currency)␊ + public␊ + view␊ + override␊ + returns (address)␊ + {␊ + // Implement how the yield source address is computed for a given currency␊ + }␊ + ␊ + function _depositToYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is deposited to it's corresponding yield source␊ + }␊ + ␊ + function _withdrawFromYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is withdrawn from it's corresponding yield source␊ + }␊ + ␊ + function _getAmountInYieldSource(Currency currency)␊ + internal␊ + view␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the hook's balance of a given currency in it's corresponding yield source is obtained␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: false,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: false,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: false,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: false,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: false␊ + });␊ + }␊ + }␊ + ` + +## inversed mixed permissions ReHypothecationHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {ReHypothecationHook} from "@openzeppelin/uniswap-hooks/general/ReHypothecationHook.sol";␊ + ␊ + contract MyHook is ReHypothecationHook {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function getCurrencyYieldSource(Currency currency)␊ + public␊ + view␊ + override␊ + returns (address)␊ + {␊ + // Implement how the yield source address is computed for a given currency␊ + }␊ + ␊ + function _depositToYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is deposited to it's corresponding yield source␊ + }␊ + ␊ + function _withdrawFromYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is withdrawn from it's corresponding yield source␊ + }␊ + ␊ + function _getAmountInYieldSource(Currency currency)␊ + internal␊ + view␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the hook's balance of a given currency in it's corresponding yield source is obtained␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: false,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: false,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: false,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: false,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: false,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## all permissions ReHypothecationHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {ReHypothecationHook} from "@openzeppelin/uniswap-hooks/general/ReHypothecationHook.sol";␊ + ␊ + contract MyHook is ReHypothecationHook {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function getCurrencyYieldSource(Currency currency)␊ + public␊ + view␊ + override␊ + returns (address)␊ + {␊ + // Implement how the yield source address is computed for a given currency␊ + }␊ + ␊ + function _depositToYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is deposited to it's corresponding yield source␊ + }␊ + ␊ + function _withdrawFromYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is withdrawn from it's corresponding yield source␊ + }␊ + ␊ + function _getAmountInYieldSource(Currency currency)␊ + internal␊ + view␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the hook's balance of a given currency in it's corresponding yield source is obtained␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function _afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: true,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## currency settler ReHypothecationHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {CurrencySettler} from "@openzeppelin/uniswap-hooks/utils/CurrencySettler.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {ReHypothecationHook} from "@openzeppelin/uniswap-hooks/general/ReHypothecationHook.sol";␊ + ␊ + contract MyHook is ReHypothecationHook {␊ + using CurrencySettler for Currency;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function getCurrencyYieldSource(Currency currency)␊ + public␊ + view␊ + override␊ + returns (address)␊ + {␊ + // Implement how the yield source address is computed for a given currency␊ + }␊ + ␊ + function _depositToYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is deposited to it's corresponding yield source␊ + }␊ + ␊ + function _withdrawFromYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is withdrawn from it's corresponding yield source␊ + }␊ + ␊ + function _getAmountInYieldSource(Currency currency)␊ + internal␊ + view␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the hook's balance of a given currency in it's corresponding yield source is obtained␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## safeCast ReHypothecationHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {ReHypothecationHook} from "@openzeppelin/uniswap-hooks/general/ReHypothecationHook.sol";␊ + import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";␊ + ␊ + contract MyHook is ReHypothecationHook {␊ + using SafeCast for *;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function getCurrencyYieldSource(Currency currency)␊ + public␊ + view␊ + override␊ + returns (address)␊ + {␊ + // Implement how the yield source address is computed for a given currency␊ + }␊ + ␊ + function _depositToYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is deposited to it's corresponding yield source␊ + }␊ + ␊ + function _withdrawFromYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is withdrawn from it's corresponding yield source␊ + }␊ + ␊ + function _getAmountInYieldSource(Currency currency)␊ + internal␊ + view␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the hook's balance of a given currency in it's corresponding yield source is obtained␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## transient storage ReHypothecationHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {ReHypothecationHook} from "@openzeppelin/uniswap-hooks/general/ReHypothecationHook.sol";␊ + import {SlotDerivation} from "@openzeppelin/contracts/utils/SlotDerivation.sol";␊ + import {TransientSlot} from "@openzeppelin/contracts/utils/TransientSlot.sol";␊ + ␊ + contract MyHook is ReHypothecationHook {␊ + using SlotDerivation for bytes32;␊ + using TransientSlot for bytes32;␊ + ␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function getCurrencyYieldSource(Currency currency)␊ + public␊ + view␊ + override␊ + returns (address)␊ + {␊ + // Implement how the yield source address is computed for a given currency␊ + }␊ + ␊ + function _depositToYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is deposited to it's corresponding yield source␊ + }␊ + ␊ + function _withdrawFromYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is withdrawn from it's corresponding yield source␊ + }␊ + ␊ + function _getAmountInYieldSource(Currency currency)␊ + internal␊ + view␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the hook's balance of a given currency in it's corresponding yield source is obtained␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## access control (ownable) ReHypothecationHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {ReHypothecationHook} from "@openzeppelin/uniswap-hooks/general/ReHypothecationHook.sol";␊ + ␊ + contract MyHook is ReHypothecationHook, Ownable {␊ + constructor(address initialOwner)␊ + Ownable(initialOwner)␊ + ERC20("MyShares", "MSH")␊ + {}␊ + ␊ + function getCurrencyYieldSource(Currency currency)␊ + public␊ + view␊ + override␊ + returns (address)␊ + {␊ + // Implement how the yield source address is computed for a given currency␊ + }␊ + ␊ + function _depositToYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is deposited to it's corresponding yield source␊ + }␊ + ␊ + function _withdrawFromYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is withdrawn from it's corresponding yield source␊ + }␊ + ␊ + function _getAmountInYieldSource(Currency currency)␊ + internal␊ + view␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the hook's balance of a given currency in it's corresponding yield source is obtained␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## access control (roles) ReHypothecationHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {ReHypothecationHook} from "@openzeppelin/uniswap-hooks/general/ReHypothecationHook.sol";␊ + ␊ + contract MyHook is ReHypothecationHook, AccessControl {␊ + constructor(address defaultAdmin) ERC20("MyShares", "MSH") {␊ + _grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);␊ + }␊ + ␊ + function getCurrencyYieldSource(Currency currency)␊ + public␊ + view␊ + override␊ + returns (address)␊ + {␊ + // Implement how the yield source address is computed for a given currency␊ + }␊ + ␊ + function _depositToYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is deposited to it's corresponding yield source␊ + }␊ + ␊ + function _withdrawFromYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is withdrawn from it's corresponding yield source␊ + }␊ + ␊ + function _getAmountInYieldSource(Currency currency)␊ + internal␊ + view␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the hook's balance of a given currency in it's corresponding yield source is obtained␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## access control (managed) ReHypothecationHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol";␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {ReHypothecationHook} from "@openzeppelin/uniswap-hooks/general/ReHypothecationHook.sol";␊ + ␊ + contract MyHook is ReHypothecationHook, AccessManaged {␊ + constructor(address initialAuthority)␊ + AccessManaged(initialAuthority)␊ + ERC20("MyShares", "MSH")␊ + {}␊ + ␊ + function getCurrencyYieldSource(Currency currency)␊ + public␊ + view␊ + override␊ + returns (address)␊ + {␊ + // Implement how the yield source address is computed for a given currency␊ + }␊ + ␊ + function _depositToYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is deposited to it's corresponding yield source␊ + }␊ + ␊ + function _withdrawFromYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is withdrawn from it's corresponding yield source␊ + }␊ + ␊ + function _getAmountInYieldSource(Currency currency)␊ + internal␊ + view␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the hook's balance of a given currency in it's corresponding yield source is obtained␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## pausable ReHypothecationHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊ + import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {ReHypothecationHook} from "@openzeppelin/uniswap-hooks/general/ReHypothecationHook.sol";␊ + import {SwapParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + ␊ + contract MyHook is ReHypothecationHook, Pausable, Ownable {␊ + constructor(address initialOwner)␊ + ERC20("MyShares", "MSH")␊ + Ownable(initialOwner)␊ + {}␊ + ␊ + function getCurrencyYieldSource(Currency currency)␊ + public␊ + view␊ + override␊ + returns (address)␊ + {␊ + // Implement how the yield source address is computed for a given currency␊ + }␊ + ␊ + function _depositToYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is deposited to it's corresponding yield source␊ + }␊ + ␊ + function _withdrawFromYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is withdrawn from it's corresponding yield source␊ + }␊ + ␊ + function _getAmountInYieldSource(Currency currency)␊ + internal␊ + view␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the hook's balance of a given currency in it's corresponding yield source is obtained␊ + }␊ + ␊ + function pause() public onlyOwner {␊ + _pause();␊ + }␊ + ␊ + function unpause() public onlyOwner {␊ + _unpause();␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeAddLiquidity(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeRemoveLiquidity(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4, BeforeSwapDelta, uint24)␊ + {␊ + return super._beforeSwap(sender, key, params, hookData);␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + whenNotPaused␊ + returns (bytes4)␊ + {␊ + return super._beforeDonate(sender, key, amount0, amount1, hookData);␊ + }␊ + ␊ + function addReHypothecatedLiquidity(uint256 shares)␊ + public␊ + payable␊ + override␊ + whenNotPaused␊ + returns (BalanceDelta)␊ + {␊ + return super.addReHypothecatedLiquidity(shares);␊ + }␊ + ␊ + function removeReHypothecatedLiquidity(uint256 shares)␊ + public␊ + override␊ + whenNotPaused␊ + returns (BalanceDelta)␊ + {␊ + return super.removeReHypothecatedLiquidity(shares);␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## shares erc20 ReHypothecationHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {ReHypothecationHook} from "@openzeppelin/uniswap-hooks/general/ReHypothecationHook.sol";␊ + ␊ + contract MyHook is ReHypothecationHook {␊ + constructor() ERC20("MyShares", "MSH") {}␊ + ␊ + function getCurrencyYieldSource(Currency currency)␊ + public␊ + view␊ + override␊ + returns (address)␊ + {␊ + // Implement how the yield source address is computed for a given currency␊ + }␊ + ␊ + function _depositToYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is deposited to it's corresponding yield source␊ + }␊ + ␊ + function _withdrawFromYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is withdrawn from it's corresponding yield source␊ + }␊ + ␊ + function _getAmountInYieldSource(Currency currency)␊ + internal␊ + view␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the hook's balance of a given currency in it's corresponding yield source is obtained␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## shares erc1155 ReHypothecationHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {ReHypothecationHook} from "@openzeppelin/uniswap-hooks/general/ReHypothecationHook.sol";␊ + ␊ + contract MyHook is ReHypothecationHook {␊ + constructor() ERC20("", "") {}␊ + ␊ + function getCurrencyYieldSource(Currency currency)␊ + public␊ + view␊ + override␊ + returns (address)␊ + {␊ + // Implement how the yield source address is computed for a given currency␊ + }␊ + ␊ + function _depositToYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is deposited to it's corresponding yield source␊ + }␊ + ␊ + function _withdrawFromYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is withdrawn from it's corresponding yield source␊ + }␊ + ␊ + function _getAmountInYieldSource(Currency currency)␊ + internal␊ + view␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the hook's balance of a given currency in it's corresponding yield source is obtained␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` + +## shares erc6909 ReHypothecationHook + +> Snapshot 1 + + `// SPDX-License-Identifier: MIT␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and OpenZeppelin Uniswap Hooks ^1.0.0␊ + pragma solidity ^0.8.27;␊ + ␊ + import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";␊ + import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";␊ + import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ + import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";␊ + import {ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";␊ + import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";␊ + import {ReHypothecationHook} from "@openzeppelin/uniswap-hooks/general/ReHypothecationHook.sol";␊ + ␊ + contract MyHook is ReHypothecationHook {␊ + constructor() ERC20("", "") {}␊ + ␊ + function getCurrencyYieldSource(Currency currency)␊ + public␊ + view␊ + override␊ + returns (address)␊ + {␊ + // Implement how the yield source address is computed for a given currency␊ + }␊ + ␊ + function _depositToYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is deposited to it's corresponding yield source␊ + }␊ + ␊ + function _withdrawFromYieldSource(Currency currency, uint256 amount)␊ + internal␊ + override␊ + {␊ + // Implement how a given currency is withdrawn from it's corresponding yield source␊ + }␊ + ␊ + function _getAmountInYieldSource(Currency currency)␊ + internal␊ + view␊ + override␊ + returns (uint256)␊ + {␊ + // Implement how the hook's balance of a given currency in it's corresponding yield source is obtained␊ + }␊ + ␊ + function _afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __afterInitialize␊ + }␊ + ␊ + function _beforeAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeAddLiquidity␊ + }␊ + ␊ + function _beforeRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeRemoveLiquidity␊ + }␊ + ␊ + function _afterAddLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterAddLiquidity␊ + }␊ + ␊ + function _afterRemoveLiquidity(address sender, PoolKey calldata key, ModifyLiquidityParams calldata params, BalanceDelta delta0, BalanceDelta delta1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4, BalanceDelta)␊ + {␊ + // Implement __afterRemoveLiquidity␊ + }␊ + ␊ + function _beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData)␊ + internal␊ + override␊ + returns (bytes4)␊ + {␊ + // Implement __beforeDonate␊ + }␊ + ␊ + function getHookPermissions()␊ + public␊ + pure␊ + override␊ + returns (Hooks.Permissions memory)␊ + {␊ + return Hooks.Permissions({␊ + beforeInitialize: true,␊ + afterInitialize: true,␊ + beforeAddLiquidity: true,␊ + beforeRemoveLiquidity: true,␊ + afterAddLiquidity: true,␊ + afterRemoveLiquidity: true,␊ + beforeSwap: true,␊ + afterSwap: true,␊ + beforeDonate: true,␊ + afterDonate: false,␊ + beforeSwapReturnDelta: true,␊ + afterSwapReturnDelta: true,␊ + afterAddLiquidityReturnDelta: true,␊ + afterRemoveLiquidityReturnDelta: true␊ + });␊ + }␊ + }␊ + ` diff --git a/packages/core/uniswap-hooks/src/hooks.test.ts.snap b/packages/core/uniswap-hooks/src/hooks.test.ts.snap new file mode 100644 index 000000000..3c6230c8f Binary files /dev/null and b/packages/core/uniswap-hooks/src/hooks.test.ts.snap differ diff --git a/packages/core/uniswap-hooks/src/hooks.ts b/packages/core/uniswap-hooks/src/hooks.ts new file mode 100644 index 000000000..02dc39124 --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks.ts @@ -0,0 +1,562 @@ +import { + withCommonDefaults, + commonDefaults, + setInfo, + setAccessControl, + addPausable, + supportsInterface, + ContractBuilder, +} from '@openzeppelin/wizard'; +import type { BaseFunction, Contract, CommonOptions, Value, ReferencedContract } from '@openzeppelin/wizard'; +import { printContract } from './print'; +import { HOOKS, PERMISSIONS, PAUSABLE_PERMISSIONS } from './hooks/'; +import type { HookName, Shares, Permissions, Permission } from './hooks/'; +import importPaths from './importPaths.json'; + +export interface HooksOptions extends CommonOptions { + hook: HookName; + name: string; + pausable: boolean; + currencySettler: boolean; + safeCast: boolean; + transientStorage: boolean; + shares: Shares; + permissions: Permissions; + inputs: { + blockNumberOffset: number; + }; +} + +export const defaults: Required = { + hook: 'BaseHook', + name: 'MyHook', + pausable: false, + access: commonDefaults.access, + upgradeable: commonDefaults.upgradeable, + info: commonDefaults.info, + currencySettler: false, + safeCast: false, + transientStorage: false, + shares: { + options: false, + name: 'MyShares', + symbol: 'MSH', + uri: '', + }, + permissions: { + beforeInitialize: false, + afterInitialize: false, + beforeAddLiquidity: false, + beforeRemoveLiquidity: false, + afterAddLiquidity: false, + afterRemoveLiquidity: false, + beforeSwap: false, + afterSwap: false, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: false, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, + }, + inputs: { + blockNumberOffset: 10, + }, +}; + +function withDefaults(opts: HooksOptions): Required { + return { + ...opts, + ...withCommonDefaults(opts), + pausable: opts.pausable ?? defaults.pausable, + currencySettler: opts.currencySettler ?? defaults.currencySettler, + safeCast: opts.safeCast ?? defaults.safeCast, + transientStorage: opts.transientStorage ?? defaults.transientStorage, + shares: opts.shares ?? defaults.shares, + permissions: opts.permissions ?? defaults.permissions, + inputs: opts.inputs ?? defaults.inputs, + }; +} + +export function printHooks(opts: HooksOptions = defaults): string { + return printContract(buildHooks(opts)); +} + +export function buildHooks(opts: HooksOptions): Contract { + const allOpts = withDefaults(opts); + + // Upgradeability is not yet available for hooks + allOpts.upgradeable = false; + + const c = new ContractBuilder(allOpts.name); + + const selectedHook = HOOKS[allOpts.hook]; + + setInfo(c, allOpts.info); + + addHook(c, allOpts); + + if (allOpts.access) { + setAccessControl(c, allOpts.access); + } + + if (allOpts.currencySettler) { + addCurrencySettler(c, allOpts); + } + + if (allOpts.safeCast) { + addSafeCast(c, allOpts); + } + + if (allOpts.transientStorage) { + addTransientStorage(c, allOpts); + } + + // Automatically preset the shares options based on the hook's shares type pre-configuration. + switch (selectedHook.shares) { + case 'disabled': + allOpts.shares.options = false; + break; + case 'required': + // Select the ERC20 shares by default when any share type is required + if (!allOpts.shares.options) allOpts.shares.options = 'ERC20'; + break; + // Select the specific shares types options when they're specifically required by the hook + case 'ERC20': + allOpts.shares.options = 'ERC20'; + break; + case 'ERC6909': + allOpts.shares.options = 'ERC6909'; + break; + case 'ERC1155': + allOpts.shares.options = 'ERC1155'; + break; + case 'optional': + default: + break; + } + + // Add the shares based on the shares options. + // if (!selectedHook.alreadyImplementsShares) { + switch (allOpts.shares.options) { + case 'ERC20': + addERC20Shares(c, allOpts); + break; + case 'ERC6909': + addERC6909Shares(c, allOpts); + break; + case 'ERC1155': + addERC1155Shares(c, allOpts); + break; + } + // } + + // Add required permissions given the current options. + for (const permission of PERMISSIONS) { + if ( + permissionRequiredByHook(allOpts.hook, permission) || + permissionRequiredByAnotherPermission(allOpts, permission) || + (allOpts.pausable && permissionRequiredByPausable(allOpts, permission)) + ) { + allOpts.permissions[permission] = true; + } + } + + if (allOpts.pausable) { + addPausable(c, allOpts.access, []); + addPausableFunctions(c, allOpts); + } + + addAdditionalPermissionFunctions(c, allOpts); + + addGetHookPermissionsFunction(c, allOpts); + + importRequiredTypes(c); + + return c; +} + +function addHook(c: ContractBuilder, allOpts: HooksOptions) { + const constructorParams: Value[] = []; + + // Add Overrides & Constructor Params specific to each hook + switch (allOpts.hook) { + case 'BaseCustomAccounting': + c.addOverride({ name: 'BaseCustomAccounting' }, HOOKS.BaseCustomAccounting.functions._getAddLiquidity!); + c.setFunctionBody( + [`// Implement how liquidity additions and minted shares are computed`], + HOOKS.BaseCustomAccounting.functions._getAddLiquidity!, + ); + c.addOverride({ name: 'BaseCustomAccounting' }, HOOKS.BaseCustomAccounting.functions._getRemoveLiquidity!); + c.setFunctionBody( + [`// Implement how liquidity removals and burned shares are computed`], + HOOKS.BaseCustomAccounting.functions._getRemoveLiquidity!, + ); + c.addOverride({ name: 'BaseCustomAccounting' }, HOOKS.BaseCustomAccounting.functions._mint!); + c.setFunctionBody([`// Implement how shares are minted`], HOOKS.BaseCustomAccounting.functions._mint!); + c.addOverride({ name: 'BaseCustomAccounting' }, HOOKS.BaseCustomAccounting.functions._burn!); + c.setFunctionBody([`// Implement how shares are burned`], HOOKS.BaseCustomAccounting.functions._burn!); + break; + case 'BaseCustomCurve': + c.addOverride({ name: 'BaseCustomCurve' }, HOOKS.BaseCustomCurve.functions._getUnspecifiedAmount!); + c.setFunctionBody( + [`// Implement how the unspecified currency amount is computed`], + HOOKS.BaseCustomCurve.functions._getUnspecifiedAmount!, + ); + c.addOverride({ name: 'BaseCustomCurve' }, HOOKS.BaseCustomCurve.functions._getSwapFeeAmount!); + c.setFunctionBody( + [`// Implement how the LPs fees amount is computed`], + HOOKS.BaseCustomCurve.functions._getSwapFeeAmount!, + ); + c.addOverride({ name: 'BaseCustomCurve' }, HOOKS.BaseCustomCurve.functions._getAmountOut!); + c.setFunctionBody( + [`// Implement how the amount out of the swap is computed`], + HOOKS.BaseCustomCurve.functions._getAmountOut!, + ); + c.addOverride({ name: 'BaseCustomCurve' }, HOOKS.BaseCustomCurve.functions._getAmountIn!); + c.setFunctionBody( + [`// Implement how the amount in of the swap is computed`], + HOOKS.BaseCustomCurve.functions._getAmountIn!, + ); + c.addOverride({ name: 'BaseCustomAccounting' }, HOOKS.BaseCustomAccounting.functions._mint!); + c.setFunctionBody([`// Implement how shares are minted`], HOOKS.BaseCustomAccounting.functions._mint!); + c.addOverride({ name: 'BaseCustomAccounting' }, HOOKS.BaseCustomAccounting.functions._burn!); + c.setFunctionBody([`// Implement how shares are burned`], HOOKS.BaseCustomAccounting.functions._burn!); + break; + case 'BaseDynamicFee': + c.addOverride({ name: 'BaseDynamicFee' }, HOOKS.BaseDynamicFee.functions._getFee!); + c.setFunctionBody([`// Implement how the LP fee is computed`], HOOKS.BaseDynamicFee.functions._getFee!); + break; + case 'BaseDynamicAfterFee': + c.addOverride({ name: 'BaseDynamicAfterFee' }, HOOKS.BaseDynamicAfterFee.functions._getTargetUnspecified!); + c.setFunctionBody( + [`// Implement how the target unspecified amount is computed`], + HOOKS.BaseDynamicAfterFee.functions._getTargetUnspecified!, + ); + c.addOverride({ name: 'BaseDynamicAfterFee' }, HOOKS.BaseDynamicAfterFee.functions._afterSwapHandler!); + c.setFunctionBody( + [`// Implement how the accumulated penalty fees are handled after swaps`], + HOOKS.BaseDynamicAfterFee.functions._afterSwapHandler!, + ); + break; + case 'BaseOverrideFee': + c.addOverride({ name: 'BaseOverrideFee' }, HOOKS.BaseOverrideFee.functions._getFee!); + c.setFunctionBody([`// Implement how the LP fee is computed`], HOOKS.BaseOverrideFee.functions._getFee!); + break; + case 'BaseHookFee': + c.addOverride({ name: 'BaseHookFee' }, HOOKS.BaseHookFee.functions._getHookFee!); + c.setFunctionBody([`// Implement how the Hook fee is computed`], HOOKS.BaseHookFee.functions._getHookFee!); + c.addOverride({ name: 'BaseHookFee' }, HOOKS.BaseHookFee.functions.handleHookFees!); + c.setFunctionBody( + [`// Implement how the accumulated hook fees are handled`], + HOOKS.BaseHookFee.functions.handleHookFees!, + ); + break; + case 'AntiSandwichHook': + c.addOverride({ name: 'AntiSandwichHook' }, HOOKS.AntiSandwichHook.functions._afterSwapHandler!); + c.setFunctionBody( + [`// Implement how the accumulated penalty fees from sandwich attacks are handled after swaps`], + HOOKS.AntiSandwichHook.functions._afterSwapHandler!, + ); + break; + case 'LiquidityPenaltyHook': + constructorParams.push(allOpts.inputs?.blockNumberOffset || 10); + break; + case 'ReHypothecationHook': + c.addOverride({ name: 'ReHypothecationHook' }, HOOKS.ReHypothecationHook.functions.getCurrencyYieldSource!); + c.setFunctionBody( + [`// Implement how the yield source address is computed for a given currency`], + HOOKS.ReHypothecationHook.functions.getCurrencyYieldSource!, + ); + c.addOverride({ name: 'ReHypothecationHook' }, HOOKS.ReHypothecationHook.functions._depositToYieldSource!); + c.setFunctionBody( + [`// Implement how a given currency is deposited to it's corresponding yield source`], + HOOKS.ReHypothecationHook.functions._depositToYieldSource!, + ); + c.addOverride({ name: 'ReHypothecationHook' }, HOOKS.ReHypothecationHook.functions._withdrawFromYieldSource!); + c.setFunctionBody( + [`// Implement how a given currency is withdrawn from it's corresponding yield source`], + HOOKS.ReHypothecationHook.functions._withdrawFromYieldSource!, + ); + c.addOverride({ name: 'ReHypothecationHook' }, HOOKS.ReHypothecationHook.functions._getAmountInYieldSource!); + c.setFunctionBody( + [`// Implement how the hook's balance of a given currency in it's corresponding yield source is obtained`], + HOOKS.ReHypothecationHook.functions._getAmountInYieldSource!, + ); + break; + default: + break; + } + + c.addParent( + { + name: allOpts.hook, + path: `@openzeppelin/uniswap-hooks/${HOOKS[allOpts.hook].category.toLowerCase()}/${allOpts.hook}.sol`, + }, + constructorParams, + ); +} + +export function isAccessControlRequired(opts: Partial): boolean { + return !!opts.pausable; +} + +function addCurrencySettler(c: ContractBuilder, _allOpts: HooksOptions) { + c.addLibrary( + { + name: 'CurrencySettler', + path: `@openzeppelin/uniswap-hooks/utils/CurrencySettler.sol`, + }, + ['Currency'], + ); +} + +function addSafeCast(c: ContractBuilder, _allOpts: HooksOptions) { + c.addLibrary( + { + name: 'SafeCast', + path: `@openzeppelin/contracts/utils/math/SafeCast.sol`, + }, + ['*'], + ); +} + +function addTransientStorage(c: ContractBuilder, _allOpts: HooksOptions) { + c.addLibrary( + { + name: 'TransientSlot', + path: `@openzeppelin/contracts/utils/TransientSlot.sol`, + }, + ['bytes32'], + ); + c.addLibrary( + { + name: 'SlotDerivation', + path: `@openzeppelin/contracts/utils/SlotDerivation.sol`, + }, + ['bytes32'], + ); +} + +function addERC20Shares(c: ContractBuilder, _allOpts: HooksOptions) { + const selectedHook = HOOKS[_allOpts.hook]; + if (selectedHook.alreadyImplementsShares) { + // add constructor params + c.addConstructionOnly({ name: 'ERC20', path: `@openzeppelin/contracts/token/ERC20/ERC20.sol` }, [ + _allOpts.shares.name || '', + _allOpts.shares.symbol || '', + ]); + } else { + c.addParent( + { + name: 'ERC20', + path: `@openzeppelin/contracts/token/ERC20/ERC20.sol`, + }, + [_allOpts.shares.name || '', _allOpts.shares.symbol || ''], + ); + } +} + +function addERC1155Shares(c: ContractBuilder, _allOpts: HooksOptions) { + c.addParent( + { + name: 'ERC1155', + path: `@openzeppelin/contracts/token/ERC1155/ERC1155.sol`, + }, + [_allOpts.shares.uri || ''], + ); + c.addOverride({ name: 'ERC1155' }, supportsInterface); +} + +function addERC6909Shares(c: ContractBuilder, _allOpts: HooksOptions) { + c.addParent( + { + name: 'ERC6909', + path: `@openzeppelin/contracts/token/ERC6909/draft-ERC6909.sol`, + }, + [], + ); + c.addOverride({ name: 'ERC6909' }, supportsInterface); +} + +// Makes the `before-*` hook functions pausable by adding the `whenNotPaused` modifier. +// Requires the `before-*` permissions to be set to true, which is enforced by the {buildHooks} function. +function addPausableFunctions(c: ContractBuilder, _allOpts: HooksOptions) { + // Make custom eligible functions pausable. See {functionShouldBePausable} for eligibility criteria. + for (const f of Object.values(HOOKS[_allOpts.hook].functions)) { + if (functionShouldBePausable(f, _allOpts)) { + const existingFunction = c.functions.find(fn => fn.name === f.name); + if (!existingFunction) { + // Function doesn't exist yet, add it with super invocation + c.setFunctionBody([returnSuperFunctionInvocation(f)], f); + c.addOverride({ name: c.name }, f); + } + c.addModifier('whenNotPaused', f); + } + } +} + +// Adds the `getHookPermissions` required function to the hook, which returns the permissions of the hook. +function addGetHookPermissionsFunction(c: ContractBuilder, _allOpts: HooksOptions) { + const permissionLines = PERMISSIONS.map( + (key, idx) => ` ${key}: ${_allOpts.permissions[key] ?? false}${idx === PERMISSIONS.length - 1 ? '' : ','}`, + ); + c.addOverride({ name: 'BaseHook' }, HOOKS.BaseHook.functions.getHookPermissions!); + c.setFunctionBody( + ['return Hooks.Permissions({', ...permissionLines, '});'], + HOOKS.BaseHook.functions.getHookPermissions!, + ); +} + +// Print hook permission functions associated with additionally enabled permissions. +function addAdditionalPermissionFunctions(c: ContractBuilder, _allOpts: HooksOptions) { + // Print each enabled permission associated function that has not been printed yet. + for (const permission of getEnabledPermissions(_allOpts)) { + // A permission is additional if it is not required by the hook and not required by pausability + // (It was manually enabled by the user) + const isAdditionalPermission = + !permissionRequiredByHook(_allOpts.hook, permission) && + !(_allOpts.pausable && permissionRequiredByPausable(_allOpts, permission)); + + // If the permission is additional, add the permission associated function to the contract. + if (isAdditionalPermission) { + const functionName = `_${permission}`; + const permissionFunction = HOOKS.BaseHook.functions[functionName]!; + // Permissions of the type `*-ReturnDelta` doesn't have a permission associated function. + if (!permission.includes('ReturnDelta') && !c.functions.some(f => f.name === permissionFunction?.name)) { + c.addOverride({ name: 'BaseHook' }, permissionFunction); + c.setFunctionBody([`// Implement _${functionName}`], permissionFunction); + } + } + } +} + +function returnSuperFunctionInvocation(f: BaseFunction): string { + return `return super.${f.name}(${f.args.map(arg => arg.name).join(', ')});`; +} + +function functionShouldBePausable(f: BaseFunction, _allOpts: HooksOptions) { + // Doesn't require pausability if the function is disabled in the hook. + if (HOOKS[_allOpts.hook].disabledFunctions.includes(f.name)) return false; + + // Should be pausable if it is a pausable permission function. + for (const p of PAUSABLE_PERMISSIONS) { + if (f.name === `_${p}`) return true; + } + + // Should also be pausable by default if it is a public/external non-pure/view entrypoint to the hook. + const whitelist = ['unlockCallback', 'pause', 'unpause']; + if ( + (f.kind === 'external' || f.kind === 'public') && + f.mutability !== 'pure' && + f.mutability !== 'view' && + !whitelist.includes(f.name) + ) { + return true; + } + + return false; +} + +// Import all the required types from the contract, including constructor args, libraries, functions args/returns. +function importRequiredTypes(c: ContractBuilder) { + const requiredTypes = new Set(); + + for (const arg of c.constructorArgs) { + requiredTypes.add(normalizeType(arg.type)); + } + for (const library of c.libraries) { + for (const type of library.usingFor) { + requiredTypes.add(normalizeType(type)); + } + } + for (const f of Object.values(c.functions)) { + for (const arg of f.args) { + requiredTypes.add(normalizeType(arg.type)); + } + for (const returnType of f.returns || []) { + requiredTypes.add(normalizeType(returnType)); + } + } + for (const type of requiredTypes) { + if (isNativeSolidityType(type)) continue; + + const path = importPaths[type as keyof typeof importPaths] || 'add me to importPaths.json!'; + if (path === 'parent') continue; + + c.addImportOnly({ name: type, path: path }); + } +} + +// Utility to normalize the type (string | ReferencedContract) to a type string. +function normalizeType(s: string | ReferencedContract): string { + let type = ''; + // if the type is string, return the first word until the first space. + if (typeof s === 'string') { + if (s.includes(' ')) { + type = s.split(' ')[0]!; + } else { + type = s; + } + // if the type is a referenced contract, return the name. + } else { + type = s.name; + } + // if the type has a ".", return the first word until the first ".". + if (type.includes('.')) { + type = type.split('.')[0]!; + } + // Normalize array types (e.g., uint256[], Foo[2]) to their base type + while (type.endsWith(']')) { + const idx = type.lastIndexOf('['); + if (idx === -1) break; + type = type.slice(0, idx); + } + // Normalize address payable → address + if (type.startsWith('address')) type = 'address'; + return type; +} + +function isNativeSolidityType(type: string): boolean { + const base = new Set(['bool', 'address', 'string', 'bytes', 'byte', 'uint', 'int', 'fixed', 'ufixed', '*']); + if (base.has(type)) return true; + + const intMatch = type.match(/^(u?int)(\d+)$/); + if (intMatch) { + const bits = Number(intMatch[2]); + return bits >= 8 && bits <= 256 && bits % 8 === 0; + } + + if (/^bytes([1-9]|[12]\d|3[0-2])$/.test(type)) return true; + + return type.startsWith('mapping'); +} + +export function isPermissionEnabled(opts: HooksOptions, permission: Permission): boolean { + return opts.permissions[permission]; +} + +export function permissionRequiredByHook(hook: HookName, permission: Permission): boolean { + return HOOKS[hook].permissions[permission as Permission]; +} + +export function permissionRequiredByPausable(opts: HooksOptions, permission: Permission): boolean { + return opts.pausable && PAUSABLE_PERMISSIONS.includes(permission); +} + +export function returnDeltaPermissionExtension(permission: Permission): Permission { + return permission.concat('ReturnDelta') as Permission; +} + +// If permissions of the type *-ReturnDelta are enabled, the respective permission dependencies +// are also required, i.e. the beforeSwapReturnDelta permission also requires the beforeSwap permission. +export function permissionRequiredByAnotherPermission(opts: HooksOptions, permission: Permission): boolean { + const deltaExtensionPermission = returnDeltaPermissionExtension(permission); + return isPermissionEnabled(opts, deltaExtensionPermission); +} + +export function getEnabledPermissions(opts: HooksOptions): Permission[] { + return Object.entries(opts.permissions) + .filter(([_, value]) => value) + .map(([key]) => key as Permission); +} diff --git a/packages/core/uniswap-hooks/src/hooks/AntiSandwichHook.ts b/packages/core/uniswap-hooks/src/hooks/AntiSandwichHook.ts new file mode 100644 index 000000000..6a0610ceb --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/AntiSandwichHook.ts @@ -0,0 +1,50 @@ +import { defineFunctions } from '@openzeppelin/wizard'; +import { BaseHook } from './BaseHook'; +import type { Hook } from './index'; + +const AntiSandwichHook: Hook = { + name: 'AntiSandwichHook', + displayName: 'Sandwich Resistance', + category: 'General', + tooltipText: + 'Maintains the swap pricing in the zeroForOne direction anchored to the beginning-of-block price, nullifying the profitability of sandwich attacks.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/general#AntiSandwichHook', + shares: 'optional', + alreadyImplementsShares: false, + inputs: [], + disabledFunctions: [], + functions: { + ...defineFunctions({ + ...BaseHook.functions, + // handle the fee after the swap (required) + _afterSwapHandler: { + kind: 'internal', + args: [ + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'SwapParams calldata' }, + { name: 'delta', type: 'BalanceDelta' }, + { name: 'targetUnspecifiedAmount', type: 'uint256' }, + { name: 'feeAmount', type: 'uint256' }, + ], + }, + }), + }, + permissions: { + beforeInitialize: false, + afterInitialize: false, + beforeAddLiquidity: false, + afterAddLiquidity: false, + beforeRemoveLiquidity: false, + afterRemoveLiquidity: false, + beforeSwap: true, + afterSwap: true, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: false, + afterSwapReturnDelta: true, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, + }, +}; + +export { AntiSandwichHook }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseAsyncSwap.ts b/packages/core/uniswap-hooks/src/hooks/BaseAsyncSwap.ts new file mode 100644 index 000000000..309f41efd --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/BaseAsyncSwap.ts @@ -0,0 +1,40 @@ +import { defineFunctions } from '@openzeppelin/wizard'; +import { BaseHook } from './BaseHook'; +import type { Hook } from './index'; + +const BaseAsyncSwap: Hook = { + name: 'BaseAsyncSwap', + displayName: 'Async Swaps', + category: 'Base', + tooltipText: + 'Overrides the default swap flow, enabling custom execution and settlement, such as swap queuing and/or reordering.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/base#BaseAsyncSwap', + shares: 'optional', + alreadyImplementsShares: false, + inputs: [], + disabledFunctions: [], + functions: { + ...defineFunctions({ + ...BaseHook.functions, + // no required overrides. + }), + }, + permissions: { + beforeInitialize: false, + afterInitialize: false, + beforeAddLiquidity: false, + afterAddLiquidity: false, + beforeRemoveLiquidity: false, + afterRemoveLiquidity: false, + beforeSwap: true, + afterSwap: false, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: true, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, + }, +}; + +export { BaseAsyncSwap }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseCustomAccounting.ts b/packages/core/uniswap-hooks/src/hooks/BaseCustomAccounting.ts new file mode 100644 index 000000000..800382e39 --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/BaseCustomAccounting.ts @@ -0,0 +1,85 @@ +import { defineFunctions } from '@openzeppelin/wizard'; +import { BaseHook } from './BaseHook'; +import type { Hook } from './index'; + +const BaseCustomAccounting: Hook = { + name: 'BaseCustomAccounting', + displayName: 'Custom Accounting', + category: 'Base', + tooltipText: 'Overrides how liquidity modifications are processed and how liquidiy shares are minted/burned.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/base#BaseCustomAccounting', + shares: 'required', + alreadyImplementsShares: false, + inputs: [], + disabledFunctions: ['_beforeAddLiquidity', '_beforeRemoveLiquidity'], + functions: { + ...defineFunctions({ + ...BaseHook.functions, + // Public liquidity functions + addLiquidity: { + kind: 'public', + mutability: 'payable', + args: [{ name: 'params', type: 'AddLiquidityParams calldata' }], + returns: ['BalanceDelta'], + }, + removeLiquidity: { + kind: 'public', + args: [{ name: 'params', type: 'RemoveLiquidityParams calldata' }], + returns: ['BalanceDelta'], + }, + // Liquidity modification (required) + _getAddLiquidity: { + kind: 'internal', + args: [ + { name: 'sqrtPriceX96', type: 'uint160' }, + { name: 'params', type: 'AddLiquidityParams memory' }, + ], + returns: ['bytes memory', 'uint256'], + }, + _getRemoveLiquidity: { + kind: 'internal', + args: [{ name: 'params', type: 'RemoveLiquidityParams memory' }], + returns: ['bytes memory', 'uint256'], + }, + // Shares accounting (required) + _mint: { + kind: 'internal', + args: [ + { name: 'params', type: 'AddLiquidityParams memory' }, + { name: 'callerDelta', type: 'BalanceDelta' }, + { name: 'feesAccrued', type: 'BalanceDelta' }, + { name: 'shares', type: 'uint256' }, + ], + returns: [], + }, + _burn: { + kind: 'internal', + args: [ + { name: 'params', type: 'RemoveLiquidityParams memory' }, + { name: 'callerDelta', type: 'BalanceDelta' }, + { name: 'feesAccrued', type: 'BalanceDelta' }, + { name: 'shares', type: 'uint256' }, + ], + returns: [], + }, + }), + }, + permissions: { + beforeInitialize: true, + afterInitialize: false, + beforeAddLiquidity: true, + afterAddLiquidity: false, + beforeRemoveLiquidity: true, + afterRemoveLiquidity: false, + beforeSwap: false, + afterSwap: false, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: false, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, + }, +}; + +export { BaseCustomAccounting }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseCustomCurve.ts b/packages/core/uniswap-hooks/src/hooks/BaseCustomCurve.ts new file mode 100644 index 000000000..e48154544 --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/BaseCustomCurve.ts @@ -0,0 +1,67 @@ +import { defineFunctions } from '@openzeppelin/wizard'; +import { BaseCustomAccounting } from './BaseCustomAccounting'; +import { BaseHook } from './BaseHook'; +import type { Hook } from './index'; + +const BaseCustomCurve: Hook = { + name: 'BaseCustomCurve', + displayName: 'Custom Curve', + category: 'Base', + tooltipText: 'Allows for custom pricing logic and swap amount calculations, useful to implement a custom curve.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/base#BaseCustomCurve', + shares: 'required', + alreadyImplementsShares: false, + inputs: [], + disabledFunctions: [...BaseCustomAccounting.disabledFunctions], + functions: { + ...defineFunctions({ + ...BaseHook.functions, + ...BaseCustomAccounting.functions, + // Calculate the amount of the unspecified currency taken/settled during swap (required) + _getUnspecifiedAmount: { + kind: 'internal', + args: [{ name: 'params', type: 'SwapParams calldata' }], + returns: ['uint256'], + }, + // Calculate the total LP fees to be paid for the swap (required) + _getSwapFeeAmount: { + kind: 'internal', + args: [ + { name: 'params', type: 'SwapParams calldata' }, + { name: 'unspecifiedAmount', type: 'uint256' }, + ], + returns: ['uint256'], + }, + // Amounts used and shares burned on remove liquidity (required) + _getAmountOut: { + kind: 'internal', + args: [{ name: 'params', type: 'RemoveLiquidityParams memory' }], + returns: ['uint256', 'uint256', 'uint256'], + }, + // Amounts used and shares minted on add liquidity (required) + _getAmountIn: { + kind: 'internal', + args: [{ name: 'params', type: 'AddLiquidityParams memory' }], + returns: ['uint256', 'uint256', 'uint256'], + }, + }), + }, + permissions: { + beforeInitialize: true, + afterInitialize: false, + beforeAddLiquidity: true, + afterAddLiquidity: false, + beforeRemoveLiquidity: true, + afterRemoveLiquidity: false, + beforeSwap: true, + afterSwap: false, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: true, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, + }, +}; + +export { BaseCustomCurve }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseDynamicAfterFee.ts b/packages/core/uniswap-hooks/src/hooks/BaseDynamicAfterFee.ts new file mode 100644 index 000000000..35709a1b6 --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/BaseDynamicAfterFee.ts @@ -0,0 +1,61 @@ +import { defineFunctions } from '@openzeppelin/wizard'; +import { BaseHook } from './BaseHook'; +import type { Hook } from './index'; + +const BaseDynamicAfterFee: Hook = { + name: 'BaseDynamicAfterFee', + displayName: 'Swap Target Enforcer', + category: 'Fee', + tooltipText: + 'Enforces a target for swap outcomes determined by _getTargetUnspecified, capturing any better-than-expected results as hook fees that can be handled or distributed via _afterSwapHandler.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/fee#BaseDynamicAfterFee', + shares: 'optional', + alreadyImplementsShares: false, + inputs: [], + disabledFunctions: [], + functions: { + ...defineFunctions({ + ...BaseHook.functions, + // determine the target unspecified amount (required) + _getTargetUnspecified: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'SwapParams calldata' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['uint256', 'bool'], + }, + // handle the fee after the swap (required) + _afterSwapHandler: { + kind: 'internal', + args: [ + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'SwapParams calldata' }, + { name: 'delta', type: 'BalanceDelta' }, + { name: 'targetUnspecifiedAmount', type: 'uint256' }, + { name: 'feeAmount', type: 'uint256' }, + ], + }, + }), + }, + permissions: { + beforeInitialize: false, + afterInitialize: false, + beforeAddLiquidity: false, + afterAddLiquidity: false, + beforeRemoveLiquidity: false, + afterRemoveLiquidity: false, + beforeSwap: true, + afterSwap: true, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: false, + afterSwapReturnDelta: true, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, + }, +}; + +export { BaseDynamicAfterFee }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseDynamicFee.ts b/packages/core/uniswap-hooks/src/hooks/BaseDynamicFee.ts new file mode 100644 index 000000000..c34023c81 --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/BaseDynamicFee.ts @@ -0,0 +1,50 @@ +import { defineFunctions } from '@openzeppelin/wizard'; +import { BaseHook } from './BaseHook'; +import type { Hook } from './index'; + +const BaseDynamicFee: Hook = { + name: 'BaseDynamicFee', + displayName: 'Dynamic Pool Fee', + category: 'Fee', + tooltipText: + 'Applies a dynamic fee to the entire pool, determined by _getFee and updated upon calling _poke.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/fee#BaseDynamicFee', + shares: 'optional', + alreadyImplementsShares: false, + inputs: [], + disabledFunctions: [], + functions: { + ...defineFunctions({ + ...BaseHook.functions, + // dynamically override the fee (required) + _getFee: { + kind: 'internal', + args: [{ name: 'key', type: 'PoolKey calldata' }], + returns: ['uint24'], + }, + // poke the fee (optional override) + poke: { + kind: 'public', // external/public for our generator purposes + args: [{ name: 'key', type: 'PoolKey calldata' }], + }, + }), + }, + permissions: { + beforeInitialize: false, + afterInitialize: true, + beforeAddLiquidity: false, + afterAddLiquidity: false, + beforeRemoveLiquidity: false, + afterRemoveLiquidity: false, + beforeSwap: false, + afterSwap: false, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: false, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, + }, +}; + +export { BaseDynamicFee }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseHook.ts b/packages/core/uniswap-hooks/src/hooks/BaseHook.ts new file mode 100644 index 000000000..f61b0b6b2 --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/BaseHook.ts @@ -0,0 +1,153 @@ +import { defineFunctions } from '@openzeppelin/wizard'; +import type { Hook } from './index'; + +const BaseHook: Hook = { + name: 'BaseHook', + displayName: 'Base Hook', + category: 'Base', + tooltipText: 'Provides standard entry points, permission checks, and validation utilities for building hooks.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/base#BaseHook', + shares: 'optional', + alreadyImplementsShares: false, + inputs: [], + disabledFunctions: [], + functions: { + ...defineFunctions({ + // Permissions descriptor that inheritors must implement (required) + getHookPermissions: { + kind: 'public', + mutability: 'pure', + args: [], + returns: ['Hooks.Permissions memory'], + }, + // Initialize + _beforeInitialize: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'sqrtPriceX96', type: 'uint160' }, + ], + returns: ['bytes4'], + }, + _afterInitialize: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'sqrtPriceX96', type: 'uint160' }, + { name: 'tick', type: 'int24' }, + ], + returns: ['bytes4'], + }, + // Liquidity add/remove + _beforeAddLiquidity: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'ModifyLiquidityParams calldata' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['bytes4'], + }, + _afterAddLiquidity: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'ModifyLiquidityParams calldata' }, + { name: 'delta0', type: 'BalanceDelta' }, + { name: 'delta1', type: 'BalanceDelta' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['bytes4', 'BalanceDelta'], + }, + _beforeRemoveLiquidity: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'ModifyLiquidityParams calldata' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['bytes4'], + }, + _afterRemoveLiquidity: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'ModifyLiquidityParams calldata' }, + { name: 'delta0', type: 'BalanceDelta' }, + { name: 'delta1', type: 'BalanceDelta' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['bytes4', 'BalanceDelta'], + }, + // Swap + _beforeSwap: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'SwapParams calldata' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['bytes4', 'BeforeSwapDelta', 'uint24'], + }, + _afterSwap: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'SwapParams calldata' }, + { name: 'delta', type: 'BalanceDelta' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['bytes4', 'int128'], + }, + // Donate + _beforeDonate: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'amount0', type: 'uint256' }, + { name: 'amount1', type: 'uint256' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['bytes4'], + }, + _afterDonate: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'amount0', type: 'uint256' }, + { name: 'amount1', type: 'uint256' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['bytes4'], + }, + }), + }, + permissions: { + beforeInitialize: false, + afterInitialize: false, + beforeAddLiquidity: false, + afterAddLiquidity: false, + beforeRemoveLiquidity: false, + afterRemoveLiquidity: false, + beforeSwap: false, + afterSwap: false, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: false, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, + }, +}; + +export { BaseHook }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseHookFee.ts b/packages/core/uniswap-hooks/src/hooks/BaseHookFee.ts new file mode 100644 index 000000000..90320eb12 --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/BaseHookFee.ts @@ -0,0 +1,58 @@ +import { defineFunctions } from '@openzeppelin/wizard'; +import { BaseHook } from './BaseHook'; +import type { Hook } from './index'; + +const BaseHookFee: Hook = { + name: 'BaseHookFee', + displayName: 'Hook Fee', + category: 'Fee', + tooltipText: + "Base implementation for applying hook fees to the unspecified currency of the swap, independent of the pool's LP fee.", + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/fee#BaseHookFee', + shares: 'optional', + alreadyImplementsShares: false, + inputs: [], + disabledFunctions: [], + functions: { + ...defineFunctions({ + ...BaseHook.functions, + // Determine the hook fee (required) + _getHookFee: { + kind: 'internal', + mutability: 'view', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'SwapParams calldata' }, + { name: 'delta', type: 'BalanceDelta' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['uint24'], + }, + // Handle the accumulated hook fees (required) + handleHookFees: { + kind: 'public', + args: [{ name: 'currencies', type: 'Currency[] memory' }], + returns: [], + }, + }), + }, + permissions: { + beforeInitialize: false, + afterInitialize: false, + beforeAddLiquidity: false, + afterAddLiquidity: false, + beforeRemoveLiquidity: false, + afterRemoveLiquidity: false, + beforeSwap: false, + afterSwap: true, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: false, + afterSwapReturnDelta: true, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, + }, +}; + +export { BaseHookFee }; diff --git a/packages/core/uniswap-hooks/src/hooks/BaseOverrideFee.ts b/packages/core/uniswap-hooks/src/hooks/BaseOverrideFee.ts new file mode 100644 index 000000000..b646ae313 --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/BaseOverrideFee.ts @@ -0,0 +1,49 @@ +import { defineFunctions } from '@openzeppelin/wizard'; +import { BaseHook } from './BaseHook'; +import type { Hook } from './index'; + +const BaseOverrideFee: Hook = { + name: 'BaseOverrideFee', + displayName: 'Dynamic Swap Fee', + category: 'Fee', + tooltipText: 'Applies a dynamic fee calculated in a per-swap basis, determined by the _getFee function.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/fee#BaseOverrideFee', + shares: 'optional', + alreadyImplementsShares: false, + inputs: [], + disabledFunctions: [], + functions: { + ...defineFunctions({ + ...BaseHook.functions, + // dynamically override the fee (required) + _getFee: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'SwapParams calldata' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['uint24'], + }, + }), + }, + permissions: { + beforeInitialize: true, + afterInitialize: false, + beforeAddLiquidity: false, + afterAddLiquidity: false, + beforeRemoveLiquidity: false, + afterRemoveLiquidity: false, + beforeSwap: true, + afterSwap: false, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: false, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, + }, +}; + +export { BaseOverrideFee }; diff --git a/packages/core/uniswap-hooks/src/hooks/LimitOrderHook.ts b/packages/core/uniswap-hooks/src/hooks/LimitOrderHook.ts new file mode 100644 index 000000000..5d94d66be --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/LimitOrderHook.ts @@ -0,0 +1,131 @@ +import { defineFunctions } from '@openzeppelin/wizard'; +import { BaseHook } from './BaseHook'; +import type { Hook } from './index'; + +const LimitOrderHook: Hook = { + name: 'LimitOrderHook', + displayName: 'Limit Orders', + category: 'General', + tooltipText: + 'Enables to place, cancel and withdraw orders that are executed when the limit price is reached. Orders are placed in single-currency and out-of-range of the current price.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/general#LimitOrderHook', + shares: 'optional', + alreadyImplementsShares: false, + inputs: [], + disabledFunctions: [], + functions: { + ...defineFunctions({ + ...BaseHook.functions, + _afterInitialize: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'sqrtPriceX96', type: 'uint160' }, + { name: 'tick', type: 'int24' }, + ], + returns: ['bytes4'], + }, + _afterSwap: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'SwapParams calldata' }, + { name: 'delta', type: 'BalanceDelta' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['bytes4', 'int128'], + }, + placeOrder: { + kind: 'public', + args: [ + { name: 'key', type: 'PoolKey calldata' }, + { name: 'tick', type: 'int24' }, + { name: 'zeroForOne', type: 'bool' }, + { name: 'liquidity', type: 'uint128' }, + ], + }, + cancelOrder: { + kind: 'public', + args: [ + { name: 'key', type: 'PoolKey calldata' }, + { name: 'tickLower', type: 'int24' }, + { name: 'zeroForOne', type: 'bool' }, + { name: 'to', type: 'address' }, + ], + }, + withdraw: { + kind: 'public', + args: [ + { name: 'orderId', type: 'OrderIdLibrary.OrderId' }, + { name: 'to', type: 'address' }, + ], + returns: ['uint256', 'uint256'], + }, + getTickLowerLast: { + kind: 'public', + mutability: 'view', + args: [{ name: 'poolId', type: 'PoolId' }], + returns: ['int24'], + }, + getOrderId: { + kind: 'public', + mutability: 'view', + args: [ + { name: 'key', type: 'PoolKey memory' }, + { name: 'tickLower', type: 'int24' }, + { name: 'zeroForOne', type: 'bool' }, + ], + returns: ['OrderIdLibrary.OrderId'], + }, + getOrderLiquidity: { + kind: 'public', + mutability: 'view', + args: [ + { name: 'orderId', type: 'OrderIdLibrary.OrderId' }, + { name: 'owner', type: 'address' }, + ], + returns: ['uint256'], + }, + getHookPermissions: { + kind: 'public', + mutability: 'pure', + args: [], + returns: ['Hooks.Permissions memory'], + }, + _handlePlaceCallback: { + kind: 'internal', + args: [{ name: 'placeData', type: 'PlaceCallbackData memory' }], + returns: ['uint256', 'uint256'], + }, + _handleCancelCallback: { + kind: 'internal', + args: [{ name: 'cancelData', type: 'CancelCallbackData memory' }], + returns: ['uint256', 'uint256'], + }, + _handleWithdrawCallback: { + kind: 'internal', + args: [{ name: 'withdrawData', type: 'WithdrawCallbackData memory' }], + }, + }), + }, + permissions: { + beforeInitialize: false, + afterInitialize: true, + beforeAddLiquidity: false, + afterAddLiquidity: false, + beforeRemoveLiquidity: false, + afterRemoveLiquidity: false, + beforeSwap: false, + afterSwap: true, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: false, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, + }, +}; + +export { LimitOrderHook }; diff --git a/packages/core/uniswap-hooks/src/hooks/LiquidityPenaltyHook.ts b/packages/core/uniswap-hooks/src/hooks/LiquidityPenaltyHook.ts new file mode 100644 index 000000000..a0da21f89 --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/LiquidityPenaltyHook.ts @@ -0,0 +1,133 @@ +import { defineFunctions } from '@openzeppelin/wizard'; +import { BaseHook } from './BaseHook'; +import type { Hook } from './index'; + +const LiquidityPenaltyHook: Hook = { + name: 'LiquidityPenaltyHook', + displayName: 'JIT Liquidity Resistance', + category: 'General', + tooltipText: + 'When liquidity is added and removed faster than _blockNumberOffset blocks, accumulated fees are linearly penalized and donated to in-range LPs.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/general#LiquidityPenaltyHook', + shares: 'optional', + alreadyImplementsShares: false, + inputs: [ + { + name: 'blockNumberOffset', + label: 'Block Number Offset', + placeholder: '10', + type: 'number', + tooltipText: + 'The minimum time window (in blocks) that must pass after adding liquidity before it can be removed without any penalty. During this period, JIT attacks are deterred through fee withholding and penalties. Higher values provide stronger JIT protection but may discourage legitimate LPs.', + }, + ], + disabledFunctions: [], + functions: { + ...defineFunctions({ + ...BaseHook.functions, + _afterAddLiquidity: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'ModifyLiquidityParams calldata' }, + { name: 'delta', type: 'BalanceDelta' }, + { name: 'feeDelta', type: 'BalanceDelta' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['bytes4', 'BalanceDelta'], + }, + _afterRemoveLiquidity: { + kind: 'internal', + args: [ + { name: 'sender', type: 'address' }, + { name: 'key', type: 'PoolKey calldata' }, + { name: 'params', type: 'ModifyLiquidityParams calldata' }, + { name: 'delta', type: 'BalanceDelta' }, + { name: 'feeDelta', type: 'BalanceDelta' }, + { name: 'hookData', type: 'bytes calldata' }, + ], + returns: ['bytes4', 'BalanceDelta'], + }, + _getBlockNumber: { + kind: 'internal', + mutability: 'view', + args: [], + returns: ['uint48'], + }, + getBlockNumberOffset: { + kind: 'public', + mutability: 'view', + args: [], + returns: ['uint48'], + }, + getLastAddedLiquidityBlock: { + kind: 'public', + mutability: 'view', + args: [ + { name: 'poolId', type: 'PoolId' }, + { name: 'positionKey', type: 'bytes32' }, + ], + returns: ['uint48'], + }, + getWithheldFees: { + kind: 'public', + mutability: 'view', + args: [ + { name: 'poolId', type: 'PoolId' }, + { name: 'positionKey', type: 'bytes32' }, + ], + returns: ['BalanceDelta'], + }, + _updateLastAddedLiquidityBlock: { + kind: 'internal', + args: [ + { name: 'poolId', type: 'PoolId' }, + { name: 'positionKey', type: 'bytes32' }, + ], + }, + _takeFeesToHook: { + kind: 'internal', + args: [ + { name: 'key', type: 'PoolKey calldata' }, + { name: 'positionKey', type: 'bytes32' }, + { name: 'feeDelta', type: 'BalanceDelta' }, + ], + }, + _settleFeesFromHook: { + kind: 'internal', + args: [ + { name: 'key', type: 'PoolKey calldata' }, + { name: 'positionKey', type: 'bytes32' }, + ], + returns: ['BalanceDelta'], + }, + _calculateLiquidityPenalty: { + kind: 'internal', + args: [ + { name: 'feeDelta', type: 'BalanceDelta' }, + { name: 'lastAddedLiquidityBlock', type: 'uint48' }, + ], + returns: ['BalanceDelta'], + }, + }), + }, + permissions: { + beforeInitialize: false, + afterInitialize: false, + beforeAddLiquidity: false, + afterAddLiquidity: true, + beforeRemoveLiquidity: false, + afterRemoveLiquidity: true, + beforeSwap: false, + afterSwap: false, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: false, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: true, + afterRemoveLiquidityReturnDelta: true, + }, +}; + +export { LiquidityPenaltyHook }; diff --git a/packages/core/uniswap-hooks/src/hooks/ReHypothecationHook.ts b/packages/core/uniswap-hooks/src/hooks/ReHypothecationHook.ts new file mode 100644 index 000000000..f7c1dd628 --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/ReHypothecationHook.ts @@ -0,0 +1,164 @@ +import { defineFunctions } from '@openzeppelin/wizard'; +import { BaseHook } from './BaseHook'; +import type { Hook } from './index'; + +const ReHypothecationHook: Hook = { + name: 'ReHypothecationHook', + displayName: 'Liquidity Rehypothecation', + category: 'General', + tooltipText: + 'Enables rehypothecation of liquidity positions by depositing assets into yield-generating sources while providing Just-in-Time liquidity during swaps.', + tooltipLink: 'https://docs.openzeppelin.com/uniswap-hooks/api/general#ReHypothecationHook', + shares: 'ERC20', + alreadyImplementsShares: true, + inputs: [], + disabledFunctions: [], + functions: { + ...defineFunctions({ + ...BaseHook.functions, + // Pool key management + getPoolKey: { + kind: 'public', + mutability: 'view', + args: [], + returns: ['PoolKey memory'], + }, + // Rehypothecated liquidity management (required) + addReHypothecatedLiquidity: { + kind: 'public', + mutability: 'payable', + args: [{ name: 'shares', type: 'uint256' }], + returns: ['BalanceDelta'], + }, + removeReHypothecatedLiquidity: { + kind: 'public', + mutability: 'nonpayable', + args: [{ name: 'shares', type: 'uint256' }], + returns: ['BalanceDelta'], + }, + // Preview functions (optional override) + previewAmountsForShares: { + kind: 'public', + mutability: 'view', + args: [{ name: 'shares', type: 'uint256' }], + returns: ['uint256', 'uint256'], + }, + // Tick boundary functions + getTickLower: { + kind: 'public', + mutability: 'view', + args: [], + returns: ['int24'], + }, + getTickUpper: { + kind: 'public', + mutability: 'view', + args: [], + returns: ['int24'], + }, + // Yield source interface (required) + getCurrencyYieldSource: { + kind: 'public', + mutability: 'view', + args: [{ name: 'currency', type: 'Currency' }], + returns: ['address'], + }, + _depositToYieldSource: { + kind: 'internal', + args: [ + { name: 'currency', type: 'Currency' }, + { name: 'amount', type: 'uint256' }, + ], + returns: [], + }, + _withdrawFromYieldSource: { + kind: 'internal', + args: [ + { name: 'currency', type: 'Currency' }, + { name: 'amount', type: 'uint256' }, + ], + returns: [], + }, + _getAmountInYieldSource: { + kind: 'internal', + mutability: 'view', + args: [{ name: 'currency', type: 'Currency' }], + returns: ['uint256'], + }, + // Internal helper functions + _convertSharesToAmounts: { + kind: 'internal', + mutability: 'view', + args: [{ name: 'shares', type: 'uint256' }], + returns: ['uint256', 'uint256'], + }, + _shareToAmount: { + kind: 'internal', + mutability: 'view', + args: [ + { name: 'shares', type: 'uint256' }, + { name: 'currency', type: 'Currency' }, + ], + returns: ['uint256'], + }, + _getLiquidityToUse: { + kind: 'internal', + mutability: 'view', + args: [], + returns: ['uint256'], + }, + _getHookPositionLiquidity: { + kind: 'internal', + mutability: 'view', + args: [], + returns: ['uint128'], + }, + _modifyLiquidity: { + kind: 'internal', + args: [{ name: 'liquidityDelta', type: 'int256' }], + returns: ['BalanceDelta'], + }, + _resolveHookDelta: { + kind: 'internal', + args: [{ name: 'currency', type: 'Currency' }], + returns: [], + }, + _transferFromSenderToHook: { + kind: 'internal', + args: [ + { name: 'currency', type: 'Currency' }, + { name: 'amount', type: 'uint256' }, + { name: 'sender', type: 'address' }, + ], + returns: [], + }, + _transferFromHookToSender: { + kind: 'internal', + args: [ + { name: 'currency', type: 'Currency' }, + { name: 'amount', type: 'uint256' }, + { name: 'sender', type: 'address' }, + ], + returns: [], + }, + }), + }, + permissions: { + beforeInitialize: true, + afterInitialize: false, + beforeAddLiquidity: false, + afterAddLiquidity: false, + beforeRemoveLiquidity: false, + afterRemoveLiquidity: false, + beforeSwap: true, + afterSwap: true, + beforeDonate: false, + afterDonate: false, + beforeSwapReturnDelta: false, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false, + }, +}; + +export { ReHypothecationHook }; diff --git a/packages/core/uniswap-hooks/src/hooks/index.ts b/packages/core/uniswap-hooks/src/hooks/index.ts new file mode 100644 index 000000000..75873545c --- /dev/null +++ b/packages/core/uniswap-hooks/src/hooks/index.ts @@ -0,0 +1,129 @@ +import type { BaseFunction } from '@openzeppelin/wizard'; + +import { BaseHook } from './BaseHook'; +import { BaseAsyncSwap } from './BaseAsyncSwap'; +import { BaseCustomAccounting } from './BaseCustomAccounting'; +import { BaseCustomCurve } from './BaseCustomCurve'; +import { BaseDynamicFee } from './BaseDynamicFee'; +import { BaseOverrideFee } from './BaseOverrideFee'; +import { BaseDynamicAfterFee } from './BaseDynamicAfterFee'; +import { BaseHookFee } from './BaseHookFee'; +import { AntiSandwichHook } from './AntiSandwichHook'; +import { LimitOrderHook } from './LimitOrderHook'; +import { LiquidityPenaltyHook } from './LiquidityPenaltyHook'; +import { ReHypothecationHook } from './ReHypothecationHook'; + +export type HookCategory = 'Base' | 'Fee' | 'General'; + +/** + * Hook configuration object that defines the structure and behavior of each hook. + * @property name - The Smart Contract Name of the hook + * @property displayName - Human-readable name shown in the UI + * @property category - Classification category for organizing hooks + * @property tooltipText - Descriptive text displayed in tooltips (supports HTML) + * @property tooltipLink - URL to documentation for this hook + * @property permissions - Bitmap of hook lifecycle permissions + * @property functions - Map of relevant function definitions from the hook for it's configuration on the wizard. All public/external functions must be included + * in order to automatically get the `whenNotPaused` modifier added to them. + * @property disabledFunctions - Hook functions that are disabled in the hook, so that the {Pausable} option doesn't add the `whenNotPaused` modifier to them. + * i.e, `BaseCustomAccounting` disables `_beforeAddLiquidity` and `_beforeRemoveLiquidity`, and therefore they don't require pausability. + * @property shares - Configuration for hook shares functionality + * @property alreadyImplementsShares - Whether this hook implements already implements shares and doesn't require to inherit. + * @property inputs - Array of user-configurable input parameters for the wizard UI. + */ +export type Hook = { + name: HookName; + displayName: string; + category: HookCategory; + tooltipText: string; + tooltipLink: string; + permissions: Permissions; + functions: Record; + disabledFunctions: string[]; + shares: SharesConfig; + alreadyImplementsShares: boolean; + inputs: HookInput[]; +}; + +export const HOOKS = { + BaseHook, + BaseAsyncSwap, + BaseCustomAccounting, + BaseCustomCurve, + BaseDynamicFee, + BaseOverrideFee, + BaseDynamicAfterFee, + BaseHookFee, + AntiSandwichHook, + LiquidityPenaltyHook, + LimitOrderHook, + ReHypothecationHook, +} as const; + +export type HookName = keyof typeof HOOKS; +export type HookDictionary = Record; + +export const PERMISSIONS = [ + 'beforeInitialize', + 'afterInitialize', + 'beforeAddLiquidity', + 'beforeRemoveLiquidity', + 'afterAddLiquidity', + 'afterRemoveLiquidity', + 'beforeSwap', + 'afterSwap', + 'beforeDonate', + 'afterDonate', + 'beforeSwapReturnDelta', + 'afterSwapReturnDelta', + 'afterAddLiquidityReturnDelta', + 'afterRemoveLiquidityReturnDelta', +] as const; + +export type Permission = (typeof PERMISSIONS)[number]; +export type Permissions = Record; + +export const PAUSABLE_PERMISSIONS: Permission[] = [ + 'beforeSwap', + 'beforeAddLiquidity', + 'beforeRemoveLiquidity', + 'beforeDonate', +]; + +/** + * @property options - The type of shares to use + * @property name - The name of the shares + * @property symbol - The symbol of the shares + * @property uri - The URI of the shares + */ +export type Shares = { + options: false | 'ERC20' | 'ERC6909' | 'ERC1155'; + name?: string; + symbol?: string; + uri?: string; +}; + +/** + * @description Determines if the hook share type compatibility is specific and cannot be changed by the user + * @param sharesConfig - The type of shares to use + * @returns True if the shares type is ERC20, ERC6909, or ERC1155 + */ +export function specificSharesType(sharesConfig: SharesConfig): boolean { + return sharesConfig === 'ERC20' || sharesConfig === 'ERC6909' || sharesConfig === 'ERC1155'; +} + +export type SharesConfig = 'required' | 'optional' | 'disabled' | 'ERC20' | 'ERC6909' | 'ERC1155'; + +/** + * @property name - The name of the input parameter in camelCase + * @property label - The label of the input parameter in human-readable format + * @property value - The value of the input parameter + * @property type - The type of the input parameter + */ +export type HookInput = { + name: string; + label: string; + type: 'string' | 'number'; + placeholder?: string; + tooltipText?: string; +}; diff --git a/packages/core/uniswap-hooks/src/importPaths.json b/packages/core/uniswap-hooks/src/importPaths.json new file mode 100644 index 000000000..e3d2fb7d9 --- /dev/null +++ b/packages/core/uniswap-hooks/src/importPaths.json @@ -0,0 +1,33 @@ +{ + "BaseHook": "@openzeppelin/uniswap-hooks/base/BaseHook.sol", + "BaseAsyncSwap": "@openzeppelin/uniswap-hooks/base/BaseAsyncSwap.sol", + + "BaseCustomAccounting": "@openzeppelin/uniswap-hooks/base/BaseCustomAccounting.sol", + + "AddLiquidityParams": "parent", + "RemoveLiquidityParams": "parent", + + "BaseCustomCurve": "@openzeppelin/uniswap-hooks/base/BaseCustomCurve.sol", + + "BaseDynamicFee": "@openzeppelin/uniswap-hooks/fee/BaseDynamicFee.sol", + "BaseOverrideFee": "@openzeppelin/uniswap-hooks/fee/BaseOverrideFee.sol", + "BasedDynamicAfterFee": "@openzeppelin/uniswap-hooks/fee/BaseDynamicAfterFee.sol", + + "AntiSandwichHook": "@openzeppelin/uniswap-hooks/general/AntiSandwichHook.sol", + "LiquidityPenaltyHook": "@openzeppelin/uniswap-hooks/general/LiquidityPenaltyHook.sol", + + "LimitOrderHook": "@openzeppelin/uniswap-hooks/general/LimitOrderHook.sol", + "OrderIdLibrary": "@openzeppelin/uniswap-hooks/general/LimitOrderHook.sol", + + "BeforeSwapDelta": "@uniswap/v4-core/src/types/BeforeSwapDelta.sol", + "Hooks": "@uniswap/v4-core/src/libraries/Hooks.sol", + "IPoolManager": "@uniswap/v4-core/src/interfaces/IPoolManager.sol", + "PoolKey": "@uniswap/v4-core/src/types/PoolKey.sol", + "PoolId": "@uniswap/v4-core/src/types/PoolId.sol", + "Currency": "@uniswap/v4-core/src/types/Currency.sol", + "BalanceDelta": "@uniswap/v4-core/src/types/BalanceDelta.sol", + "SwapParams": "@uniswap/v4-core/src/types/PoolOperation.sol", + "ModifyLiquidityParams": "@uniswap/v4-core/src/types/PoolOperation.sol", + + "CurrencySettler": "@openzeppelin/uniswap-hooks/utils/CurrencySettler.sol" +} \ No newline at end of file diff --git a/packages/core/uniswap-hooks/src/index.ts b/packages/core/uniswap-hooks/src/index.ts new file mode 100644 index 000000000..78700f39e --- /dev/null +++ b/packages/core/uniswap-hooks/src/index.ts @@ -0,0 +1,15 @@ +export { buildGeneric, type GenericOptions, type KindedOptions } from './build-generic'; + +export { sanitizeKind, type Kind } from './kind'; + +export { hooks } from './api'; + +export { HOOKS, specificSharesType } from './hooks/'; + +export type { Hook, HookName, HookCategory, Shares, Permissions, Permission, HookInput, SharesConfig } from './hooks/'; + +export { type HooksOptions } from './hooks'; + +export { compatibleContractsSemver } from './utils/version'; + +export { printContract } from './print'; diff --git a/packages/core/uniswap-hooks/src/kind.ts b/packages/core/uniswap-hooks/src/kind.ts new file mode 100644 index 000000000..e623ef0fb --- /dev/null +++ b/packages/core/uniswap-hooks/src/kind.ts @@ -0,0 +1,27 @@ +import type { GenericOptions } from './build-generic'; + +export type Kind = GenericOptions['kind']; + +export function sanitizeKind(kind: unknown): Kind { + if (typeof kind === 'string') { + const lowered = kind.trim().toLowerCase(); + const sanitized = lowered.charAt(0).toUpperCase() + lowered.slice(1); + if (isKind(sanitized)) { + return sanitized; + } + } + return 'Hooks'; +} + +function isKind(value: Kind | T): value is Kind { + switch (value) { + case 'Hooks': + return true; + + default: { + // Static assert that we've checked all kinds. + const _: T = value; + return false; + } + } +} diff --git a/packages/core/uniswap-hooks/src/print.ts b/packages/core/uniswap-hooks/src/print.ts new file mode 100644 index 000000000..f4e8315a3 --- /dev/null +++ b/packages/core/uniswap-hooks/src/print.ts @@ -0,0 +1,12 @@ +import { printContract as printSolidityContract, type Contract } from '@openzeppelin/wizard'; +import type { HooksOptions } from './hooks'; +import { compatibleContractsSemver } from './utils/version'; + +export function printContract(contract: Contract, opts?: HooksOptions): string { + return printSolidityContract(contract, { + ...opts, + additionalCompatibleLibraries: [ + { name: 'OpenZeppelin Uniswap Hooks', path: '@openzeppelin/uniswap-hooks', version: compatibleContractsSemver }, + ], + }); +} diff --git a/packages/core/uniswap-hooks/src/test.ts b/packages/core/uniswap-hooks/src/test.ts new file mode 100644 index 000000000..bf596676d --- /dev/null +++ b/packages/core/uniswap-hooks/src/test.ts @@ -0,0 +1,34 @@ +import { promises as fs } from 'fs'; +import type { TestFn, ExecutionContext } from 'ava'; +import _test from 'ava'; +import hre from 'hardhat'; +import path from 'path'; +import { writeGeneratedSources } from './generate/sources'; +import type { KindedOptions } from './build-generic'; + +interface Context { + generatedSourcesPath: string; +} + +const test = _test as TestFn; + +test.serial('hooks result compiles', async t => { + await testCompile(t, 'Hooks'); +}); + +async function testCompile(t: ExecutionContext, kind: keyof KindedOptions) { + const generatedSourcesPath = path.join(hre.config.paths.sources, `generated`); + await fs.rm(generatedSourcesPath, { force: true, recursive: true }); + + await writeGeneratedSources(generatedSourcesPath, 'all', kind); + + // We only want to check that contracts compile and we don't care about any + // of the outputs. Setting empty outputSelection causes compilation to go a + // lot faster and not run out of memory. + for (const { settings } of hre.config.solidity.compilers) { + settings.outputSelection = {}; + } + + await hre.run('compile'); + t.pass(); +} diff --git a/packages/core/uniswap-hooks/src/utils/version.ts b/packages/core/uniswap-hooks/src/utils/version.ts new file mode 100644 index 000000000..4e8ec0955 --- /dev/null +++ b/packages/core/uniswap-hooks/src/utils/version.ts @@ -0,0 +1,4 @@ +/** + * Semantic version string representing of the minimum compatible version of Contracts to display in output. + */ +export const compatibleContractsSemver = '^1.0.0'; diff --git a/packages/core/uniswap-hooks/tsconfig.json b/packages/core/uniswap-hooks/tsconfig.json new file mode 100644 index 000000000..e51988c6e --- /dev/null +++ b/packages/core/uniswap-hooks/tsconfig.json @@ -0,0 +1,16 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "incremental": true, + "module": "commonjs", + "sourceMap": true, + "declaration": true, + "declarationMap": true, + "skipLibCheck": true, + "rootDir": "src", + "outDir": "dist" + }, + "include": [ + "src/**/*" + ] +} diff --git a/packages/ui/public/cairo.html b/packages/ui/public/cairo.html index 01bcff71a..a85c1c3fe 100644 --- a/packages/ui/public/cairo.html +++ b/packages/ui/public/cairo.html @@ -75,6 +75,7 @@ stellarStellar stylusStylus + uniswap-hooksUniswap Hooks
diff --git a/packages/ui/public/icons/uniswap-hooks.svg b/packages/ui/public/icons/uniswap-hooks.svg new file mode 100644 index 000000000..3c5cc5d1d --- /dev/null +++ b/packages/ui/public/icons/uniswap-hooks.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/ui/public/icons/uniswap-hooks_active.svg b/packages/ui/public/icons/uniswap-hooks_active.svg new file mode 100644 index 000000000..78675fc9b --- /dev/null +++ b/packages/ui/public/icons/uniswap-hooks_active.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/packages/ui/public/index.html b/packages/ui/public/index.html index 2a61b50fa..b9b9c1a98 100644 --- a/packages/ui/public/index.html +++ b/packages/ui/public/index.html @@ -99,6 +99,7 @@ cairoCairo stellarStellar stylusStylus + uniswap-hooksUniswap Hooks
diff --git a/packages/ui/public/stellar.html b/packages/ui/public/stellar.html index c2d355f4f..33d841c1c 100644 --- a/packages/ui/public/stellar.html +++ b/packages/ui/public/stellar.html @@ -67,6 +67,7 @@ cairoCairo stellarStellar stylusStylus + uniswap-hooksUniswap Hooks
diff --git a/packages/ui/public/stylus.html b/packages/ui/public/stylus.html index 2c47c85c1..ec0a6c70d 100644 --- a/packages/ui/public/stylus.html +++ b/packages/ui/public/stylus.html @@ -67,6 +67,7 @@ cairoCairo stellarStellar stylusStylus + uniswap-hooksUniswap Hooks
diff --git a/packages/ui/public/uniswap-hooks.html b/packages/ui/public/uniswap-hooks.html new file mode 100644 index 000000000..447a88d91 --- /dev/null +++ b/packages/ui/public/uniswap-hooks.html @@ -0,0 +1,152 @@ + + + + + + OpenZeppelin Uniswap Hooks Wizard + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+ Forum + Docs + GitHub OpenZeppelin + Twitter/X +
+
+ + + +
+ +
+ + + + + + + + + + + + + + + + diff --git a/packages/ui/src/common/ExpandableSection.svelte b/packages/ui/src/common/ExpandableSection.svelte new file mode 100644 index 000000000..b73fe69ac --- /dev/null +++ b/packages/ui/src/common/ExpandableSection.svelte @@ -0,0 +1,30 @@ + + + + + diff --git a/packages/ui/src/common/ParentExpandableSection.svelte b/packages/ui/src/common/ParentExpandableSection.svelte index bd1ce9d94..fbba1fbfa 100644 --- a/packages/ui/src/common/ParentExpandableSection.svelte +++ b/packages/ui/src/common/ParentExpandableSection.svelte @@ -13,7 +13,7 @@ import ChevronDown from './icons/ChevronDown.svelte'; export let label: string; - export let type: 'checkbox' | 'toggleradio'; + export let type: 'checkbox' | 'toggleradio' | 'section'; export let checkboxChecked: boolean | undefined = undefined; @@ -60,17 +60,19 @@