From 1c69d39c6b5571e8501cd4be8d32e3d1bd9d3844 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 10 Dec 2024 17:16:28 -0800 Subject: [PATCH] chore!: remove agoricNames from VstorageKit --- .../proposals/z:acceptance/test-lib/utils.js | 2 +- .../proposals/z:acceptance/test-lib/vaults.js | 28 +++++++-------- packages/agoric-cli/src/commands/auction.js | 9 +++-- packages/agoric-cli/src/commands/gov.js | 36 ++++++++++++------- packages/agoric-cli/src/commands/oracle.js | 10 +++--- packages/agoric-cli/src/commands/psm.js | 17 ++++----- packages/agoric-cli/src/commands/reserve.js | 12 +++++-- packages/agoric-cli/src/commands/vaults.js | 15 +++++--- packages/agoric-cli/src/commands/wallet.js | 18 +++++----- packages/client-utils/src/vstorage-kit.js | 9 +++-- packages/client-utils/src/wallet-utils.js | 13 +++---- .../client-utils/test/vstorage-kit.test.js | 10 ++++-- packages/fast-usdc/src/cli/lp-commands.js | 19 ++++++---- .../fast-usdc/src/cli/operator-commands.js | 11 ++++-- .../fast-usdc/test/cli/lp-commands.test.ts | 4 +-- 15 files changed, 131 insertions(+), 82 deletions(-) diff --git a/a3p-integration/proposals/z:acceptance/test-lib/utils.js b/a3p-integration/proposals/z:acceptance/test-lib/utils.js index 330fb799c6d..c4cc3316128 100644 --- a/a3p-integration/proposals/z:acceptance/test-lib/utils.js +++ b/a3p-integration/proposals/z:acceptance/test-lib/utils.js @@ -4,7 +4,7 @@ import { readFile, writeFile } from 'node:fs/promises'; import { networkConfig } from './rpc.js'; export const stargateClientP = makeStargateClient(networkConfig, { fetch }); -export const vstorageKitP = makeVstorageKit({ fetch }, networkConfig); +export const vstorageKit = makeVstorageKit({ fetch }, networkConfig); /** * @import {WalletUtils} from '@agoric/client-utils'; diff --git a/a3p-integration/proposals/z:acceptance/test-lib/vaults.js b/a3p-integration/proposals/z:acceptance/test-lib/vaults.js index 88a07564ca9..a7604622a3f 100644 --- a/a3p-integration/proposals/z:acceptance/test-lib/vaults.js +++ b/a3p-integration/proposals/z:acceptance/test-lib/vaults.js @@ -1,10 +1,6 @@ /* eslint-env node */ -import { - boardSlottingMarshaller, - makeFromBoard, - retryUntilCondition, -} from '@agoric/client-utils'; +import { makeAgoricNames, retryUntilCondition } from '@agoric/client-utils'; import { AmountMath } from '@agoric/ertp'; import { agops, @@ -18,12 +14,8 @@ import { ceilMultiplyBy, makeRatio, } from '@agoric/zoe/src/contractSupport/ratio.js'; -import { E } from '@endo/far'; import { walletUtils } from './index.js'; -import { listVaults, vstorageKitP } from './utils.js'; - -const fromBoard = makeFromBoard(); -const marshaller = boardSlottingMarshaller(fromBoard.convertSlotToVal); +import { listVaults, vstorageKit } from './utils.js'; /** * @param {string} address @@ -97,7 +89,10 @@ export const getMinInitialDebt = async () => { * @returns {Promise<{ mintFee: import('@agoric/ertp/src/types.js').NatAmount, adjustedToMintAmount: import('@agoric/ertp/src/types.js').NatAmount }>} */ export const calculateMintFee = async (toMintValue, vaultManager) => { - const { brand } = await E.get(vstorageKitP).agoricNames; + const { brand } = await makeAgoricNames( + vstorageKit.fromBoard, + vstorageKit.vstorage, + ); /** @type {import('@agoric/ertp').Brand} */ // @ts-expect-error let this BoardRemote masquerade as a Brand const ISTBrand = brand.IST; @@ -157,11 +152,16 @@ const paramChangeOfferGeneration = async ( ) => { const ISTunit = 1_000_000n; // aka displayInfo: { decimalPlaces: 6 } - const { brand } = await E.get(vstorageKitP).agoricNames; + const agoricNames = await makeAgoricNames( + vstorageKit.fromBoard, + vstorageKit.vstorage, + ); + + const { brand } = agoricNames; assert(brand.IST); assert(brand.ATOM); - const { instance } = await E.get(vstorageKitP).agoricNames; + const { instance } = agoricNames; assert(instance.VaultFactory); const voteDurSec = BigInt(voteDur); @@ -203,7 +203,7 @@ const paramChangeOfferGeneration = async ( }; // @ts-expect-error tolerate BoardRemote instances with getBoardId methods - return JSON.stringify(marshaller.toCapData(harden(body))); + return JSON.stringify(vstorageKit.marshaller.toCapData(harden(body))); }; /** diff --git a/packages/agoric-cli/src/commands/auction.js b/packages/agoric-cli/src/commands/auction.js index ac9306ffb45..684cd4356a4 100644 --- a/packages/agoric-cli/src/commands/auction.js +++ b/packages/agoric-cli/src/commands/auction.js @@ -1,6 +1,10 @@ // @ts-check /* eslint-env node */ -import { fetchEnvNetworkConfig, makeVstorageKit } from '@agoric/client-utils'; +import { + fetchEnvNetworkConfig, + makeAgoricNames, + makeVstorageKit, +} from '@agoric/client-utils'; import { Fail } from '@endo/errors'; import { InvalidArgumentError } from 'commander'; import { outputActionAndHint } from '../lib/wallet.js'; @@ -88,10 +92,11 @@ export const makeAuctionCommand = ( * }} opts */ async opts => { - const { agoricNames, readPublished } = await makeVstorageKit( + const { readPublished, ...vsk } = makeVstorageKit( { fetch }, networkConfig, ); + const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage); const { current } = await readPublished(`auction.governance`); diff --git a/packages/agoric-cli/src/commands/gov.js b/packages/agoric-cli/src/commands/gov.js index be116b87514..007b6b1a2ea 100644 --- a/packages/agoric-cli/src/commands/gov.js +++ b/packages/agoric-cli/src/commands/gov.js @@ -1,7 +1,11 @@ // @ts-check /* eslint-disable func-names */ /* eslint-env node */ -import { fetchEnvNetworkConfig, makeVstorageKit } from '@agoric/client-utils'; +import { + fetchEnvNetworkConfig, + makeAgoricNames, + makeVstorageKit, +} from '@agoric/client-utils'; import { execFileSync as execFileSyncAmbient } from 'child_process'; import { Command, CommanderError } from 'commander'; import { normalizeAddressWithOptions, pollBlocks } from '../lib/chain.js'; @@ -14,8 +18,10 @@ import { } from '../lib/wallet.js'; /** - * @import {OfferSpec} from '@agoric/smart-wallet/src/offers.js' - * @import {QuestionDetails} from '@agoric/governance/src/types.js' + * @import {OfferSpec} from '@agoric/smart-wallet/src/offers.js'; + * @import {AgoricNamesRemotes} from '@agoric/vats/tools/board-utils.js'; + * @import {CurrentWalletRecord} from '@agoric/smart-wallet/src/smartWallet.js'; + * @import {VstorageKit} from '@agoric/client-utils'; */ const collectValues = (val, memo) => { @@ -85,19 +91,21 @@ export const makeGovCommand = (_logger, io = {}) => { * given a sendFrom address; else print it. * * @param {{ - * toOffer: (agoricNames: *, current: import('@agoric/smart-wallet/src/smartWallet.js').CurrentWalletRecord | undefined) => OfferSpec, + * toOffer: (agoricNames: AgoricNamesRemotes, current: CurrentWalletRecord | undefined) => OfferSpec, * sendFrom?: string | undefined, * keyringBackend: string, * instanceName?: string, * }} detail - * @param {Awaited>} [optUtils] + * @param {VstorageKit} [vsk] */ const processOffer = async function ( { toOffer, sendFrom, keyringBackend }, - optUtils, + vsk, ) { - const utils = await (optUtils || makeVstorageKit({ fetch }, networkConfig)); - const { agoricNames, readPublished } = utils; + await null; + vsk ||= makeVstorageKit({ fetch }, networkConfig); + const { readPublished } = vsk; + const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage); assert(keyringBackend, 'missing keyring-backend option'); @@ -264,10 +272,11 @@ export const makeGovCommand = (_logger, io = {}) => { ) .requiredOption('--for ', 'description of the invitation') .action(async opts => { - const { agoricNames, readPublished } = await makeVstorageKit( + const { readPublished, ...vsk } = makeVstorageKit( { fetch }, networkConfig, ); + const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage); const current = await getCurrent(opts.from, { readPublished }); const known = findContinuingIds(current, agoricNames); @@ -293,10 +302,11 @@ export const makeGovCommand = (_logger, io = {}) => { normalizeAddress, ) .action(async opts => { - const { agoricNames, readPublished } = await makeVstorageKit( + const { readPublished, ...vsk } = makeVstorageKit( { fetch }, networkConfig, ); + const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage); const current = await getCurrent(opts.from, { readPublished }); const found = findContinuingIds(current, agoricNames); @@ -332,8 +342,8 @@ export const makeGovCommand = (_logger, io = {}) => { normalizeAddress, ) .action(async function (opts, options) { - const utils = await makeVstorageKit({ fetch }, networkConfig); - const { readPublished } = utils; + const vsk = makeVstorageKit({ fetch }, networkConfig); + const { readPublished } = vsk; const questionDesc = await readPublished( `committees.${opts.pathname}.latestQuestion`, @@ -383,7 +393,7 @@ export const makeGovCommand = (_logger, io = {}) => { sendFrom: opts.sendFrom, keyringBackend: options.optsWithGlobals().keyringBackend, }, - utils, + vsk, ); }); diff --git a/packages/agoric-cli/src/commands/oracle.js b/packages/agoric-cli/src/commands/oracle.js index 2882cef094a..e91d9967be7 100644 --- a/packages/agoric-cli/src/commands/oracle.js +++ b/packages/agoric-cli/src/commands/oracle.js @@ -3,6 +3,7 @@ /* eslint-env node */ import { fetchEnvNetworkConfig, + makeAgoricNames, makeVstorageKit, makeWalletUtils, storageHelper, @@ -90,19 +91,20 @@ export const makeOracleCommand = (logger, io = {}) => { env: process.env, fetch, }); - const utils = await makeVstorageKit({ fetch }, networkConfig); + const vsk = makeVstorageKit({ fetch }, networkConfig); + const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage); const lookupPriceAggregatorInstance = ([brandIn, brandOut]) => { const name = oracleBrandFeedName(brandIn, brandOut); - const instance = utils.agoricNames.instance[name]; + const instance = agoricNames.instance[name]; if (!instance) { - logger.debug('known instances:', utils.agoricNames.instance); + logger.debug('known instances:', agoricNames.instance); throw Error(`Unknown instance ${name}`); } return instance; }; - return { ...utils, networkConfig, lookupPriceAggregatorInstance }; + return { ...vsk, networkConfig, lookupPriceAggregatorInstance }; }; oracle diff --git a/packages/agoric-cli/src/commands/psm.js b/packages/agoric-cli/src/commands/psm.js index a59a8b81639..e800b5f1c16 100644 --- a/packages/agoric-cli/src/commands/psm.js +++ b/packages/agoric-cli/src/commands/psm.js @@ -3,6 +3,7 @@ /* eslint-env node */ import { fetchEnvNetworkConfig, + makeAgoricNames, makeVstorageKit, storageHelper, } from '@agoric/client-utils'; @@ -66,13 +67,14 @@ export const makePsmCommand = logger => { ); const rpcTools = async () => { - const utils = await makeVstorageKit({ fetch }, networkConfig); + const vsk = await makeVstorageKit({ fetch }, networkConfig); + const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage); const lookupPsmInstance = ([minted, anchor]) => { const name = `psm-${minted}-${anchor}`; - const instance = utils.agoricNames.instance[name]; + const instance = agoricNames.instance[name]; if (!instance) { - logger.debug('known instances:', utils.agoricNames.instance); + logger.debug('known instances:', agoricNames.instance); throw Error(`Unknown instance ${name}`); } return instance; @@ -83,20 +85,19 @@ export const makePsmCommand = logger => { * @param {[Minted: string, Anchor: string]} pair */ const getGovernanceState = async ([Minted, Anchor]) => { - const govContent = await utils.vstorage.readLatest( + const govContent = await vsk.vstorage.readLatest( `published.psm.${Minted}.${Anchor}.governance`, ); assert(govContent, 'no gov content'); const { current: governance } = last( - storageHelper.unserializeTxt(govContent, utils.fromBoard), + storageHelper.unserializeTxt(govContent, vsk.fromBoard), ); - const { [`psm.${Minted}.${Anchor}`]: instance } = - utils.agoricNames.instance; + const { [`psm.${Minted}.${Anchor}`]: instance } = agoricNames.instance; return { instance, governance }; }; - return { ...utils, lookupPsmInstance, getGovernanceState }; + return { ...vsk, agoricNames, lookupPsmInstance, getGovernanceState }; }; psm diff --git a/packages/agoric-cli/src/commands/reserve.js b/packages/agoric-cli/src/commands/reserve.js index eebb6c7d73d..9716590402e 100644 --- a/packages/agoric-cli/src/commands/reserve.js +++ b/packages/agoric-cli/src/commands/reserve.js @@ -1,7 +1,11 @@ // @ts-check /* eslint-disable func-names */ /* eslint-env node */ -import { fetchEnvNetworkConfig, makeVstorageKit } from '@agoric/client-utils'; +import { + fetchEnvNetworkConfig, + makeAgoricNames, + makeVstorageKit, +} from '@agoric/client-utils'; import { Offers } from '@agoric/inter-protocol/src/clientSupport.js'; import { Command } from 'commander'; import { outputActionAndHint } from '../lib/wallet.js'; @@ -31,7 +35,8 @@ export const makeReserveCommand = (_logger, io = {}) => { * }} opts */ async ({ collateralBrand, ...opts }) => { - const { agoricNames } = await makeVstorageKit({ fetch }, networkConfig); + const vsk = makeVstorageKit({ fetch }, networkConfig); + const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage); const offer = Offers.reserve.AddCollateral(agoricNames, { collateralBrandKey: collateralBrand, @@ -65,7 +70,8 @@ export const makeReserveCommand = (_logger, io = {}) => { 1, ) .action(async function (opts) { - const { agoricNames } = await makeVstorageKit({ fetch }, networkConfig); + const vsk = makeVstorageKit({ fetch }, networkConfig); + const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage); const reserveInstance = agoricNames.instance.reserve; assert(reserveInstance, 'missing reserve in names'); diff --git a/packages/agoric-cli/src/commands/vaults.js b/packages/agoric-cli/src/commands/vaults.js index 51032d89482..006831862e7 100644 --- a/packages/agoric-cli/src/commands/vaults.js +++ b/packages/agoric-cli/src/commands/vaults.js @@ -1,7 +1,11 @@ // @ts-check /* eslint-disable func-names */ /* eslint-env node */ -import { fetchEnvNetworkConfig, makeVstorageKit } from '@agoric/client-utils'; +import { + fetchEnvNetworkConfig, + makeAgoricNames, + makeVstorageKit, +} from '@agoric/client-utils'; import { lookupOfferIdForVault, Offers, @@ -63,7 +67,8 @@ export const makeVaultsCommand = logger => { .option('--collateralBrand ', 'Collateral brand key', 'ATOM') .action(async function (opts) { logger.warn('running with options', opts); - const { agoricNames } = await makeVstorageKit({ fetch }, networkConfig); + const vsk = makeVstorageKit({ fetch }, networkConfig); + const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage); const offer = Offers.vaults.OpenVault(agoricNames, { giveCollateral: opts.giveCollateral, @@ -98,10 +103,11 @@ export const makeVaultsCommand = logger => { .requiredOption('--vaultId ', 'Key of vault (e.g. vault1)') .action(async function (opts) { logger.warn('running with options', opts); - const { agoricNames, readPublished } = await makeVstorageKit( + const { readPublished, ...vsk } = makeVstorageKit( { fetch }, networkConfig, ); + const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage); const previousOfferId = await lookupOfferIdForVault( opts.vaultId, @@ -142,10 +148,11 @@ export const makeVaultsCommand = logger => { ) .action(async function (opts) { logger.warn('running with options', opts); - const { agoricNames, readPublished } = await makeVstorageKit( + const { readPublished, ...vsk } = makeVstorageKit( { fetch }, networkConfig, ); + const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage); const previousOfferId = await lookupOfferIdForVault( opts.vaultId, diff --git a/packages/agoric-cli/src/commands/wallet.js b/packages/agoric-cli/src/commands/wallet.js index e41258716d4..18d3d597c2b 100644 --- a/packages/agoric-cli/src/commands/wallet.js +++ b/packages/agoric-cli/src/commands/wallet.js @@ -8,7 +8,11 @@ import { makeLeader, makeLeaderFromRpcAddresses, } from '@agoric/casting'; -import { makeVstorageKit, fetchEnvNetworkConfig } from '@agoric/client-utils'; +import { + makeVstorageKit, + fetchEnvNetworkConfig, + makeAgoricNames, +} from '@agoric/client-utils'; import { execFileSync } from 'child_process'; import fs from 'fs'; import util from 'util'; @@ -214,13 +218,11 @@ export const makeWalletCommand = async command => { normalizeAddress, ) .action(async function (opts) { - const { agoricNames, unserializer, readPublished } = - await makeVstorageKit( - { - fetch, - }, - networkConfig, - ); + const { readPublished, unserializer, ...vsk } = makeVstorageKit( + { fetch }, + networkConfig, + ); + const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage); const leader = makeLeader(networkConfig.rpcAddrs[0]); const follower = await makeFollower( diff --git a/packages/client-utils/src/vstorage-kit.js b/packages/client-utils/src/vstorage-kit.js index bca8d7b074e..6643d81fe63 100644 --- a/packages/client-utils/src/vstorage-kit.js +++ b/packages/client-utils/src/vstorage-kit.js @@ -2,6 +2,7 @@ import { boardSlottingMarshaller, makeBoardRemote, } from '@agoric/vats/tools/board-utils.js'; +import { assertAllDefined } from '@agoric/internal'; import { makeVStorage } from './vstorage.js'; export { boardSlottingMarshaller }; @@ -73,6 +74,7 @@ harden(storageHelper); * @returns {Promise} */ export const makeAgoricNames = async (ctx, vstorage) => { + assertAllDefined({ ctx, vstorage }); const reverse = {}; const entries = await Promise.all( ['brand', 'instance', 'vbankAsset'].map(async kind => { @@ -96,12 +98,10 @@ export const makeAgoricNames = async (ctx, vstorage) => { * @param {{ fetch: typeof window.fetch }} io * @param {MinimalNetworkConfig} config */ -export const makeVstorageKit = async ({ fetch }, config) => { - await null; +export const makeVstorageKit = ({ fetch }, config) => { try { const vstorage = makeVStorage({ fetch }, config); const fromBoard = makeFromBoard(); - const agoricNames = await makeAgoricNames(fromBoard, vstorage); const marshaller = boardSlottingMarshaller(fromBoard.convertSlotToVal); @@ -131,7 +131,6 @@ export const makeVstorageKit = async ({ fetch }, config) => { readLatestHead(`published.${subpath}`); return { - agoricNames, fromBoard, marshaller, readLatestHead, @@ -143,4 +142,4 @@ export const makeVstorageKit = async ({ fetch }, config) => { throw Error(`RPC failure (${config.rpcAddrs}): ${err.message}`); } }; -/** @typedef {Awaited>} VstorageKit */ +/** @typedef {ReturnType} VstorageKit */ diff --git a/packages/client-utils/src/wallet-utils.js b/packages/client-utils/src/wallet-utils.js index 2cd63a1498d..b7d44a4c9d6 100644 --- a/packages/client-utils/src/wallet-utils.js +++ b/packages/client-utils/src/wallet-utils.js @@ -1,7 +1,7 @@ import { makeWalletStateCoalescer } from '@agoric/smart-wallet/src/utils.js'; import { pollBlocks } from './chain.js'; import { makeStargateClient } from './rpc.js'; -import { boardSlottingMarshaller, makeVstorageKit } from './vstorage-kit.js'; +import { makeAgoricNames, makeVstorageKit } from './vstorage-kit.js'; /** * @import {Amount, Brand} from '@agoric/ertp/src/types.js' @@ -20,12 +20,12 @@ import { boardSlottingMarshaller, makeVstorageKit } from './vstorage-kit.js'; * @param {MinimalNetworkConfig} networkConfig */ export const makeWalletUtils = async ({ fetch, delay }, networkConfig) => { - const vsk = await makeVstorageKit({ fetch }, networkConfig); - - const m = boardSlottingMarshaller(vsk.fromBoard.convertSlotToVal); + const vsk = makeVstorageKit({ fetch }, networkConfig); const client = await makeStargateClient(networkConfig, { fetch }); + const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage); + /** * @param {string} from * @param {number|string} [minHeight] @@ -38,12 +38,12 @@ export const makeWalletUtils = async ({ fetch, delay }, networkConfig) => { /** @type {{ Invitation: Brand<'set'> }} */ // @ts-expect-error XXX how to narrow AssetKind to set? - const { Invitation } = vsk.agoricNames.brand; + const { Invitation } = agoricNames.brand; const coalescer = makeWalletStateCoalescer(Invitation); // update with oldest first for (const txt of history.reverse()) { const { body, slots } = JSON.parse(txt); - const record = m.fromCapData({ body, slots }); + const record = vsk.marshaller.fromCapData({ body, slots }); coalescer.update(record); } const coalesced = coalescer.state; @@ -103,6 +103,7 @@ export const makeWalletUtils = async ({ fetch, delay }, networkConfig) => { return { // pass along all of VstorageKit ...vsk, + agoricNames, networkConfig, getLastUpdate, getCurrentWalletRecord, diff --git a/packages/client-utils/test/vstorage-kit.test.js b/packages/client-utils/test/vstorage-kit.test.js index bf2ffb07ea5..a6d11c6972f 100644 --- a/packages/client-utils/test/vstorage-kit.test.js +++ b/packages/client-utils/test/vstorage-kit.test.js @@ -1,6 +1,6 @@ /* eslint-env node */ import test from 'ava'; -import { makeVstorageKit } from '../src/vstorage-kit.js'; +import { makeAgoricNames, makeVstorageKit } from '../src/vstorage-kit.js'; const makeMockFetch = (responses = {}) => { return async url => { @@ -73,9 +73,13 @@ test('agoricNames contains expected structure', async t => { }, }); - const vstorageKit = await makeVstorageKit({ fetch }, makeTestConfig()); + const vstorageKit = makeVstorageKit({ fetch }, makeTestConfig()); + const agoricNames = await makeAgoricNames( + vstorageKit.fromBoard, + vstorageKit.vstorage, + ); - t.snapshot(vstorageKit.agoricNames, 'agoricnNames from A3P'); + t.snapshot(agoricNames, 'agoricNames from A3P'); const priceFeed = await vstorageKit.readPublished( 'priceFeed.ATOM-USD_price_feed', diff --git a/packages/fast-usdc/src/cli/lp-commands.js b/packages/fast-usdc/src/cli/lp-commands.js index 4b829cfbfba..ab354313f84 100644 --- a/packages/fast-usdc/src/cli/lp-commands.js +++ b/packages/fast-usdc/src/cli/lp-commands.js @@ -5,7 +5,11 @@ * @import {USDCProposalShapes} from '../pool-share-math.js'; */ -import { fetchEnvNetworkConfig, makeVstorageKit } from '@agoric/client-utils'; +import { + fetchEnvNetworkConfig, + makeAgoricNames, + makeVstorageKit, +} from '@agoric/client-utils'; import { InvalidArgumentError } from 'commander'; import { assertParsableNumber, @@ -41,7 +45,8 @@ const parseUSDCAmount = (amountString, usdc) => { * @param {Command} program * @param {{ * fetch?: Window['fetch']; - * vstorageKit?: Awaited>; + * agoricNames?: import('@agoric/vats/tools/board-utils.js').AgoricNamesRemotes; + * vstorageKit?: import('@agoric/client-utils').VstorageKit; * stdout: typeof process.stdout; * stderr: typeof process.stderr; * env: typeof process.env; @@ -50,7 +55,7 @@ const parseUSDCAmount = (amountString, usdc) => { */ export const addLPCommands = ( program, - { fetch, vstorageKit, stderr, stdout, env, now }, + { fetch, agoricNames, vstorageKit, stderr, stdout, env, now }, ) => { const loadVsk = async () => { if (vstorageKit) { @@ -75,9 +80,10 @@ export const addLPCommands = ( .action(async opts => { vskP ||= loadVsk(); const vsk = await vskP; + agoricNames ||= await makeAgoricNames(vsk.fromBoard, vsk.vstorage); /** @type {Brand<'nat'>} */ // @ts-expect-error it doesnt recognize usdc as a Brand type - const usdc = vsk.agoricNames.brand.USDC; + const usdc = agoricNames.brand.USDC; assert(usdc, 'USDC brand not in agoricNames'); const usdcAmount = parseUSDCAmount(opts.amount, usdc); @@ -121,15 +127,16 @@ export const addLPCommands = ( .action(async opts => { vskP ||= loadVsk(); const vsk = await vskP; + agoricNames ||= await makeAgoricNames(vsk.fromBoard, vsk.vstorage); /** @type {Brand<'nat'>} */ // @ts-expect-error it doesnt recognize FastLP as a Brand type - const poolShare = vsk.agoricNames.brand.FastLP; + const poolShare = agoricNames.brand.FastLP; assert(poolShare, 'FastLP brand not in agoricNames'); /** @type {Brand<'nat'>} */ // @ts-expect-error it doesnt recognize usdc as a Brand type - const usdc = vsk.agoricNames.brand.USDC; + const usdc = agoricNames.brand.USDC; assert(usdc, 'USDC brand not in agoricNames'); const usdcAmount = parseUSDCAmount(opts.amount, usdc); diff --git a/packages/fast-usdc/src/cli/operator-commands.js b/packages/fast-usdc/src/cli/operator-commands.js index 196a48af8a4..b635efd41ed 100644 --- a/packages/fast-usdc/src/cli/operator-commands.js +++ b/packages/fast-usdc/src/cli/operator-commands.js @@ -5,7 +5,11 @@ * @import {OperatorKit} from '../exos/operator-kit.js'; */ -import { fetchEnvNetworkConfig, makeVstorageKit } from '@agoric/client-utils'; +import { + fetchEnvNetworkConfig, + makeAgoricNames, + makeVstorageKit, +} from '@agoric/client-utils'; import { mustMatch } from '@agoric/internal'; import { Nat } from '@endo/nat'; import { InvalidArgumentError } from 'commander'; @@ -53,8 +57,9 @@ export const addOperatorCommands = ( .option('--offerId ', 'Offer id', String, `operatorAccept-${now()}`) .action(async opts => { const networkConfig = await fetchEnvNetworkConfig({ env, fetch }); - const vsk = await makeVstorageKit({ fetch }, networkConfig); - const instance = vsk.agoricNames.instance.fastUsdc; + const vsk = makeVstorageKit({ fetch }, networkConfig); + const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage); + const instance = agoricNames.instance.fastUsdc; assert(instance, 'fastUsdc instance not in agoricNames'); /** @type {OfferSpec} */ diff --git a/packages/fast-usdc/test/cli/lp-commands.test.ts b/packages/fast-usdc/test/cli/lp-commands.test.ts index 367dc9a78f6..f3bb7ef1a73 100644 --- a/packages/fast-usdc/test/cli/lp-commands.test.ts +++ b/packages/fast-usdc/test/cli/lp-commands.test.ts @@ -32,9 +32,9 @@ const makeTestContext = () => { const now = () => 1234; addLPCommands(program, { + // @ts-expect-error fake brands + agoricNames: { brand: { FastLP, USDC } }, vstorageKit: { - // @ts-expect-error fake brands - agoricNames: { brand: { FastLP, USDC } }, marshaller, // @ts-expect-error ignore fancy return type readPublished: async (path: string) => {