agoric 0.22.0-upgrade-14-dev-c8f9e7b.0 → 0.22.0-upgrade-16-dev-07b0130.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.
package/src/lib/chain.js CHANGED
@@ -36,8 +36,9 @@ harden(normalizeAddressWithOptions);
36
36
 
37
37
  /**
38
38
  * @param {ReadonlyArray<string>} swingsetArgs
39
- * @param {import('./rpc').MinimalNetworkConfig & {
39
+ * @param {import('./rpc.js').MinimalNetworkConfig & {
40
40
  * from: string,
41
+ * fees?: string,
41
42
  * dryRun?: boolean,
42
43
  * verbose?: boolean,
43
44
  * keyring?: {home?: string, backend: string}
@@ -48,6 +49,7 @@ harden(normalizeAddressWithOptions);
48
49
  export const execSwingsetTransaction = (swingsetArgs, opts) => {
49
50
  const {
50
51
  from,
52
+ fees,
51
53
  dryRun = false,
52
54
  verbose = true,
53
55
  keyring = undefined,
@@ -60,9 +62,11 @@ export const execSwingsetTransaction = (swingsetArgs, opts) => {
60
62
  const backendOpt = keyring?.backend
61
63
  ? [`--keyring-backend=${keyring.backend}`]
62
64
  : [];
65
+ const feeOpt = fees ? ['--fees', fees] : [];
63
66
  const cmd = [`--node=${rpcAddrs[0]}`, `--chain-id=${chainName}`].concat(
64
67
  homeOpt,
65
68
  backendOpt,
69
+ feeOpt,
66
70
  [`--from=${from}`, 'tx', 'swingset'],
67
71
  swingsetArgs,
68
72
  );
@@ -75,14 +79,26 @@ export const execSwingsetTransaction = (swingsetArgs, opts) => {
75
79
  } else {
76
80
  const yesCmd = cmd.concat(['--yes']);
77
81
  if (verbose) console.log('Executing ', yesCmd);
78
- return execFileSync(agdBinary, yesCmd, { encoding: 'utf-8' });
82
+ const out = execFileSync(agdBinary, yesCmd, { encoding: 'utf-8' });
83
+
84
+ // agd puts this diagnostic on stdout rather than stderr :-/
85
+ // "Default sign-mode 'direct' not supported by Ledger, using sign-mode 'amino-json'.
86
+ if (out.startsWith('Default sign-mode')) {
87
+ const stripDiagnostic = out.replace(/^Default[^\n]+\n/, '');
88
+ return stripDiagnostic;
89
+ }
90
+ return out;
79
91
  }
80
92
  };
81
93
  harden(execSwingsetTransaction);
82
94
 
83
- // xxx rpc should be able to query this by HTTP without shelling out
95
+ /**
96
+ *
97
+ * @param {import('./rpc.js').MinimalNetworkConfig} net
98
+ */
99
+ // TODO fetch by HTTP instead of shelling out https://github.com/Agoric/agoric-sdk/issues/9200
84
100
  export const fetchSwingsetParams = net => {
85
- const { chainName, rpcAddrs, execFileSync = execFileSyncAmbient } = net;
101
+ const { chainName, rpcAddrs } = net;
86
102
  const cmd = [
87
103
  `--node=${rpcAddrs[0]}`,
88
104
  `--chain-id=${chainName}`,
@@ -90,15 +106,15 @@ export const fetchSwingsetParams = net => {
90
106
  'swingset',
91
107
  'params',
92
108
  '--output',
93
- '--json',
109
+ 'json',
94
110
  ];
95
- const buffer = execFileSync(agdBinary, cmd);
111
+ const buffer = execFileSyncAmbient(agdBinary, cmd);
96
112
  return JSON.parse(buffer.toString());
97
113
  };
98
114
  harden(fetchSwingsetParams);
99
115
 
100
116
  /**
101
- * @param {import('./rpc').MinimalNetworkConfig & {
117
+ * @param {import('./rpc.js').MinimalNetworkConfig & {
102
118
  * execFileSync: typeof import('child_process').execFileSync,
103
119
  * delay: (ms: number) => Promise<void>,
104
120
  * period?: number,
@@ -122,7 +138,6 @@ export const pollBlocks = opts => async lookup => {
122
138
  } = status;
123
139
  try {
124
140
  // see await null above
125
- // eslint-disable-next-line @jessie.js/no-nested-await, no-await-in-loop
126
141
  const result = await lookup({ time, height });
127
142
  return result;
128
143
  } catch (_err) {
@@ -132,7 +147,6 @@ export const pollBlocks = opts => async lookup => {
132
147
  height,
133
148
  'retrying...',
134
149
  );
135
- // eslint-disable-next-line @jessie.js/no-nested-await, no-await-in-loop
136
150
  await delay(period);
137
151
  }
138
152
  }
@@ -140,7 +154,7 @@ export const pollBlocks = opts => async lookup => {
140
154
 
141
155
  /**
142
156
  * @param {string} txhash
143
- * @param {import('./rpc').MinimalNetworkConfig & {
157
+ * @param {import('./rpc.js').MinimalNetworkConfig & {
144
158
  * execFileSync: typeof import('child_process').execFileSync,
145
159
  * delay: (ms: number) => Promise<void>,
146
160
  * period?: number,
package/src/lib/format.js CHANGED
@@ -1,12 +1,9 @@
1
1
  // @ts-check
2
- import { makeBoardRemote } from '@agoric/vats/tools/board-utils.js';
3
- // eslint-disable-next-line no-unused-vars -- typeof below
4
- import { makeAgoricNames } from './rpc.js';
5
2
 
6
- // ambient types
7
- import '@agoric/ertp/src/types-ambient.js';
3
+ import { makeBoardRemote } from '@agoric/vats/tools/board-utils.js';
8
4
 
9
- /** @typedef {import('@agoric/vats/tools/board-utils.js').BoardRemote} BoardRemote */
5
+ /** @import {BoardRemote} from '@agoric/vats/tools/board-utils.js' */
6
+ /** @import {VBankAssetDetail} from '@agoric/vats/tools/board-utils.js'; */
10
7
 
11
8
  /**
12
9
  * Like @endo/nat but coerces
@@ -30,21 +27,18 @@ export const Natural = str => {
30
27
  */
31
28
  export const bigintReplacer = (k, v) => (typeof v === 'bigint' ? `${v}` : v);
32
29
 
33
- /** @type {import('@agoric/vats/tools/board-utils.js').VBankAssetDetail} */
30
+ /** @type {Partial<VBankAssetDetail>} */
34
31
  // eslint-disable-next-line no-unused-vars
35
32
  const exampleAsset = {
36
- // @ts-expect-error cast
37
33
  brand: makeBoardRemote({ boardId: 'board0425', iface: 'Alleged: BLD brand' }),
38
34
  displayInfo: { assetKind: 'nat', decimalPlaces: 6 },
39
- // @ts-expect-error cast
40
35
  issuer: makeBoardRemote({ boardId: null, iface: undefined }),
41
- petname: 'Agoric staking token',
36
+ proposedName: 'Agoric staking token',
42
37
  };
43
- /** @typedef {import('@agoric/vats/tools/board-utils.js').VBankAssetDetail } AssetDescriptor */
44
38
 
45
39
  /**
46
- * @param {AssetDescriptor[]} assets
47
- * @returns {(a: Amount & { brand: BoardRemote }) => [string, number | any[]]}
40
+ * @param {VBankAssetDetail[]} assets
41
+ * @returns {(a: Amount & { brand: BoardRemote }) => [string | null, number | any[]]}
48
42
  */
49
43
  export const makeAmountFormatter = assets => amt => {
50
44
  const { brand, value } = amt;
@@ -60,7 +54,9 @@ export const makeAmountFormatter = assets => amt => {
60
54
  return [issuerName, Number(value) / 10 ** decimalPlaces];
61
55
  case 'set':
62
56
  assert(Array.isArray(value));
57
+ // @ts-expect-error narrowed
63
58
  if (value[0]?.handle?.iface?.includes('InvitationHandle')) {
59
+ // @ts-expect-error narrowed
64
60
  return [issuerName, value.map(v => v.description)];
65
61
  }
66
62
  return [issuerName, value];
@@ -94,8 +90,8 @@ export const asBoardRemote = x => {
94
90
  /**
95
91
  * Summarize the balances array as user-facing informative tuples
96
92
  *
97
- * @param {import('@agoric/smart-wallet/src/smartWallet').CurrentWalletRecord['purses']} purses
98
- * @param {AssetDescriptor[]} assets
93
+ * @param {import('@agoric/smart-wallet/src/smartWallet.js').CurrentWalletRecord['purses']} purses
94
+ * @param {VBankAssetDetail[]} assets
99
95
  */
100
96
  export const purseBalanceTuples = (purses, assets) => {
101
97
  const fmt = makeAmountFormatter(assets);
@@ -122,7 +118,7 @@ export const fmtRecordOfLines = record => {
122
118
  * Summarize the offerStatuses of the state as user-facing informative tuples
123
119
  *
124
120
  * @param {import('@agoric/smart-wallet/src/utils.js').CoalescedWalletState} state
125
- * @param {Awaited<ReturnType<typeof makeAgoricNames>>} agoricNames
121
+ * @param {import('@agoric/vats/tools/board-utils.js').AgoricNamesRemotes} agoricNames
126
122
  */
127
123
  export const offerStatusTuples = (state, agoricNames) => {
128
124
  const { offerStatuses } = state;
@@ -177,9 +173,9 @@ export const offerStatusTuples = (state, agoricNames) => {
177
173
  };
178
174
 
179
175
  /**
180
- * @param {import('@agoric/smart-wallet/src/smartWallet').CurrentWalletRecord} current
176
+ * @param {import('@agoric/smart-wallet/src/smartWallet.js').CurrentWalletRecord} current
181
177
  * @param {ReturnType<import('@agoric/smart-wallet/src/utils.js').makeWalletStateCoalescer>['state']} coalesced
182
- * @param {Awaited<ReturnType<typeof makeAgoricNames>>} agoricNames
178
+ * @param {import('@agoric/vats/tools/board-utils.js').AgoricNamesRemotes} agoricNames
183
179
  */
184
180
  export const summarize = (current, coalesced, agoricNames) => {
185
181
  return {
package/src/lib/rpc.js CHANGED
@@ -1,5 +1,4 @@
1
1
  // @ts-check
2
- /* eslint-disable @jessie.js/no-nested-await */
3
2
  /* global Buffer, fetch, process */
4
3
 
5
4
  import { NonNullish } from '@agoric/assert';
@@ -50,7 +49,8 @@ export const getNetworkConfig = async env => {
50
49
  };
51
50
 
52
51
  /** @type {MinimalNetworkConfig} */
53
- export const networkConfig = await getNetworkConfig(process.env);
52
+ const networkConfig = await getNetworkConfig(process.env);
53
+ export { networkConfig };
54
54
  // console.warn('networkConfig', networkConfig);
55
55
 
56
56
  /**
@@ -136,11 +136,11 @@ export const makeVStorage = (powers, config = networkConfig) => {
136
136
  const parts = [];
137
137
  // undefined the first iteration, to query at the highest
138
138
  let blockHeight;
139
+ await null;
139
140
  do {
140
141
  // console.debug('READING', { blockHeight });
141
142
  let values;
142
143
  try {
143
- // eslint-disable-next-line no-await-in-loop
144
144
  ({ blockHeight, values } = await this.readAt(
145
145
  path,
146
146
  blockHeight && Number(blockHeight) - 1,
@@ -148,12 +148,13 @@ export const makeVStorage = (powers, config = networkConfig) => {
148
148
  // console.debug('readAt returned', { blockHeight });
149
149
  } catch (err) {
150
150
  if (
151
- // CosmosSDK ErrNotFound; there is no data at the path
152
- (err.codespace === 'sdk' && err.code === 38) ||
153
- // CosmosSDK ErrUnknownRequest; misrepresentation of the same until
154
- // https://github.com/Agoric/agoric-sdk/commit/dafc7c1708977aaa55e245dc09a73859cf1df192
155
- // TODO remove after upgrade-12
156
- err.message.match(/unknown request/)
151
+ // CosmosSDK ErrInvalidRequest with particular message text;
152
+ // misrepresentation of pruned data
153
+ // TODO replace after incorporating a fix to
154
+ // https://github.com/cosmos/cosmos-sdk/issues/19992
155
+ err.codespace === 'sdk' &&
156
+ err.code === 18 &&
157
+ err.message.match(/pruned/)
157
158
  ) {
158
159
  // console.error(err);
159
160
  break;
@@ -253,6 +254,7 @@ export const makeAgoricNames = async (ctx, vstorage) => {
253
254
  * @param {MinimalNetworkConfig} config
254
255
  */
255
256
  export const makeRpcUtils = async ({ fetch }, config = networkConfig) => {
257
+ await null;
256
258
  try {
257
259
  const vstorage = makeVStorage({ fetch }, config);
258
260
  const fromBoard = makeFromBoard();
package/src/lib/wallet.js CHANGED
@@ -6,8 +6,8 @@ import { makeWalletStateCoalescer } from '@agoric/smart-wallet/src/utils.js';
6
6
  import { execSwingsetTransaction, pollBlocks, pollTx } from './chain.js';
7
7
  import { boardSlottingMarshaller, makeRpcUtils } from './rpc.js';
8
8
 
9
- /** @typedef {import('@agoric/smart-wallet/src/smartWallet.js').CurrentWalletRecord} CurrentWalletRecord */
10
- /** @typedef {import('@agoric/vats/tools/board-utils.js').AgoricNamesRemotes} AgoricNamesRemotes */
9
+ /** @import {CurrentWalletRecord} from '@agoric/smart-wallet/src/smartWallet.js' */
10
+ /** @import {AgoricNamesRemotes} from '@agoric/vats/tools/board-utils.js' */
11
11
 
12
12
  const { Fail } = assert;
13
13
  const marshaller = boardSlottingMarshaller();
@@ -23,13 +23,13 @@ const emptyCurrentRecord = {
23
23
  /**
24
24
  * @param {string} addr
25
25
  * @param {Pick<import('./rpc.js').RpcUtils, 'readLatestHead'>} io
26
- * @returns {Promise<import('@agoric/smart-wallet/src/smartWallet').CurrentWalletRecord>}
26
+ * @returns {Promise<import('@agoric/smart-wallet/src/smartWallet.js').CurrentWalletRecord>}
27
27
  */
28
28
  export const getCurrent = async (addr, { readLatestHead }) => {
29
29
  // Partial because older writes may not have had all properties
30
30
  // NB: assumes changes are only additions
31
31
  let current =
32
- /** @type {Partial<import('@agoric/smart-wallet/src/smartWallet').CurrentWalletRecord> | undefined} */ (
32
+ /** @type {Partial<import('@agoric/smart-wallet/src/smartWallet.js').CurrentWalletRecord> | undefined} */ (
33
33
  await readLatestHead(`published.wallet.${addr}.current`)
34
34
  );
35
35
  if (current === undefined) {
@@ -58,7 +58,7 @@ export const getCurrent = async (addr, { readLatestHead }) => {
58
58
  /**
59
59
  * @param {string} addr
60
60
  * @param {Pick<import('./rpc.js').RpcUtils, 'readLatestHead'>} io
61
- * @returns {Promise<import('@agoric/smart-wallet/src/smartWallet').UpdateRecord>}
61
+ * @returns {Promise<import('@agoric/smart-wallet/src/smartWallet.js').UpdateRecord>}
62
62
  */
63
63
  export const getLastUpdate = (addr, { readLatestHead }) => {
64
64
  // @ts-expect-error cast
@@ -66,7 +66,7 @@ export const getLastUpdate = (addr, { readLatestHead }) => {
66
66
  };
67
67
 
68
68
  /**
69
- * @param {import('@agoric/smart-wallet/src/smartWallet').BridgeAction} bridgeAction
69
+ * @param {import('@agoric/smart-wallet/src/smartWallet.js').BridgeAction} bridgeAction
70
70
  * @param {Pick<import('stream').Writable,'write'>} [stdout]
71
71
  */
72
72
  export const outputAction = (bridgeAction, stdout = process.stdout) => {
@@ -75,11 +75,11 @@ export const outputAction = (bridgeAction, stdout = process.stdout) => {
75
75
  stdout.write('\n');
76
76
  };
77
77
 
78
- const sendHint =
78
+ export const sendHint =
79
79
  'Now use `agoric wallet send ...` to sign and broadcast the offer.\n';
80
80
 
81
81
  /**
82
- * @param {import('@agoric/smart-wallet/src/smartWallet').BridgeAction} bridgeAction
82
+ * @param {import('@agoric/smart-wallet/src/smartWallet.js').BridgeAction} bridgeAction
83
83
  * @param {{
84
84
  * stdout: Pick<import('stream').Writable,'write'>,
85
85
  * stderr: Pick<import('stream').Writable,'write'>,
@@ -93,19 +93,25 @@ export const outputActionAndHint = (bridgeAction, { stdout, stderr }) => {
93
93
  /**
94
94
  * @param {import('@agoric/smart-wallet/src/offers.js').OfferSpec} offer
95
95
  * @param {Pick<import('stream').Writable,'write'>} [stdout]
96
+ * @param {Pick<import('stream').Writable,'write'>} [stderr]
96
97
  */
97
- export const outputExecuteOfferAction = (offer, stdout = process.stdout) => {
98
- /** @type {import('@agoric/smart-wallet/src/smartWallet').BridgeAction} */
98
+ export const outputExecuteOfferAction = (
99
+ offer,
100
+ stdout = process.stdout,
101
+ stderr = process.stderr,
102
+ ) => {
103
+ /** @type {import('@agoric/smart-wallet/src/smartWallet.js').BridgeAction} */
99
104
  const spendAction = {
100
105
  method: 'executeOffer',
101
106
  offer,
102
107
  };
103
108
  outputAction(spendAction, stdout);
109
+ stderr.write(sendHint);
104
110
  };
105
111
 
106
112
  /**
107
113
  * @deprecated use `.current` node for current state
108
- * @param {import('@agoric/casting').Follower<import('@agoric/casting').ValueFollowerElement<import('@agoric/smart-wallet/src/smartWallet').UpdateRecord>>} follower
114
+ * @param {import('@agoric/casting').Follower<import('@agoric/casting').ValueFollowerElement<import('@agoric/smart-wallet/src/smartWallet.js').UpdateRecord>>} follower
109
115
  * @param {Brand<'set'>} [invitationBrand]
110
116
  */
111
117
  export const coalesceWalletState = async (follower, invitationBrand) => {
@@ -135,9 +141,10 @@ export const coalesceWalletState = async (follower, invitationBrand) => {
135
141
  * Sign and broadcast a wallet-action.
136
142
  *
137
143
  * @throws { Error & { code: number } } if transaction fails
138
- * @param {import('@agoric/smart-wallet/src/smartWallet').BridgeAction} bridgeAction
139
- * @param {import('./rpc').MinimalNetworkConfig & {
144
+ * @param {import('@agoric/smart-wallet/src/smartWallet.js').BridgeAction} bridgeAction
145
+ * @param {import('./rpc.js').MinimalNetworkConfig & {
140
146
  * from: string,
147
+ * fees?: string,
141
148
  * verbose?: boolean,
142
149
  * keyring?: {home?: string, backend: string},
143
150
  * stdout: Pick<import('stream').Writable, 'write'>,
@@ -165,7 +172,7 @@ export const sendAction = async (bridgeAction, opts) => {
165
172
  assert(out); // not dry run
166
173
  const tx = JSON.parse(out);
167
174
  if (tx.code !== 0) {
168
- const err = Error(`failed to send action. code: ${tx.code}`);
175
+ const err = Error(`failed to send tx: ${tx.raw_log} code: ${tx.code}`);
169
176
  // @ts-expect-error XXX how to add properties to an error?
170
177
  err.code = tx.code;
171
178
  throw err;
@@ -180,7 +187,7 @@ export const sendAction = async (bridgeAction, opts) => {
180
187
  */
181
188
  export const findContinuingIds = (current, agoricNames) => {
182
189
  // XXX should runtime type-check
183
- /** @type {{ offerToUsedInvitation: [string, Amount<'set'>][]}} */
190
+ /** @type {{ offerToUsedInvitation: [string, InvitationAmount][]}} */
184
191
  const { offerToUsedInvitation: entries } = /** @type {any} */ (current);
185
192
 
186
193
  Array.isArray(entries) || Fail`entries must be an array: ${entries}`;
@@ -253,7 +260,6 @@ export const makeWalletUtils = async (
253
260
  untilNumWantsSatisfied = false,
254
261
  ) => {
255
262
  const lookup = async () => {
256
- // eslint-disable-next-line @jessie.js/no-nested-await, no-await-in-loop
257
263
  const { offerStatuses } = await storedWalletState(from, minHeight);
258
264
  const offerStatus = [...offerStatuses.values()].find(s => s.id === id);
259
265
  if (!offerStatus) throw Error('retry');
@@ -31,9 +31,9 @@ const publishMain = async (progname, rawArgs, powers, opts) => {
31
31
  chainID,
32
32
  };
33
33
 
34
+ await null;
34
35
  for (const bundlePath of rawArgs.slice(1)) {
35
36
  // AWAIT
36
- // eslint-disable-next-line no-await-in-loop,@jessie.js/no-nested-await
37
37
  const bundleText = await fs.readFile(bundlePath, 'utf-8');
38
38
  const bundle = parseLocatedJson(bundleText, bundlePath);
39
39
 
@@ -53,7 +53,6 @@ const publishMain = async (progname, rawArgs, powers, opts) => {
53
53
  });
54
54
 
55
55
  // AWAIT
56
- // eslint-disable-next-line no-await-in-loop,@jessie.js/no-nested-await
57
56
  const hashedBundle = await publishBundle(bundle, connectionSpec);
58
57
  process.stdout.write(`${JSON.stringify(hashedBundle)}\n`);
59
58
  }