Skip to content

Commit 77b012a

Browse files
author
Stavros
committed
disable calculate price for non crowdsale accounts
1 parent de3c792 commit 77b012a

7 files changed

+77
-6
lines changed

contracts/GetPrePricingStrategy.sol

+14-6
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ pragma solidity ^0.4.15;
88

99
import "../token_market_net/FlatPricing.sol";
1010
import "./GetWhitelist.sol";
11-
11+
import "zeppelin-solidity/contracts/ownership/Ownable.sol";
1212

1313
/// @dev Tranche based pricing with special support for pre-ico deals.
1414
/// Implementing "first price" tranches, meaning, that if byers order is
1515
/// covering more than one tranche, the price of the lowest tranche will apply
1616
/// to the whole order.
17-
contract GetPrePricingStrategy is FlatPricing {
18-
address presaleCrowdsale;
19-
address saleCrowdsale;
17+
contract GetPrePricingStrategy is FlatPricing, Ownable {
18+
address precrowdsale;
2019
GetWhitelist public whitelist;
2120
uint public presalePrice;
2221

@@ -25,15 +24,24 @@ contract GetPrePricingStrategy is FlatPricing {
2524
whitelist = _whitelist;
2625
}
2726

28-
29-
3027
function isPresalePurchase(address purchaser) public constant returns (bool) {
3128
// we log sales in presale contract as normal sales.
3229
return false;
3330
}
3431

32+
function setPrecrowdsale(address _precrowdsale) onlyOwner {
33+
require(_precrowdsale != 0);
34+
precrowdsale = _precrowdsale;
35+
}
36+
37+
function isSane(address crowdsale) public constant returns (bool) {
38+
return precrowdsale != 0;
39+
}
40+
3541
/// @dev Calculate the current price for buy in amount.
3642
function calculatePrice(uint value, uint weiRaised, uint tokensSold, address msgSender, uint decimals) public constant returns (uint) {
43+
// only precrowdsale can call this
44+
require(msg.sender == precrowdsale);
3745
// 0 is the presale tier.
3846
whitelist.subtractAmount(msgSender, 0, value);
3947
return super.calculatePrice(value, weiRaised, tokensSold, msgSender, decimals);

contracts/GetPricingStrategy.sol

+11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import "./GetWhitelist.sol";
1616
/// to the whole order.
1717
contract GetPricingStrategy is EthTranchePricing {
1818
GetWhitelist public whitelist;
19+
address crowdsale;
1920

2021
function GetPricingStrategy(GetWhitelist _whitelist, uint[] _tranches) EthTranchePricing(_tranches) {
2122
assert(_whitelist.isGetWhiteList());
@@ -26,6 +27,15 @@ contract GetPricingStrategy is EthTranchePricing {
2627
return false;
2728
}
2829

30+
function setCrowdsale(address _crowdsale) onlyOwner {
31+
require(_crowdsale != 0);
32+
crowdsale = _crowdsale;
33+
}
34+
35+
function isSane(address _crowdsale) public constant returns (bool) {
36+
return crowdsale == _crowdsale;
37+
}
38+
2939
// needed to update the correct tier in whitelist
3040
function getCurrentTrancheIndex(uint weiRaised) public constant returns (uint) {
3141
uint i;
@@ -40,6 +50,7 @@ contract GetPricingStrategy is EthTranchePricing {
4050

4151
/// @dev Calculate the current price for buy in amount.
4252
function calculatePrice(uint value, uint weiRaised, uint tokensSold, address msgSender, uint decimals) public constant returns (uint) {
53+
require(msg.sender == crowdsale);
4354
uint amount;
4455
bool isEarly;
4556
bool isWhitelisted;

migrations/4_deploy_precrowdsale.js

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ module.exports = function(deployer) {
2323
constants.precrowdsale.END,
2424
constants.precrowdsale.PRESALE_TOKEN_CAP
2525
);
26+
}).then(() => {
27+
return GetPrePricingStrategy.deployed();
28+
}).then((pricingStrategy) => {
29+
return pricingStrategy.setPrecrowdsale(GetPreCrowdsale.address);
2630
}).then(() => {
2731
return deployer.deploy(
2832
GetPreFinalizeAgent,

migrations/5_deploy_crowdsale.js

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ module.exports = function(deployer) {
3636
constants.multisig.STABILITYADDRESS,
3737
constants.multisig.BOUNTYADDRESS
3838
);
39+
}).then(() => {
40+
return GetPricingStrategy.deployed();
41+
}).then((pricingStrategy) => {
42+
return pricingStrategy.setCrowdsale(GetCrowdsale.address);
3943
}).then(() => {
4044
return GetCrowdsale.deployed();
4145
}).then((crowdsale) => {

test/1_pricingstrategy.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const GetPricingStrategy = artifacts.require("./GetPricingStrategy.sol");
2+
const GetPrePricingStrategy = artifacts.require("./GetPrePricingStrategy.sol");
3+
const GetWhitelist = artifacts.require("./GetWhitelist.sol");
4+
const constants = require('../constants.js');
5+
6+
7+
8+
contract('GetPricingStrategy', function(accounts) {
9+
it("non crowdsale cannot call calculateprice", async function() {
10+
const pricingstrategy = await GetPricingStrategy.deployed();
11+
const whitelist = await GetWhitelist.deployed();
12+
await whitelist.setWhitelister(accounts[0], true)
13+
await whitelist.accept(accounts[0], true);
14+
15+
try{
16+
await pricingstrategy.calculatePrice(
17+
100, 0, 0, accounts[0], 18
18+
);
19+
}catch (error){
20+
assert(error.message.indexOf("invalid opcode") != -1, "Incorrect throw");
21+
return;
22+
}
23+
throw new Error("Could call calculate price");
24+
});
25+
})
26+
27+
contract('GetPrePricingStrategy', function(accounts) {
28+
it("non crowdsale cannot call calculateprice", async function() {
29+
const pricingstrategy = await GetPrePricingStrategy.deployed();
30+
const whitelist = await GetWhitelist.deployed();
31+
await whitelist.setWhitelister(accounts[0], true)
32+
await whitelist.accept(accounts[0], true);
33+
34+
try{
35+
await pricingstrategy.calculatePrice(
36+
100, 0, 0, accounts[0], 18
37+
);
38+
}catch (error){
39+
assert(error.message.indexOf("invalid opcode") != -1, "Incorrect throw");
40+
return;
41+
}
42+
throw new Error("bought more than cap");
43+
});
44+
})
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)