agoric 0.18.4 → 0.18.5-dev-800c2bb.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,161 @@
1
+ /* eslint-disable no-await-in-loop */
2
+ /* eslint-disable @jessie.js/no-nested-await */
3
+ // @ts-check
4
+ /* eslint-disable func-names */
5
+ /* global fetch, process */
6
+ import { Command } from 'commander';
7
+ import {
8
+ lookupOfferIdForVault,
9
+ Offers,
10
+ } from '@agoric/inter-protocol/src/clientSupport.js';
11
+ import { normalizeAddressWithOptions } from '../lib/chain.js';
12
+ import { makeRpcUtils } from '../lib/rpc.js';
13
+ import { getCurrent, outputExecuteOfferAction } from '../lib/wallet.js';
14
+
15
+ /**
16
+ * @param {import('anylogger').Logger} logger
17
+ */
18
+ export const makeVaultsCommand = logger => {
19
+ const vaults = new Command('vaults')
20
+ .description('Vault Factory commands')
21
+ .option('--home [dir]', 'agd application home directory')
22
+ .option(
23
+ '--keyring-backend <os|file|test>',
24
+ 'keyring\'s backend (os|file|test) (default "os")',
25
+ );
26
+
27
+ const normalizeAddress = literalOrName =>
28
+ normalizeAddressWithOptions(literalOrName, vaults.opts());
29
+
30
+ vaults
31
+ .command('list')
32
+ .description(
33
+ 'list vaults ever owned by the address (as path that can be followed)',
34
+ )
35
+ .requiredOption(
36
+ '--from <address>',
37
+ 'wallet address literal or name',
38
+ normalizeAddress,
39
+ )
40
+ .action(async function (opts) {
41
+ const { readLatestHead } = await makeRpcUtils({ fetch });
42
+
43
+ const current = await getCurrent(opts.from, {
44
+ readLatestHead,
45
+ });
46
+
47
+ const vaultStoragePaths = current.offerToPublicSubscriberPaths.map(
48
+ ([_offerId, pathmap]) => pathmap.vault,
49
+ );
50
+
51
+ for (const path of vaultStoragePaths) {
52
+ process.stdout.write(path);
53
+ process.stdout.write('\n');
54
+ }
55
+ });
56
+
57
+ vaults
58
+ .command('open')
59
+ .description('open a new vault')
60
+ .requiredOption('--giveCollateral <number>', 'Collateral to give', Number)
61
+ .requiredOption('--wantMinted <number>', 'Minted wants', Number)
62
+ .option('--offerId <string>', 'Offer id', String, `openVault-${Date.now()}`)
63
+ .option('--collateralBrand <string>', 'Collateral brand key', 'ATOM')
64
+ .action(async function (opts) {
65
+ logger.warn('running with options', opts);
66
+ const { agoricNames } = await makeRpcUtils({ fetch });
67
+
68
+ const offer = Offers.vaults.OpenVault(agoricNames.brand, {
69
+ giveCollateral: opts.giveCollateral,
70
+ wantMinted: opts.wantMinted,
71
+ offerId: opts.offerId,
72
+ // rename to allow CLI to be more concise
73
+ collateralBrandKey: opts.collateralBrand,
74
+ });
75
+
76
+ outputExecuteOfferAction(offer);
77
+ });
78
+
79
+ vaults
80
+ .command('adjust')
81
+ .description('adjust an existing vault')
82
+ .requiredOption(
83
+ '--from <address>',
84
+ 'wallet address literal or name',
85
+ normalizeAddress,
86
+ )
87
+ .option('--giveCollateral <number>', 'More collateral to lend', Number)
88
+ .option('--wantCollateral <number>', 'Collateral to get back', Number)
89
+ .option('--giveMinted <number>', 'Minted to give back', Number)
90
+ .option('--wantMinted <number>', 'More minted to borrow', Number)
91
+ .option(
92
+ '--offerId <string>',
93
+ 'Offer id',
94
+ String,
95
+ `adjustVault-${Date.now()}`,
96
+ )
97
+ .option('--collateralBrand <string>', 'Collateral brand key', 'ATOM')
98
+ .requiredOption('--vaultId <string>', 'Key of vault (e.g. vault1)')
99
+ .action(async function (opts) {
100
+ logger.warn('running with options', opts);
101
+ const { agoricNames, readLatestHead } = await makeRpcUtils({ fetch });
102
+
103
+ const previousOfferId = await lookupOfferIdForVault(
104
+ opts.vaultId,
105
+ getCurrent(opts.from, { readLatestHead }),
106
+ );
107
+
108
+ const offer = Offers.vaults.AdjustBalances(
109
+ agoricNames.brand,
110
+ {
111
+ giveCollateral: opts.giveCollateral,
112
+ wantCollateral: opts.wantCollateral,
113
+ giveMinted: opts.giveMinted,
114
+ wantMinted: opts.wantMinted,
115
+ offerId: opts.offerId,
116
+ // rename to allow CLI to be more concise
117
+ collateralBrandKey: opts.collateralBrand,
118
+ },
119
+ previousOfferId,
120
+ );
121
+ outputExecuteOfferAction(offer);
122
+ });
123
+
124
+ vaults
125
+ .command('close')
126
+ .description('close an existing vault')
127
+ .requiredOption(
128
+ '--from <address>',
129
+ 'wallet address literal or name',
130
+ normalizeAddress,
131
+ )
132
+ .requiredOption('--giveMinted <number>', 'Minted to give back', Number)
133
+ .requiredOption('--vaultId <string>', 'Key of vault (e.g. vault1)')
134
+ .option(
135
+ '--offerId <string>',
136
+ 'Offer id',
137
+ String,
138
+ `closeVault-${Date.now()}`,
139
+ )
140
+ .action(async function (opts) {
141
+ logger.warn('running with options', opts);
142
+ const { agoricNames, readLatestHead } = await makeRpcUtils({ fetch });
143
+
144
+ const previousOfferId = await lookupOfferIdForVault(
145
+ opts.vaultId,
146
+ getCurrent(opts.from, { readLatestHead }),
147
+ );
148
+
149
+ const offer = Offers.vaults.CloseVault(
150
+ agoricNames.brand,
151
+ {
152
+ giveMinted: opts.giveMinted,
153
+ offerId: opts.offerId,
154
+ },
155
+ previousOfferId,
156
+ );
157
+ outputExecuteOfferAction(offer);
158
+ });
159
+
160
+ return vaults;
161
+ };
@@ -8,28 +8,34 @@ import {
8
8
  makeLeader,
9
9
  makeLeaderFromRpcAddresses,
10
10
  } from '@agoric/casting';
