agoric 0.21.2-other-dev-3eb1a1d.0 → 0.21.2-other-dev-fbe72e7.0.fbe72e7

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/README.md CHANGED
@@ -2,79 +2,6 @@
2
2
 
3
3
  If you just want to use the Agoric CLI for your own smart contract, please see the [Getting Started website](https://agoric.com/documentation/getting-started/) for information.
4
4
 
5
- ## Relaying via IBC
6
-
7
- The CLI integrates support for the [Confio
8
- ts-relayer](https://github.com/confio/ts-relayer#quick-start) via the
9
- `agoric ibc-setup` and `agoric ibc-relayer` commands.
10
-
11
- Run `agoric start --reset -v local-chain` in a project directory. In the
12
- meantime, you can configure the relayer (note that `--registry-from .` means to use `./registry.yaml`):
13
-
14
- ```console
15
- $ agoric ibc-setup init --registry-from . --src local --dest ollinet
16
- ...
17
- $ agoric ibc-setup keys list
18
- ollinet: agoric1fwk40de0xu7gtlk8z858q2f5lfcqv33ml8qdg4
19
- local: agoric1rvyry6jqmcrrm4ay9tu23rer7que8kdj4206zk
20
- $
21
- ```
22
-
23
- Once your chain has booted, send some `uist` tokens to your `local` relayer
24
- account printed above:
25
-
26
- ```console
27
- $ agd --home=_agstate/keys tx --keyring-backend=test bank send provision agoric1rvyry6jqmcrrm4ay9tu23rer7que8kdj4206zk 20000000uist --from=provision --chain-id=agoriclocal --yes
28
- ...
29
- $
30
- ```
31
-
32
- Go to https://ollinet.faucet.agoric.net and fund your `ollinet` relayer account
33
- printed above with BLD/IBC toy tokens.
34
-
35
- Check your relayer balances. Both `local` and `ollinet` relayer accounts should
36
- show `ubld` and `uist`:
37
-
38
- ```console
39
- $ agoric ibc-setup balances
40
- CHAIN AMOUNT
41
- ollinet 74972124ubld
42
- local 20000000uist
43
- $
44
- ```
45
-
46
- Create an ICS-20 fungible token transfer channel:
47
-
48
- ```console
49
- $ agoric ibc-setup ics20 -v
50
- ...
51
- Created channel:
52
- agoriclocal: transfer/channel-0 (connection-0)
53
- agoricollinet-55: transfer/channel-33 (connection-12)
54
- $
55
- ```
56
-
57
- Now that the channel exists, you can relay packets along it just by using:
58
-
59
- ```console
60
- $ agoric ibc-relayer start -v --poll 15
61
- ```
62
-
63
- Leave this running in the background, and use the above `transfer/channel-0` or
64
- `transfer/channel-33` to send tokens back and forth. The following
65
- example uses the `tx ibc-transfer transfer` command, and then
66
- `transfer channel-0` to indicate the `transfer/channel-0` portID/channelID. It really wants you to know this is about token *transfer*.
67
-
68
- ```console
69
- $ agd --home=_agstate/keys tx ibc-transfer transfer --keyring-backend=test \
70
- transfer channel-0 \
71
- agoric1fwk40de0xu7gtlk8z858q2f5lfcqv33ml8qdg4 200uist \
72
- --from=provision --chain-id=agoriclocal --yes
73
- ...
74
- # Watch the ibc-relayer send a packet and its acknowledgement, then...
75
- $ agd query bank balances agoric1rvyry6jqmcrrm4ay9tu23rer7que8kdj4206zk
76
- ```
77
-
78
5
  ## Developing Agoric CLI
79
6
 
80
7
  **NOTE: these steps are only for modifying the Agoric CLI. See the above for using it to create your own smart contracts.**
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "agoric",
3
- "version": "0.21.2-other-dev-3eb1a1d.0+3eb1a1d",
3
+ "version": "0.21.2-other-dev-fbe72e7.0.fbe72e7",
4
4
  "description": "Manage the Agoric Javascript smart contract platform",
5
5
  "type": "module",
6
6
  "main": "src/main.js",
7
7
  "bin": {
8
- "agoric": "src/entrypoint.js",
9
- "agops": "src/bin-agops.js"
8
+ "agops": "src/bin-agops.js",
9
+ "agoric": "src/entrypoint.js"
10
10
  },
11
11
  "exports": {
12
12
  "./src/entrypoint.js": "./src/entrypoint.js",
13
- "./src/helpers.js": "./src/helpers.js"
13
+ "./src/helpers.js": "./src/helpers.js",
14
+ "./src/lib/index.js": "./src/lib/index.js"
14
15
  },
15
16
  "files": [
16
17
  "src",
@@ -20,62 +21,60 @@
20
21
  "scripts": {
21
22
  "build": "node ./scripts/get-sdk-package-names.js > src/sdk-package-names.js",
22
23
  "test": "ava",
23
- "test:c8": "c8 --all $C8_OPTIONS ava",
24
+ "test:c8": "c8 --all ${C8_OPTIONS:-} ava",
24
25
  "test:xs": "exit 0",
25
26
  "integration-test": "ava --config .ava-integration-test.config.js",
26
27
  "lint-fix": "yarn lint:eslint --fix",
27
- "lint": "run-s --continue-on-error lint:*",
28
- "lint:types": "tsc",
29
- "lint:eslint": "eslint ."
28
+ "lint": "yarn run -T run-s --continue-on-error 'lint:*'",
29
+ "lint:types": "yarn run -T tsc",
30
+ "lint:eslint": "yarn run -T eslint ."
30
31
  },
31
32
  "devDependencies": {
32
- "@agoric/cosmic-swingset": "0.41.4-other-dev-3eb1a1d.0+3eb1a1d",
33
- "@agoric/deploy-script-support": "0.10.4-other-dev-3eb1a1d.0+3eb1a1d",
33
+ "@agoric/cosmic-swingset": "0.41.4-other-dev-fbe72e7.0.fbe72e7",
34
+ "@agoric/deploy-script-support": "0.10.4-other-dev-fbe72e7.0.fbe72e7",
34
35
  "ava": "^5.3.0",
35
- "c8": "^10.1.2",
36
- "dd-trace": "^4.11.1"
36
+ "c8": "^10.1.2"
37
37
  },
38
38
  "dependencies": {
39
- "@agoric/access-token": "0.4.22-other-dev-3eb1a1d.0+3eb1a1d",
40
- "@agoric/cache": "0.3.3-other-dev-3eb1a1d.0+3eb1a1d",
41
- "@agoric/casting": "0.4.3-other-dev-3eb1a1d.0+3eb1a1d",
42
- "@agoric/client-utils": "0.1.1-other-dev-3eb1a1d.0+3eb1a1d",
43
- "@agoric/cosmic-proto": "0.4.1-other-dev-3eb1a1d.0+3eb1a1d",
44
- "@agoric/ertp": "0.16.3-other-dev-3eb1a1d.0+3eb1a1d",
45
- "@agoric/governance": "0.10.4-other-dev-3eb1a1d.0+3eb1a1d",
46
- "@agoric/inter-protocol": "0.16.2-other-dev-3eb1a1d.0+3eb1a1d",
47
- "@agoric/internal": "0.3.3-other-dev-3eb1a1d.0+3eb1a1d",
48
- "@agoric/network": "0.1.1-other-dev-3eb1a1d.0+3eb1a1d",
49
- "@agoric/smart-wallet": "0.5.4-other-dev-3eb1a1d.0+3eb1a1d",
50
- "@agoric/store": "0.9.3-other-dev-3eb1a1d.0+3eb1a1d",
51
- "@agoric/swingset-vat": "0.32.3-other-dev-3eb1a1d.0+3eb1a1d",
52
- "@agoric/vats": "0.15.2-other-dev-3eb1a1d.0+3eb1a1d",
53
- "@agoric/zoe": "0.26.3-other-dev-3eb1a1d.0+3eb1a1d",
54
- "@agoric/zone": "0.2.3-other-dev-3eb1a1d.0+3eb1a1d",
55
- "@confio/relayer": "^0.11.3",
56
- "@cosmjs/crypto": "^0.32.3",
57
- "@cosmjs/encoding": "^0.32.3",
58
- "@cosmjs/math": "^0.32.3",
59
- "@cosmjs/proto-signing": "^0.32.3",
60
- "@cosmjs/stargate": "^0.32.3",
61
- "@endo/bundle-source": "^3.5.0",
62
- "@endo/captp": "^4.4.3",
63
- "@endo/compartment-mapper": "^1.4.0",
64
- "@endo/env-options": "^1.1.8",
65
- "@endo/errors": "^1.2.8",
66
- "@endo/far": "^1.1.9",
67
- "@endo/init": "^1.1.7",
68
- "@endo/marshal": "^1.6.2",
69
- "@endo/nat": "^5.0.13",
70
- "@endo/patterns": "^1.4.7",
71
- "@endo/promise-kit": "^1.1.8",
72
- "@endo/zip": "^1.0.9",
39
+ "@agoric/access-token": "0.4.22-other-dev-fbe72e7.0.fbe72e7",
40
+ "@agoric/cache": "0.3.3-other-dev-fbe72e7.0.fbe72e7",
41
+ "@agoric/casting": "0.4.3-other-dev-fbe72e7.0.fbe72e7",
42
+ "@agoric/client-utils": "0.1.1-other-dev-fbe72e7.0.fbe72e7",
43
+ "@agoric/cosmic-proto": "0.4.1-other-dev-fbe72e7.0.fbe72e7",
44
+ "@agoric/ertp": "0.16.3-other-dev-fbe72e7.0.fbe72e7",
45
+ "@agoric/governance": "0.10.4-other-dev-fbe72e7.0.fbe72e7",
46
+ "@agoric/inter-protocol": "0.16.2-other-dev-fbe72e7.0.fbe72e7",
47
+ "@agoric/internal": "0.3.3-other-dev-fbe72e7.0.fbe72e7",
48
+ "@agoric/network": "0.1.1-other-dev-fbe72e7.0.fbe72e7",
49
+ "@agoric/smart-wallet": "0.5.4-other-dev-fbe72e7.0.fbe72e7",
50
+ "@agoric/store": "0.9.3-other-dev-fbe72e7.0.fbe72e7",
51
+ "@agoric/swingset-vat": "0.32.3-other-dev-fbe72e7.0.fbe72e7",
52
+ "@agoric/vats": "0.15.2-other-dev-fbe72e7.0.fbe72e7",
53
+ "@agoric/zoe": "0.26.3-other-dev-fbe72e7.0.fbe72e7",
54
+ "@agoric/zone": "0.2.3-other-dev-fbe72e7.0.fbe72e7",
55
+ "@cosmjs/crypto": "^0.36.0",
56
+ "@cosmjs/encoding": "^0.36.0",
57
+ "@cosmjs/math": "^0.36.0",
58
+ "@cosmjs/proto-signing": "^0.36.0",
59
+ "@cosmjs/stargate": "^0.36.0",
60
+ "@endo/base64": "^1.0.12",
61
+ "@endo/bundle-source": "^4.1.2",
62
+ "@endo/captp": "^4.4.8",
63
+ "@endo/compartment-mapper": "^1.6.3",
64
+ "@endo/env-options": "^1.1.11",
65
+ "@endo/errors": "^1.2.13",
66
+ "@endo/far": "^1.1.14",
67
+ "@endo/init": "^1.1.12",
68
+ "@endo/marshal": "^1.8.0",
69
+ "@endo/nat": "^5.1.3",
70
+ "@endo/patterns": "^1.7.0",
71
+ "@endo/promise-kit": "^1.1.13",
72
+ "@endo/zip": "^1.0.11",
73
73
  "@iarna/toml": "^2.2.3",
74
74
  "anylogger": "^0.21.0",
75
75
  "chalk": "^5.2.0",
76
76
  "commander": "^12.1.0",
77
77
  "deterministic-json": "^1.0.5",
78
- "esm": "agoric-labs/esm#Agoric-built",
79
78
  "inquirer": "^8.2.2",
80
79
  "opener": "^1.5.2",
81
80
  "tmp": "^0.2.1",
@@ -100,7 +99,10 @@
100
99
  "workerThreads": false
101
100
  },
102
101
  "typeCoverage": {
103
- "atLeast": 77.54
102
+ "atLeast": 79.88
104
103
  },
105
- "gitHead": "3eb1a1d2d75b2b4a94807cd3bf759bc9fc531f05"
104
+ "engines": {
105
+ "node": "^20.9 || ^22.11"
106
+ },
107
+ "gitHead": "fbe72e72107f9997f788674e668c660d92ec4492"
106
108
  }
package/src/bin-agops.js CHANGED
@@ -3,8 +3,6 @@
3
3
  // @ts-check
4
4
  // @jessie-check
5
5
 
6
- import '@endo/init/pre.js';
7
-
8
6
  import '@endo/init';
9
7
 
10
8
  import { E } from '@endo/far';
@@ -30,7 +28,6 @@ const progname = path.basename(process.argv[1]);
30
28
  const program = new Command();
31
29
  program.name(progname).version('unversioned');
32
30
 
33
- program.addCommand(makeOracleCommand(logger));
34
31
  program.addCommand(makeGovCommand(logger));
35
32
  program.addCommand(makePerfCommand(logger));
36
33
  program.addCommand(makePsmCommand(logger));
@@ -69,6 +66,7 @@ const procIO = {
69
66
  setTimeout,
70
67
  };
71
68
 
69
+ program.addCommand(makeOracleCommand(procIO, logger));
72
70
  program.addCommand(makeReserveCommand(logger, procIO));
73
71
  program.addCommand(makeAuctionCommand(logger, { ...procIO, fetch }));
74
72
  program.addCommand(makeInterCommand(procIO, { fetch }));
@@ -132,6 +132,7 @@ export function finishCosmosApp({
132
132
 
133
133
  // Optionally enable the rosetta service
134
134
  if (enableRosetta) {
135
+ app.rosetta ||= {};
135
136
  app.rosetta.enable = enableRosetta;
136
137
  app.rosetta.network = chainId;
137
138
  app.rosetta.retries = 30;
@@ -255,8 +256,14 @@ export function finishCosmosGenesis({ genesisJson, exportedGenesisJson }) {
255
256
 
256
257
  // Set the denomination for different modules.
257
258
  genesis.app_state.mint.params.mint_denom = MINT_DENOM;
258
- genesis.app_state.gov.deposit_params.min_deposit = GOV_DEPOSIT_COINS;
259
- genesis.app_state.gov.voting_params.voting_period = GOV_VOTING_PERIOD;
259
+
260
+ {
261
+ const gov = genesis.app_state.gov;
262
+ const depositParams = gov.params ?? gov.deposit_params;
263
+ const votingParams = gov.params ?? gov.voting_params;
264
+ depositParams.min_deposit = GOV_DEPOSIT_COINS;
265
+ votingParams.voting_period = GOV_VOTING_PERIOD;
266
+ }
260
267
 
261
268
  // Reduce the cost of a transaction.
262
269
  genesis.app_state.auth.params.tx_size_cost_per_byte = '1';
@@ -1,17 +1,21 @@
1
1
  // @ts-check
2
2
  /* eslint-env node */
3
- import { InvalidArgumentError } from 'commander';
3
+ import {
4
+ fetchEnvNetworkConfig,
5
+ makeAgoricNames,
6
+ makeVstorageKit,
7
+ } from '@agoric/client-utils';
4
8
  import { Fail } from '@endo/errors';
5
- import { makeVstorageKit } from '@agoric/client-utils';
9
+ import { InvalidArgumentError } from 'commander';
6
10
  import { outputActionAndHint } from '../lib/wallet.js';
7
- import { getNetworkConfig } from '../lib/network-config.js';
8
11
 
9
12
  /**
10
13
  * @import {ParamTypesMap, ParamTypesMapFromRecord} from '@agoric/governance/src/contractGovernance/typedParamManager.js'
14
+ * @import {AuctionParamRecord} from '@agoric/inter-protocol/src/auction/params.js';
11
15
  * @import {ParamValueForType} from '@agoric/governance/src/types.js'
12
16
  */
13
17
 
14
- const networkConfig = await getNetworkConfig({ env: process.env, fetch });
18
+ const networkConfig = await fetchEnvNetworkConfig({ env: process.env, fetch });
15
19
 
16
20
  /**
17
21
  * @template {ParamTypesMap} M
@@ -20,7 +24,6 @@ const networkConfig = await getNetworkConfig({ env: process.env, fetch });
20
24
  * }} ParamValues
21
25
  */
22
26
 
23
- /** @typedef {ReturnType<import('@agoric/inter-protocol/src/auction/params.js').makeAuctioneerParams>} AuctionParamRecord */
24
27
  /** @typedef {ParamValues<ParamTypesMapFromRecord<AuctionParamRecord>>} AuctionParams */
25
28
 
26
29
  /**
@@ -89,10 +92,11 @@ export const makeAuctionCommand = (
89
92
  * }} opts
90
93
  */
91
94
  async opts => {
92
- const { agoricNames, readPublished } = await makeVstorageKit(
95
+ const { readPublished, ...vsk } = makeVstorageKit(
93
96
  { fetch },
94
97
  networkConfig,
95
98
  );
99
+ const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage);
96
100
 
97
101
  const { current } = await readPublished(`auction.governance`);
98
102
 
@@ -1,11 +1,14 @@
1
1
  // @ts-check
2
2
  /* eslint-disable func-names */
3
3
  /* eslint-env node */
4
- import { makeVstorageKit } from '@agoric/client-utils';
4
+ import {
5
+ fetchEnvNetworkConfig,
6
+ makeAgoricNames,
7
+ makeVstorageKit,
8
+ } from '@agoric/client-utils';
5
9
  import { execFileSync as execFileSyncAmbient } from 'child_process';
6
10
  import { Command, CommanderError } from 'commander';
7
11
  import { normalizeAddressWithOptions, pollBlocks } from '../lib/chain.js';
8
- import { getNetworkConfig } from '../lib/network-config.js';
9
12
  import {
10
13
  findContinuingIds,
11
14
  getCurrent,
@@ -15,8 +18,10 @@ import {
15
18
  } from '../lib/wallet.js';
16
19
 
17
20
  /**
18
- * @import {OfferSpec} from '@agoric/smart-wallet/src/offers.js'
19
- * @import {QuestionDetails} from '@agoric/governance/src/types.js'
21
+ * @import {OfferSpec} from '@agoric/smart-wallet/src/offers.js';
22
+ * @import {AgoricNamesRemotes} from '@agoric/vats/tools/board-utils.js';
23
+ * @import {CurrentWalletRecord} from '@agoric/smart-wallet/src/smartWallet.js';
24
+ * @import {VstorageKit} from '@agoric/client-utils';
20
25
  */
21
26
 
22
27
  const collectValues = (val, memo) => {
@@ -26,7 +31,7 @@ const collectValues = (val, memo) => {
26
31
 
27
32
  const defaultKeyring = process.env.AGORIC_KEYRING_BACKEND || 'test';
28
33
 
29
- const networkConfig = await getNetworkConfig({ env: process.env, fetch });
34
+ const networkConfig = await fetchEnvNetworkConfig({ env: process.env, fetch });
30
35
 
31
36
  /**
32
37
  * @param {import('anylogger').Logger} _logger
@@ -86,19 +91,21 @@ export const makeGovCommand = (_logger, io = {}) => {
86
91
  * given a sendFrom address; else print it.
87
92
  *
88
93
  * @param {{
89
- * toOffer: (agoricNames: *, current: import('@agoric/smart-wallet/src/smartWallet.js').CurrentWalletRecord | undefined) => OfferSpec,
94
+ * toOffer: (agoricNames: AgoricNamesRemotes, current: CurrentWalletRecord | undefined) => OfferSpec,
90
95
  * sendFrom?: string | undefined,
91
96
  * keyringBackend: string,
92
97
  * instanceName?: string,
93
98
  * }} detail
94
- * @param {Awaited<ReturnType<makeVstorageKit>>} [optUtils]
99
+ * @param {VstorageKit} [vsk]
95
100
  */
96
101
  const processOffer = async function (
97
102
  { toOffer, sendFrom, keyringBackend },
98
- optUtils,
103
+ vsk,
99
104
  ) {
100
- const utils = await (optUtils || makeVstorageKit({ fetch }, networkConfig));
101
- const { agoricNames, readPublished } = utils;
105
+ await null;
106
+ vsk ||= makeVstorageKit({ fetch }, networkConfig);
107
+ const { readPublished } = vsk;
108
+ const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage);
102
109
 
103
110
  assert(keyringBackend, 'missing keyring-backend option');
104
111
 
@@ -265,10 +272,11 @@ export const makeGovCommand = (_logger, io = {}) => {
265
272
  )
266
273
  .requiredOption('--for <string>', 'description of the invitation')
267
274
  .action(async opts => {
268
- const { agoricNames, readPublished } = await makeVstorageKit(
275
+ const { readPublished, ...vsk } = makeVstorageKit(
269
276
  { fetch },
270
277
  networkConfig,
271
278
  );
279
+ const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage);
272
280
  const current = await getCurrent(opts.from, { readPublished });
273
281
 
274
282
  const known = findContinuingIds(current, agoricNames);
@@ -294,10 +302,11 @@ export const makeGovCommand = (_logger, io = {}) => {
294
302
  normalizeAddress,
295
303
  )
296
304
  .action(async opts => {
297
- const { agoricNames, readPublished } = await makeVstorageKit(
305
+ const { readPublished, ...vsk } = makeVstorageKit(
298
306
  { fetch },
299
307
  networkConfig,
300
308
  );
309
+ const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage);
301
310
  const current = await getCurrent(opts.from, { readPublished });
302
311
 
303
312
  const found = findContinuingIds(current, agoricNames);
@@ -333,8 +342,8 @@ export const makeGovCommand = (_logger, io = {}) => {
333
342
  normalizeAddress,
334
343
  )
335
344
  .action(async function (opts, options) {
336
- const utils = await makeVstorageKit({ fetch }, networkConfig);
337
- const { readPublished } = utils;
345
+ const vsk = makeVstorageKit({ fetch }, networkConfig);
346
+ const { readPublished } = vsk;
338
347
 
339
348
  const questionDesc = await readPublished(
340
349
  `committees.${opts.pathname}.latestQuestion`,
@@ -384,7 +393,7 @@ export const makeGovCommand = (_logger, io = {}) => {
384
393
  sendFrom: opts.sendFrom,
385
394
  keyringBackend: options.optsWithGlobals().keyringBackend,
386
395
  },
387
- utils,
396
+ vsk,
388
397
  );
389
398
  });
390
399
 
@@ -4,20 +4,19 @@
4
4
  */
5
5
 
6
6
  // @ts-check
7
- import { makeWalletUtils } from '@agoric/client-utils';
7
+ import { fetchEnvNetworkConfig, makeWalletUtils } from '@agoric/client-utils';
8
8
  import { makeOfferSpecShape } from '@agoric/inter-protocol/src/auction/auctionBook.js';
9
9
  import { Offers } from '@agoric/inter-protocol/src/clientSupport.js';
10
10
  import { objectMap } from '@agoric/internal';
11
11
  import { M, matches } from '@endo/patterns';
12
12
  import { CommanderError, InvalidArgumentError } from 'commander';
13
13
  import { normalizeAddressWithOptions, pollBlocks } from '../lib/chain.js';
14
- import { getCurrent, outputActionAndHint, sendAction } from '../lib/wallet.js';
15
14
  import {
16
15
  asBoardRemote,
17
16
  bigintReplacer,
18
17
  makeAmountFormatter,
19
18
  } from '../lib/format.js';
20
- import { getNetworkConfig } from '../lib/network-config.js';
19
+ import { getCurrent, outputActionAndHint, sendAction } from '../lib/wallet.js';
21
20
 
22
21
  const { values } = Object;
23
22
 
@@ -232,7 +231,7 @@ export const makeInterCommand = (
232
231
  try {
233
232
  // XXX pass fetch to getNetworkConfig() explicitly
234
233
  // await null above makes this await safe
235
- const networkConfig = await getNetworkConfig({ env, fetch });
234
+ const networkConfig = await fetchEnvNetworkConfig({ env, fetch });
236
235
  return makeWalletUtils({ fetch, delay }, networkConfig);
237
236
  } catch (err) {
238
237
  // CommanderError is a class constructor, and so
@@ -2,6 +2,8 @@
2
2
  /* eslint-disable func-names */
3
3
  /* eslint-env node */
4
4
  import {
5
+ fetchEnvNetworkConfig,
6
+ makeAgoricNames,
5
7
  makeVstorageKit,
6
8
  makeWalletUtils,
7
9
  storageHelper,
@@ -10,43 +12,48 @@ import { Offers } from '@agoric/inter-protocol/src/clientSupport.js';
10
12
  import { oracleBrandFeedName } from '@agoric/inter-protocol/src/proposals/utils.js';
11
13
  import { Fail } from '@endo/errors';
12
14
  import { Nat } from '@endo/nat';
13
- import * as cp from 'child_process';
14
15
  import { Command } from 'commander';
15
16
  import { inspect } from 'util';
16
17
  import { normalizeAddressWithOptions } from '../lib/chain.js';
17
- import { getNetworkConfig } from '../lib/network-config.js';
18
+ import { bigintReplacer } from '../lib/format.js';
18
19
  import {
19
20
  getCurrent,
20
21
  outputAction,
21
22
  sendAction,
22
23
  sendHint,
23
24
  } from '../lib/wallet.js';
24
- import { bigintReplacer } from '../lib/format.js';
25
25
 
26
26
  /** @import {PriceAuthority, PriceDescription, PriceQuote, PriceQuoteValue, PriceQuery,} from '@agoric/zoe/tools/types.js'; */
27
27
 
28
28
  // XXX support other decimal places
29
29
  const COSMOS_UNIT = 1_000_000n;
30
- const scaleDecimals = num => BigInt(num * Number(COSMOS_UNIT));
30
+ /** @param {number} num */
31
+ const scaleDecimals = num => BigInt(Math.round(num * Number(COSMOS_UNIT)));
31
32
 
32
33
  /**
33
34
  * Prints JSON output to stdout and diagnostic info (like logs) to stderr
34
35
  *
35
- * @param {import('anylogger').Logger} logger
36
36
  * @param {{
37
- * delay?: (ms: number) => Promise<void>,
38
- * execFileSync?: typeof import('child_process').execFileSync,
39
- * env?: Record<string, string | undefined>,
40
- * stdout?: Pick<import('stream').Writable,'write'>,
41
- * }} [io]
37
+ * createCommand: typeof import('commander').createCommand,
38
+ * env: Partial<Record<string, string>>,
39
+ * execFileSync: typeof import('child_process').execFileSync,
40
+ * now: () => number,
41
+ * setTimeout: typeof setTimeout,
42
+ * stderr: Pick<import('stream').Writable,'write'>,
43
+ * stdout: Pick<import('stream').Writable,'write'>,
44
+ * }} process
45
+ * @param {import('anylogger').Logger} [logger]
42
46
  */
43
- export const makeOracleCommand = (logger, io = {}) => {
44
- const {
45
- delay = ms => new Promise(resolve => setTimeout(resolve, ms)),
46
- execFileSync = cp.execFileSync,
47
- env = process.env,
48
- stdout = process.stdout,
49
- } = io;
47
+ export const makeOracleCommand = (
48
+ { env, execFileSync, setTimeout, stderr, stdout },
49
+ logger,
50
+ ) => {
51
+ /**
52
+ * @param {number} ms
53
+ * @returns {Promise<void>}
54
+ */
55
+ const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
56
+
50
57
  const oracle = new Command('oracle')
51
58
  .description('Oracle commands')
52
59
  .usage(
@@ -86,20 +93,24 @@ export const makeOracleCommand = (logger, io = {}) => {
86
93
 
87
94
  const rpcTools = async () => {
88
95
  // XXX pass fetch to getNetworkConfig() explicitly
89
- const networkConfig = await getNetworkConfig({ env: process.env, fetch });
90
- const utils = await makeVstorageKit({ fetch }, networkConfig);
96
+ const networkConfig = await fetchEnvNetworkConfig({
97
+ env: process.env,
98
+ fetch,
99
+ });
100
+ const vsk = makeVstorageKit({ fetch }, networkConfig);
101
+ const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage);
91
102
 
92
103
  const lookupPriceAggregatorInstance = ([brandIn, brandOut]) => {
93
104
  const name = oracleBrandFeedName(brandIn, brandOut);
94
- const instance = utils.agoricNames.instance[name];
105
+ const instance = agoricNames.instance[name];
95
106
  if (!instance) {
96
- logger.debug('known instances:', utils.agoricNames.instance);
107
+ logger && logger.debug('known instances:', agoricNames.instance);
97
108
  throw Error(`Unknown instance ${name}`);
98
109
  }
99
110
  return instance;
100
111
  };
101
112
 
102
- return { ...utils, networkConfig, lookupPriceAggregatorInstance };
113
+ return { ...vsk, networkConfig, lookupPriceAggregatorInstance };
103
114
  };
104
115
 
105
116
  oracle
@@ -132,12 +143,15 @@ export const makeOracleCommand = (logger, io = {}) => {
132
143
  proposal: {},
133
144
  };
134
145
 
135
- outputAction({
136
- method: 'executeOffer',
137
- offer,
138
- });
146
+ outputAction(
147
+ {
148
+ method: 'executeOffer',
149
+ offer,
150
+ },
151
+ stdout,
152
+ );
139
153
 
140
- console.warn(sendHint);
154
+ stderr.write(sendHint);
141
155
  });
142
156
 
143
157
  oracle
@@ -167,12 +181,15 @@ export const makeOracleCommand = (logger, io = {}) => {
167
181
  opts.oracleAdminAcceptOfferId,
168
182
  );
169
183
 
170
- outputAction({
171
- method: 'executeOffer',
172
- offer,
173
- });
184
+ outputAction(
185
+ {
186
+ method: 'executeOffer',
187
+ offer,
188
+ },
189
+ stdout,
190
+ );
174
191
 
175
- console.warn(sendHint);
192
+ stderr.write(sendHint);
176
193
  });
177
194
 
178
195
  const findOracleCap = async (instance, from, readPublished) => {
@@ -204,11 +221,10 @@ export const makeOracleCommand = (logger, io = {}) => {
204
221
  s => s.split('.'),
205
222
  )
206
223
  .action(async opts => {
207
- const { readLatestHead, lookupPriceAggregatorInstance } =
208
- await rpcTools();
224
+ const { readPublished, lookupPriceAggregatorInstance } = await rpcTools();
209
225
  const instance = lookupPriceAggregatorInstance(opts.pair);
210
226
 
211
- const offerId = await findOracleCap(instance, opts.from, readLatestHead);
227
+ const offerId = await findOracleCap(instance, opts.from, readPublished);
212
228
  if (!offerId) {
213
229
  console.error('No continuing ids found');
214
230
  }
@@ -269,8 +285,12 @@ export const makeOracleCommand = (logger, io = {}) => {
269
285
  * }}
270
286
  */ { pair, keys, price },
271
287
  ) => {
272
- const { readLatestHead, networkConfig, lookupPriceAggregatorInstance } =
273
- await rpcTools();
288
+ const {
289
+ readLatestHead,
290
+ readPublished,
291
+ networkConfig,
292
+ lookupPriceAggregatorInstance,
293
+ } = await rpcTools();
274
294
  const wutil = await makeWalletUtils({ fetch, delay }, networkConfig);
275
295
  const unitPrice = scaleDecimals(price);
276
296
 
@@ -280,7 +300,7 @@ export const makeOracleCommand = (logger, io = {}) => {
280
300
  /** @type {Promise<PriceDescription>} */ (
281
301
  readLatestHead(feedPath).catch(() => {
282
302
  const viewer = `https://vstorage.agoric.net/#${networkConfig.rpcAddrs[0]}|published,published.priceFeed|${feedPath}`;
283
- console.warn(`no existing price data; see ${viewer}`);
303
+ stderr.write(`no existing price data; see ${viewer}`);
284
304
  return undefined;
285
305
  })
286
306
  );
@@ -325,7 +345,7 @@ export const makeOracleCommand = (logger, io = {}) => {
325
345
  }
326
346
  }),
327
347
  ]).catch(err => {
328
- console.warn(err);
348
+ stderr.write(err);
329
349
  });
330
350
  }
331
351
 
@@ -335,7 +355,7 @@ export const makeOracleCommand = (logger, io = {}) => {
335
355
  adminOfferIds[from] = await findOracleCap(
336
356
  instance,
337
357
  from,
338
- readLatestHead,
358
+ readPublished,
339
359
  );
340
360
  if (!adminOfferIds[from]) {
341
361
  console.error(