diff --git a/packages/ERTP/src/issuerKit.js b/packages/ERTP/src/issuerKit.js index 479eff192f2..0493f44ebfa 100644 --- a/packages/ERTP/src/issuerKit.js +++ b/packages/ERTP/src/issuerKit.js @@ -9,8 +9,11 @@ import { AssetKind, assertAssetKind } from './amountMath.js'; import { coerceDisplayInfo } from './displayInfo.js'; import { preparePaymentLedger } from './paymentLedger.js'; -/** @import {AdditionalDisplayInfo, RecoverySetsOption, IssuerKit, PaymentLedger} from './types.js' */ -/** @import {ShutdownWithFailure} from '@agoric/swingset-vat' */ +/** + * @import {AdditionalDisplayInfo, RecoverySetsOption, IssuerKit, PaymentLedger} from './types.js'; + * @import {ShutdownWithFailure} from '@agoric/swingset-vat'; + * @import {TypedPattern} from '@agoric/internal'; + */ /** * @template {AssetKind} K @@ -224,6 +227,7 @@ harden(makeDurableIssuerKit); * Used to either revive a predecessor issuerKit, or to make a new durable one * if it is absent, and to place it in baggage for the next successor. * + * @template {IssuerOptionsRecord} O * @template {AssetKind} K The name becomes part of the brand in asset * descriptions. The name is useful for debugging and double-checking * assumptions, but should not be trusted wrt any external namespace. For @@ -247,8 +251,10 @@ harden(makeDurableIssuerKit); * unit of computation, like the enclosing vat, can be shutdown before * anything else is corrupted by that corrupted state. See * https://github.com/Agoric/agoric-sdk/issues/3434 - * @param {IssuerOptionsRecord} [options] - * @returns {IssuerKit} + * @param {O} [options] + * @returns {O['elementShape'] extends TypedPattern + * ? IssuerKit + * : IssuerKit} */ export const prepareIssuerKit = ( issuerBaggage, @@ -257,6 +263,7 @@ export const prepareIssuerKit = ( assetKind = AssetKind.NAT, displayInfo = harden({}), optShutdownWithFailure = undefined, + // @ts-expect-error could have a different subtype of IssuerOptionsRecord options = {}, ) => { if (hasIssuer(issuerBaggage)) { @@ -285,6 +292,7 @@ export const prepareIssuerKit = ( optShutdownWithFailure, options, ); + // @ts-expect-error cast to the type parameter return issuerKit; } }; @@ -299,21 +307,19 @@ harden(prepareIssuerKit); * Currently used for testing only. Should probably continue to be used for * testing only. * - * @template {AssetKind} [K='nat'] The name becomes part of the brand in asset + * @template {AssetKind} [K='nat'] + * @template {IssuerOptionsRecord} [O={}] + * @param {string} name The name becomes part of the brand in asset * descriptions. The name is useful for debugging and double-checking * assumptions, but should not be trusted wrt any external namespace. For * example, anyone could create a new issuer kit with name 'BTC', but it is * not bitcoin or even related. It is only the name according to that issuer * and brand. - * - * The assetKind will be used to import a specific mathHelpers from the - * mathHelpers library. For example, natMathHelpers, the default, is used for - * basic fungible tokens. - * - * `displayInfo` gives information to the UI on how to display the amount. - * @param {string} name - * @param {K} [assetKind] - * @param {AdditionalDisplayInfo} [displayInfo] + * @param {K} [assetKind] The assetKind will be used to import a specific + * mathHelpers from the mathHelpers library. For example, natMathHelpers, the + * default, is used for basic fungible tokens. + * @param {AdditionalDisplayInfo} [displayInfo] `displayInfo` gives information + * to the UI on how to display the amount. * @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails in * the middle of an atomic action (which btw should never happen), it * potentially leaves its ledger in a corrupted state. If this function was @@ -321,8 +327,10 @@ harden(prepareIssuerKit); * unit of computation, like the enclosing vat, can be shutdown before * anything else is corrupted by that corrupted state. See * https://github.com/Agoric/agoric-sdk/issues/3434 - * @param {IssuerOptionsRecord} [options] - * @returns {IssuerKit} + * @param {O} [options] + * @returns {O['elementShape'] extends TypedPattern + * ? IssuerKit + * : IssuerKit} */ export const makeIssuerKit = ( name, @@ -330,8 +338,10 @@ export const makeIssuerKit = ( assetKind = AssetKind.NAT, displayInfo = harden({}), optShutdownWithFailure = undefined, + // @ts-expect-error O could be instantiated with a different subtype { elementShape = undefined, recoverySetsOption = undefined } = {}, ) => + // @ts-expect-error cast makeDurableIssuerKit( makeScalarBigMapStore('dropped issuer kit', { durable: true }), name, diff --git a/packages/ERTP/src/legacy-payment-helpers.js b/packages/ERTP/src/legacy-payment-helpers.js index 8b3520bc001..aa8fa4dfeb7 100644 --- a/packages/ERTP/src/legacy-payment-helpers.js +++ b/packages/ERTP/src/legacy-payment-helpers.js @@ -7,6 +7,7 @@ import { AmountMath } from './amountMath.js'; /** * @import {ERef} from '@endo/far'; + * @import {Key} from '@endo/patterns'; * @import {Amount, AssetKind, Payment, Purse} from './types.js'; */ @@ -25,11 +26,12 @@ import { AmountMath } from './amountMath.js'; */ /** - * @template {Payment} P - * @param {ERef} recoveryPurse - * @param {ERef

} srcPaymentP + * @template {AssetKind} K + * @template {Key} T type of values in set-like kind + * @param {ERef>} recoveryPurse + * @param {ERef>} srcPaymentP * @param {Pattern} [optAmountShape] - * @returns {Promise

} + * @returns {Promise>} */ export const claim = async ( recoveryPurse, @@ -37,7 +39,6 @@ export const claim = async ( optAmountShape = undefined, ) => { const srcPayment = await srcPaymentP; - // @ts-expect-error XXX could be instantiated with a different subtype return E.when(E(recoveryPurse).deposit(srcPayment, optAmountShape), amount => E(recoveryPurse).withdraw(amount), ); @@ -53,10 +54,11 @@ harden(claim); * origin. * * @template {AssetKind} K - * @param {ERef>} recoveryPurse - * @param {ERef>[]} srcPaymentsPs + * @template {Key} T type of values in set-like kind + * @param {ERef>} recoveryPurse + * @param {ERef>[]} srcPaymentsPs * @param {Pattern} [optTotalAmount] - * @returns {Promise>} + * @returns {Promise>} */ export const combine = async ( recoveryPurse, @@ -69,7 +71,11 @@ export const combine = async ( E(brandP).getDisplayInfo(), ...srcPaymentsPs, ]); - const emptyAmount = AmountMath.makeEmpty(brand, displayInfo.assetKind); + + // XXX Brand lacks M + const emptyAmount = /** @type {Amount} */ ( + AmountMath.makeEmpty(brand, displayInfo.assetKind) + ); const amountPs = srcPayments.map(srcPayment => E(recoveryPurse).deposit(srcPayment), ); diff --git a/packages/ERTP/src/payment.js b/packages/ERTP/src/payment.js index eca1a9e2a77..d52cbbd7f86 100644 --- a/packages/ERTP/src/payment.js +++ b/packages/ERTP/src/payment.js @@ -11,7 +11,7 @@ import { initEmpty } from '@agoric/store'; * @param {string} name * @param {Brand} brand * @param {import('@endo/patterns').InterfaceGuard} PaymentI - * @returns {() => Payment} + * @returns {() => Payment} */ export const preparePaymentKind = (issuerZone, name, brand, PaymentI) => { const makePayment = issuerZone.exoClass( @@ -24,6 +24,7 @@ export const preparePaymentKind = (issuerZone, name, brand, PaymentI) => { }, }, ); + // @ts-expect-error [tag] for tagged type not defined in runtime return makePayment; }; harden(preparePaymentKind); diff --git a/packages/ERTP/src/types.ts b/packages/ERTP/src/types.ts index 5195da07f12..4e8a28785c5 100644 --- a/packages/ERTP/src/types.ts +++ b/packages/ERTP/src/types.ts @@ -2,6 +2,7 @@ import type { LatestTopic } from '@agoric/notifier'; import type { ERef } from '@endo/far'; import type { RemotableObject } from '@endo/pass-style'; import type { CopyBag, CopySet, Key, Pattern } from '@endo/patterns'; +import type { TypeTag } from '@agoric/internal/src/tagged.js'; import type { AssetKind } from './amountMath.js'; export type { AssetKind } from './amountMath.js'; @@ -405,16 +406,21 @@ export type PurseMethods< export type Payment< K extends AssetKind = AssetKind, M extends Key = Key, -> = RemotableObject & PaymentMethods; -export type PaymentMethods = { - /** - * Get the allegedBrand, indicating - * the type of digital asset this payment purports to be, and which issuer to - * use. Because payments are not trusted, any method calls on payments should - * be treated with suspicion and verified elsewhere. - */ - getAllegedBrand: () => Brand; -}; +> = RemotableObject & + TypeTag< + { + /** + * Get the allegedBrand, indicating + * the type of digital asset this payment purports to be, and which issuer to + * use. Because payments are not trusted, any method calls on payments should + * be treated with suspicion and verified elsewhere. + */ + getAllegedBrand: () => Brand; + }, + 'Set-like value type', + M + >; + /** * All of the difference in how digital asset * amount are manipulated can be reduced to the behavior of the math on diff --git a/packages/ERTP/test/unitTests/mintObj.test.js b/packages/ERTP/test/unitTests/mintObj.test.js index 782f4cd5917..0b03fc4b413 100644 --- a/packages/ERTP/test/unitTests/mintObj.test.js +++ b/packages/ERTP/test/unitTests/mintObj.test.js @@ -7,6 +7,10 @@ import { defineDurableKind, makeKindHandle } from '@agoric/vat-data'; import { makeIssuerKit, AssetKind, AmountMath } from '../../src/index.js'; import { claim, combine } from '../../src/legacy-payment-helpers.js'; +/** + * @import {IssuerKit} from '../../src/types.js' + */ + test('mint.getIssuer', t => { const { mint, issuer } = makeIssuerKit('fungible'); t.is(mint.getIssuer(), issuer); @@ -24,13 +28,18 @@ test('mint.mintPayment default nat AssetKind', async t => { t.assert(AmountMath.isEqual(paymentBalance2, fungible1000)); }); +/** @type {import('@agoric/internal').TypedPattern} */ +const StringPattern = M.string(); + test('mint.mintPayment set w strings AssetKind', async t => { const { mint, issuer, brand } = makeIssuerKit( 'items', AssetKind.SET, undefined, undefined, - { elementShape: M.string() }, + { + elementShape: StringPattern, + }, ); const items1and2and4 = AmountMath.make(brand, harden(['1', '2', '4'])); const payment1 = mint.mintPayment(items1and2and4); @@ -110,11 +119,14 @@ test('mint.mintPayment set AssetKind with invites', async t => { // This test models ballet tickets test('non-fungible tokens example', async t => { t.plan(11); + const { mint: balletTicketMint, issuer: balletTicketIssuer, brand, - } = makeIssuerKit('Agoric Ballet Opera tickets', AssetKind.SET); + } = /** + * @type {IssuerKit<'set', { seat: number; show: string; start: string }>} + */ (makeIssuerKit('Agoric Ballet Opera tickets', AssetKind.SET)); const startDateString = new Date(2020, 1, 17, 20, 30).toISOString(); diff --git a/packages/deploy-script-support/test/unitTests/depositInvitation.test.js b/packages/deploy-script-support/test/unitTests/depositInvitation.test.js index 91e9a9561e5..e0af858f5d1 100644 --- a/packages/deploy-script-support/test/unitTests/depositInvitation.test.js +++ b/packages/deploy-script-support/test/unitTests/depositInvitation.test.js @@ -3,10 +3,19 @@ import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; import { makeIssuerKit, AssetKind, AmountMath } from '@agoric/ertp'; +import { InvitationElementShape } from '@agoric/zoe/src/typeGuards.js'; import { makeDepositInvitation } from '../../src/depositInvitation.js'; test('depositInvitation', async t => { - const { mint, issuer, brand } = makeIssuerKit('invitations', AssetKind.SET); + const { mint, issuer, brand } = makeIssuerKit( + 'invitations', + AssetKind.SET, + undefined, + undefined, + { + elementShape: InvitationElementShape, + }, + ); const purse = issuer.makeEmptyPurse(); const paymentAmount = AmountMath.make(brand, harden([{ instance: {} }])); const payment = mint.mintPayment(paymentAmount); diff --git a/packages/deploy-script-support/test/unitTests/findInvitationAmount.test.js b/packages/deploy-script-support/test/unitTests/findInvitationAmount.test.js index bb2e7f9e982..d9bf073135b 100644 --- a/packages/deploy-script-support/test/unitTests/findInvitationAmount.test.js +++ b/packages/deploy-script-support/test/unitTests/findInvitationAmount.test.js @@ -1,15 +1,24 @@ -// @ts-nocheck import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; import { makeIssuerKit, AssetKind, AmountMath } from '@agoric/ertp'; +import { InvitationElementShape } from '@agoric/zoe/src/typeGuards.js'; import { makeOfferAndFindInvitationAmount } from '../../src/offer.js'; test('findInvitationAmount', async t => { - const { mint, issuer, brand } = makeIssuerKit('invitations', AssetKind.SET); + const { mint, issuer, brand } = makeIssuerKit( + 'invitations', + AssetKind.SET, + undefined, + undefined, + { + elementShape: InvitationElementShape, + }, + ); const zoeInvitationPurse = issuer.makeEmptyPurse(); const walletAdmin = {}; + const zoe = {}; const paymentAmount = AmountMath.make( @@ -21,6 +30,7 @@ test('findInvitationAmount', async t => { const { findInvitationAmount } = makeOfferAndFindInvitationAmount( walletAdmin, + // @ts-expect-error mock zoe, zoeInvitationPurse, ); diff --git a/packages/inter-protocol/test/price/fluxAggregatorKit.test.js b/packages/inter-protocol/test/price/fluxAggregatorKit.test.js index 7dbf4c3fc78..cfc673e290d 100644 --- a/packages/inter-protocol/test/price/fluxAggregatorKit.test.js +++ b/packages/inter-protocol/test/price/fluxAggregatorKit.test.js @@ -16,6 +16,7 @@ import { buildZoeManualTimer } from '@agoric/zoe/tools/manualTimer.js'; import { TimeMath } from '@agoric/time'; import { prepareRecorderKitMakers } from '@agoric/zoe/src/contractSupport/recorder.js'; import { documentStorageSchema } from '@agoric/governance/tools/storageDoc.js'; +import { makePriceQuoteIssuer } from '@agoric/zoe/src/contractSupport/priceQuote.js'; import { prepareFluxAggregatorKit } from '../../src/price/fluxAggregatorKit.js'; import { topicPath } from '../supports.js'; @@ -49,7 +50,7 @@ const makeContext = async () => { const toTS = val => TimeMath.coerceTimestampRecord(val, timerBrand); const baggage = makeScalarBigMapStore('test baggage'); - const quoteIssuerKit = makeIssuerKit('quote', AssetKind.SET); + const quoteIssuerKit = makePriceQuoteIssuer(); const { makeDurablePublishKit, makeRecorder } = prepareRecorderKitMakers( baggage, diff --git a/packages/inter-protocol/test/vaultFactory/driver.js b/packages/inter-protocol/test/vaultFactory/driver.js index d203afcd8b1..5434ff1e8bd 100644 --- a/packages/inter-protocol/test/vaultFactory/driver.js +++ b/packages/inter-protocol/test/vaultFactory/driver.js @@ -1,9 +1,10 @@ -import { AmountMath, AssetKind, makeIssuerKit } from '@agoric/ertp'; -import { allValues, makeTracer, objectMap, NonNullish } from '@agoric/internal'; +import { AmountMath, makeIssuerKit } from '@agoric/ertp'; +import { allValues, makeTracer, NonNullish, objectMap } from '@agoric/internal'; import { makeNotifierFromSubscriber } from '@agoric/notifier'; import { unsafeMakeBundleCache } from '@agoric/swingset-vat/tools/bundleTool.js'; import { ceilMultiplyBy, + makePriceQuoteIssuer, makeRatio, makeRatioFromAmounts, } from '@agoric/zoe/src/contractSupport/index.js'; @@ -13,8 +14,8 @@ import { E } from '@endo/eventual-send'; import { deeplyFulfilled } from '@endo/marshal'; import { eventLoopIteration } from '@agoric/notifier/tools/testSupports.js'; -import { providePriceAuthorityRegistry } from '@agoric/vats/src/priceAuthorityRegistry.js'; import { makeScalarBigMapStore } from '@agoric/vat-data/src/index.js'; +import { providePriceAuthorityRegistry } from '@agoric/vats/src/priceAuthorityRegistry.js'; import { setupReserve, @@ -30,6 +31,7 @@ import { } from '../supports.js'; /** + * @import {PriceDescription} from '@agoric/zoe/tools/types.js'; * @import {VaultFactoryContract as VFC} from '../../src/vaultFactory/vaultFactory.js'; * @import {AmountUtils} from '@agoric/zoe/tools/test-utils.js'; */ @@ -230,7 +232,7 @@ const setupServices = async (t, initialPrice, priceBase) => { actualBrandOut: run.brand, initialPrice: makeRatioFromAmounts(initialPrice, priceBase), timer, - quoteIssuerKit: makeIssuerKit('quote', AssetKind.SET), + quoteIssuerKit: makePriceQuoteIssuer(), }); const baggage = makeScalarBigMapStore('baggage'); const { priceAuthority: priceAuthorityReg, adminFacet: priceAuthorityAdmin } = diff --git a/packages/inter-protocol/test/vaultFactory/replacePriceAuthority.test.js b/packages/inter-protocol/test/vaultFactory/replacePriceAuthority.test.js index a9b7aca8a1f..448d0f39a1f 100644 --- a/packages/inter-protocol/test/vaultFactory/replacePriceAuthority.test.js +++ b/packages/inter-protocol/test/vaultFactory/replacePriceAuthority.test.js @@ -162,7 +162,6 @@ export const setupElectorateReserveAndAuction = async ( await startEconomicCommittee(space, electorateTerms); await setupReserve(space); - // const quoteIssuerKit = makeIssuerKit('quote', AssetKind.SET); /** @type {import('@agoric/vat-data').Baggage} */ const paBaggage = makeScalarMapStore(); diff --git a/packages/inter-protocol/test/vaultFactory/vaultFactoryUtils.js b/packages/inter-protocol/test/vaultFactory/vaultFactoryUtils.js index 62f4e6e94cd..45220cdea53 100644 --- a/packages/inter-protocol/test/vaultFactory/vaultFactoryUtils.js +++ b/packages/inter-protocol/test/vaultFactory/vaultFactoryUtils.js @@ -1,9 +1,12 @@ -import { AmountMath, AssetKind, makeIssuerKit } from '@agoric/ertp'; +import { AmountMath } from '@agoric/ertp'; import { makeNotifierFromSubscriber } from '@agoric/notifier'; -import { makeRatio } from '@agoric/zoe/src/contractSupport/index.js'; -import { makeManualPriceAuthority } from '@agoric/zoe/tools/manualPriceAuthority.js'; import { makeScalarBigMapStore } from '@agoric/vat-data/src/index.js'; import { providePriceAuthorityRegistry } from '@agoric/vats/src/priceAuthorityRegistry.js'; +import { + makePriceQuoteIssuer, + makeRatio, +} from '@agoric/zoe/src/contractSupport/index.js'; +import { makeManualPriceAuthority } from '@agoric/zoe/tools/manualPriceAuthority.js'; import { makeScriptedPriceAuthority } from '@agoric/zoe/tools/scriptedPriceAuthority.js'; import { E } from '@endo/eventual-send'; @@ -12,16 +15,20 @@ import { setupReserve, startAuctioneer, } from '../../src/proposals/econ-behaviors.js'; +import { startEconomicCommittee } from '../../src/proposals/startEconCommittee.js'; import { installPuppetGovernance, produceInstallations, setupBootstrap, } from '../supports.js'; -import { startEconomicCommittee } from '../../src/proposals/startEconCommittee.js'; export const BASIS_POINTS = 10000n; -/** @import {AmountUtils} from '@agoric/zoe/tools/test-utils.js'; */ +/** + * @import {AmountUtils} from '@agoric/zoe/tools/test-utils.js'; + * @import {IssuerKit} from '@agoric/ertp'; + * @import {PriceDescription} from '@agoric/zoe/tools/types.js'; + */ /** * @typedef {Record & { @@ -95,7 +102,7 @@ export const setupElectorateReserveAndAuction = async ( await startEconomicCommittee(space, electorateTerms); await setupReserve(space); - const quoteIssuerKit = makeIssuerKit('quote', AssetKind.SET); + const quoteIssuerKit = makePriceQuoteIssuer(); // priceAuthorityReg is the registry, which contains and multiplexes multiple // individual priceAuthorities, including aethPriceAuthority. diff --git a/packages/internal/src/tagged.d.ts b/packages/internal/src/tagged.d.ts index c5cc24e9728..7d8a85f8a14 100644 --- a/packages/internal/src/tagged.d.ts +++ b/packages/internal/src/tagged.d.ts @@ -1,4 +1,7 @@ -/** @file adapted from https://raw.githubusercontent.com/sindresorhus/type-fest/main/source/opaque.d.ts */ +/** @file adapted from https://raw.githubusercontent.com/sindresorhus/type-fest/main/source/tagged.d.ts */ + +// different name to avoid confusion with pass-style "tagged" +export { Tagged as TypeTag }; declare const tag: unique symbol; diff --git a/packages/smart-wallet/src/types.ts b/packages/smart-wallet/src/types.ts index 6100d4b96e8..019bcc212dc 100644 --- a/packages/smart-wallet/src/types.ts +++ b/packages/smart-wallet/src/types.ts @@ -15,7 +15,7 @@ declare const CapDataShape: unique symbol; // Match the type in Zoe, which can't be imported because it's ambient. // This omits the parameters that aren't used in this module. -type Invitation = Payment<'set'>; +type Invitation = Payment<'set', InvitationDetails>; /** * A petname can either be a plain string or a path for which the first element diff --git a/packages/smart-wallet/test/marshal-contexts.test.js b/packages/smart-wallet/test/marshal-contexts.test.js index 5af2fd47159..85f4a57a967 100644 --- a/packages/smart-wallet/test/marshal-contexts.test.js +++ b/packages/smart-wallet/test/marshal-contexts.test.js @@ -142,6 +142,7 @@ test('makeExportContext.serialize handles unregistered identities', t => { t.deepEqual(context.fromCapData(actual), invitationAmount); + // @ts-expect-error missing [tag] for set-like key const myPayment = /** @type {Payment} */ ( Far('payment', { getAllegedBrand: () => assert.fail('no impl') }) ); diff --git a/packages/wallet/api/test/middleware.test.js b/packages/wallet/api/test/middleware.test.js index 6cbb124fc6b..4d760560731 100644 --- a/packages/wallet/api/test/middleware.test.js +++ b/packages/wallet/api/test/middleware.test.js @@ -18,6 +18,8 @@ test('makeLoggingPresence logs calls on purse/payment actions', async t => { const purse = { actions: await makeLoggingPresence('Alleged: purse.actions', enqueue), }; + /** @type {Payment} */ + // @ts-expect-error mock const myPayment = Far('payment', { getAllegedBrand: () => assert.fail('mock'), }); diff --git a/packages/zoe/src/contractSupport/priceQuote.js b/packages/zoe/src/contractSupport/priceQuote.js index 33d18db434e..39553649066 100644 --- a/packages/zoe/src/contractSupport/priceQuote.js +++ b/packages/zoe/src/contractSupport/priceQuote.js @@ -3,7 +3,7 @@ import { Fail } from '@endo/errors'; import { Nat } from '@endo/nat'; import { E } from '@endo/eventual-send'; -import { AmountMath } from '@agoric/ertp'; +import { AmountMath, AssetKind, makeIssuerKit } from '@agoric/ertp'; /** * @import {PriceAuthority, PriceDescription, PriceQuote, PriceQuoteValue, PriceQuery,} from '@agoric/zoe/tools/types.js'; @@ -39,3 +39,8 @@ export const unitAmount = async brand => { return AmountMath.make(brand, 10n ** Nat(decimalPlaces)); }; harden(unitAmount); + +export const makePriceQuoteIssuer = () => + /** @type {IssuerKit<'set', PriceDescription>} */ ( + makeIssuerKit('quote', AssetKind.SET) + ); diff --git a/packages/zoe/src/contracts/priceAggregator.js b/packages/zoe/src/contracts/priceAggregator.js index f3ee1c4de1d..6697321622d 100644 --- a/packages/zoe/src/contracts/priceAggregator.js +++ b/packages/zoe/src/contracts/priceAggregator.js @@ -1,6 +1,6 @@ -import { Fail, q } from '@endo/errors'; -import { AmountMath, AssetKind, makeIssuerKit } from '@agoric/ertp'; +import { AmountMath } from '@agoric/ertp'; import { assertAllDefined } from '@agoric/internal'; +import { notForProductionUse } from '@agoric/internal/src/magic-cookie-test-only.js'; import { makeNotifierKit, makeStoredPublishKit, @@ -8,13 +8,14 @@ import { } from '@agoric/notifier'; import { makeLegacyMap } from '@agoric/store'; import { TimeMath } from '@agoric/time'; +import { Fail, q } from '@endo/errors'; import { E } from '@endo/eventual-send'; import { Far } from '@endo/marshal'; -import { notForProductionUse } from '@agoric/internal/src/magic-cookie-test-only.js'; import { calculateMedian, makeOnewayPriceAuthorityKit, + makePriceQuoteIssuer, } from '../contractSupport/index.js'; import { addRatios, @@ -82,7 +83,7 @@ const start = async (zcf, privateArgs) => { const quoteMint = privateArgs.quoteMint || // makeIssuerKit fails upgrade, this contract is for demo only - makeIssuerKit('quote', AssetKind.SET).mint; + makePriceQuoteIssuer().mint; const quoteIssuerRecord = await zcf.saveIssuer( E(quoteMint).getIssuer(), 'Quote', diff --git a/packages/zoe/src/typeGuards.js b/packages/zoe/src/typeGuards.js index 3690c681102..f2ba085c7e8 100644 --- a/packages/zoe/src/typeGuards.js +++ b/packages/zoe/src/typeGuards.js @@ -133,6 +133,7 @@ export const isAfterDeadlineExitRule = exit => { }; harden(isAfterDeadlineExitRule); +/** @type {TypedPattern} */ export const InvitationElementShape = M.splitRecord({ description: M.string(), handle: InvitationHandleShape, diff --git a/packages/zoe/src/zoeService/makeInvitation.js b/packages/zoe/src/zoeService/makeInvitation.js index b6e5c20242f..8558695db98 100644 --- a/packages/zoe/src/zoeService/makeInvitation.js +++ b/packages/zoe/src/zoeService/makeInvitation.js @@ -30,7 +30,6 @@ export const prepareInvitationKit = (baggage, shutdownZoeVat = undefined) => { } /** @type {IssuerKit<'set', InvitationDetails>} */ - // @ts-expect-error cast const invitationKit = prepareIssuerKit( invitationKitBaggage, 'Zoe Invitation', diff --git a/packages/zoe/src/zoeService/offer/burnInvitation.js b/packages/zoe/src/zoeService/offer/burnInvitation.js index 42b8c9dea05..d30bea0d7dc 100644 --- a/packages/zoe/src/zoeService/offer/burnInvitation.js +++ b/packages/zoe/src/zoeService/offer/burnInvitation.js @@ -7,8 +7,9 @@ import { E } from '@endo/eventual-send'; * Burn the invitation, assert that only one invitation was burned, * and extract and return the instanceHandle and invitationHandle * - * @param {Issuer} invitationIssuer - * @param {ERef} invitation + * @template {AssetKind} K + * @param {Issuer} invitationIssuer + * @param {ERef>} invitation * @returns {Promise<{ * instanceHandle: Instance, * invitationHandle: InvitationHandle, diff --git a/packages/zoe/src/zoeService/types-ambient.js b/packages/zoe/src/zoeService/types-ambient.js index 9576ffc0ce4..812eae00278 100644 --- a/packages/zoe/src/zoeService/types-ambient.js +++ b/packages/zoe/src/zoeService/types-ambient.js @@ -199,7 +199,7 @@ * @property {() => Promise} getPayouts * returns a promise for a KeywordPaymentRecord containing all the payouts from * this seat. The promise will resolve after the seat has exited. - * @property {(keyword: Keyword) => Promise>} getPayout + * @property {(keyword: Keyword) => Promise>} getPayout * returns a promise for the Payment corresponding to the indicated keyword. * The promise will resolve after the seat has exited. If there is no payment * corresponding to the keyword, an error will be thrown. (It used to return diff --git a/packages/zoe/test/unitTests/contracts/coveredCall.test.js b/packages/zoe/test/unitTests/contracts/coveredCall.test.js index a718a212e6d..aca556a0aaa 100644 --- a/packages/zoe/test/unitTests/contracts/coveredCall.test.js +++ b/packages/zoe/test/unitTests/contracts/coveredCall.test.js @@ -994,7 +994,7 @@ test('zoe - coveredCall non-fungible', async t => { // already escrowed. const invitationIssuer = await E(zoe).getInvitationIssuer(); - /** @type {Payment} */ + /** @type {Payment<'set', InvitationDetails>} */ const bobExclOption = await claim( E(invitationIssuer).makeEmptyPurse(), optionP, diff --git a/packages/zoe/tools/fakePriceAuthority.js b/packages/zoe/tools/fakePriceAuthority.js index f7b24db3ec6..067218ad8ce 100644 --- a/packages/zoe/tools/fakePriceAuthority.js +++ b/packages/zoe/tools/fakePriceAuthority.js @@ -1,16 +1,19 @@ import { Fail } from '@endo/errors'; -import { makePromiseKit } from '@endo/promise-kit'; import { E } from '@endo/eventual-send'; import { Far } from '@endo/marshal'; +import { makePromiseKit } from '@endo/promise-kit'; -import { makeIssuerKit, AssetKind, AmountMath } from '@agoric/ertp'; +import { AmountMath } from '@agoric/ertp'; import { - makeNotifierKit, makeNotifierFromAsyncIterable, + makeNotifierKit, } from '@agoric/notifier'; import { TimeMath } from '@agoric/time'; -import { natSafeMath } from '../src/contractSupport/index.js'; +import { + makePriceQuoteIssuer, + natSafeMath, +} from '../src/contractSupport/index.js'; /** * @import {PriceAuthority, PriceDescription, PriceQuote, PriceQuoteValue, PriceQuery,} from '@agoric/zoe/tools/types.js'; @@ -31,7 +34,7 @@ const timestampLTE = (a, b) => TimeMath.compareAbs(a, b) <= 0; * @property {Array<[number, number]>} [tradeList] * @property {import('@agoric/time').TimerService} timer * @property {import('@agoric/time').RelativeTime} [quoteInterval] - * @property {ERef>} [quoteMint] + * @property {ERef>} [quoteMint] * @property {Amount<'nat'>} [unitAmountIn] */ @@ -51,7 +54,7 @@ export async function makeFakePriceAuthority(options) { timer, unitAmountIn = AmountMath.make(actualBrandIn, 1n), quoteInterval = 1n, - quoteMint = makeIssuerKit('quote', AssetKind.SET).mint, + quoteMint = makePriceQuoteIssuer().mint, } = options; tradeList || diff --git a/packages/zoe/tools/manualPriceAuthority.js b/packages/zoe/tools/manualPriceAuthority.js index 9203130fc7e..2ad8c2df3d9 100644 --- a/packages/zoe/tools/manualPriceAuthority.js +++ b/packages/zoe/tools/manualPriceAuthority.js @@ -1,13 +1,14 @@ // @jessie-check -import { AmountMath, makeIssuerKit, AssetKind } from '@agoric/ertp'; +import { AmountMath } from '@agoric/ertp'; +import { makeNotifierKit } from '@agoric/notifier'; import { E } from '@endo/eventual-send'; import { Far } from '@endo/marshal'; -import { makeNotifierKit } from '@agoric/notifier'; import { - makeOnewayPriceAuthorityKit, - floorMultiplyBy, floorDivideBy, + floorMultiplyBy, + makeOnewayPriceAuthorityKit, + makePriceQuoteIssuer, } from '../src/contractSupport/index.js'; /** @@ -20,7 +21,7 @@ import { * @param {Brand<'nat'>} options.actualBrandOut * @param {Ratio} options.initialPrice * @param {import('@agoric/time').TimerService} options.timer - * @param {IssuerKit<'set'>} [options.quoteIssuerKit] + * @param {IssuerKit<'set', PriceDescription>} [options.quoteIssuerKit] * @returns {PriceAuthority & { setPrice: (Ratio) => void; disable: () => void }} */ export function makeManualPriceAuthority(options) { @@ -29,7 +30,7 @@ export function makeManualPriceAuthority(options) { actualBrandOut, initialPrice, // brandOut / brandIn timer, - quoteIssuerKit = makeIssuerKit('quote', AssetKind.SET), + quoteIssuerKit = makePriceQuoteIssuer(), } = options; const { brand, issuer: quoteIssuer, mint: quoteMint } = quoteIssuerKit; diff --git a/packages/zoe/tools/scriptedPriceAuthority.js b/packages/zoe/tools/scriptedPriceAuthority.js index 1d01dac4b9a..a35e3ee7d35 100644 --- a/packages/zoe/tools/scriptedPriceAuthority.js +++ b/packages/zoe/tools/scriptedPriceAuthority.js @@ -1,11 +1,12 @@ -import { AmountMath, makeIssuerKit, AssetKind } from '@agoric/ertp'; -import { E } from '@endo/eventual-send'; -import { Far } from '@endo/marshal'; +import { AmountMath } from '@agoric/ertp'; import { observeNotifier } from '@agoric/notifier'; import { TimeMath } from '@agoric/time'; +import { E } from '@endo/eventual-send'; +import { Far } from '@endo/marshal'; import { - natSafeMath, makeOnewayPriceAuthorityKit, + makePriceQuoteIssuer, + natSafeMath, } from '../src/contractSupport/index.js'; /** @@ -20,7 +21,7 @@ export function makeScriptedPriceAuthority(options) { timer, unitAmountIn = AmountMath.make(actualBrandIn, 1n), quoteInterval = 1n, - quoteIssuerKit = makeIssuerKit('quote', AssetKind.SET), + quoteIssuerKit = makePriceQuoteIssuer(), } = options; const { brand, issuer: quoteIssuer, mint: quoteMint } = quoteIssuerKit; let currentPrice = priceList[0]; diff --git a/packages/zoe/tools/test-utils.js b/packages/zoe/tools/test-utils.js index bb50ababc94..51975aa13d9 100644 --- a/packages/zoe/tools/test-utils.js +++ b/packages/zoe/tools/test-utils.js @@ -5,7 +5,7 @@ import { makeRatio } from '../src/contractSupport/ratio.js'; * @import {Amount, Brand, DepositFacet, Issuer, IssuerKit, NatValue} from '@agoric/ertp'; */ -/** @param {Pick, 'brand' | 'issuer' | 'mint'>} kit */ +/** @param {Pick, 'brand' | 'issuer' | 'mint'>} kit */ export const withAmountUtils = kit => { const decimalPlaces = kit.issuer.getDisplayInfo?.()?.decimalPlaces ?? 6; return {