11
- import { coalesceWalletState } from '@agoric/smart-wallet/src/utils.js';
12
11
  import { Command } from 'commander';
12
+ import fs from 'fs';
13
13
  import util from 'util';
14
+ import { execFileSync } from 'child_process';
14
15
  import { fmtRecordOfLines, summarize } from '../lib/format.js';
15
- import {
16
- boardSlottingMarshaller,
17
- makeRpcUtils,
18
- networkConfig,
19
- } from '../lib/rpc.js';
16
+ import { makeRpcUtils, networkConfig } from '../lib/rpc.js';
20
17
 
21
18
  import { makeLeaderOptions } from '../lib/casting.js';
22
19
  import {
23
20
  execSwingsetTransaction,
24
21
  fetchSwingsetParams,
25
- normalizeAddress,
22
+ normalizeAddressWithOptions,
26
23
  } from '../lib/chain.js';
27
- import { getCurrent } from '../lib/wallet.js';
24
+ import { coalesceWalletState, getCurrent } from '../lib/wallet.js';
28
25
 
29
26
  const SLEEP_SECONDS = 3;
30
27
 
31
28
  export const makeWalletCommand = async () => {
32
- const wallet = new Command('wallet').description('wallet commands');
29
+ const wallet = new Command('wallet')
30
+ .description('wallet commands')
31
+ .option('--home <dir>', 'agd application home directory')
32
+ .option(
33
+ '--keyring-backend <os|file|test>',
34
+ 'keyring\'s backend (os|file|test) (default "os")',
35
+ );
36
+
37
+ const normalizeAddress = literalOrName =>
38
+ normalizeAddressWithOptions(literalOrName, wallet.opts());
33
39
 
34
40
  wallet
35
41
  .command('provision')
@@ -40,25 +46,16 @@ export const makeWalletCommand = async () => {
40
46
  normalizeAddress,
41
47
  )
42
48
  .option('--spend', 'confirm you want to spend')
43
- .option('--home [dir]', 'agd application home directory')
44
- .option(
45
- '--keyring-backend [os|file|test]',
46
- 'keyring\'s backend (os|file|test) (default "os")',
47
- )
48
- .option('--nickname [string]', 'nickname to use', 'my-wallet')
49
- .action(function () {
50
- const {
51
- account,
52
- nickname,
53
- spend,
54
- home,
55
- keyringBackend: backend,
56
- } = this.opts();
57
- const tx = `provision-one ${nickname} ${account} SMART_WALLET`;
49
+ .option('--nickname <string>', 'nickname to use', 'my-wallet')
50
+ .action(function (opts) {
51
+ const { account, nickname, spend } = opts;
52
+ const { home, keyringBackend: backend } = wallet.opts();
53
+ const tx = ['provision-one', nickname, account, 'SMART_WALLET'];
58
54
  if (spend) {
59
- execSwingsetTransaction(tx, networkConfig, account, false, {
60
- home,
61
- backend,
55
+ execSwingsetTransaction(tx, {
56
+ from: account,
57
+ keyring: { home, backend },
58
+ ...networkConfig,
62
59
  });
63
60
  } else {
64
61
  const params = fetchSwingsetParams(networkConfig);
@@ -73,13 +70,43 @@ export const makeWalletCommand = async () => {
73
70
  .join(' + ');
74
71
  process.stdout.write(`Provisioning a wallet costs ${costs}\n`);
75
72
  process.stdout.write(`To really provision, rerun with --spend or...\n`);
76
- execSwingsetTransaction(tx, networkConfig, account, true, {
77
- home,
78
- backend,
73
+ execSwingsetTransaction(tx, {
74
+ from: account,
75
+ dryRun: true,
76
+ keyring: { home, backend },
77
+ ...networkConfig,
79
78
  });
80
79
  }
81
80
  });
82
81
 
82
+ wallet
83
+ .command('print')
84
+ .description('print out a marshalled message on disk')
85
+ .requiredOption('--file [filename]', 'path to file with prepared message')
86
+ .action(async function (opts) {
87
+ const offerStr = fs.readFileSync(opts.file).toString();
88
+
89
+ const { unserializer } = await makeRpcUtils({ fetch });
90
+
91
+ const offerObj = unserializer.fromCapData(JSON.parse(offerStr));
92
+ console.log(offerObj);
93
+ });
94
+
95
+ wallet
96
+ .command('extract-id')
97
+ .description(
98
+ 'print out the offer id of a marshalled offer messsage on disk',
99
+ )
100
+ .requiredOption('--offer [filename]', 'path to file with prepared offer')
101
+ .action(async function (opts) {
102
+ const offerStr = fs.readFileSync(opts.offer).toString();
103
+
104
+ const { unserializer } = await makeRpcUtils({ fetch });
105
+
106
+ const offerObj = unserializer.fromCapData(JSON.parse(offerStr));
107
+ console.log(offerObj.offer.id);
108
+ });
109
+
83
110
  wallet
84
111
  .command('send')
85
112
  .description('send a prepared offer')
@@ -89,28 +116,18 @@ export const makeWalletCommand = async () => {
89
116
  normalizeAddress,
90
117
  )
91
118
  .requiredOption('--offer [filename]', 'path to file with prepared offer')
92
- .option('--home [dir]', 'agd application home directory')
93
- .option(
94
- '--keyring-backend [os|file|test]',
95
- 'keyring\'s backend (os|file|test) (default "os")',
96
- )
97
119
  .option('--dry-run', 'spit out the command instead of running it')
98
- .action(function () {
99
- const {
100
- dryRun,
101
- from,
102
- offer,
103
- home,
104
- keyringBackend: backend,
105
- } = this.opts();
106
-
107
- execSwingsetTransaction(
108
- `wallet-action --allow-spend "$(cat ${offer})"`,
109
- networkConfig,
120
+ .action(function (opts) {
121
+ const { dryRun, from, offer } = opts;
122
+ const { home, keyringBackend: backend } = wallet.opts();
123
+
124
+ const offerBody = fs.readFileSync(offer).toString();
125
+ execSwingsetTransaction(['wallet-action', '--allow-spend', offerBody], {
110
126
  from,
111
127
  dryRun,
112
- { home, backend },
113
- );
128
+ keyring: { home, backend },
129
+ ...networkConfig,
130
+ });
114
131
  });
115
132
 
116
133
  wallet
@@ -130,15 +147,11 @@ export const makeWalletCommand = async () => {
130
147
  'wallet address literal or name',
131
148
  normalizeAddress,
132
149
  )
133
- .action(async function () {
134
- const opts = this.opts();
135
-
136
- const { agoricNames, fromBoard, vstorage } = await makeRpcUtils({
150
+ .action(async function (opts) {
151
+ const { agoricNames, unserializer, readLatestHead } = await makeRpcUtils({
137
152
  fetch,
138
153
  });
139
154
 
140
- const unserializer = boardSlottingMarshaller(fromBoard.convertSlotToVal);
141
-
142
155
  const leader = makeLeader(networkConfig.rpcAddrs[0]);
143
156
  const follower = await makeFollower(
144
157
  `:published.wallet.${opts.from}`,
@@ -151,9 +164,7 @@ export const makeWalletCommand = async () => {
151
164
 
152
165
  const coalesced = await coalesceWalletState(follower);
153
166
 
154
- const current = await getCurrent(opts.from, fromBoard, {
155
- vstorage,
156
- });
167
+ const current = await getCurrent(opts.from, { readLatestHead });
157
168
 
158
169
  console.warn(
159
170
  'got coalesced',
@@ -162,9 +173,24 @@ export const makeWalletCommand = async () => {
162
173
  try {
163
174
  const summary = summarize(current, coalesced, agoricNames);
164
175
  process.stdout.write(fmtRecordOfLines(summary));
176
+ process.stdout.write('\n');
165
177
  } catch (e) {
166
178
  console.error('CAUGHT HERE', e);
167
179
  }
180
+ execFileSync(
181
+ 'agd',
182
+ [
183
+ 'query',
184
+ '--node',
185
+ networkConfig.rpcAddrs[0],
186
+ 'bank',
187
+ 'balances',
188
+ opts.from,
189
+ ],
190
+ {
191
+ stdio: 'inherit',
192
+ },
193
+ );
168
194
  });
169
195
 
170
196
  wallet
@@ -175,8 +201,7 @@ export const makeWalletCommand = async () => {
175
201
  'address literal or name',
176
202
  normalizeAddress,
177
203
  )
178
- .action(async function () {
179
- const { from } = this.opts();
204
+ .action(async function ({ from }) {
180
205
  const spec = `:published.wallet.${from}`;
181
206
 
182
207
  const leaderOptions = makeLeaderOptions({
package/src/cosmos.js CHANGED
@@ -5,7 +5,7 @@ import { makePspawn, getSDKBinaries } from './helpers.js';
5
5
  const filename = new URL(import.meta.url).pathname;
6
6
 
7
7
  export default async function cosmosMain(progname, rawArgs, powers, opts) {
8
- const IMAGE = `agoric/agoric-sdk`;
8
+ const IMAGE = `ghcr.io/agoric/agoric-sdk`;
9
9
  const { anylogger, fs, spawn, process } = powers;
10
10
  const log = anylogger('agoric:cosmos');
11
11
 
@@ -58,9 +58,7 @@ export default async function cosmosMain(progname, rawArgs, powers, opts) {
58
58
  )
59
59
  .then(code => {
60
60
  if (code !== 0) {
61
- throw new Error(
62
- `Cosmos client helper build failed with code ${code}`,
63
- );
61
+ throw Error(`Cosmos client helper build failed with code ${code}`);
64
62
  }
65
63
  return pspawn(cosmosHelper, args, hopts);
66
64
  });
@@ -84,11 +82,9 @@ export default async function cosmosMain(progname, rawArgs, powers, opts) {
84
82
  );
85
83
  }
86
84
 
87
- if (popts.pull) {
88
- const exitStatus = await pspawn('docker', ['pull', IMAGE]);
89
- if (exitStatus) {
90
- return exitStatus;
91
- }
85
+ const exitStatus = await (popts.pull && pspawn('docker', ['pull', IMAGE]));
86
+ if (exitStatus) {
87
+ return exitStatus;
92
88
  }
93
89
 
94
90
  return helper(rawArgs.slice(1));