Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Ownable() {
- owner = msg.sender;
- }
- modifier onlyOwner {
- if (msg.sender != owner) throw;
- _;
- }
- function transferOwnership(address newOwner) onlyOwner {
- if (newOwner != address(0)) {
- owner = newOwner;
- }
- }
- if (payment == 0) {
- throw;
- }
- if (this.balance < payment) {
- throw;
- }
- payments[payee] = 0;
- if (!payee.send(payment)) {
- throw;
- }
- LogRefundETH(payee,payment);
- using SafeMath for uint;
- struct Backer {
- uint weiReceived; // Amount of Ether given
- uint manusSent;
- }
- /*
- * Constants
- */
- /* Minimum number of manus to sell */
- uint public constant MIN_CAP = 2000000000000000000000000;
- /* Maximum number of manus to sell */
- uint public constant MAX_CAP =4000000000000000000000000 ;
- /*
- * Variables
- */
- /* Manus contract reference */
- Manus public manus;
- /* Multisig contract that will receive the Ether */
- address public multisigEther;
- /* Number of Ether received */
- uint public etherReceived;
- /* Number of manus sent to Ether contributors */
- uint public manusSentToEther;
- /* Backers Ether indexed by their Ethereum address */
- mapping(address => Backer) public backers;
- /*
- * Modifiers
- */
- modifier minCapNotReached() {
- if (manusSentToEther >= MIN_CAP ) throw;
- _;
- }
- /*
- * Event
- */
- event LogReceivedETH(address addr, uint value);
- event LogManusEmited(address indexed from, uint amount);
- /*
- * Constructor
- */
- function Crowdsale(address _manusAddress, address _to) {
- manus = Manus(_manusAddress);
- multisigEther = _to;
- }
- /*
- /*
- * Receives a donation in Ether
- */
- function receiveETH(address beneficiary) internal {
- uint manusToSend = bonus(msg.value.div(1 ether));
- Backer backer = backers[beneficiary];
- manus.transfer(beneficiary, manusToSend); // Transfer ManusToken right now
- backer.manusSent = backer.manusSent.add(manusToSend);
- backer.weiReceived = backer.weiReceived.add(msg.value); // Update the total wei collected during the crowdfunding for this backer
- etherReceived = etherReceived.add(msg.value); // Update the total wei collected during the crowdfunding
- manusSentToEther = manusSentToEther.add(manusToSend);
- // Send events
- LogManusEmited(msg.sender ,manusToSend);
- LogReceivedETH(beneficiary, etherReceived);
- }
- /*
- *Compute the manus bonus according to the investment period
- */
- function bonus(uint amount) internal constant returns (uint) {
- return amount.add(amount.div(5)); // bonus 20%
- return amount;
- }
- /*
- * Finalize the crowdsale, should be called after the refund period
- */
- /*
- * Failsafe drain
- */
- function drain() onlyOwner {
- if (!owner.send(this.balance)) throw;
- }
- /**
- * Allow to change the team multisig address in the case of emergency.
- */
- function setMultisig(address addr) onlyOwner public {
- if (addr == address(0)) throw;
- multisigEther = addr;
- }
- /**
- * Manually back manus owner address.
- */
- function backManusOwner() onlyOwner public {
- manus.transferOwnership(owner);
- }
- /*
- * When MIN_CAP is not reach:
- * 1) backer call the "approve" function of the manus token contract with the amount of all manus they got in order to be refund
- * 2) backer call the "refund" function of the Crowdsale contract with the same amount of manus
- * 3) backer call the "withdrawPayments" function of the Crowdsale contract to get a refund in ETH
- */
- function refund(uint _value) minCapNotReached public {
- if (_value != backers[msg.sender].manusSent) throw; // compare value from backer balance
- manus.transferFrom(msg.sender, address(this), _value); // get the token back to the crowdsale contract
- if (!manus.burn(_value)) throw ; // token sent for refund are burnt
- uint ETHToSend = backers[msg.sender].weiReceived;
- backers[msg.sender].weiReceived=0;
- if (ETHToSend > 0) {
- asyncSend(msg.sender, ETHToSend); // pull payment to get refund in ETH
- }
- }
Add Comment
Please, Sign In to add comment