Skip to content

Commit

Permalink
feat(RONRegistrarController): add bulkRenew to batch extend duration …
Browse files Browse the repository at this point in the history
…for rns names
  • Loading branch information
TuDo1403 committed Oct 16, 2024
1 parent c32e8f6 commit e96aee3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/RONRegistrarController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,35 @@ contract RONRegistrarController is
_transferRONToTreasury();
}

/**
* @inheritdoc IRONRegistrarController
*/
function bulkRenew(string[] calldata names, uint64[] calldata durations) external payable whenNotPaused nonReentrant {
uint256 length = names.length;
if (length == 0 || length != durations.length) revert InvalidArrayLength();

uint256 id;
uint256 totalPrice;
uint64 expiryTime;

for (uint256 i; i < length; ++i) {
(, uint256 ronPrice) = rentPrice(names[i], durations[i]);
totalPrice += ronPrice;

// Require id to be > previous id to prevent duplicate names
require(id < (id = computeId(names[i])), "BulkRenew: Invalid order of names");

expiryTime = _rnsUnified.renew(id, durations[i]);
emit NameRenewed(names[i], id, ronPrice, expiryTime);
}

if (msg.value < totalPrice) revert InsufficientValue();
uint256 remainAmount = msg.value - totalPrice;

if (remainAmount != 0) RONTransferHelper.safeTransfer(payable(_msgSender()), remainAmount);
_transferRONToTreasury();
}

/**
* @inheritdoc IRONRegistrarController
*/
Expand Down
13 changes: 13 additions & 0 deletions src/interfaces/IRONRegistrarController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ interface IRONRegistrarController {
error InvalidArrayLength();
/// @dev Thrown when treasury address is set to null
error NullAddress();
/// @dev Thrown when the names is not sorted in ascending order
error InvalidOrderOfNames();

/**
* @dev Emitted when the min registration duration is updated.
Expand Down Expand Up @@ -176,6 +178,17 @@ interface IRONRegistrarController {
*/
function renew(string calldata name, uint64 duration) external payable;

/**
* @dev Renew multiple names in a single transaction.
* Requirements:
* - `names` and `duration` arrays must have the same length.
* - The caller must provide enough value to cover the total renewal cost.
* - `names` must be sorted in ascending order.
* @param names The array of names to be renewed.
* @param duration The duration of the renewal.
*/
function bulkRenew(string[] calldata names, uint64 duration) external payable;

/**
* @dev Registers a protected name.
*
Expand Down

0 comments on commit e96aee3

Please sign in to comment.