Skip to content

Commit cbbc725

Browse files
authored
[Protocol3] replace tslint with eslint and fix some solium issues (#279)
1 parent a4b19c5 commit cbbc725

14 files changed

+83
-85
lines changed

packages/loopring_v3/.eslintrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
parser: "@typescript-eslint/parser",
3+
plugins: ["@typescript-eslint"],
4+
extends: ["plugin:prettier/recommended"]
5+
};

packages/loopring_v3/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ transpiled/
44
ethsnarks/
55
keys/
66
blocks/
7+
package-lock.json
78
.DS_Store
89
.node-*
910
*.log
@@ -14,4 +15,4 @@ __pycache__
1415
*.pyc
1516
.idea/
1617
genkeys/
17-
EDDSA_KeyPair.json
18+
EDDSA_KeyPair.json

packages/loopring_v3/.soliumignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules
22
contracts/Migrations.sol
33
contracts/thirdparty/MiMC.sol
44
contracts/thirdparty/MerkleTree.sol
5+
contracts/thirdparty/Proxy.sol

packages/loopring_v3/contracts/iface/IExchange.sol

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,11 @@ contract IExchange
10571057
function getProtocolFeeValues()
10581058
external
10591059
view
1060-
returns (uint32 timestamp,
1061-
uint8 takerFeeBips, uint8 makerFeeBips,
1062-
uint8 previousTakerFeeBips, uint8 previousMakerFeeBips);
1060+
returns (
1061+
uint32 timestamp,
1062+
uint8 takerFeeBips,
1063+
uint8 makerFeeBips,
1064+
uint8 previousTakerFeeBips,
1065+
uint8 previousMakerFeeBips
1066+
);
10631067
}

packages/loopring_v3/contracts/iface/IProtocolFeeVault.sol

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ contract IProtocolFeeVault
106106
address token,
107107
uint amount
108108
)
109-
external
110-
;
109+
external;
111110

112111
/// @dev Sell a non-LRC token or Ether to LRC, only callable by the owner.
113112
/// @param token The token or ether (0x0) to sell.

packages/loopring_v3/contracts/iface/IUserStakingPool.sol

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ contract IUserStakingPool
4040
/// @dev Set a new IProtocolFeeVault address, only callable by the owner.
4141
/// @param _protocolFeeVaultAddress The new IProtocolFeeVault address.
4242
function setProtocolFeeVault(address _protocolFeeVaultAddress)
43-
external
44-
;
43+
external;
4544

