Skip to content

Commit

Permalink
chore(types): Amount member
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jan 18, 2024
1 parent 9d3dd4d commit 226da84
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
5 changes: 3 additions & 2 deletions packages/ERTP/src/amountMath.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<K>} brand
* @param {AssetValueForKind<K>} allegedValue
* @returns {Amount<K>}
* @param {AssetValueForKind<K, M>} allegedValue
* @returns {Amount<K, M>}
*/
// allegedValue has a conditional expression for type widening, to prevent V being bound to a a literal like 1n
make: (brand, allegedValue) => {
Expand Down
30 changes: 16 additions & 14 deletions packages/ERTP/src/types-ambient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,7 +19,7 @@
* bucks. AmountMath relies heavily on polymorphic MathHelpers, which
* manipulate the unbranded portion.
* @property {Brand<K>} brand
* @property {AssetValueForKind<K>} value
* @property {AssetValueForKind<K, M>} value
*/

/**
Expand Down Expand Up @@ -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<M>
* : K extends 'copySet'
* ? CopySet
* ? CopySet<M>
* : K extends 'copyBag'
* ? CopyBag
* ? CopyBag<M>
* : never} AssetValueForKind
*/

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 11 additions & 8 deletions packages/zoe/tools/fakePriceAuthority.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion packages/zoe/tools/types-ambient.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* @typedef {object} PriceQuote
* @property {Amount<'set'>} quoteAmount
* @property {Amount<'set', PriceDescription>} quoteAmount
* Amount whose value is a PriceQuoteValue
* @property {ERef<Payment<'set'>>} quotePayment
* The `quoteAmount` wrapped as a payment
Expand Down

0 comments on commit 226da84

Please sign in to comment.