Skip to content

Commit 12db563

Browse files
committed
script: add bulk renew script
1 parent 35db78a commit 12db563

File tree

4 files changed

+2883
-4600
lines changed

4 files changed

+2883
-4600
lines changed

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
],
1111
"devDependencies": {
1212
"dotenv": "^16.3.1",
13+
"ethers": "6.13.3",
1314
"hardhat": "^2.12.7",
1415
"hardhat-deploy": "0.11.29",
1516
"husky": "^8.0.3",
@@ -24,5 +25,6 @@
2425
},
2526
"scripts": {
2627
"prepare": "husky install"
27-
}
28-
}
28+
},
29+
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
30+
}

remappings.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@rns-contracts/=src/
22
ds-test/=lib/forge-std/lib/ds-test/src/
33
forge-std/=dependencies/@fdk-0.3.0-beta/dependencies/forge-std-1.8.2/src/
4-
@openzeppelin/contracts/=dependencies/@openzeppelin-contracts-4.9.3/
4+
@openzeppelin/contracts/=dependencies/openzeppelin-4.9.3/contracts/
55
contract-template/=lib/contract-template/src/
66
@solady/=dependencies/@fdk-0.3.0-beta/dependencies/solady-0.0.206/src/
77
@ensdomains/ens-contracts/=lib/ens-contracts/contracts/

script/operations/bulk-renew.mjs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { ethers } from "ethers";
2+
import fs from "fs";
3+
import dotenv from "dotenv";
4+
5+
dotenv.config();
6+
7+
const provider = new ethers.JsonRpcProvider("https://api-archived.roninchain.com/rpc");
8+
const wallet = new ethers.Wallet(process.env.RONIN_MAINNET_PK, provider);
9+
const renewList = JSON.parse(fs.readFileSync("renew-list.json", "utf8"));
10+
// Verify: https://app.roninchain.com/address/0x662852853614cbbb5d04bf2e29955b97e3c50b69
11+
const ronRegistrarControllerAddr = "0x662852853614cbbb5d04bf2e29955b97e3c50b69";
12+
const abi = ["function renew(string calldata name, uint64 duration) external payable"];
13+
const defaultRenewDuration = 5 * 365 * 24 * 60 * 60; // 5 years
14+
// Structure of data.json is assumed to be like this:
15+
// ["label1", "label2", "label3", ...]
16+
const durations = renewList.map(() => defaultRenewDuration);
17+
// Get current nonce of account
18+
let nonce = await wallet.getNonce();
19+
console.log(`Current nonce: ${nonce}`);
20+
const account = wallet.address;
21+
const shouldSimulate = true;
22+
// Assert the list is unique
23+
if (new Set(renewList).size !== renewList.length) {
24+
console.error("List is not unique");
25+
process.exit(1);
26+
}
27+
28+
async function bulkRenew() {
29+
const contract = new ethers.Contract(ronRegistrarControllerAddr, abi, provider);
30+
31+
const promises = renewList.map(async (label) => {
32+
if (shouldSimulate) {
33+
console.log(`nonce: ${nonce++}`);
34+
try {
35+
await contract.renew.staticCall(label, defaultRenewDuration, {
36+
from: account,
37+
});
38+
} catch (error) {
39+
console.error(`Failed to simulate renew for ${label} - ${defaultRenewDuration}`, error);
40+
}
41+
} else {
42+
console.log(`nonce: ${nonce}`);
43+
try {
44+
await contract.connect(wallet).renew(label, defaultRenewDuration, {
45+
nonce: nonce++,
46+
});
47+
console.log(`Renew for label ${label} - duration: ${defaultRenewDuration} success`);
48+
} catch (error) {
49+
console.error(`Failed to renew label ${label} - duration ${defaultRenewDuration}:`, error);
50+
}
51+
}
52+
});
53+
54+
await Promise.all(promises);
55+
}
56+
57+
bulkRenew();

0 commit comments

Comments
 (0)