Skip to content

Commit

Permalink
✨ DSAuth + DSRoles
Browse files Browse the repository at this point in the history
  • Loading branch information
transmissions11 committed Jul 17, 2021
1 parent 07d6272 commit 538f3a8
Show file tree
Hide file tree
Showing 13 changed files with 587 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .dapprc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Basic build/test configuration.
export DAPP_SOLC_VERSION=0.8.6
export DAPP_BUILD_OPTIMIZE=1
export DAPP_BUILD_OPTIMIZE_RUNS=1000000000
export DAPP_LINK_TEST_LIBRARIES=0
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.sol linguist-language=Solidity
.dapprc linguist-language=Shell
21 changes: 21 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Tests

on: [push, pull_request]

jobs:
tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: cachix/install-nix-action@v13
- uses: cachix/cachix-action@v10
with:
name: dapp

- name: Install dependencies
run: nix-shell --run 'make'

- name: Run tests
run: nix-shell --run 'dapp test'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/out
/node_modules
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"solidity.packageDefaultDependenciesContractsDirectory": "src",
"solidity.packageDefaultDependenciesDirectory": "lib",
"solidity.compileUsingRemoteVersion": "v0.8.6",
"files.associations": {
".dapprc": "shellscript"
}
}
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Install, update, build and test everything.
all: solc install update
# Install proper solc version.
solc:; nix-env -f https://github.com/dapphub/dapptools/archive/master.tar.gz -iA solc-static-versions.solc_0_8_6
# Install npm dependencies.
install:; npm install
# Install dapp dependencies.
update:; dapp update
125 changes: 125 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@rari-capital/dappsys",
"version": "1.0.0",
"description": "Rari Capital's modern fork of some key Dappsys contracts.",
"files": [
"src/**/*.sol"
],
"repository": {
"type": "git",
"url": "git+https://github.com/Rari-Capital/dappsys.git"
},
"devDependencies": {
"prettier": "^2.3.1",
"prettier-plugin-solidity": "^1.0.0-beta.13"
}
}
45 changes: 45 additions & 0 deletions src/DSAuth.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >=0.4.23;

import "./DSAuthority.sol";

/// @notice Provides a flexible and updatable auth pattern which is completely separate from application logic.
abstract contract DSAuth {
event LogSetAuthority(address indexed authority);
event LogSetOwner(address indexed owner);

DSAuthority public authority;
address public owner;

constructor() {
owner = msg.sender;
emit LogSetOwner(msg.sender);
}

function setOwner(address owner_) external auth {
owner = owner_;
emit LogSetOwner(owner);
}

function setAuthority(DSAuthority authority_) external auth {
authority = authority_;
emit LogSetAuthority(address(authority));
}

modifier auth() {
require(isAuthorized(msg.sender, msg.sig), "ds-auth-unauthorized");
_;
}

function isAuthorized(address src, bytes4 sig) internal view returns (bool) {
if (src == address(this)) {
return true;
} else if (src == owner) {
return true;
} else if (authority == DSAuthority(address(0))) {
return false;
} else {
return authority.canCall(src, address(this), sig);
}
}
}
11 changes: 11 additions & 0 deletions src/DSAuthority.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >=0.4.23;

/// @notice A generic interface for a contract which provides authorization data to a DSAuth instance.
interface DSAuthority {
function canCall(
address src,
address dst,
bytes4 sig
) external view returns (bool);
}
Loading

0 comments on commit 538f3a8

Please sign in to comment.