|
| 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