Skip to content

Commit

Permalink
Merge pull request #90 from depools/linters
Browse files Browse the repository at this point in the history
apply linter fixes
  • Loading branch information
Alexander Lazarev committed Oct 26, 2020
2 parents 0aa6044 + c80793d commit bfec632
Show file tree
Hide file tree
Showing 31 changed files with 388 additions and 184 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

"rules": {
"prettier/prettier": "error",
"max-len": ["warn", { "code": 140, "ignoreUrls": true }],
"max-len": ["warn", { "code": 140, "ignoreComments": true, "ignoreUrls": true }],
"no-undef": "warn",
"no-unused-vars": "warn",
"prefer-const": "warn",
Expand Down
11 changes: 11 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "solhint:recommended",
"rules": {
"no-inline-assembly": "off",
"var-name-mixedcase": "off",
"compiler-version": "off",
"reason-string": "off",
"no-empty-blocks": "off",
"func-name-mixedcase": "off"
}
}
49 changes: 35 additions & 14 deletions .soliumrc.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
{
"extends": "solium:recommended",
"plugins": [
"security"
],
"extends": "solium:all",
"plugins": ["security"],
"rules": {
"quotes": [
"security/no-low-level-calls": "off",
"security/no-inline-assembly": "off",
"security/no-assign-params": "warning",
"error-reason": "off",
"imports-on-top": "error",
"variable-declarations": "error",
"array-declarations": "error",
"operator-whitespace": "error",
"conditionals-whitespace": "error",
"comma-whitespace": "error",
"semicolon-whitespace": "error",
"function-whitespace": "error",
"lbrace": "error",
"mixedcase": "off",
"camelcase": "error",
"uppercase": "error",
"no-empty-blocks": "error",
"no-unused-vars": "error",
"quotes": "error",
"blank-lines": "error",
"indentation": "error",
"arg-overflow": ["error", 8],
"whitespace": "error",
"deprecated-suicide": "error",
"pragma-on-top": "error",
"function-order": [
"error",
"double"
{"ignore": {"functions": ["initialize"]}}
],
"indentation": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
]
"emit": "error",
"no-constant": "error",
"value-in-payable": "error",
"max-len": "error",
"visibility-first": "error",
"linebreak-style": "error"
}
}
104 changes: 56 additions & 48 deletions contracts/0.4.24/DePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,13 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {
uint256 initialUsedSigningKeys; // for write-back control
}


