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