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 14 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
13 changes: 4 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ on:
branches:
- mainnet
- testnet
- 'feature/*'
- 'features/*'
- "feature/*"
- "features/*"
pull_request:
branches:
- mainnet
- testnet
- 'feature/*'
- 'features/*'
- "feature/*"
- "features/*"

env:
FOUNDRY_PROFILE: ci
Expand All @@ -37,11 +37,6 @@ jobs:
- name: Update package with soldeer
run: forge soldeer update

- name: Recursively update dependencies
run: |
chmod +x ./update-deps.sh
./update-deps.sh

- name: Run Forge build
run: |
forge --version
Expand Down
28 changes: 24 additions & 4 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ffi = true

solc = '0.8.21'
extra_output = ["devdoc", "userdoc", "storagelayout"]
evm_version = 'istanbul'
evm_version = 'london'
use_literal_content = true
fs_permissions = [{ access = "read-write", path = "./" }]

Expand All @@ -30,6 +30,26 @@ runs = 256
runs = 256

[dependencies]
"@fdk" = { version = "0.3.0-beta", url = "https://github.com/axieinfinity/foundry-deployment-kit/archive/refs/tags/v0.3.0-beta.zip" }
"@pythnetwork-pyth-sdk-solidity" = { version = "2.2.0" }
"@openzeppelin-contracts" = { version = "4.9.3" }
"@fdk" = { version = "0.3.4-beta", url = "https://github.com/axieinfinity/foundry-deployment-kit/archive/refs/tags/v0.3.4-beta.zip" }
"@pythnetwork-pyth-sdk-solidity" = { version = "2.2.0", url = "https://github.com/pyth-network/pyth-sdk-solidity/archive/refs/tags/v2.2.0.zip" }
"@openzeppelin-contracts" = { version = "4.9.3", url = "https://github.com/OpenZeppelin/openzeppelin-contracts/archive/refs/tags/v4.9.3.zip" }

[soldeer]
# whether soldeer manages remappings
remappings_generate = false

# whether soldeer re-generates all remappings when installing, updating or uninstalling deps
remappings_regenerate = false

# whether to suffix the remapping with the version: `name-a.b.c`
remappings_version = true

# a prefix to add to the remappings ("@" would give `@name`)
remappings_prefix = "@"

# where to store the remappings ("txt" for `remappings.txt` or "config" for `foundry.toml`)
# ignored when `soldeer.toml` is used as config (uses `remappings.txt`)
remappings_location = "txt"

# whether to install sub-dependencies or not. If true this wil install the dependencies of dependencies 1 level down.
recursive_deps = true
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
],
"devDependencies": {
"dotenv": "^16.3.1",
"ethers": "6.13.3",
"hardhat": "^2.12.7",
"hardhat-deploy": "0.11.29",
"husky": "^8.0.3",
Expand All @@ -24,5 +25,6 @@
},
"scripts": {
"prepare": "husky install"
}
}
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
2 changes: 1 addition & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@rns-contracts/=src/
ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=dependencies/@fdk-0.3.0-beta/dependencies/forge-std-1.8.2/src/
@openzeppelin/contracts/=dependencies/@openzeppelin-contracts-4.9.3/
@openzeppelin/contracts/=dependencies/openzeppelin-4.9.3/contracts/
contract-template/=lib/contract-template/src/
@solady/=dependencies/@fdk-0.3.0-beta/dependencies/solady-0.0.206/src/
@ensdomains/ens-contracts/=lib/ens-contracts/contracts/
Expand Down
62 changes: 62 additions & 0 deletions script/operations/bulk-renew.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { ethers } from "ethers";
import fs from "fs";
import dotenv from "dotenv";

dotenv.config();