function initialize(ISTETH _token, IValidatorRegistration validatorRegistration, address _oracle,
IStakingProvidersRegistry _sps, uint256 _depositIterationLimit)
function initialize(
ISTETH _token,
IValidatorRegistration validatorRegistration,
address _oracle,
IStakingProvidersRegistry _sps,
uint256 _depositIterationLimit
)
public onlyInit
{
_setToken(_token);
Expand All @@ -99,7 +103,6 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {
initialized();
}


/**
* @notice Adds eth to the pool
*/
Expand All @@ -115,7 +118,6 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {
return _submit(_referral);
}


/**
* @notice Stop pool routine operations
*/
Expand All @@ -130,7 +132,6 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {
_resume();
}


/**
* @notice Set fee rate to `_feeBasisPoints` basis points. The fees are accrued when oracles report staking results
* @param _feeBasisPoints Fee rate, in basis points
Expand All @@ -143,11 +144,19 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {
/**
* @notice Set fee distribution: `_treasuryFeeBasisPoints` basis points go to the treasury, `_insuranceFeeBasisPoints` basis points go to the insurance fund, `_SPFeeBasisPoints` basis points go to staking providers. The sum has to be 10 000.
*/
function setFeeDistribution(uint16 _treasuryFeeBasisPoints, uint16 _insuranceFeeBasisPoints,
uint16 _SPFeeBasisPoints) external auth(MANAGE_FEE)
function setFeeDistribution(
uint16 _treasuryFeeBasisPoints,
uint16 _insuranceFeeBasisPoints,
uint16 _SPFeeBasisPoints
)
external auth(MANAGE_FEE)
{
require(10000 == uint256(_treasuryFeeBasisPoints).add(uint256(_insuranceFeeBasisPoints)).add(uint256(_SPFeeBasisPoints)),
"FEES_DONT_ADD_UP");
require(
10000 == uint256(_treasuryFeeBasisPoints)
.add(uint256(_insuranceFeeBasisPoints))
.add(uint256(_SPFeeBasisPoints)),
"FEES_DONT_ADD_UP"
);

_setBPValue(TREASURY_FEE_VALUE_POSITION, _treasuryFeeBasisPoints);
_setBPValue(INSURANCE_FEE_VALUE_POSITION, _insuranceFeeBasisPoints);
Expand All @@ -164,15 +173,13 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {
_setOracle(_oracle);
}


/**
* @notice Set maximum number of Ethereum 2.0 validators registered in a single transaction.
*/
function setDepositIterationLimit(uint256 _limit) external auth(SET_DEPOSIT_ITERATION_LIMIT) {
_setDepositIterationLimit(_limit);
}


/**
* @notice Set credentials to withdraw ETH on ETH 2.0 side after the phase 2 is launched to `_withdrawalCredentials`
* @dev Note that setWithdrawalCredentials discards all unused signing keys as the signatures are invalidated.
Expand All @@ -188,17 +195,15 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {
emit WithdrawalCredentialsSet(_withdrawalCredentials);
}


/**
* @notice Issues withdrawal request. Large withdrawals will be processed only after the phase 2 launch. WIP.
* @param _amount Amount of StETH to burn
* @param _pubkeyHash Receiving address
*/
function withdraw(uint256 _amount, bytes32 _pubkeyHash) external whenNotStopped {
function withdraw(uint256 _amount, bytes32 _pubkeyHash) external whenNotStopped { /* solhint-disable-line no-unused-vars */
revert("NOT_IMPLEMENTED_YET");
}


/**
* @notice Ether on the ETH 2.0 side reported by the oracle
* @param _eth2balance Balance in wei on the ETH 2.0 side
Expand All @@ -222,11 +227,10 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {
}
}


/**
* @notice Send funds to recovery Vault. Overrides default AragonApp behaviour.
* @param _token Token to be sent to recovery vault.
*/
* @notice Send funds to recovery Vault. Overrides default AragonApp behaviour.
* @param _token Token to be sent to recovery vault.
*/
function transferToVault(address _token) external {
require(allowRecoverability(_token), "RECOVER_DISALLOWED");
address vault = getRecoveryVault();
Expand All @@ -245,7 +249,6 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {
emit RecoverToVault(vault, _token, balance);
}


/**
* @notice Returns staking rewards fee rate
*/
Expand All @@ -256,8 +259,14 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {
/**
* @notice Returns fee distribution proportion
*/
function getFeeDistribution() external view returns (uint16 treasuryFeeBasisPoints, uint16 insuranceFeeBasisPoints,
uint16 SPFeeBasisPoints)
function getFeeDistribution()
external
view
returns (
uint16 treasuryFeeBasisPoints,
uint16 insuranceFeeBasisPoints,
uint16 SPFeeBasisPoints
)
{
return _getFeeDistribution();
}
Expand All @@ -269,7 +278,6 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {
return withdrawalCredentials;
}


/**
* @notice Gets the amount of Ether temporary buffered on this contract balance
*/
Expand All @@ -284,7 +292,6 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {
return _getTotalControlledEther();
}


/**
* @notice Gets liquid token interface handle
*/
Expand Down Expand Up @@ -314,9 +321,9 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {
}

/**
* @notice Returns the value against which the next reward will be calculated
* This method can be discarded in the future
*/
* @notice Returns the value against which the next reward will be calculated
* This method can be discarded in the future
*/
function getRewardBase() public view returns (uint256) {
return REWARD_BASE_VALUE_POSITION.getStorageUint256();
}
Expand Down Expand Up @@ -350,12 +357,11 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {
* @return deposited Amount of Ether deposited from the current Ethereum
* @return remote Amount of Ether currently present on the Ethereum 2 side (can be 0 if the Ethereum 2 is yet to be launch
*/
function getEther2Stat() external view returns (uint256 deposited, uint256 remote) {
function getEther2Stat() public view returns (uint256 deposited, uint256 remote) {
deposited = DEPOSITED_ETHER_VALUE_POSITION.getStorageUint256();
remote = REMOTE_ETHER2_VALUE_POSITION.getStorageUint256();
}


/**
* @dev Sets liquid token interface handle
*/
Expand Down Expand Up @@ -396,7 +402,6 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {
DEPOSIT_ITERATION_LIMIT_VALUE_POSITION.setStorageUint256(_limit);
}


/**
* @dev Processes user deposit
*/
Expand Down Expand Up @@ -440,7 +445,8 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {

uint256 totalDepositCalls = 0;
uint256 maxDepositCalls = getDepositIterationLimit();
while (_amount != 0 && totalDepositCalls < maxDepositCalls) {
uint256 depositAmount = _amount;
while (depositAmount != 0 && totalDepositCalls < maxDepositCalls) {
// Finding the best suitable SP
uint256 bestSPidx = cache.length; // 'not found' flag
uint256 smallestStake;
Expand All @@ -466,11 +472,11 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {
break;

// Invoking deposit for the best SP
_amount = _amount.sub(DEPOSIT_SIZE);
depositAmount = depositAmount.sub(DEPOSIT_SIZE);
++totalDepositCalls;

(bytes memory key, bytes memory signature, bool used) =
getSPs().getSigningKey(cache[bestSPidx].id, cache[bestSPidx].usedSigningKeys++);
(bytes memory key, bytes memory signature, bool used) = /* solium-disable-line */
getSPs().getSigningKey(cache[bestSPidx].id, cache[bestSPidx].usedSigningKeys++);
assert(!used);

// finally, stake the notch for the assigned validator
Expand Down Expand Up @@ -502,15 +508,19 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {

// Compute deposit data root (`DepositData` hash tree root) according to validator_registration.vy
bytes32 pubkeyRoot = sha256(_pad64(_pubkey));
bytes32 signatureRoot = sha256(abi.encodePacked(
sha256(BytesLib.slice(_signature, 0, 64)),
sha256(_pad64(BytesLib.slice(_signature, 64, SIGNATURE_LENGTH.sub(64))))
));
bytes32 signatureRoot = sha256(
abi.encodePacked(
sha256(BytesLib.slice(_signature, 0, 64)),
sha256(_pad64(BytesLib.slice(_signature, 64, SIGNATURE_LENGTH.sub(64))))
)
);

bytes32 depositDataRoot = sha256(abi.encodePacked(
sha256(abi.encodePacked(pubkeyRoot, withdrawalCredentials)),
sha256(abi.encodePacked(_toLittleEndian64(depositAmount), signatureRoot))
));
bytes32 depositDataRoot = sha256(
abi.encodePacked(
sha256(abi.encodePacked(pubkeyRoot, withdrawalCredentials)),
sha256(abi.encodePacked(_toLittleEndian64(depositAmount), signatureRoot))
)
);

uint256 targetBalance = address(this).balance.sub(value);

Expand Down Expand Up @@ -543,7 +553,6 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {
);
}


/**
* @dev Records a deposit made by a user with optional referral
* @param _value Deposit value in wei
Expand Down Expand Up @@ -602,7 +611,6 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {
getSPs().updateUsedKeys(ids, usedSigningKeys);
}


/**
* @dev Returns staking rewards fee rate
*/
Expand Down Expand Up @@ -698,7 +706,6 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {
require(idx == cache.length, "SP_REGISTRY_INCOSISTENCY");
}


/**
* @dev Padding memory array with zeroes up to 64 bytes on the right
* @param _b Memory array of size 32 .. 64
Expand All @@ -723,12 +730,13 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {
*/
function _toLittleEndian64(uint256 _value) internal pure returns (uint256 result) {
result = 0;
uint256 temp_value = _value;
for (uint256 i = 0; i < 8; ++i) {
result = (result << 8) | (_value & 0xFF);
_value >>= 8;
result = (result << 8) | (temp_value & 0xFF);
temp_value >>= 8;
}

assert(0 == _value); // fully converted
assert(0 == temp_value); // fully converted
result <<= (24 * 8);
}

Expand Down
9 changes: 4 additions & 5 deletions contracts/0.4.24/StETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ contract StETH is ISTETH, Pausable, AragonApp {
uint256 value
);

function initialize(IDePool _dePool) public onlyInit {
dePool = _dePool;
initialized();
}

/**
* @notice Stop transfers
Expand Down Expand Up @@ -101,11 +105,6 @@ contract StETH is ISTETH, Pausable, AragonApp {
_burn(_account, _value);
}

function initialize(IDePool _dePool) public onlyInit {
dePool = _dePool;
initialized();
}

/**
* @dev Total number of tokens in existence
*/
Expand Down
7 changes: 5 additions & 2 deletions contracts/0.4.24/interfaces/IDePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ interface IDePool {
/**
* @notice Set fee distribution: `_treasuryFeeBasisPoints` basis points go to the treasury, `_insuranceFeeBasisPoints` basis points go to the insurance fund, `_SPFeeBasisPoints` basis points go to staking providers. The sum has to be 10 000.
*/
function setFeeDistribution(uint16 _treasuryFeeBasisPoints, uint16 _insuranceFeeBasisPoints,
uint16 _SPFeeBasisPoints) external;
function setFeeDistribution(
uint16 _treasuryFeeBasisPoints,
uint16 _insuranceFeeBasisPoints,
uint16 _SPFeeBasisPoints)
external;

/**
* @notice Returns staking rewards fee rate
Expand Down
Loading

0 comments on commit bfec632

Please sign in to comment.