-
Notifications
You must be signed in to change notification settings - Fork 7
/
KYCHook.sol
86 lines (76 loc) · 2.71 KB
/
KYCHook.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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.19;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IPoolManager} from "@uniswap/v4-core/contracts/interfaces/IPoolManager.sol";
import {Hooks} from "@uniswap/v4-core/contracts/libraries/Hooks.sol";
import {BaseHook} from "./BaseHook.sol";
/**
* @title An interface for checking whether an address has a valid kycNFT token
*/
interface IKycValidity {
/// @dev Check whether a given address has a valid kycNFT token
/// @param _addr Address to check for tokens
/// @return valid Whether the address has a valid token
function hasValidToken(address _addr) external view returns (bool valid);
}
/**
* Only KYC'ed people can trade on the V4 hook'ed pool.
* Caveat: Relies on external oracle for info on an address's KYC status.
*/
contract KYCSwaps is BaseHook, Ownable {
IKycValidity public kycValidity;
address private _preKycValidity;
uint256 private _setKycValidityReqTimestamp;
constructor(
IPoolManager _poolManager,
address _kycValidity
) BaseHook(_poolManager) {
kycValidity = IKycValidity(_kycValidity);
}
modifier onlyPermitKYC() {
require(
kycValidity.hasValidToken(tx.origin),
"Swaps available for valid KYC token holders"
);
_;
}
/// Sorta timelock
function setKycValidity(address _kycValidity) external onlyOwner {
if (
block.timestamp - _setKycValidityReqTimestamp >= 7 days &&
_kycValidity == _preKycValidity
) {
kycValidity = IKycValidity(_kycValidity);
} else {
_preKycValidity = _kycValidity;
_setKycValidityReqTimestamp = block.timestamp;
}
}
function getHooksCalls() public pure override returns (Hooks.Calls memory) {
return
Hooks.Calls({
beforeInitialize: false,
afterInitialize: false,
beforeModifyPosition: true,
afterModifyPosition: false,
beforeSwap: true,
afterSwap: false,
beforeDonate: false,
afterDonate: false
});
}
function beforeModifyPosition(
address,
IPoolManager.PoolKey calldata,
IPoolManager.ModifyPositionParams calldata
) external view override poolManagerOnly onlyPermitKYC returns (bytes4) {
return BaseHook.beforeModifyPosition.selector;
}
function beforeSwap(
address,
IPoolManager.PoolKey calldata,
IPoolManager.SwapParams calldata
) external view override poolManagerOnly onlyPermitKYC returns (bytes4) {
return BaseHook.beforeSwap.selector;
}
}