Skip to content

Commit

Permalink
[#23] Organise imports, remove unused imports, fix linting issues (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay-ap authored Oct 13, 2023
1 parent 402ab26 commit 22d474b
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 37 deletions.
1 change: 0 additions & 1 deletion contracts/contracts/Imports.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity ^0.8.18;

// Import the contract so hardhat compiles it, and we have the ABI available
import {MockContract} from "@safe-global/mock-contract/contracts/MockContract.sol";
import {TestSafeProtocolRegistryUnrestricted} from "@safe-global/safe-core-protocol/contracts/test/TestSafeProtocolRegistryUnrestricted.sol";

// ExecutableMockContract for testing

Expand Down
3 changes: 1 addition & 2 deletions contracts/contracts/RecoveryWithDelayPlugin.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.18;
import {ISafe} from "@safe-global/safe-core-protocol/contracts/interfaces/Accounts.sol";
import {ISafeProtocolPlugin} from "@safe-global/safe-core-protocol/contracts/interfaces/Integrations.sol";
import {ISafeProtocolManager} from "@safe-global/safe-core-protocol/contracts/interfaces/Manager.sol";
import {BasePluginWithEventMetadata, PluginMetadata} from "./Base.sol";
import {SafeTransaction, SafeRootAccess, SafeProtocolAction} from "@safe-global/safe-core-protocol/contracts/DataTypes.sol";
import { SafeRootAccess, SafeProtocolAction} from "@safe-global/safe-core-protocol/contracts/DataTypes.sol";

/**
* @title RecoveryWithDelayPlugin - A contract compatible with Safe{Core} Protocol that replaces a specified owner for a Safe by a non-owner account.
Expand Down
3 changes: 1 addition & 2 deletions contracts/contracts/WhitelistPlugin.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.18;
import {ISafe} from "@safe-global/safe-core-protocol/contracts/interfaces/Accounts.sol";
import {ISafeProtocolPlugin} from "@safe-global/safe-core-protocol/contracts/interfaces/Integrations.sol";
import {ISafeProtocolManager} from "@safe-global/safe-core-protocol/contracts/interfaces/Manager.sol";
import {SafeTransaction, SafeRootAccess, SafeProtocolAction} from "@safe-global/safe-core-protocol/contracts/DataTypes.sol";
import {SafeTransaction, SafeProtocolAction} from "@safe-global/safe-core-protocol/contracts/DataTypes.sol";
import {BasePluginWithEventMetadata, PluginMetadata} from "./Base.sol";

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/tasks/test_registry.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "hardhat-deploy";
import "@nomicfoundation/hardhat-ethers";
import { task } from "hardhat/config";
import { getPlugin, getRegistry, getRelayPlugin } from "../utils/contracts";
import { getPlugin, getRegistry, getRelayPlugin } from "../../test/utils/contracts";
import { IntegrationType } from "../utils/constants";
import { loadPluginMetadata } from "../utils/metadata";

Expand Down
2 changes: 1 addition & 1 deletion contracts/src/utils/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbiCoder, Interface, isHexString, keccak256 } from "ethers";
import { BasePlugin, IMetadataProvider } from "../../typechain-types";
import { getInstance } from "../utils/contracts";
import { getInstance } from "../../test/utils/contracts";
import { HardhatRuntimeEnvironment } from "hardhat/types";

interface PluginMetadata {
Expand Down
44 changes: 22 additions & 22 deletions contracts/src/utils/protocol.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import protocolDeployments from "@safe-global/safe-core-protocol"
import protocolDeployments from "@safe-global/safe-core-protocol";
import { id } from "ethers";

const deployMock = async(hre: HardhatRuntimeEnvironment, name: string): Promise<string> => {
const deployMock = async (hre: HardhatRuntimeEnvironment, name: string): Promise<string> => {
const { deployments, getNamedAccounts } = hre;
const { deployer } = await getNamedAccounts();
const { deploy } = deployments;
Expand All @@ -13,30 +13,30 @@ const deployMock = async(hre: HardhatRuntimeEnvironment, name: string): Promise<
log: true,
deterministicDeployment: id(name),
});
return result.address
}
return result.address;
};

export const getProtocolManagerAddress = async(hre: HardhatRuntimeEnvironment): Promise<string> => {
const chainId = await hre.getChainId()
export const getProtocolManagerAddress = async (hre: HardhatRuntimeEnvironment): Promise<string> => {
const chainId = await hre.getChainId();

// For the tests we deploy a mock for the manager
if (chainId === "31337") return deployMock(hre, "ManagerMock")

if (!(chainId in protocolDeployments)) throw Error("Unsupported Chain")
const manager = (protocolDeployments as any)[chainId][0].contracts.SafeProtocolManager.address
if (typeof manager !== "string") throw Error("Unexpected Manager")
return manager
}
if (chainId === "31337") return deployMock(hre, "ManagerMock");

export const getProtocolRegistryAddress = async(hre: HardhatRuntimeEnvironment): Promise<string> => {
const chainId = await hre.getChainId()
if (!(chainId in protocolDeployments)) throw Error("Unsupported Chain");
const manager = (protocolDeployments as any)[chainId][0].contracts.SafeProtocolManager.address;
if (typeof manager !== "string") throw Error("Unexpected Manager");
return manager;
};

export const getProtocolRegistryAddress = async (hre: HardhatRuntimeEnvironment): Promise<string> => {
const chainId = await hre.getChainId();

// For the tests we deploy a mock for the registry
if (chainId === "31337") return deployMock(hre, "RegistryMock")
if (!(chainId in protocolDeployments)) throw Error("Unsupported Chain")
if (chainId === "31337") return deployMock(hre, "RegistryMock");

if (!(chainId in protocolDeployments)) throw Error("Unsupported Chain");
// We use the unrestricted registry for the demo
const registry = (protocolDeployments as any)[chainId][0].contracts.TestSafeProtocolRegistryUnrestricted.address
if (typeof registry !== "string") throw Error("Unexpected Registry")
return registry
}
const registry = (protocolDeployments as any)[chainId][0].contracts.TestSafeProtocolRegistryUnrestricted.address;
if (typeof registry !== "string") throw Error("Unexpected Registry");
return registry;
};
2 changes: 1 addition & 1 deletion contracts/test/RecoveryWithDelayPlugin.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import hre, { deployments, ethers } from "hardhat";
import { expect } from "chai";
import { getProtocolManagerAddress } from "../src/utils/protocol";
import { getRecoveryWithDelayPlugin } from "../src/utils/contracts";
import { getRecoveryWithDelayPlugin } from "./utils/contracts";
import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";
import { ISafeProtocolManager__factory } from "../typechain-types";
import { SafeProtocolAction, SafeRootAccess } from "../src/utils/dataTypes";
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/RelayPlugin.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import hre, { deployments, ethers } from "hardhat";
import { expect } from "chai";
import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";
import { getRelayPlugin } from "../src/utils/contracts";
import { getRelayPlugin } from "./utils/contracts";
import { loadPluginMetadata } from "../src/utils/metadata";
import { getProtocolManagerAddress } from "../src/utils/protocol";
import { Interface, MaxUint256, ZeroAddress, ZeroHash, getAddress, keccak256 } from "ethers";
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/WhitelistPlugin.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import hre, { deployments, ethers } from "hardhat";
import { expect } from "chai";
import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";
import { getWhiteListPlugin, getInstance } from "../src/utils/contracts";
import { getWhiteListPlugin, getInstance } from "./utils/contracts";
import { loadPluginMetadata } from "../src/utils/metadata";
import { buildSingleTx } from "../src/utils/builder";
import { ISafeProtocolManager__factory, MockContract } from "../typechain-types";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import { Addressable, BaseContract } from "ethers";
import { BasePlugin, RecoveryWithDelayPlugin, RelayPlugin, TestSafeProtocolRegistryUnrestricted, WhitelistPlugin } from "../../typechain-types";
import {
BasePlugin,
RecoveryWithDelayPlugin,
RelayPlugin,
TestSafeProtocolRegistryUnrestricted,
WhitelistPlugin,
} from "../../typechain-types";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { getProtocolManagerAddress, getProtocolRegistryAddress } from "./protocol";
import { getProtocolRegistryAddress } from "../../src/utils/protocol";

export const getInstance = async <T extends BaseContract>(hre: HardhatRuntimeEnvironment, name: string, address: string | Addressable): Promise<T> => {
export const getInstance = async <T extends BaseContract>(
hre: HardhatRuntimeEnvironment,
name: string,
address: string | Addressable,
): Promise<T> => {
// TODO: this typecasting should be refactored
return (await hre.ethers.getContractAt(name, address)) as unknown as T;
};
Expand All @@ -15,6 +25,8 @@ export const getSingleton = async <T extends BaseContract>(hre: HardhatRuntimeEn

export const getPlugin = (hre: HardhatRuntimeEnvironment, address: string) => getInstance<BasePlugin>(hre, "BasePlugin", address);
export const getRelayPlugin = (hre: HardhatRuntimeEnvironment) => getSingleton<RelayPlugin>(hre, "RelayPlugin");
export const getRegistry = async (hre: HardhatRuntimeEnvironment) => getInstance<TestSafeProtocolRegistryUnrestricted>(hre, "TestSafeProtocolRegistryUnrestricted", await getProtocolRegistryAddress(hre));
export const getRegistry = async (hre: HardhatRuntimeEnvironment) =>
getInstance<TestSafeProtocolRegistryUnrestricted>(hre, "TestSafeProtocolRegistryUnrestricted", await getProtocolRegistryAddress(hre));
export const getWhiteListPlugin = async (hre: HardhatRuntimeEnvironment) => getSingleton<WhitelistPlugin>(hre, "WhitelistPlugin");
export const getRecoveryWithDelayPlugin= async(hre: HardhatRuntimeEnvironment) => getSingleton<RecoveryWithDelayPlugin>(hre, "RecoveryWithDelayPlugin");
export const getRecoveryWithDelayPlugin = async (hre: HardhatRuntimeEnvironment) =>
getSingleton<RecoveryWithDelayPlugin>(hre, "RecoveryWithDelayPlugin");

0 comments on commit 22d474b

Please sign in to comment.