mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
added authority connector
This commit is contained in:
parent
d6aaa161fd
commit
80da914bbc
7
contracts/optimism/connectors/authority/events.sol
Normal file
7
contracts/optimism/connectors/authority/events.sol
Normal file
|
@ -0,0 +1,7 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
event LogAddAuth(address indexed _msgSender, address indexed _authority);
|
||||
event LogRemoveAuth(address indexed _msgSender, address indexed _authority);
|
||||
}
|
16
contracts/optimism/connectors/authority/helpers.sol
Normal file
16
contracts/optimism/connectors/authority/helpers.sol
Normal file
|
@ -0,0 +1,16 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import { DSMath } from "../../common/math.sol";
|
||||
import { Basic } from "../../common/basic.sol";
|
||||
import { ListInterface } from "./interface.sol";
|
||||
|
||||
abstract contract Helpers is DSMath, Basic {
|
||||
ListInterface internal constant listContract = ListInterface(0x9926955e0Dd681Dc303370C52f4Ad0a4dd061687);
|
||||
|
||||
function checkAuthCount() internal view returns (uint count) {
|
||||
uint64 accountId = listContract.accountID(address(this));
|
||||
count = listContract.accountLink(accountId).count;
|
||||
}
|
||||
}
|
14
contracts/optimism/connectors/authority/interface.sol
Normal file
14
contracts/optimism/connectors/authority/interface.sol
Normal file
|
@ -0,0 +1,14 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
interface ListInterface {
|
||||
struct AccountLink {
|
||||
address first;
|
||||
address last;
|
||||
uint64 count;
|
||||
}
|
||||
|
||||
function accountID(address) external view returns (uint64);
|
||||
function accountLink(uint64) external view returns (AccountLink memory);
|
||||
}
|
58
contracts/optimism/connectors/authority/main.sol
Normal file
58
contracts/optimism/connectors/authority/main.sol
Normal file
|
@ -0,0 +1,58 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
/**
|
||||
* @title Authority.
|
||||
* @dev Manage Authorities to DSA.
|
||||
*/
|
||||
|
||||
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
|
||||
* @notice Add an address as account authority
|
||||
* @param authority The authority Address.
|
||||
*/
|
||||
function add(
|
||||
address authority
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
require(authority != address(0), "Not-valid-authority");
|
||||
AccountInterface _dsa = AccountInterface(address(this));
|
||||
if (_dsa.isAuth(authority)) {
|
||||
authority = address(0);
|
||||
} else {
|
||||
_dsa.enable(authority);
|
||||
}
|
||||
|
||||
_eventName = "LogAddAuth(address,address)";
|
||||
_eventParam = abi.encode(msg.sender, authority);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Remove authority
|
||||
* @notice Remove an address as account authority
|
||||
* @param authority The authority Address.
|
||||
*/
|
||||
function remove(
|
||||
address authority
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
require(checkAuthCount() > 1, "Removing-all-authorities");
|
||||
require(authority != address(0), "Not-valid-authority");
|
||||
AccountInterface _dsa = AccountInterface(address(this));
|
||||
if (_dsa.isAuth(authority)) {
|
||||
_dsa.disable(authority);
|
||||
} else {
|
||||
authority = address(0);
|
||||
}
|
||||
|
||||
_eventName = "LogRemoveAuth(address,address)";
|
||||
_eventParam = abi.encode(msg.sender, authority);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2AuthOptimism is AuthorityResolver {
|
||||
string public constant name = "Auth-v1.1";
|
||||
}
|
Loading…
Reference in New Issue
Block a user