Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use TS satisfies #8032

Merged
merged 3 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/agoric-cli/src/commands/inter.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const makeFormatters = assets => {
* Dynamic check that an OfferStatus is also a BidSpec.
*
* @param {import('@agoric/smart-wallet/src/offers.js').OfferStatus} offerStatus
* @param {Awaited<ReturnType<import('../lib/rpc').makeAgoricNames>>} agoricNames
* @param {import('../lib/wallet.js').AgoricNamesRemotes} agoricNames
* @param {typeof console.warn} warn
* returns null if offerStatus is not a BidSpec
*/
Expand Down
8 changes: 7 additions & 1 deletion packages/agoric-cli/src/commands/test-upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ export const makeTestCommand = (
publicInvitationMaker: 'makeInvitation',
},
proposal: {
want: { Tokens: { brand: agoricNames.brand.GoodStuff, value: 32n } },
want: {
Tokens: {
// @ts-expect-error BoardRemote not a Brand object
brand: agoricNames.brand.GoodStuff,
value: 32n,
},
},
},
};
const result = await sendAction(
Expand Down
15 changes: 6 additions & 9 deletions packages/agoric-cli/src/lib/format.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// @ts-check
import { makeBoardRemote } from '@agoric/vats/tools/board-utils.js';
// eslint-disable-next-line no-unused-vars -- typeof below
import { makeAgoricNames } from './rpc.js';

// ambient types
import '@agoric/ertp/src/types-ambient.js';
import { makeBoardRemote } from '@agoric/vats/tools/board-utils.js';

/** @typedef {import('@agoric/vats/tools/board-utils.js').BoardRemote} BoardRemote */

Expand All @@ -30,16 +28,15 @@ export const Natural = str => {
*/
export const bigintReplacer = (k, v) => (typeof v === 'bigint' ? `${v}` : v);

/** @type {import('@agoric/vats/tools/board-utils.js').VBankAssetDetail} */
/** @type {Partial<import('@agoric/vats/tools/board-utils.js').VBankAssetDetail>} */
// eslint-disable-next-line no-unused-vars
const exampleAsset = {
// @ts-expect-error cast
brand: makeBoardRemote({ boardId: 'board0425', iface: 'Alleged: BLD brand' }),
displayInfo: { assetKind: 'nat', decimalPlaces: 6 },
// @ts-expect-error cast
issuer: makeBoardRemote({ boardId: null, iface: undefined }),
petname: 'Agoric staking token',
proposedName: 'Agoric staking token',
};

/** @typedef {import('@agoric/vats/tools/board-utils.js').VBankAssetDetail } AssetDescriptor */

/**
Expand Down Expand Up @@ -122,7 +119,7 @@ export const fmtRecordOfLines = record => {
* Summarize the offerStatuses of the state as user-facing informative tuples
*
* @param {import('@agoric/smart-wallet/src/utils.js').CoalescedWalletState} state
* @param {Awaited<ReturnType<typeof makeAgoricNames>>} agoricNames
* @param {import('./wallet.js').AgoricNamesRemotes} agoricNames
*/
export const offerStatusTuples = (state, agoricNames) => {
const { offerStatuses } = state;
Expand Down Expand Up @@ -179,7 +176,7 @@ export const offerStatusTuples = (state, agoricNames) => {
/**
* @param {import('@agoric/smart-wallet/src/smartWallet').CurrentWalletRecord} current
* @param {ReturnType<import('@agoric/smart-wallet/src/utils.js').makeWalletStateCoalescer>['state']} coalesced
* @param {Awaited<ReturnType<typeof makeAgoricNames>>} agoricNames
* @param {import('./wallet.js').AgoricNamesRemotes} agoricNames
*/
export const summarize = (current, coalesced, agoricNames) => {
return {
Expand Down
17 changes: 8 additions & 9 deletions packages/inter-protocol/src/clientSupport.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { parseRatio } from '@agoric/zoe/src/contractSupport/ratio.js';
const COSMOS_UNIT = 1_000_000n;
const scaleDecimals = num => BigInt(num * Number(COSMOS_UNIT));

// TODO use '@satisfies" in TS 5.1 to make sure these each conform to OfferMaker interface

// NB: not really a Proposal because the brands are not remotes
// Instead they're copyRecord like "{"boardId":"board0257","iface":"Alleged: IST brand"}" to pass through the boardId
// mustMatch(harden(proposal), ProposalShape);
Comment on lines 12 to 14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This NB: is no longer the case, is it? makeBoardRemote uses Far. The change to smallcaps made it necessary, IIRC.

Expand Down Expand Up @@ -143,11 +141,10 @@ export const lookupOfferIdForVault = async (vaultId, currentP) => {
};

/**
* @param {Record<string, Brand>} brands
* @param {Record<string, import('@agoric/internal/src/marshal.js').BoardRemote>} brands
* @param {({ wantMinted: number, giveMinted?: undefined } | { giveMinted: number, wantMinted?: undefined })} opts
* @param {number} [fee=0]
* @param {number} [fee]
* @param {string} [anchor]
* @returns {Proposal} XXX not a real proposal, uses BoardRemote
*/
const makePsmProposal = (brands, opts, fee = 0, anchor = 'AUSD') => {
const giving = 'giveMinted' in opts ? 'minted' : 'anchor';
Expand Down Expand Up @@ -202,15 +199,13 @@ const makePsmSwapOffer = ({ brand }, instance, opts) => {
instance,
publicInvitationMaker: method,
},
// @ts-expect-error BoardRemote not a Brand object
proposal,
};
};

/**
* @param {{
* brand: Record<string, Brand>,
* vbankAsset: Record<string, { brand: Brand, displayInfo: DisplayInfo }>,
* }} agoricNames
* @param {Pick<import('@agoric/vats/tools/board-utils.js').AgoricNamesRemotes, 'brand' | 'vbankAsset'>} agoricNames
* @param {(msg: string) => Error} makeError error constructor
* @returns {(a: string) => Amount<'nat'>}
*/
Expand Down Expand Up @@ -329,6 +324,7 @@ const makeAddCollateralOffer = ({ brand }, opts) => {
/** @type {AmountKeywordRecord} */
const give = {
Collateral: AmountMath.make(
// @ts-expect-error BoardRemote not a Brand object
brand[opts.collateralBrandKey],
scaleDecimals(opts.give),
),
Expand Down Expand Up @@ -373,6 +369,9 @@ const makePushPriceOffer = (_agoricNames, opts, previousOffer) => {
};
};

/**
* @satisfies {Record<string, Record<string, import('@agoric/smart-wallet/src/types.js').OfferMaker>>}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL:

satisfies makes sure a value's type matches some type shape, but doesn't widen the type unnecessarily.

*/
export const Offers = {
auction: {
Bid: makeBidOffer,
Expand Down
22 changes: 10 additions & 12 deletions packages/inter-protocol/test/test-clientSupport.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,32 @@ import { withAmountUtils } from './supports.js';
const ist = withAmountUtils(makeIssuerKit('IST'));
const atom = withAmountUtils(makeIssuerKit('ATOM'));

const brands = {
IST: ist.brand,
ATOM: atom.brand,
};

// XXX use @satisfies
/** @type {import('@agoric/vats/tools/board-utils.js').AgoricNamesRemotes} */
const agoricNames = /** @type {any} */ ({
brand: brands,
// uses actual Brand objects instead of BoardRemote to make the test output more legible
/** @satisfies {Partial<import('@agoric/vats/tools/board-utils.js').AgoricNamesRemotes>} */
const agoricNames = {
brand: {
IST: /** @type {any} */ (ist.brand),
ATOM: /** @type {any} */ (atom.brand),
},
vbankAsset: {
uist: {
denom: 'uist',
brand: ist.brand,
brand: /** @type {any} */ (ist.brand),
displayInfo: { assetKind: 'nat', decimalPlaces: 6 },
issuer: /** @type {any} */ ({}),
issuerName: 'IST',
proposedName: 'Agoric stable token',
},
'ibc/toyatom': {
denom: 'ibc/toyatom',
brand: atom.brand,
brand: /** @type {any} */ (atom.brand),
displayInfo: { assetKind: 'nat', decimalPlaces: 6 },
issuer: /** @type {any} */ ({}),
issuerName: 'ATOM',
proposedName: 'ATOM',
},
},
});
};

test('Offers.auction.Bid', async t => {
const discounts = [
Expand Down
6 changes: 3 additions & 3 deletions packages/vats/tools/board-utils.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// @ts-check
/**
* @typedef {{
* brand: import('@agoric/internal/src/marshal.js').BoardRemote & Brand,
* brand: import('@agoric/internal/src/marshal.js').BoardRemote,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Losing Brand is a bummer.

I have come to realize that the unmarshalled objects don't need to know their board id - the correspondence can be kept elsewhere. That's the approach I'm using in 2d7a2c5 in #7939.

But I suppose the current code relies on getBoardId(), so BoardRemote is the relevant type.

* denom: string,
* displayInfo: DisplayInfo,
* issuer: import('@agoric/internal/src/marshal.js').BoardRemote & Issuer,
* issuer: import('@agoric/internal/src/marshal.js').BoardRemote,
* issuerName: string,
* proposedName: string,
* }} VBankAssetDetail
*/
/**
* @typedef {{
* brand: Record<string, Brand>,
* brand: Record<string, import('@agoric/internal/src/marshal.js').BoardRemote>,
* instance: Record<string, Instance>,
* vbankAsset: Record<string, VBankAssetDetail>,
* reverse: Record<string, string>,
Expand Down