diff --git a/src/base/BaseNoOp.sol b/src/base/BaseAsyncSwap.sol similarity index 83% rename from src/base/BaseNoOp.sol rename to src/base/BaseAsyncSwap.sol index 27e3133..f4be2e8 100644 --- a/src/base/BaseNoOp.sol +++ b/src/base/BaseAsyncSwap.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Uniswap Hooks (last updated v0.1.0) (src/base/BaseNoOp.sol) +// OpenZeppelin Uniswap Hooks (last updated v0.1.0) (src/base/BaseAsyncSwap.sol) pragma solidity ^0.8.24; @@ -13,19 +13,19 @@ import {SafeCast} from "v4-core/src/libraries/SafeCast.sol"; import {CurrencySettler} from "src/lib/CurrencySettler.sol"; /** - * @dev Base implementation for no-op hooks, which skips the v3-like swap implementation of the `PoolManager` + * @dev Base implementation for async swaps, which skip the v3-like swap implementation of the `PoolManager` * by taking the full swap input amount and returning a delta that nets out the specified amount to 0. * * This base hook allows developers to implement arbitrary logic to handle swaps, including use-cases like * asynchronous swaps and custom swap-ordering. However, given this flexibility, developers should ensure * that any logic implemented interacts safely with the `PoolManager` and works correctly. * - * In order to no-op the swap, the hook mints ERC-6909 claim tokens for the specified currency and amount. + * In order to handle async swaps, the hook mints ERC-6909 claim tokens for the specified currency and amount. * Inheriting contracts are free to handle these claim tokens as necessary, which can be redeemed for the * underlying currency by using the `settle` function from the `CurrencySettler` library. * - * IMPORTANT: No-op hooks only support exact-input swaps. For exact-output swaps, the hook will not act - * as a no-op, so they would be processed with the `PoolManager`'s implementation. + * IMPORTANT: The hook only supports async exact-input swaps. Exact-output swaps will be processed normally + * by the `PoolManager`. * * WARNING: This is experimental software and is provided on an "as is" and "as available" basis. We do * not give any warranties and will not be liable for any losses incurred through any use of this code @@ -33,7 +33,7 @@ import {CurrencySettler} from "src/lib/CurrencySettler.sol"; * * _Available since v0.1.0_ */ -abstract contract BaseNoOp is BaseHook { +abstract contract BaseAsyncSwap is BaseHook { using SafeCast for uint256; using CurrencySettler for Currency; @@ -43,7 +43,8 @@ abstract contract BaseNoOp is BaseHook { constructor(IPoolManager _poolManager) BaseHook(_poolManager) {} /** - * @dev No-op exact-input swaps by returning a delta that nets out the specified amount to 0. + * @dev Skip the v3-like swap implementation of the `PoolManager` by returning a delta that nets out the + * specified amount to 0 to enable asynchronous swaps. */ function _beforeSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata params, bytes calldata) internal @@ -51,7 +52,7 @@ abstract contract BaseNoOp is BaseHook { override returns (bytes4, BeforeSwapDelta, uint24) { - // No-op is only possible on exact-input swaps, so exact-output swaps are executed by the `PoolManager` as normal + // Async swaps are only possible on exact-input swaps, so exact-output swaps are executed by the `PoolManager` as normal if (params.amountSpecified < 0) { // Determine which currency is specified Currency specified = params.zeroForOne ? key.currency0 : key.currency1; diff --git a/src/base/README.adoc b/src/base/README.adoc index be14d0d..07ac5e9 100644 --- a/src/base/README.adoc +++ b/src/base/README.adoc @@ -8,7 +8,7 @@ Base contracts for building secure and modular Uniswap hooks, providing core fun * {BaseCustomAccounting}: Base hook implementation for custom accounting, including support for swaps and liquidity management. * {BaseCustomCurve}: Base hook implementation for custom curves. * {BaseHook}: Base implementation for hooks. - * {BaseNoOp}: Base hook implementation for no-op hooks. + * {BaseAsyncSwap}: Base hook implementation for asynchronous swaps. == Hooks @@ -18,4 +18,4 @@ Base contracts for building secure and modular Uniswap hooks, providing core fun {{BaseHook}} -{{BaseNoOp}} +{{BaseAsyncSwap}} diff --git a/test/base/BaseNoOp.t.sol b/test/base/BaseAsyncSwap.t.sol similarity index 93% rename from test/base/BaseNoOp.t.sol rename to test/base/BaseAsyncSwap.t.sol index f8fcba8..2896951 100644 --- a/test/base/BaseNoOp.t.sol +++ b/test/base/BaseAsyncSwap.t.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.26; import "forge-std/Test.sol"; import {Deployers} from "v4-core/test/utils/Deployers.sol"; -import {BaseNoOpMock} from "test/mocks/BaseNoOpMock.sol"; +import {BaseAsyncSwapMock} from "test/mocks/BaseAsyncSwapMock.sol"; import {IHooks} from "v4-core/src/interfaces/IHooks.sol"; import {Hooks} from "v4-core/src/libraries/Hooks.sol"; import {PoolSwapTest} from "v4-core/src/test/PoolSwapTest.sol"; @@ -17,11 +17,11 @@ import {ProtocolFeeLibrary} from "v4-core/src/libraries/ProtocolFeeLibrary.sol"; import {PoolId} from "v4-core/src/types/PoolId.sol"; import {Pool} from "v4-core/src/libraries/Pool.sol"; -contract BaseNoOpTest is Test, Deployers { +contract BaseAsyncSwapTest is Test, Deployers { using StateLibrary for IPoolManager; using ProtocolFeeLibrary for uint16; - BaseNoOpMock hook; + BaseAsyncSwapMock hook; event Swap( PoolId indexed poolId, @@ -37,8 +37,8 @@ contract BaseNoOpTest is Test, Deployers { function setUp() public { deployFreshManagerAndRouters(); - hook = BaseNoOpMock(address(uint160(Hooks.BEFORE_SWAP_FLAG | Hooks.BEFORE_SWAP_RETURNS_DELTA_FLAG))); - deployCodeTo("test/mocks/BaseNoOpMock.sol:BaseNoOpMock", abi.encode(manager), address(hook)); + hook = BaseAsyncSwapMock(address(uint160(Hooks.BEFORE_SWAP_FLAG | Hooks.BEFORE_SWAP_RETURNS_DELTA_FLAG))); + deployCodeTo("test/mocks/BaseAsyncSwapMock.sol:BaseAsyncSwapMock", abi.encode(manager), address(hook)); deployMintAndApprove2Currencies(); (key,) = initPoolAndAddLiquidity( @@ -87,7 +87,7 @@ contract BaseNoOpTest is Test, Deployers { uint256 balance0After = currency0.balanceOfSelf(); uint256 balance1After = currency1.balanceOfSelf(); - // no-op is not applied to exact-output swaps + // async swaps are not applied to exact-output swaps assertEq(balance0Before - balance0After, 101); assertEq(balance1After - balance1Before, 100); } diff --git a/test/mocks/BaseAsyncSwapMock.sol b/test/mocks/BaseAsyncSwapMock.sol new file mode 100644 index 0000000..60cb1d4 --- /dev/null +++ b/test/mocks/BaseAsyncSwapMock.sol @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.26; + +import "src/base/BaseAsyncSwap.sol"; + +contract BaseAsyncSwapMock is BaseAsyncSwap { + constructor(IPoolManager _poolManager) BaseAsyncSwap(_poolManager) {} + + // Exclude from coverage report + function test() public {} +} diff --git a/test/mocks/BaseNoOpMock.sol b/test/mocks/BaseNoOpMock.sol deleted file mode 100644 index 68d7dd5..0000000 --- a/test/mocks/BaseNoOpMock.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.26; - -import "src/base/BaseNoOp.sol"; - -contract BaseNoOpMock is BaseNoOp { - constructor(IPoolManager _poolManager) BaseNoOp(_poolManager) {} - - // Exclude from coverage report - function test() public {} -}