From 226da84848152f2330723ac47b6a329672cd1211 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Thu, 18 Jan 2024 11:29:02 -0800 Subject: [PATCH] chore(types): Amount member --- packages/ERTP/src/amountMath.js | 5 ++-- packages/ERTP/src/types-ambient.js | 30 +++++++++++++----------- packages/zoe/tools/fakePriceAuthority.js | 19 ++++++++------- packages/zoe/tools/types-ambient.js | 2 +- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/packages/ERTP/src/amountMath.js b/packages/ERTP/src/amountMath.js index 2820cdc9c95..ab7d49ab681 100644 --- a/packages/ERTP/src/amountMath.js +++ b/packages/ERTP/src/amountMath.js @@ -200,9 +200,10 @@ const AmountMath = { * Make an amount from a value by adding the brand. * * @template {AssetKind} K + * @template {Key} [M=any] member kind * @param {Brand} brand - * @param {AssetValueForKind} allegedValue - * @returns {Amount} + * @param {AssetValueForKind} allegedValue + * @returns {Amount} */ // allegedValue has a conditional expression for type widening, to prevent V being bound to a a literal like 1n make: (brand, allegedValue) => { diff --git a/packages/ERTP/src/types-ambient.js b/packages/ERTP/src/types-ambient.js index 073d6cc17c6..b9797dfeb6a 100644 --- a/packages/ERTP/src/types-ambient.js +++ b/packages/ERTP/src/types-ambient.js @@ -9,6 +9,7 @@ /** * @template {AssetKind} [K=AssetKind] + * @template {Key} [M=Key] member kind, for Amounts that have member values * @typedef {object} Amount Amounts are descriptions of digital assets, * answering the questions "how much" and "of what kind". Amounts are values * labeled with a brand. AmountMath executes the logic of how amounts are @@ -18,7 +19,7 @@ * bucks. AmountMath relies heavily on polymorphic MathHelpers, which * manipulate the unbranded portion. * @property {Brand} brand - * @property {AssetValueForKind} value + * @property {AssetValueForKind} value */ /** @@ -51,14 +52,15 @@ /** * @template {AssetKind} K + * @template {Key} [M=Key] member kind, for Amounts that have member values * @typedef {K extends 'nat' * ? NatValue * : K extends 'set' - * ? SetValue + * ? SetValue * : K extends 'copySet' - * ? CopySet + * ? CopySet * : K extends 'copyBag' - * ? CopyBag + * ? CopyBag * : never} AssetValueForKind */ @@ -93,10 +95,10 @@ /** * @template {AssetKind} [K=AssetKind] - * @typedef {object} Brand The brand identifies the kind of issuer, and has a - * function to get the alleged name for the kind of asset described. The - * alleged name (such as 'BTC' or 'moola') is provided by the maker of the - * issuer and should not be trusted as accurate. + * @typedef {import('@endo/marshal').RemotableObject} Brand The brand identifies + * the kind of issuer, and has a function to get the alleged name for the kind + * of asset described. The alleged name (such as 'BTC' or 'moola') is provided + * by the maker of the issuer and should not be trusted as accurate. * * Every amount created by a particular AmountMath will share the same brand, * but recipients cannot rely on the brand to verify that a purported amount @@ -289,12 +291,12 @@ /** * @template {AssetKind} [K=AssetKind] - * @typedef {object} Payment Payments hold amount of digital assets of the same - * brand in transit. Payments can be deposited in purses, split into multiple - * payments, combined, and claimed (getting an exclusive payment). Payments - * are linear, meaning that either a payment has the same amount of digital - * assets it started with, or it is used up entirely. It is impossible to - * partially use a payment. + * @typedef {import('@endo/marshal').RemotableObject} Payment Payments hold + * amount of digital assets of the same brand in transit. Payments can be + * deposited in purses, split into multiple payments, combined, and claimed + * (getting an exclusive payment). Payments are linear, meaning that either a + * payment has the same amount of digital assets it started with, or it is + * used up entirely. It is impossible to partially use a payment. * * Payments are often received from other actors and therefore should not be * trusted themselves. To get the amount of digital assets in a payment, use diff --git a/packages/zoe/tools/fakePriceAuthority.js b/packages/zoe/tools/fakePriceAuthority.js index 625f3cf5b2a..a62405ba3f4 100644 --- a/packages/zoe/tools/fakePriceAuthority.js +++ b/packages/zoe/tools/fakePriceAuthority.js @@ -115,16 +115,19 @@ export async function makeFakePriceAuthority(options) { natSafeMath.multiply(amountIn.value, tradeValueOut), tradeValueIn, ); + /** @type {Amount<'set', PriceDescription>} */ const quoteAmount = AmountMath.make( quoteBrand, - harden([ - { - amountIn, - amountOut: AmountMath.make(actualBrandOut, valueOut), - timer, - timestamp: quoteTime, - }, - ]), + /** @type {[PriceDescription]} */ ( + harden([ + { + amountIn, + amountOut: AmountMath.make(actualBrandOut, valueOut), + timer, + timestamp: quoteTime, + }, + ]) + ), ); const quote = harden({ quotePayment: E(quoteMint).mintPayment(quoteAmount), diff --git a/packages/zoe/tools/types-ambient.js b/packages/zoe/tools/types-ambient.js index f34db44c459..ed50b345a1f 100644 --- a/packages/zoe/tools/types-ambient.js +++ b/packages/zoe/tools/types-ambient.js @@ -2,7 +2,7 @@ /** * @typedef {object} PriceQuote - * @property {Amount<'set'>} quoteAmount + * @property {Amount<'set', PriceDescription>} quoteAmount * Amount whose value is a PriceQuoteValue * @property {ERef>} quotePayment * The `quoteAmount` wrapped as a payment