Skip to content

Commit

Permalink
fix: address validation (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev authored Dec 20, 2024
1 parent 3b9a093 commit 0b208f1
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 0 deletions.
5 changes: 5 additions & 0 deletions contracts/nft/tasks/connectedSetUniversal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
import { EVMUniversalNFT } from "@/typechain-types";

const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const { isAddress } = hre.ethers.utils;
const [signer] = await hre.ethers.getSigners();
if (!signer) {
throw new Error(
`Wallet not found. Please, run "npx hardhat account --save" or set PRIVATE_KEY env variable (for example, in a .env file)`
);
}

if (!isAddress(args.contract) || !isAddress(args.universal)) {
throw new Error("Invalid Ethereum address provided.");
}

const contract: EVMUniversalNFT = await hre.ethers.getContractAt(
"EVMUniversalNFT",
args.contract
Expand Down
8 changes: 8 additions & 0 deletions contracts/nft/tasks/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { task, types } from "hardhat/config";
import { HardhatRuntimeEnvironment } from "hardhat/types";

const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const { isAddress } = hre.ethers.utils;
const network = hre.network.name;

const [signer] = await hre.ethers.getSigners();
Expand All @@ -11,6 +12,13 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
);
}

if (
!isAddress(args.gateway) ||
(args.uniswapRouter && !isAddress(args.uniswapRouter))
) {
throw new Error("Invalid Ethereum address provided.");
}

const factory: any = await hre.ethers.getContractFactory(args.name);

const contract = await hre.upgrades.deployProxy(factory, [
Expand Down
6 changes: 6 additions & 0 deletions contracts/nft/tasks/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
import isURL from "validator/lib/isURL";

const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const { isAddress } = hre.ethers.utils;

const [signer] = await hre.ethers.getSigners();
if (signer === undefined) {
throw new Error(
`Wallet not found. Please, run "npx hardhat account --save" or set PRIVATE_KEY env variable (for example, in a .env file)`
);
}

if (!isAddress(args.contract)) {
throw new Error("Invalid Ethereum address provided.");
}

const supportedProtocols = ["https", "ipfs"];

const isValidTokenUri = isURL(args.tokenUri, {
Expand Down
7 changes: 7 additions & 0 deletions contracts/nft/tasks/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const { ethers } = hre;
const [signer] = await ethers.getSigners();

const { isAddress } = hre.ethers.utils;

if (!isAddress(args.to) || !isAddress(args.revertAddress)) {
throw new Error("Invalid Ethereum address provided.");
}

const nftContract = await ethers.getContractAt("IERC721", args.from);
const approveTx = await nftContract
.connect(signer)
Expand Down
9 changes: 9 additions & 0 deletions contracts/nft/tasks/universalSetConnected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
import { ZetaChainUniversalNFT } from "@/typechain-types";

const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const { isAddress } = hre.ethers.utils;
const [signer] = await hre.ethers.getSigners();
if (!signer) {
throw new Error(
`Wallet not found. Please, run "npx hardhat account --save" or set PRIVATE_KEY env variable (for example, in a .env file)`
);
}

if (
!isAddress(args.contract) ||
!isAddress(args.zrc20) ||
!isAddress(args.connected)
) {
throw new Error("Invalid Ethereum address provided.");
}

const contract: ZetaChainUniversalNFT = await hre.ethers.getContractAt(
"ZetaChainUniversalNFT",
args.contract
Expand Down
6 changes: 6 additions & 0 deletions contracts/token/tasks/connectedSetUniversal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
import { EVMUniversalToken } from "../typechain-types";

const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const { isAddress } = hre.ethers.utils;

const [signer] = await hre.ethers.getSigners();
if (!signer) {
throw new Error(
`Wallet not found. Please, run "npx hardhat account --save" or set PRIVATE_KEY env variable (for example, in a .env file)`
);
}

if (!isAddress(args.contract) || !isAddress(args.universal)) {
throw new Error("Invalid Ethereum address provided.");
}

const contract: EVMUniversalToken = await hre.ethers.getContractAt(
"EVMUniversalToken",
args.contract
Expand Down
9 changes: 9 additions & 0 deletions contracts/token/tasks/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { task, types } from "hardhat/config";
import { HardhatRuntimeEnvironment } from "hardhat/types";

const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const { isAddress } = hre.ethers.utils;

const network = hre.network.name;

const [signer] = await hre.ethers.getSigners();
Expand All @@ -11,6 +13,13 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
);
}

if (
!isAddress(args.gateway) ||
(args.uniswapRouter && !isAddress(args.uniswapRouter))
) {
throw new Error("Invalid Ethereum address provided.");
}

const factory: any = await hre.ethers.getContractFactory(args.name);

const contract = await hre.upgrades.deployProxy(factory, [
Expand Down
6 changes: 6 additions & 0 deletions contracts/token/tasks/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ import { task } from "hardhat/config";
import { HardhatRuntimeEnvironment } from "hardhat/types";

const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const { isAddress } = hre.ethers.utils;

const [signer] = await hre.ethers.getSigners();
if (signer === undefined) {
throw new Error(
`Wallet not found. Please, run "npx hardhat account --save" or set PRIVATE_KEY env variable (for example, in a .env file)`
);
}

if (!isAddress(args.contract)) {
throw new Error("Invalid Ethereum address provided.");
}

const contract: any = await hre.ethers.getContractAt(
args.name,
args.contract
Expand Down
6 changes: 6 additions & 0 deletions contracts/token/tasks/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const { ethers } = hre;
const [signer] = await ethers.getSigners();

const { isAddress } = hre.ethers.utils;

if (!isAddress(args.to) || !isAddress(args.revertAddress)) {
throw new Error("Invalid Ethereum address provided.");
}

const txOptions = {
gasPrice: args.txOptionsGasPrice,
gasLimit: args.txOptionsGasLimit,
Expand Down
10 changes: 10 additions & 0 deletions contracts/token/tasks/universalSetConnected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
import { ZetaChainUniversalToken } from "../typechain-types";

const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const { isAddress } = hre.ethers.utils;

const [signer] = await hre.ethers.getSigners();
if (!signer) {
throw new Error(
`Wallet not found. Please, run "npx hardhat account --save" or set PRIVATE_KEY env variable (for example, in a .env file)`
);
}

if (
!isAddress(args.contract) ||
!isAddress(args.zrc20) ||
!isAddress(args.connected)
) {
throw new Error("Invalid Ethereum address provided.");
}

const contract: ZetaChainUniversalToken = await hre.ethers.getContractAt(
"ZetaChainUniversalToken",
args.contract
Expand Down

0 comments on commit 0b208f1

Please sign in to comment.