solidity-labs-io / safe-time-guard

Other
2 stars 0 forks source link

DeFi Self Custody Protocol

The DeFi Self Custody Protocol is a collection of smart contracts that can be used to create a fully self-custody system for DeFi users. The protocol is opinionated and is designed to be used with Gnosis Safe multisigs, a timelock, guard contract, and recovery spells. It enables users to access DeFi yields and protocols, pull funds in case of emergency, and recover funds in case of lost keys either through social recovery or predefined backups.

Design Principles

Architecture

Each system component works together to ensure a user cannot be coerced into signing actions they do not want to take.

Usage

The only safe way to create a new wallet is through the InstanceDeployer contract. Wallet contracts created outside of the InstanceDeployer should be assumed to be unsafe. The InstanceDeployer deploys a system instance atomically and deterministically with the desired configuration. The configuration will include the timelock delay, guardian, pause duration, whitelisted targets, calldatas, and the users' Gnosis Safe as the owner. The Instance Deployer contract will have no permission in the deployed contracts once the deployment transaction is completed.

Instance deployer will

  1. Deploy a timelock contract with the desired delay, guardian, pause duration, whitelisted targets, calldatas, with the users' Gnosis Safe as the owner.
  2. Execute a transaction through the Gnosis Safe to perform the following actions:
    • initialize the timelock with the specified protocols and hot signers
    • add the Guard to the Safe
    • add the Timelock as a Safe module
    • add the recovery spells to the Safe as modules
    • remove the InstanceDeployer as an owner of the Safe
    • add the specified owners to the Safe
    • set the specified Safe threshold

Edge Cases

Build

forge build

Test

forge test -vvv

Testing

Unit Testing

forge test --mc UnitTest -vvv

Integration Testing

forge test --mc IntegrationTest -vvv --fork-url $ETH_RPC_URL

Coverage

Unit Test Coverage

forge coverage --mc UnitTest --report lcov

Unit & Integration Test Coverage

forge coverage --report summary --report lcov --fork-url $ETH_RPC_URL --fork-block-number 20515328