github.com/cgcardona/r-subnet-evm@v0.1.5/contracts/tasks.ts (about) 1 import { task } from "hardhat/config" 2 import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers" 3 import { BigNumber } from "ethers" 4 5 const BLACKHOLE_ADDRESS = "0x0100000000000000000000000000000000000000" 6 const CONTRACT_ALLOW_LIST_ADDRESS = "0x0200000000000000000000000000000000000000" 7 const MINT_ADDRESS = "0x0200000000000000000000000000000000000001" 8 const TX_ALLOW_LIST_ADDRESS = "0x0200000000000000000000000000000000000002" 9 const FEE_MANAGER_ADDRESS = "0x0200000000000000000000000000000000000003" 10 const REWARD_MANAGER_ADDDRESS = "0x0200000000000000000000000000000000000004" 11 12 13 const ROLES = { 14 0: "None", 15 1: "Enabled", 16 2: "Admin", 17 } 18 19 const getRole = async (allowList, address) => { 20 const role = await allowList.readAllowList(address) 21 console.log(`${address} has role: ${ROLES[role.toNumber()]}`) 22 } 23 24 task("accounts", "Prints the list of accounts", async (args, hre): Promise<void> => { 25 const accounts: SignerWithAddress[] = await hre.ethers.getSigners() 26 accounts.forEach((account: SignerWithAddress): void => { 27 console.log(account.address) 28 }) 29 }) 30 31 task("balances", "Prints the list of account balances", async (args, hre): Promise<void> => { 32 const accounts: SignerWithAddress[] = await hre.ethers.getSigners() 33 for (const account of accounts) { 34 const balance: BigNumber = await hre.ethers.provider.getBalance( 35 account.address 36 ) 37 console.log(`${account.address} has balance ${balance.toString()}`) 38 } 39 }) 40 41 42 task("balance", "get the balance") 43 .addParam("address", "the address you want to know balance of") 44 .setAction(async (args, hre) => { 45 const balance = await hre.ethers.provider.getBalance(args.address) 46 const balanceInCoin = hre.ethers.utils.formatEther(balance) 47 console.log(`balance: ${balanceInCoin} Coin`) 48 }) 49 50 // npx hardhat allowList:readRole --network local --address [address] 51 task("deployerAllowList:readRole", "Gets the network deployer allow list") 52 .addParam("address", "the address you want to know the allowlist role for") 53 .setAction(async (args, hre) => { 54 const allowList = await hre.ethers.getContractAt("IAllowList", CONTRACT_ALLOW_LIST_ADDRESS) 55 await getRole(allowList, args.address) 56 }) 57 58 // npx hardhat allowList:addDeployer --network local --address [address] 59 task("deployerAllowList:addDeployer", "Adds the deployer on the allow list") 60 .addParam("address", "the address you want to add as a deployer") 61 .setAction(async (args, hre) => { 62 const allowList = await hre.ethers.getContractAt("IAllowList", CONTRACT_ALLOW_LIST_ADDRESS) 63 // ADD CODE BELOW 64 await allowList.setEnabled(args.address) 65 await getRole(allowList, args.address) 66 }) 67 68 // npx hardhat allowList:addAdmin --network local --address [address] 69 task("deployerAllowList:addAdmin", "Adds an admin on the allowlist") 70 .addParam("address", "the address you want to add as a admin") 71 .setAction(async (args, hre) => { 72 const allowList = await hre.ethers.getContractAt("IAllowList", CONTRACT_ALLOW_LIST_ADDRESS) 73 await allowList.setAdmin(args.address) 74 await getRole(allowList, args.address) 75 }) 76 77 // npx hardhat allowList:revoke --network local --address [address] 78 task("deployerAllowList:revoke", "Removes the address from the list") 79 .addParam("address", "the address you want to revoke all permission") 80 .setAction(async (args, hre) => { 81 const allowList = await hre.ethers.getContractAt("IAllowList", CONTRACT_ALLOW_LIST_ADDRESS) 82 await allowList.setNone(args.address) 83 await getRole(allowList, args.address) 84 }) 85 86 // npx hardhat allowList:readRole --network local --address [address] 87 task("txAllowList:readRole", "Gets the network transaction allow list") 88 .addParam("address", "the address you want to know the allowlist role for") 89 .setAction(async (args, hre) => { 90 const allowList = await hre.ethers.getContractAt("IAllowList", TX_ALLOW_LIST_ADDRESS) 91 await getRole(allowList, args.address) 92 }) 93 94 // npx hardhat allowList:addDeployer --network local --address [address] 95 task("txAllowList:addDeployer", "Adds an address to the transaction allow list") 96 .addParam("address", "the address you want to add as a deployer") 97 .setAction(async (args, hre) => { 98 const allowList = await hre.ethers.getContractAt("IAllowList", TX_ALLOW_LIST_ADDRESS) 99 // ADD CODE BELOW 100 await allowList.setEnabled(args.address) 101 await getRole(allowList, args.address) 102 }) 103 104 // npx hardhat allowList:addAdmin --network local --address [address] 105 task("txAllowList:addAdmin", "Adds an admin on the transaction allow list") 106 .addParam("address", "the address you want to add as a admin") 107 .setAction(async (args, hre) => { 108 const allowList = await hre.ethers.getContractAt("IAllowList", TX_ALLOW_LIST_ADDRESS) 109 await allowList.setAdmin(args.address) 110 await getRole(allowList, args.address) 111 }) 112 113 // npx hardhat allowList:revoke --network local --address [address] 114 task("txAllowList:revoke", "Removes the address from the transaction allow list") 115 .addParam("address", "the address you want to revoke all permission") 116 .setAction(async (args, hre) => { 117 const allowList = await hre.ethers.getContractAt("IAllowList", TX_ALLOW_LIST_ADDRESS) 118 await allowList.setNone(args.address) 119 await getRole(allowList, args.address) 120 }) 121 122 // npx hardhat minter:readRole --network local --address [address] 123 task("minter:readRole", "Gets the network deployer minter list") 124 .addParam("address", "the address you want to know the minter role for") 125 .setAction(async (args, hre) => { 126 const allowList = await hre.ethers.getContractAt("INativeMinter", MINT_ADDRESS) 127 await getRole(allowList, args.address) 128 }) 129 130 131 // npx hardhat minter:addMinter --network local --address [address] 132 task("minter:addMinter", "Adds the address on the minter list") 133 .addParam("address", "the address you want to add as a minter") 134 .setAction(async (args, hre) => { 135 const allowList = await hre.ethers.getContractAt("INativeMinter", MINT_ADDRESS) 136 await allowList.setEnabled(args.address) 137 await getRole(allowList, args.address) 138 }) 139 140 // npx hardhat minter:addAdmin --network local --address [address] 141 task("minter:addAdmin", "Adds an admin on the minter list") 142 .addParam("address", "the address you want to add as a admin") 143 .setAction(async (args, hre) => { 144 const allowList = await hre.ethers.getContractAt("INativeMinter", MINT_ADDRESS) 145 await allowList.setAdmin(args.address) 146 await getRole(allowList, args.address) 147 }) 148 149 // npx hardhat minter:revoke --network local --address [address] 150 task("minter:revoke", "Removes the address from the list") 151 .addParam("address", "the address you want to revoke all permission") 152 .setAction(async (args, hre) => { 153 const allowList = await hre.ethers.getContractAt("INativeMinter", MINT_ADDRESS) 154 await allowList.setNone(args.address) 155 await getRole(allowList, args.address) 156 }) 157 158 // npx hardhat minter:mint --network local --address [address] 159 task("minter:mint", "Mints native tokens") 160 .addParam("address", "the address you want to mint for") 161 .addParam("amount", "the amount you want to mint") 162 .setAction(async (args, hre) => { 163 const minter = await hre.ethers.getContractAt("INativeMinter", MINT_ADDRESS) 164 await minter.mintNativeCoin(args.address, args.amount) 165 }) 166 167 // npx hardhat minter:burn --network local --address [address] 168 task("minter:burn", "Burns native tokens") 169 .addParam("amount", "the amount you want to burn (in AVAX unit)") 170 .setAction(async (args, hre) => { 171 const [owner] = await hre.ethers.getSigners() 172 const transactionHash = await owner.sendTransaction({ 173 to: BLACKHOLE_ADDRESS, 174 value: hre.ethers.utils.parseEther(args.amount), 175 }) 176 console.log(transactionHash) 177 }) 178 179 // npx hardhat feeManager:set --network local --address [address] 180 task("feeManager:set", "Sets the provided fee config") 181 .addParam("gaslimit", "", undefined, undefined, false) 182 .addParam("targetblockrate", "", undefined, undefined, false) 183 .addParam("minbasefee", "", undefined, undefined, false) 184 .addParam("targetgas", "", undefined, undefined, false) 185 .addParam("basefeechangedenominator", "", undefined, undefined, false) 186 .addParam("minblockgascost", "", undefined, undefined, false) 187 .addParam("maxblockgascost", "", undefined, undefined, false) 188 .addParam("blockgascoststep", "", undefined, undefined, false) 189 190 .setAction(async (args, hre) => { 191 const feeManager = await hre.ethers.getContractAt("IFeeManager", FEE_MANAGER_ADDRESS) 192 await feeManager.setFeeConfig( 193 args.gaslimit, 194 args.targetblockrate, 195 args.minbasefee, 196 args.targetgas, 197 args.basefeechangedenominator, 198 args.minblockgascost, 199 args.maxblockgascost, 200 args.blockgascoststep) 201 }) 202 203 task("feeManager:get", "Gets the fee config") 204 .setAction(async (_, hre) => { 205 const feeManager = await hre.ethers.getContractAt("IFeeManager", FEE_MANAGER_ADDRESS) 206 const result = await feeManager.getFeeConfig() 207 console.log(`Fee Manager Precompile Config is set to: 208 gasLimit: ${result[0]} 209 targetBlockRate: ${result[1]} 210 minBaseFee: ${result[2]} 211 targetGas: ${result[3]} 212 baseFeeChangeDenominator: ${result[4]} 213 minBlockGasCost: ${result[5]} 214 maxBlockGasCost: ${result[6]} 215 blockGasCostStep: ${result[7]}`) 216 }) 217 218 219 // npx hardhat feeManager:readRole --network local --address [address] 220 task("feeManager:readRole", "Gets the network deployer minter list") 221 .addParam("address", "the address you want to know the minter role for") 222 .setAction(async (args, hre) => { 223 const allowList = await hre.ethers.getContractAt("IFeeManager", FEE_MANAGER_ADDRESS) 224 await getRole(allowList, args.address) 225 }) 226 227 228 // npx hardhat rewardManager:currentRewardAddress --network local 229 task("rewardManager:currentRewardAddress", "Gets the current configured rewarding address") 230 .setAction(async (_, hre) => { 231 const rewardManager = await hre.ethers.getContractAt("IRewardManager", REWARD_MANAGER_ADDDRESS) 232 const areFeeRecipientsAllowed = await rewardManager.areFeeRecipientsAllowed() 233 const result = await rewardManager.currentRewardAddress() 234 if (areFeeRecipientsAllowed) { 235 console.log("Custom Fee Recipients are allowed. (%s)", result) 236 } else { 237 console.log(`Current reward address is ${result}`) 238 } 239 }) 240 241 // npx hardhat rewardManager:areFeeRecipientsAllowed --network local 242 task("rewardManager:areFeeRecipientsAllowed", "Gets whether the fee recipients are allowed to receive rewards") 243 .setAction(async (_, hre) => { 244 const rewardManager = await hre.ethers.getContractAt("IRewardManager", REWARD_MANAGER_ADDDRESS) 245 const result = await rewardManager.areFeeRecipientsAllowed() 246 console.log(result) 247 }) 248 249 // npx hardhat rewardManager:setRewardAddress --network local --address [address] 250 task("rewardManager:setRewardAddress", "Sets a new reward address") 251 .addParam("address", "the address that will receive rewards") 252 .setAction(async (args, hre) => { 253 const rewardManager = await hre.ethers.getContractAt("IRewardManager", REWARD_MANAGER_ADDDRESS) 254 const result = await rewardManager.setRewardAddress(args.address) 255 console.log(result) 256 }) 257 258 // npx hardhat rewardManager:allowFeeRecipients --network local 259 task("rewardManager:allowFeeRecipients", "Allows custom fee recipients to receive rewards") 260 .setAction(async (_, hre) => { 261 const rewardManager = await hre.ethers.getContractAt("IRewardManager", REWARD_MANAGER_ADDDRESS) 262 const result = await rewardManager.allowFeeRecipients() 263 console.log(result) 264 }) 265 266 // npx hardhat rewardManager:disableRewards --network local 267 task("rewardManager:disableRewards", "Disables all rewards, and starts burning fees.") 268 .setAction(async (_, hre) => { 269 const rewardManager = await hre.ethers.getContractAt("IRewardManager", REWARD_MANAGER_ADDDRESS) 270 const result = await rewardManager.disableRewards() 271 console.log(result) 272 })