Add Reflexer mapping

This commit is contained in:
Guillaume Felley 2021-03-30 12:52:29 +02:00
parent 770fd97f45
commit b67be72a13
4 changed files with 86 additions and 6 deletions

View File

@ -3,7 +3,14 @@ pragma solidity ^0.7.0;
import { DSMath } from "../../common/math.sol";
import { Basic } from "../../common/basic.sol";
import { TokenInterface } from "../../common/interfaces.sol";
import { ManagerLike, CoinJoinInterface, SafeEngineLike, TaxCollectorLike, TokenJoinInterface } from "./interface.sol";
import {
ManagerLike,
CoinJoinInterface,
SafeEngineLike,
TaxCollectorLike,
TokenJoinInterface,
GebMapping
} from "./interface.sol";
abstract contract Helpers is DSMath, Basic {
/**
@ -26,6 +33,18 @@ abstract contract Helpers is DSMath, Basic {
*/
address internal constant giveAddr = 0x4dD58550eb15190a5B3DfAE28BB14EeC181fC267;
/**
* @dev Return Reflexer mapping Address.
*/
function getGebMappingAddress() internal pure returns (address) {
// TODO: Set the real deployed Reflexer mapping address
return 0x0000000000000000000000000000000000000000;
}
function getCollateralJoinAddress(bytes32 collateralType) internal view returns (address) {
return GebMapping(getGebMappingAddress()).collateralJoinMapping(collateralType);
}
/**
* @dev Get Safe's collateral type.
*/

View File

@ -61,3 +61,7 @@ interface ConnectorsInterface {
interface IndexInterface {
function master() external view returns (address);
}
interface GebMapping {
function collateralJoinMapping(bytes32) external view returns(address);
}

View File

@ -12,7 +12,7 @@ abstract contract GebResolver is Helpers, Events {
*/
function open(string calldata colType) external payable returns (string memory _eventName, bytes memory _eventParam) {
bytes32 collateralType = stringToBytes32(colType);
require(instaMapping.gemJoinMapping(collateralType) != address(0), "wrong-col-type");
require(getCollateralJoinAddress(collateralType) != address(0), "wrong-col-type");
uint256 safe = managerContract.openSAFE(collateralType, address(this));
_eventName = "LogOpen(uint256,bytes32)";
@ -54,7 +54,7 @@ abstract contract GebResolver is Helpers, Events {
uint _safe = getSafe(safe);
(bytes32 collateralType, address handler) = getSafeData(_safe);
address colAddr = instaMapping.gemJoinMapping(collateralType);
address colAddr = getCollateralJoinAddress(collateralType);
TokenJoinInterface tokenJoinContract = TokenJoinInterface(colAddr);
TokenInterface tokenContract = tokenJoinContract.collateral();
@ -100,7 +100,7 @@ abstract contract GebResolver is Helpers, Events {
uint _safe = getSafe(safe);
(bytes32 collateralType, address handler) = getSafeData(_safe);
address colAddr = instaMapping.gemJoinMapping(collateralType);
address colAddr = getCollateralJoinAddress(collateralType);
TokenJoinInterface tokenJoinContract = TokenJoinInterface(colAddr);
uint _amt18;
@ -247,7 +247,7 @@ abstract contract GebResolver is Helpers, Events {
uint _amt = getUint(getId, amt);
(bytes32 collateralType, address handler) = getSafeData(safe);
address colAddr = instaMapping.gemJoinMapping(collateralType);
address colAddr = getCollateralJoinAddress(collateralType);
TokenJoinInterface tokenJoinContract = TokenJoinInterface(colAddr);
uint _amt18;
@ -309,7 +309,7 @@ abstract contract GebResolver is Helpers, Events {
gebData._safe = getSafe(safe);
(bytes32 collateralType, address handler) = getSafeData(gebData._safe);
gebData.colAddr = instaMapping.gemJoinMapping(collateralType);
gebData.colAddr = getCollateralJoinAddress(collateralType);
gebData.tokenJoinContract = TokenJoinInterface(gebData.colAddr);
gebData.safeEngineContract = SafeEngineLike(managerContract.safeEngine());
gebData.tokenContract = gebData.tokenJoinContract.collateral();

View File

@ -0,0 +1,57 @@
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
interface CollateralJoinInterface {
function collateralType() external view returns (bytes32);
}
interface ConnectorsInterface {
function chief(address) external view returns (bool);
}
interface IndexInterface {
function master() external view returns (address);
}
contract Helpers {
address public constant connectors = 0xD6A602C01a023B98Ecfb29Df02FBA380d3B21E0c;
address public constant instaIndex = 0x2971AdFa57b20E5a416aE5a708A8655A9c74f723;
uint public version = 1;
mapping (bytes32 => address) public collateralJoinMapping;
event LogAddCollateralJoinMapping(address[] collateralJoin);
modifier isChief {
require(
ConnectorsInterface(connectors).chief(msg.sender) ||
IndexInterface(instaIndex).master() == msg.sender, "not-Chief");
_;
}
function addCollateralJoinMapping(address[] memory collateralJoins) public isChief {
_addCollateralJoinMapping(collateralJoins);
}
function _addCollateralJoinMapping(address[] memory collateralJoins) internal {
require(collateralJoins.length > 0, "No-CollateralJoin-Address");
for(uint i = 0; i < collateralJoins.length; i++) {
address collateralJoin = collateralJoins[i];
bytes32 collateralType = CollateralJoinInterface(collateralJoin).collateralType();
require(collateralJoinMapping[collateralType] == address(0), "CollateralJoin-Already-Added");
collateralJoinMapping[collateralType] = collateralJoin;
}
emit LogAddCollateralJoinMapping(collateralJoins);
}
}
contract GebMapping is Helpers {
string constant public name = "Reflexer-Mapping-v1";
constructor() public {
address[] memory collateralJoins = new address[](1);
collateralJoins[0] = 0x2D3cD7b81c93f188F3CB8aD87c8Acc73d6226e3A; // ETH-A Join contract address
_addCollateralJoinMapping(collateralJoins);
}
}