Skip to content

Commit

Permalink
Merge pull request #271 from PolymathNetwork/add_dai
Browse files Browse the repository at this point in the history
Add DAI to USDTieredSTO
  • Loading branch information
adamdossa authored Sep 21, 2018
2 parents 69dbc41 + 6c404e5 commit 94edbed
Show file tree
Hide file tree
Showing 17 changed files with 911 additions and 501 deletions.
145 changes: 100 additions & 45 deletions CLI/commands/ST20Generator.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions CLI/commands/helpers/contract_addresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ module.exports = {
else
return JSON.parse(require('fs').readFileSync('./build/contracts/CappedSTOFactory.json').toString()).networks[networkId].address;
},
daiToken: async function() {
//TODO: Add a proper test DAI token here
let polymathRegistry = await getPolymathRegistry();
return await polymathRegistry.methods.getAddress("PolyToken").call();
},
usdTieredSTOFactoryAddress: async function() {
let networkId = await web3.eth.net.getId();
if (networkId == 1)
Expand Down
30 changes: 15 additions & 15 deletions CLI/commands/investor_portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async function inputSymbol(symbol) {
} else {
STSymbol = symbol;
}

if (STSymbol == "") process.exit();

STAddress = await securityTokenRegistry.methods.getSecurityTokenAddress(STSymbol).call();
Expand Down Expand Up @@ -169,8 +169,8 @@ async function investUsdTieredSTO(currency, amount) {
if (typeof amount === 'undefined') {
let investorInvestedUSD = web3.utils.fromWei(await currentSTO.methods.investorInvestedUSD(User.address).call());
let minimumInvestmentUSD = await currentSTO.methods.minimumInvestmentUSD().call();
let minimumInvestmentRaiseType = await currentSTO.methods.convertFromUSD(web3.utils.fromAscii(raiseType), minimumInvestmentUSD).call();
cost = readlineSync.question(chalk.yellow(`Enter the amount of ${raiseType} you would like to invest or press 'Enter' to exit: `), {
let minimumInvestmentRaiseType = await currentSTO.methods.convertFromUSD(web3.utils.fromAscii(raiseType), minimumInvestmentUSD).call();
cost = readlineSync.question(chalk.yellow(`Enter the amount of ${raiseType} you would like to invest or press 'Enter' to exit: `), {
limit: function(input) {
return investorInvestedUSD != 0 || input > web3.utils.fromWei(minimumInvestmentRaiseType);
},
Expand Down Expand Up @@ -229,7 +229,7 @@ async function investCappedSTO(currency, amount) {

let costWei = web3.utils.toWei(cost.toString());
if (displayRaiseType == 'POLY') {
let userBalance = await polyBalance(User.address);
let userBalance = await polyBalance(User.address);
if (parseInt(userBalance) >= parseInt(cost)) {
let allowance = await polyToken.methods.allowance(STOAddress, User.address).call();
if (allowance < costWei) {
Expand Down Expand Up @@ -279,25 +279,25 @@ async function showTokenInfo() {

async function showUserInfoForUSDTieredSTO()
{
if (await currentSTO.methods.fundRaiseType(0).call()) {
if (await currentSTO.methods.fundRaiseTypes(0).call()) {
let displayInvestorInvestedETH = web3.utils.fromWei(await currentSTO.methods.investorInvestedETH(User.address).call());
console.log(` - Invested in ETH: ${displayInvestorInvestedETH} ETH`);
}
if (await currentSTO.methods.fundRaiseType(1).call()) {
if (await currentSTO.methods.fundRaiseTypes(1).call()) {
let displayInvestorInvestedPOLY = web3.utils.fromWei(await currentSTO.methods.investorInvestedPOLY(User.address).call());
console.log(` - Invested in POLY: ${displayInvestorInvestedPOLY} POLY`);
}
let displayInvestorInvestedUSD = web3.utils.fromWei(await currentSTO.methods.investorInvestedUSD(User.address).call());
console.log(` - Invested in USD: ${displayInvestorInvestedUSD} USD`);

await generalTransferManager.methods.whitelist(User.address).call({}, function(error, result){
displayCanBuy = result.canBuyFromSTO;
});
console.log(` - Whitelisted: ${(displayCanBuy)?'YES':'NO'}`)

let displayIsUserAccredited = await currentSTO.methods.accredited(User.address).call();
console.log(` - Accredited: ${(displayIsUserAccredited)?"YES":"NO"}`)

if (!await currentSTO.methods.accredited(User.address).call()) {
let displayOverrideNonAccreditedLimitUSD = web3.utils.fromWei(await currentSTO.methods.nonAccreditedLimitUSDOverride(User.address).call())
let displayNonAccreditedLimitUSD = displayOverrideNonAccreditedLimitUSD != 0 ? displayOverrideNonAccreditedLimitUSD : web3.utils.fromWei(await currentSTO.methods.nonAccreditedLimitUSD().call());
Expand All @@ -313,15 +313,15 @@ async function showUSDTieredSTOInfo() {
let displayCurrentTier = parseInt(await currentSTO.methods.currentTier().call()) + 1;
let displayNonAccreditedLimitUSD = web3.utils.fromWei(await currentSTO.methods.nonAccreditedLimitUSD().call());
let displayMinimumInvestmentUSD = web3.utils.fromWei(await currentSTO.methods.minimumInvestmentUSD().call());
let ethRaise = await currentSTO.methods.fundRaiseType(0).call();
let polyRaise = await currentSTO.methods.fundRaiseType(1).call();
let ethRaise = await currentSTO.methods.fundRaiseTypes(0).call();
let polyRaise = await currentSTO.methods.fundRaiseTypes(1).call();
let displayTokensSold = web3.utils.fromWei(await currentSTO.methods.getTokensSold().call());
let displayInvestorCount = await currentSTO.methods.investorCount().call();
let displayIsFinalized = await currentSTO.methods.isFinalized().call();
let displayIsOpen = await currentSTO.methods.isOpen().call();
let displayTokenSymbol = await securityToken.methods.symbol().call();

let tiersLength = await currentSTO.methods.getNumberOfTiers().call();
let tiersLength = await currentSTO.methods.investorCount().call();

let displayTiers = "";
let displayMintedPerTier = "";
Expand All @@ -333,7 +333,7 @@ async function showUSDTieredSTOInfo() {
let displayMintedPerTierETH = "";
if (ethRaise) {
let mintedPerTierETH = await currentSTO.methods.mintedPerTierETH(t).call();

displayMintedPerTierETH = `
Sold for ETH: ${web3.utils.fromWei(mintedPerTierETH)} ${displayTokenSymbol}`
}
Expand Down Expand Up @@ -367,7 +367,7 @@ async function showUSDTieredSTOInfo() {
Rate: ${web3.utils.fromWei(ratePerTier, 'ether')} USD per Token`
+ displayDiscountTokens;
displayMintedPerTier = displayMintedPerTier + `
- Tokens minted in Tier ${t+1}: ${web3.utils.fromWei(mintedPerTierTotal)} ${displayTokenSymbol}`
- Tokens minted in Tier ${t+1}: ${web3.utils.fromWei(mintedPerTierTotal)} ${displayTokenSymbol}`
+ displayMintedPerTierETH
+ displayMintedPerTierPOLY;}

Expand All @@ -379,7 +379,7 @@ async function showUSDTieredSTOInfo() {
let fundsRaisedETH = web3.utils.fromWei(await currentSTO.methods.fundsRaisedETH().call());
displayFundsRaisedETH = `
ETH: ${fundsRaisedETH} ETH`;

//Only show sold for ETH if POLY raise is allowed too
if (polyRaise) {
let tokensSoldETH = web3.utils.fromWei(await currentSTO.methods.getTokensSoldForETH().call());
Expand Down Expand Up @@ -471,7 +471,7 @@ async function showCappedSTOInfo() {
let displayTokensRemaining = web3.utils.fromWei(displayCap) - web3.utils.fromWei(displayTokensSold);

let displayFundsRaised;
if (await currentSTO.methods.fundRaiseType(0).call()) {
if (await currentSTO.methods.fundRaiseTypes(0).call()) {
displayRaiseType = 'ETH';
displayFundsRaised = await currentSTO.methods.fundsRaisedETH().call();
} else {
Expand Down
40 changes: 9 additions & 31 deletions contracts/modules/STO/CappedSTO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ contract CappedSTO is ISTO, ReentrancyGuard {
uint256 _endTime,
uint256 _cap,
uint256 _rate,
uint8[] _fundRaiseTypes,
FundRaiseType[] _fundRaiseTypes,
address _fundsReceiver
)
public
Expand All @@ -74,7 +74,7 @@ contract CappedSTO is ISTO, ReentrancyGuard {
cap = _cap;
rate = _rate;
wallet = _fundsReceiver;
_configureFunding(_fundRaiseTypes);
_setFundRaiseType(_fundRaiseTypes);
}

/**
Expand Down Expand Up @@ -104,7 +104,7 @@ contract CappedSTO is ISTO, ReentrancyGuard {
}

require(!paused);
require(fundRaiseType[uint8(FundRaiseType.ETH)], "ETH should be the mode of investment");
require(fundRaiseTypes[uint8(FundRaiseType.ETH)], "ETH should be the mode of investment");

uint256 weiAmount = msg.value;
_processTx(_beneficiary, weiAmount);
Expand All @@ -119,8 +119,7 @@ contract CappedSTO is ISTO, ReentrancyGuard {
*/
function buyTokensWithPoly(uint256 _investedPOLY) public nonReentrant{
require(!paused);
require(fundRaiseType[uint8(FundRaiseType.POLY)], "POLY should be the mode of investment");
require(verifyInvestment(msg.sender, _investedPOLY), "Not valid Investment");
require(fundRaiseTypes[uint8(FundRaiseType.POLY)], "POLY should be the mode of investment");
_processTx(msg.sender, _investedPOLY);
_forwardPoly(msg.sender, wallet, _investedPOLY);
_postValidatePurchase(msg.sender, _investedPOLY);
Expand All @@ -134,27 +133,6 @@ contract CappedSTO is ISTO, ReentrancyGuard {
return totalTokensSold >= cap;
}

/**
* @notice Return ETH raised by the STO
*/
function getRaisedEther() public view returns (uint256) {
return fundsRaisedETH;
}

/**
* @notice Return POLY raised by the STO
*/
function getRaisedPOLY() public view returns (uint256) {
return fundsRaisedPOLY;
}

/**
* @notice Return the total no. of investors
*/
function getNumberInvestors() public view returns (uint256) {
return investorCount;
}

/**
* @notice Return the total no. of tokens sold
*/
Expand All @@ -179,10 +157,10 @@ contract CappedSTO is ISTO, ReentrancyGuard {
endTime,
cap,
rate,
(fundRaiseType[uint8(FundRaiseType.POLY)]) ? fundsRaisedPOLY: fundsRaisedETH,
(fundRaiseTypes[uint8(FundRaiseType.POLY)]) ? fundsRaised[uint8(FundRaiseType.POLY)]: fundsRaised[uint8(FundRaiseType.ETH)],
investorCount,
totalTokensSold,
(fundRaiseType[uint8(FundRaiseType.POLY)])
(fundRaiseTypes[uint8(FundRaiseType.POLY)])
);
}

Expand All @@ -201,10 +179,10 @@ contract CappedSTO is ISTO, ReentrancyGuard {
uint256 tokens = _getTokenAmount(_investedAmount);

// update state
if (fundRaiseType[uint8(FundRaiseType.POLY)]) {
fundsRaisedPOLY = fundsRaisedPOLY.add(_investedAmount);
if (fundRaiseTypes[uint8(FundRaiseType.POLY)]) {
fundsRaised[uint8(FundRaiseType.POLY)] = fundsRaised[uint8(FundRaiseType.POLY)].add(_investedAmount);
} else {
fundsRaisedETH = fundsRaisedETH.add(_investedAmount);
fundsRaised[uint8(FundRaiseType.ETH)] = fundsRaised[uint8(FundRaiseType.ETH)].add(_investedAmount);
}
totalTokensSold = totalTokensSold.add(tokens);

Expand Down
14 changes: 0 additions & 14 deletions contracts/modules/STO/DummySTO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,6 @@ contract DummySTO is ISTO {
emit LogGenerateTokens (_investor, _amount);
}

/**
* @notice Return ETH raised by the STO
*/
function getRaisedEther() public view returns (uint256) {
return 0;
}

/**
* @notice Return POLY raised by the STO
*/
function getRaisedPOLY() public view returns (uint256) {
return 0;
}

/**
* @notice Return the total no. of investors
*/
Expand Down
52 changes: 15 additions & 37 deletions contracts/modules/STO/ISTO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@ import "openzeppelin-solidity/contracts/math/SafeMath.sol";
contract ISTO is Module, Pausable {
using SafeMath for uint256;

enum FundRaiseType { ETH, POLY }
mapping (uint8 => bool) public fundRaiseType;
enum FundRaiseType { ETH, POLY, DAI }
mapping (uint8 => bool) public fundRaiseTypes;
mapping (uint8 => uint256) public fundsRaised;

// Start time of the STO
uint256 public startTime;
// End time of the STO
uint256 public endTime;
// Time STO was paused
uint256 public pausedTime;
// Amount of ETH funds raised
uint256 public fundsRaisedETH;
// Amount of POLY funds raised
uint256 public fundsRaisedPOLY;
// Number of individual investors
uint256 public investorCount;
// Address where ETH & POLY funds are delivered
Expand All @@ -32,7 +29,7 @@ contract ISTO is Module, Pausable {
uint256 public totalTokensSold;

// Event
event SetFunding(uint8[] _fundRaiseTypes);
event SetFundRaiseTypes(FundRaiseType[] _fundRaiseTypes);

/**
* @notice Reclaim ERC20Basic compatible tokens
Expand All @@ -47,29 +44,12 @@ contract ISTO is Module, Pausable {
}

/**
* @notice used to verify the investment, whether the investor provided an allowance to the STO or not.
* @param _beneficiary Ethereum address of the beneficiary, who intends to buy the st-20 tokens
* @param _fundsAmount Amount invested by the beneficiary
* @notice Return funds raised by the STO
*/
function verifyInvestment(address _beneficiary, uint256 _fundsAmount) public view returns(bool) {
return polyToken.allowance(_beneficiary, address(this)) >= _fundsAmount;
function getRaised(FundRaiseType _fundRaiseType) public view returns (uint256) {
return fundsRaised[uint8(_fundRaiseType)];
}

/**
* @notice Return ETH raised by the STO
*/
function getRaisedEther() public view returns (uint256);

/**
* @notice Return POLY raised by the STO
*/
function getRaisedPOLY() public view returns (uint256);

/**
* @notice Return the total no. of investors
*/
function getNumberInvestors() public view returns (uint256);

/**
* @notice Return the total no. of tokens sold
*/
Expand All @@ -90,18 +70,16 @@ contract ISTO is Module, Pausable {
super._unpause();
}

function _configureFunding(uint8[] _fundRaiseTypes) internal {
require(_fundRaiseTypes.length > 0 && _fundRaiseTypes.length < 3, "No fund raising currencies specified");
fundRaiseType[uint8(FundRaiseType.POLY)] = false;
fundRaiseType[uint8(FundRaiseType.ETH)] = false;
function _setFundRaiseType(FundRaiseType[] _fundRaiseTypes) internal {
// FundRaiseType[] parameter type ensures only valid values for _fundRaiseTypes
require(_fundRaiseTypes.length > 0, "Raise type not specified");
fundRaiseTypes[uint8(FundRaiseType.ETH)] = false;
fundRaiseTypes[uint8(FundRaiseType.POLY)] = false;
fundRaiseTypes[uint8(FundRaiseType.DAI)] = false;
for (uint8 j = 0; j < _fundRaiseTypes.length; j++) {
require(_fundRaiseTypes[j] < 2);
fundRaiseType[_fundRaiseTypes[j]] = true;
}
if (fundRaiseType[uint8(FundRaiseType.POLY)]) {
require(address(polyToken) != address(0), "Address of the polyToken should not be 0x");
fundRaiseTypes[uint8(_fundRaiseTypes[j])] = true;
}
emit SetFunding(_fundRaiseTypes);
emit SetFundRaiseTypes(_fundRaiseTypes);
}

}
18 changes: 2 additions & 16 deletions contracts/modules/STO/PreSaleSTO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,6 @@ contract PreSaleSTO is ISTO {
return bytes4(keccak256("configure(uint256)"));
}

/**
* @notice Return ETH raised by the STO
*/
function getRaisedEther() public view returns (uint256) {
return fundsRaisedETH;
}

/**
* @notice Return POLY raised by the STO
*/
function getRaisedPOLY() public view returns (uint256) {
return fundsRaisedPOLY;
}

/**
* @notice Return the total no. of investors
*/
Expand Down Expand Up @@ -93,8 +79,8 @@ contract PreSaleSTO is ISTO {
ISecurityToken(securityToken).mint(_investor, _amount);
investors[_investor] = investors[_investor].add(_amount);
investorCount = investorCount.add(1);
fundsRaisedETH = fundsRaisedETH.add(_etherContributed);
fundsRaisedPOLY = fundsRaisedPOLY.add(_polyContributed);
fundsRaised[uint8(FundRaiseType.ETH)] = fundsRaised[uint8(FundRaiseType.ETH)].add(_etherContributed);
fundsRaised[uint8(FundRaiseType.POLY)] = fundsRaised[uint8(FundRaiseType.POLY)].add(_polyContributed);
totalTokensSold = totalTokensSold.add(_amount);
emit TokensAllocated(_investor, _amount);
}
Expand Down
Loading

0 comments on commit 94edbed

Please sign in to comment.