├── .gitattributes ├── .czrc ├── test ├── constants │ ├── values.json │ └── error-messages.json ├── types.ts ├── constants.ts ├── utils.ts ├── factory.ts ├── SafeGuardScenarios │ └── gnosisSafe.ts └── safeGuard.ts ├── .DS_Store ├── tasks ├── task-names.ts ├── accounts.ts └── clean.ts ├── .commitlintrc.js ├── .huskyrc ├── assets └── architecture-diagram.png ├── .solhintignore ├── .mocharc.json ├── .prettierignore ├── types ├── index.ts └── augmentations.d.ts ├── .eslintignore ├── contracts ├── mocks │ ├── MockContract.sol │ ├── Timelock.sol │ └── Comp.sol ├── ITimelock.sol ├── ISafeGuard.sol ├── SafeGuardFactory.sol └── SafeGuard.sol ├── .editorconfig ├── .env.example ├── .gitignore ├── .prettierrc ├── .github └── workflows │ ├── greetings.yml │ └── integration.yml ├── .solhint.json ├── .eslintrc.yaml ├── tsconfig.json ├── .solcover.js ├── LICENSE ├── scripts ├── deploy.ts ├── fail-safe-deploy.ts └── mainnet-deployment.ts ├── hardhat.config.ts ├── package.json └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sol linguist-language=Solidity -------------------------------------------------------------------------------- /.czrc: -------------------------------------------------------------------------------- 1 | { 2 | "path": "cz-conventional-changelog" 3 | } 4 | -------------------------------------------------------------------------------- /test/constants/values.json: -------------------------------------------------------------------------------- 1 | { 2 | "SAFEGUARD_VERSION": 1 3 | } -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/withtally/safeguard/HEAD/.DS_Store -------------------------------------------------------------------------------- /tasks/task-names.ts: -------------------------------------------------------------------------------- 1 | export const TASK_ACCOUNTS: string = "accounts"; 2 | -------------------------------------------------------------------------------- /.commitlintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ["@commitlint/config-conventional"], 3 | }; 4 | -------------------------------------------------------------------------------- /.huskyrc: -------------------------------------------------------------------------------- 1 | { 2 | "hooks": { 3 | "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /assets/architecture-diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/withtally/safeguard/HEAD/assets/architecture-diagram.png -------------------------------------------------------------------------------- /.solhintignore: -------------------------------------------------------------------------------- 1 | # folders 2 | .yarn/ 3 | build/ 4 | dist/ 5 | node_modules/ 6 | contracts/mocks 7 | contracts/ITimelock.sol -------------------------------------------------------------------------------- /.mocharc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extension": ["ts"], 3 | "recursive": "test", 4 | "require": ["hardhat/register"], 5 | "timeout": 20000 6 | } 7 | -------------------------------------------------------------------------------- /test/types.ts: -------------------------------------------------------------------------------- 1 | import { Signer } from "@ethersproject/abstract-signer"; 2 | 3 | export type User = { 4 | signer: Signer; 5 | address: string; 6 | }; 7 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # folders 2 | artifacts/ 3 | build/ 4 | cache/ 5 | coverage/ 6 | dist/ 7 | lib/ 8 | node_modules/ 9 | typechain/ 10 | 11 | # files 12 | coverage.json 13 | -------------------------------------------------------------------------------- /types/index.ts: -------------------------------------------------------------------------------- 1 | import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/dist/src/signer-with-address"; 2 | 3 | export interface Signers { 4 | admin: SignerWithAddress; 5 | } 6 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | # folders 2 | artifacts/ 3 | build/ 4 | cache/ 5 | coverage/ 6 | dist/ 7 | lib/ 8 | node_modules/ 9 | typechain/ 10 | 11 | # files 12 | .solcover.js 13 | coverage.json 14 | -------------------------------------------------------------------------------- /contracts/mocks/MockContract.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.8.0; 2 | 3 | contract MockContract { 4 | address public lastReceiver; 5 | 6 | function _transfer(address payable _reciver, uint256 amount) public payable { 7 | _reciver.transfer(amount); 8 | 9 | lastReceiver = _reciver; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # All files 7 | [*] 8 | charset = utf-8 9 | end_of_line = lf 10 | indent_size = 2 11 | indent_style = space 12 | insert_final_newline = true 13 | trim_trailing_whitespace = true 14 | 15 | [*.sol] 16 | indent_size = 4 17 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | INFURA_API_KEY=zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz 2 | MNEMONIC=here is where your twelve words mnemonic should be put my friend 3 | RINKEBY_PRIVATE_KEY=here you put the private key used for deployments to rinkeby 4 | METAMASK_ADDRESS=here you should put your metamask address 5 | SAFE_ADDRESS=here you should put your gnosis safe address -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # folders 2 | .coverage_artifacts/ 3 | .coverage_cache/ 4 | .coverage_contracts/ 5 | artifacts/ 6 | build/ 7 | cache/ 8 | coverage/ 9 | dist/ 10 | lib/ 11 | node_modules/ 12 | typechain/ 13 | 14 | # files 15 | *.env 16 | *.log 17 | *.tsbuildinfo 18 | coverage.json 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | -------------------------------------------------------------------------------- /test/constants.ts: -------------------------------------------------------------------------------- 1 | export const Address0 = "0x".padEnd(42, "0"); 2 | export const proposerRole = "0xb09aa5aeb3702cfd50b6b62bc4532604938f21248a27a1d5ca736082b6819cc1"; 3 | export const executerRole = "0xd8aa0f3194971a2a116679f7c2090f6939c8d4e01a2a8d7e41d55e5351469e63"; 4 | export const cancelerRole = "0xebfdca8e46c0b8dacf9989ee613e35727eadd20a1d5e5ad01a53968c7e5fe07a"; -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "arrowParens": "avoid", 3 | "bracketSpacing": true, 4 | "endOfLine":"auto", 5 | "printWidth": 120, 6 | "singleQuote": false, 7 | "tabWidth": 2, 8 | "trailingComma": "all", 9 | "overrides": [ 10 | { 11 | "files": "*.sol", 12 | "options": { 13 | "tabWidth": 4 14 | } 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /types/augmentations.d.ts: -------------------------------------------------------------------------------- 1 | // eslint-disable @typescript-eslint/no-explicit-any 2 | import { Fixture } from "ethereum-waffle"; 3 | 4 | import { Signers } from "./"; 5 | import { Greeter } from "../typechain"; 6 | 7 | declare module "mocha" { 8 | export interface Context { 9 | greeter: Greeter; 10 | loadFixture: (fixture: Fixture) => Promise; 11 | signers: Signers; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/constants/error-messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "INVALID_FAILSAFE_INDEX": "SafeGuardFactory:: Invalid index", 3 | "INVALID_VERSION": "SafeGuardFactory:: Invalid version", 4 | "ALREADY_REGISTERED": "SafeGuardFactory:: SafeGuard already registered", 5 | "REQUIRES_PERMISSION": "SafeGuard: sender requires permission", 6 | "TIMELOCK_ALREADY_DEFINED": "SafeGuard::setTimelock: Timelock address already defined" 7 | } -------------------------------------------------------------------------------- /tasks/accounts.ts: -------------------------------------------------------------------------------- 1 | import { Signer } from "@ethersproject/abstract-signer"; 2 | import { task } from "hardhat/config"; 3 | 4 | import { TASK_ACCOUNTS } from "./task-names"; 5 | 6 | task(TASK_ACCOUNTS, "Prints the list of accounts", async (_taskArgs, hre) => { 7 | const accounts: Signer[] = await hre.ethers.getSigners(); 8 | 9 | for (const account of accounts) { 10 | console.log(await account.getAddress()); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /tasks/clean.ts: -------------------------------------------------------------------------------- 1 | import fsExtra from "fs-extra"; 2 | import { TASK_CLEAN } from "hardhat/builtin-tasks/task-names"; 3 | import { task } from "hardhat/config"; 4 | 5 | task(TASK_CLEAN, "Overrides the standard clean task", async function (_taskArgs, { config }, runSuper) { 6 | await fsExtra.remove("./coverage"); 7 | await fsExtra.remove("./coverage.json"); 8 | if (config.typechain?.outDir) { 9 | await fsExtra.remove(config.typechain.outDir); 10 | } 11 | await runSuper(); 12 | }); 13 | -------------------------------------------------------------------------------- /.github/workflows/greetings.yml: -------------------------------------------------------------------------------- 1 | name: Greetings 2 | 3 | on: [pull_request, issues] 4 | 5 | jobs: 6 | greeting: 7 | runs-on: ubuntu-latest 8 | permissions: 9 | issues: write 10 | pull-requests: write 11 | steps: 12 | - uses: actions/first-interaction@v1 13 | with: 14 | repo-token: ${{ secrets.GITHUB_TOKEN }} 15 | issue-message: 'Message that will be displayed on users first issue' 16 | pr-message: 'Message that will be displayed on users first pull request' 17 | -------------------------------------------------------------------------------- /.solhint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "solhint:recommended", 3 | "plugins": ["prettier"], 4 | "rules": { 5 | "code-complexity": ["error", 7], 6 | "compiler-version": ["error", "^0.8.0"], 7 | "const-name-snakecase": "off", 8 | "constructor-syntax": "error", 9 | "func-visibility": ["error", { "ignoreConstructors": true }], 10 | "max-line-length": ["error", 120], 11 | "not-rely-on-time": "off", 12 | "prettier/prettier": [ 13 | "error", 14 | { 15 | "endOfLine": "auto" 16 | } 17 | ], 18 | "reason-string": ["warn", { "maxLength": 64 }] 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /.eslintrc.yaml: -------------------------------------------------------------------------------- 1 | extends: 2 | - eslint:recommended 3 | - plugin:@typescript-eslint/eslint-recommended 4 | - plugin:@typescript-eslint/recommended 5 | - prettier/@typescript-eslint 6 | parser: "@typescript-eslint/parser" 7 | parserOptions: 8 | project: tsconfig.json 9 | plugins: 10 | - "@typescript-eslint" 11 | root: true 12 | rules: 13 | "@typescript-eslint/no-floating-promises": 14 | - error 15 | - ignoreIIFE: true 16 | ignoreVoid: true 17 | "@typescript-eslint/no-inferrable-types": "off" 18 | "@typescript-eslint/no-unused-vars": 19 | - error 20 | - argsIgnorePattern: _ 21 | varsIgnorePattern: _ 22 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "esModuleInterop": true, 4 | "forceConsistentCasingInFileNames": true, 5 | "lib": ["es5", "es6"], 6 | "module": "commonjs", 7 | "moduleResolution": "node", 8 | "noImplicitAny": true, 9 | "outDir": "dist", 10 | "resolveJsonModule": true, 11 | "sourceMap": true, 12 | "strict": true, 13 | "target": "es5" 14 | }, 15 | "exclude": ["node_modules"], 16 | "include": [ 17 | "artifacts/**/*", 18 | "artifacts/**/*.json", 19 | "scripts/**/*", 20 | "tasks/**/*", 21 | "test/**/*", 22 | "typechain/**/*", 23 | "types/**/*", 24 | "hardhat.config.ts" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /.solcover.js: -------------------------------------------------------------------------------- 1 | const shell = require("shelljs"); 2 | 3 | // The environment variables are loaded in hardhat.config.ts 4 | const mnemonic = process.env.MNEMONIC; 5 | if (!mnemonic) { 6 | throw new Error("Please set your MNEMONIC in a .env file"); 7 | } 8 | 9 | module.exports = { 10 | istanbulReporter: ["html", "lcov"], 11 | onCompileComplete: async function (_config) { 12 | await run("typechain"); 13 | }, 14 | onIstanbulComplete: async function (_config) { 15 | // We need to do this because solcover generates bespoke artifacts. 16 | shell.rm("-rf", "./artifacts"); 17 | shell.rm("-rf", "./typechain"); 18 | }, 19 | providerOptions: { 20 | mnemonic, 21 | }, 22 | skipFiles: ["mocks", "test"], 23 | }; 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Tally 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /contracts/ITimelock.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-License-Identifier: MIT 3 | */ 4 | 5 | pragma solidity 0.8.7; 6 | 7 | /** 8 | * @dev External interface of Coumpound timelock 9 | */ 10 | interface ITimelock { 11 | function delay() external view returns (uint256); 12 | 13 | function GRACE_PERIOD() external view returns (uint256); 14 | 15 | function acceptAdmin() external; 16 | 17 | function queuedTransactions(bytes32 hash) external view returns (bool); 18 | 19 | function queueTransaction( 20 | address target, 21 | uint256 value, 22 | string calldata signature, 23 | bytes calldata data, 24 | uint256 eta 25 | ) external returns (bytes32); 26 | 27 | function cancelTransaction( 28 | address target, 29 | uint256 value, 30 | string calldata signature, 31 | bytes calldata data, 32 | uint256 eta 33 | ) external; 34 | 35 | function executeTransaction( 36 | address target, 37 | uint256 value, 38 | string calldata signature, 39 | bytes calldata data, 40 | uint256 eta 41 | ) external payable returns (bytes memory); 42 | } 43 | -------------------------------------------------------------------------------- /contracts/ISafeGuard.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-License-Identifier: MIT 3 | */ 4 | 5 | pragma solidity 0.8.7; 6 | 7 | /** 8 | * @dev External interface of SafeGuard. 9 | */ 10 | interface ISafeGuard { 11 | function setTimelock(address _timelock) external; 12 | 13 | function hashProposalTx( 14 | address _target, 15 | uint256 _value, 16 | string memory _signature, 17 | bytes memory _data, 18 | uint256 _eta 19 | ) external pure returns (bytes32); 20 | 21 | function queueTransaction( 22 | address _target, 23 | uint256 _value, 24 | string calldata _signature, 25 | bytes calldata _data, 26 | uint256 _eta 27 | ) external; 28 | 29 | function queueTransactionWithDescription( 30 | address _target, 31 | uint256 _value, 32 | string memory _signature, 33 | bytes memory _data, 34 | uint256 _eta, 35 | string memory _description 36 | ) external; 37 | 38 | function cancelTransaction( 39 | address _target, 40 | uint256 _value, 41 | string calldata _signature, 42 | bytes calldata _data, 43 | uint256 _eta 44 | ) external; 45 | 46 | function executeTransaction( 47 | address _target, 48 | uint256 _value, 49 | string calldata _signature, 50 | bytes calldata _data, 51 | uint256 _eta 52 | ) external payable; 53 | } 54 | -------------------------------------------------------------------------------- /scripts/deploy.ts: -------------------------------------------------------------------------------- 1 | import { Contract, ContractFactory } from "ethers"; 2 | // We require the Hardhat Runtime Environment explicitly here. This is optional 3 | // but useful for running the script in a standalone fashion through `node