Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
feat: draft implementation of Safebox
Browse files Browse the repository at this point in the history
  • Loading branch information
amusingaxl committed Oct 19, 2022
1 parent f18f147 commit 82918ab
Show file tree
Hide file tree
Showing 13 changed files with 2,273 additions and 54 deletions.
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
indent_size = 2
indent_style = space

[*.sol]
indent_size = 4

# Tab indentation (no size specified)
[Makefile]
indent_style = tab
indent_size = 4

[*.sh]
switch_case_indent = true
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ cache/
out/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/
!broadcast
broadcast/*/31337/
broadcast/**/dry-run/

# Dotenv file
.env

# Node modules
node_modules/
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
lib/
out/
node_modules/
cache/
.vscode/
13 changes: 13 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"printWidth": 120,
"overrides": [
{
"files": [
"*.json"
],
"options": {
"parser": "json-stringify"
}
}
]
}
20 changes: 20 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "solhint:recommended",
"plugins": [
"prettier"
],
"rules": {
"prettier/prettier": "warn",
"max-line-length": "off",
"check-send-result": "off",
"not-rely-on-time": "off",
"multiple-sends": "off",
"compiler-version": "off",
"func-visibility": [
"warn",
{
"ignoreConstructors": true
}
]
}
}
3 changes: 3 additions & 0 deletions .solhintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lib/
src/spell/rates.sol
src/spell/addresses_*.sol
4 changes: 3 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[profile.default]
src = 'src'
test = 'src'
out = 'out'
libs = ['lib']
optimizer = false

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
# See more config options https://github.com/foundry-rs/foundry/tree/master/config
35 changes: 35 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "dss-safebox",
"version": "0.1.0",
"main": "index.js",
"repository": "git@github.com:clio-finance/dss-safebox.git",
"author": "Clio Finance",
"license": "GPL-3.0",
"scripts": {
"prepare": "husky install",
"prepublishOnly": "copyfiles -u 1 \"./src/**/*.sol\" ./",
"postpublish": "rimraf ./*.sol",
"prepack": "yarn prepublishOnly",
"postpack": "yarn postpublish",
"lint:fix": "run-s solhint:fix prettier:fix",
"lint:check": "run-s prettier:check solhint:check",
"prettier:fix": "yarn prettier:check --write",
"prettier:check": "prettier --check \"src/**/*.sol\"",
"solhint:fix": "yarn solhint:check --fix",
"solhint:check": "solhint --config ./.solhint.json \"src/**/*.sol\""
},
"devDependencies": {
"copyfiles": "^2.4.1",
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
"npm-run-all": "^4.1.5",
"prettier": "^2.5.1",
"prettier-plugin-solidity": "^1.0.0-beta.19",
"rimraf": "^3.0.2",
"solhint": "^3.3.7",
"solhint-plugin-prettier": "^0.0.5"
},
"lint-staged": {
"*.{js,css,md,sol}": "prettier --write"
}
}
12 changes: 0 additions & 12 deletions script/Counter.s.sol

This file was deleted.

14 changes: 0 additions & 14 deletions src/Counter.sol

This file was deleted.

125 changes: 125 additions & 0 deletions src/Safebox.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
pragma solidity ^0.8.16;

interface WardsLike {
function rely(address usr) external;

function deny(address usr) external;

function wards(address usr) external view returns (uint256);
}

interface CanLike {
function hope(address usr) external;

function nope(address usr) external;

function can(address usr) external view returns (uint256);
}

interface FileLike {
function file(bytes32 what, address data) external;
}

contract Safebox is WardsLike, CanLike, FileLike {
mapping(address => uint256) public wards;

mapping(address => uint256) public can;

address public recipient;

address public pendingRecipient;

event Rely(address indexed usr);
event Deny(address indexed usr);

event Hope(address indexed usr);
event Nope(address indexed usr);

event File(bytes32 indexed what, address data);

event RecipientChange(address indexed recipient);

modifier auth() {
require(wards[msg.sender] == 1, "Safebox/not-authorized");
_;
}

constructor(
address _owner,
address _custodian,
address _recipient
) {
wards[_owner] = 1;
emit Rely(_owner);

can[_custodian] = 1;
emit Hope(_custodian);

recipient = _recipient;
emit RecipientChange(_recipient);
}

function rely(address usr) external auth {
wards[usr] = 1;
emit Rely(usr);
}

function deny(address usr) external auth {
wards[usr] = 0;
emit Deny(usr);
}

function hope(address usr) external auth {
can[usr] = 1;
emit Hope(usr);
}

function nope(address usr) external auth {
can[usr] = 0;
emit Nope(usr);
}

function file(bytes32 what, address data) external auth {
if (what == "recipient") {
pendingRecipient = data;
emit File(what, data);
} else {
revert("Safebox/file-unrecognized-param");
}
}

function approveChangeRecipient(address _recipient) external {
require(can[msg.sender] == 1, "Safebox/not-allowed");
require(pendingRecipient != address(0) && pendingRecipient == _recipient, "Safebox/recipient-mismatch");

recipient = _recipient;
pendingRecipient = address(0);

emit RecipientChange(_recipient);
}

function withdraw(address token) external {
_safeTransfer(token, recipient, ERC20Like(token).balanceOf(address(this)));
}

function withdraw(address token, uint256 amount) external {
_safeTransfer(token, recipient, amount);
}

function _safeTransfer(
address token,
address to,
uint256 amount
) internal {
(bool success, bytes memory result) = token.call(
abi.encodeWithSelector(ERC20Like(address(0)).transfer.selector, to, amount)
);
require(success && (result.length == 0 || abi.decode(result, (bool))), "Safebox/token-transfer-failed");
}
}

interface ERC20Like {
function transfer(address to, uint256 amt) external returns (bool);

function balanceOf(address usr) external view returns (uint256);
}
24 changes: 0 additions & 24 deletions test/Counter.t.sol

This file was deleted.

Loading

0 comments on commit 82918ab

Please sign in to comment.