Skip to content

Commit

Permalink
Merge pull request #17 from svandisproject/audit_updates
Browse files Browse the repository at this point in the history
Audit updates
  • Loading branch information
onigiri-x committed May 30, 2018
2 parents 88b8ac4 + b5d5011 commit 62d4b53
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
3 changes: 1 addition & 2 deletions EIP20Interface.sol
Expand Up @@ -2,7 +2,6 @@
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
pragma solidity ^0.4.19;


contract EIP20Interface {
uint256 public totalSupply;
function balanceOf(address _owner) public view returns (uint256 balance);
Expand All @@ -13,4 +12,4 @@ contract EIP20Interface {

event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
}
27 changes: 16 additions & 11 deletions Sale.sol
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.4.21;
import "./Svandis.sol";

contract Sale is Svandis {

using SafeMath for uint256;
address owner;
address withdrawWallet;
uint256 public tier1Rate;
Expand All @@ -14,6 +14,7 @@ contract Sale is Svandis {
uint256 public preSaleRate;
mapping(uint8 => uint256) public tierToRates;
mapping (address => uint256) public companyAllowed;
mapping (address => uint256) public contributorAllowed;

constructor() public {
owner = msg.sender;
Expand Down Expand Up @@ -59,7 +60,7 @@ contract Sale is Svandis {

function addToWhitelist(address _whitelisted, uint256 _quantity) public onlyOwner returns (bool success) {
require(_quantity <= balances[this]);
allowed[this][_whitelisted] = _quantity;
contributorAllowed[_whitelisted] = _quantity;
return true;
}

Expand All @@ -79,7 +80,7 @@ contract Sale is Svandis {
}

function removeFromWhitelist(address _whitelisted) public onlyOwner returns (bool success) {
allowed[this][_whitelisted] = 0;
contributorAllowed[_whitelisted] = 0;
return true;
}

Expand All @@ -89,7 +90,7 @@ contract Sale is Svandis {
}

function checkWhitelisted(address _whitelisted) public view onlyOwner returns (uint256 quantity) {
return allowed[this][_whitelisted];
return contributorAllowed[_whitelisted];
}

function checkCompanyWhitelisted(address _whitelisted) public view onlyOwner returns (uint256 quantity) {
Expand Down Expand Up @@ -120,22 +121,26 @@ contract Sale is Svandis {
}

function buyTokens() public saleOngoing payable {
uint256 quantity = (msg.value * tierToRates[currentTier])/(1 ether);
require(quantity <= allowed[this][msg.sender]);
uint256 quantity = (msg.value * tierToRates[currentTier]).div(1 ether);
require(quantity <= contributorAllowed[msg.sender]);

balances[msg.sender] += quantity;
balances[address(this)] -= quantity;
allowed[this][msg.sender] -= quantity;
balances[msg.sender] = balances[msg.sender].add(quantity);
balances[address(this)] = balances[address(this)].sub(quantity);
contributorAllowed[msg.sender] = contributorAllowed[msg.sender].sub(quantity);

withdrawWallet.transfer(msg.value);
emit Transfer(this, msg.sender, quantity);
}

function takeCompanyTokensOwnership() public {
balances[msg.sender] += companyAllowed[msg.sender];
balances[address(this)] -= companyAllowed[msg.sender];
balances[msg.sender] = balances[msg.sender].add(companyAllowed[msg.sender]);
balances[address(this)] = balances[address(this)].sub(companyAllowed[msg.sender]);

emit Transfer(this, msg.sender, companyAllowed[msg.sender]);
companyAllowed[msg.sender] = 0;
}

function transferAnyEIP20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return EIP20Interface(tokenAddress).transfer(owner, tokens);
}
}
32 changes: 25 additions & 7 deletions Svandis.sol
Expand Up @@ -2,12 +2,30 @@ pragma solidity ^0.4.21;

import "./EIP20Interface.sol";

library SafeMath {
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
require(c >= a);
}
function sub(uint256 a, uint256 b) internal pure returns (uint256 c) {
require(b <= a);
c = a - b;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a * b;
require(a == 0 || c / a == b);
}
function div(uint256 a, uint256 b) internal pure returns (uint256 c) {
require(b > 0);
c = a / b;
}
}

contract Svandis is EIP20Interface {

using SafeMath for uint256;
uint256 constant private MAX_UINT256 = 2**256 - 1;
uint256 constant public totalSupply = 400000000000000000000000000;
uint256 constant public decimals = 18;
uint8 constant public decimals = 18;

mapping (address => uint256) public balances;
mapping (address => mapping (address => uint256)) public allowed;
Expand All @@ -18,8 +36,8 @@ contract Svandis is EIP20Interface {

function transfer(address _to, uint256 _value) public returns (bool success) {
require(balances[msg.sender] >= _value);
balances[msg.sender] -= _value;
balances[_to] += _value;
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
Expand All @@ -28,10 +46,10 @@ contract Svandis is EIP20Interface {
uint256 allowance = allowed[_from][msg.sender];
require(balances[_from] >= _value && allowance >= _value);
require(_from != address(this));
balances[_to] += _value;
balances[_from] -= _value;
balances[_to] = balances[_to].add(_value);
balances[_from] = balances[_from].sub(_value);
if (allowance < MAX_UINT256) {
allowed[_from][msg.sender] -= _value;
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
}
emit Transfer(_from, _to, _value);
return true;
Expand Down

0 comments on commit 62d4b53

Please sign in to comment.