Add authority

This commit is contained in:
Mubaris NK 2021-02-08 20:28:48 +05:30
parent 959ecbc2e3
commit 8518657e83
No known key found for this signature in database
GPG Key ID: 9AC09AD0F8D68561
8 changed files with 87 additions and 20 deletions

View File

@ -27,4 +27,14 @@ abstract contract Basic is DSMath, Stores {
return abi.encode(eventName, eventParam);
}
}
function convertEthToWeth(bool isEth, TokenInterface token, uint amount) internal {
if(isEth) token.deposit{value: amount}();
}
function convertWethToEth(bool isEth, TokenInterface token, uint amount) internal {
if(isEth) {
token.approve(address(token), amount);
token.withdraw(amount);
}
}
}

View File

@ -17,4 +17,10 @@ interface MemoryInterface {
interface InstaMapping {
function cTokenMapping(address) external view returns (address);
}
}
interface AccountInterface {
function enable(address) external;
function disable(address) external;
function isAuth(address) external view returns (bool);
}

View File

@ -1,16 +0,0 @@
pragma solidity ^0.7.0;
import { TokenInterface } from "./interfaces.sol";
abstract contract Utils {
function convertEthToWeth(bool isEth, TokenInterface token, uint amount) internal {
if(isEth) token.deposit{value: amount}();
}
function convertWethToEth(bool isEth, TokenInterface token, uint amount) internal {
if(isEth) {
token.approve(address(token), amount);
token.withdraw(amount);
}
}
}

View File

@ -2,12 +2,11 @@ pragma solidity ^0.7.0;
import { TokenInterface } from "../../../common/interfaces.sol";
import { Stores } from "../../../common/stores.sol";
import { Utils } from "../../../common/utils.sol";
import { Helpers } from "./helpers.sol";
import { Events } from "./events.sol";
import { AaveInterface } from "./interface.sol";
abstract contract AaveResolver is Events, Helpers, Utils {
abstract contract AaveResolver is Events, Helpers {
/**
* @dev Deposit ETH/ERC20_Token.
* @param token token address to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)

View File

@ -0,0 +1,6 @@
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,15 @@
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(0x4c8a1BEb8a87765788946D6B19C6C6355194AbEb);
function checkAuthCount() internal view returns (uint count) {
uint64 accountId = listContract.accountID(address(this));
count = listContract.accountLink(accountId).count;
}
}

View File

@ -0,0 +1,13 @@
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,34 @@
pragma solidity ^0.7.0;
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
* @param authority authority Address.
*/
function add(
address authority
) external payable returns (string memory _eventName, bytes memory _eventParam) {
AccountInterface(address(this)).enable(authority);
_eventName = "LogAddAuth(address,address)";
_eventParam = abi.encode(msg.sender, authority);
}
/**
* @dev Remove authority
* @param authority authority Address.
*/
function remove(
address authority
) external payable returns (string memory _eventName, bytes memory _eventParam) {
require(checkAuthCount() > 1, "Removing-all-authorities");
AccountInterface(address(this)).disable(authority);
_eventName = "LogRemoveAuth(address,address)";
_eventParam = abi.encode(msg.sender, authority);
}
}