-
Notifications
You must be signed in to change notification settings - Fork 112
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
1 parent
d60cbb8
commit 0cc0363
Showing
3 changed files
with
406 additions
and
0 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,172 @@ | ||
/* | ||
This file is part of The Colony Network. | ||
The Colony Network 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. | ||
The Colony Network 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 The Colony Network. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
pragma solidity 0.7.3; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import "./../../lib/dappsys/erc20.sol"; | ||
import "./../colonyNetwork/IColonyNetwork.sol"; | ||
import "./ColonyExtensionMeta.sol"; | ||
|
||
// ignore-file-swc-108 | ||
|
||
|
||
contract UxGate is ColonyExtensionMeta { | ||
|
||
// Constants | ||
|
||
// Events | ||
|
||
event StakeSubmitted(bytes32 indexed stakeType, address indexed staker); | ||
|
||
// Data structures | ||
|
||
struct Stake { | ||
bytes32 stakeType; | ||
address staker; | ||
uint256 amount; | ||
uint256 cancelledAt; | ||
} | ||
|
||
// Storage | ||
|
||
address colonyNetworkAddress; | ||
|
||
// Parameters keyed by stake type | ||
mapping (bytes32 => uint256) stakeFractions; | ||
mapping (bytes32 => uint256) securityDelays; | ||
|
||
uint256 numStakes; | ||
mapping (uint256 => Stake) stakes; | ||
|
||
// Modifiers | ||
|
||
modifier onlyRootArchitect() { | ||
require(colony.hasUserRole(msgSender(), 1, ColonyDataTypes.ColonyRole.Architecture), "ux-gate-caller-not-root-architect"); | ||
_; | ||
} | ||
|
||
// Overrides | ||
|
||
/// @notice Returns the identifier of the extension | ||
function identifier() public override pure returns (bytes32) { | ||
return keccak256("UxGate"); | ||
} | ||
|
||
/// @notice Returns the version of the extension | ||
function version() public override pure returns (uint256) { | ||
return 1; | ||
} | ||
|
||
/// @notice Configures the extension | ||
/// @param _colony The colony in which the extension holds permissions | ||
function install(address _colony) public override auth { | ||
require(address(colony) == address(0x0), "extension-already-installed"); | ||
|
||
colony = IColony(_colony); | ||
colonyNetworkAddress = colony.getColonyNetwork(); | ||
} | ||
|
||
/// @notice Called when upgrading the extension | ||
function finishUpgrade() public override auth {} | ||
|
||
/// @notice Called when deprecating (or undeprecating) the extension | ||
function deprecate(bool _deprecated) public override auth { | ||
deprecated = _deprecated; | ||
} | ||
|
||
/// @notice Called when uninstalling the extension | ||
function uninstall() public override auth { | ||
selfdestruct(address(uint160(address(colony)))); | ||
} | ||
|
||
// Public | ||
|
||
function setStakeFraction(bytes32 _stakeType, uint256 _stakeFraction) public onlyRootArchitect { | ||
stakeFractions[_stakeType] = _stakeFraction; | ||
} | ||
|
||
function setSecurityDelay(bytes32 _stakeType, uint256 securityDelay) public onlyRootArchitect { | ||
securityDelays[_stakeType] = securityDelay; | ||
} | ||
|
||
function submitStake( | ||
bytes32 _stakeType, | ||
bytes memory _colonyKey, | ||
bytes memory _colonyValue, | ||
uint256 _colonyBranchMask, | ||
bytes32[] memory _colonySiblings, | ||
bytes memory _userKey, | ||
bytes memory _userValue, | ||
uint256 _userBranchMask, | ||
bytes32[] memory _userSiblings | ||
) | ||
public | ||
notDeprecated | ||
{ | ||
bytes32 rootHash = IColonyNetwork(colonyNetworkAddress).getReputationRootHash(); | ||
uint256 rootSkillId = colony.getDomain(1).skillId; | ||
|
||
uint256 colonyReputation = checkReputation(rootHash, rootSkillId, address(0x0), _colonyKey, _colonyValue, _colonyBranchMask, _colonySiblings); | ||
uint256 userReputation = checkReputation(rootHash, rootSkillId, msgSender(), _userKey, _userValue, _userBranchMask, _userSiblings); | ||
|
||
uint256 requiredStake = getRequiredReputation(_stakeType, colonyReputation); | ||
require(userReputation >= requiredStake, "ux-gate-insufficient-rep"); | ||
|
||
stakes[++numStakes] = Stake({ | ||
staker: msgSender(), | ||
stakeType: _stakeType, | ||
amount: requiredStake, | ||
cancelledAt: UINT256_MAX | ||
}); | ||
|
||
colony.obligateStake(msgSender(), 1, requiredStake); | ||
|
||
emit StakeSubmitted(_stakeType, msgSender()); | ||
} | ||
|
||
function cancelStake() public {} | ||
|
||
function reclaimStake() public {} | ||
|
||
function slashStake() public {} | ||
|
||
// View | ||
|
||
function getNumStakes() external view returns (uint256) { | ||
return numStakes; | ||
} | ||
|
||
function getStakeFraction(bytes32 _stakeType) external view returns (uint256) { | ||
return stakeFractions[_stakeType]; | ||
} | ||
|
||
function getSecurityDelay(bytes32 _stakeType) external view returns (uint256) { | ||
return securityDelays[_stakeType]; | ||
} | ||
|
||
function getStake(uint256 _id) external view returns (Stake memory stake) { | ||
return stakes[_id]; | ||
} | ||
|
||
// Internal | ||
|
||
function getRequiredReputation(bytes32 _stakeType, uint256 _colonyRep) internal view returns (uint256) { | ||
uint256 stakeFraction = stakeFractions[_stakeType] > 0 ? stakeFractions[_stakeType] : WAD; | ||
return wmul(_colonyRep, stakeFraction); | ||
} | ||
} |
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
Oops, something went wrong.