-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
358 changed files
with
33,542 additions
and
9,178 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
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 |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
|
||
build/* | ||
contracts/* | ||
contracts-test/* | ||
coverage/* | ||
lib/* |
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,5 +1,6 @@ | ||
node_modules | ||
build | ||
build-legacy | ||
tmp | ||
bin | ||
.outputParameter | ||
|
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 +1 @@ | ||
10.12.0 | ||
10.21.0 |
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,14 @@ | ||
{ | ||
"extends": "solhint:recommended", | ||
"plugins": [], | ||
"rules": { | ||
"compiler-version": ["off"], | ||
"no-inline-assembly": ["error"], | ||
"not-rely-on-time": ["off"], | ||
"avoid-low-level-calls": ["off"], | ||
"max-line-length": ["error", 150], | ||
"func-param-name-mixedcase": "error", | ||
"modifier-name-mixedcase": "error", | ||
"reason-string": ["warn", { "maxLength":32 }] | ||
} | ||
} |
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 @@ | ||
node_modules | ||
lib | ||
contracts-test | ||
contracts-legacy | ||
contracts/infrastructure_0.5 |
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
Binary file not shown.
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,158 @@ | ||
// Copyright (C) 2018 Argent Labs Ltd. <https://argent.xyz> | ||
|
||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
pragma solidity ^0.5.4; | ||
import "./SafeMath.sol"; | ||
import "./BaseWallet.sol"; | ||
import "./ModuleRegistry.sol"; | ||
import "./GuardianStorage.sol"; | ||
import "./Module.sol"; | ||
|
||
/** | ||
* @title BaseModule | ||
* @dev Basic module that contains some methods common to all modules. | ||
* @author Julien Niset - <[email protected]> | ||
*/ | ||
contract BaseModule is Module { | ||
|
||
// Empty calldata | ||
bytes constant internal EMPTY_BYTES = ""; | ||
|
||
// The adddress of the module registry. | ||
ModuleRegistry internal registry; | ||
// The address of the Guardian storage | ||
GuardianStorage internal guardianStorage; | ||
|
||
/** | ||
* @dev Throws if the wallet is locked. | ||
*/ | ||
modifier onlyWhenUnlocked(BaseWallet _wallet) { | ||
verifyUnlocked(_wallet); | ||
_; | ||
} | ||
|
||
event ModuleCreated(bytes32 name); | ||
event ModuleInitialised(address wallet); | ||
|
||
constructor(ModuleRegistry _registry, GuardianStorage _guardianStorage, bytes32 _name) public { | ||
registry = _registry; | ||
guardianStorage = _guardianStorage; | ||
emit ModuleCreated(_name); | ||
} | ||
|
||
/** | ||
* @dev Throws if the sender is not the target wallet of the call. | ||
*/ | ||
modifier onlyWallet(BaseWallet _wallet) { | ||
require(msg.sender == address(_wallet), "BM: caller must be wallet"); | ||
_; | ||
} | ||
|
||
/** | ||
* @dev Throws if the sender is not the owner of the target wallet or the module itself. | ||
*/ | ||
modifier onlyWalletOwner(BaseWallet _wallet) { | ||
// Wrapping in an internal method reduces deployment cost by avoiding duplication of inlined code | ||
verifyWalletOwner(_wallet); | ||
_; | ||
} | ||
|
||
/** | ||
* @dev Throws if the sender is not the owner of the target wallet. | ||
*/ | ||
modifier strictOnlyWalletOwner(BaseWallet _wallet) { | ||
require(isOwner(_wallet, msg.sender), "BM: msg.sender must be an owner for the wallet"); | ||
_; | ||
} | ||
|
||
/** | ||
* @dev Inits the module for a wallet by logging an event. | ||
* The method can only be called by the wallet itself. | ||
* @param _wallet The wallet. | ||
*/ | ||
function init(BaseWallet _wallet) public onlyWallet(_wallet) { | ||
emit ModuleInitialised(address(_wallet)); | ||
} | ||
|
||
/** | ||
* @dev Adds a module to a wallet. First checks that the module is registered. | ||
* @param _wallet The target wallet. | ||
* @param _module The modules to authorise. | ||
*/ | ||
function addModule(BaseWallet _wallet, Module _module) external strictOnlyWalletOwner(_wallet) { | ||
require(registry.isRegisteredModule(address(_module)), "BM: module is not registered"); | ||
_wallet.authoriseModule(address(_module), true); | ||
} | ||
|
||
/** | ||
* @dev Utility method enbaling anyone to recover ERC20 token sent to the | ||
* module by mistake and transfer them to the Module Registry. | ||
* @param _token The token to recover. | ||
*/ | ||
function recoverToken(address _token) external { | ||
uint total = ERC20(_token).balanceOf(address(this)); | ||
bool success = ERC20(_token).transfer(address(registry), total); | ||
require(success, "BM: recover token transfer failed"); | ||
} | ||
|
||
/** | ||
* @dev Verify that the wallet is unlocked. | ||
* @param _wallet The target wallet. | ||
*/ | ||
function verifyUnlocked(BaseWallet _wallet) internal view { | ||
require(!guardianStorage.isLocked(_wallet), "BM: wallet locked"); | ||
} | ||
|
||
/** | ||
* @dev Verify that the caller is the module or the wallet owner. | ||
* @param _wallet The target wallet. | ||
*/ | ||
function verifyWalletOwner(BaseWallet _wallet) internal view { | ||
require(msg.sender == address(this) || isOwner(_wallet, msg.sender), "BM: must be wallet owner"); | ||
} | ||
|
||
/** | ||
* @dev Helper method to check if an address is the owner of a target wallet. | ||
* @param _wallet The target wallet. | ||
* @param _addr The address. | ||
*/ | ||
function isOwner(BaseWallet _wallet, address _addr) internal view returns (bool) { | ||
return _wallet.owner() == _addr; | ||
} | ||
|
||
/** | ||
* @dev Helper method to invoke a wallet. | ||
* @param _wallet The target wallet. | ||
* @param _to The target address for the transaction. | ||
* @param _value The value of the transaction. | ||
* @param _data The data of the transaction. | ||
*/ | ||
function invokeWallet(address _wallet, address _to, uint256 _value, bytes memory _data) internal returns (bytes memory _res) { | ||
bool success; | ||
// solium-disable-next-line security/no-call-value | ||
(success, _res) = _wallet.call(abi.encodeWithSignature("invoke(address,uint256,bytes)", _to, _value, _data)); | ||
if (success && _res.length > 0) { //_res is empty if _wallet is an "old" BaseWallet that can't return output values | ||
(_res) = abi.decode(_res, (bytes)); | ||
} else if (_res.length > 0) { | ||
// solium-disable-next-line security/no-inline-assembly | ||
assembly { | ||
returndatacopy(0, 0, returndatasize) | ||
revert(0, returndatasize) | ||
} | ||
} else if (!success) { | ||
revert("BM: wallet invoke reverted"); | ||
} | ||
} | ||
} |
Oops, something went wrong.