@agoric/ertp 0.16.3-u14.0 → 0.16.3-u16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/exported.d.ts +37 -0
  2. package/exported.js +2 -1
  3. package/package.json +35 -26
  4. package/src/amountMath.d.ts +44 -31
  5. package/src/amountMath.d.ts.map +1 -1
  6. package/src/amountMath.js +130 -120
  7. package/src/amountStore.d.ts +9 -0
  8. package/src/amountStore.d.ts.map +1 -0
  9. package/src/amountStore.js +34 -0
  10. package/src/displayInfo.d.ts +3 -0
  11. package/src/displayInfo.d.ts.map +1 -1
  12. package/src/displayInfo.js +2 -0
  13. package/src/index.js +8 -0
  14. package/src/issuerKit.d.ts +30 -6
  15. package/src/issuerKit.d.ts.map +1 -1
  16. package/src/issuerKit.js +218 -76
  17. package/src/legacy-payment-helpers.d.ts +6 -1
  18. package/src/legacy-payment-helpers.d.ts.map +1 -1
  19. package/src/legacy-payment-helpers.js +33 -32
  20. package/src/mathHelpers/copyBagMathHelpers.d.ts +3 -4
  21. package/src/mathHelpers/copyBagMathHelpers.d.ts.map +1 -1
  22. package/src/mathHelpers/copyBagMathHelpers.js +4 -5
  23. package/src/mathHelpers/copySetMathHelpers.d.ts +3 -3
  24. package/src/mathHelpers/copySetMathHelpers.d.ts.map +1 -1
  25. package/src/mathHelpers/copySetMathHelpers.js +6 -4
  26. package/src/mathHelpers/natMathHelpers.d.ts +8 -7
  27. package/src/mathHelpers/natMathHelpers.d.ts.map +1 -1
  28. package/src/mathHelpers/natMathHelpers.js +7 -8
  29. package/src/mathHelpers/setMathHelpers.d.ts +2 -0
  30. package/src/mathHelpers/setMathHelpers.d.ts.map +1 -1
  31. package/src/mathHelpers/setMathHelpers.js +2 -1
  32. package/src/payment.d.ts +4 -2
  33. package/src/payment.d.ts.map +1 -1
  34. package/src/payment.js +6 -7
  35. package/src/paymentLedger.d.ts +6 -2
  36. package/src/paymentLedger.d.ts.map +1 -1
  37. package/src/paymentLedger.js +71 -90
  38. package/src/purse.d.ts +19 -9
  39. package/src/purse.d.ts.map +1 -1
  40. package/src/purse.js +86 -25
  41. package/src/transientNotifier.d.ts +1 -1
  42. package/src/transientNotifier.d.ts.map +1 -1
  43. package/src/transientNotifier.js +5 -0
  44. package/src/typeGuards.d.ts +41 -9
  45. package/src/typeGuards.d.ts.map +1 -1
  46. package/src/typeGuards.js +38 -43
  47. package/src/types.d.ts +250 -215
  48. package/src/types.d.ts.map +1 -1
  49. package/src/types.js +305 -326
  50. package/CHANGELOG.md +0 -775
  51. package/src/types-ambient.d.ts +0 -376
  52. package/src/types-ambient.d.ts.map +0 -1
  53. package/src/types-ambient.js +0 -440
package/src/issuerKit.js CHANGED
@@ -1,16 +1,16 @@
1
1
  // @jessie-check
2
2
 
3
- import { assert } from '@agoric/assert';
3
+ import { assert, Fail } from '@agoric/assert';
4
4
  import { assertPattern } from '@agoric/store';
5
5
  import { makeScalarBigMapStore } from '@agoric/vat-data';
6
+ import { makeDurableZone } from '@agoric/zone/durable.js';
6
7
 
7
8
  import { AssetKind, assertAssetKind } from './amountMath.js';
8
9
  import { coerceDisplayInfo } from './displayInfo.js';
9
10
  import { preparePaymentLedger } from './paymentLedger.js';
10
11
 
11
- import './types-ambient.js';
12
-
13
- /** @typedef {import('@agoric/vat-data').Baggage} Baggage */
12
+ /** @import {AdditionalDisplayInfo, RecoverySetsOption, IssuerKit, PaymentLedger} from './types.js' */
13
+ /** @import {ShutdownWithFailure} from '@agoric/swingset-vat' */
14
14
 
15
15
  /**
16
16
  * @template {AssetKind} K
@@ -22,21 +22,26 @@ import './types-ambient.js';
22
22
  */
23
23
 
