Skip to content

Commit

Permalink
Merge pull request #437 from PolymathNetwork/multiple-stable-coins
Browse files Browse the repository at this point in the history
Multiple stable coins support in USD Tiered STO
  • Loading branch information
VictorVicente authored Dec 19, 2018
2 parents 2336d85 + 15d9dcf commit 86508fb
Show file tree
Hide file tree
Showing 24 changed files with 677 additions and 311 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ 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

## CappedSTO 2.1.0
* `rate` is now accepted as multiplied by 10^18 to allow settting higher price than 1ETH/POLY per token.
* Indivisble tokens are now supported. When trying to buy partial tokens, allowed full units of tokens will be purchased and remaining funds will be returned.

## USDTieredSTO 2.1.0
* Added `stableCoinsRaised` function that returns amount of individual stable coin raised when address of that stable coin is passed.
* Added support for multiple stable coins in USDTSTO.
* Added `buyTokensView` and `getTokensMintedByTier` to USDTSTO.
* Added `getSTODetails` to USDTSTO.
* Added an Array of Tiers that will hold data about every tier in USDTSTO.
Expand Down
4 changes: 3 additions & 1 deletion CLI/commands/ST20Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ async function executeApp(_ticker, _transferOwnership, _name, _details, _divisib
await step_transfer_ticker_ownership(_transferOwnership);
await step_token_deploy(_name, _details, _divisible);
}
await tokenManager.executeApp(tokenSymbol);
if (typeof _divisible === 'undefined') {
await tokenManager.executeApp(tokenSymbol);
}
} catch (err) {
console.log(err);
return;
Expand Down
18 changes: 9 additions & 9 deletions CLI/commands/TickerRollForward.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ let securityTokenRegistry;
let securityTokenRegistryAddress;

function Ticker(_owner, _symbol, _name) {
this.owner = _owner;
this.symbol = _symbol;
this.name = _name;
this.owner = _owner;
this.symbol = _symbol;
this.name = _name;
}

function FailedRegistration(_ticker, _error) {
Expand Down Expand Up @@ -58,11 +58,11 @@ async function startScript() {
}

async function readFile() {
var stream = fs.createReadStream("./CLI/data/ticker_data.csv");
var stream = fs.createReadStream(`${__dirname}/../data/ticker_data.csv`);

var csvStream = csv()
.on("data", function (data) {
ticker_data.push(new Ticker(data[0],data[1],data[2],data[3]));
ticker_data.push(new Ticker(data[0], data[1], data[2], data[3]));
})
.on("end", async function () {
await registerTickers();
Expand All @@ -73,12 +73,12 @@ async function readFile() {
async function registerTickers() {
// Poly approval for registration fees
let polyBalance = BigNumber(await polyToken.methods.balanceOf(Issuer.address).call());
let fee = web3.utils.fromWei(await securityTokenRegistry.methods.getTickerRegistrationFee().call());
let fee = web3.utils.fromWei(await securityTokenRegistry.methods.getTickerRegistrationFee().call());
let totalFee = BigNumber(ticker_data.length).mul(fee);

if (totalFee.gt(polyBalance)) {
console.log(chalk.red(`\n*******************************************************************************`));
console.log(chalk.red(`Not enough POLY to pay registration fee. Require ${totalFee.div(10**18).toNumber()} POLY but have ${polyBalance.div(10**18).toNumber()} POLY.`));
console.log(chalk.red(`Not enough POLY to pay registration fee. Require ${totalFee.div(10 ** 18).toNumber()} POLY but have ${polyBalance.div(10 ** 18).toNumber()} POLY.`));
console.log(chalk.red(`*******************************************************************************\n`));
process.exit(0);
} else {
Expand All @@ -100,7 +100,7 @@ async function registerTickers() {
}

// validate ticker
await securityTokenRegistry.methods.getTickerDetails(ticker_data[i].symbol).call({}, function(error, result){
await securityTokenRegistry.methods.getTickerDetails(ticker_data[i].symbol).call({}, function (error, result) {
if (result[1] != 0) {
failed_tickers.push(` ${i} is already registered`);
valid = false;
Expand Down Expand Up @@ -131,7 +131,7 @@ async function logResults() {
Successful registrations: ${registered_tickers.length}
Failed registrations: ${failed_tickers.length}
Total gas consumed: ${totalGas}
Total gas cost: ${defaultGasPrice.mul(totalGas).div(10**18)} ETH
Total gas cost: ${defaultGasPrice.mul(totalGas).div(10 ** 18)} ETH
List of failed registrations:
${failed_tickers}
Expand Down
11 changes: 7 additions & 4 deletions CLI/commands/common/common_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const Tx = require('ethereumjs-tx');
const permissionsList = require('./permissions_list');
const abis = require('../helpers/contract_abis');

async function connect(abi, address) {
function connect(abi, address) {
contractRegistry = new web3.eth.Contract(abi, address);
contractRegistry.setProvider(web3.currentProvider);
return contractRegistry
Expand All @@ -15,7 +15,7 @@ async function checkPermission(contractName, functionName, contractRegistry) {
return true
} else {
let stAddress = await contractRegistry.methods.securityToken().call();
let securityToken = await connect(abis.securityToken(), stAddress);
let securityToken = connect(abis.securityToken(), stAddress);
let stOwner = await securityToken.methods.owner().call();
if (stOwner == Issuer.address) {
return true
Expand Down Expand Up @@ -48,11 +48,11 @@ async function getGasLimit(options, action) {
}

async function checkPermissions(action) {
let contractRegistry = await connect(action._parent.options.jsonInterface, action._parent._address);
let contractRegistry = connect(action._parent.options.jsonInterface, action._parent._address);
//NOTE this is a condition to verify if the transaction comes from a module or not.
if (contractRegistry.methods.hasOwnProperty('factory')) {
let moduleAddress = await contractRegistry.methods.factory().call();
let moduleRegistry = await connect(abis.moduleFactory(), moduleAddress);
let moduleRegistry = connect(abis.moduleFactory(), moduleAddress);
let parentModule = await moduleRegistry.methods.getName().call();
let result = await checkPermission(web3.utils.hexToUtf8(parentModule), action._method.name, contractRegistry);
if (!result) {
Expand Down Expand Up @@ -153,6 +153,9 @@ module.exports = {
let filteredLogs = logs.filter(l => l.topics.includes(eventJsonInterface.signature));
return filteredLogs.map(l => web3.eth.abi.decodeLog(eventJsonInterface.inputs, l.data, l.topics.slice(1)));
},
connect: function (abi, address) {
return connect(abi, address)
},
splitIntoBatches: function (data, batchSize) {
let allBatches = [];
for (let index = 0; index < data.length; index += batchSize) {
Expand Down
2 changes: 1 addition & 1 deletion CLI/commands/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = Object.freeze({
FUND_RAISE_TYPES: {
ETH: 0,
POLY: 1,
DAI: 2
STABLE: 2
},
DEFAULT_BATCH_SIZE: 75,
ADDRESS_ZERO: '0x0000000000000000000000000000000000000000'
Expand Down
4 changes: 2 additions & 2 deletions CLI/commands/common/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ module.exports = {
console.log("Invalid remote node")
process.exit(0)
}
await httpProvider(remoteNetwork, './privKey');
await httpProvider(remoteNetwork, `${__dirname}/../../../privKey`);
} else {
await httpProvider("http://localhost:8545", './privKeyLocal');
await httpProvider("http://localhost:8545", `${__dirname}/../../../privKeyLocal`);
}
defaultGasPrice = getGasPrice(await web3.eth.net.getId());
}
Expand Down
Loading

0 comments on commit 86508fb

Please sign in to comment.