@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/ertp",
3
- "version": "0.16.3-mainnet1B-dev-26244e8.0+26244e8",
3
+ "version": "0.16.3-orchestration-dev-096c4e8.0+096c4e8",
4
4
  "description": "Electronic Rights Transfer Protocol (ERTP). A smart contract framework for exchanging electronic rights",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "scripts": {
11
11
  "build": "exit 0",
12
- "prepack": "echo \"export {}; \" | cat - src/types-ambient.js > src/types.js && tsc --build jsconfig.build.json",
12
+ "prepack": "echo \"export {}; \" | cat - src/types-ambient.js > src/types.js && tsc --build --clean tsconfig.build.json",
13
13
  "postpack": "git clean -f '*.d.ts*' src/types.js",
14
14
  "test": "ava",
15
15
  "test:c8": "c8 $C8_OPTIONS ava",
@@ -19,7 +19,7 @@
19
19
  "lint-fix": "yarn lint:eslint --fix",
20
20
  "lint": "run-s --continue-on-error lint:*",
21
21
  "lint:eslint": "eslint .",
22
- "lint:types": "tsc -p jsconfig.json"
22
+ "lint:types": "tsc"
23
23
  },
24
24
  "repository": {
25
25
  "type": "git",
@@ -39,22 +39,24 @@
39
39
  },
40
40
  "homepage": "https://github.com/Agoric/agoric-sdk#readme",
41
41
  "dependencies": {
42
- "@agoric/assert": "0.6.1-mainnet1B-dev-26244e8.0+26244e8",
43
- "@agoric/notifier": "0.6.3-mainnet1B-dev-26244e8.0+26244e8",
44
- "@agoric/store": "0.9.3-mainnet1B-dev-26244e8.0+26244e8",
45
- "@agoric/swingset-vat": "0.32.3-mainnet1B-dev-26244e8.0+26244e8",
46
- "@agoric/vat-data": "0.5.3-mainnet1B-dev-26244e8.0+26244e8",
47
- "@endo/eventual-send": "0.17.2",
48
- "@endo/far": "0.2.18",
49
- "@endo/marshal": "0.8.5",
50
- "@endo/nat": "4.1.27",
51
- "@endo/promise-kit": "0.2.56"
42
+ "@agoric/assert": "0.6.1-orchestration-dev-096c4e8.0+096c4e8",
43
+ "@agoric/notifier": "0.6.3-orchestration-dev-096c4e8.0+096c4e8",
44
+ "@agoric/store": "0.9.3-orchestration-dev-096c4e8.0+096c4e8",
45
+ "@agoric/vat-data": "0.5.3-orchestration-dev-096c4e8.0+096c4e8",
46
+ "@agoric/zone": "0.2.3-orchestration-dev-096c4e8.0+096c4e8",
47
+ "@endo/eventual-send": "^1.1.2",
48
+ "@endo/far": "^1.0.4",
49
+ "@endo/marshal": "^1.3.0",
50
+ "@endo/nat": "^5.0.4",
51
+ "@endo/patterns": "^1.2.0",
52
+ "@endo/promise-kit": "^1.0.4"
52
53
  },
53
54
  "devDependencies": {
54
- "@endo/bundle-source": "2.5.2-upstream-rollup",
55
- "@fast-check/ava": "^1.1.3",
56
- "ava": "^5.2.0",
57
- "tsd": "^0.28.1"
55
+ "@agoric/swingset-vat": "0.32.3-orchestration-dev-096c4e8.0+096c4e8",
56
+ "@endo/bundle-source": "^3.1.0",
57
+ "@fast-check/ava": "^1.1.5",
58
+ "ava": "^5.3.0",
59
+ "tsd": "^0.30.4"
58
60
  },
59
61
  "files": [
60
62
  "src",
@@ -74,10 +76,16 @@
74
76
  "files": [
75
77
  "test/**/test-*.js"
76
78
  ],
79
+ "require": [
80
+ "@endo/init/debug.js"
81
+ ],
77
82
  "timeout": "5m"
78
83
  },
79
84
  "publishConfig": {
80
85
  "access": "public"
81
86
  },
82
- "gitHead": "26244e821f1a83cd5868f0c7d54aa480c8c17e5e"
87
+ "typeCoverage": {
88
+ "atLeast": 90.56
89
+ },
90
+ "gitHead": "096c4e8fce80e9a509b0e1a30fda11736c4570e1"
83
91
  }