24
24
  /**
25
+ * Used _only_ internally, to make a new issuerKit or to revive an old one.
26
+ *
25
27
  * @template {AssetKind} K
26
28
  * @param {IssuerRecord<K>} issuerRecord
27
- * @param {Baggage} issuerBaggage
28
- * @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails
29
- * in the middle of an atomic action (which btw should never happen), it
30
- * potentially leaves its ledger in a corrupted state. If this function was
31
- * provided, then the failed atomic action will call it, so that some
32
- * larger unit of computation, like the enclosing vat, can be shutdown
33
- * before anything else is corrupted by that corrupted state.
34
- * See https://github.com/Agoric/agoric-sdk/issues/3434
29
+ * @param {import('@agoric/zone').Zone} issuerZone
30
+ * @param {RecoverySetsOption} recoverySetsState Omitted from issuerRecord
31
+ * because it was added in an upgrade.
32
+ * @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails in
33
+ * the middle of an atomic action (which btw should never happen), it
34
+ * potentially leaves its ledger in a corrupted state. If this function was
35
+ * provided, then the failed atomic action will call it, so that some larger
36
+ * unit of computation, like the enclosing vat, can be shutdown before
37
+ * anything else is corrupted by that corrupted state. See
38
+ * https://github.com/Agoric/agoric-sdk/issues/3434
35
39
  * @returns {IssuerKit<K>}
36
40
  */
