mirror of
https://github.com/fluencelabs/smartcontracts
synced 2025-04-25 03:02:18 +00:00
tiny fixes
This commit is contained in:
parent
7b44d46a68
commit
8e0e8902a3
3
.gitignore
vendored
3
.gitignore
vendored
@ -2,4 +2,5 @@
|
|||||||
/.idea
|
/.idea
|
||||||
*.iml
|
*.iml
|
||||||
/node_modules
|
/node_modules
|
||||||
1501*
|
1501*
|
||||||
|
tmp
|
@ -1,8 +0,0 @@
|
|||||||
pragma solidity ^0.4.4;
|
|
||||||
|
|
||||||
library ConvertLib{
|
|
||||||
function convert(uint amount,uint conversionRate) returns (uint convertedAmount)
|
|
||||||
{
|
|
||||||
return amount * conversionRate;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,50 +1,26 @@
|
|||||||
pragma solidity ^0.4.13;
|
pragma solidity ^0.4.13;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/* taking ideas from FirstBlood token */
|
||||||
* Math operations with safety checks
|
contract SafeMath {
|
||||||
*/
|
|
||||||
library SafeMath {
|
function safeAdd(uint256 x, uint256 y) internal returns(uint256) {
|
||||||
function mul(uint256 a, uint256 b) internal returns (uint256) {
|
uint256 z = x + y;
|
||||||
uint256 c = a * b;
|
assert((z >= x) && (z >= y));
|
||||||
assert(a == 0 || c / a == b);
|
return z;
|
||||||
return c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function div(uint256 a, uint256 b) internal returns (uint256) {
|
function safeSubtract(uint256 x, uint256 y) internal returns(uint256) {
|
||||||
// assert(b > 0); // Solidity automatically throws when dividing by 0
|
assert(x >= y);
|
||||||
uint256 c = a / b;
|
uint256 z = x - y;
|
||||||
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
|
return z;
|
||||||
return c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sub(uint256 a, uint256 b) internal returns (uint256) {
|
function safeMult(uint256 x, uint256 y) internal returns(uint256) {
|
||||||
assert(b <= a);
|
uint256 z = x * y;
|
||||||
return a - b;
|
assert((x == 0)||(z/x == y));
|
||||||
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
function add(uint256 a, uint256 b) internal returns (uint256) {
|
|
||||||
uint256 c = a + b;
|
|
||||||
assert(c >= a);
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
function max64(uint64 a, uint64 b) internal constant returns (uint64) {
|
|
||||||
return a >= b ? a : b;
|
|
||||||
}
|
|
||||||
|
|
||||||
function min64(uint64 a, uint64 b) internal constant returns (uint64) {
|
|
||||||
return a < b ? a : b;
|
|
||||||
}
|
|
||||||
|
|
||||||
function max256(uint256 a, uint256 b) internal constant returns (uint256) {
|
|
||||||
return a >= b ? a : b;
|
|
||||||
}
|
|
||||||
|
|
||||||
function min256(uint256 a, uint256 b) internal constant returns (uint256) {
|
|
||||||
return a < b ? a : b;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -110,9 +86,7 @@ contract Haltable is Ownable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract FluencePreSale is Haltable {
|
contract FluencePreSale is Haltable, SafeMath {
|
||||||
using SafeMath for uint;
|
|
||||||
using SafeMath for uint256;
|
|
||||||
|
|
||||||
mapping (address => uint256) public balanceOf;
|
mapping (address => uint256) public balanceOf;
|
||||||
|
|
||||||
@ -193,7 +167,7 @@ contract FluencePreSale is Haltable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setBeneficiary(address to) onlyOwner external {
|
function setBeneficiary(address to) onlyOwner external {
|
||||||
require(to != 0x0);
|
require(to != address(0));
|
||||||
beneficiary = to;
|
beneficiary = to;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,20 +182,22 @@ contract FluencePreSale is Haltable {
|
|||||||
uint256 tokensToIssue;
|
uint256 tokensToIssue;
|
||||||
|
|
||||||
if(msg.value >= expertThreshold) {
|
if(msg.value >= expertThreshold) {
|
||||||
tokensToIssue = (msg.value / 1 ether).mul(expertTokensPerEth);
|
tokensToIssue = safeMult(msg.value, expertTokensPerEth);
|
||||||
} else if(msg.value >= advancedThreshold) {
|
} else if(msg.value >= advancedThreshold) {
|
||||||
tokensToIssue = (msg.value / 1 ether).mul(advancedTokensPerEth);
|
tokensToIssue = safeMult(msg.value, advancedTokensPerEth);
|
||||||
} else {
|
} else {
|
||||||
tokensToIssue = (msg.value / 1 ether).mul(basicTokensPerEth);
|
tokensToIssue = safeMult(msg.value, basicTokensPerEth);
|
||||||
}
|
}
|
||||||
|
|
||||||
totalSupply = totalSupply.add(tokensToIssue);
|
assert(tokensToIssue > 0);
|
||||||
|
|
||||||
|
totalSupply = safeAdd(totalSupply, tokensToIssue);
|
||||||
require(totalSupply <= SUPPLY_LIMIT);
|
require(totalSupply <= SUPPLY_LIMIT);
|
||||||
|
|
||||||
etherContributions[_address] = etherContributions[_address].add(msg.value);
|
etherContributions[_address] = safeAdd(etherContributions[_address], msg.value);
|
||||||
uint collectedBefore = etherCollected;
|
uint collectedBefore = etherCollected;
|
||||||
etherCollected = etherCollected.add(msg.value);
|
etherCollected = safeAdd(etherCollected, msg.value);
|
||||||
balanceOf[_address] = balanceOf[_address].add(tokensToIssue);
|
balanceOf[_address] = safeAdd(balanceOf[_address], tokensToIssue);
|
||||||
|
|
||||||
NewContribution(_address, tokensToIssue, msg.value);
|
NewContribution(_address, tokensToIssue, msg.value);
|
||||||
|
|
||||||
@ -250,8 +226,8 @@ contract FluencePreSale is Haltable {
|
|||||||
etherContributions[msg.sender] = 0; // Clear state
|
etherContributions[msg.sender] = 0; // Clear state
|
||||||
|
|
||||||
// Reduce counters
|
// Reduce counters
|
||||||
etherCollected = etherCollected.sub(amount);
|
etherCollected = safeSubtract(etherCollected, amount);
|
||||||
totalSupply = totalSupply.sub(balanceOf[msg.sender]);
|
totalSupply = safeSubtract(totalSupply, tokensToBurn);
|
||||||
|
|
||||||
msg.sender.transfer(amount); // Process refund. In case of error, it will be thrown
|
msg.sender.transfer(amount); // Process refund. In case of error, it will be thrown
|
||||||
|
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
pragma solidity ^0.4.4;
|
|
||||||
|
|
||||||
import "./ConvertLib.sol";
|
|
||||||
|
|
||||||
// This is just a simple example of a coin-like contract.
|
|
||||||
// It is not standards compatible and cannot be expected to talk to other
|
|
||||||
// coin/token contracts. If you want to create a standards-compliant
|
|
||||||
// token, see: https://github.com/ConsenSys/Tokens. Cheers!
|
|
||||||
|
|
||||||
contract MetaCoin {
|
|
||||||
mapping (address => uint) balances;
|
|
||||||
|
|
||||||
event Transfer(address indexed _from, address indexed _to, uint256 _value);
|
|
||||||
|
|
||||||
function MetaCoin() {
|
|
||||||
balances[tx.origin] = 10000;
|
|
||||||
}
|
|
||||||
|
|
||||||
function sendCoin(address receiver, uint amount) returns(bool sufficient) {
|
|
||||||
if (balances[msg.sender] < amount) return false;
|
|
||||||
balances[msg.sender] -= amount;
|
|
||||||
balances[receiver] += amount;
|
|
||||||
Transfer(msg.sender, receiver, amount);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getBalanceInEth(address addr) returns(uint){
|
|
||||||
return ConvertLib.convert(getBalance(addr),2);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getBalance(address addr) returns(uint) {
|
|
||||||
return balances[addr];
|
|
||||||
}
|
|
||||||
}
|
|
@ -21,7 +21,7 @@ contract TestFluencePreSale {
|
|||||||
|
|
||||||
Assert.equal(fluence.owner(), tx.origin, "Owner must be set to sender");
|
Assert.equal(fluence.owner(), tx.origin, "Owner must be set to sender");
|
||||||
|
|
||||||
fluence.transfer.value(1 ether).gas(210000)();
|
assert(fluence.call.gas(3000000).value(1 ether)());
|
||||||
|
|
||||||
assert(fluence.balanceOf(tx.origin) == 1500);
|
assert(fluence.balanceOf(tx.origin) == 1500);
|
||||||
|
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
pragma solidity ^0.4.2;
|
|
||||||
|
|
||||||
import "truffle/Assert.sol";
|
|
||||||
import "truffle/DeployedAddresses.sol";
|
|
||||||
import "../contracts/MetaCoin.sol";
|
|
||||||
|
|
||||||
contract TestMetacoin {
|
|
||||||
|
|
||||||
function testInitialBalanceUsingDeployedContract() {
|
|
||||||
MetaCoin meta = new MetaCoin();
|
|
||||||
|
|
||||||
uint expected = 10000;
|
|
||||||
|
|
||||||
Assert.equal(meta.getBalance(tx.origin), expected, "Owner should have 10000 MetaCoin initially");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testInitialBalanceWithNewMetaCoin() {
|
|
||||||
MetaCoin meta = new MetaCoin();
|
|
||||||
|
|
||||||
uint expected = 10000;
|
|
||||||
|
|
||||||
Assert.equal(meta.getBalance(tx.origin), expected, "Owner should have 10000 MetaCoin initially");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
var MetaCoin = artifacts.require("./MetaCoin.sol");
|
/*var MetaCoin = artifacts.require("./MetaCoin.sol");
|
||||||
|
|
||||||
contract('MetaCoin', function(accounts) {
|
contract('MetaCoin', function(accounts) {
|
||||||
it("should put 10000 MetaCoin in the first account", function() {
|
it("should put 10000 MetaCoin in the first account", function() {
|
||||||
@ -61,3 +61,4 @@ contract('MetaCoin', function(accounts) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
*/
|
Loading…
x
Reference in New Issue
Block a user