-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPassedInDataExample.sol
More file actions
73 lines (62 loc) · 2.34 KB
/
PassedInDataExample.sol
File metadata and controls
73 lines (62 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import {IClankerHookV2PoolExtension} from
"@clanker-v4/src/hooks/interfaces/IClankerHookV2PoolExtension.sol";
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";
import {PoolId} from "@uniswap/v4-core/src/types/PoolId.sol";
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
// example pool extension that accesses passed in data in the setup and swap phases
contract PassedInDataExample is IClankerHookV2PoolExtension {
error InvalidFoo();
error InvalidBar();
uint256 constant REQUIRED_FOO = 42;
uint256 constant REQUIRED_BAR = 43;
// example data to pass in during initialization
struct PoolInitializationData {
uint256 foo;
}
// example data to pass in during a swap
struct PoolSwapData {
uint256 bar;
}
modifier onlyHook(PoolKey calldata poolKey) {
if (msg.sender != address(poolKey.hooks)) {
revert OnlyHook();
}
_;
}
function initializePreLockerSetup(
PoolKey calldata poolKey,
bool clankerIsToken0,
bytes calldata poolExtensionData
) external onlyHook(poolKey) {
// check that the foo is the required foo
if (abi.decode(poolExtensionData, (PoolInitializationData)).foo != REQUIRED_FOO) {
// this will prevent the token and pool from being deployed
revert InvalidFoo();
}
}
function initializePostLockerSetup(PoolKey calldata poolKey, address lpLocker, bool)
external
onlyHook(poolKey)
{}
// called after a swap has completed
function afterSwap(
PoolKey calldata poolKey,
IPoolManager.SwapParams calldata,
BalanceDelta delta,
bool,
bytes calldata swapData
) external onlyHook(poolKey) {
// try to decode the swap data
if (abi.decode(swapData, (PoolSwapData)).bar != REQUIRED_BAR) {
// note: this doesn't revert the swap, it just logs an error
revert InvalidBar();
}
}
// implements the IClankerHookV2PoolExtension interface
function supportsInterface(bytes4 interfaceId) external pure returns (bool) {
return interfaceId == type(IClankerHookV2PoolExtension).interfaceId;
}
}