Skip to content

Commit

Permalink
Merge branch 'feat/signed-payload-2'
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed Nov 6, 2017
2 parents 5df45db + e456431 commit fe22c8b
Show file tree
Hide file tree
Showing 17 changed files with 1,161 additions and 454 deletions.
7 changes: 7 additions & 0 deletions contracts/AMLToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ import "./BurnableCrowdsaleToken.sol";
* This subset of BurnableCrowdsaleToken gives the Owner a possibility to
* reclaim tokens from a participant before the token is released
* after a participant has failed a prolonged AML process.
*
* It is assumed that the anti-money laundering process depends on blockchain data.
* The data is not available before the transaction and not for the smart contract.
* Thus, we need to implement logic to handle AML failure cases post payment.
* We give a time window before the token release for the token sale owners to
* complete the AML and claw back all token transactions that were
* caused by rejected purchases.
*/
contract AMLToken is BurnableCrowdsaleToken {

Expand Down
49 changes: 6 additions & 43 deletions contracts/AllocatedCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,20 @@

pragma solidity ^0.4.8;

import "./AllocatedCrowdsaleMixin.sol";
import "./Crowdsale.sol";


/**
* A crowdsale that is selling tokens from a preallocated pool
*
*
* - Tokens have precreated supply "premined"
* An implementation of allocated crowdsale.
*
* - Token owner must transfer sellable tokens to the crowdsale contract using ERC20.approve()
* This implementation does not have KYC logic (vs. KYCCrowdsale).
*
*/
contract AllocatedCrowdsale is Crowdsale {

/* The party who holds the full token pool and has approve()'ed tokens for this crowdsale */
address public beneficiary;

function AllocatedCrowdsale(address _token, PricingStrategy _pricingStrategy, address _multisigWallet, uint _start, uint _end, uint _minimumFundingGoal, address _beneficiary) Crowdsale(_token, _pricingStrategy, _multisigWallet, _start, _end, _minimumFundingGoal) {
beneficiary = _beneficiary;
}
contract AllocatedCrowdsale is AllocatedCrowdsaleMixin, Crowdsale {

/**
* Called from invest() to confirm if the curret investment does not break our cap rule.
*/
function isBreakingCap(uint weiAmount, uint tokenAmount, uint weiRaisedTotal, uint tokensSoldTotal) constant returns (bool limitBroken) {
if(tokenAmount > getTokensLeft()) {
return true;
} else {
return false;
}
}
function AllocatedCrowdsale(address _token, PricingStrategy _pricingStrategy, address _multisigWallet, uint _start, uint _end, uint _minimumFundingGoal, address _beneficiary) Crowdsale(_token, _pricingStrategy, _multisigWallet, _start, _end, _minimumFundingGoal) AllocatedCrowdsaleMixin(_beneficiary) {

/**
* We are sold out when our approve pool becomes empty.
*/
function isCrowdsaleFull() public constant returns (bool) {
return getTokensLeft() == 0;
}

/**
* Get the amount of unsold tokens allocated to this contract;
*/
function getTokensLeft() public constant returns (uint) {
return token.allowance(owner, this);
}

/**
* Transfer tokens from approve() pool to the buyer.
*
* Use approve() given to this crowdsale to distribute the tokens.
*/
function assignTokens(address receiver, uint tokenAmount) private {
if(!token.transferFrom(beneficiary, receiver, tokenAmount)) throw;
}
}
67 changes: 67 additions & 0 deletions contracts/AllocatedCrowdsaleMixin.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* This smart contract code is Copyright 2017 TokenMarket Ltd. For more information see https://tokenmarket.net
*
* Licensed under the Apache License, version 2.0: https://github.com/TokenMarketNet/ico/blob/master/LICENSE.txt
*/

pragma solidity ^0.4.8;

import "./CrowdsaleBase.sol";

/**
* A mixin that is selling tokens from a preallocated pool
*
* - Tokens have precreated supply "premined"
*
* - Token owner must transfer sellable tokens to the crowdsale contract using ERC20.approve()
*
* - The mixin does not implement buy entry point.
*
*/
contract AllocatedCrowdsaleMixin is CrowdsaleBase {

/* The party who holds the full token pool and has approve()'ed tokens for this crowdsale */
address public beneficiary;

/**
* @param _beneficiary The account who has performed approve() to allocate tokens for the token sale.
*
*/
function AllocatedCrowdsaleMixin(address _beneficiary) {
beneficiary = _beneficiary;
}

/**
* Called from invest() to confirm if the curret investment does not break our cap rule.
*/
function isBreakingCap(uint weiAmount, uint tokenAmount, uint weiRaisedTotal, uint tokensSoldTotal) constant returns (bool limitBroken) {
if(tokenAmount > getTokensLeft()) {
return true;
} else {
return false;
}
}

/**
* We are sold out when our approve pool becomes empty.
*/
function isCrowdsaleFull() public constant returns (bool) {
return getTokensLeft() == 0;
}

/**
* Get the amount of unsold tokens allocated to this contract;
*/
function getTokensLeft() public constant returns (uint) {
return token.allowance(owner, this);
}

/**
* Transfer tokens from approve() pool to the buyer.
*
* Use approve() given to this crowdsale to distribute the tokens.
*/
function assignTokens(address receiver, uint tokenAmount) internal {
if(!token.transferFrom(beneficiary, receiver, tokenAmount)) throw;
}
}
77 changes: 77 additions & 0 deletions contracts/BytesDeserializer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* This smart contract code is Copyright 2017 TokenMarket Ltd. For more information see https://tokenmarket.net
*
* Licensed under the Apache License, version 2.0: https://github.com/TokenMarketNet/ico/blob/master/LICENSE.txt
*/

/**
* Deserialize bytes payloads.
*
* Values are in big-endian byte order.
*
*/
library BytesDeserializer {

/**
* Extract 256-bit worth of data from the bytes stream.
*/
function slice32(bytes b, uint offset) constant returns (bytes32) {
bytes32 out;

for (uint i = 0; i < 32; i++) {
out |= bytes32(b[offset + i] & 0xFF) >> (i * 8);
}
return out;
}

/**
* Extract Ethereum address worth of data from the bytes stream.
*/
function sliceAddress(bytes b, uint offset) constant returns (address) {
bytes32 out;

for (uint i = 0; i < 20; i++) {
out |= bytes32(b[offset + i] & 0xFF) >> ((i+12) * 8);
}
return address(uint(out));
}

/**
* Extract 128-bit worth of data from the bytes stream.
*/
function slice16(bytes b, uint offset) constant returns (bytes16) {
bytes16 out;

for (uint i = 0; i < 16; i++) {
out |= bytes16(b[offset + i] & 0xFF) >> (i * 8);
}
return out;
}

/**
* Extract 32-bit worth of data from the bytes stream.
*/
function slice4(bytes b, uint offset) constant returns (bytes4) {
bytes4 out;

for (uint i = 0; i < 4; i++) {
out |= bytes4(b[offset + i] & 0xFF) >> (i * 8);
}
return out;
}

/**
* Extract 16-bit worth of data from the bytes stream.
*/
function slice2(bytes b, uint offset) constant returns (bytes2) {
bytes2 out;

for (uint i = 0; i < 2; i++) {
out |= bytes2(b[offset + i] & 0xFF) >> (i * 8);
}
return out;
}



}

0 comments on commit fe22c8b

Please sign in to comment.