package/src/amountMath.js CHANGED
@@ -11,7 +11,12 @@ const { quote: q, Fail } = assert;
11
11
  /**
12
12
  * Constants for the kinds of assets we support.
13
13
  *
14
- * @type {{ NAT: 'nat', SET: 'set', COPY_SET: 'copySet', COPY_BAG: 'copyBag' }}
14
+ * @type {{
15
+ * NAT: 'nat';
16
+ * SET: 'set';
17
+ * COPY_SET: 'copySet';
18
+ * COPY_BAG: 'copyBag';
19
+ * }}
15
20
  */
16
21
  const AssetKind = harden({
17
22
  NAT: 'nat',
@@ -21,9 +26,7 @@ const AssetKind = harden({
21
26
  });
22
27
  const assetKindNames = harden(Object.values(AssetKind).sort());
23
28
 
24
- /**
25
- * @param {AssetKind} allegedAK
26
- */
29
+ /** @param {AssetKind} allegedAK */
27
30
  const assertAssetKind = allegedAK => {
28
31
  assetKindNames.includes(allegedAK) ||
29
32
  Fail`The assetKind ${allegedAK} must be one of ${q(assetKindNames)}`;
@@ -31,42 +34,37 @@ const assertAssetKind = allegedAK => {
31
34
  harden(assertAssetKind);
32
35
 
33
36
  /**
34
- * Amounts describe digital assets. From an amount, you can learn the
35
- * brand of digital asset as well as "how much" or "how many". Amounts
36
- * have two parts: a brand (loosely speaking, the type of digital
37
- * asset) and the value (the answer to "how much"). For example, in
38
- * the phrase "5 bucks", "bucks" takes the role of the brand and the
39
- * value is 5. Amounts can describe fungible and non-fungible digital
40
- * assets. Amounts are pass-by-copy and can be made by and sent to
41
- * anyone.
37
+ * Amounts describe digital assets. From an amount, you can learn the brand of
38
+ * digital asset as well as "how much" or "how many". Amounts have two parts: a
39
+ * brand (loosely speaking, the type of digital asset) and the value (the answer
40
+ * to "how much"). For example, in the phrase "5 bucks", "bucks" takes the role
41
+ * of the brand and the value is 5. Amounts can describe fungible and
42
+ * non-fungible digital assets. Amounts are pass-by-copy and can be made by and
43
+ * sent to anyone.
42
44
  *
43
- * The issuer is the authoritative source of the amount in payments
44
- * and purses. The issuer must be able to do things such as add
45
- * digital assets to a purse and withdraw digital assets from a purse.
46
- * To do so, it must know how to add and subtract digital assets.
47
- * Rather than hard-coding a particular solution, we chose to
48
- * parameterize the issuer with a collection of polymorphic functions,
49
- * which we call `AmountMath`. These math functions include concepts
45
+ * The issuer is the authoritative source of the amount in payments and purses.
46
+ * The issuer must be able to do things such as add digital assets to a purse
47
+ * and withdraw digital assets from a purse. To do so, it must know how to add
48
+ * and subtract digital assets. Rather than hard-coding a particular solution,
49
+ * we chose to parameterize the issuer with a collection of polymorphic
50
+ * functions, which we call `AmountMath`. These math functions include concepts
50
51
  * like addition, subtraction, and greater than or equal to.
51
52
  *
52
- * We also want to make sure there is no confusion as to what kind of
53
- * asset we are using. Thus, AmountMath includes checks of the
54
- * `brand`, the unique identifier for the type of digital asset. If
55
- * the wrong brand is used in AmountMath, an error is thrown and the
56
- * operation does not succeed.
53
+ * We also want to make sure there is no confusion as to what kind of asset we
54
+ * are using. Thus, AmountMath includes checks of the `brand`, the unique
55
+ * identifier for the type of digital asset. If the wrong brand is used in
56
+ * AmountMath, an error is thrown and the operation does not succeed.
57
57
  *
58
- * AmountMath uses mathHelpers to do most of the work, but then adds
59
- * the brand to the result. The function `value` gets the value from
60
- * the amount by removing the brand (amount -> value), and the
61
- * function `make` adds the brand to produce an amount (value ->
62
- * amount). The function `coerce` takes an amount and checks it,
63
- * returning an amount (amount -> amount).
58
+ * AmountMath uses mathHelpers to do most of the work, but then adds the brand
59
+ * to the result. The function `value` gets the value from the amount by
60
+ * removing the brand (amount -> value), and the function `make` adds the brand
61
+ * to produce an amount (value -> amount). The function `coerce` takes an amount
62
+ * and checks it, returning an amount (amount -> amount).
64
63
  *
65
- * Each issuer of digital assets has an associated brand in a
66
- * one-to-one mapping. In untrusted contexts, such as in analyzing
67
- * payments and amounts, we can get the brand and find the issuer
68
- * which matches the brand. The issuer and the brand mutually validate
69
- * each other.
64
+ * Each issuer of digital assets has an associated brand in a one-to-one
65
+ * mapping. In untrusted contexts, such as in analyzing payments and amounts, we
66
+ * can get the brand and find the issuer which matches the brand. The issuer and
67
+ * the brand mutually validate each other.
70
68
  */
71
69
 
72
70
  const helpers = {
@@ -137,7 +135,7 @@ const optionalBrandCheck = (allegedBrand, brand) => {
137
135
  * @param {Amount<K>} leftAmount
138
136
  * @param {Amount<K>} rightAmount
139
137
  * @param {Brand<K> | undefined} brand
140
- * @returns {MathHelpers<*>}
138
+ * @returns {MathHelpers<any>}
141
139
  */
142
140
  const checkLRAndGetHelpers = (leftAmount, rightAmount, brand = undefined) => {
143
141
  assertRecord(leftAmount, 'leftAmount');
@@ -172,11 +170,11 @@ const coerceLR = (h, leftAmount, rightAmount) => {
172
170
  };
173
171
 
174
172
  /**
175
- * Returns true if the leftAmount is greater than or equal to the
176
- * rightAmount. The notion of "greater than or equal to" depends
177
- * on the kind of amount, as defined by the MathHelpers. For example,
178
- * whether rectangle A is greater than rectangle B depends on whether rectangle
179
- * A includes rectangle B as defined by the logic in MathHelpers.
173
+ * Returns true if the leftAmount is greater than or equal to the rightAmount.
174
+ * The notion of "greater than or equal to" depends on the kind of amount, as
175
+ * defined by the MathHelpers. For example, whether rectangle A is greater than
176
+ * rectangle B depends on whether rectangle A includes rectangle B as defined by
177
+ * the logic in MathHelpers.
180
178
  *
181
179
  * @template {AssetKind} K
182
180
  * @param {Amount<K>} leftAmount
@@ -194,9 +192,8 @@ const isGTE = (leftAmount, rightAmount, brand = undefined) => {
194
192
  *
195
193
  * Amounts are the canonical description of tradable goods. They are manipulated
196
194
  * by issuers and mints, and represent the goods and currency carried by purses
197
- * and
198
- * payments. They can be used to represent things like currency, stock, and the
199
- * abstract right to participate in a particular exchange.
195
+ * and payments. They can be used to represent things like currency, stock, and
196
+ * the abstract right to participate in a particular exchange.
200
197
  */
201
198
  const AmountMath = {
202
199
  /**
@@ -215,8 +212,8 @@ const AmountMath = {
215
212
  return harden({ brand, value });
216
213
  },
217
214
  /**
218
- * Make sure this amount is valid enough, and return a corresponding
219
- * valid amount if so.
215
+ * Make sure this amount is valid enough, and return a corresponding valid
216
+ * amount if so.
220
217
  *
221
218
  * @template {AssetKind} K
222
219
  * @param {Brand<K>} brand
@@ -242,8 +239,8 @@ const AmountMath = {
242
239
  */
243
240
  getValue: (brand, amount) => AmountMath.coerce(brand, amount).value,
244
241
  /**
245
- * Return the amount representing an empty amount. This is the
246
- * identity element for MathHelpers.add and MatHelpers.subtract.
242
+ * Return the amount representing an empty amount. This is the identity
243
+ * element for MathHelpers.add and MatHelpers.subtract.
247
244
  *
248
245
  * @type {{
249
246
  * (brand: Brand): Amount<'nat'>;
@@ -257,8 +254,8 @@ const AmountMath = {
257
254
  return harden({ brand, value });
258
255
  },
259
256
  /**
260
- * Return the amount representing an empty amount, using another
261
- * amount as the template for the brand and assetKind.
257
+ * Return the amount representing an empty amount, using another amount as the
258
+ * template for the brand and assetKind.
262
259
  *
263
260
  * @template {AssetKind} K
264
261
  * @param {Amount<K>} amount
@@ -289,8 +286,8 @@ const AmountMath = {
289
286
  },
290
287
  isGTE,
291
288
  /**
292
- * Returns true if the leftAmount equals the rightAmount. We assume
293
- * that if isGTE is true in both directions, isEqual is also true
289
+ * Returns true if the leftAmount equals the rightAmount. We assume that if
290
+ * isGTE is true in both directions, isEqual is also true
294
291
  *
295
292
  * @template {AssetKind} K
296
293
  * @param {Amount<K>} leftAmount
@@ -306,8 +303,8 @@ const AmountMath = {
306
303
  * Returns a new amount that is the union of both leftAmount and rightAmount.
307
304
  *
308
305
  * For fungible amount this means adding the values. For other kinds of
309
- * amount, it usually means including all of the elements from both
310
- * left and right.
306
+ * amount, it usually means including all of the elements from both left and
307
+ * right.
311
308
  *
312
309
  * @template {AssetKind} K
313
310
  * @param {Amount<K>} leftAmount
@@ -321,12 +318,11 @@ const AmountMath = {
321
318
  return harden({ brand: leftAmount.brand, value });
322
319
  },
323
320
  /**
324
- * Returns a new amount that is the leftAmount minus the rightAmount
325
- * (i.e. everything in the leftAmount that is not in the
326
- * rightAmount). If leftAmount doesn't include rightAmount
327
- * (subtraction results in a negative), throw an error. Because the
328
- * left amount must include the right amount, this is NOT equivalent
329
- * to set subtraction.
321
+ * Returns a new amount that is the leftAmount minus the rightAmount (i.e.
322
+ * everything in the leftAmount that is not in the rightAmount). If leftAmount
323
+ * doesn't include rightAmount (subtraction results in a negative), throw an
324
+ * error. Because the left amount must include the right amount, this is NOT
325
+ * equivalent to set subtraction.
330
326
  *
331
327
  * @template {AssetKind} K
332
328
  * @param {Amount<K>} leftAmount
@@ -374,9 +370,7 @@ const AmountMath = {
374
370
  };
375
371
  harden(AmountMath);
376
372
 
377
- /**
378
- * @param {Amount} amount
379
- */
373
+ /** @param {Amount} amount */
380
374
  const getAssetKind = amount => {
381
375
  assertRecord(amount, 'amount');
382
376
  const { value } = amount;
@@ -0,0 +1,32 @@
1
+ import { AmountMath } from './amountMath.js';
2
+
3
+ /**
4
+ * @template {AssetKind} [K=AssetKind]
5
+ * @typedef {object} AmountStore
6
+ * @property {() => Amount<K>} getAmount
7
+ * @property {(delta: Amount<K>) => void} increment
8
+ * @property {(delta: Amount<K>) => boolean} decrement
9
+ */
10
+
11
+ /**
12
+ * @template {AssetKind} [K=AssetKind]
13
+ * @param {object} state
14
+ * @param {string} key
15
+ * @returns {AmountStore<K>}
16
+ */
17
+ export const makeAmountStore = (state, key) => {
18
+ return harden({
19
+ getAmount: () => state[key],
20
+ increment: delta => {
21
+ state[key] = AmountMath.add(state[key], delta);
22
+ },
23
+ decrement: delta => {
24
+ if (AmountMath.isGTE(state[key], delta)) {
25
+ state[key] = AmountMath.subtract(state[key], delta);
26
+ return true;
27
+ }
28
+ return false;
29
+ },
30
+ });
31
+ };
32
+ harden(makeAmountStore);
package/src/index.js CHANGED
@@ -3,3 +3,10 @@
3
3
  export * from './amountMath.js';
4
4
  export * from './issuerKit.js';
5
5
  export * from './typeGuards.js';
6
+
7
+ /**
8
+ * Importing Baggage from `@agoric/ertp` is deprecated. Import Baggage from
9
+ * `@agoric/vat-data` instead
10
+ *
11
+ * @typedef {import('@agoric/vat-data').Baggage} Baggage
12
+ */