Fix feedback from instadapp, update interfaces, addresses

This commit is contained in:
babkendev01 2021-10-08 11:21:31 +04:00
parent 5ff2546efe
commit 9fa4499b69
5 changed files with 25 additions and 101 deletions

View File

@ -15,11 +15,6 @@ interface MemoryInterface {
function setUint(uint id, uint val) external;
}
interface InstaMapping {
function qiTokenMapping(address) external view returns (address);
function gemJoinMapping(bytes32) external view returns (address);
}
interface AccountInterface {
function enable(address) external;
function disable(address) external;

View File

@ -1,6 +1,6 @@
pragma solidity ^0.7.0;
import { MemoryInterface, InstaMapping } from "./interfaces.sol";
import { MemoryInterface } from "./interfaces.sol";
abstract contract Stores {
@ -18,12 +18,7 @@ abstract contract Stores {
/**
* @dev Return memory variable address
*/
MemoryInterface constant internal instaMemory = MemoryInterface(0x8a5419CfC711B2343c17a6ABf4B2bAFaBb06957F);
/**
* @dev Return InstaDApp Mapping Addresses
*/
InstaMapping constant internal instaMapping = InstaMapping(0xe81F70Cc7C0D46e12d70efc60607F16bbD617E88);
MemoryInterface constant internal instaMemory = MemoryInterface(0x3254Ce8f5b1c82431B8f21Df01918342215825C2);
/**
* @dev Get Uint value from InstaMemory Contract.

View File

@ -436,6 +436,6 @@ abstract contract BenqiResolver is Events, Helpers {
}
}
contract ConnectV2Benqi is BenqiResolver {
contract ConnectV2BenqiAvalanche is BenqiResolver {
string public name = "Benqi-v1";
}

View File

@ -14,6 +14,10 @@ interface QiTokenInterface {
function underlying() external view returns (address);
}
interface MappingControllerInterface {
function hasRole(address,address) external view returns (bool);
}
abstract contract Helpers {
struct TokenMap {
@ -24,10 +28,13 @@ abstract contract Helpers {
event LogQiTokenAdded(string indexed name, address indexed token, address indexed qitoken);
event LogQiTokenUpdated(string indexed name, address indexed token, address indexed qitoken);
ConnectorsInterface public immutable connectors;
// InstaConnectorsV2
ConnectorsInterface public constant connectors = ConnectorsInterface(0x127d8cD0E2b2E0366D522DeA53A787bfE9002C14);
// InstaIndex Address.
IndexInterface public constant instaIndex = IndexInterface(0x2971AdFa57b20E5a416aE5a708A8655A9c74f723);
IndexInterface public constant instaIndex = IndexInterface(0x6CE3e607C808b4f4C26B7F6aDAeB619e49CAbb25);
// InstaMappingController Address.
MappingControllerInterface public constant mappingController = MappingControllerInterface(0xF2113d0c99f36D7D6F6c6FAf05E0863892255999);
address public constant avaxAddr = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
@ -38,8 +45,14 @@ abstract contract Helpers {
_;
}
constructor(address _connectors) {
connectors = ConnectorsInterface(_connectors);
modifier hasRoleOrIsChief {
require(
msg.sender == instaIndex.master() ||
connectors.chief(msg.sender) ||
mappingController.hasRole(address(this), msg.sender),
"not-an-chief/controller"
);
_;
}
function _addQitokenMapping(
@ -78,8 +91,7 @@ abstract contract Helpers {
string[] calldata _names,
address[] memory _tokens,
address[] calldata _qitokens
) external {
require(msg.sender == instaIndex.master(), "not-master");
) external isChief {
require(_names.length == _tokens.length, "updateQitokenMapping: not same length");
require(_names.length == _qitokens.length, "updateQitokenMapping: not same length");
@ -112,7 +124,7 @@ abstract contract Helpers {
string[] memory _names,
address[] memory _tokens,
address[] memory _qitokens
) external isChief {
) external hasRoleOrIsChief {
_addQitokenMapping(_names, _tokens, _qitokens);
}
@ -123,15 +135,14 @@ abstract contract Helpers {
}
contract InstaBenqiMapping is Helpers {
contract InstaBenqiMappingAvalanche is Helpers {
string constant public name = "Benqi-Mapping-v1.0";
constructor(
address _connectors,
string[] memory _qitokenNames,
address[] memory _tokens,
address[] memory _qitokens
) Helpers(_connectors) {
) {
_addQitokenMapping(_qitokenNames, _tokens, _qitokens);
}
}

View File

@ -1,77 +0,0 @@
pragma solidity ^0.7.0;
/**
* @title StaticConnectBasic.
* @dev Static Connector to withdraw assets.
*/
interface TokenInterface {
function balanceOf(address) external view returns (uint);
function transfer(address, uint) external returns (bool);
}
interface AccountInterface {
function isAuth(address) external view returns (bool);
}
interface EventInterface {
function emitEvent(uint _connectorType, uint _connectorID, bytes32 _eventCode, bytes calldata _eventData) external;
}
contract Memory {
/**
* @dev Return InstaEvent Address.
*/
function getEventAddr() internal pure returns (address) {
return 0x2af7ea6Cb911035f3eb1ED895Cb6692C39ecbA97;
}
function connectorID() public pure returns(uint _type, uint _id) {
(_type, _id) = (2, 1);
}
}
contract BasicResolver is Memory {
event LogWithdraw(address arc20, uint tokenAmt, address to);
/**
* @dev AVAX Address.
*/
address constant internal avaxAddr = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
/**
* @dev Withdraw Assets To Smart Account.
* @param arc20 Token Address.
* @param tokenAmt Token Amount.
*/
function withdraw(
address arc20,
uint tokenAmt
) external payable {
uint amt;
if (arc20 == avaxAddr) {
amt = tokenAmt == uint(-1) ? address(this).balance : tokenAmt;
msg.sender.transfer(amt);
} else {
TokenInterface token = TokenInterface(arc20);
amt = tokenAmt == uint(-1) ? token.balanceOf(address(this)) : tokenAmt;
token.transfer(msg.sender, amt);
}
emit LogWithdraw(arc20, amt, msg.sender);
bytes32 _eventCode = keccak256("LogWithdraw(address,uint256,address)");
bytes memory _eventParam = abi.encode(arc20, amt, msg.sender);
(uint _type, uint _id) = connectorID();
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
}
}
contract StaticConnectBasic is BasicResolver {
string public constant name = "Static-Basic-v1";
}