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 renewal updates/optimisations #351

Open
wants to merge 9 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
82 changes: 0 additions & 82 deletions contracts/ethregistrar/BulkRenewal.sol

This file was deleted.

2 changes: 1 addition & 1 deletion contracts/ethregistrar/IETHRegistrarController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface IETHRegistrarController {
uint256
) external view returns (IPriceOracle.Price memory);

function available(string memory) external returns (bool);
function available(string memory) external view returns (bool);

function makeCommitment(
string memory,
Expand Down
40 changes: 40 additions & 0 deletions contracts/ethregistrar/bulk-renewal/BulkRenewal.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//SPDX-License-Identifier: MIT
pragma solidity ~0.8.17;

import "@openzeppelin/contracts/utils/introspection/ERC165.sol";

import {IETHRegistrarController} from "../IETHRegistrarController.sol";
import {IBaseRegistrar} from "../IBaseRegistrar.sol";

import {FixedItemPriceBulkRenewal} from "./FixedItemPriceBulkRenewal.sol";
import {FixedDurationBulkRenewal} from "./FixedDurationBulkRenewal.sol";
import {TargetExpiryBulkRenewal} from "./TargetExpiryBulkRenewal.sol";
import {BulkRenewalBase} from "./BulkRenewalBase.sol";

contract BulkRenewal is
BulkRenewalBase,
FixedItemPriceBulkRenewal,
FixedDurationBulkRenewal,
TargetExpiryBulkRenewal
{
constructor(
IBaseRegistrar _base,
IETHRegistrarController _controller
) BulkRenewalBase(_base, _controller) {}

function supportsInterface(
bytes4 interfaceID
)
public
view
override(
ERC165,
FixedItemPriceBulkRenewal,
FixedDurationBulkRenewal,
TargetExpiryBulkRenewal
)
returns (bool)
{
return super.supportsInterface(interfaceID);
}
}
19 changes: 19 additions & 0 deletions contracts/ethregistrar/bulk-renewal/BulkRenewalBase.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//SPDX-License-Identifier: MIT
pragma solidity ~0.8.17;

import "@openzeppelin/contracts/utils/introspection/ERC165.sol";

import {IETHRegistrarController} from "../IETHRegistrarController.sol";
import {IBaseRegistrar} from "../IBaseRegistrar.sol";

error NameAvailable(string name);

abstract contract BulkRenewalBase is ERC165 {
IBaseRegistrar immutable base;
IETHRegistrarController immutable controller;

constructor(IBaseRegistrar _base, IETHRegistrarController _controller) {
base = _base;
controller = _controller;
}
}
57 changes: 57 additions & 0 deletions contracts/ethregistrar/bulk-renewal/FixedDurationBulkRenewal.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//SPDX-License-Identifier: MIT
pragma solidity ~0.8.17;

import {IPriceOracle} from "../IPriceOracle.sol";

import {IFixedDurationBulkRenewal} from "./IFixedDurationBulkRenewal.sol";
import {BulkRenewalBase, NameAvailable} from "./BulkRenewalBase.sol";

abstract contract FixedDurationBulkRenewal is
IFixedDurationBulkRenewal,
BulkRenewalBase
{
function getFixedDurationPriceData(
string[] calldata names,
uint256 duration
) external view returns (uint256 total, uint256[] memory prices) {
uint256 length = names.length;
prices = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
string memory name = names[i];
if (controller.available(name)) revert NameAvailable(name);
IPriceOracle.Price memory price = controller.rentPrice(
name,
duration
);

total += price.base;
prices[i] = price.base;
}
}

function renewAllWithFixedDuration(
string[] calldata names,
uint256 duration,
uint256[] calldata prices
) external payable {
uint256 length = names.length;
for (uint256 i = 0; i < length; ) {
string memory name = names[i];
uint256 value = prices[i];
controller.renew{value: value}(name, duration);
unchecked {
++i;
}
}
// Send any excess funds back
payable(msg.sender).transfer(address(this).balance);
}

function supportsInterface(
bytes4 interfaceID
) public view virtual override returns (bool) {
return
interfaceID == type(IFixedDurationBulkRenewal).interfaceId ||
super.supportsInterface(interfaceID);
}
}
59 changes: 59 additions & 0 deletions contracts/ethregistrar/bulk-renewal/FixedItemPriceBulkRenewal.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//SPDX-License-Identifier: MIT
pragma solidity ~0.8.17;

import {IPriceOracle} from "../IPriceOracle.sol";

import {IFixedItemPriceBulkRenewal} from "./IFixedItemPriceBulkRenewal.sol";
import {BulkRenewalBase, NameAvailable} from "./BulkRenewalBase.sol";

error NameMismatchedPrice(string name);

