@agoric/ertp 0.16.3-other-dev-8f8782b.0 → 0.16.3-other-dev-3eb1a1d.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/exported.d.ts +37 -0
- package/exported.js +2 -1
- package/package.json +35 -35
- package/src/amountMath.d.ts +42 -38
- package/src/amountMath.d.ts.map +1 -1
- package/src/amountMath.js +131 -127
- package/src/amountStore.d.ts +9 -0
- package/src/amountStore.d.ts.map +1 -0
- package/src/amountStore.js +34 -0
- package/src/displayInfo.d.ts +3 -0
- package/src/displayInfo.d.ts.map +1 -1
- package/src/displayInfo.js +3 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +4 -0
- package/src/issuerKit.d.ts +30 -5
- package/src/issuerKit.d.ts.map +1 -1
- package/src/issuerKit.js +218 -76
- package/src/legacy-payment-helpers.d.ts +6 -1
- package/src/legacy-payment-helpers.d.ts.map +1 -1
- package/src/legacy-payment-helpers.js +34 -34
- package/src/mathHelpers/copyBagMathHelpers.d.ts +3 -4
- package/src/mathHelpers/copyBagMathHelpers.d.ts.map +1 -1
- package/src/mathHelpers/copyBagMathHelpers.js +4 -5
- package/src/mathHelpers/copySetMathHelpers.d.ts +3 -3
- package/src/mathHelpers/copySetMathHelpers.d.ts.map +1 -1
- package/src/mathHelpers/copySetMathHelpers.js +6 -4
- package/src/mathHelpers/natMathHelpers.d.ts +8 -7
- package/src/mathHelpers/natMathHelpers.d.ts.map +1 -1
- package/src/mathHelpers/natMathHelpers.js +8 -9
- package/src/mathHelpers/setMathHelpers.d.ts +2 -0
- package/src/mathHelpers/setMathHelpers.d.ts.map +1 -1
- package/src/mathHelpers/setMathHelpers.js +2 -1
- package/src/payment.d.ts +4 -2
- package/src/payment.d.ts.map +1 -1
- package/src/payment.js +6 -7
- package/src/paymentLedger.d.ts +6 -2
- package/src/paymentLedger.d.ts.map +1 -1
- package/src/paymentLedger.js +76 -95
- package/src/purse.d.ts +19 -9
- package/src/purse.d.ts.map +1 -1
- package/src/purse.js +86 -26
- package/src/transientNotifier.d.ts +1 -1
- package/src/transientNotifier.d.ts.map +1 -1
- package/src/transientNotifier.js +5 -0
- package/src/typeGuards.d.ts +60 -13
- package/src/typeGuards.d.ts.map +1 -1
- package/src/typeGuards.js +69 -57
- package/src/types-index.d.ts +2 -0
- package/src/types-index.js +2 -0
- package/src/types.d.ts +253 -219
- package/src/types.d.ts.map +1 -1
- package/src/types.ts +468 -0
- package/CHANGELOG.md +0 -743
- package/src/types-ambient.d.ts +0 -376
- package/src/types-ambient.d.ts.map +0 -1
- package/src/types-ambient.js +0 -440
- package/src/types.js +0 -441
package/src/purse.js
CHANGED
|
@@ -1,27 +1,73 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Fail } from '@endo/errors';
|
|
2
|
+
import { M, makeCopySet } from '@agoric/store';
|
|
3
3
|
import { AmountMath } from './amountMath.js';
|
|
4
4
|
import { makeTransientNotifierKit } from './transientNotifier.js';
|
|
5
|
+
import { makeAmountStore } from './amountStore.js';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
/** @import {AssetKind, RecoverySetsOption, Brand, Payment} from './types.js' */
|
|
7
8
|
|
|
9
|
+
const EMPTY_COPY_SET = makeCopySet([]);
|
|
10
|
+
|
|
11
|
+
// TODO Type InterfaceGuard better than InterfaceGuard<any>
|
|
12
|
+
/**
|
|
13
|
+
* @param {import('@agoric/zone').Zone} issuerZone
|
|
14
|
+
* @param {string} name
|
|
15
|
+
* @param {AssetKind} assetKind
|
|
16
|
+
* @param {Brand} brand
|
|
17
|
+
* @param {{
|
|
18
|
+
* purse: import('@endo/patterns').InterfaceGuard<any>;
|
|
19
|
+
* depositFacet: import('@endo/patterns').InterfaceGuard<any>;
|
|
20
|
+
* }} PurseIKit
|
|
21
|
+
* @param {{
|
|
22
|
+
* depositInternal: any;
|
|
23
|
+
* withdrawInternal: any;
|
|
24
|
+
* }} purseMethods
|
|
25
|
+
* @param {RecoverySetsOption} recoverySetsState
|
|
26
|
+
* @param {WeakMapStore<Payment, SetStore<Payment>>} paymentRecoverySets
|
|
27
|
+
*/
|
|
8
28
|
export const preparePurseKind = (
|
|
9
|
-
|
|
29
|
+
issuerZone,
|
|
10
30
|
name,
|
|
11
31
|
assetKind,
|
|
12
32
|
brand,
|
|
13
33
|
PurseIKit,
|
|
14
34
|
purseMethods,
|
|
35
|
+
recoverySetsState,
|
|
36
|
+
paymentRecoverySets,
|
|
15
37
|
) => {
|
|
16
38
|
const amountShape = brand.getAmountShape();
|
|
17
39
|
|
|
18
40
|
// Note: Virtual for high cardinality, but *not* durable, and so
|
|
19
41
|
// broken across an upgrade.
|
|
42
|
+
// TODO propagate zonifying to notifiers, maybe?
|
|
20
43
|
const { provideNotifier, update: updateBalance } = makeTransientNotifierKit();
|
|
21
44
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
45
|
+
/**
|
|
46
|
+
* If `recoverySetsState === 'hasRecoverySets'` (the normal state), then just
|
|
47
|
+
* return `state.recoverySet`.
|
|
48
|
+
*
|
|
49
|
+
* If `recoverySetsState === 'noRecoverySets'`, return `undefined`. Callers
|
|
50
|
+
* must be aware that the `undefined` return happens iff `recoverySetsState
|
|
51
|
+
* === 'noRecoverySets'`, and to avoid storing or retrieving anything from the
|
|
52
|
+
* actual recovery set.
|
|
53
|
+
*
|
|
54
|
+
* @param {{ recoverySet: SetStore<Payment> }} state
|
|
55
|
+
* @returns {SetStore<Payment> | undefined}
|
|
56
|
+
*/
|
|
57
|
+
const maybeRecoverySet = state => {
|
|
58
|
+
const { recoverySet } = state;
|
|
59
|
+
if (recoverySetsState === 'hasRecoverySets') {
|
|
60
|
+
return recoverySet;
|
|
61
|
+
} else {
|
|
62
|
+
recoverySetsState === 'noRecoverySets' ||
|
|
63
|
+
Fail`recoverSetsState must be noRecoverySets if it isn't hasRecoverSets`;
|
|
64
|
+
paymentRecoverySets !== undefined ||
|
|
65
|
+
Fail`paymentRecoverySets must always be defined`;
|
|
66
|
+
recoverySet.getSize() === 0 ||
|
|
67
|
+
Fail`With noRecoverySets, recoverySet must be empty`;
|
|
68
|
+
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
25
71
|
};
|
|
26
72
|
|
|
27
73
|
// - This kind is a pair of purse and depositFacet that have a 1:1
|
|
@@ -31,17 +77,14 @@ export const preparePurseKind = (
|
|
|
31
77
|
// that created depositFacet as needed. But this approach ensures a constant
|
|
32
78
|
// identity for the facet and exercises the multi-faceted object style.
|
|
33
79
|
const { depositInternal, withdrawInternal } = purseMethods;
|
|
34
|
-
const makePurseKit =
|
|
35
|
-
issuerBaggage,
|
|
80
|
+
const makePurseKit = issuerZone.exoClassKit(
|
|
36
81
|
`${name} Purse`,
|
|
37
82
|
PurseIKit,
|
|
38
83
|
() => {
|
|
39
84
|
const currentBalance = AmountMath.makeEmpty(brand, assetKind);
|
|
40
85
|
|
|
41
86
|
/** @type {SetStore<Payment>} */
|
|
42
|
-
const recoverySet =
|
|
43
|
-
durable: true,
|
|
44
|
-
});
|
|
87
|
+
const recoverySet = issuerZone.detached().setStore('recovery set');
|
|
45
88
|
|
|
46
89
|
return {
|
|
47
90
|
currentBalance,
|
|
@@ -54,28 +97,36 @@ export const preparePurseKind = (
|
|
|
54
97
|
// PurseI does *not* delay `deposit` until `srcPayment` is fulfulled.
|
|
55
98
|
// See the comments on PurseI.deposit in typeGuards.js
|
|
56
99
|
const { state } = this;
|
|
100
|
+
const { purse } = this.facets;
|
|
101
|
+
const balanceStore = makeAmountStore(state, 'currentBalance');
|
|
57
102
|
// Note COMMIT POINT within deposit.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
newPurseBalance =>
|
|
61
|
-
updatePurseBalance(state, newPurseBalance, this.facets.purse),
|
|
103
|
+
const srcPaymentBalance = depositInternal(
|
|
104
|
+
balanceStore,
|
|
62
105
|
srcPayment,
|
|
63
106
|
optAmountShape,
|
|
64
107
|
);
|
|
108
|
+
updateBalance(purse, balanceStore.getAmount());
|
|
109
|
+
return srcPaymentBalance;
|
|
65
110
|
},
|
|
66
111
|
withdraw(amount) {
|
|
67
112
|
const { state } = this;
|
|
113
|
+
const { purse } = this.facets;
|
|
114
|
+
|
|
115
|
+
const optRecoverySet = maybeRecoverySet(state);
|
|
116
|
+
const balanceStore = makeAmountStore(state, 'currentBalance');
|
|
68
117
|
// Note COMMIT POINT within withdraw.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
newPurseBalance =>
|
|
72
|
-
updatePurseBalance(state, newPurseBalance, this.facets.purse),
|
|
118
|
+
const payment = withdrawInternal(
|
|
119
|
+
balanceStore,
|
|
73
120
|
amount,
|
|
74
|
-
|
|
121
|
+
optRecoverySet,
|
|
75
122
|
);
|
|
123
|
+
updateBalance(purse, balanceStore.getAmount());
|
|
124
|
+
return payment;
|
|
76
125
|
},
|
|
77
126
|
getCurrentAmount() {
|
|
78
|
-
|
|
127
|
+
const { state } = this;
|
|
128
|
+
const balanceStore = makeAmountStore(state, 'currentBalance');
|
|
129
|
+
return balanceStore.getAmount();
|
|
79
130
|
},
|
|
80
131
|
getCurrentAmountNotifier() {
|
|
81
132
|
return provideNotifier(this.facets.purse);
|
|
@@ -83,24 +134,33 @@ export const preparePurseKind = (
|
|
|
83
134
|
getAllegedBrand() {
|
|
84
135
|
return brand;
|
|
85
136
|
},
|
|
86
|
-
|
|
137
|
+
|
|
87
138
|
getDepositFacet() {
|
|
88
139
|
return this.facets.depositFacet;
|
|
89
140
|
},
|
|
90
141
|
|
|
91
142
|
getRecoverySet() {
|
|
92
|
-
|
|
143
|
+
const { state } = this;
|
|
144
|
+
const optRecoverySet = maybeRecoverySet(state);
|
|
145
|
+
if (optRecoverySet === undefined) {
|
|
146
|
+
return EMPTY_COPY_SET;
|
|
147
|
+
}
|
|
148
|
+
return optRecoverySet.snapshot();
|
|
93
149
|
},
|
|
94
150
|
recoverAll() {
|
|
95
151
|
const { state, facets } = this;
|
|
96
152
|
let amount = AmountMath.makeEmpty(brand, assetKind);
|
|
97
|
-
|
|
153
|
+
const optRecoverySet = maybeRecoverySet(state);
|
|
154
|
+
if (optRecoverySet === undefined) {
|
|
155
|
+
return amount; // empty at this time
|
|
156
|
+
}
|
|
157
|
+
for (const payment of optRecoverySet.keys()) {
|
|
98
158
|
// This does cause deletions from the set while iterating,
|
|
99
159
|
// but this special case is allowed.
|
|
100
160
|
const delta = facets.purse.deposit(payment);
|
|
101
161
|
amount = AmountMath.add(amount, delta, brand);
|
|
102
162
|
}
|
|
103
|
-
|
|
163
|
+
optRecoverySet.getSize() === 0 ||
|
|
104
164
|
Fail`internal: Remaining unrecovered payments: ${facets.purse.getRecoverySet()}`;
|
|
105
165
|
return amount;
|
|
106
166
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transientNotifier.d.ts","sourceRoot":"","sources":["transientNotifier.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transientNotifier.d.ts","sourceRoot":"","sources":["transientNotifier.js"],"names":[],"mappings":"AAaO;;;EAoBN"}
|
package/src/transientNotifier.js
CHANGED
|
@@ -4,6 +4,11 @@ import { makeScalarBigWeakMapStore } from '@agoric/vat-data';
|
|
|
4
4
|
import { provideLazy } from '@agoric/store';
|
|
5
5
|
import { makeNotifierKit } from '@agoric/notifier';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @import {Purse} from './types.js';
|
|
9
|
+
* @import {NotifierRecord} from '@agoric/notifier';
|
|
10
|
+
*/
|
|
11
|
+
|
|
7
12
|
// Note: Virtual for high cardinality, but *not* durable, and so
|
|
8
13
|
// broken across an upgrade.
|
|
9
14
|
export const makeTransientNotifierKit = () => {
|
package/src/typeGuards.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {AmountValue, Ratio} from './types.js'
|
|
3
|
+
* @import {TypedPattern} from '@agoric/internal'
|
|
4
|
+
*/
|
|
1
5
|
export const BrandShape: import("@endo/patterns").Matcher;
|
|
2
6
|
export const IssuerShape: import("@endo/patterns").Matcher;
|
|
3
7
|
export const PaymentShape: import("@endo/patterns").Matcher;
|
|
@@ -9,14 +13,24 @@ export namespace AmountShape {
|
|
|
9
13
|
export { BrandShape as brand };
|
|
10
14
|
export { AmountValueShape as value };
|
|
11
15
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
/**
|
|
17
|
+
* To be used to guard an amount pattern argument, i.e., an argument which is a
|
|
18
|
+
* pattern that can be used to test amounts. Since amounts are keys, anywhere an
|
|
19
|
+
* amount pattern is expected, an amount can be provided and will match only
|
|
20
|
+
* that concrete amount, i.e., amounts that are `keyEQ` to that amount.
|
|
21
|
+
*
|
|
22
|
+
* The `AmountShape` guard above is an amount pattern. But not all amount
|
|
23
|
+
* patterns are like `AmountShape`. For example, `M.any()` is a valid amount
|
|
24
|
+
* pattern that will admit any amount, but is does not resemble the
|
|
25
|
+
* `AmountShape` pattern above.
|
|
26
|
+
*/
|
|
27
|
+
export const AmountPatternShape: import("@endo/patterns").Matcher;
|
|
28
|
+
/** @type {TypedPattern<Ratio>} */
|
|
29
|
+
export const RatioShape: TypedPattern<Ratio>;
|
|
30
|
+
export function isNatValue(value: AmountValue): value is import("./types.js").NatValue;
|
|
31
|
+
export function isCopySetValue(value: AmountValue): value is CopySet;
|
|
18
32
|
export function isSetValue(value: AmountValue): value is SetValue;
|
|
19
|
-
export function isCopyBagValue(value: AmountValue): value is CopyBag
|
|
33
|
+
export function isCopyBagValue(value: AmountValue): value is CopyBag;
|
|
20
34
|
export const MAX_ABSOLUTE_DECIMAL_PLACES: 100;
|
|
21
35
|
export const AssetKindShape: import("@endo/patterns").Matcher;
|
|
22
36
|
export const DisplayInfoShape: import("@endo/patterns").Matcher;
|
|
@@ -27,16 +41,49 @@ export namespace IssuerKitShape {
|
|
|
27
41
|
export { IssuerShape as issuer };
|
|
28
42
|
export { DisplayInfoShape as displayInfo };
|
|
29
43
|
}
|
|
30
|
-
export const BrandI: import("@endo/patterns").InterfaceGuard
|
|
44
|
+
export const BrandI: import("@endo/patterns").InterfaceGuard<{
|
|
45
|
+
isMyIssuer: import("@endo/patterns").MethodGuard;
|
|
46
|
+
getAllegedName: import("@endo/patterns").MethodGuard;
|
|
47
|
+
getDisplayInfo: import("@endo/patterns").MethodGuard;
|
|
48
|
+
getAmountShape: import("@endo/patterns").MethodGuard;
|
|
49
|
+
}>;
|
|
31
50
|
export function makeIssuerInterfaces(brandShape?: Pattern, assetKindShape?: Pattern, amountShape?: Pattern): {
|
|
32
|
-
IssuerI: import("@endo/patterns").InterfaceGuard
|
|
33
|
-
|
|
34
|
-
|
|
51
|
+
IssuerI: import("@endo/patterns").InterfaceGuard<{
|
|
52
|
+
getBrand: import("@endo/patterns").MethodGuard;
|
|
53
|
+
getAllegedName: import("@endo/patterns").MethodGuard;
|
|
54
|
+
getAssetKind: import("@endo/patterns").MethodGuard;
|
|
55
|
+
getDisplayInfo: import("@endo/patterns").MethodGuard;
|
|
56
|
+
makeEmptyPurse: import("@endo/patterns").MethodGuard;
|
|
57
|
+
isLive: import("@endo/patterns").MethodGuard;
|
|
58
|
+
getAmountOf: import("@endo/patterns").MethodGuard;
|
|
59
|
+
burn: import("@endo/patterns").MethodGuard;
|
|
60
|
+
}>;
|
|
61
|
+
MintI: import("@endo/patterns").InterfaceGuard<{
|
|
62
|
+
getIssuer: import("@endo/patterns").MethodGuard;
|
|
63
|
+
mintPayment: import("@endo/patterns").MethodGuard;
|
|
64
|
+
}>;
|
|
65
|
+
PaymentI: import("@endo/patterns").InterfaceGuard<{
|
|
66
|
+
getAllegedBrand: import("@endo/patterns").MethodGuard;
|
|
67
|
+
}>;
|
|
35
68
|
PurseIKit: {
|
|
36
|
-
purse: import("@endo/patterns").InterfaceGuard
|
|
37
|
-
|
|
69
|
+
purse: import("@endo/patterns").InterfaceGuard<{
|
|
70
|
+
getAllegedBrand: import("@endo/patterns").MethodGuard;
|
|
71
|
+
getCurrentAmount: import("@endo/patterns").MethodGuard;
|
|
72
|
+
getCurrentAmountNotifier: import("@endo/patterns").MethodGuard;
|
|
73
|
+
deposit: import("@endo/patterns").MethodGuard;
|
|
74
|
+
getDepositFacet: import("@endo/patterns").MethodGuard;
|
|
75
|
+
withdraw: import("@endo/patterns").MethodGuard;
|
|
76
|
+
getRecoverySet: import("@endo/patterns").MethodGuard;
|
|
77
|
+
recoverAll: import("@endo/patterns").MethodGuard;
|
|
78
|
+
}>;
|
|
79
|
+
depositFacet: import("@endo/patterns").InterfaceGuard<{
|
|
80
|
+
receive: import("@endo/patterns").MethodGuard;
|
|
81
|
+
}>;
|
|
38
82
|
};
|
|
39
83
|
};
|
|
40
84
|
declare const AmountValueShape: import("@endo/patterns").Matcher;
|
|
85
|
+
import type { Ratio } from './types.js';
|
|
86
|
+
import type { TypedPattern } from '@agoric/internal';
|
|
87
|
+
import type { AmountValue } from './types.js';
|
|
41
88
|
export {};
|
|
42
89
|
//# sourceMappingURL=typeGuards.d.ts.map
|
package/src/typeGuards.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeGuards.d.ts","sourceRoot":"","sources":["typeGuards.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"typeGuards.d.ts","sourceRoot":"","sources":["typeGuards.js"],"names":[],"mappings":"AAGA;;;GAGG;AAEH,0DAA+C;AAC/C,2DAAiD;AACjD,4DAAmD;AACnD,0DAA+C;AAC/C,iEAA6D;AAC7D,6DAAqD;AACrD,yDAA6C;;;;;AAkE7C;;;;;;;;;;GAUG;AACH,kEAA8C;AAE9C,kCAAkC;AAClC,yBADW,aAAa,KAAK,CAAC,CACiD;AASxE,kCAHI,WAAW,GACT,KAAK,IAAI,OAAO,YAAY,EAAE,QAAQ,CAEa;AASzD,sCAHI,WAAW,GACT,KAAK,IAAI,OAAO,CAE2C;AAYjE,kCAHI,WAAW,GACT,KAAK,IAAI,QAAQ,CAEkC;AASzD,sCAHI,WAAW,GACT,KAAK,IAAI,OAAO,CAE2C;AAIxE,8CAA+C;AAE/C,8DAAuE;AAEvE,gEAaE;;;;;;;;AAaF;;;;;GAKG;AAOI,kDAJI,OAAO,mBACP,OAAO,gBACP,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqEjB;AAhLD,iEAKE;2BAvEmC,YAAY;kCAClB,kBAAkB;iCADZ,YAAY"}
|
package/src/typeGuards.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
// @jessie-check
|
|
2
2
|
|
|
3
|
-
import { M, matches } from '@
|
|
3
|
+
import { M, matches, getInterfaceGuardPayload } from '@endo/patterns';
|
|
4
|
+
/**
|
|
5
|
+
* @import {AmountValue, Ratio} from './types.js'
|
|
6
|
+
* @import {TypedPattern} from '@agoric/internal'
|
|
7
|
+
*/
|
|
4
8
|
|
|
5
9
|
export const BrandShape = M.remotable('Brand');
|
|
6
10
|
export const IssuerShape = M.remotable('Issuer');
|
|
@@ -11,62 +15,56 @@ export const NotifierShape = M.remotable('Notifier');
|
|
|
11
15
|
export const MintShape = M.remotable('Mint');
|
|
12
16
|
|
|
13
17
|
/**
|
|
14
|
-
* When the AmountValue of an Amount fits the NatValueShape, i.e., when it is
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* set of fungible units.
|
|
18
|
+
* When the AmountValue of an Amount fits the NatValueShape, i.e., when it is a
|
|
19
|
+
* non-negative bigint, then it represents that many units of the fungible asset
|
|
20
|
+
* represented by that amount. The brand of that amount should indeed represent
|
|
21
|
+
* a kind of asset consisting of a countable set of fungible units.
|
|
19
22
|
*/
|
|
20
23
|
const NatValueShape = M.nat();
|
|
21
24
|
|
|
22
25
|
/**
|
|
23
26
|
* When the AmountValue of an Amount fits the CopySetValueShape, i.e., when it
|
|
24
|
-
* is a CopySet, then it represents the set of those
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* from the same asset class.
|
|
27
|
+
* is a CopySet, then it represents the set of those keys, where each key
|
|
28
|
+
* represents some individual non-fungible item, like a concert ticket, from the
|
|
29
|
+
* non-fungible asset class represented by that amount's brand. The amount
|
|
30
|
+
* itself represents the set of these items, as opposed to any of the other
|
|
31
|
+
* items from the same asset class.
|
|
30
32
|
*
|
|
31
|
-
* If a given value class represents concert tickets, it seems bizarre
|
|
32
|
-
*
|
|
33
|
-
* the
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* "You can't always get..."
|
|
33
|
+
* If a given value class represents concert tickets, it seems bizarre that we
|
|
34
|
+
* can form amounts of any key. The hard constraint is that the code that holds
|
|
35
|
+
* the mint for that asset class---the one associated with that brand, only
|
|
36
|
+
* mints the items representing the real units of that asset class as defined by
|
|
37
|
+
* it. Anyone else can put together an amount expressing, for example, that they
|
|
38
|
+
* "want" some items that will never be minted. That want will never be
|
|
39
|
+
* satisfied. "You can't always get..."
|
|
39
40
|
*/
|
|
40
41
|
const CopySetValueShape = M.set();
|
|
41
42
|
|
|
42
43
|
/**
|
|
43
|
-
* When the AmountValue of an Amount fits the SetValueShape, i.e., when it
|
|
44
|
-
*
|
|
44
|
+
* When the AmountValue of an Amount fits the SetValueShape, i.e., when it is a
|
|
45
|
+
* CopyArray of passable Keys. This representation is deprecated.
|
|
45
46
|
*
|
|
46
47
|
* @deprecated Please change from using array-based SetValues to CopySet-based
|
|
47
|
-
*
|
|
48
|
+
* CopySetValues.
|
|
48
49
|
*/
|
|
49
50
|
const SetValueShape = M.arrayOf(M.key());
|
|
50
51
|
|
|
51
52
|
/**
|
|
52
53
|
* When the AmountValue of an Amount fits the CopyBagValueShape, i.e., when it
|
|
53
|
-
* is a CopyBag, then it represents the bag (multiset) of those
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* the bag of these items, as opposed to any of the other items
|
|
60
|
-
* from the same asset class.
|
|
54
|
+
* is a CopyBag, then it represents the bag (multiset) of those keys, where each
|
|
55
|
+
* key represents some individual semi-fungible item, like a concert ticket,
|
|
56
|
+
* from the semi-fungible asset class represented by that amount's brand. The
|
|
57
|
+
* number of times that key appears in the bag is the number of fungible units
|
|
58
|
+
* of that key. The amount itself represents the bag of these items, as opposed
|
|
59
|
+
* to any of the other items from the same asset class.
|
|
61
60
|
*
|
|
62
|
-
* If a given value class represents concert tickets, it seems bizarre
|
|
63
|
-
*
|
|
64
|
-
* the
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* "You can't always get..."
|
|
61
|
+
* If a given value class represents concert tickets, it seems bizarre that we
|
|
62
|
+
* can form amounts of any key. The hard constraint is that the code that holds
|
|
63
|
+
* the mint for that asset class---the one associated with that brand, only
|
|
64
|
+
* mints the items representing the real units of that asset class as defined by
|
|
65
|
+
* it. Anyone else can put together an amount expressing, for example, that they
|
|
66
|
+
* "want" some items that will never be minted. That want will never be
|
|
67
|
+
* satisfied. "You can't always get..."
|
|
70
68
|
*/
|
|
71
69
|
const CopyBagValueShape = M.bag();
|
|
72
70
|
|
|
@@ -77,15 +75,25 @@ const AmountValueShape = M.or(
|
|
|
77
75
|
CopyBagValueShape,
|
|
78
76
|
);
|
|
79
77
|
|
|
80
|
-
export const AmountShape =
|
|
81
|
-
|
|
82
|
-
value: AmountValueShape,
|
|
83
|
-
});
|
|
78
|
+
export const AmountShape = { brand: BrandShape, value: AmountValueShape };
|
|
79
|
+
harden(AmountShape);
|
|
84
80
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
81
|
+
/**
|
|
82
|
+
* To be used to guard an amount pattern argument, i.e., an argument which is a
|
|
83
|
+
* pattern that can be used to test amounts. Since amounts are keys, anywhere an
|
|
84
|
+
* amount pattern is expected, an amount can be provided and will match only
|
|
85
|
+
* that concrete amount, i.e., amounts that are `keyEQ` to that amount.
|
|
86
|
+
*
|
|
87
|
+
* The `AmountShape` guard above is an amount pattern. But not all amount
|
|
88
|
+
* patterns are like `AmountShape`. For example, `M.any()` is a valid amount
|
|
89
|
+
* pattern that will admit any amount, but is does not resemble the
|
|
90
|
+
* `AmountShape` pattern above.
|
|
91
|
+
*/
|
|
92
|
+
export const AmountPatternShape = M.pattern();
|
|
93
|
+
|
|
94
|
+
/** @type {TypedPattern<Ratio>} */
|
|
95
|
+
export const RatioShape = { numerator: AmountShape, denominator: AmountShape };
|
|
96
|
+
harden(RatioShape);
|
|
89
97
|
|
|
90
98
|
/**
|
|
91
99
|
* Returns true if value is a Nat bigint.
|
|
@@ -106,11 +114,11 @@ export const isCopySetValue = value => matches(value, CopySetValueShape);
|
|
|
106
114
|
harden(isCopySetValue);
|
|
107
115
|
|
|
108
116
|
/**
|
|
109
|
-
* Returns true if value is a pass by copy array structure. Does not
|
|
110
|
-
*
|
|
117
|
+
* Returns true if value is a pass by copy array structure. Does not check for
|
|
118
|
+
* duplicates. To check for duplicates, use setMathHelpers.coerce.
|
|
111
119
|
*
|
|
112
120
|
* @deprecated Please change from using array-based SetValues to CopySet-based
|
|
113
|
-
*
|
|
121
|
+
* CopySetValues.
|
|
114
122
|
* @param {AmountValue} value
|
|
115
123
|
* @returns {value is SetValue}
|
|
116
124
|
*/
|
|
@@ -146,13 +154,14 @@ export const DisplayInfoShape = M.splitRecord(
|
|
|
146
154
|
},
|
|
147
155
|
);
|
|
148
156
|
|
|
149
|
-
export const IssuerKitShape =
|
|
157
|
+
export const IssuerKitShape = {
|
|
150
158
|
brand: BrandShape,
|
|
151
159
|
mint: MintShape,
|
|
152
160
|
mintRecoveryPurse: PurseShape,
|
|
153
161
|
issuer: IssuerShape,
|
|
154
162
|
displayInfo: DisplayInfoShape,
|
|
155
|
-
}
|
|
163
|
+
};
|
|
164
|
+
harden(IssuerKitShape);
|
|
156
165
|
|
|
157
166
|
// //////////////////////// Interfaces /////////////////////////////////////////
|
|
158
167
|
|
|
@@ -183,7 +192,7 @@ export const makeIssuerInterfaces = (
|
|
|
183
192
|
isLive: M.callWhen(M.await(PaymentShape)).returns(M.boolean()),
|
|
184
193
|
getAmountOf: M.callWhen(M.await(PaymentShape)).returns(amountShape),
|
|
185
194
|
burn: M.callWhen(M.await(PaymentShape))
|
|
186
|
-
.optional(
|
|
195
|
+
.optional(AmountPatternShape)
|
|
187
196
|
.returns(amountShape),
|
|
188
197
|
});
|
|
189
198
|
|
|
@@ -210,7 +219,9 @@ export const makeIssuerInterfaces = (
|
|
|
210
219
|
// `srcPayment` is a remotable, leaving it
|
|
211
220
|
// to this raw method to validate that this remotable is actually
|
|
212
221
|
// a live payment of the correct brand with sufficient funds.
|
|
213
|
-
deposit: M.call(PaymentShape)
|
|
222
|
+
deposit: M.call(PaymentShape)
|
|
223
|
+
.optional(AmountPatternShape)
|
|
224
|
+
.returns(amountShape),
|
|
214
225
|
getDepositFacet: M.call().returns(DepositFacetShape),
|
|
215
226
|
withdraw: M.call(amountShape).returns(PaymentShape),
|
|
216
227
|
getRecoverySet: M.call().returns(M.setOf(PaymentShape)),
|
|
@@ -218,13 +229,14 @@ export const makeIssuerInterfaces = (
|
|
|
218
229
|
});
|
|
219
230
|
|
|
220
231
|
const DepositFacetI = M.interface('DepositFacet', {
|
|
221
|
-
receive: PurseI.methodGuards.deposit,
|
|
232
|
+
receive: getInterfaceGuardPayload(PurseI).methodGuards.deposit,
|
|
222
233
|
});
|
|
223
234
|
|
|
224
|
-
const PurseIKit =
|
|
235
|
+
const PurseIKit = {
|
|
225
236
|
purse: PurseI,
|
|
226
237
|
depositFacet: DepositFacetI,
|
|
227
|
-
}
|
|
238
|
+
};
|
|
239
|
+
harden(PurseIKit);
|
|
228
240
|
|
|
229
241
|
return harden({
|
|
230
242
|
IssuerI,
|