-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
131 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
412696 | ||
390028 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
206962 | ||
184294 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
154763 | ||
133445 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
879542 | ||
896690 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
200095 | ||
177393 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
379287 | ||
362063 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
112303 | ||
93791 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
153038 | ||
131720 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.20; | ||
|
||
import {CurrencyLibrary, Currency} from "@uniswap/v4-core/src/types/Currency.sol"; | ||
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol"; | ||
import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol"; | ||
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol"; | ||
import {PoolTestBase} from "@uniswap/v4-core/src/test/PoolTestBase.sol"; | ||
import {Test} from "forge-std/Test.sol"; | ||
|
||
contract HookEnabledSwapRouter is Test, PoolTestBase { | ||
using CurrencyLibrary for Currency; | ||
|
||
constructor(IPoolManager _manager) PoolTestBase(_manager) {} | ||
|
||
error NoSwapOccurred(); | ||
|
||
struct CallbackData { | ||
address sender; | ||
TestSettings testSettings; | ||
PoolKey key; | ||
IPoolManager.SwapParams params; | ||
bytes hookData; | ||
} | ||
|
||
struct TestSettings { | ||
bool withdrawTokens; | ||
bool settleUsingTransfer; | ||
} | ||
|
||
function swap( | ||
PoolKey memory key, | ||
IPoolManager.SwapParams memory params, | ||
TestSettings memory testSettings, | ||
bytes memory hookData | ||
) external payable returns (BalanceDelta delta) { | ||
delta = abi.decode( | ||
manager.lock(abi.encode(CallbackData(msg.sender, testSettings, key, params, hookData))), (BalanceDelta) | ||
); | ||
|
||
uint256 ethBalance = address(this).balance; | ||
if (ethBalance > 0) CurrencyLibrary.NATIVE.transfer(msg.sender, ethBalance); | ||
} | ||
|
||
function lockAcquired(bytes calldata rawData) external returns (bytes memory) { | ||
require(msg.sender == address(manager)); | ||
|
||
CallbackData memory data = abi.decode(rawData, (CallbackData)); | ||
|
||
BalanceDelta delta = manager.swap(data.key, data.params, data.hookData); | ||
|
||
// Make sure youve added liquidity to the test pool! | ||
if (BalanceDelta.unwrap(delta) == 0) revert NoSwapOccurred(); | ||
|
||
if (data.params.zeroForOne) { | ||
_settle(data.key.currency0, data.sender, delta.amount0(), data.testSettings.settleUsingTransfer); | ||
_take(data.key.currency1, data.sender, delta.amount1(), data.testSettings.withdrawTokens); | ||
} else { | ||
_settle(data.key.currency1, data.sender, delta.amount1(), data.testSettings.settleUsingTransfer); | ||
_take(data.key.currency0, data.sender, delta.amount0(), data.testSettings.withdrawTokens); | ||
} | ||
|
||
return abi.encode(delta); | ||
} | ||
} |