@agoric/ertp 0.16.3-mainnet1B-dev-b0c1f78.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.
- package/package.json +26 -18
- package/src/amountMath.js +57 -63
- package/src/amountStore.js +32 -0
- package/src/index.js +7 -0
- package/src/issuerKit.js +218 -74
- package/src/legacy-payment-helpers.js +23 -28
- package/src/mathHelpers/copyBagMathHelpers.js +2 -4
- package/src/mathHelpers/copySetMathHelpers.js +1 -3
- package/src/mathHelpers/natMathHelpers.js +6 -7
- package/src/payment.js +5 -8
- package/src/paymentLedger.js +84 -91
- package/src/purse.js +83 -24
- package/src/typeGuards.js +37 -43
- package/src/types-ambient.js +237 -314
- package/src/types.js +237 -314
- package/CHANGELOG.md +0 -767
- package/src/amountMath.d.ts +0 -53
- package/src/amountMath.d.ts.map +0 -1
- package/src/displayInfo.d.ts +0 -2
- package/src/displayInfo.d.ts.map +0 -1
- package/src/index.d.ts +0 -4
- package/src/index.d.ts.map +0 -1
- package/src/issuerKit.d.ts +0 -19
- package/src/issuerKit.d.ts.map +0 -1
- package/src/legacy-payment-helpers.d.ts +0 -5
- package/src/legacy-payment-helpers.d.ts.map +0 -1
- package/src/mathHelpers/copyBagMathHelpers.d.ts +0 -5
- package/src/mathHelpers/copyBagMathHelpers.d.ts.map +0 -1
- package/src/mathHelpers/copySetMathHelpers.d.ts +0 -5
- package/src/mathHelpers/copySetMathHelpers.d.ts.map +0 -1
- package/src/mathHelpers/natMathHelpers.d.ts +0 -14
- package/src/mathHelpers/natMathHelpers.d.ts.map +0 -1
- package/src/mathHelpers/setMathHelpers.d.ts +0 -6
- package/src/mathHelpers/setMathHelpers.d.ts.map +0 -1
- package/src/payment.d.ts +0 -3
- package/src/payment.d.ts.map +0 -1
- package/src/paymentLedger.d.ts +0 -3
- package/src/paymentLedger.d.ts.map +0 -1
- package/src/purse.d.ts +0 -13
- package/src/purse.d.ts.map +0 -1
- package/src/transientNotifier.d.ts +0 -5
- package/src/transientNotifier.d.ts.map +0 -1
- package/src/typeGuards.d.ts +0 -42
- package/src/typeGuards.d.ts.map +0 -1
- package/src/types-ambient.d.ts +0 -376
- package/src/types-ambient.d.ts.map +0 -1
- package/src/types.d.ts +0 -376
- 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-
|
|
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
|
|
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
|
|
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-
|
|
43
|
-
"@agoric/notifier": "0.6.3-
|
|
44
|
-
"@agoric/store": "0.9.3-
|
|
45
|
-
"@agoric/
|
|
46
|
-
"@agoric/
|
|
47
|
-
"@endo/eventual-send": "
|
|
48
|
-
"@endo/far": "0.
|
|
49
|
-
"@endo/marshal": "
|
|
50
|
-
"@endo/nat": "
|
|
51
|
-
"@endo/
|
|
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
|
-
"@
|
|
55
|
-
"@
|
|
56
|
-
"ava": "^
|
|
57
|
-
"
|
|
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
|
-
"
|
|
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 {{
|
|
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
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* the
|
|
39
|
-
*
|
|
40
|
-
*
|
|
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
|
-
*
|
|
45
|
-
* digital assets
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
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
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
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
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
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
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
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
|
-
*
|
|
177
|
-
*
|
|
178
|
-
* whether rectangle A
|
|
179
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
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
|
+
*/
|