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

Add more usefull tasks #63

Merged
merged 8 commits into from
Oct 5, 2024
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
INFURA_API_KEY=zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
MNEMONIC=here is where your twelve words mnemonic should be put my friend
INITIAL_INDEX=0
9 changes: 9 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ import "./tasks/get-statuses-after-execution";
import "./tasks/depositSC";
import "./tasks/set-batch-settle-limit-on-safe"
import "./tasks/deploy";
import "./tasks/token-balance-query"
import "./tasks/get-relayers"
import "./tasks/native-tokens"
import "./tasks/mintburn-tokens"
import "./tasks/reset-total-balance"

import { resolve } from "path";

Expand All @@ -49,6 +54,7 @@ const chainIds = {

// Ensure that we have all the environment variables we need.
const mnemonic: string | undefined = process.env.MNEMONIC;
const initialindex: string | undefined = process.env.INITIAL_INDEX
if (!mnemonic) {
throw new Error("Please set your MNEMONIC in a .env file");
}
Expand All @@ -64,6 +70,7 @@ function getETHConfig(network: string): NetworkUserConfig {
count: 12,
mnemonic,
path: "m/44'/60'/0'/0",
initialIndex: Number(initialindex),
},
url: "https://" + chainIds.sepolia + ".infura.io/v3/" + infuraApiKey,
};
Expand All @@ -88,6 +95,7 @@ function getBSCConfig(network: string): NetworkUserConfig {
count: 12,
mnemonic,
path: "m/44'/60'/0'/0",
initialIndex: Number(initialindex),
},
url: `https://data-seed-prebsc-1-s1.binance.org:8545`,
};
Expand All @@ -112,6 +120,7 @@ function getPolygonConfig(network: string): NetworkUserConfig {
count: 12,
mnemonic,
path: "m/44'/60'/0'/0",
initialIndex: Number(initialindex),
},
url: "https://polygon-mumbai.infura.io/v3/" + infuraApiKey,
};
Expand Down
16 changes: 16 additions & 0 deletions tasks/get-relayers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import "@nomicfoundation/hardhat-toolbox";

task("get-relayers", "Get the whitelisted relayers").setAction(async (taskArgs, hre) => {
const [adminWallet] = await hre.ethers.getSigners();
const fs = require("fs");
const config = JSON.parse(fs.readFileSync("setup.config.json", "utf8"));
const bridgeAddress = config["bridge"];
const bridgeContractFactory = await hre.ethers.getContractFactory("Bridge");
const bridge = bridgeContractFactory.attach(bridgeAddress).connect(adminWallet);

const relayers = await bridge.getRelayers();
console.log("whitelisted relayers:")
for (let relayer of relayers) {
console.log(relayer);
}
});
2 changes: 1 addition & 1 deletion tasks/init-supply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getDeployOptions } from "./args/deployOptions";

task("init-supply", "Deposit the initial supply on a new SC from an old one")
.addParam("address", "The addres of the token that will be deposited")
.addParam("amount", "New amount we want to set (full value, with 18 decimals)")
.addParam("amount", "New amount we want to set (full denominated value, with all decimals)")
.addOptionalParam("price", "Gas price in gwei for this transaction", undefined)
.setAction(async (taskArgs, hre) => {
const [adminWallet] = await hre.ethers.getSigners();
Expand Down
24 changes: 24 additions & 0 deletions tasks/mintburn-tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import "@nomicfoundation/hardhat-toolbox";
import fs from "fs";

task("mintburn-tokens", "Returns if the token is mint-burn or not")
.addParam("address", "Address of the token")
.setAction(async (taskArgs, hre) => {
const address = taskArgs.address;

const filename = "setup.config.json";
const config = JSON.parse(fs.readFileSync(filename, "utf8"));
const safeAddress = config["erc20Safe"];

const safeContractFactory = await hre.ethers.getContractFactory("ERC20Safe");
const contract = safeContractFactory.attach(safeAddress)

await contract
.mintBurnTokens(address)
.then((isMintBurn: any) => {
console.log(`Token ${address} is mint-burn: ${isMintBurn.toString()}`);
})
.catch((err: any) => {
console.log(err);
});
});
24 changes: 24 additions & 0 deletions tasks/native-tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import "@nomicfoundation/hardhat-toolbox";
import fs from "fs";

task("native-tokens", "Returns if the token is native or not")
.addParam("address", "Address of the token")
.setAction(async (taskArgs, hre) => {
const address = taskArgs.address;

const filename = "setup.config.json";
const config = JSON.parse(fs.readFileSync(filename, "utf8"));
const safeAddress = config["erc20Safe"];

const safeContractFactory = await hre.ethers.getContractFactory("ERC20Safe");
const contract = safeContractFactory.attach(safeAddress)

await contract
.nativeTokens(address)
.then((isNative: any) => {
console.log(`Token ${address} is native: ${isNative.toString()}`);
})
.catch((err: any) => {
console.log(err);
});
});
17 changes: 17 additions & 0 deletions tasks/reset-total-balance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import "@nomicfoundation/hardhat-toolbox";
import { getDeployOptions } from "./args/deployOptions";

task("reset-total-balance", "Resets the total balance for the native token")
.addParam("address", "The addres of the token that will reset")
.addOptionalParam("price", "Gas price in gwei for this transaction", undefined)
.setAction(async (taskArgs, hre) => {
const [adminWallet] = await hre.ethers.getSigners();
const fs = require("fs");
const address = taskArgs.address;
const config = JSON.parse(fs.readFileSync("setup.config.json", "utf8"));
const safeAddress = config["erc20Safe"];
const safeContractFactory = await hre.ethers.getContractFactory("ERC20Safe");
const safe = safeContractFactory.attach(safeAddress).connect(adminWallet);

await safe.resetTotalBalance(address, getDeployOptions(taskArgs));
});
20 changes: 20 additions & 0 deletions tasks/token-balance-query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import "@nomicfoundation/hardhat-toolbox";

task("token-balance-query", "Query the balance of the provided address for the defined tokens")
.addParam("address", "Address for the balance query")
.setAction(async (taskArgs, hre) => {
const fs = require("fs");
const filename = "setup.config.json";
let config = JSON.parse(fs.readFileSync(filename, "utf8"));
const address = taskArgs.address;

console.log("Querying ERC20 balance of the address", address);
for (let token of config["tokens"]) {
const tokenContract = (await hre.ethers.getContractFactory("GenericERC20")).attach(token);
await tokenContract.balanceOf(address)
.then((balance: any) => {
console.log(`Balance of token ${token.toString()}: ${balance.toString()}`);
})

}
});
Loading