@agoric/ertp 0.15.6-pismo-dev-0d5327f.0 → 0.16.1-dev-bf4b59f.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 +35 -0
- package/README.md +1 -1
- package/exported.js +1 -1
- package/package.json +19 -16
- package/src/amountMath.d.ts +53 -0
- package/src/amountMath.d.ts.map +1 -0
- package/src/amountMath.js +78 -85
- package/src/displayInfo.d.ts +2 -0
- package/src/displayInfo.d.ts.map +1 -0
- package/src/displayInfo.js +6 -10
- package/src/index.d.ts +4 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +1 -1
- package/src/issuerKit.d.ts +19 -0
- package/src/issuerKit.d.ts.map +1 -0
- package/src/issuerKit.js +65 -22
- package/src/legacy-payment-helpers.d.ts +5 -0
- package/src/legacy-payment-helpers.d.ts.map +1 -0
- package/src/legacy-payment-helpers.js +146 -0
- package/src/mathHelpers/copyBagMathHelpers.d.ts +5 -0
- package/src/mathHelpers/copyBagMathHelpers.d.ts.map +1 -0
- package/src/mathHelpers/copyBagMathHelpers.js +6 -6
- package/src/mathHelpers/copySetMathHelpers.d.ts +5 -0
- package/src/mathHelpers/copySetMathHelpers.d.ts.map +1 -0
- package/src/mathHelpers/copySetMathHelpers.js +6 -6
- package/src/mathHelpers/natMathHelpers.d.ts +14 -0
- package/src/mathHelpers/natMathHelpers.d.ts.map +1 -0
- package/src/mathHelpers/natMathHelpers.js +7 -7
- package/src/mathHelpers/setMathHelpers.d.ts +6 -0
- package/src/mathHelpers/setMathHelpers.d.ts.map +1 -0
- package/src/mathHelpers/setMathHelpers.js +3 -3
- package/src/payment.d.ts +3 -0
- package/src/payment.d.ts.map +1 -0
- package/src/payment.js +5 -5
- package/src/paymentLedger.d.ts +3 -0
- package/src/paymentLedger.d.ts.map +1 -0
- package/src/paymentLedger.js +76 -163
- package/src/purse.d.ts +13 -0
- package/src/purse.d.ts.map +1 -0
- package/src/purse.js +15 -9
- package/src/transientNotifier.d.ts +5 -0
- package/src/transientNotifier.d.ts.map +1 -0
- package/src/transientNotifier.js +1 -1
- package/src/typeGuards.d.ts +42 -0
- package/src/typeGuards.d.ts.map +1 -0
- package/src/typeGuards.js +25 -22
- package/src/types-ambient.d.ts +376 -0
- package/src/types-ambient.d.ts.map +1 -0
- package/src/types-ambient.js +440 -0
- package/src/types.d.ts +376 -0
- package/src/types.d.ts.map +1 -0
- package/src/types.js +41 -87
package/src/issuerKit.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-check
|
|
2
1
|
// @jessie-check
|
|
3
2
|
|
|
4
3
|
import { assert } from '@agoric/assert';
|
|
@@ -7,16 +6,26 @@ import { makeScalarBigMapStore } from '@agoric/vat-data';
|
|
|
7
6
|
|
|
8
7
|
import { AssetKind, assertAssetKind } from './amountMath.js';
|
|
9
8
|
import { coerceDisplayInfo } from './displayInfo.js';
|
|
10
|
-
import {
|
|
9
|
+
import { preparePaymentLedger } from './paymentLedger.js';
|
|
11
10
|
|
|
12
|
-
import './types.js';
|
|
11
|
+
import './types-ambient.js';
|
|
13
12
|
|
|
14
13
|
/** @typedef {import('@agoric/vat-data').Baggage} Baggage */
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* @template {AssetKind} K
|
|
17
|
+
* @typedef {object} IssuerRecord
|
|
18
|
+
* @property {string} name
|
|
19
|
+
* @property {K} assetKind
|
|
20
|
+
* @property {AdditionalDisplayInfo} displayInfo
|
|
21
|
+
* @property {Pattern} elementShape
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @template {AssetKind} K
|
|
26
|
+
* @param {IssuerRecord<K>} issuerRecord
|
|
18
27
|
* @param {Baggage} issuerBaggage
|
|
19
|
-
* @param {ShutdownWithFailure
|
|
28
|
+
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails
|
|
20
29
|
* in the middle of an atomic action (which btw should never happen), it
|
|
21
30
|
* potentially leaves its ledger in a corrupted state. If this function was
|
|
22
31
|
* provided, then the failed atomic action will call it, so that some
|
|
@@ -25,14 +34,11 @@ import './types.js';
|
|
|
25
34
|
* See https://github.com/Agoric/agoric-sdk/issues/3434
|
|
26
35
|
* @returns {IssuerKit<K>}
|
|
27
36
|
*/
|
|
28
|
-
|
|
37
|
+
const setupIssuerKit = (
|
|
38
|
+
{ name, assetKind, displayInfo, elementShape },
|
|
29
39
|
issuerBaggage,
|
|
30
40
|
optShutdownWithFailure = undefined,
|
|
31
41
|
) => {
|
|
32
|
-
const name = issuerBaggage.get('name');
|
|
33
|
-
const assetKind = issuerBaggage.get('assetKind');
|
|
34
|
-
const displayInfo = issuerBaggage.get('displayInfo');
|
|
35
|
-
const elementShape = issuerBaggage.get('elementShape');
|
|
36
42
|
assert.typeof(name, 'string');
|
|
37
43
|
assertAssetKind(assetKind);
|
|
38
44
|
|
|
@@ -47,7 +53,9 @@ export const vivifyIssuerKit = (
|
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
// Attenuate the powerful authority to mint and change balances
|
|
50
|
-
|
|
56
|
+
/** @type {PaymentLedger<K>} */
|
|
57
|
+
// @ts-expect-error could be instantiated with different subtype of AssetKind
|
|
58
|
+
const { issuer, mint, brand, mintRecoveryPurse } = preparePaymentLedger(
|
|
51
59
|
issuerBaggage,
|
|
52
60
|
name,
|
|
53
61
|
assetKind,
|
|
@@ -60,10 +68,47 @@ export const vivifyIssuerKit = (
|
|
|
60
68
|
brand,
|
|
61
69
|
issuer,
|
|
62
70
|
mint,
|
|
71
|
+
mintRecoveryPurse,
|
|
63
72
|
displayInfo: cleanDisplayInfo,
|
|
64
73
|
});
|
|
65
74
|
};
|
|
66
|
-
harden(
|
|
75
|
+
harden(setupIssuerKit);
|
|
76
|
+
|
|
77
|
+
/** The key at which the issuer record is stored. */
|
|
78
|
+
const INSTANCE_KEY = 'issuer';
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @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
|
|
90
|
+
* @returns {IssuerKit<K>}
|
|
91
|
+
*/
|
|
92
|
+
export const prepareIssuerKit = (
|
|
93
|
+
issuerBaggage,
|
|
94
|
+
optShutdownWithFailure = undefined,
|
|
95
|
+
) => {
|
|
96
|
+
const issuerRecord = issuerBaggage.get(INSTANCE_KEY);
|
|
97
|
+
return setupIssuerKit(issuerRecord, issuerBaggage, optShutdownWithFailure);
|
|
98
|
+
};
|
|
99
|
+
harden(prepareIssuerKit);
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Does baggage already have an issuer from prepareIssuerKit()?
|
|
103
|
+
* That is: does it have the relevant keys defined?
|
|
104
|
+
*
|
|
105
|
+
* @param {Baggage} baggage
|
|
106
|
+
*/
|
|
107
|
+
export const hasIssuer = baggage => baggage.has(INSTANCE_KEY);
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @typedef {Partial<{elementShape: Pattern}>} IssuerOptionsRecord
|
|
111
|
+
*/
|
|
67
112
|
|
|
68
113
|
/**
|
|
69
114
|
* @template {AssetKind} K
|
|
@@ -84,14 +129,14 @@ harden(vivifyIssuerKit);
|
|
|
84
129
|
* @param {string} name
|
|
85
130
|
* @param {K} [assetKind=AssetKind.NAT]
|
|
86
131
|
* @param {AdditionalDisplayInfo} [displayInfo={}]
|
|
87
|
-
* @param {ShutdownWithFailure
|
|
132
|
+
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails
|
|
88
133
|
* in the middle of an atomic action (which btw should never happen), it
|
|
89
134
|
* potentially leaves its ledger in a corrupted state. If this function was
|
|
90
135
|
* provided, then the failed atomic action will call it, so that some
|
|
91
136
|
* larger unit of computation, like the enclosing vat, can be shutdown
|
|
92
137
|
* before anything else is corrupted by that corrupted state.
|
|
93
138
|
* See https://github.com/Agoric/agoric-sdk/issues/3434
|
|
94
|
-
* @param {
|
|
139
|
+
* @param {IssuerOptionsRecord} [options]
|
|
95
140
|
* @returns {IssuerKit<K>}
|
|
96
141
|
*/
|
|
97
142
|
export const makeDurableIssuerKit = (
|
|
@@ -103,16 +148,14 @@ export const makeDurableIssuerKit = (
|
|
|
103
148
|
optShutdownWithFailure = undefined,
|
|
104
149
|
{ elementShape = undefined } = {},
|
|
105
150
|
) => {
|
|
106
|
-
|
|
107
|
-
issuerBaggage.init(
|
|
108
|
-
|
|
109
|
-
issuerBaggage.init('elementShape', elementShape);
|
|
110
|
-
return vivifyIssuerKit(issuerBaggage, optShutdownWithFailure);
|
|
151
|
+
const issuerData = harden({ name, assetKind, displayInfo, elementShape });
|
|
152
|
+
issuerBaggage.init(INSTANCE_KEY, issuerData);
|
|
153
|
+
return setupIssuerKit(issuerData, issuerBaggage, optShutdownWithFailure);
|
|
111
154
|
};
|
|
112
155
|
harden(makeDurableIssuerKit);
|
|
113
156
|
|
|
114
157
|
/**
|
|
115
|
-
* @template {AssetKind} K
|
|
158
|
+
* @template {AssetKind} [K='nat']
|
|
116
159
|
* The name becomes part of the brand in asset descriptions.
|
|
117
160
|
* The name is useful for debugging and double-checking
|
|
118
161
|
* assumptions, but should not be trusted wrt any external namespace.
|
|
@@ -127,16 +170,16 @@ harden(makeDurableIssuerKit);
|
|
|
127
170
|
* `displayInfo` gives information to the UI on how to display the amount.
|
|
128
171
|
*
|
|
129
172
|
* @param {string} name
|
|
130
|
-
* @param {K} [assetKind=
|
|
173
|
+
* @param {K} [assetKind='nat']
|
|
131
174
|
* @param {AdditionalDisplayInfo} [displayInfo={}]
|
|
132
|
-
* @param {ShutdownWithFailure
|
|
175
|
+
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails
|
|
133
176
|
* in the middle of an atomic action (which btw should never happen), it
|
|
134
177
|
* potentially leaves its ledger in a corrupted state. If this function was
|
|
135
178
|
* provided, then the failed atomic action will call it, so that some
|
|
136
179
|
* larger unit of computation, like the enclosing vat, can be shutdown
|
|
137
180
|
* before anything else is corrupted by that corrupted state.
|
|
138
181
|
* See https://github.com/Agoric/agoric-sdk/issues/3434
|
|
139
|
-
* @param {
|
|
182
|
+
* @param {IssuerOptionsRecord} [options]
|
|
140
183
|
* @returns {IssuerKit<K>}
|
|
141
184
|
*/
|
|
142
185
|
export const makeIssuerKit = (
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export function claim<K extends AssetKind>(recoveryPurse: ERef<Purse<K>>, srcPaymentP: ERef<Payment<K>>, optAmountShape?: Pattern): Promise<Payment<K>>;
|
|
2
|
+
export function combine<K extends AssetKind>(recoveryPurse: ERef<Purse<K>>, srcPaymentsPs: ERef<Payment<K>>[], optTotalAmount?: Pattern): Promise<Payment<K>>;
|
|
3
|
+
export function split<K extends AssetKind>(recoveryPurse: ERef<Purse<K>>, srcPaymentP: ERef<Payment<K>>, paymentAmountA: Amount<K>): Promise<Payment<K>[]>;
|
|
4
|
+
export function splitMany<K extends AssetKind>(recoveryPurse: ERef<Purse<K>>, srcPaymentP: ERef<Payment<K>>, amounts: Amount<K>[]): Promise<Payment[]>;
|
|
5
|
+
//# sourceMappingURL=legacy-payment-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy-payment-helpers.d.ts","sourceRoot":"","sources":["legacy-payment-helpers.js"],"names":[],"mappings":"AA+BO,0HAHI,OAAO,uBAYjB;AAiBM,gIAHI,OAAO,uBA2BjB;AAiBM,2JAUN;AAkBM,oIAFM,QAAQ,OAAO,EAAE,CAAC,CAoB9B"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// @jessie-check
|
|
2
|
+
|
|
3
|
+
import { mustMatch } from '@agoric/store';
|
|
4
|
+
import { E } from '@endo/far';
|
|
5
|
+
import { AmountMath } from './amountMath.js';
|
|
6
|
+
|
|
7
|
+
const { Fail } = assert;
|
|
8
|
+
|
|
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.
|
|
17
|
+
*
|
|
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`.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @template {AssetKind} K
|
|
27
|
+
* @param {ERef<Purse<K>>} recoveryPurse
|
|
28
|
+
* @param {ERef<Payment<K>>} srcPaymentP
|
|
29
|
+
* @param {Pattern} [optAmountShape]
|
|
30
|
+
* @returns {Promise<Payment<K>>}
|
|
31
|
+
*/
|
|
32
|
+
export const claim = async (
|
|
33
|
+
recoveryPurse,
|
|
34
|
+
srcPaymentP,
|
|
35
|
+
optAmountShape = undefined,
|
|
36
|
+
) => {
|
|
37
|
+
const srcPayment = await srcPaymentP;
|
|
38
|
+
return E.when(E(recoveryPurse).deposit(srcPayment, optAmountShape), amount =>
|
|
39
|
+
E(recoveryPurse).withdraw(amount),
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
harden(claim);
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 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.
|
|
51
|
+
*
|
|
52
|
+
* @template {AssetKind} K
|
|
53
|
+
* @param {ERef<Purse<K>>} recoveryPurse
|
|
54
|
+
* @param {ERef<Payment<K>>[]} srcPaymentsPs
|
|
55
|
+
* @param {Pattern} [optTotalAmount]
|
|
56
|
+
* @returns {Promise<Payment<K>>}
|
|
57
|
+
*/
|
|
58
|
+
export const combine = async (
|
|
59
|
+
recoveryPurse,
|
|
60
|
+
srcPaymentsPs,
|
|
61
|
+
optTotalAmount = undefined,
|
|
62
|
+
) => {
|
|
63
|
+
const brandP = E(recoveryPurse).getAllegedBrand();
|
|
64
|
+
const [brand, displayInfo, ...srcPayments] = await Promise.all([
|
|
65
|
+
brandP,
|
|
66
|
+
E(brandP).getDisplayInfo(),
|
|
67
|
+
...srcPaymentsPs,
|
|
68
|
+
]);
|
|
69
|
+
const emptyAmount = AmountMath.makeEmpty(brand, displayInfo.assetKind);
|
|
70
|
+
const amountPs = srcPayments.map(srcPayment =>
|
|
71
|
+
E(recoveryPurse).deposit(srcPayment),
|
|
72
|
+
);
|
|
73
|
+
const amounts = await Promise.all(amountPs);
|
|
74
|
+
const total = amounts.reduce(
|
|
75
|
+
(x, y) => AmountMath.add(x, y, brand),
|
|
76
|
+
emptyAmount,
|
|
77
|
+
);
|
|
78
|
+
if (optTotalAmount !== undefined) {
|
|
79
|
+
mustMatch(total, optTotalAmount, 'amount');
|
|
80
|
+
}
|
|
81
|
+
return E(recoveryPurse).withdraw(total);
|
|
82
|
+
};
|
|
83
|
+
harden(combine);
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 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`.
|
|
92
|
+
*
|
|
93
|
+
* @template {AssetKind} K
|
|
94
|
+
* @param {ERef<Purse<K>>} recoveryPurse
|
|
95
|
+
* @param {ERef<Payment<K>>} srcPaymentP
|
|
96
|
+
* @param {Amount<K>} paymentAmountA
|
|
97
|
+
* @returns {Promise<Payment<K>[]>}
|
|
98
|
+
*/
|
|
99
|
+
export const split = async (recoveryPurse, srcPaymentP, paymentAmountA) => {
|
|
100
|
+
const srcPayment = await srcPaymentP;
|
|
101
|
+
// See https://github.com/Agoric/agoric-sdk/issues/7193 which explains
|
|
102
|
+
// how we would like to write the following line, and why we cannot yet do so.
|
|
103
|
+
const srcAmount = await E(recoveryPurse).deposit(srcPayment);
|
|
104
|
+
const paymentAmountB = AmountMath.subtract(srcAmount, paymentAmountA);
|
|
105
|
+
return Promise.all([
|
|
106
|
+
E(recoveryPurse).withdraw(paymentAmountA),
|
|
107
|
+
E(recoveryPurse).withdraw(paymentAmountB),
|
|
108
|
+
]);
|
|
109
|
+
};
|
|
110
|
+
harden(split);
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 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`.
|
|
120
|
+
*
|
|
121
|
+
* @template {AssetKind} K
|
|
122
|
+
* @param {ERef<Purse<K>>} recoveryPurse
|
|
123
|
+
* @param {ERef<Payment<K>>} srcPaymentP
|
|
124
|
+
* @param {Amount<K>[]} amounts
|
|
125
|
+
* @returns {Promise<Payment[]>}
|
|
126
|
+
*/
|
|
127
|
+
export const splitMany = async (recoveryPurse, srcPaymentP, amounts) => {
|
|
128
|
+
const srcPayment = await srcPaymentP;
|
|
129
|
+
// If we could calculate `total` before the `deposit`, then we
|
|
130
|
+
// could use the `total` as the second argument to `deposit` and be
|
|
131
|
+
// failure atomic. But this would require making an empty amount first,
|
|
132
|
+
// which is possible, but too much trouble for a deprecated legacy support
|
|
133
|
+
// method.
|
|
134
|
+
const srcAmount = await E(recoveryPurse).deposit(srcPayment);
|
|
135
|
+
const brand = srcAmount.brand;
|
|
136
|
+
const emptyAmount = AmountMath.makeEmptyFromAmount(srcAmount);
|
|
137
|
+
const total = amounts.reduce(
|
|
138
|
+
(x, y) => AmountMath.add(x, y, brand),
|
|
139
|
+
emptyAmount,
|
|
140
|
+
);
|
|
141
|
+
AmountMath.isEqual(srcAmount, total) ||
|
|
142
|
+
Fail`rights were not conserved: ${total} vs ${srcAmount}`;
|
|
143
|
+
|
|
144
|
+
return Promise.all(amounts.map(amount => E(recoveryPurse).withdraw(amount)));
|
|
145
|
+
};
|
|
146
|
+
harden(splitMany);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copyBagMathHelpers.d.ts","sourceRoot":"","sources":["copyBagMathHelpers.js"],"names":[],"mappings":"AAiBA;;GAEG;AACH,iCAFU,YAAY,OAAO,CAAC,CAa3B"}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
// @
|
|
1
|
+
// @jessie-check
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
keyEQ,
|
|
5
5
|
makeCopyBag,
|
|
6
|
-
|
|
6
|
+
mustMatch,
|
|
7
7
|
M,
|
|
8
8
|
getCopyBagEntries,
|
|
9
9
|
bagIsSuperbag,
|
|
10
10
|
bagUnion,
|
|
11
11
|
bagDisjointSubtract,
|
|
12
12
|
} from '@agoric/store';
|
|
13
|
-
import '../types.js';
|
|
13
|
+
import '../types-ambient.js';
|
|
14
14
|
|
|
15
|
-
/** @type {
|
|
15
|
+
/** @type {CopyBag} */
|
|
16
16
|
const empty = makeCopyBag([]);
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* @type {
|
|
19
|
+
* @type {MathHelpers<CopyBag>}
|
|
20
20
|
*/
|
|
21
21
|
export const copyBagMathHelpers = harden({
|
|
22
22
|
doCoerce: bag => {
|
|
23
|
-
|
|
23
|
+
mustMatch(bag, M.bag(), 'bag of amount');
|
|
24
24
|
return bag;
|
|
25
25
|
},
|
|
26
26
|
doMakeEmpty: () => empty,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copySetMathHelpers.d.ts","sourceRoot":"","sources":["copySetMathHelpers.js"],"names":[],"mappings":"AAiBA;;GAEG;AACH,iCAFU,YAAY,OAAO,CAAC,CAa3B"}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
// @
|
|
1
|
+
// @jessie-check
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
keyEQ,
|
|
5
5
|
makeCopySet,
|
|
6
|
-
|
|
6
|
+
mustMatch,
|
|
7
7
|
M,
|
|
8
8
|
getCopySetKeys,
|
|
9
9
|
setIsSuperset,
|
|
10
10
|
setDisjointUnion,
|
|
11
11
|
setDisjointSubtract,
|
|
12
12
|
} from '@agoric/store';
|
|
13
|
-
import '../types.js';
|
|
13
|
+
import '../types-ambient.js';
|
|
14
14
|
|
|
15
|
-
/** @type {
|
|
15
|
+
/** @type {CopySet} */
|
|
16
16
|
const empty = makeCopySet([]);
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* @type {
|
|
19
|
+
* @type {MathHelpers<CopySet>}
|
|
20
20
|
*/
|
|
21
21
|
export const copySetMathHelpers = harden({
|
|
22
22
|
doCoerce: set => {
|
|
23
|
-
|
|
23
|
+
mustMatch(set, M.set(), 'set of amount');
|
|
24
24
|
return set;
|
|
25
25
|
},
|
|
26
26
|
doMakeEmpty: () => empty,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fungible digital assets use the natMathHelpers to manage balances -
|
|
3
|
+
* the operations are merely arithmetic on natural, non-negative
|
|
4
|
+
* numbers.
|
|
5
|
+
*
|
|
6
|
+
* Natural numbers are used for fungible erights such as money because
|
|
7
|
+
* rounding issues make floats problematic. All operations should be
|
|
8
|
+
* done with the smallest whole unit such that the `natMathHelpers` never
|
|
9
|
+
* deals with fractional parts.
|
|
10
|
+
*
|
|
11
|
+
* @type {MathHelpers<NatValue>}
|
|
12
|
+
*/
|
|
13
|
+
export const natMathHelpers: MathHelpers<NatValue>;
|
|
14
|
+
//# sourceMappingURL=natMathHelpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"natMathHelpers.d.ts","sourceRoot":"","sources":["natMathHelpers.js"],"names":[],"mappings":"AASA;;;;;;;;;;;GAWG;AACH,6BAFU,YAAY,QAAQ,CAAC,CAgB5B"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
// @
|
|
1
|
+
// @jessie-check
|
|
2
2
|
|
|
3
|
-
import { Nat, isNat } from '@
|
|
3
|
+
import { Nat, isNat } from '@endo/nat';
|
|
4
4
|
|
|
5
|
-
import '../types.js';
|
|
5
|
+
import '../types-ambient.js';
|
|
6
6
|
|
|
7
|
-
const {
|
|
7
|
+
const { Fail } = assert;
|
|
8
8
|
const empty = 0n;
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -14,16 +14,16 @@ const empty = 0n;
|
|
|
14
14
|
*
|
|
15
15
|
* Natural numbers are used for fungible erights such as money because
|
|
16
16
|
* rounding issues make floats problematic. All operations should be
|
|
17
|
-
* done with the smallest whole unit such that the
|
|
17
|
+
* done with the smallest whole unit such that the `natMathHelpers` never
|
|
18
18
|
* deals with fractional parts.
|
|
19
19
|
*
|
|
20
|
-
* @type {
|
|
20
|
+
* @type {MathHelpers<NatValue>}
|
|
21
21
|
*/
|
|
22
22
|
export const natMathHelpers = harden({
|
|
23
23
|
doCoerce: nat => {
|
|
24
24
|
// TODO: tighten the definition of Nat in @agoric/nat to throw on `number`
|
|
25
25
|
assert.typeof(nat, 'bigint');
|
|
26
|
-
|
|
26
|
+
isNat(nat) || Fail`value ${nat} must be a natural number`;
|
|
27
27
|
return Nat(nat);
|
|
28
28
|
},
|
|
29
29
|
doMakeEmpty: () => empty,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setMathHelpers.d.ts","sourceRoot":"","sources":["setMathHelpers.js"],"names":[],"mappings":"AAkBA;;;GAGG;AACH,6BAFU,qBAAqB,CAkB5B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @
|
|
1
|
+
// @jessie-check
|
|
2
2
|
|
|
3
3
|
import { passStyleOf } from '@endo/marshal';
|
|
4
4
|
import {
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
coerceToElements,
|
|
10
10
|
elementsCompare,
|
|
11
11
|
} from '@agoric/store';
|
|
12
|
-
import '../types.js';
|
|
12
|
+
import '../types-ambient.js';
|
|
13
13
|
|
|
14
14
|
// Operations for arrays with unique objects identifying and providing
|
|
15
15
|
// information about digital assets. Used for Zoe invites.
|
|
@@ -18,7 +18,7 @@ const empty = harden([]);
|
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* @deprecated Replace array-based SetMath with CopySet-based CopySetMath
|
|
21
|
-
* @type {
|
|
21
|
+
* @type {MathHelpers<SetValue>}
|
|
22
22
|
*/
|
|
23
23
|
export const setMathHelpers = harden({
|
|
24
24
|
doCoerce: list => {
|
package/src/payment.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["payment.js"],"names":[],"mappings":"AAeO,wGALI,MAAM,6BAEN,cAAc,oBAgBxB;sBAvBa,OAAO,kBAAkB,EAAE,OAAO"}
|
package/src/payment.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// @
|
|
1
|
+
// @jessie-check
|
|
2
2
|
|
|
3
3
|
import { initEmpty } from '@agoric/store';
|
|
4
|
-
import {
|
|
4
|
+
import { prepareExoClass } from '@agoric/vat-data';
|
|
5
5
|
|
|
6
6
|
/** @typedef {import('@agoric/vat-data').Baggage} Baggage */
|
|
7
7
|
|
|
@@ -13,8 +13,8 @@ import { vivifyFarClass } from '@agoric/vat-data';
|
|
|
13
13
|
* @param {InterfaceGuard} PaymentI
|
|
14
14
|
* @returns {() => Payment<K>}
|
|
15
15
|
*/
|
|
16
|
-
export const
|
|
17
|
-
const makePayment =
|
|
16
|
+
export const preparePaymentKind = (issuerBaggage, name, brand, PaymentI) => {
|
|
17
|
+
const makePayment = prepareExoClass(
|
|
18
18
|
issuerBaggage,
|
|
19
19
|
`${name} payment`,
|
|
20
20
|
PaymentI,
|
|
@@ -27,4 +27,4 @@ export const vivifyPaymentKind = (issuerBaggage, name, brand, PaymentI) => {
|
|
|
27
27
|
);
|
|
28
28
|
return makePayment;
|
|
29
29
|
};
|
|
30
|
-
harden(
|
|
30
|
+
harden(preparePaymentKind);
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export function preparePaymentLedger<K extends AssetKind>(issuerBaggage: MapStore<string, unknown>, name: string, assetKind: K, displayInfo: DisplayInfo<K>, elementShape: Pattern, optShutdownWithFailure?: import("@agoric/swingset-vat").ShutdownWithFailure | undefined): PaymentLedger<K>;
|
|
2
|
+
export type Baggage = import('@agoric/vat-data').Baggage;
|
|
3
|
+
//# sourceMappingURL=paymentLedger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paymentLedger.d.ts","sourceRoot":"","sources":["paymentLedger.js"],"names":[],"mappings":"AAoFO,0GAPI,MAAM,2DAGN,OAAO,6GA+UjB;sBA9Ya,OAAO,kBAAkB,EAAE,OAAO"}
|