Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CappedSTO price fix #440

Merged
merged 14 commits into from
Dec 4, 2018
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.

[__2.1.0__](https://www.npmjs.com/package/polymath-core?activeTab=readme) __13-09-18__

# CappedSTO 2.0.1
* `rate` is now accepted as multiplied by 10^18 to allow settting higher price than 1ETH/POLY per token.

# USDTieredSTO 2.0.1
* Added `buyTokensView` and `getTokensMintedByTier` to USDTSTO.
* Added `getSTODetails` to USDTSTO.
Expand Down
12 changes: 8 additions & 4 deletions contracts/modules/STO/CappedSTO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ contract CappedSTO is ISTO, ReentrancyGuard {

// Determine whether users can invest on behalf of a beneficiary
bool public allowBeneficialInvestments = false;
// How many token units a buyer gets per wei / base unit of POLY
// How many token units multiplied by 10^18 a buyer gets per wei / base unit of POLY
// If rate is 10^18, buyer will get 1 token unit for every wei / base unit of poly.
uint256 public rate;
//How many tokens this STO will be allowed to sell to investors
uint256 public cap;
Expand Down Expand Up @@ -49,7 +50,7 @@ contract CappedSTO is ISTO, ReentrancyGuard {
* @param _startTime Unix timestamp at which offering get started
* @param _endTime Unix timestamp at which offering get ended
* @param _cap Maximum No. of tokens for sale
* @param _rate Token units a buyer gets per wei / base unit of POLY
* @param _rate Token units multiplied by 10^18 a buyer gets per wei / base unit of POLY

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're gonna specify this for this param, you should specify it for the cap as well (same for the function signature comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cap is not multiplied by 10^18. Consider indivisible tokens where decimals = 1. In that case, the cap will not be multiplied by 10^18. To sell max 2 tokens, I'll have to set the cap as 2 only.

cap is to be entered multiplied by 10^decimals like all values of tokens are entered in smart contracts usually.

In the comment regarding rate, the base unit of POLY means 10 to the power minus 18 POLY token. If a user wants 1 POLY = 1 Security Token even then they have to enter rate as 10^18.

To summarize: cap is multiplied according to the security token's decimals like every other number like transfer amount is. On the other hand, rate is multiplied by fixed 10^18.

That being said, you are right, I should make this clearer in the comments, thanks.

* @param _fundRaiseTypes Type of currency used to collect the funds
* @param _fundsReceiver Ethereum account address to hold the funds
*/
Expand Down Expand Up @@ -154,6 +155,7 @@ contract CappedSTO is ISTO, ReentrancyGuard {
* @return Unixtimestamp at which offering gets start.
* @return Unixtimestamp at which offering ends.
* @return Number of tokens this STO will be allowed to sell to investors.
* @return Token units multiplied by 10^18 a buyer gets per wei / base unit of POLY
* @return Amount of funds raised
* @return Number of individual investors this STO have.
* @return Amount of tokens get sold.
Expand Down Expand Up @@ -259,8 +261,10 @@ contract CappedSTO is ISTO, ReentrancyGuard {
* @param _investedAmount Value in wei to be converted into tokens
* @return Number of tokens that can be purchased with the specified _investedAmount
*/
function _getTokenAmount(uint256 _investedAmount) internal view returns (uint256) {
return _investedAmount.mul(rate);
function _getTokenAmount(uint256 _investedAmount) internal view returns (uint256 tokenAmount) {
tokenAmount = _investedAmount.mul(rate);
tokenAmount = tokenAmount.div(uint256(10) ** 18);
return tokenAmount;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions test/b_capped_sto.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ contract("CappedSTO", accounts => {
let startTime_ETH2;
let endTime_ETH2;
const cap = web3.utils.toWei("10000");
const rate = 1000;
const rate = web3.utils.toWei("1000");
const E_fundRaiseType = 0;
const address_zero = "0x0000000000000000000000000000000000000000";

Expand All @@ -97,7 +97,7 @@ contract("CappedSTO", accounts => {
let blockNo;
const P_cap = web3.utils.toWei("50000");
const P_fundRaiseType = 1;
const P_rate = 5;
const P_rate = web3.utils.toWei("5");
const cappedSTOSetupCost = web3.utils.toWei("20000", "ether");
const maxCost = cappedSTOSetupCost;
const STOParameters = ["uint256", "uint256", "uint256", "uint256", "uint8[]", "address"];
Expand Down Expand Up @@ -298,7 +298,7 @@ contract("CappedSTO", accounts => {
assert.equal(await I_CappedSTO_Array_ETH[0].startTime.call(), startTime_ETH1, "STO Configuration doesn't set as expected");
assert.equal(await I_CappedSTO_Array_ETH[0].endTime.call(), endTime_ETH1, "STO Configuration doesn't set as expected");
assert.equal((await I_CappedSTO_Array_ETH[0].cap.call()).toNumber(), cap, "STO Configuration doesn't set as expected");
assert.equal(await I_CappedSTO_Array_ETH[0].rate.call(), rate, "STO Configuration doesn't set as expected");
assert.equal((await I_CappedSTO_Array_ETH[0].rate.call()).toNumber(), rate, "STO Configuration doesn't set as expected");
assert.equal(
await I_CappedSTO_Array_ETH[0].fundRaiseTypes.call(E_fundRaiseType),
true,
Expand Down Expand Up @@ -554,7 +554,7 @@ contract("CappedSTO", accounts => {
assert.equal(await I_CappedSTO_Array_ETH[1].startTime.call(), startTime_ETH2, "STO Configuration doesn't set as expected");
assert.equal(await I_CappedSTO_Array_ETH[1].endTime.call(), endTime_ETH2, "STO Configuration doesn't set as expected");
assert.equal((await I_CappedSTO_Array_ETH[1].cap.call()).toNumber(), cap, "STO Configuration doesn't set as expected");
assert.equal(await I_CappedSTO_Array_ETH[1].rate.call(), rate, "STO Configuration doesn't set as expected");
assert.equal((await I_CappedSTO_Array_ETH[1].rate.call()).toNumber(), rate, "STO Configuration doesn't set as expected");
assert.equal(
await I_CappedSTO_Array_ETH[1].fundRaiseTypes.call(E_fundRaiseType),
true,
Expand Down Expand Up @@ -993,8 +993,8 @@ contract("CappedSTO", accounts => {

it("Should successfully invest in second STO", async () => {
const polyToInvest = 1000;
const stToReceive = polyToInvest * P_rate;

const stToReceive = (polyToInvest * P_rate)/Math.pow(10, 18);
await I_PolyToken.getTokens(polyToInvest * Math.pow(10, 18), account_investor3);

let tx = await I_GeneralTransferManager.modifyWhitelist(account_investor3, P_fromTime, P_toTime, P_expiryTime, true, {
Expand Down
2 changes: 1 addition & 1 deletion test/i_Issuance.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ contract("Issuance", accounts => {
//let startTime; // Start time will be 5000 seconds more than the latest time
//let endTime; // Add 30 days more
const cap = web3.utils.toWei("10000");
const rate = 1000;
const rate = web3.utils.toWei("1000");
const fundRaiseType = [0];
const cappedSTOSetupCost = web3.utils.toWei("20000", "ether");
const maxCost = cappedSTOSetupCost;
Expand Down
2 changes: 1 addition & 1 deletion test/o_security_token.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ contract("SecurityToken", accounts => {
let startTime;
let endTime;
const cap = web3.utils.toWei("10000");
const rate = 1000;
const rate = web3.utils.toWei("1000");
const fundRaiseType = [0];
const cappedSTOSetupCost = web3.utils.toWei("20000", "ether");
const maxCost = cappedSTOSetupCost;
Expand Down
2 changes: 1 addition & 1 deletion test/r_concurrent_STO.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ contract("Concurrent STO", accounts => {
const startTime = latestTime() + duration.days(1);
const endTime = latestTime() + duration.days(90);
const cap = web3.utils.toWei("10000");
const rate = 1000;
const rate = web3.utils.toWei("1000");
const fundRaiseType = [0];
const budget = 0;
const maxCost = STOSetupCost;
Expand Down