Skip to content

Commit

Permalink
Merge pull request #13 from gnosis/chore/scripts-and-documentation-up…
Browse files Browse the repository at this point in the history
…date

Chore: Tasks and documentation improved
  • Loading branch information
auryn-macmillan committed Sep 12, 2021
2 parents 7ff6a90 + 19ffb23 commit b9bc0e2
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ env/
.history
coverage*
build/
deployments
7 changes: 4 additions & 3 deletions docs/setup_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ For the hardhat tasks to work the environment needs to be properly configured. S

## Deploying the ScopeGuard

Hardhat tasks can be used to deploy a ScopeGuard instance. There are two different tasks to deploy it, the first one is through a normal deployment and passing arguments to the constructor (with the task `setup`), or, deploy the Module through a [Minimal Proxy Factory](https://eips.ethereum.org/EIPS/eip-1167) and save on gas costs (with the task `factorySetup`) - In rinkeby the address of the Proxy Factory is: `0xd067410a85ffC8C55f7245DE4BfE16C95329D232` and the Master Copy of the ScopeGuard: `0x13d233567817E3a38B4082217E44CBa77c06Eb7f`.
The guard only has one attribute which is:
- Owner: address that can call setter functions

These setup tasks requires the `owner` parameter
Hardhat tasks can be used to deploy a ScopeGuard instance. There are two different ways to deploy it, the first one is through a normal deployment and passing arguments to the constructor (without the `proxied` flag), or, deploy the Module through a [Minimal Proxy Factory](https://eips.ethereum.org/EIPS/eip-1167) and save on gas costs (without the `proxied` flag) - The master copy and factory address can be found in the [zodiac repository](https://github.com/gnosis/zodiac/blob/master/src/factory/constants.ts) and these are the addresses that are going to be used when deploying the module through factory.

_Note: Multiple safes can use the same instance of a ScopeGuard, but they will all have the same settings controlled by the same `owner`. In most cases it is preferable for each safe to have its own instance of ScopeGuard._

Expand All @@ -47,7 +48,7 @@ yarn hardhat setup --network rinkeby --owner <owner_address>
or

```bash
yarn hardhat factorySetup --network rinkeby --factory <factory_address> --mastercopy <masterCopy_address> --owner <owner_address>
yarn hardhat setup --network rinkeby --owner <owner_address> --proxied true
```

This should return the address of the deployed Scope Guard. For this guide we assume this to be `0x3939393939393939393939393939393939393939`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"test": "test"
},
"devDependencies": {
"@gnosis.pm/zodiac": "^0.0.1-prealpha2",
"@gnosis.pm/zodiac": "0.0.1-prealpha7",
"@nomiclabs/hardhat-ethers": "2.0.2",
"@nomiclabs/hardhat-etherscan": "2.1.4",
"@nomiclabs/hardhat-waffle": "2.0.1",
Expand Down
77 changes: 41 additions & 36 deletions src/tasks/setup.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,55 @@
import "hardhat-deploy";
import "@nomiclabs/hardhat-ethers";
import { task, types } from "hardhat/config";
import { Contract } from "ethers";
import { AbiCoder } from "ethers/lib/utils";
import { deployAndSetUpModule } from "@gnosis.pm/zodiac";
import { HardhatRuntimeEnvironment } from "hardhat/types";

const ZeroAddress = "0x0000000000000000000000000000000000000000";
const FirstAddress = "0x0000000000000000000000000000000000000001";
interface ScopeGuardTaskArgs {
owner: string;
proxied: boolean;
}

task("setup", "Deploys a ScopeGuard").setAction(async (_, hardhatRuntime) => {
const deployScopeGuard = async (
taskArgs: ScopeGuardTaskArgs,
hardhatRuntime: HardhatRuntimeEnvironment
) => {
const [caller] = await hardhatRuntime.ethers.getSigners();
console.log("Using the account:", caller.address);
const Guard = await hardhatRuntime.ethers.getContractFactory("ScopeGuard");
const guard = await Guard.deploy(ZeroAddress);

console.log("ScopeGuard deployed to:", guard.address);
});
if (taskArgs.proxied) {
const chainId = await hardhatRuntime.getChainId();
const { transaction } = deployAndSetUpModule(
"scopeGuard",
{
types: ["address"],
values: [taskArgs.owner],
},
hardhatRuntime.ethers.provider,
Number(chainId),
Date.now().toString()
);

task("factorySetup", "deploy a ScopeGuard through factory")
.addParam("factory", "Address of the Proxy Factory", undefined, types.string)
.addParam("mastercopy", "Address of the ScopeGuard Master Copy")
.addParam("owner", "Address of the owner", undefined, types.string)
.setAction(async (taskArgs, hardhatRuntime) => {
const [caller] = await hardhatRuntime.ethers.getSigners();
console.log("Using the account:", caller.address);
const deploymentTransaction = await caller.sendTransaction(transaction);
const receipt = await deploymentTransaction.wait();
console.log("ScopeGuard deployed to:", receipt.logs[1].address);
return;
}

const FactoryAbi = [
`function deployModule(
address masterCopy,
bytes memory initializer
) public returns (address proxy)`,
];
const Guard = await hardhatRuntime.ethers.getContractFactory("ScopeGuard");
const guard = await Guard.deploy(taskArgs.owner);
console.log("ScopeGuard deployed to:", guard.address);
};

const Factory = new Contract(taskArgs.factory, FactoryAbi, caller);
const ScopeGuard = await hardhatRuntime.ethers.getContractFactory(
"ScopeGuard"
);
const encodedParams = new AbiCoder().encode(["address"], [taskArgs.owner]);
const initParams = ScopeGuard.interface.encodeFunctionData("setUp", [
encodedParams,
]);
const receipt = await Factory.deployModule(
taskArgs.mastercopy,
initParams
).then((tx: any) => tx.wait(3));
console.log("ScopeGuard deployed to:", receipt.logs[1].address);
});
task("setup", "Deploys a ScopeGuard")
.addParam("owner", "Address of the Owner", undefined, types.string)
.addParam(
"proxied",
"Deploys contract through factory",
false,
types.boolean,
true
)
.setAction(deployScopeGuard);

task("verifyEtherscan", "Verifies the contract on etherscan")
.addParam("guard", "Address of the ScopeGuard", undefined, types.string)
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,10 @@
resolved "https://registry.yarnpkg.com/@gnosis.pm/safe-contracts/-/safe-contracts-1.3.0.tgz#316741a7690d8751a1f701538cfc9ec80866eedc"
integrity sha512-1p+1HwGvxGUVzVkFjNzglwHrLNA67U/axP0Ct85FzzH8yhGJb4t9jDjPYocVMzLorDoWAfKicGy1akPY9jXRVw==

"@gnosis.pm/zodiac@^0.0.1-prealpha2":
version "0.0.1-prealpha2"
resolved "https://registry.yarnpkg.com/@gnosis.pm/zodiac/-/zodiac-0.0.1-prealpha2.tgz#37634bf3abfda208b120622ed5b75f200dbe16c6"
integrity sha512-sSkhBrqerMiU//zHT6hAjrMJXSz6TcmRFL2OQRK+wBRpyoazBFfCJRQi3GAPLEjfDp/GOWsXJ8ERuo2CEGQAWQ==
"@gnosis.pm/zodiac@0.0.1-prealpha7":
version "0.0.1-prealpha7"
resolved "https://registry.yarnpkg.com/@gnosis.pm/zodiac/-/zodiac-0.0.1-prealpha7.tgz#0e648e45ca71cbe34fcc25e4c49332570c21d48b"
integrity sha512-BPgND+dozu3c0g0Tijm/DbYC/Xo51/EQHnCMN8yK1glogsM13BEkto8dshzTxXgwrRRyv6X46CGPLeNg7D56zQ==
dependencies:
"@gnosis.pm/mock-contract" "^4.0.0"
"@gnosis.pm/safe-contracts" "1.3.0"
Expand Down

0 comments on commit b9bc0e2

Please sign in to comment.