mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Add authority
This commit is contained in:
parent
959ecbc2e3
commit
8518657e83
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
|
6
contracts/connectors/authority/events.sol
Normal file
6
contracts/connectors/authority/events.sol
Normal 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);
|
||||
}
|
15
contracts/connectors/authority/helpers.sol
Normal file
15
contracts/connectors/authority/helpers.sol
Normal 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;
|
||||
}
|
||||
}
|
13
contracts/connectors/authority/interface.sol
Normal file
13
contracts/connectors/authority/interface.sol
Normal 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);
|
||||
}
|
34
contracts/connectors/authority/main.sol
Normal file
34
contracts/connectors/authority/main.sol
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user