-
Notifications
You must be signed in to change notification settings - Fork 212
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
chore: improve use of AssetKind type #4736
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,38 @@ import { makePaymentLedger } from './paymentLedger.js'; | |
import './types.js'; | ||
|
||
/** | ||
* @type {MakeIssuerKit} | ||
* @template {AssetKind} K | ||
* The allegedName becomes part of the brand in asset descriptions. The | ||
* allegedName doesn't have to be a string, but it will only be used for | ||
* its value. The allegedName is useful for debugging and double-checking | ||
* assumptions, but should not be trusted. | ||
* | ||
* 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} allegedName | ||
* @param {K} [assetKind=AssetKind.NAT] | ||
* @param {AdditionalDisplayInfo} [displayInfo={}] | ||
* @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 | ||
* provided, then the failed atomic action will call it, so that some | ||
* larger 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 | ||
* @returns {{ | ||
* mint: Mint<K>, | ||
* issuer: Issuer<K>, | ||
Comment on lines
+37
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and lo, there was much rejoicing in the land! |
||
* brand: Brand<K>, | ||
* displayInfo: DisplayInfo, | ||
* }} | ||
*/ | ||
const makeIssuerKit = ( | ||
allegedName, | ||
// @ts-expect-error K could be instantiated with a different subtype of AssetKind | ||
assetKind = AssetKind.NAT, | ||
displayInfo = harden({}), | ||
optShutdownWithFailure = undefined, | ||
|
@@ -61,3 +89,5 @@ const makeIssuerKit = ( | |
harden(makeIssuerKit); | ||
|
||
export { makeIssuerKit }; | ||
|
||
/** @typedef {ReturnType<typeof makeIssuerKit>} IssuerKit */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fond of this idiom for internal use, but for an external API, it seems more important to spell out the type. Callers should not need to look at the implementation of somewhat related: generating documentation: #4291 . If we can use |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,12 +16,13 @@ import '@agoric/store/exported.js'; | |||||||||
* Make the paymentLedger, the source of truth for the balances of | ||||||||||
* payments. All minting and transfer authority originates here. | ||||||||||
* | ||||||||||
* @template {AssetKind} [K=AssetKind] | ||||||||||
* @param {string} allegedName | ||||||||||
* @param {Brand} brand | ||||||||||
* @param {AssetKind} assetKind | ||||||||||
Comment on lines
21
to
22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again,
Suggested change
The |
||||||||||
* @param {DisplayInfo} displayInfo | ||||||||||
* @param {ShutdownWithFailure=} optShutdownWithFailure | ||||||||||
* @returns {{ issuer: Issuer, mint: Mint }} | ||||||||||
* @returns {{ issuer: Issuer<K>, mint: Mint<K> }} | ||||||||||
*/ | ||||||||||
export const makePaymentLedger = ( | ||||||||||
allegedName, | ||||||||||
|
@@ -248,7 +249,12 @@ export const makePaymentLedger = ( | |||||||||
}); | ||||||||||
}; | ||||||||||
|
||||||||||
/** @type {MintPayment} */ | ||||||||||
/** | ||||||||||
* Creates a new Payment containing newly minted amount. | ||||||||||
* | ||||||||||
* @param {Amount<K>} newAmount | ||||||||||
* @returns {Payment} | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh... we don't get |
||||||||||
*/ | ||||||||||
const mintPayment = newAmount => { | ||||||||||
newAmount = coerce(newAmount); | ||||||||||
const payment = makePayment(allegedName, brand); | ||||||||||
|
@@ -331,7 +337,7 @@ export const makePaymentLedger = ( | |||||||||
withdraw, | ||||||||||
}; | ||||||||||
|
||||||||||
/** @type {Issuer} */ | ||||||||||
/** @type {Issuer<K>} */ | ||||||||||
const issuer = Far(`${allegedName} issuer`, { | ||||||||||
isLive, | ||||||||||
getAmountOf, | ||||||||||
|
@@ -348,7 +354,7 @@ export const makePaymentLedger = ( | |||||||||
makePurse(allegedName, assetKind, brand, purseMethods), | ||||||||||
}); | ||||||||||
|
||||||||||
/** @type {Mint} */ | ||||||||||
/** @type {Mint<K>} */ | ||||||||||
const mint = Far(`${allegedName} mint`, { | ||||||||||
getIssuer: () => issuer, | ||||||||||
mintPayment, | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, an asset kind determines a value type, but not the other way around. We could have another assetkind that uses bigint values but uses mod p math or some such. The mapping is currently invertible, so I guess this is OK, but it gives me pause.