-
Notifications
You must be signed in to change notification settings - Fork 1
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
github-actions
wants to merge
11
commits into
feature/bulk-renew
Choose a base branch
from
implement-feature/bulk-renew/add-bulk-renew
base: feature/bulk-renew
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+389
−19
Open
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e96aee3
feat(RONRegistrarController): add bulkRenew to batch extend duration …
TuDo1403 4326d25
Merge branch 'feature/bulk-renew' into implement-feature/bulk-renew/a…
TuDo1403 c300ffb
fix(RONRegistrarController): minor fix
TuDo1403 275ca19
Update src/RONRegistrarController.sol
TuDo1403 ec0fb58
ci: update ci
TuDo1403 b6a11a1
ci: update ci
TuDo1403 a5de680
doc(RONRegistrarController): fix doc
TuDo1403 4d6fa4f
fix(RONRegistrarController): remove duplicate check
TuDo1403 81ea8cf
Update foundry.toml
TuDo1403 bbf5b4d
test(RONRegistrarController): unit test for bulkRenew func
tringuyenskymavis 3a1e815
Update src/interfaces/IRONRegistrarController.sol
TuDo1403 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -1,17 +1,20 @@ | ||
[[dependencies]] | ||
name = "@fdk" | ||
version = "0.3.0-beta" | ||
source = "https://github.com/axieinfinity/foundry-deployment-kit/archive/refs/tags/v0.3.0-beta.zip" | ||
url = "https://github.com/axieinfinity/foundry-deployment-kit/archive/refs/tags/v0.3.0-beta.zip" | ||
checksum = "aabeda6cc1fe02227d26f3edd86d4af6c91e2167e8b9f1971cc1ea7ce33d34f9" | ||
|
||
[[dependencies]] | ||
name = "@pythnetwork-pyth-sdk-solidity" | ||
version = "2.2.0" | ||
source = "https://soldeer-revisions.s3.amazonaws.com/@pythnetwork-pyth-sdk-solidity/2_2_0_15-04-2024_18:50:54_pyth-sdk-solidity.zip" | ||
checksum = "54e3bda3b27467f84c1605722f58e1d2b5a19d6ca3c24840550f1d6cf3bc2231" | ||
integrity = "436f06791b10ed0ce2363d3dde8e520e79376df1b81b00f0787670ad03941661" | ||
|
||
[[dependencies]] | ||
name = "@openzeppelin-contracts" | ||
version = "4.9.3" | ||
source = "https://soldeer-revisions.s3.amazonaws.com/@openzeppelin-contracts/4_9_3_22-01-2024_13:13:53_contracts.zip" | ||
url = "https://soldeer-revisions.s3.amazonaws.com/@openzeppelin-contracts/4_9_3_22-01-2024_13:13:53_contracts.zip" | ||
checksum = "95886307069cf73310b41396c49df51801a73f31f18f62e7d05adfc2031e7725" | ||
integrity = "6daa959732c1bceabda7f2823d1baa097b96509b48db78cb2e3ddd38bd4fd030" | ||
|
||
[[dependencies]] | ||
name = "@pythnetwork-pyth-sdk-solidity" | ||
version = "2.2.0" | ||
url = "https://soldeer-revisions.s3.amazonaws.com/@pythnetwork-pyth-sdk-solidity/2_2_0_15-04-2024_18:50:54_pyth-sdk-solidity.zip" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should use link from official github repo |
||
checksum = "54e3bda3b27467f84c1605722f58e1d2b5a19d6ca3c24840550f1d6cf3bc2231" | ||
integrity = "4a13c0cb110ee72e9f453835fcd63af6f13d5bbf4b102340ed454971d84c40fd" |
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
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
216 changes: 216 additions & 0 deletions
216
test/RONRegistrarController/RONRegistrarController.bulkRenew.t.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,216 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; | ||
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; | ||
import { console2, Test } from "forge-std/Test.sol"; | ||
import { RNSUnified } from "@rns-contracts/RNSUnified.sol"; | ||
import { | ||
RONRegistrarController, | ||
IRONRegistrarController, | ||
INSUnified, | ||
INameChecker, | ||
INSDomainPrice, | ||
INSReverseRegistrar | ||
} from "@rns-contracts/RONRegistrarController.sol"; | ||
import { RONTransferHelper } from "@rns-contracts/libraries/transfers/RONTransferHelper.sol"; | ||
import { LibString } from "@rns-contracts/libraries/LibString.sol"; | ||
import { LibRNSDomain } from "@rns-contracts/libraries/LibRNSDomain.sol"; | ||
import { RONRegistrarControllerTest } from "./RONRegistrarController.t.sol"; | ||
|
||
contract RONRegistrarControllerBulkRenewTest is RONRegistrarControllerTest { | ||
event NameRenewed(string name, uint256 indexed id, uint256 cost, uint64 expires); | ||
|
||
function testConcreate_Renew_2names_Check_CorrectFeeCharged() external { | ||
string[] memory names = new string[](2); | ||
names[0] = "tori.ron"; | ||
names[1] = "test.ron"; | ||
|
||
(uint256[] memory ids, string[] memory sortedNames) = _sortNames(names); | ||
uint64[] memory expires = new uint64[](ids.length); | ||
uint64 duration = 30 days; | ||
for (uint256 i; i < ids.length; ++i) { | ||
console2.log("id", ids[i]); | ||
console2.log("name", sortedNames[i]); | ||
expires[i] = _rnsUnified.getRecord(ids[i]).mut.expiry + duration; | ||
} | ||
|
||
uint256[] memory fees = new uint256[](2); | ||
fees[0] = _calFee(names[0], duration); | ||
fees[1] = _calFee(names[1], duration); | ||
|
||
uint256 totalFee = fees[0] + fees[1]; | ||
|
||
uint256 sendValue = 10 ether; | ||
uint256 balanceBefore = address(_caller).balance; | ||
|
||
uint64[] memory durations = new uint64[](2); | ||
durations[0] = duration; | ||
durations[1] = duration; | ||
_expectEmit(sortedNames, ids, fees, expires); | ||
vm.prank(_caller); | ||
_controller.bulkRenew{ value: sendValue }(sortedNames, durations); | ||
assertEq(address(_caller).balance, balanceBefore - totalFee); | ||
|
||
durations[0] = duration; | ||
durations[1] = duration; | ||
vm.prank(_caller); | ||
_controller.bulkRenew{ value: sendValue }(sortedNames, durations); | ||
} | ||
|
||
function testConcreate_bulkRenew_TheSameName_CorrectFeeCharged() external { | ||
string[] memory names = new string[](2); | ||
names[0] = "tori.vip.ron"; | ||
names[1] = "tori.vip.ron"; | ||
|
||
uint64 duration = 30 days; | ||
uint64[] memory durations = new uint64[](2); | ||
durations[0] = duration; | ||
durations[1] = duration; | ||
uint256 balanceBefore = address(_caller).balance; | ||
|
||
uint256 fee = _calFee(names[0], duration) * 2; | ||
|
||
vm.prank(_caller); | ||
_controller.bulkRenew{ value: 10 ether }(names, durations); | ||
|
||
assertEq(address(_caller).balance, balanceBefore - fee); | ||
assertEq(_treasury.balance, fee); | ||
} | ||
|
||
function testRevert_bulkRenew_InsufficientValue() external { | ||
string[] memory names = new string[](2); | ||
names[0] = "test.ron"; | ||
names[1] = "tori.ron"; | ||
|
||
uint64 duration = 30 days; | ||
uint64[] memory durations = new uint64[](2); | ||
durations[0] = duration; | ||
durations[1] = duration; | ||
|
||
uint256 name0Fee = _calFee(names[0], duration); | ||
uint256 name1Fee = _calFee(names[1], duration); | ||
|
||
vm.prank(_caller); | ||
vm.expectRevert(IRONRegistrarController.InsufficientValue.selector); | ||
_controller.bulkRenew{ value: name0Fee + name1Fee - 1 }(names, durations); | ||
|
||
// Call success | ||
_controller.bulkRenew{ value: name0Fee + name1Fee }(names, durations); | ||
} | ||
|
||
function testRevert_bulkRenew_ExpiryNotLargerThanOldOne() external { | ||
string[] memory names = new string[](1); | ||
names[0] = "test.ron"; | ||
|
||
uint64[] memory durations = new uint64[](1); | ||
durations[0] = 0; | ||
|
||
vm.prank(_caller); | ||
vm.expectRevert(INSUnified.ExpiryTimeMustBeLargerThanTheOldOne.selector); | ||
_controller.bulkRenew{ value: 10 ether }(names, durations); | ||
} | ||
|
||
function testBenchMark_bulkRenew(uint8 times) external { | ||
vm.pauseGasMetering(); | ||
vm.assume(times > 0); | ||
string[] memory names = new string[](times); | ||
uint64[] memory durations = new uint64[](times); | ||
uint256 totalFee; | ||
for (uint256 i; i < times; ++i) { | ||
names[i] = string.concat("test", vm.toString(i), ".ron"); | ||
durations[i] = 30 days; | ||
totalFee += _calFee(names[i], durations[i]); | ||
} | ||
vm.deal(_caller, totalFee + 10 ether); | ||
(, string[] memory sortedNames) = _sortNames(names); | ||
vm.resumeGasMetering(); | ||
vm.prank(_caller); | ||
_controller.bulkRenew{ value: totalFee + 10 ether }(sortedNames, durations); | ||
|
||
assertEq(address(_caller).balance, 10 ether); | ||
assertEq(_treasury.balance, totalFee); | ||
} | ||
|
||
function testRevert_bulkRenew_InvalidArrayLength() external { | ||
string[] memory names = new string[](2); | ||
names[0] = "test.ron"; | ||
names[1] = "tori.ron"; | ||
|
||
uint64[] memory durations = new uint64[](1); | ||
durations[0] = 30 days; | ||
|
||
vm.prank(_caller); | ||
vm.expectRevert(IRONRegistrarController.InvalidArrayLength.selector); | ||
_controller.bulkRenew{ value: 10 ether }(names, durations); | ||
|
||
names = new string[](0); | ||
durations = new uint64[](0); | ||
vm.expectRevert(IRONRegistrarController.InvalidArrayLength.selector); | ||
_controller.bulkRenew{ value: 10 ether }(names, durations); | ||
} | ||
|
||
function testConcreate_DuplicateNames_With_TheSameDuration() external { | ||
string[] memory names = new string[](2); | ||
names[0] = "test.ron"; | ||
names[1] = "test.ron"; | ||
|
||
uint64[] memory durations = new uint64[](2); | ||
durations[0] = 30 days; | ||
durations[1] = 30 days; | ||
|
||
vm.prank(_caller); | ||
// vm.expectRevert(IRONRegistrarController.InvalidArrayLength.selector); | ||
_controller.bulkRenew{ value: 10 ether }(names, durations); | ||
} | ||
|
||
function testConcreate_DuplicateNames_With_DifferentDuration() external { | ||
string[] memory names = new string[](2); | ||
names[0] = "test.ron"; | ||
names[1] = "test.ron"; | ||
|
||
uint64[] memory durations = new uint64[](2); | ||
durations[0] = 30 days; | ||
durations[1] = 10 days; | ||
|
||
vm.prank(_caller); | ||
// vm.expectRevert(IRONRegistrarController.InvalidArrayLength.selector); | ||
_controller.bulkRenew{ value: 10 ether }(names, durations); | ||
} | ||
|
||
function _calFee(string memory name, uint64 duration) internal returns (uint256) { | ||
(, uint256 ronPrice) = _controller.rentPrice(name, duration); | ||
return ronPrice; | ||
} | ||
|
||
function _sortNames(string[] memory names) internal returns (uint256[] memory, string[] memory) { | ||
uint256[] memory ids = new uint256[](names.length); | ||
for (uint256 i = 0; i < names.length; i++) { | ||
ids[i] = _controller.computeId(names[i]); | ||
} | ||
|
||
for (uint256 i = 0; i < names.length; i++) { | ||
for (uint256 j = i + 1; j < names.length; j++) { | ||
if (ids[i] > ids[j]) { | ||
uint256 tempId = ids[i]; | ||
ids[i] = ids[j]; | ||
ids[j] = tempId; | ||
|
||
string memory tempName = names[i]; | ||
names[i] = names[j]; | ||
names[j] = tempName; | ||
} | ||
} | ||
} | ||
return (ids, names); | ||
} | ||
|
||
function _expectEmit(string[] memory names, uint256[] memory ids, uint256[] memory fees, uint64[] memory expires) | ||
internal | ||
{ | ||
for (uint256 i; i < names.length; ++i) { | ||
vm.expectEmit(false, true, false, true); | ||
emit NameRenewed(names[i], ids[i], fees[i], expires[i]); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should use link from official github repo