generated from NomicFoundation/hardhat-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 9
/
ERC1155ThresholdMech.sol
48 lines (43 loc) · 1.35 KB
/
ERC1155ThresholdMech.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: LGPL-3.0
pragma solidity ^0.8.12;
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import "./base/ThresholdMech.sol";
import "./libraries/MinimalProxyStore.sol";
/**
* @dev A Mech that is operated by any holder of a defined set of minimum ERC1155 token balances
*/
contract ERC1155ThresholdMech is ThresholdMech {
function threshold()
public
view
returns (
address token,
uint256[] memory tokenIds,
uint256[] memory minBalances,
uint256 minTotalBalance
)
{
return
abi.decode(
MinimalProxyStore.getContext(address(this)),
(address, uint256[], uint256[], uint256)
);
}
function isOperator(address signer) public view override returns (bool) {
(
address token,
uint256[] memory tokenIds,
uint256[] memory minBalances,
uint256 minTotalBalance
) = threshold();
uint256 balanceSum = 0;
for (uint256 i = 0; i < tokenIds.length; i++) {
uint256 balance = IERC1155(token).balanceOf(signer, tokenIds[i]);
if (balance < minBalances[i]) {
return false;
}
balanceSum += balance;
}
return balanceSum >= minTotalBalance;
}
}