@agoric/ertp 0.16.3-dev-5dc325b.0 → 0.16.3-getting-started-dev-d127d1d.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 +759 -0
- package/package.json +17 -24
- package/src/amountMath.d.ts +53 -0
- package/src/amountMath.d.ts.map +1 -0
- package/src/amountMath.js +63 -57
- package/src/displayInfo.d.ts +2 -0
- package/src/displayInfo.d.ts.map +1 -0
- package/src/index.d.ts +4 -0
- package/src/index.d.ts.map +1 -0
- package/src/issuerKit.d.ts +19 -0
- package/src/issuerKit.d.ts.map +1 -0
- package/src/issuerKit.js +59 -145
- 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 +28 -23
- package/src/mathHelpers/copyBagMathHelpers.d.ts +5 -0
- package/src/mathHelpers/copyBagMathHelpers.d.ts.map +1 -0
- package/src/mathHelpers/copyBagMathHelpers.js +3 -1
- package/src/mathHelpers/copySetMathHelpers.d.ts +5 -0
- package/src/mathHelpers/copySetMathHelpers.d.ts.map +1 -0
- package/src/mathHelpers/copySetMathHelpers.js +3 -1
- package/src/mathHelpers/natMathHelpers.d.ts +14 -0
- package/src/mathHelpers/natMathHelpers.d.ts.map +1 -0
- package/src/mathHelpers/natMathHelpers.js +7 -6
- package/src/mathHelpers/setMathHelpers.d.ts +6 -0
- package/src/mathHelpers/setMathHelpers.d.ts.map +1 -0
- package/src/payment.d.ts +3 -0
- package/src/payment.d.ts.map +1 -0
- package/src/payment.js +0 -5
- package/src/paymentLedger.d.ts +3 -0
- package/src/paymentLedger.d.ts.map +1 -0
- package/src/paymentLedger.js +40 -38
- package/src/purse.d.ts +13 -0
- package/src/purse.d.ts.map +1 -0
- package/src/purse.js +0 -18
- package/src/transientNotifier.d.ts +5 -0
- package/src/transientNotifier.d.ts.map +1 -0
- package/src/typeGuards.d.ts +42 -0
- package/src/typeGuards.d.ts.map +1 -0
- package/src/typeGuards.js +43 -37
- package/src/types-ambient.d.ts +376 -0
- package/src/types-ambient.d.ts.map +1 -0
- package/src/types-ambient.js +314 -218
- package/src/types.d.ts +376 -0
- package/src/types.d.ts.map +1 -0
- package/src/types.js +314 -218
package/src/issuerKit.js
CHANGED
|
@@ -10,8 +10,6 @@ import { preparePaymentLedger } from './paymentLedger.js';
|
|
|
10
10
|
|
|
11
11
|
import './types-ambient.js';
|
|
12
12
|
|
|
13
|
-
// TODO Why does TypeScript lose the `MapStore` typing of `Baggage` here, even
|
|
14
|
-
// though it knows the correct type at the exporting `@agoric/vat-data`
|
|
15
13
|
/** @typedef {import('@agoric/vat-data').Baggage} Baggage */
|
|
16
14
|
|
|
17
15
|
/**
|
|
@@ -24,18 +22,16 @@ import './types-ambient.js';
|
|
|
24
22
|
*/
|
|
25
23
|
|
|
26
24
|
/**
|
|
27
|
-
* Used _only_ internally, to make a new issuerKit or to revive an old one.
|
|
28
|
-
*
|
|
29
25
|
* @template {AssetKind} K
|
|
30
26
|
* @param {IssuerRecord<K>} issuerRecord
|
|
31
27
|
* @param {Baggage} issuerBaggage
|
|
32
|
-
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
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
|
|
39
35
|
* @returns {IssuerKit<K>}
|
|
40
36
|
*/
|
|
41
37
|
const setupIssuerKit = (
|
|
@@ -82,77 +78,64 @@ harden(setupIssuerKit);
|
|
|
82
78
|
const INSTANCE_KEY = 'issuer';
|
|
83
79
|
|
|
84
80
|
/**
|
|
85
|
-
* Used _only_ to upgrade a predecessor issuerKit. Use `makeDurableIssuerKit` to
|
|
86
|
-
* make a new one.
|
|
87
|
-
*
|
|
88
81
|
* @template {AssetKind} K
|
|
89
82
|
* @param {Baggage} issuerBaggage
|
|
90
|
-
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
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
|
|
97
90
|
* @returns {IssuerKit<K>}
|
|
98
91
|
*/
|
|
99
|
-
export const
|
|
92
|
+
export const prepareIssuerKit = (
|
|
100
93
|
issuerBaggage,
|
|
101
94
|
optShutdownWithFailure = undefined,
|
|
102
95
|
) => {
|
|
103
96
|
const issuerRecord = issuerBaggage.get(INSTANCE_KEY);
|
|
104
97
|
return setupIssuerKit(issuerRecord, issuerBaggage, optShutdownWithFailure);
|
|
105
98
|
};
|
|
106
|
-
harden(
|
|
99
|
+
harden(prepareIssuerKit);
|
|
107
100
|
|
|
108
101
|
/**
|
|
109
|
-
* Does baggage already have an
|
|
102
|
+
* Does baggage already have an issuer from prepareIssuerKit()?
|
|
103
|
+
* That is: does it have the relevant keys defined?
|
|
110
104
|
*
|
|
111
105
|
* @param {Baggage} baggage
|
|
112
106
|
*/
|
|
113
107
|
export const hasIssuer = baggage => baggage.has(INSTANCE_KEY);
|
|
114
108
|
|
|
115
109
|
/**
|
|
116
|
-
*
|
|
117
|
-
* it is a `Pattern` that every element of this issuerKits's amounts must
|
|
118
|
-
* satisfy. For example, the Zoe Invitation issuerKit uses an elementShape
|
|
119
|
-
* describing the invitation details for an individual invitation. An invitation
|
|
120
|
-
* purse or payment has an amount that can only be a set of these. (Though
|
|
121
|
-
* typically, the amount of an invitation payment is a singleton set. Such a
|
|
122
|
-
* payment is often referred to in the singular as "an invitation".)
|
|
123
|
-
*
|
|
124
|
-
* @typedef {Partial<{
|
|
125
|
-
* elementShape: Pattern;
|
|
126
|
-
* }>} IssuerOptionsRecord
|
|
110
|
+
* @typedef {Partial<{elementShape: Pattern}>} IssuerOptionsRecord
|
|
127
111
|
*/
|
|
128
112
|
|
|
129
113
|
/**
|
|
130
|
-
*
|
|
131
|
-
*
|
|
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.
|
|
132
121
|
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* example, anyone could create a new issuer kit with name 'BTC', but it is
|
|
137
|
-
* not bitcoin or even related. It is only the name according to that issuer
|
|
138
|
-
* and brand.
|
|
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.
|
|
139
125
|
*
|
|
140
|
-
*
|
|
141
|
-
* mathHelpers library. For example, natMathHelpers, the default, is used for
|
|
142
|
-
* basic fungible tokens.
|
|
126
|
+
* `displayInfo` gives information to the UI on how to display the amount.
|
|
143
127
|
*
|
|
144
|
-
* `displayInfo` gives information to the UI on how to display the amount.
|
|
145
128
|
* @param {Baggage} issuerBaggage
|
|
146
129
|
* @param {string} name
|
|
147
|
-
* @param {K} [assetKind]
|
|
148
|
-
* @param {AdditionalDisplayInfo} [displayInfo]
|
|
149
|
-
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
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
|
|
156
139
|
* @param {IssuerOptionsRecord} [options]
|
|
157
140
|
* @returns {IssuerKit<K>}
|
|
158
141
|
*/
|
|
@@ -172,99 +155,30 @@ export const makeDurableIssuerKit = (
|
|
|
172
155
|
harden(makeDurableIssuerKit);
|
|
173
156
|
|
|
174
157
|
/**
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
* not bitcoin or even related. It is only the name according to that issuer
|
|
183
|
-
* and brand.
|
|
184
|
-
*
|
|
185
|
-
* The assetKind will be used to import a specific mathHelpers from the
|
|
186
|
-
* mathHelpers library. For example, natMathHelpers, the default, is used for
|
|
187
|
-
* basic fungible tokens.
|
|
188
|
-
*
|
|
189
|
-
* `displayInfo` gives information to the UI on how to display the amount.
|
|
190
|
-
* @param {Baggage} issuerBaggage
|
|
191
|
-
* @param {string} name
|
|
192
|
-
* @param {K} [assetKind]
|
|
193
|
-
* @param {AdditionalDisplayInfo} [displayInfo]
|
|
194
|
-
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails in
|
|
195
|
-
* the middle of an atomic action (which btw should never happen), it
|
|
196
|
-
* potentially leaves its ledger in a corrupted state. If this function was
|
|
197
|
-
* provided, then the failed atomic action will call it, so that some larger
|
|
198
|
-
* unit of computation, like the enclosing vat, can be shutdown before
|
|
199
|
-
* anything else is corrupted by that corrupted state. See
|
|
200
|
-
* https://github.com/Agoric/agoric-sdk/issues/3434
|
|
201
|
-
* @param {IssuerOptionsRecord} [options]
|
|
202
|
-
* @returns {IssuerKit<K>}
|
|
203
|
-
*/
|
|
204
|
-
export const prepareIssuerKit = (
|
|
205
|
-
issuerBaggage,
|
|
206
|
-
name,
|
|
207
|
-
// @ts-expect-error K could be instantiated with a different subtype of AssetKind
|
|
208
|
-
assetKind = AssetKind.NAT,
|
|
209
|
-
displayInfo = harden({}),
|
|
210
|
-
optShutdownWithFailure = undefined,
|
|
211
|
-
options = {},
|
|
212
|
-
) => {
|
|
213
|
-
if (hasIssuer(issuerBaggage)) {
|
|
214
|
-
const { elementShape: _ = undefined } = options;
|
|
215
|
-
const issuerKit = upgradeIssuerKit(issuerBaggage, optShutdownWithFailure);
|
|
216
|
-
|
|
217
|
-
// TODO check consistency with name, assetKind, displayInfo, elementShape.
|
|
218
|
-
// Consistency either means that these are the same, or that they differ
|
|
219
|
-
// in a direction we are prepared to upgrade.
|
|
220
|
-
|
|
221
|
-
// @ts-expect-error Type parameter confusion.
|
|
222
|
-
return issuerKit;
|
|
223
|
-
} else {
|
|
224
|
-
const issuerKit = makeDurableIssuerKit(
|
|
225
|
-
issuerBaggage,
|
|
226
|
-
name,
|
|
227
|
-
assetKind,
|
|
228
|
-
displayInfo,
|
|
229
|
-
optShutdownWithFailure,
|
|
230
|
-
options,
|
|
231
|
-
);
|
|
232
|
-
return issuerKit;
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
harden(prepareIssuerKit);
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Used _only_ to make a new issuerKit that is effectively non-durable. This is
|
|
239
|
-
* currently done by making a durable one in a baggage not reachable from
|
|
240
|
-
* anywhere. TODO Once rebuilt on zones, this should instead just build on the
|
|
241
|
-
* virtual zone. See https://github.com/Agoric/agoric-sdk/pull/7116
|
|
242
|
-
*
|
|
243
|
-
* Currently used for testing only. Should probably continue to be used for
|
|
244
|
-
* testing only.
|
|
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.
|
|
245
165
|
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
* example, anyone could create a new issuer kit with name 'BTC', but it is
|
|
250
|
-
* not bitcoin or even related. It is only the name according to that issuer
|
|
251
|
-
* and brand.
|
|
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.
|
|
252
169
|
*
|
|
253
|
-
*
|
|
254
|
-
* mathHelpers library. For example, natMathHelpers, the default, is used for
|
|
255
|
-
* basic fungible tokens.
|
|
170
|
+
* `displayInfo` gives information to the UI on how to display the amount.
|
|
256
171
|
*
|
|
257
|
-
* `displayInfo` gives information to the UI on how to display the amount.
|
|
258
172
|
* @param {string} name
|
|
259
|
-
* @param {K} [assetKind]
|
|
260
|
-
* @param {AdditionalDisplayInfo} [displayInfo]
|
|
261
|
-
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
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
|
|
268
182
|
* @param {IssuerOptionsRecord} [options]
|
|
269
183
|
* @returns {IssuerKit<K>}
|
|
270
184
|
*/
|
|
@@ -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"}
|
|
@@ -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
|
|
@@ -0,0 +1 @@
|
|
|
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');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copySetMathHelpers.d.ts","sourceRoot":"","sources":["copySetMathHelpers.js"],"names":[],"mappings":"AAiBA;;GAEG;AACH,iCAFU,YAAY,OAAO,CAAC,CAa3B"}
|
|
@@ -15,7 +15,9 @@ import '../types-ambient.js';
|
|
|
15
15
|
/** @type {CopySet} */
|
|
16
16
|
const empty = makeCopySet([]);
|
|
17
17
|
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* @type {MathHelpers<CopySet>}
|
|
20
|
+
*/
|
|
19
21
|
export const copySetMathHelpers = harden({
|
|
20
22
|
doCoerce: set => {
|
|
21
23
|
mustMatch(set, M.set(), 'set of amount');
|
|
@@ -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"}
|
|
@@ -8,13 +8,14 @@ const { Fail } = assert;
|
|
|
8
8
|
const empty = 0n;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Fungible digital assets use the natMathHelpers to manage balances -
|
|
12
|
-
* operations are merely arithmetic on natural, non-negative
|
|
11
|
+
* Fungible digital assets use the natMathHelpers to manage balances -
|
|
12
|
+
* the operations are merely arithmetic on natural, non-negative
|
|
13
|
+
* numbers.
|
|
13
14
|
*
|
|
14
|
-
* Natural numbers are used for fungible erights such as money because
|
|
15
|
-
* issues make floats problematic. All operations should be
|
|
16
|
-
* smallest whole unit such that the `natMathHelpers` never
|
|
17
|
-
* fractional parts.
|
|
15
|
+
* Natural numbers are used for fungible erights such as money because
|
|
16
|
+
* rounding issues make floats problematic. All operations should be
|
|
17
|
+
* done with the smallest whole unit such that the `natMathHelpers` never
|
|
18
|
+
* deals with fractional parts.
|
|
18
19
|
*
|
|
19
20
|
* @type {MathHelpers<NatValue>}
|
|
20
21
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setMathHelpers.d.ts","sourceRoot":"","sources":["setMathHelpers.js"],"names":[],"mappings":"AAkBA;;;GAGG;AACH,6BAFU,qBAAqB,CAkB5B"}
|
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
|
@@ -3,11 +3,6 @@
|
|
|
3
3
|
import { initEmpty } from '@agoric/store';
|
|
4
4
|
import { prepareExoClass } from '@agoric/vat-data';
|
|
5
5
|
|
|
6
|
-
/** @typedef {import('@endo/patterns').MethodGuard} MethodGuard */
|
|
7
|
-
/**
|
|
8
|
-
* @template {Record<string | symbol, MethodGuard>} [T=Record<string | symbol, MethodGuard>]
|
|
9
|
-
* @typedef {import('@endo/patterns').InterfaceGuard<T>} InterfaceGuard
|
|
10
|
-
*/
|
|
11
6
|
/** @typedef {import('@agoric/vat-data').Baggage} Baggage */
|
|
12
7
|
|
|
13
8
|
/**
|
|
@@ -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"}
|
package/src/paymentLedger.js
CHANGED
|
@@ -70,8 +70,8 @@ const amountShapeFromElementShape = (brand, assetKind, elementShape) => {
|
|
|
70
70
|
};
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
|
-
* Make the paymentLedger, the source of truth for the balances of
|
|
74
|
-
* minting and transfer authority originates here.
|
|
73
|
+
* Make the paymentLedger, the source of truth for the balances of
|
|
74
|
+
* payments. All minting and transfer authority originates here.
|
|
75
75
|
*
|
|
76
76
|
* @template {AssetKind} K
|
|
77
77
|
* @param {Baggage} issuerBaggage
|
|
@@ -146,21 +146,22 @@ export const preparePaymentLedger = (
|
|
|
146
146
|
);
|
|
147
147
|
|
|
148
148
|
/**
|
|
149
|
-
* A withdrawn live payment is associated with the recovery set of
|
|
150
|
-
* it was withdrawn from. Let's call these "recoverable"
|
|
151
|
-
* recoverable payments are live, but not all live
|
|
152
|
-
* We do the bookkeeping for payment recovery
|
|
153
|
-
* recoverable payments to the recovery set they are
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
149
|
+
* A withdrawn live payment is associated with the recovery set of
|
|
150
|
+
* the purse it was withdrawn from. Let's call these "recoverable"
|
|
151
|
+
* payments. All recoverable payments are live, but not all live
|
|
152
|
+
* payments are recoverable. We do the bookkeeping for payment recovery
|
|
153
|
+
* with this weakmap from recoverable payments to the recovery set they are
|
|
154
|
+
* in.
|
|
155
|
+
* A bunch of interesting invariants here:
|
|
156
|
+
* * Every payment that is a key in the outer `paymentRecoverySets`
|
|
157
|
+
* weakMap is also in the recovery set indexed by that payment.
|
|
158
|
+
* * Implied by the above but worth stating: the payment is only
|
|
159
|
+
* in at most one recovery set.
|
|
160
|
+
* * A recovery set only contains such payments.
|
|
161
|
+
* * Every purse is associated with exactly one recovery set unique to
|
|
162
|
+
* it.
|
|
163
|
+
* * A purse's recovery set only contains payments withdrawn from
|
|
164
|
+
* that purse and not yet consumed.
|
|
164
165
|
*
|
|
165
166
|
* @type {WeakMapStore<Payment, SetStore<Payment>>}
|
|
166
167
|
*/
|
|
@@ -171,7 +172,8 @@ export const preparePaymentLedger = (
|
|
|
171
172
|
|
|
172
173
|
/**
|
|
173
174
|
* To maintain the invariants listed in the `paymentRecoverySets` comment,
|
|
174
|
-
* `initPayment` should contain the only
|
|
175
|
+
* `initPayment` should contain the only
|
|
176
|
+
* call to `paymentLedger.init`.
|
|
175
177
|
*
|
|
176
178
|
* @param {Payment} payment
|
|
177
179
|
* @param {Amount} amount
|
|
@@ -187,7 +189,8 @@ export const preparePaymentLedger = (
|
|
|
187
189
|
|
|
188
190
|
/**
|
|
189
191
|
* To maintain the invariants listed in the `paymentRecoverySets` comment,
|
|
190
|
-
* `deletePayment` should contain the only
|
|
192
|
+
* `deletePayment` should contain the only
|
|
193
|
+
* call to `paymentLedger.delete`.
|
|
191
194
|
*
|
|
192
195
|
* @param {Payment} payment
|
|
193
196
|
*/
|
|
@@ -200,18 +203,19 @@ export const preparePaymentLedger = (
|
|
|
200
203
|
}
|
|
201
204
|
};
|
|
202
205
|
|
|
203
|
-
/** @type {(left: Amount, right: Amount) => Amount} */
|
|
206
|
+
/** @type {(left: Amount, right: Amount) => Amount } */
|
|
204
207
|
const add = (left, right) => AmountMath.add(left, right, brand);
|
|
205
|
-
/** @type {(left: Amount, right: Amount) => Amount} */
|
|
208
|
+
/** @type {(left: Amount, right: Amount) => Amount } */
|
|
206
209
|
const subtract = (left, right) => AmountMath.subtract(left, right, brand);
|
|
207
210
|
/** @type {(allegedAmount: Amount) => Amount} */
|
|
208
211
|
const coerce = allegedAmount => AmountMath.coerce(brand, allegedAmount);
|
|
209
|
-
/** @type {(left: Amount, right: Amount) => boolean} */
|
|
212
|
+
/** @type {(left: Amount, right: Amount) => boolean } */
|
|
210
213
|
|
|
211
214
|
/**
|
|
212
|
-
* Methods like deposit() have an optional second parameter
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
+
* Methods like deposit() have an optional second parameter
|
|
216
|
+
* `optAmountShape`
|
|
217
|
+
* which, if present, is supposed to match the balance of the
|
|
218
|
+
* payment. This helper function does that check.
|
|
215
219
|
*
|
|
216
220
|
* Note: `optAmountShape` is user-supplied with no previous validation.
|
|
217
221
|
*
|
|
@@ -239,10 +243,10 @@ export const preparePaymentLedger = (
|
|
|
239
243
|
/**
|
|
240
244
|
* Used by the purse code to implement purse.deposit
|
|
241
245
|
*
|
|
242
|
-
* @param {Amount} currentBalance - the current balance of the purse
|
|
243
|
-
*
|
|
244
|
-
* @param {(newPurseBalance: Amount) => void} updatePurseBalance -
|
|
245
|
-
*
|
|
246
|
+
* @param {Amount} currentBalance - the current balance of the purse
|
|
247
|
+
* before a deposit
|
|
248
|
+
* @param {(newPurseBalance: Amount) => void} updatePurseBalance -
|
|
249
|
+
* commit the purse balance
|
|
246
250
|
* @param {Payment} srcPayment
|
|
247
251
|
* @param {Pattern} [optAmountShape]
|
|
248
252
|
* @returns {Amount}
|
|
@@ -278,10 +282,10 @@ export const preparePaymentLedger = (
|
|
|
278
282
|
/**
|
|
279
283
|
* Used by the purse code to implement purse.withdraw
|
|
280
284
|
*
|
|
281
|
-
* @param {Amount} currentBalance - the current balance of the purse
|
|
282
|
-
*
|
|
283
|
-
* @param {(newPurseBalance: Amount) => void} updatePurseBalance -
|
|
284
|
-
*
|
|
285
|
+
* @param {Amount} currentBalance - the current balance of the purse
|
|
286
|
+
* before a withdrawal
|
|
287
|
+
* @param {(newPurseBalance: Amount) => void} updatePurseBalance -
|
|
288
|
+
* commit the purse balance
|
|
285
289
|
* @param {Amount} amount - the amount to be withdrawn
|
|
286
290
|
* @param {SetStore<Payment>} recoverySet
|
|
287
291
|
* @returns {Payment}
|
|
@@ -310,8 +314,6 @@ export const preparePaymentLedger = (
|
|
|
310
314
|
return payment;
|
|
311
315
|
};
|
|
312
316
|
|
|
313
|
-
/** @type {() => Purse<K>} */
|
|
314
|
-
// @ts-expect-error type parameter confusion
|
|
315
317
|
const makeEmptyPurse = preparePurseKind(
|
|
316
318
|
issuerBaggage,
|
|
317
319
|
name,
|
|
@@ -376,9 +378,9 @@ export const preparePaymentLedger = (
|
|
|
376
378
|
/**
|
|
377
379
|
* Provides for the recovery of newly minted but not-yet-deposited payments.
|
|
378
380
|
*
|
|
379
|
-
* Because the `mintRecoveryPurse` is placed in baggage, even if the
|
|
380
|
-
* `makeIssuerKit` drops it on the floor, it can still be
|
|
381
|
-
* emergency upgrade.
|
|
381
|
+
* Because the `mintRecoveryPurse` is placed in baggage, even if the
|
|
382
|
+
* caller of `makeIssuerKit` drops it on the floor, it can still be
|
|
383
|
+
* recovered in an emergency upgrade.
|
|
382
384
|
*
|
|
383
385
|
* @type {Purse<K>}
|
|
384
386
|
*/
|