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

Draft
wants to merge 4 commits into
base: staging
Choose a base branch
from
Draft
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.

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 NameHasPremium(string name);

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

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

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

import {IFixedDurationBulkRenewal} from "./IFixedDurationBulkRenewal.sol";
import {BulkRenewalBase, NameHasPremium} 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];
IPriceOracle.Price memory price = controller.rentPrice(
name,
duration
);

if (price.premium > 0) revert NameHasPremium(name);

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);
}
}
60 changes: 60 additions & 0 deletions contracts/ethregistrar/bulk-renewal/FixedItemPriceBulkRenewal.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//SPDX-License-Identifier: MIT
pragma solidity ~0.8.17;

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

import {IFixedItemPriceBulkRenewal} from "./IFixedItemPriceBulkRenewal.sol";
import {BulkRenewalBase, NameHasPremium} 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];
IPriceOracle.Price memory price = controller.rentPrice(
name,
duration
);

if (price.premium > 0) revert NameHasPremium(name);

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;
}
25 changes: 25 additions & 0 deletions contracts/ethregistrar/bulk-renewal/IOptimisedBulkRenewal.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//SPDX-License-Identifier: MIT
pragma solidity ~0.8.17;

interface IOptimisedBulkRenewal {
function rentPrice(
string[] calldata names,
uint256 duration
)
external
view
returns (
uint256 total,
uint256 fiveCharPrice,
uint256 fourCharPrice,
uint256 threeCharPrice
);

function renewAll(
string[] calldata names,
uint256 duration,
uint256 fiveCharPrice,
uint256 fourCharPrice,
uint256 threeCharPrice
) external payable;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
interface IBulkRenewal {
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;
}
Loading
Loading