@agoric/ertp 0.16.3-dev-57802f9.0 → 0.16.3-other-dev-70beeb7.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/CHANGELOG.md +743 -0
- package/package.json +17 -21
- package/src/amountMath.d.ts +13 -14
- package/src/amountMath.d.ts.map +1 -1
- package/src/amountMath.js +63 -57
- package/src/issuerKit.d.ts +3 -3
- package/src/issuerKit.d.ts.map +1 -1
- package/src/issuerKit.js +61 -55
- package/src/legacy-payment-helpers.d.ts.map +1 -1
- package/src/legacy-payment-helpers.js +28 -23
- package/src/mathHelpers/copyBagMathHelpers.d.ts +3 -1
- package/src/mathHelpers/copyBagMathHelpers.d.ts.map +1 -1
- package/src/mathHelpers/copyBagMathHelpers.js +3 -1
- package/src/mathHelpers/copySetMathHelpers.d.ts +3 -1
- package/src/mathHelpers/copySetMathHelpers.d.ts.map +1 -1
- package/src/mathHelpers/copySetMathHelpers.js +3 -1
- package/src/mathHelpers/natMathHelpers.d.ts +7 -6
- package/src/mathHelpers/natMathHelpers.d.ts.map +1 -1
- package/src/mathHelpers/natMathHelpers.js +7 -6
- package/src/payment.d.ts +1 -3
- package/src/payment.d.ts.map +1 -1
- package/src/payment.js +0 -5
- package/src/paymentLedger.d.ts +1 -1
- package/src/paymentLedger.d.ts.map +1 -1
- package/src/paymentLedger.js +40 -36
- package/src/typeGuards.d.ts +6 -36
- package/src/typeGuards.d.ts.map +1 -1
- package/src/typeGuards.js +43 -37
- package/src/types-ambient.d.ts +174 -178
- package/src/types-ambient.d.ts.map +1 -1
- package/src/types-ambient.js +280 -217
- package/src/types.d.ts +174 -178
- package/src/types.d.ts.map +1 -1
- package/src/types.js +280 -217
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/ertp",
|
|
3
|
-
"version": "0.16.3-dev-
|
|
3
|
+
"version": "0.16.3-other-dev-70beeb7.0+70beeb7",
|
|
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 jsconfig.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 -p jsconfig.json"
|
|
23
23
|
},
|
|
24
24
|
"repository": {
|
|
25
25
|
"type": "git",
|
|
@@ -39,22 +39,21 @@
|
|
|
39
39
|
},
|
|
40
40
|
"homepage": "https://github.com/Agoric/agoric-sdk#readme",
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@agoric/assert": "0.6.1-dev-
|
|
43
|
-
"@agoric/notifier": "0.6.3-dev-
|
|
44
|
-
"@agoric/store": "0.9.3-dev-
|
|
45
|
-
"@agoric/vat
|
|
46
|
-
"@
|
|
47
|
-
"@endo/
|
|
48
|
-
"@endo/
|
|
49
|
-
"@endo/
|
|
50
|
-
"@endo/
|
|
51
|
-
"@endo/promise-kit": "
|
|
42
|
+
"@agoric/assert": "0.6.1-other-dev-70beeb7.0+70beeb7",
|
|
43
|
+
"@agoric/notifier": "0.6.3-other-dev-70beeb7.0+70beeb7",
|
|
44
|
+
"@agoric/store": "0.9.3-other-dev-70beeb7.0+70beeb7",
|
|
45
|
+
"@agoric/swingset-vat": "0.32.3-other-dev-70beeb7.0+70beeb7",
|
|
46
|
+
"@agoric/vat-data": "0.5.3-other-dev-70beeb7.0+70beeb7",
|
|
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"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@
|
|
55
|
-
"@
|
|
56
|
-
"
|
|
57
|
-
"ava": "^5.3.0",
|
|
54
|
+
"@endo/bundle-source": "2.5.2-upstream-rollup",
|
|
55
|
+
"@fast-check/ava": "^1.1.3",
|
|
56
|
+
"ava": "^5.2.0",
|
|
58
57
|
"tsd": "^0.28.1"
|
|
59
58
|
},
|
|
60
59
|
"files": [
|
|
@@ -75,13 +74,10 @@
|
|
|
75
74
|
"files": [
|
|
76
75
|
"test/**/test-*.js"
|
|
77
76
|
],
|
|
78
|
-
"require": [
|
|
79
|
-
"@endo/init/debug.js"
|
|
80
|
-
],
|
|
81
77
|
"timeout": "5m"
|
|
82
78
|
},
|
|
83
79
|
"publishConfig": {
|
|
84
80
|
"access": "public"
|
|
85
81
|
},
|
|
86
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "70beeb7e476f24cfad30fa8cd5918f04746e8839"
|
|
87
83
|
}
|
package/src/amountMath.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export namespace AmountMath {
|
|
|
3
3
|
export function make<K extends AssetKind>(brand: Brand<K>, allegedValue: AssetValueForKind<K>): Amount<K>;
|
|
4
4
|
export function coerce<K extends AssetKind>(brand: Brand<K>, allegedAmount: Amount<K>): Amount<K>;
|
|
5
5
|
export function getValue<K extends AssetKind>(brand: Brand<K>, amount: Amount<K>): AssetValueForKind<K>;
|
|
6
|
-
export
|
|
6
|
+
export const makeEmpty: {
|
|
7
7
|
(brand: Brand<AssetKind>): Amount<"nat">;
|
|
8
8
|
<K extends AssetKind>(brand: Brand<AssetKind>, assetKind: K): Amount<K>;
|
|
9
9
|
};
|
|
@@ -19,12 +19,7 @@ export namespace AmountMath {
|
|
|
19
19
|
/**
|
|
20
20
|
* Constants for the kinds of assets we support.
|
|
21
21
|
*
|
|
22
|
-
* @type {{
|
|
23
|
-
* NAT: 'nat';
|
|
24
|
-
* SET: 'set';
|
|
25
|
-
* COPY_SET: 'copySet';
|
|
26
|
-
* COPY_BAG: 'copyBag';
|
|
27
|
-
* }}
|
|
22
|
+
* @type {{ NAT: 'nat', SET: 'set', COPY_SET: 'copySet', COPY_BAG: 'copyBag' }}
|
|
28
23
|
*/
|
|
29
24
|
export const AssetKind: {
|
|
30
25
|
NAT: 'nat';
|
|
@@ -32,16 +27,20 @@ export const AssetKind: {
|
|
|
32
27
|
COPY_SET: 'copySet';
|
|
33
28
|
COPY_BAG: 'copyBag';
|
|
34
29
|
};
|
|
35
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* @param {Amount} amount
|
|
32
|
+
*/
|
|
36
33
|
export function getAssetKind(amount: Amount): AssetKindForValue<V>;
|
|
37
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* @param {AssetKind} allegedAK
|
|
36
|
+
*/
|
|
38
37
|
export function assertAssetKind(allegedAK: AssetKind): void;
|
|
39
38
|
/**
|
|
40
|
-
* Returns true if the leftAmount is greater than or equal to the
|
|
41
|
-
* The notion of "greater than or equal to" depends
|
|
42
|
-
* defined by the MathHelpers. For example,
|
|
43
|
-
*
|
|
44
|
-
* the logic in MathHelpers.
|
|
39
|
+
* Returns true if the leftAmount is greater than or equal to the
|
|
40
|
+
* rightAmount. The notion of "greater than or equal to" depends
|
|
41
|
+
* on the kind of amount, as defined by the MathHelpers. For example,
|
|
42
|
+
* whether rectangle A is greater than rectangle B depends on whether rectangle
|
|
43
|
+
* A includes rectangle B as defined by the logic in MathHelpers.
|
|
45
44
|
*
|
|
46
45
|
* @template {AssetKind} K
|
|
47
46
|
* @param {Amount<K>} leftAmount
|
package/src/amountMath.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amountMath.d.ts","sourceRoot":"","sources":["amountMath.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"amountMath.d.ts","sourceRoot":"","sources":["amountMath.js"],"names":[],"mappings":"AAuHO,uFAEkC;;IAyFjC,0GAKL;IAUO,kGAQP;IASS,wGAAyD;;;;;IAwB9C,uFAOpB;IAQQ,kGAOR;;IAYQ,mIAGR;IAcI,iIAIJ;IAeS,sIAIT;IAUI,8GAMqC;IAUrC,8GAMqC;;AA1W5C;;;;GAIG;AACH,wBAFU;IAAE,GAAG,EAAE,KAAK,CAAC;IAAC,GAAG,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAA;CAAE,CAO3E;AAoWH;;GAEG;AACH,qCAFW,MAAM,wBAOhB;AAzWD;;GAEG;AACH,2CAFW,SAAS,QAKnB;AAgJD;;;;;;;;;;;;GAYG;AACH,0HAFa,OAAO,CAKnB"}
|
package/src/amountMath.js
CHANGED
|
@@ -11,12 +11,7 @@ const { quote: q, Fail } = assert;
|
|
|
11
11
|
/**
|
|
12
12
|
* Constants for the kinds of assets we support.
|
|
13
13
|
*
|
|
14
|
-
* @type {{
|
|
15
|
-
* NAT: 'nat';
|
|
16
|
-
* SET: 'set';
|
|
17
|
-
* COPY_SET: 'copySet';
|
|
18
|
-
* COPY_BAG: 'copyBag';
|
|
19
|
-
* }}
|
|
14
|
+
* @type {{ NAT: 'nat', SET: 'set', COPY_SET: 'copySet', COPY_BAG: 'copyBag' }}
|
|
20
15
|
*/
|
|
21
16
|
const AssetKind = harden({
|
|
22
17
|
NAT: 'nat',
|
|
@@ -26,7 +21,9 @@ const AssetKind = harden({
|
|
|
26
21
|
});
|
|
27
22
|
const assetKindNames = harden(Object.values(AssetKind).sort());
|
|
28
23
|
|
|
29
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* @param {AssetKind} allegedAK
|
|
26
|
+
*/
|
|
30
27
|
const assertAssetKind = allegedAK => {
|
|
31
28
|
assetKindNames.includes(allegedAK) ||
|
|
32
29
|
Fail`The assetKind ${allegedAK} must be one of ${q(assetKindNames)}`;
|
|
@@ -34,37 +31,42 @@ const assertAssetKind = allegedAK => {
|
|
|
34
31
|
harden(assertAssetKind);
|
|
35
32
|
|
|
36
33
|
/**
|
|
37
|
-
* Amounts describe digital assets. From an amount, you can learn the
|
|
38
|
-
* digital asset as well as "how much" or "how many". Amounts
|
|
39
|
-
* brand (loosely speaking, the type of digital
|
|
40
|
-
* to "how much"). For example, in
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* sent to
|
|
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.
|
|
44
42
|
*
|
|
45
|
-
* The issuer is the authoritative source of the amount in payments
|
|
46
|
-
* The issuer must be able to do things such as add
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
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
|
|
51
50
|
* like addition, subtraction, and greater than or equal to.
|
|
52
51
|
*
|
|
53
|
-
* We also want to make sure there is no confusion as to what kind of
|
|
54
|
-
* are using. Thus, AmountMath includes checks of the
|
|
55
|
-
* identifier for the type of digital asset. If
|
|
56
|
-
* AmountMath, an error is thrown and the
|
|
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.
|
|
57
57
|
*
|
|
58
|
-
* AmountMath uses mathHelpers to do most of the work, but then adds
|
|
59
|
-
* to the result. The function `value` gets the value from
|
|
60
|
-
* removing the brand (amount -> value), and the
|
|
61
|
-
* to produce an amount (value ->
|
|
62
|
-
*
|
|
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).
|
|
63
64
|
*
|
|
64
|
-
* Each issuer of digital assets has an associated brand in a
|
|
65
|
-
* mapping. In untrusted contexts, such as in analyzing
|
|
66
|
-
* can get the brand and find the issuer
|
|
67
|
-
* the brand mutually validate
|
|
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.
|
|
68
70
|
*/
|
|
69
71
|
|
|
70
72
|
const helpers = {
|
|
@@ -135,7 +137,7 @@ const optionalBrandCheck = (allegedBrand, brand) => {
|
|
|
135
137
|
* @param {Amount<K>} leftAmount
|
|
136
138
|
* @param {Amount<K>} rightAmount
|
|
137
139
|
* @param {Brand<K> | undefined} brand
|
|
138
|
-
* @returns {MathHelpers
|
|
140
|
+
* @returns {MathHelpers<*>}
|
|
139
141
|
*/
|
|
140
142
|
const checkLRAndGetHelpers = (leftAmount, rightAmount, brand = undefined) => {
|
|
141
143
|
assertRecord(leftAmount, 'leftAmount');
|
|
@@ -170,11 +172,11 @@ const coerceLR = (h, leftAmount, rightAmount) => {
|
|
|
170
172
|
};
|
|
171
173
|
|
|
172
174
|
/**
|
|
173
|
-
* Returns true if the leftAmount is greater than or equal to the
|
|
174
|
-
* The notion of "greater than or equal to" depends
|
|
175
|
-
* defined by the MathHelpers. For example,
|
|
176
|
-
*
|
|
177
|
-
* the logic in MathHelpers.
|
|
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.
|
|
178
180
|
*
|
|
179
181
|
* @template {AssetKind} K
|
|
180
182
|
* @param {Amount<K>} leftAmount
|
|
@@ -192,8 +194,9 @@ const isGTE = (leftAmount, rightAmount, brand = undefined) => {
|
|
|
192
194
|
*
|
|
193
195
|
* Amounts are the canonical description of tradable goods. They are manipulated
|
|
194
196
|
* by issuers and mints, and represent the goods and currency carried by purses
|
|
195
|
-
* and
|
|
196
|
-
*
|
|
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.
|
|
197
200
|
*/
|
|
198
201
|
const AmountMath = {
|
|
199
202
|
/**
|
|
@@ -212,8 +215,8 @@ const AmountMath = {
|
|
|
212
215
|
return harden({ brand, value });
|
|
213
216
|
},
|
|
214
217
|
/**
|
|
215
|
-
* Make sure this amount is valid enough, and return a corresponding
|
|
216
|
-
* amount if so.
|
|
218
|
+
* Make sure this amount is valid enough, and return a corresponding
|
|
219
|
+
* valid amount if so.
|
|
217
220
|
*
|
|
218
221
|
* @template {AssetKind} K
|
|
219
222
|
* @param {Brand<K>} brand
|
|
@@ -239,8 +242,8 @@ const AmountMath = {
|
|
|
239
242
|
*/
|
|
240
243
|
getValue: (brand, amount) => AmountMath.coerce(brand, amount).value,
|
|
241
244
|
/**
|
|
242
|
-
* Return the amount representing an empty amount. This is the
|
|
243
|
-
* element for MathHelpers.add and MatHelpers.subtract.
|
|
245
|
+
* Return the amount representing an empty amount. This is the
|
|
246
|
+
* identity element for MathHelpers.add and MatHelpers.subtract.
|
|
244
247
|
*
|
|
245
248
|
* @type {{
|
|
246
249
|
* (brand: Brand): Amount<'nat'>;
|
|
@@ -254,8 +257,8 @@ const AmountMath = {
|
|
|
254
257
|
return harden({ brand, value });
|
|
255
258
|
},
|
|
256
259
|
/**
|
|
257
|
-
* Return the amount representing an empty amount, using another
|
|
258
|
-
* template for the brand and assetKind.
|
|
260
|
+
* Return the amount representing an empty amount, using another
|
|
261
|
+
* amount as the template for the brand and assetKind.
|
|
259
262
|
*
|
|
260
263
|
* @template {AssetKind} K
|
|
261
264
|
* @param {Amount<K>} amount
|
|
@@ -286,8 +289,8 @@ const AmountMath = {
|
|
|
286
289
|
},
|
|
287
290
|
isGTE,
|
|
288
291
|
/**
|
|
289
|
-
* Returns true if the leftAmount equals the rightAmount. We assume
|
|
290
|
-
* isGTE is true in both directions, isEqual is also true
|
|
292
|
+
* Returns true if the leftAmount equals the rightAmount. We assume
|
|
293
|
+
* that if isGTE is true in both directions, isEqual is also true
|
|
291
294
|
*
|
|
292
295
|
* @template {AssetKind} K
|
|
293
296
|
* @param {Amount<K>} leftAmount
|
|
@@ -303,8 +306,8 @@ const AmountMath = {
|
|
|
303
306
|
* Returns a new amount that is the union of both leftAmount and rightAmount.
|
|
304
307
|
*
|
|
305
308
|
* For fungible amount this means adding the values. For other kinds of
|
|
306
|
-
* amount, it usually means including all of the elements from both
|
|
307
|
-
* right.
|
|
309
|
+
* amount, it usually means including all of the elements from both
|
|
310
|
+
* left and right.
|
|
308
311
|
*
|
|
309
312
|
* @template {AssetKind} K
|
|
310
313
|
* @param {Amount<K>} leftAmount
|
|
@@ -318,11 +321,12 @@ const AmountMath = {
|
|
|
318
321
|
return harden({ brand: leftAmount.brand, value });
|
|
319
322
|
},
|
|
320
323
|
/**
|
|
321
|
-
* Returns a new amount that is the leftAmount minus the rightAmount
|
|
322
|
-
* everything in the leftAmount that is not in the
|
|
323
|
-
* doesn't include rightAmount
|
|
324
|
-
*
|
|
325
|
-
*
|
|
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.
|
|
326
330
|
*
|
|
327
331
|
* @template {AssetKind} K
|
|
328
332
|
* @param {Amount<K>} leftAmount
|
|
@@ -370,7 +374,9 @@ const AmountMath = {
|
|
|
370
374
|
};
|
|
371
375
|
harden(AmountMath);
|
|
372
376
|
|
|
373
|
-
/**
|
|
377
|
+
/**
|
|
378
|
+
* @param {Amount} amount
|
|
379
|
+
*/
|
|
374
380
|
const getAssetKind = amount => {
|
|
375
381
|
assertRecord(amount, 'amount');
|
|
376
382
|
const { value } = amount;
|
package/src/issuerKit.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export function prepareIssuerKit<K extends AssetKind>(issuerBaggage:
|
|
2
|
-
export function hasIssuer(baggage:
|
|
3
|
-
export function makeDurableIssuerKit<K extends AssetKind>(issuerBaggage:
|
|
1
|
+
export function prepareIssuerKit<K extends AssetKind>(issuerBaggage: MapStore<string, unknown>, optShutdownWithFailure?: import("@agoric/swingset-vat").ShutdownWithFailure | undefined): IssuerKit<K>;
|
|
2
|
+
export function hasIssuer(baggage: MapStore<string, unknown>): any;
|
|
3
|
+
export function makeDurableIssuerKit<K extends AssetKind>(issuerBaggage: MapStore<string, unknown>, name: string, assetKind?: K | undefined, displayInfo?: AdditionalDisplayInfo | undefined, optShutdownWithFailure?: import("@agoric/swingset-vat").ShutdownWithFailure | undefined, { elementShape }?: Partial<{
|
|
4
4
|
elementShape: Pattern;
|
|
5
5
|
}> | undefined): IssuerKit<K>;
|
|
6
6
|
export function makeIssuerKit<K extends AssetKind = "nat">(name: string, assetKind?: K | undefined, displayInfo?: AdditionalDisplayInfo | undefined, optShutdownWithFailure?: import("@agoric/swingset-vat").ShutdownWithFailure | undefined, { elementShape }?: Partial<{
|
package/src/issuerKit.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"issuerKit.d.ts","sourceRoot":"","sources":["issuerKit.js"],"names":[],"mappings":"AA2FO,
|
|
1
|
+
{"version":3,"file":"issuerKit.d.ts","sourceRoot":"","sources":["issuerKit.js"],"names":[],"mappings":"AA2FO,uMAMN;AASM,mEAAsD;AAmCtD,0GAbI,MAAM;kBAnBmB,OAAO;8BA4C1C;AA+BM,iEAbI,MAAM;kBA9DmB,OAAO;8BA0FxC;sBA3LW,OAAO,kBAAkB,EAAE,OAAO;;UAKlC,MAAM;eACN,CAAC;iBACD,qBAAqB;kBACrB,OAAO;;kCAyFR,QAAQ;IAAC,YAAY,EAAE,OAAO,CAAA;CAAC,CAAC"}
|
package/src/issuerKit.js
CHANGED
|
@@ -25,13 +25,13 @@ import './types-ambient.js';
|
|
|
25
25
|
* @template {AssetKind} K
|
|
26
26
|
* @param {IssuerRecord<K>} issuerRecord
|
|
27
27
|
* @param {Baggage} issuerBaggage
|
|
28
|
-
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
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
|
|
35
35
|
* @returns {IssuerKit<K>}
|
|
36
36
|
*/
|
|
37
37
|
const setupIssuerKit = (
|
|
@@ -80,13 +80,13 @@ const INSTANCE_KEY = 'issuer';
|
|
|
80
80
|
/**
|
|
81
81
|
* @template {AssetKind} K
|
|
82
82
|
* @param {Baggage} issuerBaggage
|
|
83
|
-
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
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
|
|
90
90
|
* @returns {IssuerKit<K>}
|
|
91
91
|
*/
|
|
92
92
|
export const prepareIssuerKit = (
|
|
@@ -99,39 +99,43 @@ export const prepareIssuerKit = (
|
|
|
99
99
|
harden(prepareIssuerKit);
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
|
-
* Does baggage already have an issuer from prepareIssuerKit()?
|
|
103
|
-
* have the relevant keys defined?
|
|
102
|
+
* Does baggage already have an issuer from prepareIssuerKit()?
|
|
103
|
+
* That is: does it have the relevant keys defined?
|
|
104
104
|
*
|
|
105
105
|
* @param {Baggage} baggage
|
|
106
106
|
*/
|
|
107
107
|
export const hasIssuer = baggage => baggage.has(INSTANCE_KEY);
|
|
108
108
|
|
|
109
|
-
/**
|
|
109
|
+
/**
|
|
110
|
+
* @typedef {Partial<{elementShape: Pattern}>} IssuerOptionsRecord
|
|
111
|
+
*/
|
|
110
112
|
|
|
111
113
|
/**
|
|
112
|
-
* @template {AssetKind} K
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
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.
|
|
118
121
|
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
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.
|
|
125
|
+
*
|
|
126
|
+
* `displayInfo` gives information to the UI on how to display the amount.
|
|
122
127
|
*
|
|
123
|
-
* `displayInfo` gives information to the UI on how to display the amount.
|
|
124
128
|
* @param {Baggage} issuerBaggage
|
|
125
129
|
* @param {string} name
|
|
126
|
-
* @param {K} [assetKind]
|
|
127
|
-
* @param {AdditionalDisplayInfo} [displayInfo]
|
|
128
|
-
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
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
|
|
135
139
|
* @param {IssuerOptionsRecord} [options]
|
|
136
140
|
* @returns {IssuerKit<K>}
|
|
137
141
|
*/
|
|
@@ -151,28 +155,30 @@ export const makeDurableIssuerKit = (
|
|
|
151
155
|
harden(makeDurableIssuerKit);
|
|
152
156
|
|
|
153
157
|
/**
|
|
154
|
-
* @template {AssetKind} [K='nat']
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
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.
|
|
165
|
+
*
|
|
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.
|
|
160
169
|
*
|
|
161
|
-
*
|
|
162
|
-
* mathHelpers library. For example, natMathHelpers, the default, is used for
|
|
163
|
-
* basic fungible tokens.
|
|
170
|
+
* `displayInfo` gives information to the UI on how to display the amount.
|
|
164
171
|
*
|
|
165
|
-
* `displayInfo` gives information to the UI on how to display the amount.
|
|
166
172
|
* @param {string} name
|
|
167
|
-
* @param {K} [assetKind]
|
|
168
|
-
* @param {AdditionalDisplayInfo} [displayInfo]
|
|
169
|
-
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
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
|
|
176
182
|
* @param {IssuerOptionsRecord} [options]
|
|
177
183
|
* @returns {IssuerKit<K>}
|
|
178
184
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legacy-payment-helpers.d.ts","sourceRoot":"","sources":["legacy-payment-helpers.js"],"names":[],"mappings":"
|
|
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"}
|
|
@@ -7,17 +7,19 @@ import { AmountMath } from './amountMath.js';
|
|
|
7
7
|
const { Fail } = assert;
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* @file
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
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
17
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
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
23
|
*/
|
|
22
24
|
|
|
23
25
|
/**
|
|
@@ -41,11 +43,11 @@ harden(claim);
|
|
|
41
43
|
|
|
42
44
|
/**
|
|
43
45
|
* Note: Not failure atomic. But as long as you don't lose the argument
|
|
44
|
-
* `recoveryPurse`, no assets are lost.
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* origin.
|
|
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.
|
|
49
51
|
*
|
|
50
52
|
* @template {AssetKind} K
|
|
51
53
|
* @param {ERef<Purse<K>>} recoveryPurse
|
|
@@ -82,10 +84,11 @@ harden(combine);
|
|
|
82
84
|
|
|
83
85
|
/**
|
|
84
86
|
* Note: Not failure atomic. But as long as you don't lose the argument
|
|
85
|
-
* `recoveryPurse`, no assets are lost.
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
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`.
|
|
89
92
|
*
|
|
90
93
|
* @template {AssetKind} K
|
|
91
94
|
* @param {ERef<Purse<K>>} recoveryPurse
|
|
@@ -108,10 +111,12 @@ harden(split);
|
|
|
108
111
|
|
|
109
112
|
/**
|
|
110
113
|
* Note: Not failure atomic. But as long as you don't lose the argument
|
|
111
|
-
* `recoveryPurse`, no assets are lost.
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
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`.
|
|
115
120
|
*
|
|
116
121
|
* @template {AssetKind} K
|
|
117
122
|
* @param {ERef<Purse<K>>} recoveryPurse
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copyBagMathHelpers.d.ts","sourceRoot":"","sources":["copyBagMathHelpers.js"],"names":[],"mappings":"AAiBA
|
|
1
|
+
{"version":3,"file":"copyBagMathHelpers.d.ts","sourceRoot":"","sources":["copyBagMathHelpers.js"],"names":[],"mappings":"AAiBA;;GAEG;AACH,iCAFU,YAAY,OAAO,CAAC,CAa3B"}
|
|
@@ -15,7 +15,9 @@ import '../types-ambient.js';
|
|
|
15
15
|
/** @type {CopyBag} */
|
|
16
16
|
const empty = makeCopyBag([]);
|
|
17
17
|
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* @type {MathHelpers<CopyBag>}
|
|
20
|
+
*/
|
|
19
21
|
export const copyBagMathHelpers = harden({
|
|
20
22
|
doCoerce: bag => {
|
|
21
23
|
mustMatch(bag, M.bag(), 'bag of amount');
|