Skip to content

Commit

Permalink
Merge pull request #8032 from Agoric/ta/use-satisfies
Browse files Browse the repository at this point in the history
use TS satisfies
  • Loading branch information
turadg authored and mhofman committed Aug 7, 2023
2 parents 7b12cf1 + 5e909c1 commit ef2341a
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 118 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
"ava": "^5.3.0",
"c8": "^7.13.0",
"conventional-changelog-conventionalcommits": "^4.6.0",
"eslint": "^8.36.0",
"eslint": "^8.44.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-jessie": "^0.0.6",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-github": "^4.8.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jsdoc": "^40.1.0",
"eslint-plugin-jsdoc": "^46.4.3",
"eslint-plugin-prettier": "^5.0.0-alpha.2",
"lerna": "^3.22.1",
"npm-run-all": "^4.1.5",
Expand Down
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);
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>>}
*/
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,
* 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
Loading

0 comments on commit ef2341a

Please sign in to comment.