-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
336 additions
and
91 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
58
contracts/ethregistrar/bulk-renewal/FixedDurationBulkRenewal.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
60
contracts/ethregistrar/bulk-renewal/FixedItemPriceBulkRenewal.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
contracts/ethregistrar/bulk-renewal/IFixedDurationBulkRenewal.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
contracts/ethregistrar/bulk-renewal/IFixedItemPriceBulkRenewal.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
25
contracts/ethregistrar/bulk-renewal/IOptimisedBulkRenewal.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
2 changes: 1 addition & 1 deletion
2
contracts/ethregistrar/IBulkRenewal.sol → ...strar/bulk-renewal/IStaticBulkRenewal.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
contracts/ethregistrar/bulk-renewal/ITargetExpiryBulkRenewal.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.