Skip to content

Commit

Permalink
script: add bulk renew script
Browse files Browse the repository at this point in the history
  • Loading branch information
TuDo1403 committed Nov 4, 2024
1 parent 35db78a commit 12db563
Show file tree
Hide file tree
Showing 4 changed files with 2,883 additions and 4,600 deletions.
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
57 changes: 57 additions & 0 deletions script/operations/bulk-renew.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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);
}

async function bulkRenew() {
const contract = new ethers.Contract(ronRegistrarControllerAddr, abi, provider);

const promises = renewList.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();
Loading

0 comments on commit 12db563

Please sign in to comment.