Skip to content

Commit

Permalink
simplify to allow user to pass in flag to deposit 1 ETH on current fe…
Browse files Browse the repository at this point in the history
…e window or next fee window (#578)
  • Loading branch information
bthaile committed Apr 10, 2019
1 parent a19d7fb commit 232cdca
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 23 deletions.
115 changes: 94 additions & 21 deletions scripts/flash/deposit-cash-to-address.js
@@ -1,11 +1,53 @@
#!/usr/bin/env node

"use strict";

var chalk = require("chalk");
var speedomatic = require("speedomatic");

function showCashBalance(augur, address, callback) {
augur.api.Cash.balanceOf({ _owner: address }, function (err, cashBalance) {
if (err) {
console.log(chalk.red(err));
return callback(err);
}
var bnCashBalance = speedomatic.bignum(cashBalance);
var totalCashBalance = speedomatic.unfix(bnCashBalance, "string");
console.log("Cash:", chalk.green(totalCashBalance));
callback(null);
});
}

function getNextFeeWindow(augur, universe, auth, callback) {
augur.api.Universe.getOrCreateNextFeeWindow({
meta: auth,
tx: { to: universe },
onSent: result => {
console.log("Deposit Cash to address:", JSON.stringify(result));
},
onSuccess: function (result) {
callback(null, result.callReturn);
},
onFailed: function (result) {
console.log("Failed Deposit:", JSON.stringify(result));
callback(result);
},
});
}

function getCurrentFeeWindow(augur, universe, callback) {
augur.api.Universe.getCurrentFeeWindow({ tx: { to: universe } }, function (err, feeWindow) {
if (err) {
console.log(chalk.red(err));
return callback(err);
}
callback(err, feeWindow);
});
}

function help() {
console.log(chalk.red("deposit-cash, will simply deposits the amount of CASH givn in ETH on the address provided"));
console.log(chalk.red("default address is next fee window"));
console.log(chalk.red("default amount is 1 ETH"));
}

function depositCashToAddress(augur, args, auth, callback) {
Expand All @@ -15,28 +57,59 @@ function depositCashToAddress(augur, args, auth, callback) {
}

var address = args.opt.address;
var amount = args.opt.amount;
var amount = args.opt.amount || 1000000000000000000;
var currentFeeWindowFlag = args.opt.current;
var nextFeeWindowFlag = args.opt.next;
var cash = augur.contracts.addresses[augur.rpc.getNetworkID()].Cash;
console.log(chalk.green.dim("address:"), chalk.green(address));
var cashPayload = {
meta: auth,
tx: { to: cash, value: augur.utils.convertBigNumberToHexString(amount) },
_to: address,
onSent: result => {
console.log(chalk.yellow.dim("Deposit Cash to address:"), chalk.yellow(JSON.stringify(result)));
console.log(chalk.yellow.dim("Waiting for reply ...."));
},
onSuccess: function (result) {
console.log(chalk.green.dim("Success Deposited:"), chalk.green(JSON.stringify(result)));
callback(null);
},
onFailed: function (result) {
console.log(chalk.red.dim("Failed Deposit:"), chalk.red(JSON.stringify(result)));
callback(result);
},
};
var universe = augur.contracts.addresses[augur.rpc.getNetworkID()].Universe;

getNextFeeWindow(augur, universe, auth, (err, nextFeeWindow) => {
if (err) {
console.log(chalk.red(err));
return callback(err);
}
getCurrentFeeWindow(augur, universe, (err, currentFeeWindow) => {
if (err) {
console.log(chalk.red(err));
return callback(err);
}
console.log("next fee window", nextFeeWindow);
console.log("current fee window", currentFeeWindow);

const fw = currentFeeWindowFlag ? currentFeeWindow : nextFeeWindow;
const nfw = nextFeeWindowFlag ? nextFeeWindow : fw;
const feeWindow = address ? address : nfw;

console.log(chalk.green.dim("address:"), chalk.green(feeWindow));
console.log(chalk.green.dim("amount:"), chalk.green(amount));

var cashPayload = {
meta: auth,
tx: { to: cash, value: augur.utils.convertBigNumberToHexString(amount) },
_to: feeWindow,
onSent: result => {
console.log(chalk.yellow.dim("Deposit Cash to address:"), chalk.yellow(JSON.stringify(result)));
console.log(chalk.yellow.dim("Waiting for reply ...."));
},
onSuccess: function (result) {
console.log(chalk.green.dim("Success Deposited:"), chalk.green(JSON.stringify(result)));
showCashBalance(augur, feeWindow, function (err) {
if (err) {
console.log(chalk.red(err));
return callback(JSON.stringify(err));
}
callback(null);
});
},
onFailed: function (result) {
console.log(chalk.red.dim("Failed Deposit:"), chalk.red(JSON.stringify(result)));
callback(result);
},
};

augur.api.Cash.depositEtherFor(cashPayload);
augur.api.Cash.depositEtherFor(cashPayload);
});
});
}

module.exports = depositCashToAddress;
6 changes: 4 additions & 2 deletions scripts/flash/index.js
Expand Up @@ -39,8 +39,10 @@ var methods = {
method: depositCashToAddress,
opts: {
help: { flag: true, short: "h", help: "This help, deposit CASH to address" },
address: { required: true, short: "t", help: "address to get the CASH" },
amount: { required: true, short: "a", help: "amount to deposit" },
address: { short: "t", help: "address to get the CASH" },
amount: { short: "a", help: "amount to deposit" },
current: { flag: true, short: "c", help: "deposit on current fee window" },
next: { flag: true, short: "n", help: "deposit on next fee window" },
},
},
"trade-complete-sets": {
Expand Down

0 comments on commit 232cdca

Please sign in to comment.