Skip to content

Commit 1c04b56

Browse files
committed
Create a script to update the default burn percentage
1 parent 24db86e commit 1c04b56

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

scripts/updateBurnPercentage.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const hre = require('hardhat')
2+
const ethers = require('ethers')
3+
4+
const readline = require('node:readline/promises')
5+
const process = require('node:process')
6+
7+
const X_REQUEST_PROCESSOR_ABI =
8+
require('../artifacts/contracts/XRequestProcessor.sol/XRequestProcessor.json').abi
9+
10+
const cliReader = readline.createInterface({ input: process.stdin, output: process.stdout })
11+
12+
async function main() {
13+
const chainId = hre.network.config.chainId
14+
const rpcUrl = hre.network.config.url
15+
const provider = new ethers.JsonRpcProvider(rpcUrl)
16+
17+
const privateKey = process.env.PRIVATE_KEY || 'YOUR_PRIVATE_KEY'
18+
const wallet = new hre.ethers.Wallet(privateKey)
19+
const walletSigner = wallet.connect(provider)
20+
21+
const requestProcessorAddress =
22+
process.env.XREQUEST_PROCESSOR_ADDRESS ||
23+
(await cliReader.question(`Enter XRequestProcessor address": `)).trim()
24+
if (!ethers.isAddress(requestProcessorAddress)) {
25+
console.log('Invalid XRequestProcessor address. Aborting.')
26+
return
27+
}
28+
29+
const networkName = hre.network.name
30+
.replace(/(?<=[a-z])(?=[A-Z])/g, ' ')
31+
.split(' ')
32+
.map(s => `${s[0].toUpperCase()}${s.slice(1)}`)
33+
.join(' ')
34+
35+
console.log(
36+
`Updating burn percentage for XRequestProcessor deployment: ${requestProcessorAddress} on ${networkName}`
37+
)
38+
39+
const newBurnPercent = parseInt(
40+
await cliReader.question('Please enter the new burn percentage: ')
41+
)
42+
if (isNaN(newBurnPercent) || newBurnPercent < 0 || newBurnPercent > 100) {
43+
console.log('Error: please enter a value between 0-100')
44+
return
45+
}
46+
47+
console.log(`New burn percentage: ${newBurnPercent}%`)
48+
const proceedWithTransaction = await cliReader.question('Do you wish to proceed? [y]: ')
49+
if (proceedWithTransaction !== '' && proceedWithTransaction.slice(0, 1) !== 'y') {
50+
console.log('Aborting operation.')
51+
return
52+
}
53+
54+
console.log('Publishing new burn percentage...')
55+
const contract = new ethers.Contract(
56+
requestProcessorAddress,
57+
X_REQUEST_PROCESSOR_ABI,
58+
walletSigner
59+
)
60+
const txData = await contract.setBurnPercentage(newBurnPercent)
61+
console.log(`TX: ${txData.hash}`)
62+
}
63+
64+
// We recommend this pattern to be able to use async/await everywhere
65+
// and properly handle errors.
66+
main()
67+
.catch(error => {
68+
console.error(error)
69+
process.exitCode = 1
70+
})
71+
.finally(() => {
72+
cliReader.close()
73+
})

0 commit comments

Comments
 (0)