Skip to content

Commit

Permalink
chore!: remove agoricNames from VstorageKit
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Dec 11, 2024
1 parent 10302ad commit 1c69d39
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 82 deletions.
2 changes: 1 addition & 1 deletion a3p-integration/proposals/z:acceptance/test-lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
28 changes: 14 additions & 14 deletions a3p-integration/proposals/z:acceptance/test-lib/vaults.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)));
};

/**
Expand Down
9 changes: 7 additions & 2 deletions packages/agoric-cli/src/commands/auction.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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`);

Expand Down
36 changes: 23 additions & 13 deletions packages/agoric-cli/src/commands/gov.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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) => {
Expand Down Expand Up @@ -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<ReturnType<makeVstorageKit>>} [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');

Expand Down Expand Up @@ -264,10 +272,11 @@ export const makeGovCommand = (_logger, io = {}) => {
)
.requiredOption('--for <string>', '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);
Expand All @@ -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);
Expand Down Expand Up @@ -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`,
Expand Down Expand Up @@ -383,7 +393,7 @@ export const makeGovCommand = (_logger, io = {}) => {
sendFrom: opts.sendFrom,
keyringBackend: options.optsWithGlobals().keyringBackend,
},
utils,
vsk,
);
});

Expand Down
10 changes: 6 additions & 4 deletions packages/agoric-cli/src/commands/oracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/* eslint-env node */
import {
fetchEnvNetworkConfig,
makeAgoricNames,
makeVstorageKit,
makeWalletUtils,
storageHelper,
Expand Down Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions packages/agoric-cli/src/commands/psm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/* eslint-env node */
import {
fetchEnvNetworkConfig,
makeAgoricNames,
makeVstorageKit,
storageHelper,
} from '@agoric/client-utils';
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
12 changes: 9 additions & 3 deletions packages/agoric-cli/src/commands/reserve.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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');
Expand Down
15 changes: 11 additions & 4 deletions packages/agoric-cli/src/commands/vaults.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -63,7 +67,8 @@ export const makeVaultsCommand = logger => {
.option('--collateralBrand <string>', '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,
Expand Down Expand Up @@ -98,10 +103,11 @@ export const makeVaultsCommand = logger => {
.requiredOption('--vaultId <string>', '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,
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 10 additions & 8 deletions packages/agoric-cli/src/commands/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand Down
Loading

0 comments on commit 1c69d39

Please sign in to comment.