const provider = new ethers.JsonRpcProvider("https://api-archived.roninchain.com/rpc");
const wallet = new ethers.Wallet(process.env.RONIN_MAINNET_PK, provider);
const renewList = JSON.parse(fs.readFileSync("renew-list.json", "utf8"));
// Verify: https://app.roninchain.com/address/0x662852853614cbbb5d04bf2e29955b97e3c50b69
const ronRegistrarControllerAddr = "0x662852853614cbbb5d04bf2e29955b97e3c50b69";
const abi = ["function renew(string calldata name, uint64 duration) external payable"];
const defaultRenewDuration = 5 * 365 * 24 * 60 * 60; // 5 years
// Structure of data.json is assumed to be like this:
// ["label1", "label2", "label3", ...]
const durations = renewList.map(() => defaultRenewDuration);
// Get current nonce of account
let nonce = await wallet.getNonce();
console.log(`Current nonce: ${nonce}`);
const account = wallet.address;
const shouldSimulate = true;
// Assert the list is unique
// if (new Set(renewList).size !== renewList.length) {
// console.error("List is not unique");
// process.exit(1);
// }
const contract = new ethers.Contract(ronRegistrarControllerAddr, abi, provider);
const chunkSize = 20;

async function bulkRenew() {
for (let i = 0; i < renewList.length; i += chunkSize) {
const chunk = renewList.slice(i, i + chunkSize);
console.log(`Processing chunk ${i / chunkSize + 1} - ${chunk.length} labels`);

const promises = chunk.map(async (label) => {
if (shouldSimulate) {
console.log(`nonce: ${nonce++}`);
try {
await contract.renew.staticCall(label, defaultRenewDuration, {
from: account,
});
} catch (error) {
console.error(`Failed to simulate renew for ${label} - ${defaultRenewDuration}`, error);
}
} else {
console.log(`nonce: ${nonce}`);
try {
await contract.connect(wallet).renew(label, defaultRenewDuration, {
nonce: nonce++,
});
console.log(`Renew for label ${label} - duration: ${defaultRenewDuration} success`);
} catch (error) {
console.error(`Failed to renew label ${label} - duration ${defaultRenewDuration}:`, error);
}
}
});

await Promise.all(promises);
}
}

bulkRenew();
25 changes: 14 additions & 11 deletions soldeer.lock
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"
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"
version = "0.3.4-beta"
url = "https://github.com/axieinfinity/foundry-deployment-kit/archive/refs/tags/v0.3.4-beta.zip"
checksum = "d93cfa76dee3a227b2ee24d41c4afe2141fb25498eed9352d036ab13bbc16c13"
integrity = "4f0417853a563024747cba0dd88d501717c13d4387132e5b1b854da69b7486b2"

[[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"
checksum = "95886307069cf73310b41396c49df51801a73f31f18f62e7d05adfc2031e7725"
url = "https://github.com/OpenZeppelin/openzeppelin-contracts/archive/refs/tags/v4.9.3.zip"
checksum = "94270990c32ff2d00c06a9dabaf5b7a8e36773e017254acbb39d13733eb82960"
integrity = "5cca086987dbce97760f8a337c0d29e6383fcafaffa9662897695f17566756d0"

[[dependencies]]
name = "@pythnetwork-pyth-sdk-solidity"
version = "2.2.0"
url = "https://github.com/pyth-network/pyth-sdk-solidity/archive/refs/tags/v2.2.0.zip"
checksum = "71431ac3fe4e61ce2b8abd649d3e741277ca4dba287c2a4291d040190b8fb8da"
integrity = "845f9e662935eb347e9189da9b156f0062bcab1d372c7397777dbda609776a5c"
28 changes: 28 additions & 0 deletions src/RONRegistrarController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,34 @@ 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;
id = computeId(names[i]);
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
11 changes: 11 additions & 0 deletions src/interfaces/IRONRegistrarController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@ interface IRONRegistrarController {
*/
function renew(string calldata name, uint64 duration) external payable;

/**
* @dev Renew multiple names in a single transaction.
* Requirements:
* - `names` and `durations` arrays must have the same length.
* - The caller must provide enough value to cover the total renewal cost.
* WARNING: The function does not check for duplicate names.
* @param names The array of names to be renewed.
* @param durations 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
Loading