dsa-connectors/contracts/mainnet/connectors/authority/main.sol

59 lines
1.8 KiB
Solidity
Raw Normal View History

2022-03-22 15:24:40 +00:00
//SPDX-License-Identifier: MIT
2021-02-08 14:58:48 +00:00
pragma solidity ^0.7.0;
/**
* @title Authority.
* @dev Manage Authorities to DSA.
*/
2021-02-08 14:58:48 +00:00
import { AccountInterface } from "../../common/interfaces.sol";
import { Helpers } from "./helpers.sol";
import { Events } from "./events.sol";
abstract contract AuthorityResolver is Events, Helpers {
/**
* @dev Add New authority
2021-03-24 12:23:36 +00:00
* @notice Add an address as account authority
* @param authority The authority Address.
2021-02-08 14:58:48 +00:00
*/
function add(
address authority
) external payable returns (string memory _eventName, bytes memory _eventParam) {
2021-06-15 16:14:04 +00:00
require(authority != address(0), "Not-valid-authority");
2021-06-15 14:13:35 +00:00
AccountInterface _dsa = AccountInterface(address(this));
if (_dsa.isAuth(authority)) {
authority = address(0);
} else {
_dsa.enable(authority);
}
2021-02-08 14:58:48 +00:00
_eventName = "LogAddAuth(address,address)";
_eventParam = abi.encode(msg.sender, authority);
}
/**
* @dev Remove authority
2021-03-24 12:23:36 +00:00
* @notice Remove an address as account authority
* @param authority The authority Address.
2021-02-08 14:58:48 +00:00
*/
function remove(
address authority
) external payable returns (string memory _eventName, bytes memory _eventParam) {
require(checkAuthCount() > 1, "Removing-all-authorities");
2021-06-15 16:14:04 +00:00
require(authority != address(0), "Not-valid-authority");
2021-06-15 14:13:35 +00:00
AccountInterface _dsa = AccountInterface(address(this));
if (_dsa.isAuth(authority)) {
_dsa.disable(authority);
} else {
authority = address(0);
}
2021-02-08 14:58:48 +00:00
_eventName = "LogRemoveAuth(address,address)";
_eventParam = abi.encode(msg.sender, authority);
}
}
2021-02-08 15:18:32 +00:00
2021-03-15 12:26:22 +00:00
contract ConnectV2Auth is AuthorityResolver {
2021-06-15 16:14:04 +00:00
string public constant name = "Auth-v1.1";
2021-02-08 15:18:32 +00:00
}