-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSetCollectionCollateralFilter.sol
112 lines (92 loc) · 3.12 KB
/
SetCollectionCollateralFilter.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.25;
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "./CollateralFilter.sol";
/**
* @title Set Collection Collateral Filter
* @author MetaStreet Labs
*/
contract SetCollectionCollateralFilter is CollateralFilter {
using EnumerableSet for EnumerableSet.UintSet;
/**************************************************************************/
/* State */
/**************************************************************************/
/**
* @notice Supported token
*/
address private _token;
/**
* @notice Set of supported token IDs
*/
EnumerableSet.UintSet private _tokenIds;
/**************************************************************************/
/* Initializer */
/**************************************************************************/
/**
* @notice SetCollectionCollateralFilter initializer
*/
function _initialize(address token, uint256[] memory tokenIds_) internal {
/* Validate root and node count */
if (tokenIds_.length == 0) revert InvalidCollateralFilterParameters();
/* Set supported token */
_token = token;
/* Add each token ID to set of token IDs */
for (uint256 i; i < tokenIds_.length; i++) {
_tokenIds.add(tokenIds_[i]);
}
}
/**************************************************************************/
/* Getters */
/**************************************************************************/
/**
* @inheritdoc CollateralFilter
*/
function COLLATERAL_FILTER_NAME() external pure override returns (string memory) {
return "SetCollectionCollateralFilter";
}
/**
* @inheritdoc CollateralFilter
*/
function COLLATERAL_FILTER_VERSION() external pure override returns (string memory) {
return "1.0";
}
/**
* @notice Get collateral token
* @return Collateral token contract
*/
function collateralToken() public view override returns (address) {
return _token;
}
/**
* @inheritdoc CollateralFilter
*/
function collateralTokens() external view override returns (address[] memory) {
address[] memory tokens = new address[](1);
tokens[0] = _token;
return tokens;
}
/**
* @notice Get collateral token IDs
* @return Collateral token IDs
*/
function collateralTokenIds() external view returns (uint256[] memory) {
return _tokenIds.values();
}
/**************************************************************************/
/* Implementation */
/**************************************************************************/
/**
* @inheritdoc CollateralFilter
*/
function _collateralSupported(
address token,
uint256 tokenId,
uint256,
bytes calldata
) internal view override returns (bool) {
/* Validate token supported */
if (token != _token) return false;
/* Validate token ID is in set of token IDs */
return _tokenIds.contains(tokenId);
}
}