Skip to content

Commit

Permalink
Merge pull request #1 from OriginTrail/slither-updates
Browse files Browse the repository at this point in the history
Fixes based on Slither for re-entrancy and code readability
  • Loading branch information
branarakic authored Dec 29, 2020
2 parents d71f503 + 97b4f9c commit 6481b12
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.8.0;
pragma solidity >=0.4.22 <=0.8.0;

contract Migrations {
address public owner = msg.sender;
Expand Down
40 changes: 21 additions & 19 deletions contracts/StarfleetStake.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity >=0.6.0 <0.8.0;
pragma solidity >=0.6.0 <=0.8.0;

import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
Expand All @@ -18,10 +18,10 @@ contract StarfleetStake is Ownable {
// Time periods

// Official start time of the staking period
uint256 public t_zero;
uint256 public BOARDING_PERIOD_LENGTH = 30 days;
uint256 public LOCK_PERIOD_LENGTH = 180 days;
uint256 public BRIDGE_PERIOD_LENGTH = 180 days;
uint256 public tZero;
uint256 public constant BOARDING_PERIOD_LENGTH = 30 days;
uint256 public constant LOCK_PERIOD_LENGTH = 180 days;
uint256 public constant BRIDGE_PERIOD_LENGTH = 180 days;
bool public min_threshold_reached = false;

// list of participants
Expand All @@ -42,9 +42,9 @@ contract StarfleetStake is Ownable {
constructor(uint256 startTime,address tokenAddress) public {

if(startTime!=0){
t_zero = startTime;
tZero = startTime;
}else{
t_zero = now;
tZero = now;
}

if (tokenAddress!=address(0x0)){
Expand All @@ -60,8 +60,8 @@ contract StarfleetStake is Ownable {
// Functional requirement FR1
function depositTokens(uint256 amount) public {

require(now >= t_zero);
require(now < t_zero + BOARDING_PERIOD_LENGTH);
require(now >= tZero);
require(now < tZero + BOARDING_PERIOD_LENGTH);
require(token.balanceOf(address(this)) + amount <= MAX_THRESHOLD, "Sender cannot deposit amounts that would cross the MAX_THRESHOLD");
require(token.allowance(msg.sender, address(this)) >= amount, "Sender allowance must be equal to or higher than chosen amount");
require(token.balanceOf(msg.sender) >= amount, "Sender balance must be equal to or higher than chosen amount!");
Expand Down Expand Up @@ -98,31 +98,33 @@ function isMinimumReached() public view returns(bool){
// Functional requirement FR2
function withdrawTokens() public {

require(now >= t_zero);
require(now >= tZero);
require(!min_threshold_reached);
require(stake[msg.sender] > 0);

token.transfer(msg.sender, stake[msg.sender]);
emit TokenWithdrawn(msg.sender, stake[msg.sender]);
uint256 amount = stake[msg.sender];
stake[msg.sender] = 0;
token.transfer(msg.sender, amount);
emit TokenWithdrawn(msg.sender, amount);


}

// Functional requirement FR6
function fallbackWithdrawTokens() public {

require(now > t_zero + BOARDING_PERIOD_LENGTH + LOCK_PERIOD_LENGTH + BRIDGE_PERIOD_LENGTH);
require(now > tZero + BOARDING_PERIOD_LENGTH + LOCK_PERIOD_LENGTH + BRIDGE_PERIOD_LENGTH);
require(StarTRAC_snapshot[msg.sender] > 0);

token.transfer(msg.sender, StarTRAC_snapshot[msg.sender]);
emit TokenFallbackWithdrawn(msg.sender, StarTRAC_snapshot[msg.sender]);
uint256 amount = StarTRAC_snapshot[msg.sender];
StarTRAC_snapshot[msg.sender] = 0;
token.transfer(msg.sender, amount);
emit TokenFallbackWithdrawn(msg.sender, StarTRAC_snapshot[msg.sender]);


}

// Functional requirement FR5
function accountStarTRAC(address[] memory contributors, uint256[] memory amounts) onlyOwner public {
require(now > t_zero + BOARDING_PERIOD_LENGTH + LOCK_PERIOD_LENGTH + BRIDGE_PERIOD_LENGTH);
require(now > tZero + BOARDING_PERIOD_LENGTH + LOCK_PERIOD_LENGTH + BRIDGE_PERIOD_LENGTH);
require(contributors.length == amounts.length);
for (uint i = 0; i < contributors.length; i++) {
StarTRAC_snapshot[contributors[i]] = amounts[i];
Expand All @@ -139,7 +141,7 @@ function getStarTRACamount(address contributor) public view returns(uint256){
function transferTokens(address custodian) onlyOwner public {

require(custodian != address(0x0));
require(now >= t_zero + BOARDING_PERIOD_LENGTH + LOCK_PERIOD_LENGTH && now < t_zero + BOARDING_PERIOD_LENGTH + LOCK_PERIOD_LENGTH + BRIDGE_PERIOD_LENGTH);
require(now >= tZero + BOARDING_PERIOD_LENGTH + LOCK_PERIOD_LENGTH && now < tZero + BOARDING_PERIOD_LENGTH + LOCK_PERIOD_LENGTH + BRIDGE_PERIOD_LENGTH);

uint256 balanceTransferred= token.balanceOf(address(this));
token.transfer(custodian, token.balanceOf(address(this)));
Expand Down
4 changes: 2 additions & 2 deletions contracts/TracToken.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pragma solidity >=0.6.0 <0.8.0;
pragma solidity >=0.6.0 <=0.8.0;

import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";

contract TestTraceToken is ERC20 {

uint public INITIAL_SUPPLY = 5e26;
uint public constant INITIAL_SUPPLY = 5e26;
// for contract testing purposes, not to be confused with TRAC
constructor() public ERC20('Test-Trace token', 'T-TRAC') {
_mint(msg.sender, INITIAL_SUPPLY);
Expand Down

0 comments on commit 6481b12

Please sign in to comment.