@agoric/ertp 0.16.3-other-dev-8f8782b.0 → 0.16.3-other-dev-fbe72e7.0.fbe72e7
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 +37 -37
- package/src/amountMath.d.ts +46 -38
- package/src/amountMath.d.ts.map +1 -1
- package/src/amountMath.js +136 -128
- 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 +29 -9
- package/src/issuerKit.d.ts.map +1 -1
- package/src/issuerKit.js +230 -75
- package/src/legacy-payment-helpers.d.ts +9 -2
- package/src/legacy-payment-helpers.d.ts.map +1 -1
- package/src/legacy-payment-helpers.js +43 -37
- 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 +8 -8
- package/src/paymentLedger.d.ts +8 -2
- package/src/paymentLedger.d.ts.map +1 -1
- package/src/paymentLedger.js +80 -97
- package/src/purse.d.ts +19 -9
- package/src/purse.d.ts.map +1 -1
- package/src/purse.js +86 -26
- package/src/ratio.d.ts +48 -0
- package/src/ratio.d.ts.map +1 -0
- package/src/ratio.js +441 -0
- package/src/safeMath.d.ts +11 -0
- package/src/safeMath.d.ts.map +1 -0
- package/src/safeMath.js +50 -0
- 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 +64 -13
- package/src/typeGuards.d.ts.map +1 -1
- package/src/typeGuards.js +70 -57
- package/src/types-index.d.ts +2 -0
- package/src/types-index.js +2 -0
- package/src/types.d.ts +254 -220
- package/src/types.d.ts.map +1 -1
- package/src/types.ts +474 -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/issuerKit.js
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
// @jessie-check
|
|
2
2
|
|
|
3
|
-
import { assert } from '@
|
|
3
|
+
import { assert, Fail } from '@endo/errors';
|
|
4
4
|
import { assertPattern } from '@agoric/store';
|
|
5
5
|
import { makeScalarBigMapStore } from '@agoric/vat-data';
|
|
6
|
+
import { makeDurableZone } from '@agoric/zone/durable.js';
|
|
6
7
|
|
|
7
8
|
import { AssetKind, assertAssetKind } from './amountMath.js';
|
|
8
9
|
import { coerceDisplayInfo } from './displayInfo.js';
|
|
9
10
|
import { preparePaymentLedger } from './paymentLedger.js';
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
/**
|
|
13
|
+
* @import {Key, Pattern} from '@endo/patterns';
|
|
14
|
+
* @import {Zone} from '@agoric/base-zone';
|
|
15
|
+
* @import {ShutdownWithFailure} from '@agoric/swingset-vat';
|
|
16
|
+
* @import {TypedPattern} from '@agoric/internal';
|
|
17
|
+
* @import {Baggage} from '@agoric/vat-data';
|
|
18
|
+
* @import {AdditionalDisplayInfo, RecoverySetsOption, IssuerKit, PaymentLedger} from './types.js';
|
|
19
|
+
*/
|
|
14
20
|
|
|
15
21
|
/**
|
|
16
22
|
* @template {AssetKind} K
|
|
@@ -22,21 +28,26 @@ import './types-ambient.js';
|
|
|
22
28
|
*/
|
|
23
29
|
|
|
24
30
|
/**
|
|
31
|
+
* Used _only_ internally, to make a new issuerKit or to revive an old one.
|
|
32
|
+
*
|
|
25
33
|
* @template {AssetKind} K
|
|
26
34
|
* @param {IssuerRecord<K>} issuerRecord
|
|
27
|
-
* @param {
|
|
28
|
-
* @param {
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
+
* @param {Zone} issuerZone
|
|
36
|
+
* @param {RecoverySetsOption} recoverySetsState Omitted from issuerRecord
|
|
37
|
+
* because it was added in an upgrade.
|
|
38
|
+
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails in
|
|
39
|
+
* the middle of an atomic action (which btw should never happen), it
|
|
40
|
+
* potentially leaves its ledger in a corrupted state. If this function was
|
|
41
|
+
* provided, then the failed atomic action will call it, so that some larger
|
|
42
|
+
* unit of computation, like the enclosing vat, can be shutdown before
|
|
43
|
+
* anything else is corrupted by that corrupted state. See
|
|
44
|
+
* https://github.com/Agoric/agoric-sdk/issues/3434
|
|
35
45
|
* @returns {IssuerKit<K>}
|
|
36
46
|
*/
|
|
37
47
|
const setupIssuerKit = (
|
|
38
48
|
{ name, assetKind, displayInfo, elementShape },
|
|
39
|
-
|
|
49
|
+
issuerZone,
|
|
50
|
+
recoverySetsState,
|
|
40
51
|
optShutdownWithFailure = undefined,
|
|
41
52
|
) => {
|
|
42
53
|
assert.typeof(name, 'string');
|
|
@@ -54,13 +65,14 @@ const setupIssuerKit = (
|
|
|
54
65
|
|
|
55
66
|
// Attenuate the powerful authority to mint and change balances
|
|
56
67
|
/** @type {PaymentLedger<K>} */
|
|
57
|
-
// @ts-expect-error could be instantiated with different subtype
|
|
68
|
+
// @ts-expect-error could be instantiated with a different subtype
|
|
58
69
|
const { issuer, mint, brand, mintRecoveryPurse } = preparePaymentLedger(
|
|
59
|
-
|
|
70
|
+
issuerZone,
|
|
60
71
|
name,
|
|
61
72
|
assetKind,
|
|
62
73
|
cleanDisplayInfo,
|
|
63
74
|
elementShape,
|
|
75
|
+
recoverySetsState,
|
|
64
76
|
optShutdownWithFailure,
|
|
65
77
|
);
|
|
66
78
|
|
|
@@ -76,66 +88,113 @@ harden(setupIssuerKit);
|
|
|
76
88
|
|
|
77
89
|
/** The key at which the issuer record is stored. */
|
|
78
90
|
const INSTANCE_KEY = 'issuer';
|
|
91
|
+
/**
|
|
92
|
+
* The key at which the issuerKit's `RecoverySetsOption` state is stored.
|
|
93
|
+
* Introduced by an upgrade, so may be absent on a predecessor incarnation. See
|
|
94
|
+
* `RecoverySetsOption` for defaulting behavior.
|
|
95
|
+
*/
|
|
96
|
+
const RECOVERY_SETS_STATE = 'recoverySetsState';
|
|
79
97
|
|
|
80
98
|
/**
|
|
99
|
+
* Used _only_ to upgrade a predecessor issuerKit. Use `makeDurableIssuerKit` to
|
|
100
|
+
* make a new one.
|
|
101
|
+
*
|
|
81
102
|
* @template {AssetKind} K
|
|
82
103
|
* @param {Baggage} issuerBaggage
|
|
83
|
-
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
104
|
+
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails in
|
|
105
|
+
* the middle of an atomic action (which btw should never happen), it
|
|
106
|
+
* potentially leaves its ledger in a corrupted state. If this function was
|
|
107
|
+
* provided, then the failed atomic action will call it, so that some larger
|
|
108
|
+
* unit of computation, like the enclosing vat, can be shutdown before
|
|
109
|
+
* anything else is corrupted by that corrupted state. See
|
|
110
|
+
* https://github.com/Agoric/agoric-sdk/issues/3434
|
|
111
|
+
* @param {RecoverySetsOption} [recoverySetsOption] Added in upgrade, so last
|
|
112
|
+
* and optional. See `RecoverySetsOption` for defaulting behavior.
|
|
90
113
|
* @returns {IssuerKit<K>}
|
|
91
114
|
*/
|
|
92
|
-
export const
|
|
115
|
+
export const upgradeIssuerKit = (
|
|
93
116
|
issuerBaggage,
|
|
94
117
|
optShutdownWithFailure = undefined,
|
|
118
|
+
recoverySetsOption = undefined,
|
|
95
119
|
) => {
|
|
96
120
|
const issuerRecord = issuerBaggage.get(INSTANCE_KEY);
|
|
97
|
-
|
|
121
|
+
const issuerZone = makeDurableZone(issuerBaggage);
|
|
122
|
+
const oldRecoverySetsState = issuerBaggage.has(RECOVERY_SETS_STATE)
|
|
123
|
+
? issuerBaggage.get(RECOVERY_SETS_STATE)
|
|
124
|
+
: 'hasRecoverySets';
|
|
125
|
+
if (
|
|
126
|
+
oldRecoverySetsState === 'noRecoverySets' &&
|
|
127
|
+
recoverySetsOption === 'hasRecoverySets'
|
|
128
|
+
) {
|
|
129
|
+
Fail`Cannot (yet?) upgrade from 'noRecoverySets' to 'hasRecoverySets'`;
|
|
130
|
+
}
|
|
131
|
+
// Extant sets are not currently deleted. If the new option is
|
|
132
|
+
// 'noRecoverySets', they won't be used but extant ones will remain. Future
|
|
133
|
+
// upgrades may make it possible to delete elements from them.
|
|
134
|
+
const recoverySetsState = recoverySetsOption || oldRecoverySetsState;
|
|
135
|
+
return setupIssuerKit(
|
|
136
|
+
issuerRecord,
|
|
137
|
+
issuerZone,
|
|
138
|
+
recoverySetsState,
|
|
139
|
+
optShutdownWithFailure,
|
|
140
|
+
);
|
|
98
141
|
};
|
|
99
|
-
harden(
|
|
142
|
+
harden(upgradeIssuerKit);
|
|
100
143
|
|
|
101
144
|
/**
|
|
102
|
-
* Does baggage already have an
|
|
103
|
-
* That is: does it have the relevant keys defined?
|
|
145
|
+
* Does baggage already have an issuerKit?
|
|
104
146
|
*
|
|
105
147
|
* @param {Baggage} baggage
|
|
106
148
|
*/
|
|
107
149
|
export const hasIssuer = baggage => baggage.has(INSTANCE_KEY);
|
|
108
150
|
|
|
109
151
|
/**
|
|
110
|
-
*
|
|
152
|
+
* `elementShape`, may only be present for collection-style amounts. If present,
|
|
153
|
+
* it is a `Pattern` that every element of this issuerKits's amounts must
|
|
154
|
+
* satisfy. For example, the Zoe Invitation issuerKit uses an elementShape
|
|
155
|
+
* describing the invitation details for an individual invitation. An invitation
|
|
156
|
+
* purse or payment has an amount that can only be a set of these. (Though
|
|
157
|
+
* typically, the amount of an invitation payment is a singleton set. Such a
|
|
158
|
+
* payment is often referred to in the singular as "an invitation".)
|
|
159
|
+
*
|
|
160
|
+
* `recoverySetsOption` added in upgrade. Note that `IssuerOptionsRecord` is
|
|
161
|
+
* never stored, so we never need to worry about inheriting one from a
|
|
162
|
+
* predecessor predating the introduction of recovery sets. See
|
|
163
|
+
* `RecoverySetsOption` for defaulting behavior.
|
|
164
|
+
*
|
|
165
|
+
* @typedef {Partial<{
|
|
166
|
+
* elementShape: Pattern;
|
|
167
|
+
* recoverySetsOption: RecoverySetsOption;
|
|
168
|
+
* }>} IssuerOptionsRecord
|
|
111
169
|
*/
|
|
112
170
|
|
|
113
171
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
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.
|
|
172
|
+
* Used _only_ to make a _new_ durable issuer, i.e., the initial incarnation of
|
|
173
|
+
* that issuer.
|
|
121
174
|
*
|
|
122
|
-
* The
|
|
123
|
-
*
|
|
124
|
-
*
|
|
175
|
+
* @template {AssetKind} K The name becomes part of the brand in asset
|
|
176
|
+
* descriptions. The name is useful for debugging and double-checking
|
|
177
|
+
* assumptions, but should not be trusted wrt any external namespace. For
|
|
178
|
+
* example, anyone could create a new issuer kit with name 'BTC', but it is
|
|
179
|
+
* not bitcoin or even related. It is only the name according to that issuer
|
|
180
|
+
* and brand.
|
|
125
181
|
*
|
|
126
|
-
*
|
|
182
|
+
* The assetKind will be used to import a specific mathHelpers from the
|
|
183
|
+
* mathHelpers library. For example, natMathHelpers, the default, is used for
|
|
184
|
+
* basic fungible tokens.
|
|
127
185
|
*
|
|
186
|
+
* `displayInfo` gives information to the UI on how to display the amount.
|
|
128
187
|
* @param {Baggage} issuerBaggage
|
|
129
188
|
* @param {string} name
|
|
130
|
-
* @param {K} [assetKind
|
|
131
|
-
* @param {AdditionalDisplayInfo} [displayInfo
|
|
132
|
-
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
189
|
+
* @param {K} [assetKind]
|
|
190
|
+
* @param {AdditionalDisplayInfo} [displayInfo]
|
|
191
|
+
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails in
|
|
192
|
+
* the middle of an atomic action (which btw should never happen), it
|
|
193
|
+
* potentially leaves its ledger in a corrupted state. If this function was
|
|
194
|
+
* provided, then the failed atomic action will call it, so that some larger
|
|
195
|
+
* unit of computation, like the enclosing vat, can be shutdown before
|
|
196
|
+
* anything else is corrupted by that corrupted state. See
|
|
197
|
+
* https://github.com/Agoric/agoric-sdk/issues/3434
|
|
139
198
|
* @param {IssuerOptionsRecord} [options]
|
|
140
199
|
* @returns {IssuerKit<K>}
|
|
141
200
|
*/
|
|
@@ -146,41 +205,135 @@ export const makeDurableIssuerKit = (
|
|
|
146
205
|
assetKind = AssetKind.NAT,
|
|
147
206
|
displayInfo = harden({}),
|
|
148
207
|
optShutdownWithFailure = undefined,
|
|
149
|
-
{ elementShape = undefined } = {},
|
|
208
|
+
{ elementShape = undefined, recoverySetsOption = undefined } = {},
|
|
150
209
|
) => {
|
|
151
|
-
const issuerData = harden({
|
|
210
|
+
const issuerData = harden({
|
|
211
|
+
name,
|
|
212
|
+
assetKind,
|
|
213
|
+
displayInfo,
|
|
214
|
+
elementShape,
|
|
215
|
+
});
|
|
152
216
|
issuerBaggage.init(INSTANCE_KEY, issuerData);
|
|
153
|
-
|
|
217
|
+
const issuerZone = makeDurableZone(issuerBaggage);
|
|
218
|
+
const recoverySetsState = recoverySetsOption || 'hasRecoverySets';
|
|
219
|
+
issuerBaggage.init(RECOVERY_SETS_STATE, recoverySetsState);
|
|
220
|
+
return setupIssuerKit(
|
|
221
|
+
issuerData,
|
|
222
|
+
issuerZone,
|
|
223
|
+
recoverySetsState,
|
|
224
|
+
optShutdownWithFailure,
|
|
225
|
+
);
|
|
154
226
|
};
|
|
155
227
|
harden(makeDurableIssuerKit);
|
|
156
228
|
|
|
157
229
|
/**
|
|
158
|
-
*
|
|
159
|
-
*
|
|
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.
|
|
230
|
+
* Used to either revive a predecessor issuerKit, or to make a new durable one
|
|
231
|
+
* if it is absent, and to place it in baggage for the next successor.
|
|
165
232
|
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
233
|
+
* @template {IssuerOptionsRecord} O
|
|
234
|
+
* @template {AssetKind} K The name becomes part of the brand in asset
|
|
235
|
+
* descriptions. The name is useful for debugging and double-checking
|
|
236
|
+
* assumptions, but should not be trusted wrt any external namespace. For
|
|
237
|
+
* example, anyone could create a new issuer kit with name 'BTC', but it is
|
|
238
|
+
* not bitcoin or even related. It is only the name according to that issuer
|
|
239
|
+
* and brand.
|
|
169
240
|
*
|
|
170
|
-
*
|
|
241
|
+
* The assetKind will be used to import a specific mathHelpers from the
|
|
242
|
+
* mathHelpers library. For example, natMathHelpers, the default, is used for
|
|
243
|
+
* basic fungible tokens.
|
|
171
244
|
*
|
|
245
|
+
* `displayInfo` gives information to the UI on how to display the amount.
|
|
246
|
+
* @param {Baggage} issuerBaggage
|
|
172
247
|
* @param {string} name
|
|
173
|
-
* @param {K} [assetKind
|
|
174
|
-
* @param {AdditionalDisplayInfo} [displayInfo
|
|
175
|
-
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
* @param {
|
|
183
|
-
* @returns {
|
|
248
|
+
* @param {K} [assetKind]
|
|
249
|
+
* @param {AdditionalDisplayInfo} [displayInfo]
|
|
250
|
+
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails in
|
|
251
|
+
* the middle of an atomic action (which btw should never happen), it
|
|
252
|
+
* potentially leaves its ledger in a corrupted state. If this function was
|
|
253
|
+
* provided, then the failed atomic action will call it, so that some larger
|
|
254
|
+
* unit of computation, like the enclosing vat, can be shutdown before
|
|
255
|
+
* anything else is corrupted by that corrupted state. See
|
|
256
|
+
* https://github.com/Agoric/agoric-sdk/issues/3434
|
|
257
|
+
* @param {O} [options]
|
|
258
|
+
* @returns {O['elementShape'] extends TypedPattern<infer T extends Key>
|
|
259
|
+
* ? IssuerKit<K, T>
|
|
260
|
+
* : IssuerKit<K>}
|
|
261
|
+
*/
|
|
262
|
+
export const prepareIssuerKit = (
|
|
263
|
+
issuerBaggage,
|
|
264
|
+
name,
|
|
265
|
+
// @ts-expect-error K could be instantiated with a different subtype of AssetKind
|
|
266
|
+
assetKind = AssetKind.NAT,
|
|
267
|
+
displayInfo = harden({}),
|
|
268
|
+
optShutdownWithFailure = undefined,
|
|
269
|
+
// @ts-expect-error could have a different subtype of IssuerOptionsRecord
|
|
270
|
+
options = {},
|
|
271
|
+
) => {
|
|
272
|
+
if (hasIssuer(issuerBaggage)) {
|
|
273
|
+
const { elementShape: _ = undefined, recoverySetsOption = undefined } =
|
|
274
|
+
options;
|
|
275
|
+
const issuerKit = upgradeIssuerKit(
|
|
276
|
+
issuerBaggage,
|
|
277
|
+
optShutdownWithFailure,
|
|
278
|
+
recoverySetsOption,
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
// TODO check consistency with name, assetKind, displayInfo, elementShape.
|
|
282
|
+
// Consistency either means that these are the same, or that they differ
|
|
283
|
+
// in a direction we are prepared to upgrade. Note that it is the
|
|
284
|
+
// responsibility of `upgradeIssuerKit` to check consistency of
|
|
285
|
+
// `recoverySetsOption`, so continue to not do that here.
|
|
286
|
+
|
|
287
|
+
// @ts-expect-error Type parameter confusion.
|
|
288
|
+
return issuerKit;
|
|
289
|
+
} else {
|
|
290
|
+
const issuerKit = makeDurableIssuerKit(
|
|
291
|
+
issuerBaggage,
|
|
292
|
+
name,
|
|
293
|
+
assetKind,
|
|
294
|
+
displayInfo,
|
|
295
|
+
optShutdownWithFailure,
|
|
296
|
+
options,
|
|
297
|
+
);
|
|
298
|
+
// @ts-expect-error cast to the type parameter
|
|
299
|
+
return issuerKit;
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
harden(prepareIssuerKit);
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Used _only_ to make a new issuerKit that is effectively non-durable. This is
|
|
306
|
+
* currently done by making a durable one in a baggage not reachable from
|
|
307
|
+
* anywhere. TODO Once rebuilt on zones, this should instead just build on the
|
|
308
|
+
* virtual zone. See https://github.com/Agoric/agoric-sdk/pull/7116
|
|
309
|
+
*
|
|
310
|
+
* Currently used for testing only. Should probably continue to be used for
|
|
311
|
+
* testing only.
|
|
312
|
+
*
|
|
313
|
+
* @template {AssetKind} [K='nat']
|
|
314
|
+
* @template {IssuerOptionsRecord} [O={}]
|
|
315
|
+
* @param {string} name The name becomes part of the brand in asset
|
|
316
|
+
* descriptions. The name is useful for debugging and double-checking
|
|
317
|
+
* assumptions, but should not be trusted wrt any external namespace. For
|
|
318
|
+
* example, anyone could create a new issuer kit with name 'BTC', but it is
|
|
319
|
+
* not bitcoin or even related. It is only the name according to that issuer
|
|
320
|
+
* and brand.
|
|
321
|
+
* @param {K} [assetKind] The assetKind will be used to import a specific
|
|
322
|
+
* mathHelpers from the mathHelpers library. For example, natMathHelpers, the
|
|
323
|
+
* default, is used for basic fungible tokens.
|
|
324
|
+
* @param {AdditionalDisplayInfo} [displayInfo] `displayInfo` gives information
|
|
325
|
+
* to the UI on how to display the amount.
|
|
326
|
+
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails in
|
|
327
|
+
* the middle of an atomic action (which btw should never happen), it
|
|
328
|
+
* potentially leaves its ledger in a corrupted state. If this function was
|
|
329
|
+
* provided, then the failed atomic action will call it, so that some larger
|
|
330
|
+
* unit of computation, like the enclosing vat, can be shutdown before
|
|
331
|
+
* anything else is corrupted by that corrupted state. See
|
|
332
|
+
* https://github.com/Agoric/agoric-sdk/issues/3434
|
|
333
|
+
* @param {O} [options]
|
|
334
|
+
* @returns {O['elementShape'] extends TypedPattern<infer T extends Key>
|
|
335
|
+
* ? IssuerKit<K, T>
|
|
336
|
+
* : IssuerKit<K>}
|
|
184
337
|
*/
|
|
185
338
|
export const makeIssuerKit = (
|
|
186
339
|
name,
|
|
@@ -188,14 +341,16 @@ export const makeIssuerKit = (
|
|
|
188
341
|
assetKind = AssetKind.NAT,
|
|
189
342
|
displayInfo = harden({}),
|
|
190
343
|
optShutdownWithFailure = undefined,
|
|
191
|
-
|
|
344
|
+
// @ts-expect-error O could be instantiated with a different subtype
|
|
345
|
+
{ elementShape = undefined, recoverySetsOption = undefined } = {},
|
|
192
346
|
) =>
|
|
347
|
+
// @ts-expect-error cast
|
|
193
348
|
makeDurableIssuerKit(
|
|
194
349
|
makeScalarBigMapStore('dropped issuer kit', { durable: true }),
|
|
195
350
|
name,
|
|
196
351
|
assetKind,
|
|
197
352
|
displayInfo,
|
|
198
353
|
optShutdownWithFailure,
|
|
199
|
-
{ elementShape },
|
|
354
|
+
{ elementShape, recoverySetsOption },
|
|
200
355
|
);
|
|
201
356
|
harden(makeIssuerKit);
|
|
@@ -1,5 +1,12 @@
|
|
|
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>>;
|
|
1
|
+
export function claim<K extends AssetKind, T extends Key>(recoveryPurse: ERef<Purse<K, T>>, srcPaymentP: ERef<Payment<K, T>>, optAmountShape?: Pattern): Promise<Payment<K, T>>;
|
|
2
|
+
export function combine<K extends AssetKind, T extends Key>(recoveryPurse: ERef<Purse<K, T>>, srcPaymentsPs: ERef<Payment<K, T>>[], optTotalAmount?: Pattern): Promise<Payment<K, T>>;
|
|
3
3
|
export function split<K extends AssetKind>(recoveryPurse: ERef<Purse<K>>, srcPaymentP: ERef<Payment<K>>, paymentAmountA: Amount<K>): Promise<Payment<K>[]>;
|
|
4
4
|
export function splitMany<K extends AssetKind>(recoveryPurse: ERef<Purse<K>>, srcPaymentP: ERef<Payment<K>>, amounts: Amount<K>[]): Promise<Payment[]>;
|
|
5
|
+
import type { AssetKind } from './types.js';
|
|
6
|
+
import type { Key } from '@endo/patterns';
|
|
7
|
+
import type { Purse } from './types.js';
|
|
8
|
+
import type { ERef } from '@endo/far';
|
|
9
|
+
import type { Payment } from './types.js';
|
|
10
|
+
import type { Pattern } from '@endo/patterns';
|
|
11
|
+
import type { Amount } from './types.js';
|
|
5
12
|
//# sourceMappingURL=legacy-payment-helpers.d.ts.map
|
|
@@ -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":"AAmCO,sBAPkB,CAAC,SAAb,SAAW,EACL,CAAC,SAAP,GAAK,iBACP,KAAK,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,eACjB,KAAK,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,mBACnB,OAAO,GACL,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAWlC;AAkBM,wBAPkB,CAAC,SAAb,SAAW,EACL,CAAC,SAAP,GAAK,iBACP,KAAK,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,iBACjB,KAAK,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,mBACrB,OAAO,GACL,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CA8BlC;AAgBM,sBANkB,CAAC,SAAb,SAAW,iBACb,KAAK,MAAM,CAAC,CAAC,CAAC,eACd,KAAK,QAAQ,CAAC,CAAC,CAAC,kBAChB,OAAO,CAAC,CAAC,GACP,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAYjC;AAgBM,0BANkB,CAAC,SAAb,SAAW,iBACb,KAAK,MAAM,CAAC,CAAC,CAAC,eACd,KAAK,QAAQ,CAAC,CAAC,CAAC,WAChB,OAAO,CAAC,CAAC,EAAE,GACT,OAAO,CAAC,OAAO,EAAE,CAAC,CAoB9B;+BA5ImD,YAAY;yBADjC,gBAAgB;2BACK,YAAY;0BAFzC,WAAW;6BAEkB,YAAY;6BADjC,gBAAgB;4BACK,YAAY"}
|
|
@@ -1,33 +1,37 @@
|
|
|
1
1
|
// @jessie-check
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { Fail } from '@endo/errors';
|
|
4
4
|
import { E } from '@endo/far';
|
|
5
|
+
import { mustMatch } from '@agoric/store';
|
|
5
6
|
import { AmountMath } from './amountMath.js';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
/**
|
|
9
|
+
* @import {ERef} from '@endo/far';
|
|
10
|
+
* @import {Key, Pattern} from '@endo/patterns';
|
|
11
|
+
* @import {Amount, AssetKind, Payment, Purse} from './types.js';
|
|
12
|
+
*/
|
|
8
13
|
|
|
9
14
|
/**
|
|
10
|
-
* @file
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* helper functions are in the recovery set of that `recoveryPurse` until
|
|
16
|
-
* otherwise used up.
|
|
15
|
+
* @file This file contains safer helper function alternatives to the similarly
|
|
16
|
+
* named methods on issuer. These are parameterized by a purse used for
|
|
17
|
+
* recovering lost payments, which we call a `recoveryPurse`. Any payments
|
|
18
|
+
* created by these helper functions are in the recovery set of that
|
|
19
|
+
* `recoveryPurse` until otherwise used up.
|
|
17
20
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
21
|
+
* One of these helper functions is less safe in one way: `combine` is not
|
|
22
|
+
* failure atomic. If the `combine` helper function fails, some of the input
|
|
23
|
+
* payments may have been used up. However, even in that case, no assets would
|
|
24
|
+
* be lost. The assets from the used up payments will be in the argument
|
|
25
|
+
* `recoveryPurse`.
|
|
23
26
|
*/
|
|
24
27
|
|
|
25
28
|
/**
|
|
26
29
|
* @template {AssetKind} K
|
|
27
|
-
* @
|
|
28
|
-
* @param {ERef<
|
|
30
|
+
* @template {Key} T type of values in set-like kind
|
|
31
|
+
* @param {ERef<Purse<K, T>>} recoveryPurse
|
|
32
|
+
* @param {ERef<Payment<K, T>>} srcPaymentP
|
|
29
33
|
* @param {Pattern} [optAmountShape]
|
|
30
|
-
* @returns {Promise<Payment<K>>}
|
|
34
|
+
* @returns {Promise<Payment<K, T>>}
|
|
31
35
|
*/
|
|
32
36
|
export const claim = async (
|
|
33
37
|
recoveryPurse,
|
|
@@ -43,17 +47,18 @@ harden(claim);
|
|
|
43
47
|
|
|
44
48
|
/**
|
|
45
49
|
* Note: Not failure atomic. But as long as you don't lose the argument
|
|
46
|
-
* `recoveryPurse`, no assets are lost.
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
50
|
+
* `recoveryPurse`, no assets are lost. If any of the deposits fail, or the
|
|
51
|
+
* total does not match optTotalAmount, some payments may still have been
|
|
52
|
+
* deposited. Those assets will be in the argument `recoveryPurse`. All
|
|
53
|
+
* undeposited payments will still be in the recovery sets of their purses of
|
|
54
|
+
* origin.
|
|
51
55
|
*
|
|
52
56
|
* @template {AssetKind} K
|
|
53
|
-
* @
|
|
54
|
-
* @param {ERef<
|
|
57
|
+
* @template {Key} T type of values in set-like kind
|
|
58
|
+
* @param {ERef<Purse<K, T>>} recoveryPurse
|
|
59
|
+
* @param {ERef<Payment<K, T>>[]} srcPaymentsPs
|
|
55
60
|
* @param {Pattern} [optTotalAmount]
|
|
56
|
-
* @returns {Promise<Payment<K>>}
|
|
61
|
+
* @returns {Promise<Payment<K, T>>}
|
|
57
62
|
*/
|
|
58
63
|
export const combine = async (
|
|
59
64
|
recoveryPurse,
|
|
@@ -66,7 +71,11 @@ export const combine = async (
|
|
|
66
71
|
E(brandP).getDisplayInfo(),
|
|
67
72
|
...srcPaymentsPs,
|
|
68
73
|
]);
|
|
69
|
-
|
|
74
|
+
|
|
75
|
+
// XXX Brand lacks M
|
|
76
|
+
const emptyAmount = /** @type {Amount<K, T>} */ (
|
|
77
|
+
AmountMath.makeEmpty(brand, displayInfo.assetKind)
|
|
78
|
+
);
|
|
70
79
|
const amountPs = srcPayments.map(srcPayment =>
|
|
71
80
|
E(recoveryPurse).deposit(srcPayment),
|
|
72
81
|
);
|
|
@@ -84,11 +93,10 @@ harden(combine);
|
|
|
84
93
|
|
|
85
94
|
/**
|
|
86
95
|
* Note: Not failure atomic. But as long as you don't lose the argument
|
|
87
|
-
* `recoveryPurse`, no assets are lost.
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* assets will be in the argument `recoveryPurse`.
|
|
96
|
+
* `recoveryPurse`, no assets are lost. If the amount in `srcPaymentP` is not >=
|
|
97
|
+
* `paymentAmountA`, the payment may still be deposited anyway, before failing
|
|
98
|
+
* in the subsequent subtract. In that case, those assets will be in the
|
|
99
|
+
* argument `recoveryPurse`.
|
|
92
100
|
*
|
|
93
101
|
* @template {AssetKind} K
|
|
94
102
|
* @param {ERef<Purse<K>>} recoveryPurse
|
|
@@ -111,12 +119,10 @@ harden(split);
|
|
|
111
119
|
|
|
112
120
|
/**
|
|
113
121
|
* Note: Not failure atomic. But as long as you don't lose the argument
|
|
114
|
-
* `recoveryPurse`, no assets are lost.
|
|
115
|
-
*
|
|
116
|
-
* the
|
|
117
|
-
*
|
|
118
|
-
* In that case, those
|
|
119
|
-
* assets will be in the argument `recoveryPurse`.
|
|
122
|
+
* `recoveryPurse`, no assets are lost. If the amount in `srcPaymentP` is
|
|
123
|
+
* exactly the sum of the amounts, the payment may still be deposited anyway,
|
|
124
|
+
* before failing in the subsequent equality check. In that case, those assets
|
|
125
|
+
* will be in the argument `recoveryPurse`.
|
|
120
126
|
*
|
|
121
127
|
* @template {AssetKind} K
|
|
122
128
|
* @param {ERef<Purse<K>>} recoveryPurse
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export const copyBagMathHelpers: MathHelpers<CopyBag>;
|
|
1
|
+
/** @type {MathHelpers<import('@endo/patterns').CopyBag>} */
|
|
2
|
+
export const copyBagMathHelpers: MathHelpers<import("@endo/patterns").CopyBag>;
|
|
3
|
+
import type { MathHelpers } from '../types.js';
|
|
5
4
|
//# sourceMappingURL=copyBagMathHelpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copyBagMathHelpers.d.ts","sourceRoot":"","sources":["copyBagMathHelpers.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"copyBagMathHelpers.d.ts","sourceRoot":"","sources":["copyBagMathHelpers.js"],"names":[],"mappings":"AAkBA,4DAA4D;AAC5D,iCADW,YAAY,OAAO,gBAAgB,EAAE,OAAO,CAAC,CAYrD;iCAjB4B,aAAa"}
|
|
@@ -10,14 +10,13 @@ import {
|
|
|
10
10
|
bagUnion,
|
|
11
11
|
bagDisjointSubtract,
|
|
12
12
|
} from '@agoric/store';
|
|
13
|
-
import '../types-ambient.js';
|
|
14
13
|
|
|
15
|
-
/** @
|
|
14
|
+
/** @import {MathHelpers} from '../types.js' */
|
|
15
|
+
|
|
16
|
+
/** @type {import('@endo/patterns').CopyBag} */
|
|
16
17
|
const empty = makeCopyBag([]);
|
|
17
18
|
|
|
18
|
-
/**
|
|
19
|
-
* @type {MathHelpers<CopyBag>}
|
|
20
|
-
*/
|
|
19
|
+
/** @type {MathHelpers<import('@endo/patterns').CopyBag>} */
|
|
21
20
|
export const copyBagMathHelpers = harden({
|
|
22
21
|
doCoerce: bag => {
|
|
23
22
|
mustMatch(bag, M.bag(), 'bag of amount');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @type {MathHelpers<CopySet>}
|
|
3
|
-
*/
|
|
1
|
+
/** @type {MathHelpers<CopySet>} */
|
|
4
2
|
export const copySetMathHelpers: MathHelpers<CopySet>;
|
|
3
|
+
import type { CopySet } from '@endo/patterns';
|
|
4
|
+
import type { MathHelpers } from '../types.js';
|
|
5
5
|
//# sourceMappingURL=copySetMathHelpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copySetMathHelpers.d.ts","sourceRoot":"","sources":["copySetMathHelpers.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"copySetMathHelpers.d.ts","sourceRoot":"","sources":["copySetMathHelpers.js"],"names":[],"mappings":"AAqBA,mCAAmC;AACnC,iCADW,YAAY,OAAO,CAAC,CAY5B;6BAlBuB,gBAAgB;iCADZ,aAAa"}
|
|
@@ -10,14 +10,16 @@ import {
|
|
|
10
10
|
setDisjointUnion,
|
|
11
11
|
setDisjointSubtract,
|
|
12
12
|
} from '@agoric/store';
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @import {MathHelpers} from '../types.js'
|
|
16
|
+
* @import {CopySet} from '@endo/patterns'
|
|
17
|
+
*/
|
|
14
18
|
|
|
15
19
|
/** @type {CopySet} */
|
|
16
20
|
const empty = makeCopySet([]);
|
|
17
21
|
|
|
18
|
-
/**
|
|
19
|
-
* @type {MathHelpers<CopySet>}
|
|
20
|
-
*/
|
|
22
|
+
/** @type {MathHelpers<CopySet>} */
|
|
21
23
|
export const copySetMathHelpers = harden({
|
|
22
24
|
doCoerce: set => {
|
|
23
25
|
mustMatch(set, M.set(), 'set of amount');
|