Skip to content

Commit

Permalink
chore(types): adapt to new coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed May 3, 2024
1 parent 1323449 commit f443198
Show file tree
Hide file tree
Showing 23 changed files with 67 additions and 29 deletions.
9 changes: 6 additions & 3 deletions packages/SwingSet/src/types-external.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

export {};

/**
* @import {Guarded} from '@endo/exo')
* @import {Passable, RemotableObject} from '@endo/pass-style')
*/

/* This file defines types that part of the external API of swingset. That
* includes standard services which user-provided vat code might interact
* with, like VatAdminService. */
Expand Down Expand Up @@ -350,9 +355,7 @@ export {};
* incarnation.
*
*
* @typedef {object} CreateVatResults
* @property {object} root
* @property {VatAdminFacet} adminNode
* @typedef {{ adminNode: Guarded<VatAdminFacet>, root: object }} CreateVatResults
*
* @typedef {object} VatAdminSvc
* @property {(id: BundleID) => ERef<BundleCap>} waitForBundleCap
Expand Down
2 changes: 2 additions & 0 deletions packages/agoric-cli/src/lib/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ export const makeAmountFormatter = assets => amt => {
return [issuerName, Number(value) / 10 ** decimalPlaces];
case 'set':
assert(Array.isArray(value));
// @ts-expect-error narrowed
if (value[0]?.handle?.iface?.includes('InvitationHandle')) {
// @ts-expect-error narrowed
return [issuerName, value.map(v => v.description)];
}
return [issuerName, value];
Expand Down
6 changes: 3 additions & 3 deletions packages/base-zone/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export {};
* @typedef {object} Stores
* @property {() => Stores} detached obtain store providers which are detached (the stores are anonymous rather than bound to `label` in the zone)
* @property {(specimen: unknown) => boolean} isStorable return true if the specimen can be stored in the zone, whether as exo-object state or in a store
* @property {<K extends Key, V extends Passable>(label: string, options?: StoreOptions) => MapStore<K, V>} mapStore provide a Map-like store named `label` in the zone
* @property {<K extends Key>(label: string, options?: StoreOptions) => SetStore<K>} setStore provide a Set-like store named `label` in the zone
* @property {<K extends Key, V extends Passable>(
* @property {(label: string, options?: StoreOptions) => MapStore<any, any>} mapStore provide a Map-like store named `label` in the zone
* @property {<K>(label: string, options?: StoreOptions) => SetStore<K>} setStore provide a Set-like store named `label` in the zone
* @property {<K, V>(
* label: string, options?: StoreOptions) => WeakMapStore<K, V>
* } weakMapStore provide a WeakMap-like store named `label` in the zone
* @property {<K>(
Expand Down
2 changes: 1 addition & 1 deletion packages/governance/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ export {};
* Akin to StartedInstanceKit but designed for the results of starting governed contracts. Used in bootstrap space.
* @property {AdminFacet} adminFacet of the governed contract
* @property {LimitedCF<SF>} creatorFacet creator-like facet within the governed contract (without the powers the governor needs)
* @property {GovernorCreatorFacet<SF>} governorCreatorFacet of the governing contract
* @property {Guarded<GovernorCreatorFacet<SF>>} governorCreatorFacet of the governing contract
* @property {AdminFacet} governorAdminFacet of the governing contract
* @property {Awaited<ReturnType<SF>>['publicFacet']} publicFacet
* @property {Instance} instance
Expand Down
1 change: 0 additions & 1 deletion packages/inter-protocol/src/provisionPoolKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ export const prepareProvisionPoolKit = (
console.log('provisionPool notified of new asset', desc.brand);
await zcf.saveIssuer(desc.issuer, desc.issuerName);
/** @type {ERef<Purse>} */
// @ts-expect-error vbank purse is close enough for our use.
const exchangePurse = E(poolBank).getPurse(desc.brand);
void observeNotifier(
E(exchangePurse).getCurrentAmountNotifier(),
Expand Down
4 changes: 4 additions & 0 deletions packages/pegasus/src/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import '@agoric/zoe/exported.js';

import '../exported.js';

/**
* @import {Remote} from '@agoric/vow';
*/

/**
* @type {ContractStartFn<import('./pegasus.js').Pegasus, never, {}, {
* board: Remote<BoardDepositFacet>,
Expand Down
1 change: 0 additions & 1 deletion packages/smart-wallet/src/smartWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,6 @@ export const prepareSmartWallet = (baggage, shared) => {
const { registry, invitationBrand } = shared;

if (registry.has(brand)) {
// @ts-expect-error virtual purse
return E(state.bank).getPurse(brand);
} else if (invitationBrand === brand) {
return state.invitationPurse;
Expand Down
1 change: 0 additions & 1 deletion packages/smart-wallet/test/contexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export const makeDefaultTestContext = async (t, makeSpace) => {
};

const anchor = withAmountUtils(
// @ts-expect-error incomplete typedef
await deeplyFulfilledObject(consume.testFirstAnchorKit),
);

Expand Down
12 changes: 8 additions & 4 deletions packages/smart-wallet/test/test-marshal-contexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ test('makeImportContext preserves identity across AMM and wallet', t => {
slots: ['board011'],
});

/** @type {Brand[]} */
const [b1] = context.fromBoard.fromCapData(ammMetricsCapData);
/** @type {Brand[]} */
const [b2] = context.fromBoard.fromCapData(amm.getMetrics());
const [b1] = /** @type {Brand[]} */ (
context.fromBoard.fromCapData(ammMetricsCapData)
);

const [b2] = /** @type {Brand[]} */ (
context.fromBoard.fromCapData(amm.getMetrics())
);
t.is(b1, b2, 'unserialization twice from same source');

const myWallet = makeOnChainWallet(board);
Expand All @@ -85,6 +88,7 @@ test('makeImportContext preserves identity across AMM and wallet', t => {
slots: ['board011', 'purse:ATOM'],
});

/** @type {any} */
const walletState = context.fromMyWallet.fromCapData(walletCapData);
t.is(walletState[0].brand, b1, 'unserialization across sources');

Expand Down
1 change: 1 addition & 0 deletions packages/solo/src/pipe-entrypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const main = async () => {
mutex.resolve(undefined);
return;
}
/** @type {any} */
const as = parse(`${msg}`);
deliverator(...as).then(() => send('go'));
});
Expand Down
1 change: 1 addition & 0 deletions packages/solo/src/pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const connectToPipe = async ({ method, args, deliverInboundToMbx }) => {
return;
}
// console.log('pipe.js', msg);
/** @type {any} */
const as = parse(`${msg}`);
deliverInboundToMbx(...as).then(() => cp.send('go'));
});
Expand Down
5 changes: 4 additions & 1 deletion packages/telemetry/src/slog-to-otel.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ export const makeSlogToOtelKit = (tracer, overrideAttrs = {}) => {
serializeBodyFormat: 'smallcaps',
});

/** @param {import('@agoric/swingset-vat').SwingSetCapData} data */
/**
* @param {import('@agoric/swingset-vat').SwingSetCapData} data
* @returns {any}
*/
const unserialize = data => {
try {
const body = rawUnserialize(data);
Expand Down
4 changes: 2 additions & 2 deletions packages/vat-data/src/vat-data-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { provideLazy } from '@agoric/store';
let VatDataGlobal;
if ('VatData' in globalThis) {
globalThis.VatData || Fail`VatData defined in global as null or undefined`;
// @ts-expect-error XXX
VatDataGlobal = globalThis.VatData;
// XXX types incompatibility
VatDataGlobal = /** @type {any} */ (globalThis.VatData);
} else {
// XXX this module has been known to get imported (transitively) in cases that
// never use it so we make a version that will satisfy module resolution but
Expand Down
3 changes: 3 additions & 0 deletions packages/vats/src/core/basic-behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const makeVatsFromBundles = async ({
// NOTE: we rely on multiple createVatAdminService calls
// to return cooperating services.
const svc = E(vats.vatAdmin).createVatAdminService(devices.vatAdmin);
// @ts-expect-error XXX
vatAdminSvc.resolve(svc);

const durableStore = await vatStore;
Expand All @@ -77,6 +78,7 @@ export const makeVatsFromBundles = async ({
if (bundleName) {
console.info(`createVatByName(${bundleName})`);
/** @type {Promise<CreateVatResults>} */
// @ts-expect-error XXX
const vatInfo = E(svc).createVatByName(bundleName, {
...defaultVatCreationOptions,
name: vatName,
Expand All @@ -87,6 +89,7 @@ export const makeVatsFromBundles = async ({
assert(bundleID);
const bcap = await E(svc).getBundleCap(bundleID);
/** @type {Promise<CreateVatResults>} */
// @ts-expect-error XXX
const vatInfo = E(svc).createVat(bcap, {
...defaultVatCreationOptions,
name: vatName,
Expand Down
4 changes: 2 additions & 2 deletions packages/vats/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ export type BridgeHandler = {
};

/** An object which handles messages for a specific bridge */
export type ScopedBridgeManager = {
export type ScopedBridgeManager = Guarded<{
toBridge: (obj: any) => Promise<any>;
fromBridge: (obj: any) => PromiseVow<void>;
initHandler: (handler: ERef<BridgeHandler>) => void;
setHandler: (handler: ERef<BridgeHandler>) => void;
};
}>;

/** The object to manage this bridge */
export type BridgeManager = {
Expand Down
24 changes: 19 additions & 5 deletions packages/vats/src/vat-bank.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import {

import '@agoric/notifier/exported.js';

/**
* @import {Guarded} from '@endo/exo')
* @import {Passable, RemotableObject} from '@endo/pass-style')
*/

const { Fail } = assert;

const { VirtualPurseControllerI } = makeVirtualPurseKitIKit();
Expand All @@ -38,8 +43,9 @@ const BridgeChannelI = M.interface('BridgeChannel', {
*/

/**
* @typedef {object} BalanceUpdater
* @property {(value: string, nonce?: string) => void} update
* @typedef {Guarded<{
* update: (value: string, nonce?: string) => void;
* }>} BalanceUpdater
*/

const BalanceUpdaterI = M.interface('BalanceUpdater', {
Expand Down Expand Up @@ -338,6 +344,7 @@ const prepareAssetSubscription = zone => {
brandToAssetDescriptor,
assetSubscriber,
) => {
// @ts-expect-error XXX
return provideLazy(assetSubscriptionCache, brandToAssetDescriptor, () =>
makeAssetSubscription(brandToAssetDescriptor, assetSubscriber),
);
Expand All @@ -362,12 +369,17 @@ const AssetIssuerKitShape = M.splitRecord(BaseIssuerKitShape, {
mint: M.remotable('Mint'),
});

/** @typedef {AssetIssuerKit & { denom: string; escrowPurse?: ERef<Purse> }} AssetRecord */
/**
* @typedef {AssetIssuerKit & {
* denom: string;
* escrowPurse?: RemotableObject & ERef<Purse>;
* }} AssetRecord
*/

/**
* @typedef {object} AssetDescriptor
* @property {Brand} brand
* @property {ERef<Issuer>} issuer
* @property {RemotableObject & ERef<Issuer>} issuer
* @property {string} issuerName
* @property {string} denom
* @property {string} proposedName
Expand Down Expand Up @@ -411,6 +423,7 @@ const prepareBank = (
// (which we emulate, since we know both address and denom are JSONable). If
// we decide to partition the provider and use `brandToVPurse` directly, we'd
// need ephemera for each `makeBank` call.
/** @type {MapStore<string, VirtualPurse>} */
const addressDenomToPurse = zone.mapStore('addressDenomToPurse');
/**
* @type {import('@agoric/store/src/stores/store-utils.js').AtomicProvider<
Expand Down Expand Up @@ -575,6 +588,7 @@ const prepareBankManager = (
* @param {Pick<import('./types.js').NameHubKit['nameAdmin'], 'update'>} [args.nameAdmin]
*/
({ bankChannel, denomToAddressUpdater, nameAdmin }) => {
// @ts-expect-error XXX
/** @type {MapStore<Brand, AssetRecord>} */
const brandToAssetRecord = detachedZone.mapStore('brandToAssetRecord');
/** @type {MapStore<Brand, AssetDescriptor>} */
Expand All @@ -584,7 +598,7 @@ const prepareBankManager = (
/**
* @type {MapStore<
* string,
* { bank: Bank; brandToVPurse: MapStore<Brand, VirtualPurse> }
* { bank: Guarded<Bank>; brandToVPurse: MapStore<Brand, VirtualPurse> }
* >}
*/
const addressToBank = detachedZone.mapStore('addressToBank');
Expand Down
1 change: 0 additions & 1 deletion packages/vats/test/test-bootstrapPayment.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ test.before(async (/** @type {CentralSupplyTestContext} */ t) => {
};

t.context = await deeplyFulfilled(
// @ts-expect-error XXX
harden({
zoe,
feeMintAccess: feeMintAccessP,
Expand Down
1 change: 1 addition & 0 deletions packages/vats/test/test-lib-board.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ test('makeBoard', async t => {
test('board values must be scalar keys', async t => {
const board = makeFakeBoard();
const nonKey = harden({ a: 1 });
// @ts-expect-error intentional error
await t.throwsAsync(() => E(board).getId(nonKey), {
message: /arg 0: A "copyRecord" cannot be a scalar key: {"a":1}/,
});
Expand Down
1 change: 1 addition & 0 deletions packages/wallet/api/src/lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ export function makeWalletRoot({
const addContact = async (petname, actions, address = undefined) => {
// @ts-expect-error XXX ERef
const already = await E(board).has(actions);
/** @type {any} */
let depositFacet;
if (already) {
depositFacet = actions;
Expand Down
5 changes: 5 additions & 0 deletions packages/zoe/src/contractSupport/priceAuthorityQuoteMint.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { AssetKind, prepareIssuerKit } from '@agoric/ertp';
import { provideDurableMapStore } from '@agoric/vat-data';

/**
* @import {EOnly} from '@endo/eventual-send';
* @import {MutableQuote, PriceAuthority, PriceDescription, PriceQuote, PriceQuoteValue, PriceQuery,} from '@agoric/zoe/tools/types.js';
*/

/**
*
* @param {import('@agoric/vat-data').Baggage} baggage
Expand Down
4 changes: 2 additions & 2 deletions packages/zoe/src/contractSupport/priceAuthorityTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { makeNotifier } from '@agoric/notifier';

/**
* @import {EOnly} from '@endo/eventual-send';
* @import {MutableQuote, PriceAuthority, PriceQuote, PriceQuoteValue, PriceQuery,} from '@agoric/zoe/tools/types.js';
* @import {MutableQuote, PriceAuthority, PriceQuote, PriceDescription,} from '@agoric/zoe/tools/types.js';
*/

/**
* @param {Brand<'set'>} quoteBrand
* @param {Amount<'nat'>} amountIn
* @param {Amount<'nat'>} amountOut
* @param {import('@agoric/time').TimerService} timer
* @param {import('@agoric/time').Timestamp} timestamp
* @param {import('@agoric/time').TimestampRecord} timestamp
* @param {ERef<Mint<'set', PriceDescription>>} quoteMint
* @returns {Promise<PriceQuote>}
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/zoe/src/zoeService/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type ContractStartFunction = (
baggage?: Baggage,
) => ERef<{ creatorFacet?: {}; publicFacet?: {} }>;

export type AdminFacet<SF extends ContractStartFunction> = {
export type AdminFacet<SF extends ContractStartFunction> = RemotableObject & {
// Completion, which is currently any
getVatShutdownPromise: () => Promise<any>;
upgradeContract: Parameters<SF>[1] extends undefined
Expand Down
2 changes: 1 addition & 1 deletion packages/zoe/tools/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export {};
* The quoted result of trading `amountIn`
* @property {import('@endo/pass-style').RemotableObject & import('@agoric/time').TimerService} timer
* The service that gave the `timestamp`
* @property {import('@agoric/time').Timestamp} timestamp
* @property {import('@agoric/time').TimestampRecord} timestamp
* A timestamp according to `timer` for the quote
* @property {any} [conditions]
* Additional conditions for the quote
Expand Down

0 comments on commit f443198

Please sign in to comment.