diff --git a/packages/agoric-cli/src/commands/wallet.js b/packages/agoric-cli/src/commands/wallet.js index f892972a8ae..d6bfdd1e1c5 100644 --- a/packages/agoric-cli/src/commands/wallet.js +++ b/packages/agoric-cli/src/commands/wallet.js @@ -14,13 +14,50 @@ import { makeRpcUtils, networkConfig } from '../lib/rpc.js'; import { getWalletState } from '../lib/wallet.js'; import { makeLeaderOptions } from '../lib/casting.js'; -import { execSwingsetTransaction, normalizeAddress } from '../lib/chain.js'; +import { + execSwingsetTransaction, + fetchSwingsetParams, + normalizeAddress, +} from '../lib/chain.js'; const SLEEP_SECONDS = 3; export const makeWalletCommand = async () => { const wallet = new Command('wallet').description('wallet commands'); + wallet + .command('provision') + .description('provision a Smart Wallet') + .requiredOption( + '--account [address]', + 'address literal or name', + normalizeAddress, + ) + .option('--spend', 'confirm you want to spend') + .option('--nickname [string]', 'nickname to use', 'my-wallet') + .action(function () { + const { account, nickname, spend } = this.opts(); + if (spend) { + const tx = `provision-one ${nickname} ${account} SMART_WALLET`; + execSwingsetTransaction(tx, networkConfig, account); + } else { + const params = fetchSwingsetParams(networkConfig); + assert( + params.power_flag_fees.length === 1, + 'multiple power_flag_fees not supported', + ); + const { fee: fees } = params.power_flag_fees[0]; + const nf = new Intl.NumberFormat('en-US'); + const costs = fees + .map(f => `${nf.format(Number(f.amount))} ${f.denom}`) + .join(' + '); + process.stdout.write(`Provisioning a wallet costs ${costs}\n`); + process.stdout.write( + `To really provision, repeat this command with --spend\n`, + ); + } + }); + wallet .command('send') .description('send a prepared offer') diff --git a/packages/agoric-cli/src/lib/chain.js b/packages/agoric-cli/src/lib/chain.js index 46a53a4dfc7..cfe658c70d5 100644 --- a/packages/agoric-cli/src/lib/chain.js +++ b/packages/agoric-cli/src/lib/chain.js @@ -14,7 +14,20 @@ export const normalizeAddress = literalOrName => { }; harden(normalizeAddress); -export const execSwingsetTransaction = (swingsetArgs, net, from, dryRun) => { +/** + * SECURITY: closes over process and child_process + * + * @param {string} swingsetArgs + * @param {import('./rpc').MinimalNetworkConfig} net + * @param {string} from + * @param {boolean} [dryRun] + */ +export const execSwingsetTransaction = ( + swingsetArgs, + net, + from, + dryRun = false, +) => { const { chainName, rpcAddrs } = net; const cmd = `agd --node=${rpcAddrs[0]} --chain-id=${chainName} --from=${from} tx swingset ${swingsetArgs}`; @@ -30,3 +43,12 @@ export const execSwingsetTransaction = (swingsetArgs, net, from, dryRun) => { } }; harden(execSwingsetTransaction); + +// xxx rpc should be able to query this by HTTP without shelling out +export const fetchSwingsetParams = net => { + const { chainName, rpcAddrs } = net; + const cmd = `agd --node=${rpcAddrs[0]} --chain-id=${chainName} query swingset params --output --json`; + const buffer = execSync(cmd); + return JSON.parse(buffer.toString()); +}; +harden(fetchSwingsetParams); diff --git a/packages/agoric-cli/test/agops-governance-smoketest.sh b/packages/agoric-cli/test/agops-governance-smoketest.sh index 9cb677bb708..deb300bb5e9 100644 --- a/packages/agoric-cli/test/agops-governance-smoketest.sh +++ b/packages/agoric-cli/test/agops-governance-smoketest.sh @@ -19,13 +19,11 @@ make scenario2-setup scenario2-run-chain-psm cd packages/cosmic-swingset # Fund the pool make fund-provision-pool -# Copy the agoric address from your keplr wallet or 'agd keys list', starts with 'agoric1' -KEY= # Provision your wallet -make ACCT_ADDR=$KEY AGORIC_POWERS=SMART_WALLET fund-acct provision-acct +agoric wallet provision --account # verify agoric wallet list -agoric wallet show --from \$KEY +agoric wallet show --from " exit 1 fi diff --git a/packages/agoric-cli/test/agops-perf-smoketest.sh b/packages/agoric-cli/test/agops-perf-smoketest.sh index 21bbd7f1883..1cbefa14d67 100755 --- a/packages/agoric-cli/test/agops-perf-smoketest.sh +++ b/packages/agoric-cli/test/agops-perf-smoketest.sh @@ -16,16 +16,14 @@ cd packages/cosmic-swingset make scenario2-setup scenario2-run-chain-psm # (new tab) -# Fund the pool (addr is a magic string) -make SOLO_COINS=1234000000ibc/usdc1234 ACCT_ADDR=agoric1megzytg65cyrgzs6fvzxgrcqvwwl7ugpt62346 fund-acct -# Provision your wallet cd packages/cosmic-swingset -# Copy the agoric address from your keplr wallet or 'agd keys list', starts with 'agoric1' -WALLET_ADDR= -make ACCT_ADDR=$WALLET_ADDR AGORIC_POWERS=SMART_WALLET fund-acct provision-acct +# Fund the pool +make fund-provision-pool +# Provision your wallet +agoric wallet provision --account # verify agoric wallet list -agoric wallet show --from $WALLET_ADDR +agoric wallet show --from " exit 1 fi