Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bulk-renew): implement add-bulk-renew #278

Open
wants to merge 16 commits into
base: feature/bulk-renew
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
huyhuynh3103 marked this conversation as resolved.
Show resolved Hide resolved
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
TuDo1403 marked this conversation as resolved.
Show resolved Hide resolved
if (id >= (id = computeId(names[i]))) revert InvalidOrderOfNames();

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();
TuDo1403 marked this conversation as resolved.
Show resolved Hide resolved
TuDo1403 marked this conversation as resolved.
Show resolved Hide resolved

/**
* @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 array of durations for the renewal.
*/
function bulkRenew(string[] calldata names, uint64[] calldata durations) external payable;

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