Skip to content

Commit

Permalink
Merge pull request #278 from PolymathNetwork/add_dai
Browse files Browse the repository at this point in the history
Add usdToken support to CLI
  • Loading branch information
pabloruiz55 committed Sep 26, 2018
2 parents b955fa2 + 97c1152 commit 8fcaa4c
Show file tree
Hide file tree
Showing 6 changed files with 435 additions and 450 deletions.
300 changes: 125 additions & 175 deletions CLI/commands/ST20Generator.js

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion CLI/commands/faucet.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var chalk = require('chalk');
////////////////////////
// App flow
let polyToken;
let usdToken;

async function executeApp(beneficiary, amount, remoteNetwork) {
await global.initialize(remoteNetwork);
Expand All @@ -29,6 +30,10 @@ async function setup(){
let polytokenABI = abis.polyToken();
polyToken = new web3.eth.Contract(polytokenABI, polytokenAddress);
polyToken.setProvider(web3.currentProvider);

let usdTokenAddress = await contracts.usdToken();
usdToken = new web3.eth.Contract(polytokenABI, usdTokenAddress);
usdToken.setProvider(web3.currentProvider);
} catch (err) {
console.log(err)
console.log('\x1b[31m%s\x1b[0m',"There was a problem getting the contracts. Make sure they are deployed to the selected network.");
Expand All @@ -41,7 +46,8 @@ async function send_poly(beneficiary, amount) {
console.log(chalk.blue(`Hello user you have '${(new BigNumber(issuerBalance).dividedBy(new BigNumber(10).pow(18))).toNumber()} POLY'\n`))

if (typeof beneficiary === 'undefined' && typeof amount === 'undefined') {
let options = ['250 POLY for ticker registration','500 POLY for token launch + ticker reg', '20K POLY for CappedSTO Module', '20.5K POLY for Ticker + Token + CappedSTO', '100.5K POLY for Ticker + Token + USDTieredSTO','As many POLY as you want'];
let options = ['250 POLY for ticker registration','500 POLY for token launch + ticker reg', '20K POLY for CappedSTO Module',
'20.5K POLY for Ticker + Token + CappedSTO', '100.5K POLY for Ticker + Token + USDTieredSTO','As many POLY as you want', '10K USD Tokens'];
index = readlineSync.keyInSelect(options, 'What do you want to do?');
console.log("Selected:", index != -1 ? options[index] : 'Cancel');
switch (index) {
Expand Down Expand Up @@ -69,6 +75,16 @@ async function send_poly(beneficiary, amount) {
beneficiary = readlineSync.question(`Enter beneficiary of transfer ('${Issuer.address}'): `);
amount = readlineSync.questionInt(`Enter the no. of POLY Tokens: `).toString();
break;
case 6:
beneficiary = readlineSync.question(`Enter beneficiary 10K USD Tokens ('${Issuer.address}'): `);
if (beneficiary == "") beneficiary = Issuer.address;
let getTokensAction = usdToken.methods.getTokens(web3.utils.toWei('10000'), beneficiary);
await common.sendTransaction(Issuer, getTokensAction, defaultGasPrice);
let balance = await usdToken.methods.balanceOf(beneficiary).call();
let balanceInPoly = new BigNumber(balance).dividedBy(new BigNumber(10).pow(18));
console.log(chalk.green(`Congratulations! balance of ${beneficiary} address is ${balanceInPoly.toNumber()} USD Tokens`));
process.exit(0);
break;
case -1:
process.exit(0);
}
Expand Down
5 changes: 5 additions & 0 deletions CLI/commands/helpers/contract_abis.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ let polymathRegistryABI;
let securityTokenRegistryABI;
let featureRegistryABI;
let securityTokenABI;
let stoInterfaceABI;
let cappedSTOABI;
let usdTieredSTOABI;
let generalTransferManagerABI;
Expand All @@ -16,6 +17,7 @@ try {
securityTokenRegistryABI = JSON.parse(require('fs').readFileSync('./build/contracts/SecurityTokenRegistry.json').toString()).abi;
featureRegistryABI = JSON.parse(require('fs').readFileSync('./build/contracts/FeatureRegistry.json').toString()).abi;
securityTokenABI = JSON.parse(require('fs').readFileSync('./build/contracts/SecurityToken.json').toString()).abi;
stoInterfaceABI = JSON.parse(require('fs').readFileSync('./build/contracts/ISTO.json').toString()).abi;
cappedSTOABI = JSON.parse(require('fs').readFileSync('./build/contracts/CappedSTO.json').toString()).abi;
usdTieredSTOABI = JSON.parse(require('fs').readFileSync('./build/contracts/USDTieredSTO.json').toString()).abi;
generalTransferManagerABI = JSON.parse(require('fs').readFileSync('./build/contracts/GeneralTransferManager.json').toString()).abi;
Expand All @@ -42,6 +44,9 @@ module.exports = {
securityToken: function () {
return securityTokenABI;
},
stoInterface: function () {
return stoInterfaceABI;
},
cappedSTO: function () {
return cappedSTOABI;
},
Expand Down
9 changes: 9 additions & 0 deletions CLI/commands/helpers/contract_addresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ module.exports = {
let polymathRegistry = await getPolymathRegistry();
return await polymathRegistry.methods.getAddress("PolyToken").call();
},
usdToken: async function() {
let networkId = await web3.eth.net.getId();
if (networkId == 1)
return "0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359";
else if (networkId == 42)
return "0xc4375b7de8af5a38a93548eb8453a498222c4ff2";
else
return JSON.parse(require('fs').readFileSync('./build/contracts/PolyTokenFaucet.json').toString()).networks[networkId].address;
},
cappedSTOFactoryAddress: async function() {
let networkId = await web3.eth.net.getId();
if (networkId == 1)
Expand Down
Loading

0 comments on commit 8fcaa4c

Please sign in to comment.