feat: token selector
This commit is contained in:
parent
b699623610
commit
04fbfed108
|
@ -0,0 +1,30 @@
|
|||
const StandardToken_development = require("./development/contracts/StandardToken.json");
|
||||
const StandardToken_ropsten = require("./ropsten/contracts/StandardToken.json");
|
||||
|
||||
module.exports = {
|
||||
development: [
|
||||
{
|
||||
name: "StandardToken",
|
||||
value: StandardToken_development.address
|
||||
}
|
||||
],
|
||||
ropsten: [
|
||||
{
|
||||
name: "StandardToken",
|
||||
value: StandardToken_ropsten.address
|
||||
},
|
||||
{
|
||||
name: "STT",
|
||||
value: "0xc55cf4b03948d7ebc8b9e8bad92643703811d162"
|
||||
}
|
||||
],
|
||||
rinkeby: [
|
||||
|
||||
],
|
||||
mainnet: [
|
||||
{
|
||||
name: "SNT",
|
||||
value: "0x744d70fdbe2ba4cf95131626614a1763df805b9e"
|
||||
}
|
||||
]
|
||||
};
|
|
@ -38,10 +38,6 @@ class Actions {
|
|||
this.accounts = accounts || [];
|
||||
}
|
||||
|
||||
getWeb3() {
|
||||
return this.web3;
|
||||
}
|
||||
|
||||
connect(options, cb) {
|
||||
const url = options.url;
|
||||
|
||||
|
@ -193,6 +189,7 @@ class Actions {
|
|||
async mintToken(params) {
|
||||
let text = `await StandardToken.methods.mint(\"${params.account}\", web3.utils.toWei(\"${params.amount}\", \"ether\")).send({gas: 2000000, gasPrice: web3.utils.toWei(${params.gasPrice}, "gwei")})`
|
||||
return doAction(text, async () => {
|
||||
this.contracts.StandardToken.options.address = params.tokenAddress;
|
||||
const toSend = this.contracts.StandardToken.methods.mint(params.account, this.web3.utils.toWei(params.amount.toString(), "ether"));
|
||||
const receipt = await this.execute(toSend, this.web3.eth.defaultAccount, this.chain, params.gasPrice);
|
||||
console.dir("txHash: " + receipt.transactionHash);
|
||||
|
@ -200,8 +197,9 @@ class Actions {
|
|||
}
|
||||
|
||||
async approveToken(params) {
|
||||
let text = `await StandardToken.methods.approve(\"${this.contracts.LiquidPledging.options.address}\", web3.utils.toWei(\"${params.amount}\", \"ether\")).send({gas: 2000000, gasPrice: web3.utils.toWei(${params.gasPrice}, "gwei")})`
|
||||
let text = `await ERC20.methods.approve(\"${this.contracts.LiquidPledging.options.address}\", web3.utils.toWei(\"${params.amount}\", \"ether\")).send({gas: 2000000, gasPrice: web3.utils.toWei(${params.gasPrice}, "gwei")})`
|
||||
return doAction(text, async () => {
|
||||
this.contracts.StandardToken.options.address = params.tokenAddress;
|
||||
const toSend = this.contracts.StandardToken.methods.approve(this.contracts.LiquidPledging.options.address, this.web3.utils.toWei(params.amount.toString(), "ether"));
|
||||
const receipt = await this.execute(toSend, this.web3.eth.defaultAccount, this.chain, params.gasPrice);
|
||||
console.dir("txHash: " + receipt.transactionHash);
|
||||
|
|
10
src/cmd.js
10
src/cmd.js
|
@ -1,12 +1,14 @@
|
|||
var inquirer = require('inquirer');
|
||||
const menus = require('./menus.js');
|
||||
const {getGasPrice} = require('./trx-utils');
|
||||
const tokenSummary = require("../chains/tokens");
|
||||
|
||||
function mainMenu(actions) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let action = (await menus.main()).action
|
||||
let subAction;
|
||||
let gasPrice = await getGasPrice(actions.getWeb3());
|
||||
let gasPrice = await getGasPrice(actions.web3Object());
|
||||
let tokens = tokenSummary[actions.chain];
|
||||
|
||||
if (action === 'Projects') {
|
||||
subAction = (await menus.projects()).action
|
||||
|
@ -26,7 +28,7 @@ function mainMenu(actions) {
|
|||
}
|
||||
|
||||
if (subAction === 'Fund a Project') {
|
||||
let params = (await menus.donate(gasPrice)())
|
||||
let params = (await menus.donate(gasPrice, tokens)())
|
||||
await actions.donate(params);
|
||||
}
|
||||
} else if(action === 'Pledges') {
|
||||
|
@ -53,10 +55,10 @@ function mainMenu(actions) {
|
|||
subAction = (await menus.tokens()).action
|
||||
|
||||
if (subAction === 'Mint') {
|
||||
let params = (await menus.mintToken(gasPrice)(actions.web3Object().eth.defaultAccount))
|
||||
let params = (await menus.mintToken(gasPrice, tokens)(actions.web3Object().eth.defaultAccount))
|
||||
await actions.mintToken(params);
|
||||
} if (subAction === 'Approve') {
|
||||
let params = (await menus.approveToken(gasPrice)())
|
||||
let params = (await menus.approveToken(gasPrice, tokens)())
|
||||
await actions.approveToken(params);
|
||||
}
|
||||
} else if (action === 'Exit') {
|
||||
|
|
33
src/menus.js
33
src/menus.js
|
@ -261,17 +261,14 @@ const menus = {
|
|||
])
|
||||
},
|
||||
|
||||
mintToken: gasPrice => async function(defaultAccount) {
|
||||
mintToken: (gasPrice, tokens) => async function(defaultAccount) {
|
||||
console.dir("note: If the transaction fails it likely means this account cannot mint the token (e.g not the owner)");
|
||||
return inquirer.prompt([
|
||||
{
|
||||
type: 'input',
|
||||
type: 'list',
|
||||
name: 'tokenAddress',
|
||||
message: 'What is the token address?',
|
||||
filter: String,
|
||||
validate: function(value) {
|
||||
return value.indexOf("0x") === 0;
|
||||
}
|
||||
message: 'Token?',
|
||||
choices: tokens
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
|
@ -297,16 +294,13 @@ const menus = {
|
|||
])
|
||||
},
|
||||
|
||||
approveToken: gasPrice => async function(lpAddress) {
|
||||
approveToken: (gasPrice, tokens) => async function(lpAddress) {
|
||||
return inquirer.prompt([
|
||||
{
|
||||
type: 'input',
|
||||
type: 'list',
|
||||
name: 'tokenAddress',
|
||||
message: 'What is the token address?',
|
||||
filter: String,
|
||||
validate: function(value) {
|
||||
return value.indexOf("0x") === 0;
|
||||
}
|
||||
message: 'Token?',
|
||||
choices: tokens
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
|
@ -337,7 +331,7 @@ const menus = {
|
|||
])
|
||||
},
|
||||
|
||||
donate: gasPrice => async function(lpAddress) {
|
||||
donate: (gasPrice, tokens) => async function(lpAddress) {
|
||||
console.dir("note: don't forget to approve the token to be withdrawn by the LF address");
|
||||
return inquirer.prompt([
|
||||
{
|
||||
|
@ -353,13 +347,10 @@ const menus = {
|
|||
filter: Number
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
type: 'list',
|
||||
name: 'tokenAddress',
|
||||
message: 'What is the token address?',
|
||||
filter: String,
|
||||
validate: function(value) {
|
||||
return value.indexOf("0x") === 0;
|
||||
}
|
||||
message: 'Token?',
|
||||
choices: tokens
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
|
|
Loading…
Reference in New Issue