generated from uniswapfoundation/v4-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TradingHours.sol
48 lines (39 loc) · 1.51 KB
/
TradingHours.sol
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;
import {Hooks} from "@uniswap/v4-core/contracts/libraries/Hooks.sol";
import {BaseHook} from "v4-periphery/BaseHook.sol";
import {IPoolManager} from "@uniswap/v4-core/contracts/interfaces/IPoolManager.sol";
import {PoolId} from "@uniswap/v4-core/contracts/libraries/PoolId.sol";
import {BalanceDelta} from "@uniswap/v4-core/contracts/types/BalanceDelta.sol";
contract TradingHours is BaseHook {
using PoolId for IPoolManager.PoolKey;
uint256 public constant openingTime = 60 * 60 * 8; // 08:00
uint256 public constant closingTime = 60 * 60 * 16; // 16:00
constructor(IPoolManager _poolManager) BaseHook(_poolManager) {}
function getHooksCalls() public pure override returns (Hooks.Calls memory) {
return Hooks.Calls({
beforeInitialize: false,
afterInitialize: false,
beforeModifyPosition: false,
afterModifyPosition: false,
beforeSwap: true,
afterSwap: false,
beforeDonate: false,
afterDonate: false
});
}
function beforeSwap(address, IPoolManager.PoolKey calldata, IPoolManager.SwapParams calldata)
external
view
override
returns (bytes4)
{
uint256 time = block.timestamp % (60 * 60 * 24);
require(
time >= openingTime &&
time < closingTime,
"TradingHours.beforeSwap: market closed"
);
return BaseHook.beforeSwap.selector;
}
}