This repository has been archived by the owner on Oct 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: draft implementation of Safebox
- Loading branch information
1 parent
f18f147
commit 82918ab
Showing
13 changed files
with
2,273 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
lib/ | ||
out/ | ||
node_modules/ | ||
cache/ | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"printWidth": 120, | ||
"overrides": [ | ||
{ | ||
"files": [ | ||
"*.json" | ||
], | ||
"options": { | ||
"parser": "json-stringify" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
lib/ | ||
src/spell/rates.sol | ||
src/spell/addresses_*.sol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.