37
41
  const setupIssuerKit = (
38
42
  { name, assetKind, displayInfo, elementShape },
39
- issuerBaggage,
43
+ issuerZone,
44
+ recoverySetsState,
40
45
  optShutdownWithFailure = undefined,
41
46
  ) => {
42
47
  assert.typeof(name, 'string');
@@ -54,13 +59,14 @@ const setupIssuerKit = (
54
59
 
55
60
  // Attenuate the powerful authority to mint and change balances
56
61
  /** @type {PaymentLedger<K>} */
57
- // @ts-expect-error could be instantiated with different subtype of AssetKind
62
+ // @ts-expect-error could be instantiated with a different subtype
58
63
  const { issuer, mint, brand, mintRecoveryPurse } = preparePaymentLedger(
59
- issuerBaggage,
64
+ issuerZone,
60
65
  name,
61
66
  assetKind,
62
67
  cleanDisplayInfo,
63
68
  elementShape,
69
+ recoverySetsState,
64
70
  optShutdownWithFailure,
65
71
  );
66
72
 
@@ -76,66 +82,113 @@ harden(setupIssuerKit);
76
82
 
77
83
  /** The key at which the issuer record is stored. */
78
84
  const INSTANCE_KEY = 'issuer';
85
+ /**
86
+ * The key at which the issuerKit's `RecoverySetsOption` state is stored.
87
+ * Introduced by an upgrade, so may be absent on a predecessor incarnation. See
88
+ * `RecoverySetsOption` for defaulting behavior.
89
+ */
90
+ const RECOVERY_SETS_STATE = 'recoverySetsState';
79
91
 
80
92
  /**
93
+ * Used _only_ to upgrade a predecessor issuerKit. Use `makeDurableIssuerKit` to
94
+ * make a new one.
95
+ *
81
96
  * @template {AssetKind} K
82
- * @param {Baggage} issuerBaggage
83
- * @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails
84
- * in the middle of an atomic action (which btw should never happen), it
85
- * potentially leaves its ledger in a corrupted state. If this function was
86
- * provided, then the failed atomic action will call it, so that some
87
- * larger unit of computation, like the enclosing vat, can be shutdown
88
- * before anything else is corrupted by that corrupted state.
89
- * See https://github.com/Agoric/agoric-sdk/issues/3434
97
+ * @param {import('@agoric/vat-data').Baggage} issuerBaggage
98
+ * @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails in
99
+ * the middle of an atomic action (which btw should never happen), it
100
+ * potentially leaves its ledger in a corrupted state. If this function was
101
+ * provided, then the failed atomic action will call it, so that some larger
102
+ * unit of computation, like the enclosing vat, can be shutdown before
103
+ * anything else is corrupted by that corrupted state. See
104
+ * https://github.com/Agoric/agoric-sdk/issues/3434
105
+ * @param {RecoverySetsOption} [recoverySetsOption] Added in upgrade, so last
106
+ * and optional. See `RecoverySetsOption` for defaulting behavior.
90
107
  * @returns {IssuerKit<K>}
91
108
  */
92
- export const prepareIssuerKit = (
109
+ export const upgradeIssuerKit = (
93
110
  issuerBaggage,
94
111
  optShutdownWithFailure = undefined,
112
+ recoverySetsOption = undefined,
95
113
  ) => {
96
114
  const issuerRecord = issuerBaggage.get(INSTANCE_KEY);
97
- return setupIssuerKit(issuerRecord, issuerBaggage, optShutdownWithFailure);
115
+ const issuerZone = makeDurableZone(issuerBaggage);
116
+ const oldRecoverySetsState = issuerBaggage.has(RECOVERY_SETS_STATE)
117
+ ? issuerBaggage.get(RECOVERY_SETS_STATE)
118
+ : 'hasRecoverySets';
119
+ if (
120
+ oldRecoverySetsState === 'noRecoverySets' &&
121
+ recoverySetsOption === 'hasRecoverySets'
122
+ ) {
123
+ Fail`Cannot (yet?) upgrade from 'noRecoverySets' to 'hasRecoverySets'`;
124
+ }
125
+ // Extant sets are not currently deleted. If the new option is
126
+ // 'noRecoverySets', they won't be used but extant ones will remain. Future
127
+ // upgrades may make it possible to delete elements from them.
128
+ const recoverySetsState = recoverySetsOption || oldRecoverySetsState;
129
+ return setupIssuerKit(
130
+ issuerRecord,
131
+ issuerZone,
132
+ recoverySetsState,
133
+ optShutdownWithFailure,
134
+ );
98
135
  };
99
- harden(prepareIssuerKit);
136
+ harden(upgradeIssuerKit);
100
137
 
101
138
  /**
102
- * Does baggage already have an issuer from prepareIssuerKit()?
103
- * That is: does it have the relevant keys defined?
139
+ * Does baggage already have an issuerKit?
104
140
  *
105
- * @param {Baggage} baggage
141
+ * @param {import('@agoric/vat-data').Baggage} baggage
106
142
  */
107
143
  export const hasIssuer = baggage => baggage.has(INSTANCE_KEY);
108
144
 
109
145
  /**
110
- * @typedef {Partial<{elementShape: Pattern}>} IssuerOptionsRecord
146
+ * `elementShape`, may only be present for collection-style amounts. If present,
147
+ * it is a `Pattern` that every element of this issuerKits's amounts must
148
+ * satisfy. For example, the Zoe Invitation issuerKit uses an elementShape
149
+ * describing the invitation details for an individual invitation. An invitation
150
+ * purse or payment has an amount that can only be a set of these. (Though
151
+ * typically, the amount of an invitation payment is a singleton set. Such a
152
+ * payment is often referred to in the singular as "an invitation".)
153
+ *
154
+ * `recoverySetsOption` added in upgrade. Note that `IssuerOptionsRecord` is
155
+ * never stored, so we never need to worry about inheriting one from a
156
+ * predecessor predating the introduction of recovery sets. See
157
+ * `RecoverySetsOption` for defaulting behavior.
158
+ *
159
+ * @typedef {Partial<{
160
+ * elementShape: Pattern;
161
+ * recoverySetsOption: RecoverySetsOption;
162
+ * }>} IssuerOptionsRecord
111
163
  */
112
164
 
113
165
  /**
114
- * @template {AssetKind} K
115
- * The name becomes part of the brand in asset descriptions.
116
- * The name is useful for debugging and double-checking
117
- * assumptions, but should not be trusted wrt any external namespace.
118
- * For example, anyone could create a new issuer kit with name 'BTC', but
119
- * it is not bitcoin or even related. It is only the name according
120
- * to that issuer and brand.
166
+ * Used _only_ to make a _new_ durable issuer, i.e., the initial incarnation of
167
+ * that issuer.
121
168
  *
122
- * The assetKind will be used to import a specific mathHelpers
123
- * from the mathHelpers library. For example, natMathHelpers, the
124
- * default, is used for basic fungible tokens.
169
+ * @template {AssetKind} K The name becomes part of the brand in asset
170
+ * descriptions. The name is useful for debugging and double-checking
171
+ * assumptions, but should not be trusted wrt any external namespace. For
172
+ * example, anyone could create a new issuer kit with name 'BTC', but it is
173
+ * not bitcoin or even related. It is only the name according to that issuer
174
+ * and brand.
125
175
  *
126
- * `displayInfo` gives information to the UI on how to display the amount.
176
+ * The assetKind will be used to import a specific mathHelpers from the
177
+ * mathHelpers library. For example, natMathHelpers, the default, is used for
178
+ * basic fungible tokens.
127
179
  *
128
- * @param {Baggage} issuerBaggage
180
+ * `displayInfo` gives information to the UI on how to display the amount.
181
+ * @param {import('@agoric/vat-data').Baggage} issuerBaggage
129
182
  * @param {string} name
130
- * @param {K} [assetKind=AssetKind.NAT]
131
- * @param {AdditionalDisplayInfo} [displayInfo={}]
132
- * @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails
133
- * in the middle of an atomic action (which btw should never happen), it
134
- * potentially leaves its ledger in a corrupted state. If this function was
135
- * provided, then the failed atomic action will call it, so that some
136
- * larger unit of computation, like the enclosing vat, can be shutdown
137
- * before anything else is corrupted by that corrupted state.
138
- * See https://github.com/Agoric/agoric-sdk/issues/3434
183
+ * @param {K} [assetKind]
184
+ * @param {AdditionalDisplayInfo} [displayInfo]
185
+ * @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails in
186
+ * the middle of an atomic action (which btw should never happen), it
187
+ * potentially leaves its ledger in a corrupted state. If this function was
188
+ * provided, then the failed atomic action will call it, so that some larger
189
+ * unit of computation, like the enclosing vat, can be shutdown before
190
+ * anything else is corrupted by that corrupted state. See
191
+ * https://github.com/Agoric/agoric-sdk/issues/3434
139
192
  * @param {IssuerOptionsRecord} [options]
140
193
  * @returns {IssuerKit<K>}
141
194
  */
@@ -146,49 +199,138 @@ export const makeDurableIssuerKit = (
146
199
  assetKind = AssetKind.NAT,
147
200
  displayInfo = harden({}),
148
201
  optShutdownWithFailure = undefined,
149
- { elementShape = undefined } = {},
202
+ { elementShape = undefined, recoverySetsOption = undefined } = {},
150
203
  ) => {
151
- const issuerData = harden({ name, assetKind, displayInfo, elementShape });
204
+ const issuerData = harden({
205
+ name,
206
+ assetKind,
207
+ displayInfo,
208
+ elementShape,
209
+ });
152
210
  issuerBaggage.init(INSTANCE_KEY, issuerData);
153
- return setupIssuerKit(issuerData, issuerBaggage, optShutdownWithFailure);
211
+ const issuerZone = makeDurableZone(issuerBaggage);
212
+ const recoverySetsState = recoverySetsOption || 'hasRecoverySets';
213
+ issuerBaggage.init(RECOVERY_SETS_STATE, recoverySetsState);
214
+ return setupIssuerKit(
215
+ issuerData,
216
+ issuerZone,
217
+ recoverySetsState,
218
+ optShutdownWithFailure,
219
+ );
154
220
  };
155
221
  harden(makeDurableIssuerKit);
156
222
 
157
223
  /**
158
- * @template {AssetKind} [K='nat']
159
- * The name becomes part of the brand in asset descriptions.
160
- * The name is useful for debugging and double-checking
161
- * assumptions, but should not be trusted wrt any external namespace.
162
- * For example, anyone could create a new issuer kit with name 'BTC', but
163
- * it is not bitcoin or even related. It is only the name according
164
- * to that issuer and brand.
224
+ * Used to either revive a predecessor issuerKit, or to make a new durable one
225
+ * if it is absent, and to place it in baggage for the next successor.
165
226
  *
166
- * The assetKind will be used to import a specific mathHelpers
167
- * from the mathHelpers library. For example, natMathHelpers, the
168
- * default, is used for basic fungible tokens.
227
+ * @template {AssetKind} K The name becomes part of the brand in asset
228
+ * descriptions. The name is useful for debugging and double-checking
229
+ * assumptions, but should not be trusted wrt any external namespace. For
230
+ * example, anyone could create a new issuer kit with name 'BTC', but it is
231
+ * not bitcoin or even related. It is only the name according to that issuer
232
+ * and brand.
169
233
  *
170
- * `displayInfo` gives information to the UI on how to display the amount.
234
+ * The assetKind will be used to import a specific mathHelpers from the
235
+ * mathHelpers library. For example, natMathHelpers, the default, is used for
236
+ * basic fungible tokens.
171
237
  *
238
+ * `displayInfo` gives information to the UI on how to display the amount.
239
+ * @param {import('@agoric/vat-data').Baggage} issuerBaggage
172
240
  * @param {string} name
173
- * @param {K} [assetKind='nat']
174
- * @param {AdditionalDisplayInfo} [displayInfo={}]
175
- * @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails
176
- * in the middle of an atomic action (which btw should never happen), it
177
- * potentially leaves its ledger in a corrupted state. If this function was
178
- * provided, then the failed atomic action will call it, so that some
179
- * larger unit of computation, like the enclosing vat, can be shutdown
180
- * before anything else is corrupted by that corrupted state.
181
- * See https://github.com/Agoric/agoric-sdk/issues/3434
241
+ * @param {K} [assetKind]
242
+ * @param {AdditionalDisplayInfo} [displayInfo]
243
+ * @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails in
244
+ * the middle of an atomic action (which btw should never happen), it
245
+ * potentially leaves its ledger in a corrupted state. If this function was
246
+ * provided, then the failed atomic action will call it, so that some larger
247
+ * unit of computation, like the enclosing vat, can be shutdown before
248
+ * anything else is corrupted by that corrupted state. See
249
+ * https://github.com/Agoric/agoric-sdk/issues/3434
182
250
  * @param {IssuerOptionsRecord} [options]
183
251
  * @returns {IssuerKit<K>}
184
252
  */
253
+ export const prepareIssuerKit = (
254
+ issuerBaggage,
255
+ name,
256
+ // @ts-expect-error K could be instantiated with a different subtype of AssetKind
257
+ assetKind = AssetKind.NAT,
258
+ displayInfo = harden({}),
259
+ optShutdownWithFailure = undefined,
260
+ options = {},
261
+ ) => {
262
+ if (hasIssuer(issuerBaggage)) {
263
+ const { elementShape: _ = undefined, recoverySetsOption = undefined } =
264
+ options;
265
+ const issuerKit = upgradeIssuerKit(
266
+ issuerBaggage,
267
+ optShutdownWithFailure,
268
+ recoverySetsOption,
269
+ );
270
+
271
+ // TODO check consistency with name, assetKind, displayInfo, elementShape.
272
+ // Consistency either means that these are the same, or that they differ
273
+ // in a direction we are prepared to upgrade. Note that it is the
274
+ // responsibility of `upgradeIssuerKit` to check consistency of
275
+ // `recoverySetsOption`, so continue to not do that here.
276
+
277
+ // @ts-expect-error Type parameter confusion.
278
+ return issuerKit;
279
+ } else {
280
+ const issuerKit = makeDurableIssuerKit(
281
+ issuerBaggage,
282
+ name,
283
+ assetKind,
284
+ displayInfo,
285
+ optShutdownWithFailure,
286
+ options,
287
+ );
288
+ return issuerKit;
289
+ }
290
+ };
291
+ harden(prepareIssuerKit);
292
+
293
+ /**
294
+ * Used _only_ to make a new issuerKit that is effectively non-durable. This is
295
+ * currently done by making a durable one in a baggage not reachable from
296
+ * anywhere. TODO Once rebuilt on zones, this should instead just build on the
297
+ * virtual zone. See https://github.com/Agoric/agoric-sdk/pull/7116
298
+ *
299
+ * Currently used for testing only. Should probably continue to be used for
300
+ * testing only.
301
+ *
302
+ * @template {AssetKind} [K='nat'] The name becomes part of the brand in asset
303
+ * descriptions. The name is useful for debugging and double-checking
304
+ * assumptions, but should not be trusted wrt any external namespace. For
305
+ * example, anyone could create a new issuer kit with name 'BTC', but it is
306
+ * not bitcoin or even related. It is only the name according to that issuer
307
+ * and brand.
308
+ *
309
+ * The assetKind will be used to import a specific mathHelpers from the
310
+ * mathHelpers library. For example, natMathHelpers, the default, is used for
311
+ * basic fungible tokens.
312
+ *
313
+ * `displayInfo` gives information to the UI on how to display the amount.
314
+ * @param {string} name
315
+ * @param {K} [assetKind]
316
+ * @param {AdditionalDisplayInfo} [displayInfo]
317
+ * @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails in
318
+ * the middle of an atomic action (which btw should never happen), it
319
+ * potentially leaves its ledger in a corrupted state. If this function was
320
+ * provided, then the failed atomic action will call it, so that some larger
321
+ * unit of computation, like the enclosing vat, can be shutdown before
322
+ * anything else is corrupted by that corrupted state. See
323
+ * https://github.com/Agoric/agoric-sdk/issues/3434
324
+ * @param {IssuerOptionsRecord} [options]
325
+ * @returns {IssuerKit<K, any>}
326
+ */
185
327
  export const makeIssuerKit = (
186
328
  name,
187
329
  // @ts-expect-error K could be instantiated with a different subtype of AssetKind
188
330
  assetKind = AssetKind.NAT,
189
331
  displayInfo = harden({}),
190
332
  optShutdownWithFailure = undefined,
191
- { elementShape = undefined } = {},
333
+ { elementShape = undefined, recoverySetsOption = undefined } = {},
192
334
  ) =>
193
335
  makeDurableIssuerKit(
194
336
  makeScalarBigMapStore('dropped issuer kit', { durable: true }),
@@ -196,6 +338,6 @@ export const makeIssuerKit = (
196
338
  assetKind,
197
339
  displayInfo,
198
340
  optShutdownWithFailure,
199
- { elementShape },
341
+ { elementShape, recoverySetsOption },
200
342
  );
201
343
  harden(makeIssuerKit);
@@ -1,5 +1,10 @@
1
- export function claim<K extends AssetKind>(recoveryPurse: ERef<Purse<K>>, srcPaymentP: ERef<Payment<K>>, optAmountShape?: Pattern): Promise<Payment<K>>;
1
+ export function claim<P extends Payment>(recoveryPurse: ERef<Purse>, srcPaymentP: ERef<P>, optAmountShape?: Pattern): Promise<P>;
2
2
  export function combine<K extends AssetKind>(recoveryPurse: ERef<Purse<K>>, srcPaymentsPs: ERef<Payment<K>>[], optTotalAmount?: Pattern): Promise<Payment<K>>;
3
3
  export function split<K extends AssetKind>(recoveryPurse: ERef<Purse<K>>, srcPaymentP: ERef<Payment<K>>, paymentAmountA: Amount<K>): Promise<Payment<K>[]>;
4
4
  export function splitMany<K extends AssetKind>(recoveryPurse: ERef<Purse<K>>, srcPaymentP: ERef<Payment<K>>, amounts: Amount<K>[]): Promise<Payment[]>;
5
+ import type { Payment } from './types.js';
6
+ import type { Purse } from './types.js';
7
+ import type { ERef } from '@endo/far';
8
+ import type { AssetKind } from './types.js';
9
+ import type { Amount } from './types.js';
5
10
  //# sourceMappingURL=legacy-payment-helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"legacy-payment-helpers.d.ts","sourceRoot":"","sources":["legacy-payment-helpers.js"],"names":[],"mappings":"AA+BO,0HAHI,OAAO,uBAYjB;AAiBM,gIAHI,OAAO,uBA2BjB;AAiBM,2JAUN;AAkBM,oIAFM,QAAQ,OAAO,EAAE,CAAC,CAoB9B"}
1
+ {"version":3,"file":"legacy-payment-helpers.d.ts","sourceRoot":"","sources":["legacy-payment-helpers.js"],"names":[],"mappings":"AAkCO,sBANgB,CAAC,SAAX,OAAS,iBACX,KAAK,KAAK,CAAC,eACX,KAAK,CAAC,CAAC,mBACP,OAAO,GACL,OAAO,CAAC,CAAC,CAAC,CAYtB;AAiBM,wBANkB,CAAC,SAAb,SAAW,iBACb,KAAK,MAAM,CAAC,CAAC,CAAC,iBACd,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,mBAClB,OAAO,GACL,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CA0B/B;AAgBM,sBANkB,CAAC,SAAb,SAAW,iBACb,KAAK,MAAM,CAAC,CAAC,CAAC,eACd,KAAK,QAAQ,CAAC,CAAC,CAAC,kBAChB,OAAO,CAAC,CAAC,GACP,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAYjC;AAgBM,0BANkB,CAAC,SAAb,SAAW,iBACb,KAAK,MAAM,CAAC,CAAC,CAAC,eACd,KAAK,QAAQ,CAAC,CAAC,CAAC,WAChB,OAAO,CAAC,CAAC,EAAE,GACT,OAAO,CAAC,OAAO,EAAE,CAAC,CAoB9B;6BAzI0F,YAAY;2BAAZ,YAAY;0BADhF,WAAW;+BACyD,YAAY;4BAAZ,YAAY"}
@@ -4,30 +4,33 @@ import { mustMatch } from '@agoric/store';
4
4
  import { E } from '@endo/far';
5
5
  import { AmountMath } from './amountMath.js';
6
6
 
7
+ /**
8
+ * @import {ERef} from '@endo/far');
9
+ * @import {Amount, AssetKind, AmountValue, AssetKindForValue, Payment, Brand, Purse} from './types.js'
10
+ */
11
+
7
12
  const { Fail } = assert;
8
13
 
9
14
  /**
10
- * @file
11
- * This file contains safer helper function alternatives to the
12
- * similarly named methods on issuer.
13
- * These are parameterized by a purse used for recovering lost payments, which
14
- * we call a `recoveryPurse`. Any payments created by these
15
- * helper functions are in the recovery set of that `recoveryPurse` until
16
- * otherwise used up.
15
+ * @file This file contains safer helper function alternatives to the similarly
16
+ * named methods on issuer. These are parameterized by a purse used for
17
+ * recovering lost payments, which we call a `recoveryPurse`. Any payments
18
+ * created by these helper functions are in the recovery set of that
19
+ * `recoveryPurse` until otherwise used up.
17
20
  *
18
- * One of these helper functions is less safe in one way:
19
- * `combine` is not failure atomic. If the `combine` helper function
20
- * fails, some of the input payments may have been used up. However, even
21
- * in that case, no assets would be lost. The assets from the used up payments
22
- * will be in the argument `recoveryPurse`.
21
+ * One of these helper functions is less safe in one way: `combine` is not
22
+ * failure atomic. If the `combine` helper function fails, some of the input
23
+ * payments may have been used up. However, even in that case, no assets would
24
+ * be lost. The assets from the used up payments will be in the argument
25
+ * `recoveryPurse`.
23
26
  */
24
27
 
25
28
  /**
26
- * @template {AssetKind} K
27
- * @param {ERef<Purse<K>>} recoveryPurse
28
- * @param {ERef<Payment<K>>} srcPaymentP
29
+ * @template {Payment} P
30
+ * @param {ERef<Purse>} recoveryPurse
31
+ * @param {ERef<P>} srcPaymentP
29
32
  * @param {Pattern} [optAmountShape]
30
- * @returns {Promise<Payment<K>>}
33
+ * @returns {Promise<P>}
31
34
  */
32
35
  export const claim = async (
33
36
  recoveryPurse,
@@ -35,6 +38,7 @@ export const claim = async (
35
38
  optAmountShape = undefined,
36
39
  ) => {
37
40
  const srcPayment = await srcPaymentP;
41
+ // @ts-expect-error XXX could be instantiated with a different subtype
38
42
  return E.when(E(recoveryPurse).deposit(srcPayment, optAmountShape), amount =>
39
43
  E(recoveryPurse).withdraw(amount),
40
44
  );
@@ -43,11 +47,11 @@ harden(claim);
43
47
 
44
48
  /**
45
49
  * Note: Not failure atomic. But as long as you don't lose the argument
46
- * `recoveryPurse`, no assets are lost.
47
- * If any of the deposits fail, or the total does not
48
- * match optTotalAmount, some payments may still have been deposited. Those
49
- * assets will be in the argument `recoveryPurse`. All undeposited payments
50
- * will still be in the recovery sets of their purses of origin.
50
+ * `recoveryPurse`, no assets are lost. If any of the deposits fail, or the
51
+ * total does not match optTotalAmount, some payments may still have been
52
+ * deposited. Those assets will be in the argument `recoveryPurse`. All
53
+ * undeposited payments will still be in the recovery sets of their purses of
54
+ * origin.
51
55
  *
52
56
  * @template {AssetKind} K
53
57
  * @param {ERef<Purse<K>>} recoveryPurse
@@ -84,11 +88,10 @@ harden(combine);
84
88
 
85
89
  /**
86
90
  * Note: Not failure atomic. But as long as you don't lose the argument
87
- * `recoveryPurse`, no assets are lost.
88
- * If the amount in `srcPaymentP` is not >= `paymentAmountA`, the payment may
89
- * still be deposited anyway, before failing in the subsequent subtract.
90
- * In that case, those
91
- * assets will be in the argument `recoveryPurse`.
91
+ * `recoveryPurse`, no assets are lost. If the amount in `srcPaymentP` is not >=
92
+ * `paymentAmountA`, the payment may still be deposited anyway, before failing
93
+ * in the subsequent subtract. In that case, those assets will be in the
94
+ * argument `recoveryPurse`.
92
95
  *
93
96
  * @template {AssetKind} K
94
97
  * @param {ERef<Purse<K>>} recoveryPurse
@@ -111,12 +114,10 @@ harden(split);
111
114
 
112
115
  /**
113
116
  * Note: Not failure atomic. But as long as you don't lose the argument
114
- * `recoveryPurse`, no assets are lost.
115
- * If the amount in `srcPaymentP` is exactly the sum of the amounts,
116
- * the payment may
117
- * still be deposited anyway, before failing in the subsequent equality check.
118
- * In that case, those
119
- * assets will be in the argument `recoveryPurse`.
117
+ * `recoveryPurse`, no assets are lost. If the amount in `srcPaymentP` is
118
+ * exactly the sum of the amounts, the payment may still be deposited anyway,
119
+ * before failing in the subsequent equality check. In that case, those assets
120
+ * will be in the argument `recoveryPurse`.
120
121
  *
121
122
  * @template {AssetKind} K
122
123
  * @param {ERef<Purse<K>>} recoveryPurse
@@ -1,5 +1,4 @@
1
- /**
2
- * @type {MathHelpers<CopyBag>}
3
- */
4
- export const copyBagMathHelpers: MathHelpers<CopyBag>;
1
+ /** @type {MathHelpers<import('@endo/patterns').CopyBag>} */
2
+ export const copyBagMathHelpers: MathHelpers<import("@endo/patterns").CopyBag>;
3
+ import type { MathHelpers } from '../types.js';
5
4
  //# sourceMappingURL=copyBagMathHelpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"copyBagMathHelpers.d.ts","sourceRoot":"","sources":["copyBagMathHelpers.js"],"names":[],"mappings":"AAiBA;;GAEG;AACH,iCAFU,YAAY,OAAO,CAAC,CAa3B"}
1
+ {"version":3,"file":"copyBagMathHelpers.d.ts","sourceRoot":"","sources":["copyBagMathHelpers.js"],"names":[],"mappings":"AAkBA,4DAA4D;AAC5D,iCADW,YAAY,OAAO,gBAAgB,EAAE,OAAO,CAAC,CAYrD;iCAjB4B,aAAa"}
@@ -10,14 +10,13 @@ import {
10
10
  bagUnion,
11
11
  bagDisjointSubtract,
12
12
  } from '@agoric/store';
13
- import '../types-ambient.js';
14
13
 
15
- /** @type {CopyBag} */
14
+ /** @import {MathHelpers} from '../types.js' */
15
+
16
+ /** @type {import('@endo/patterns').CopyBag} */
16
17
  const empty = makeCopyBag([]);
17
18
 
18
- /**
19
- * @type {MathHelpers<CopyBag>}
20
- */
19
+ /** @type {MathHelpers<import('@endo/patterns').CopyBag>} */
21
20
  export const copyBagMathHelpers = harden({
22
21
  doCoerce: bag => {
23
22
  mustMatch(bag, M.bag(), 'bag of amount');
@@ -1,5 +1,5 @@
1
- /**
2
- * @type {MathHelpers<CopySet>}
3
- */
1
+ /** @type {MathHelpers<CopySet>} */
4
2
  export const copySetMathHelpers: MathHelpers<CopySet>;
3
+ import type { CopySet } from '@endo/patterns';
4
+ import type { MathHelpers } from '../types.js';
5
5
  //# sourceMappingURL=copySetMathHelpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"copySetMathHelpers.d.ts","sourceRoot":"","sources":["copySetMathHelpers.js"],"names":[],"mappings":"AAiBA;;GAEG;AACH,iCAFU,YAAY,OAAO,CAAC,CAa3B"}
1
+ {"version":3,"file":"copySetMathHelpers.d.ts","sourceRoot":"","sources":["copySetMathHelpers.js"],"names":[],"mappings":"AAqBA,mCAAmC;AACnC,iCADW,YAAY,OAAO,CAAC,CAY5B;6BAlBuB,gBAAgB;iCADZ,aAAa"}
@@ -10,14 +10,16 @@ import {
10
10
  setDisjointUnion,
11
11
  setDisjointSubtract,
12
12
  } from '@agoric/store';
13
- import '../types-ambient.js';
13
+
14
+ /**
15
+ * @import {MathHelpers} from '../types.js'
16
+ * @import {CopySet} from '@endo/patterns'
17
+ */
14
18
 
15
19
  /** @type {CopySet} */
16
20
  const empty = makeCopySet([]);
17
21
 
18
- /**
19
- * @type {MathHelpers<CopySet>}
20
- */
22
+ /** @type {MathHelpers<CopySet>} */
21
23
  export const copySetMathHelpers = harden({
22
24
  doCoerce: set => {
23
25
  mustMatch(set, M.set(), 'set of amount');
@@ -1,14 +1,15 @@
1
1
  /**
2
- * Fungible digital assets use the natMathHelpers to manage balances -
3
- * the operations are merely arithmetic on natural, non-negative
4
- * numbers.
2
+ * Fungible digital assets use the natMathHelpers to manage balances - the
3
+ * operations are merely arithmetic on natural, non-negative numbers.
5
4
  *
6
- * Natural numbers are used for fungible erights such as money because
7
- * rounding issues make floats problematic. All operations should be
8
- * done with the smallest whole unit such that the `natMathHelpers` never
9
- * deals with fractional parts.
5
+ * Natural numbers are used for fungible erights such as money because rounding
6
+ * issues make floats problematic. All operations should be done with the
7
+ * smallest whole unit such that the `natMathHelpers` never deals with
8
+ * fractional parts.
10
9
  *
11
10
  * @type {MathHelpers<NatValue>}
12
11
  */
13
12
  export const natMathHelpers: MathHelpers<NatValue>;
13
+ import type { NatValue } from '../types.js';
14
+ import type { MathHelpers } from '../types.js';
14
15
  //# sourceMappingURL=natMathHelpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"natMathHelpers.d.ts","sourceRoot":"","sources":["natMathHelpers.js"],"names":[],"mappings":"AASA;;;;;;;;;;;GAWG;AACH,6BAFU,YAAY,QAAQ,CAAC,CAgB5B"}
1
+ {"version":3,"file":"natMathHelpers.d.ts","sourceRoot":"","sources":["natMathHelpers.js"],"names":[],"mappings":"AASA;;;;;;;;;;GAUG;AACH,6BAFU,YAAY,QAAQ,CAAC,CAgB5B;8BA9BsC,aAAa;iCAAb,aAAa"}