Skip to content

Commit

Permalink
Merge branch 'feature/bulk-renew' into fix/return-when-zero-rns-commi…
Browse files Browse the repository at this point in the history
…ssion
  • Loading branch information
TuDo1403 authored Nov 5, 2024
2 parents d26bef2 + 520215f commit 9bfd059
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,9 @@ contract Migration__20231106_SubmitReservedNames is Migration {
address[] memory tos;
string[] memory labels;
(tos, labels) = _parseData("./script/20231106-param-prelaunch/data/finalReservedNames.json");
mintBatch(multicall, duration, rns, resolver, tos, labels);
// mintBatch(multicall, duration, rns, resolver, tos, labels);
}

function mintBatch(
OwnedMulticaller multicall,
uint64 duration,
RNSUnified rns,
address resolver,
address[] memory tos,
string[] memory labels
) public {
vm.broadcast(config.getSender());
multicall.multiMint(rns, LibRNSDomain.RON_ID, resolver, duration, tos, labels);
}

function _parseData(string memory path) internal view returns (address[] memory tos, string[] memory labels) {
string memory raw = vm.readFile(path);
Expand Down
76 changes: 52 additions & 24 deletions src/utils/OwnedMulticaller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,75 @@
pragma solidity ^0.8.19;

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { INSUnified } from "../interfaces/INSUnified.sol";
import { ErrorHandler } from "../libraries/ErrorHandler.sol";
import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import { IERC721Receiver } from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import { IERC1155Receiver } from "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";

contract OwnedMulticaller is Ownable {
contract OwnedMulticaller is Ownable, IERC721Receiver, IERC1155Receiver {
using ErrorHandler for bool;

constructor(address owner_) {
require(owner_ != address(0), "owner_ == address(0x0)");
_transferOwnership(owner_);
}

function kill() external onlyOwner {
selfdestruct(payable(_msgSender()));
}
require(owner_ != address(0), "OwnedMulticaller: owner_ is null");

function multiMint(
INSUnified rns,
uint256 parentId,
address resolver,
uint64 duration,
address[] calldata tos,
string[] calldata labels
) external onlyOwner {
for (uint256 i; i < labels.length; ++i) {
rns.mint(parentId, labels[i], resolver, tos[i], duration);
}
_transferOwnership(owner_);
}

/**
* @dev Execute multiple calls in a single transaction.
* @param tos The addresses to call.
* @param callDatas The call data for each call.
* @param values The value to send for each call.
* @return results The results of each call.
* @return returnDatas The return data of each call.
*/
function multicall(address[] calldata tos, bytes[] calldata callDatas, uint256[] calldata values)
external
payable
onlyOwner
returns (bool[] memory results, bytes[] memory returnDatas)
{
require(tos.length == callDatas.length && tos.length == values.length, "invalid length");
results = new bool[](tos.length);
returnDatas = new bytes[](tos.length);
uint256 length = tos.length;
require(length == callDatas.length && length == values.length, "OwnedMulticaller: mismatch length");
results = new bool[](length);
returnDatas = new bytes[](length);

for (uint256 i; i < tos.length; ++i) {
for (uint256 i; i < length; ++i) {
(results[i], returnDatas[i]) = tos[i].call{ value: values[i] }(callDatas[i]);
results[i].handleRevert(returnDatas[i]);
}
}

/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool) {
return interfaceId == type(IERC165).interfaceId || interfaceId == type(IERC721Receiver).interfaceId
|| interfaceId == type(IERC1155Receiver).interfaceId;
}

/**
* @dev See {IERC721Receiver-onERC721Received}.
*/
function onERC721Received(address, address, uint256, bytes calldata) external pure returns (bytes4) {
return msg.sig;
}

/**
* @dev See {IERC1155Receiver-onERC1155Received}.
*/
function onERC1155BatchReceived(address, address, uint256[] calldata, uint256[] calldata, bytes calldata)
external
pure
returns (bytes4)
{
return msg.sig;
}

/**
* @dev See {IERC1155Receiver-onERC1155Received}.
*/
function onERC1155Received(address, address, uint256, uint256, bytes calldata) external pure returns (bytes4) {
return msg.sig;
}
}

0 comments on commit 9bfd059

Please sign in to comment.