|
| 1 | +pragma solidity 0.4.18; |
| 2 | + |
| 3 | +import "../ERC20Interface.sol"; |
| 4 | +import "./WrapperBase.sol"; |
| 5 | + |
| 6 | + |
| 7 | +interface IConversionRatesEnhancedSteps { |
| 8 | + |
| 9 | + function addOperator(address newOperator) public; |
| 10 | + function addToken(ERC20 token) public; |
| 11 | + function setTokenControlInfo( |
| 12 | + ERC20 token, |
| 13 | + uint minimalRecordResolution, |
| 14 | + uint maxPerBlockImbalance, |
| 15 | + uint maxTotalImbalance |
| 16 | + ) public; |
| 17 | + function setImbalanceStepFunction( |
| 18 | + ERC20 token, |
| 19 | + int[] xBuy, |
| 20 | + int[] yBuy, |
| 21 | + int[] xSell, |
| 22 | + int[] ySell |
| 23 | + ) public; |
| 24 | + function enableTokenTrade(ERC20 token) public; |
| 25 | + function setReserveAddress(address reserve) public; |
| 26 | + function setValidRateDurationInBlocks(uint duration) public; |
| 27 | + function getTokenControlInfo(ERC20 token) public view returns(uint, uint, uint); |
| 28 | +} |
| 29 | + |
| 30 | + |
| 31 | +contract WrapConversionRateEnhancedSteps is WrapperBase { |
| 32 | + |
| 33 | + IConversionRatesEnhancedSteps internal conversionRates; |
| 34 | + |
| 35 | + //general functions |
| 36 | + function WrapConversionRateEnhancedSteps(IConversionRatesEnhancedSteps _conversionRates) public |
| 37 | + WrapperBase(PermissionGroups(address(_conversionRates))) |
| 38 | + { |
| 39 | + conversionRates = _conversionRates; |
| 40 | + } |
| 41 | + |
| 42 | + //overriding base |
| 43 | + function claimWrappedContractAdmin() public onlyAdmin { |
| 44 | + super.claimWrappedContractAdmin(); |
| 45 | + //for recurring claim, remove operator from wrapped contract |
| 46 | + conversionRates.addOperator(this); |
| 47 | + } |
| 48 | + |
| 49 | + // add token functions |
| 50 | + ////////////////////// |
| 51 | + function addToken( |
| 52 | + ERC20 token, |
| 53 | + uint minRecordResolution, |
| 54 | + uint maxPerBlockImbalance, |
| 55 | + uint maxTotalImbalance |
| 56 | + ) public onlyAdmin |
| 57 | + { |
| 58 | + require(token != address(0)); |
| 59 | + require(minRecordResolution != 0); |
| 60 | + require(maxPerBlockImbalance != 0); |
| 61 | + require(maxTotalImbalance != 0); |
| 62 | + |
| 63 | + conversionRates.addToken(token); |
| 64 | + |
| 65 | + //token control info |
| 66 | + conversionRates.setTokenControlInfo( |
| 67 | + token, |
| 68 | + minRecordResolution, |
| 69 | + maxPerBlockImbalance, |
| 70 | + maxTotalImbalance |
| 71 | + ); |
| 72 | + |
| 73 | + //step functions |
| 74 | + int[] memory emptyArr = new int[](0); |
| 75 | + int[] memory zeroArr = new int[](1); |
| 76 | + zeroArr[0] = 0; |
| 77 | + |
| 78 | + conversionRates.setImbalanceStepFunction(token, emptyArr, zeroArr, emptyArr, zeroArr); |
| 79 | + |
| 80 | + conversionRates.enableTokenTrade(token); |
| 81 | + } |
| 82 | + |
| 83 | + // enable trade per token |
| 84 | + ////////////////////// |
| 85 | + function enableTokenTrade(ERC20 token) public onlyAdmin { |
| 86 | + conversionRates.enableTokenTrade(token); |
| 87 | + } |
| 88 | + |
| 89 | + // set conversion rates reserve address |
| 90 | + ////////////////////// |
| 91 | + function setReserveAddress(address reserve) public onlyAdmin { |
| 92 | + conversionRates.setReserveAddress(reserve); |
| 93 | + } |
| 94 | + |
| 95 | + //set token control info |
| 96 | + //////////////////////// |
| 97 | + function setTokenControlData(ERC20[] tokens, uint[] maxPerBlockImbalanceValues, uint[] maxTotalImbalanceValues) |
| 98 | + public |
| 99 | + onlyAdmin |
| 100 | + { |
| 101 | + require(maxPerBlockImbalanceValues.length == tokens.length); |
| 102 | + require(maxTotalImbalanceValues.length == tokens.length); |
| 103 | + |
| 104 | + uint minRecordResolution; |
| 105 | + |
| 106 | + for (uint i = 0; i < tokens.length; i++) { |
| 107 | + uint maxPerBlock; |
| 108 | + uint maxTotal; |
| 109 | + (minRecordResolution, maxPerBlock, maxTotal) = |
| 110 | + conversionRates.getTokenControlInfo(tokens[i]); |
| 111 | + require(minRecordResolution != 0); |
| 112 | + |
| 113 | + conversionRates.setTokenControlInfo(tokens[i], |
| 114 | + minRecordResolution, |
| 115 | + maxPerBlockImbalanceValues[i], |
| 116 | + maxTotalImbalanceValues[i]); |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + //set token min resolution |
| 121 | + //////////////////////// |
| 122 | + function setTokenMinResolution(ERC20[] tokens, uint[] minResolution) public onlyAdmin { |
| 123 | + require(minResolution.length == tokens.length); |
| 124 | + |
| 125 | + uint minRecordResolution; |
| 126 | + uint maxPerBlock; |
| 127 | + uint maxTotal; |
| 128 | + |
| 129 | + for (uint i = 0; i < tokens.length; i++) { |
| 130 | + (minRecordResolution, maxPerBlock, maxTotal) = conversionRates.getTokenControlInfo(tokens[i]); |
| 131 | + |
| 132 | + conversionRates.setTokenControlInfo(tokens[i], |
| 133 | + minResolution[i], |
| 134 | + maxPerBlock, |
| 135 | + maxTotal); |
| 136 | + } |
| 137 | + } |
| 138 | + |
| 139 | + //valid duration blocks |
| 140 | + /////////////////////// |
| 141 | + function setValidDurationData(uint validDurationBlocks) public onlyAdmin { |
| 142 | + require(validDurationBlocks > 5); |
| 143 | + conversionRates.setValidRateDurationInBlocks(validDurationBlocks); |
| 144 | + } |
| 145 | +} |
0 commit comments