|
2 | 2 | pragma solidity ^0.8.19;
|
3 | 3 |
|
4 | 4 | import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
|
5 |
| -import { INSUnified } from "../interfaces/INSUnified.sol"; |
6 | 5 | import { ErrorHandler } from "../libraries/ErrorHandler.sol";
|
| 6 | +import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol"; |
| 7 | +import { IERC721Receiver } from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol"; |
| 8 | +import { IERC1155Receiver } from "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol"; |
7 | 9 |
|
8 |
| -contract OwnedMulticaller is Ownable { |
| 10 | +contract OwnedMulticaller is Ownable, IERC721Receiver, IERC1155Receiver { |
9 | 11 | using ErrorHandler for bool;
|
10 | 12 |
|
11 | 13 | constructor(address owner_) {
|
12 |
| - require(owner_ != address(0), "owner_ == address(0x0)"); |
13 |
| - _transferOwnership(owner_); |
14 |
| - } |
15 |
| - |
16 |
| - function kill() external onlyOwner { |
17 |
| - selfdestruct(payable(_msgSender())); |
18 |
| - } |
| 14 | + require(owner_ != address(0), "OwnedMulticaller: owner_ is null"); |
19 | 15 |
|
20 |
| - function multiMint( |
21 |
| - INSUnified rns, |
22 |
| - uint256 parentId, |
23 |
| - address resolver, |
24 |
| - uint64 duration, |
25 |
| - address[] calldata tos, |
26 |
| - string[] calldata labels |
27 |
| - ) external onlyOwner { |
28 |
| - for (uint256 i; i < labels.length; ++i) { |
29 |
| - rns.mint(parentId, labels[i], resolver, tos[i], duration); |
30 |
| - } |
| 16 | + _transferOwnership(owner_); |
31 | 17 | }
|
32 | 18 |
|
| 19 | + /** |
| 20 | + * @dev Execute multiple calls in a single transaction. |
| 21 | + * @param tos The addresses to call. |
| 22 | + * @param callDatas The call data for each call. |
| 23 | + * @param values The value to send for each call. |
| 24 | + * @return results The results of each call. |
| 25 | + * @return returnDatas The return data of each call. |
| 26 | + */ |
33 | 27 | function multicall(address[] calldata tos, bytes[] calldata callDatas, uint256[] calldata values)
|
34 | 28 | external
|
35 | 29 | payable
|
36 | 30 | onlyOwner
|
37 | 31 | returns (bool[] memory results, bytes[] memory returnDatas)
|
38 | 32 | {
|
39 |
| - require(tos.length == callDatas.length && tos.length == values.length, "invalid length"); |
40 |
| - results = new bool[](tos.length); |
41 |
| - returnDatas = new bytes[](tos.length); |
| 33 | + uint256 length = tos.length; |
| 34 | + require(length == callDatas.length && length == values.length, "OwnedMulticaller: mismatch length"); |
| 35 | + results = new bool[](length); |
| 36 | + returnDatas = new bytes[](length); |
42 | 37 |
|
43 |
| - for (uint256 i; i < tos.length; ++i) { |
| 38 | + for (uint256 i; i < length; ++i) { |
44 | 39 | (results[i], returnDatas[i]) = tos[i].call{ value: values[i] }(callDatas[i]);
|
45 | 40 | results[i].handleRevert(returnDatas[i]);
|
46 | 41 | }
|
47 | 42 | }
|
| 43 | + |
| 44 | + /** |
| 45 | + * @dev See {IERC165-supportsInterface}. |
| 46 | + */ |
| 47 | + function supportsInterface(bytes4 interfaceId) external view returns (bool) { |
| 48 | + return interfaceId == type(IERC165).interfaceId || interfaceId == type(IERC721Receiver).interfaceId |
| 49 | + || interfaceId == type(IERC1155Receiver).interfaceId; |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * @dev See {IERC721Receiver-onERC721Received}. |
| 54 | + */ |
| 55 | + function onERC721Received(address, address, uint256, bytes calldata) external pure returns (bytes4) { |
| 56 | + return msg.sig; |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * @dev See {IERC1155Receiver-onERC1155Received}. |
| 61 | + */ |
| 62 | + function onERC1155BatchReceived(address, address, uint256[] calldata, uint256[] calldata, bytes calldata) |
| 63 | + external |
| 64 | + pure |
| 65 | + returns (bytes4) |
| 66 | + { |
| 67 | + return msg.sig; |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * @dev See {IERC1155Receiver-onERC1155Received}. |
| 72 | + */ |
| 73 | + function onERC1155Received(address, address, uint256, uint256, bytes calldata) external pure returns (bytes4) { |
| 74 | + return msg.sig; |
| 75 | + } |
48 | 76 | }
|
0 commit comments