abstract contract FixedItemPriceBulkRenewal is
IFixedItemPriceBulkRenewal,
BulkRenewalBase
{
function getFixedItemPricePriceData(
string[] calldata names,
uint256 duration
) external view returns (uint256 total, uint256 itemPrice) {
uint256 length = names.length;
for (uint256 i = 0; i < length; i++) {
string memory name = names[i];
if (controller.available(name)) revert NameAvailable(name);
IPriceOracle.Price memory price = controller.rentPrice(
name,
duration
);

total += price.base;

if (itemPrice == 0) itemPrice = price.base;
else if (itemPrice != price.base) revert NameMismatchedPrice(name);
}
}

function renewAllWithFixedItemPrice(
string[] calldata names,
uint256 duration,
uint256 itemPrice
) external payable {
uint256 length = names.length;
for (uint256 i = 0; i < length; ) {
string memory name = names[i];
controller.renew{value: itemPrice}(name, duration);
unchecked {
++i;
}
}
// Send any excess funds back
payable(msg.sender).transfer(address(this).balance);
}

function supportsInterface(
bytes4 interfaceID
) public view virtual override returns (bool) {
return
interfaceID == type(IFixedItemPriceBulkRenewal).interfaceId ||
super.supportsInterface(interfaceID);
}
}
15 changes: 15 additions & 0 deletions contracts/ethregistrar/bulk-renewal/IFixedDurationBulkRenewal.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//SPDX-License-Identifier: MIT
pragma solidity ~0.8.17;

interface IFixedDurationBulkRenewal {
function getFixedDurationPriceData(
string[] calldata names,
uint256 duration
) external view returns (uint256 total, uint256[] memory prices);

function renewAllWithFixedDuration(
string[] calldata names,
uint256 duration,
uint256[] calldata prices
) external payable;
}
15 changes: 15 additions & 0 deletions contracts/ethregistrar/bulk-renewal/IFixedItemPriceBulkRenewal.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//SPDX-License-Identifier: MIT
pragma solidity ~0.8.17;

interface IFixedItemPriceBulkRenewal {
function getFixedItemPricePriceData(
string[] calldata names,
uint256 duration
) external view returns (uint256 total, uint256 itemPrice);

function renewAllWithFixedItemPrice(
string[] calldata names,
uint256 duration,
uint256 itemPrice
) external payable;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
interface IBulkRenewal {
//SPDX-License-Identifier: MIT
pragma solidity ~0.8.17;

interface IStaticBulkRenewal {
function rentPrice(
string[] calldata names,
uint256 duration
Expand Down
22 changes: 22 additions & 0 deletions contracts/ethregistrar/bulk-renewal/ITargetExpiryBulkRenewal.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//SPDX-License-Identifier: MIT
pragma solidity ~0.8.17;

interface ITargetExpiryBulkRenewal {
function getTargetExpiryPriceData(
string[] calldata names,
uint256 targetExpiry
)
external
view
returns (
uint256 total,
uint256[] memory durations,
uint256[] memory prices
);

function renewAllWithTargetExpiry(
string[] calldata names,
uint256[] calldata duration,
uint256[] calldata prices
) external payable;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//SPDX-License-Identifier: MIT
pragma solidity ~0.8.17;

import "./ETHRegistrarController.sol";
import "./IBulkRenewal.sol";
import "./IPriceOracle.sol";
import ".././ETHRegistrarController.sol";
import "./IStaticBulkRenewal.sol";
import ".././IPriceOracle.sol";

import "@openzeppelin/contracts/utils/introspection/IERC165.sol";

contract StaticBulkRenewal is IBulkRenewal {
contract StaticBulkRenewal is IStaticBulkRenewal {
ETHRegistrarController controller;

constructor(ETHRegistrarController _controller) {
Expand All @@ -26,7 +26,7 @@ contract StaticBulkRenewal is IBulkRenewal {
);
unchecked {
++i;
total += (price.base + price.premium);
total += price.base;
}
}
}
Expand All @@ -36,7 +36,6 @@ contract StaticBulkRenewal is IBulkRenewal {
uint256 duration
) external payable override {
uint256 length = names.length;
uint256 total;
for (uint256 i = 0; i < length; ) {
IPriceOracle.Price memory price = controller.rentPrice(
names[i],
Expand All @@ -46,7 +45,6 @@ contract StaticBulkRenewal is IBulkRenewal {
controller.renew{value: totalPrice}(names[i], duration);
unchecked {
++i;
total += totalPrice;
}
}
// Send any excess funds back
Expand All @@ -58,6 +56,6 @@ contract StaticBulkRenewal is IBulkRenewal {
) external pure returns (bool) {
return
interfaceID == type(IERC165).interfaceId ||
interfaceID == type(IBulkRenewal).interfaceId;
interfaceID == type(IStaticBulkRenewal).interfaceId;
}
}
Loading
Loading