Skip to content

Commit

Permalink
feat: ad is valid function to check if the address have the address t…
Browse files Browse the repository at this point in the history
…ype and are not ero address
  • Loading branch information
clauBv23 committed Jan 27, 2025
1 parent 3d7b7d8 commit 4e15e02
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
3 changes: 2 additions & 1 deletion packages/contracts/deploy/10_create_repo/11_create_repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
findPluginRepo,
getProductionNetworkName,
pluginEnsDomain,
isValidAddress,
} from '../../utils/helpers';
import {
getLatestNetworkDeployment,
Expand Down Expand Up @@ -41,7 +42,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
let subdomainRegistrar;

if (pluginRepoFactoryAddress) {
if (!ethers.utils.isAddress(pluginRepoFactoryAddress)) {
if (!isValidAddress(pluginRepoFactoryAddress)) {
throw new Error('Plugin Repo Factory in .env is not of type Address');
}
// use this factory
Expand Down
9 changes: 7 additions & 2 deletions packages/contracts/deploy/20_new_version/23_publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
impersonatedManagementDaoSigner,
isLocal,
pluginEnsDomain,
isValidAddress,
} from '../../utils/helpers';
import {getLatestContractAddress} from '../helpers';
import {PLUGIN_REPO_PERMISSIONS, uploadToPinata} from '@aragon/osx-commons-sdk';
Expand All @@ -38,6 +39,7 @@ async function createVersion(
ethers.utils.hexlify(ethers.utils.toUtf8Bytes(buildMetadataURI)),
ethers.utils.hexlify(ethers.utils.toUtf8Bytes(releaseMetadataURI))
);

await tx.wait();
}

Expand Down Expand Up @@ -147,8 +149,10 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
process.env.PLACEHOLDER_SETUP ??
getLatestContractAddress('PlaceholderSetup', hre);

if (!ethers.utils.isAddress(placeholderSetup)) {
('Aborting. Placeholder setup not present in this network or in .env or is not an address');
if (!isValidAddress(placeholderSetup)) {
throw new Error(
'Aborting. Placeholder setup not present in this network or in .env or is not a valid address (is not an address or is address zero)'
);
}

for (let i = 0; i < VERSION.build - 1; i++) {
Expand All @@ -164,6 +168,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
}
}

// Create the new version
await createVersion(
pluginRepo,
VERSION.release,
Expand Down
12 changes: 9 additions & 3 deletions packages/contracts/deploy/30_upgrade_repo/_common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import {findPluginRepo, getProductionNetworkName} from '../../utils/helpers';
import {
findPluginRepo,
getProductionNetworkName,
isValidAddress,
} from '../../utils/helpers';
import {
getLatestNetworkDeployment,
getNetworkNameByAlias,
Expand Down Expand Up @@ -51,8 +55,10 @@ export async function fetchData(
const pluginRepoFactoryAddress = process.env.PLUGIN_REPO_FACTORY_ADDRESS;

if (pluginRepoFactoryAddress) {
if (!ethers.utils.isAddress(pluginRepoFactoryAddress)) {
throw new Error('Plugin Repo Factory in .env is not of type Address');
if (!isValidAddress(pluginRepoFactoryAddress)) {
throw new Error(
'Plugin Repo Factory in .env is not a valid address (is not an address or is address zero)'
);
}

const pluginRepoFactory = PluginRepoFactory__factory.connect(
Expand Down
20 changes: 16 additions & 4 deletions packages/contracts/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ export async function findPluginRepo(
const [deployer] = await hre.ethers.getSigners();

if (process.env.PLUGIN_REPO_ADDRESS) {
if (!ethers.utils.isAddress(process.env.PLUGIN_REPO_ADDRESS)) {
throw new Error('Plugin Repo in .env is not of type Address');
if (!isValidAddress(process.env.PLUGIN_REPO_ADDRESS)) {
throw new Error(
'Plugin Repo in .env is not a valid address (is not an address or is address zero)'
);
}

return {
Expand All @@ -90,8 +92,10 @@ export async function findPluginRepo(
const pluginRepoFactoryAddress = process.env.PLUGIN_REPO_FACTORY_ADDRESS;

if (pluginRepoFactoryAddress) {
if (!ethers.utils.isAddress(pluginRepoFactoryAddress)) {
throw new Error('Plugin Repo Factory in .env is not of type Address');
if (!isValidAddress(pluginRepoFactoryAddress)) {
throw new Error(
'Plugin Repo Factory in .env is not valid address (is not an address or is address zero)'
);
}
// get ENS registrar from the plugin factory provided
const pluginRepoFactory = PluginRepoFactory__factory.connect(
Expand Down Expand Up @@ -291,5 +295,13 @@ export async function createVersion(
return tx;
}

export function isValidAddress(address: string): boolean {
// check if the address is of type address and not zero address

return (
ethers.utils.isAddress(address) && address !== ethers.constants.AddressZero
);
}

export const AragonOSxAsciiArt =
" ____ _____ \n /\\ / __ \\ / ____| \n / \\ _ __ __ _ __ _ ___ _ __ | | | | (_____ __ \n / /\\ \\ | '__/ _` |/ _` |/ _ \\| '_ \\ | | | |\\___ \\ \\/ / \n / ____ \\| | | (_| | (_| | (_) | | | | | |__| |____) > < \n /_/ \\_\\_| \\__,_|\\__, |\\___/|_| |_| \\____/|_____/_/\\_\\ \n __/ | \n |___/ \n";

0 comments on commit 4e15e02

Please sign in to comment.