added authority connector

This commit is contained in:
pradyuman-verma 2022-01-15 22:43:53 +05:30
parent d6aaa161fd
commit 80da914bbc
No known key found for this signature in database
GPG Key ID: E36FD6BC8923221F
4 changed files with 95 additions and 0 deletions

View 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);
}

View 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;
}
}

View 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);
}

View 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";
}