Skip to content
Closed
Prev Previous commit
Next Next commit
Version bump; fixed solium warnings; added tokensMinted variable to P…
…seudoMinter
  • Loading branch information
lead4good committed Nov 25, 2017
commit f2520ea7dec86318960ae66d0ab8cfa85cab6b0a
23 changes: 16 additions & 7 deletions contracts/examples/PreMintedCrowdsale.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.11;
pragma solidity ^0.4.18;

import "../token/PseudoMinter.sol";
import "../crowdsale/Crowdsale.sol";
Expand All @@ -15,10 +15,15 @@ contract PreMintedCrowdsaleVault {
SimpleToken public token;
PreMintedCrowdsale public crowdsale;

function PreMintedCrowdsaleVault(uint256 _startTime, uint256 _endTime, uint256 _rate, address _wallet) {
function PreMintedCrowdsaleVault(
uint256 _startTime,
uint256 _endTime,
uint256 _rate,
address _wallet
) public {
token = new SimpleToken();
crowdsale = new PreMintedCrowdsale(_startTime, _endTime, _rate, _wallet, token);

PseudoMinter _pseudoMinter = PseudoMinter(crowdsale.token());
token.approve(_pseudoMinter, token.balanceOf(this));
}
Expand All @@ -33,14 +38,18 @@ contract PreMintedCrowdsaleVault {
*/
contract PreMintedCrowdsale is Crowdsale {

function PreMintedCrowdsale(uint256 _startTime, uint256 _endTime, uint256 _rate, address _wallet, ERC20 _token)
Crowdsale(_startTime, _endTime, _rate, _wallet)
{
function PreMintedCrowdsale(
uint256 _startTime,
uint256 _endTime,
uint256 _rate,
address _wallet,
ERC20 _token
) public Crowdsale(_startTime, _endTime, _rate, _wallet) {
token = new PseudoMinter(_token, msg.sender);
}

// save gas by returning address zero
function createMintableContract() internal returns (Mintable) {
function createMintableContract() internal pure returns (Mintable) {
return Mintable(0x0);
}

Expand Down
11 changes: 8 additions & 3 deletions contracts/token/PseudoMinter.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
pragma solidity ^0.4.11;
pragma solidity ^0.4.18;

import "./ERC20.sol";
import "./Mintable.sol";
import "../math/SafeMath.sol";
import "../ownership/Ownable.sol";

/**
Expand All @@ -20,13 +21,16 @@ import "../ownership/Ownable.sol";
* For an example implementation see contracts/example/PreMintedCrowdsale.sol
*/
contract PseudoMinter is Mintable, Ownable {
using SafeMath for uint256;

// The token being sold
ERC20 public token;
// address which provides tokens via token.approve(...) function
address public vault;
// amount of tokens which have been pseudo minted
uint256 public tokensMinted;

function PseudoMinter(ERC20 _token, address _vault) {
function PseudoMinter(ERC20 _token, address _vault) public {
require(address(_token) != 0x0);
require(_vault != 0x0);

Expand All @@ -42,6 +46,7 @@ contract PseudoMinter is Mintable, Ownable {
* @return A boolean that indicates if the operation was successful.
*/
function mint(address _to, uint256 _amount) onlyOwner public returns (bool) {
tokensMinted.add(_amount);
token.transferFrom(vault, _to, _amount);
return true;
}
Expand All @@ -50,7 +55,7 @@ contract PseudoMinter is Mintable, Ownable {
* @dev returns amount of tokens that can be pseudo minted. Be aware that
* this does not necessarily represent the hard cap of spendable tokens!
*/
function availableSupply() public returns (uint256) {
function availableSupply() public constant returns (uint256) {
return token.allowance(vault, this);
}
}
6 changes: 3 additions & 3 deletions test/PreMintedCrowdsale.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ether from './helpers/ether'
import {advanceBlock} from './helpers/advanceToBlock'
import {increaseTimeTo, duration} from './helpers/increaseTime'
import latestTime from './helpers/latestTime'
import EVMThrow from './helpers/EVMThrow'
import EVMRevert from './helpers/EVMRevert'

const BigNumber = web3.BigNumber

Expand Down Expand Up @@ -48,11 +48,11 @@ contract('PreMintedCrowdsale', function ([_, wallet]) {

it('should reject payments outside cap', async function () {
await this.crowdsale.send(this.cap)
await this.crowdsale.send(1).should.be.rejectedWith(EVMThrow)
await this.crowdsale.send(1).should.be.rejectedWith(EVMRevert)
})

it('should reject payments that exceed cap', async function () {
await this.crowdsale.send(this.cap.plus(1)).should.be.rejectedWith(EVMThrow)
await this.crowdsale.send(this.cap.plus(1)).should.be.rejectedWith(EVMRevert)
})

})
Expand Down
8 changes: 4 additions & 4 deletions test/PseudoMinter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ether from './helpers/ether'
import EVMThrow from './helpers/EVMThrow'
import EVMRevert from './helpers/EVMRevert'

const BigNumber = web3.BigNumber

Expand Down Expand Up @@ -35,14 +35,14 @@ contract('PseudoMinter', function ([owner, tokenAddress]) {

it('should reject minting outside approved cap', async function () {
await this.pseudoMinter.mint(tokenAddress, this.cap).should.be.fulfilled
await this.pseudoMinter.mint(tokenAddress, 1).should.be.rejectedWith(EVMThrow)
await this.pseudoMinter.mint(tokenAddress, 1).should.be.rejectedWith(EVMRevert)

let amount = await this.simpleToken.balanceOf(tokenAddress)
amount.should.be.bignumber.equal(this.cap)
})

it('should reject minting that exceed approved cap', async function () {
await this.pseudoMinter.mint(tokenAddress, this.cap.plus(1)).should.be.rejectedWith(EVMThrow)
await this.pseudoMinter.mint(tokenAddress, this.cap.plus(1)).should.be.rejectedWith(EVMRevert)

let amount = await this.simpleToken.balanceOf(tokenAddress)
amount.should.be.bignumber.equal(0)
Expand All @@ -54,7 +54,7 @@ contract('PseudoMinter', function ([owner, tokenAddress]) {
let amount = await this.pseudoMinter.availableSupply.call()
amount.should.be.bignumber.equal(0)

await this.pseudoMinter.mint(tokenAddress, 1).should.be.rejectedWith(EVMThrow)
await this.pseudoMinter.mint(tokenAddress, 1).should.be.rejectedWith(EVMRevert)
})

})