-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
2,883 additions
and
4,600 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
|
@@ -24,5 +25,6 @@ | |
}, | ||
"scripts": { | ||
"prepare": "husky install" | ||
} | ||
} | ||
}, | ||
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Oops, something went wrong.