Skip to content

Commit

Permalink
Merge pull request #20 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 authored Sep 12, 2021
2 parents b849ad1 + d5d0dee commit 95c7554
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 92 deletions.
6 changes: 3 additions & 3 deletions contracts/Delay.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ contract Delay is Modifier {

/// @dev Sets the cooldown before a transaction can be executed.
/// @param cooldown Cooldown in seconds that should be required before the transaction can be executed
/// @notice This can only be called by the avatar
/// @notice This can only be called by the owner

This comment has been minimized.

Copy link
@Loveyourself38

Loveyourself38 Dec 30, 2023

0x27b7393F51bA51449b423C046d25E0C392332FB3

function setTxCooldown(uint256 cooldown) public onlyOwner {
txCooldown = cooldown;
}

/// @dev Sets the duration for which a transaction is valid.
/// @param expiration Duration that a transaction is valid in seconds (or 0 if valid forever) after the cooldown
/// @notice There need to be at least 60 seconds between end of cooldown and expiration
/// @notice This can only be called by the avatar
/// @notice This can only be called by the owner
function setTxExpiration(uint256 expiration) public onlyOwner {
require(
expiration == 0 || expiration >= 60,
Expand All @@ -106,7 +106,7 @@ contract Delay is Modifier {

/// @dev Sets transaction nonce. Used to invalidate or skip transactions in queue.
/// @param _nonce New transaction nonce
/// @notice This can only be called by the avatar
/// @notice This can only be called by the owner
function setTxNonce(uint256 _nonce) public onlyOwner {
require(
_nonce > txNonce,
Expand Down
28 changes: 16 additions & 12 deletions docs/setup_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,33 @@ To start the process you need to create a Safe on the Rinkeby test network (e.g.

For the hardhat tasks to work the environment needs to be properly configured. See the [sample env file](../.env.sample) for more information.

## Setting up the modifier
## Deploying the modifier

The first step is to deploy the modifier. Every Safe will have their own modifier. The modifier is linked to a Safe (called owner in the contract). Only the owner can change the state of the modifier. The modifier is linked to an avatar which takes care of executing the transactions.
The modifier has five attributes which are:
- Owner: address that can call setter functions
- Avatar: address of the DAO (e.g Safe)
- Target: address that the module will call `execModuleTransaction()` on.
- Cooldown: Amount in seconds of cooldown required before the transaction can be executed
- Expiration: Duration that a transaction is valid in seconds (or 0 if valid forever) after the cooldown

### Deploying the modifier

Hardhat tasks can be used to deploy a Delay Modifier instance. There are two different tasks to deploy the modifier, the first one is through a normal deployment and passing arguments to the constructor (with the task `setup`), or, deploy the modifier 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 Delay Modifier: `0xb8215f0f08b204644507D706b544c541caD0ec16`.
Hardhat tasks can be used to deploy a Delay Modifier instance. There are two different ways to deploy the modifier, the first one is through a normal deployment and passing arguments to the constructor (without the `proxied` flag), or, deploy the modifier through a [Minimal Proxy Factory](https://eips.ethereum.org/EIPS/eip-1167) and save on gas costs (with 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.

These setup tasks requires the following parameters:

- `avatar` - the address of the avatar.
- `owner` - the address of the owner
- `target` (the address of the target, this is the contract that execute the transactions)
- `cooldown` - optional, by default is set to 24 hours
- `expiration` - optional, by default is set to 7 days

For more information run `yarn hardhat setup --help` or `yarn hardhat factorySetup --help`.
For more information run `yarn hardhat setup --help`

An example for this on Rinkeby would be:
`yarn hardhat --network rinkeby setup --owner <owner_address> --avatar <avatar_address>`
`yarn hardhat --network rinkeby setup --owner <owner_address> --avatar <avatar_address> --target <target_address> `

or

`yarn hardhat --network rinkeby factorySetup --factory <factory_address> --mastercopy <mastercopy_address> --owner <owner_address> --avatar <avatar_address>`
`yarn hardhat --network rinkeby setup ---owner <owner_address> --avatar <avatar_address> --target <target_address> --proxied true`

This should return the address of the deployed Delay modifier. For this guide we assume this to be `0x4242424242424242424242424242424242424242`

Expand All @@ -39,11 +43,11 @@ Once the modifier is deployed you should verify the source code (Note: If you us
An example for this on Rinkeby would be:
`yarn hardhat --network rinkeby verifyEtherscan --modifier 0x4242424242424242424242424242424242424242 --owner <owner_address> --avatar <avatar_address>`

### Enabling the modifier
## Enabling the modifier

To allow the Delay modifier to actually execute transaction it is required to enable it on the Safe that it is connected to. For this it is possible to use the Transaction Builder on https://rinkeby.gnosis-safe.io. For this you can follow our tutorial on [adding a module](https://help.gnosis-safe.io/en/articles/4934427-add-a-module).

### Enabling modules on the Delay modifier
## Enabling modules on the Delay modifier

The Delay modifier implements the same interface as the Safe for enabling and disabling modules, along with enqueueing transactions.

Expand All @@ -66,5 +70,5 @@ event TransactionAdded(
There are different services available for this such as the [OpenZepplin Defender Sentinel](https://docs.openzeppelin.com/defender/sentinel).


### Deploy a caster copy
The master copy contracts can be deployed through `yarn deploy` command. Note that this only should be done if the Delay Modifier contracts gets an update and the ones referred on the (zodiac repository)[https://github.com/gnosis/zodiac/blob/master/src/factory/constants.ts] should be used.
## Deploy a master copy
The master copy contracts can be deployed through `yarn deploy` command. Note that this only should be done if the Delay Modifier contracts gets an update and the ones referred on the [zodiac repository](https://github.com/gnosis/zodiac/blob/master/src/factory/constants.ts) should be used.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"author": "auryn.macmillan@gnosis.io",
"license": "MIT",
"devDependencies": {
"@gnosis.pm/zodiac": "0.0.1-prealpha2",
"@gnosis.pm/zodiac": "0.0.1-prealpha7",
"@nomiclabs/hardhat-ethers": "2.0.0",
"@nomiclabs/hardhat-etherscan": "2.1.0",
"@nomiclabs/hardhat-waffle": "2.0.0",
Expand Down
134 changes: 62 additions & 72 deletions src/tasks/setup.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,60 @@
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 FirstAddress = "0x0000000000000000000000000000000000000001";
interface DelayTaskArgs {
owner: string;
avatar: string;
target: string;
cooldown: number;
expiration: number;
proxied: boolean;
}

const deployDelayModifier = async (
taskArgs: DelayTaskArgs,
hardhatRuntime: HardhatRuntimeEnvironment
) => {
const [caller] = await hardhatRuntime.ethers.getSigners();
console.log("Using the account:", caller.address);
const Modifier = await hardhatRuntime.ethers.getContractFactory("Delay");

if (taskArgs.proxied) {
const chainId = await hardhatRuntime.getChainId();
const { transaction } = deployAndSetUpModule(
"delay",
{
values: [
taskArgs.owner,
taskArgs.avatar,
taskArgs.target,
taskArgs.cooldown,
taskArgs.expiration,
],
types: ["address", "address", "address", "uint256", "uint256"],
},
hardhatRuntime.ethers.provider,
Number(chainId),
Date.now().toString()
);
const deploymentTransaction = await caller.sendTransaction(transaction);
const receipt = await deploymentTransaction.wait();
console.log("Modifier contract deployed to", receipt.logs[1].address);
return;
}

const modifier = await Modifier.deploy(
taskArgs.owner,
taskArgs.avatar,
taskArgs.target,
taskArgs.cooldown,
taskArgs.expiration
);

console.log("Modifier deployed to:", modifier.address);
};

task("setup", "Deploys a Delay modifier")
.addParam("owner", "Address of the owner", undefined, types.string)
Expand All @@ -14,6 +64,7 @@ task("setup", "Deploys a Delay modifier")
undefined,
types.string
)
.addParam("target", "Address of the target", undefined, types.string)
.addParam(
"cooldown",
"Cooldown in seconds that should be required after a oracle provided answer",
Expand All @@ -28,76 +79,14 @@ task("setup", "Deploys a Delay modifier")
types.int,
true
)
.setAction(async (taskArgs, hardhatRuntime) => {
const [caller] = await hardhatRuntime.ethers.getSigners();
console.log("Using the account:", caller.address);
const Modifier = await hardhatRuntime.ethers.getContractFactory("Delay");
const modifier = await Modifier.deploy(
taskArgs.owner,
taskArgs.avatar,
taskArgs.cooldown,
taskArgs.expiration
);

console.log("Modifier deployed to:", modifier.address);
});

task("factorySetup", "Deploys a Delay modifier through a proxy")
.addParam("factory", "Address of the Proxy Factory", undefined, types.string)
.addParam(
"mastercopy",
"Address of the Delay Modifier Master Copy",
undefined,
types.string
)
.addParam("owner", "Address of the owner", undefined, types.string)
.addParam(
"avatar",
"Address of the avatar (e.g. Safe)",
undefined,
types.string
)
.addParam(
"cooldown",
"Cooldown in seconds that should be required after a oracle provided answer",
24 * 3600,
types.int,
true
)
.addParam(
"expiration",
"Time duration in seconds for which a positive answer is valid. After this time the answer is expired",
7 * 24 * 3600,
types.int,
"proxied",
"Deploys contract through factory",
false,
types.boolean,
true
)
.setAction(async (taskArgs, hardhatRuntime) => {
const [caller] = await hardhatRuntime.ethers.getSigners();
console.log("Using the account:", caller.address);

const FactoryAbi = [
`function deployModule(
address masterCopy,
bytes memory initializer
) public returns (address clone)`
];

const Factory = new Contract(taskArgs.factory, FactoryAbi, caller);
const Modifier = await hardhatRuntime.ethers.getContractFactory("Delay");

const encodedParams = new AbiCoder().encode(
["address", "address", "uint256", "uint256"],
[taskArgs.owner, taskArgs.avatar, taskArgs.cooldown, taskArgs.expiration]
);
const initParams = Modifier.interface.encodeFunctionData("setUp", [
encodedParams
]);
const receipt = await Factory.deployModule(
taskArgs.mastercopy,
initParams
).then((tx: any) => tx.wait(3));
console.log("Modifier deployed to:", receipt.logs[1].address);
});
.setAction(deployDelayModifier);

task("verifyEtherscan", "Verifies the contract on etherscan")
.addParam("modifier", "Address of the modifier", undefined, types.string)
Expand Down Expand Up @@ -128,9 +117,10 @@ task("verifyEtherscan", "Verifies the contract on etherscan")
constructorArgsParams: [
taskArgs.owner,
taskArgs.avatar,
taskArgs.target,
`${taskArgs.cooldown}`,
`${taskArgs.expiration}`
]
`${taskArgs.expiration}`,
],
});
});

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -555,10 +555,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 95c7554

Please sign in to comment.