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

chore(bulk-renew): merge from release/v0.3.7 #284

Open
wants to merge 14 commits into
base: feature/bulk-renew
Choose a base branch
from
Open
Prev Previous commit
script: split to chunk to reduce stress con rpc
TuDo1403 committed Nov 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 068105ece6f75c04615c3fc037f0403d550ca29d
59 changes: 32 additions & 27 deletions script/operations/bulk-renew.mjs
Original file line number Diff line number Diff line change
@@ -20,38 +20,43 @@ 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);
}
// 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() {
const contract = new ethers.Contract(ronRegistrarControllerAddr, abi, provider);
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 = 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);
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);
await Promise.all(promises);
}
}

bulkRenew();