4645
/// @dev Return the total number of LRC staked.
4746
function getTotalStaking()
@@ -56,8 +55,8 @@ contract IUserStakingPool
5655
/// @return stakeAmount The amount of LRC staked.
5756
/// @return claimableReward The amount of LRC reward waiting to be claimed.
5857
function getUserStaking(address user)
59-
view
6058
external
59+
view
6160
returns (
6261
uint withdrawalWaitTime,
6362
uint rewardWaitTime,

packages/loopring_v3/contracts/impl/ProtocolFeeVault.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ pragma solidity 0.5.7;
1818

1919
import "../iface/IProtocolFeeVault.sol";
2020

21-
import "..//lib/Claimable.sol";
21+
import "../lib/AddressUtil.sol";
22+
import "../lib/Claimable.sol";
2223
import "../lib/BurnableERC20.sol";
2324
import "../lib/ERC20.sol";
2425
import "../lib/ERC20SafeTransfer.sol";
@@ -71,6 +72,8 @@ contract IAuction {
7172
contract ProtocolFeeVault is IProtocolFeeVault, Claimable
7273
{
7374
uint public constant MIN_ETHER_TO_KEEP = 1 ether;
75+
using AddressUtil for address;
76+
using AddressUtil for address payable;
7477
using ERC20SafeTransfer for address;
7578
using MathUint for uint;
7679

@@ -168,8 +171,7 @@ contract ProtocolFeeVault is IProtocolFeeVault, Claimable
168171
require(token != lrcAddress, "INVALD_TOKEN");
169172

170173
if (token == address(0)) {
171-
address payable recipient = address(uint160(owner));
172-
require(recipient.send(amount), "TRANSFER_FAILURE");
174+
owner.transferETH(amount, gasleft());
173175
} else {
174176
require(token.safeTransfer(owner, amount), "TRANSFER_FAILURE");
175177
}
@@ -244,9 +246,7 @@ contract ProtocolFeeVault is IProtocolFeeVault, Claimable
244246
);
245247

246248
if (tokenS == address(0)) {
247-
bool success;
248-
(success, ) = auctionAddr.call.value(amountS)("");
249-
require(success, "TRANSFER_FAILURE");
249+
auctionAddr.transferETH(amountS, gasleft());
250250
} else {
251251
require(ERC20(tokenS).approve(auctionAddr, amountS), "AUTH_FAILED");
252252
IAuction(auctionAddr).ask(amountS);

packages/loopring_v3/contracts/impl/UserStakingPool.sol

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,16 @@ contract UserStakingPool is IUserStakingPool, Claimable
6464
}
6565

6666
function getTotalStaking()
67-
view
6867
external
68+
view
6969
returns (uint)
7070
{
7171
return total.stake;
7272
}
7373

7474
function getUserStaking(address user)
75-
view
7675
external
76+
view
7777
returns (
7878
uint withdrawalWaitTime,
7979
uint rewardWaitTime,
@@ -139,11 +139,11 @@ contract UserStakingPool is IUserStakingPool, Claimable
139139

140140
function withdraw(uint amount)
141141
external
142-
{
143-
require(userWithdrawalWaitTime(msg.sender) == 0);
142+
{
143+
require(userWithdrawalWaitTime(msg.sender) == 0, "NEED_TO_WAIT");
144144

145145
Stake storage user = users[msg.sender];
146-
require(user.stake >= amount);
146+
require(user.stake >= amount, "INSUFFICIENT_FUND");
147147

148148
uint _amount = amount == 0 ? user.stake : amount;
149149

@@ -167,7 +167,7 @@ contract UserStakingPool is IUserStakingPool, Claimable
167167
external
168168
returns (uint claimedAmount)
169169
{
170-
require(userClaimWaitTime(msg.sender) == 0);
170+
require(userClaimWaitTime(msg.sender) == 0, "NEED_TO_WAIT");
171171

172172
uint totalPoints;
173173
uint userPoints;
@@ -191,26 +191,26 @@ contract UserStakingPool is IUserStakingPool, Claimable
191191
// -- Private Function --
192192

193193
function userWithdrawalWaitTime(address user)
194-
view
195194
private
195+
view
196196
returns (uint _seconds)
197197
{
198198
if (users[user].depositedAt.add(MIN_WITHDRAW_DELAY) <= now) return 0;
199199
else return users[user].depositedAt.add(MIN_WITHDRAW_DELAY).sub(now);
200200
}
201201

202202
function userClaimWaitTime(address user)
203-
view
204203
private
204+
view
205205
returns (uint minutes_)
206206
{
207-
if (users[user].claimedAt.add(MIN_CLAIM_DELAY) <= now) return 0;
208-
else return users[user].claimedAt.add(MIN_CLAIM_DELAY).sub(now);
207+
if (users[user].claimedAt.add(MIN_CLAIM_DELAY) <= now) return 0;
208+
else return users[user].claimedAt.add(MIN_CLAIM_DELAY).sub(now);
209209
}
210210

211211
function userOutstandingReward(address userAddress)
212-
view
213212
private
213+
view
214214
returns (
215215
uint userPoints,
216216
uint totalPoints,

packages/loopring_v3/contracts/impl/libexchange/ExchangeBlocks.sol

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,10 @@ library ExchangeBlocks
346346
require(inputEndingHash == endingHash, "INVALID_ENDING_HASH");
347347
numWithdrawalRequestsCommitted += uint32(count);
348348
}
349-
} else if (blockType == ExchangeData.BlockType.OFFCHAIN_WITHDRAWAL) {
350-
// Do nothing
351-
} else if (blockType == ExchangeData.BlockType.ORDER_CANCELLATION) {
352-
// Do nothing
353-
} else if (blockType == ExchangeData.BlockType.TRANSFER) {
354-
// Do nothing
355-
} else {
349+
} else if (
350+
blockType != ExchangeData.BlockType.OFFCHAIN_WITHDRAWAL &&
351+
blockType != ExchangeData.BlockType.ORDER_CANCELLATION &&
352+
blockType != ExchangeData.BlockType.TRANSFER) {
356353
revert("UNSUPPORTED_BLOCK_TYPE");
357354
}
358355

@@ -429,7 +426,7 @@ library ExchangeBlocks
429426
}
430427
// The given fee values are valid if they are the current or previous protocol fee values
431428
return (takerFeeBips == data.takerFeeBips && makerFeeBips == data.makerFeeBips) ||
432-
(takerFeeBips == data.previousTakerFeeBips && makerFeeBips == data.previousMakerFeeBips);
429+
(takerFeeBips == data.previousTakerFeeBips && makerFeeBips == data.previousMakerFeeBips);
433430
}
434431

435432
function isDepositRequestForced(

packages/loopring_v3/contracts/impl/libexchange/ExchangeWithdrawals.sol

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -333,27 +333,27 @@ library ExchangeWithdrawals
333333
uint feeAmount = 0;
334334
uint32 lastRequestTimestamp = 0;
335335
{
336-
uint startIndex = previousBlock.numDepositRequestsCommitted;
337-
uint endIndex = requestedBlock.numDepositRequestsCommitted;
336+
uint startIndex = previousBlock.numDepositRequestsCommitted;
337+
uint endIndex = requestedBlock.numDepositRequestsCommitted;
338+
if(endIndex > startIndex) {
339+
feeAmount = S.depositChain[endIndex - 1].accumulatedFee.sub(
340+
S.depositChain[startIndex - 1].accumulatedFee
341+
);
342+
lastRequestTimestamp = S.depositChain[endIndex - 1].timestamp;
343+
} else {
344+
startIndex = previousBlock.numWithdrawalRequestsCommitted;
345+
endIndex = requestedBlock.numWithdrawalRequestsCommitted;
346+
338347
if(endIndex > startIndex) {
339-
feeAmount = S.depositChain[endIndex - 1].accumulatedFee.sub(
340-
S.depositChain[startIndex - 1].accumulatedFee
348+
feeAmount = S.withdrawalChain[endIndex - 1].accumulatedFee.sub(
349+
S.withdrawalChain[startIndex - 1].accumulatedFee
341350
);
342-
lastRequestTimestamp = S.depositChain[endIndex - 1].timestamp;
351+
lastRequestTimestamp = S.withdrawalChain[endIndex - 1].timestamp;
343352
} else {
344-
startIndex = previousBlock.numWithdrawalRequestsCommitted;
345-
endIndex = requestedBlock.numWithdrawalRequestsCommitted;
346-
347-
if(endIndex > startIndex) {
348-
feeAmount = S.withdrawalChain[endIndex - 1].accumulatedFee.sub(
349-
S.withdrawalChain[startIndex - 1].accumulatedFee
350-
);
351-
lastRequestTimestamp = S.withdrawalChain[endIndex - 1].timestamp;
352-
} else {
353-
revert("BLOCK_HAS_NO_OPERATOR_FEE");
354-
}
353+
revert("BLOCK_HAS_NO_OPERATOR_FEE");
355354
}
356355
}
356+
}
357357

358358
// Calculate how much of the fee the operator gets for the block
359359
// If there are many requests than lastRequestTimestamp ~= firstRequestTimestamp so
@@ -393,8 +393,12 @@ library ExchangeWithdrawals
393393
ExchangeData.Block storage withdrawBlock = S.blocks[blockIdx];
394394

395395
// Check if this is a withdrawal block
396-
require(withdrawBlock.blockType == ExchangeData.BlockType.ONCHAIN_WITHDRAWAL ||
397-
withdrawBlock.blockType == ExchangeData.BlockType.OFFCHAIN_WITHDRAWAL, "INVALID_BLOCK_TYPE");
396+
require(
397+
withdrawBlock.blockType == ExchangeData.BlockType.ONCHAIN_WITHDRAWAL ||
398+
withdrawBlock.blockType == ExchangeData.BlockType.OFFCHAIN_WITHDRAWAL,
399+
"INVALID_BLOCK_TYPE"
400+
);
401+
398402
// Only allow withdrawing on finalized blocks
399403
require(blockIdx < S.numBlocksFinalized, "BLOCK_NOT_FINALIZED");
400404
// Check if the withdrawals were already completely distributed

0 commit comments

Comments
 (0)