@agoric/ertp 0.16.3-dev-ecf2d8e.0 → 0.16.3-other-dev-70beeb7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +743 -0
- package/package.json +17 -21
- package/src/amountMath.d.ts +13 -14
- package/src/amountMath.d.ts.map +1 -1
- package/src/amountMath.js +63 -57
- package/src/issuerKit.d.ts +3 -3
- package/src/issuerKit.d.ts.map +1 -1
- package/src/issuerKit.js +61 -55
- package/src/legacy-payment-helpers.d.ts.map +1 -1
- package/src/legacy-payment-helpers.js +28 -23
- package/src/mathHelpers/copyBagMathHelpers.d.ts +3 -1
- package/src/mathHelpers/copyBagMathHelpers.d.ts.map +1 -1
- package/src/mathHelpers/copyBagMathHelpers.js +3 -1
- package/src/mathHelpers/copySetMathHelpers.d.ts +3 -1
- package/src/mathHelpers/copySetMathHelpers.d.ts.map +1 -1
- package/src/mathHelpers/copySetMathHelpers.js +3 -1
- package/src/mathHelpers/natMathHelpers.d.ts +7 -6
- package/src/mathHelpers/natMathHelpers.d.ts.map +1 -1
- package/src/mathHelpers/natMathHelpers.js +7 -6
- package/src/payment.d.ts +1 -3
- package/src/payment.d.ts.map +1 -1
- package/src/payment.js +0 -5
- package/src/paymentLedger.d.ts +1 -1
- package/src/paymentLedger.d.ts.map +1 -1
- package/src/paymentLedger.js +40 -36
- package/src/typeGuards.d.ts +6 -36
- package/src/typeGuards.d.ts.map +1 -1
- package/src/typeGuards.js +43 -37
- package/src/types-ambient.d.ts +174 -178
- package/src/types-ambient.d.ts.map +1 -1
- package/src/types-ambient.js +280 -217
- package/src/types.d.ts +174 -178
- package/src/types.d.ts.map +1 -1
- package/src/types.js +280 -217
package/src/types.js
CHANGED
|
@@ -3,141 +3,150 @@ export {};
|
|
|
3
3
|
|
|
4
4
|
/// <reference types="ses"/>
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* @template {Key} [K=Key]
|
|
8
|
-
* @typedef {import('@endo/patterns').CopyBag<K>} CopyBag
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
6
|
/**
|
|
12
7
|
* @template {AssetKind} [K=AssetKind]
|
|
13
|
-
* @typedef {object} Amount
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
8
|
+
* @typedef {object} Amount
|
|
9
|
+
* Amounts are descriptions of digital assets, answering the questions
|
|
10
|
+
* "how much" and "of what kind". Amounts are values labeled with a brand.
|
|
11
|
+
* AmountMath executes the logic of how amounts are changed when digital
|
|
12
|
+
* assets are merged, separated, or otherwise manipulated. For
|
|
13
|
+
* example, a deposit of 2 bucks into a purse that already has 3 bucks
|
|
14
|
+
* gives a new purse balance of 5 bucks. An empty purse has 0 bucks. AmountMath
|
|
15
|
+
* relies heavily on polymorphic MathHelpers, which manipulate the unbranded
|
|
16
|
+
* portion.
|
|
17
|
+
*
|
|
21
18
|
* @property {Brand<K>} brand
|
|
22
19
|
* @property {AssetValueForKind<K>} value
|
|
23
20
|
*/
|
|
24
21
|
|
|
25
22
|
/**
|
|
26
|
-
* @typedef {NatValue | SetValue | CopySet | CopyBag} AmountValue
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
23
|
+
* @typedef {NatValue | SetValue | CopySet | CopyBag} AmountValue
|
|
24
|
+
* An `AmountValue` describes a set or quantity of assets that can be owned or
|
|
25
|
+
* shared.
|
|
26
|
+
*
|
|
27
|
+
* A fungible `AmountValue` uses a non-negative bigint to represent a quantity
|
|
28
|
+
* of that many assets.
|
|
29
|
+
*
|
|
30
|
+
* A non-fungible `AmountValue` uses an array or CopySet of `Key`s to represent
|
|
31
|
+
* a set of whatever asset each key represents. A `Key` is a passable value
|
|
32
|
+
* that can be used as an element in a set (SetStore or CopySet) or as the
|
|
33
|
+
* key in a map (MapStore or CopyMap).
|
|
34
|
+
*
|
|
35
|
+
* `SetValue` is for the deprecated set representation, using an array directly
|
|
36
|
+
* to represent the array of its elements. `CopySet` is the proper
|
|
37
|
+
* representation using a CopySet.
|
|
38
|
+
*
|
|
39
|
+
* A semi-fungible `CopyBag` is represented as a
|
|
40
|
+
* `CopyBag` of `Key` objects. "Bag" is synonymous with MultiSet, where an
|
|
41
|
+
* element of a bag can be present once or more times, i.e., some positive
|
|
42
|
+
* bigint number of times, representing that quantity of the asset represented
|
|
43
|
+
* by that key.
|
|
46
44
|
*/
|
|
47
45
|
|
|
48
46
|
/**
|
|
49
|
-
* @typedef {'nat' | 'set' | 'copySet' | 'copyBag'} AssetKind
|
|
50
|
-
*
|
|
47
|
+
* @typedef {'nat' | 'set' | 'copySet' | 'copyBag' } AssetKind
|
|
48
|
+
*
|
|
49
|
+
* See doc-comment for `AmountValue`.
|
|
51
50
|
*/
|
|
52
51
|
|
|
53
52
|
/**
|
|
54
53
|
* @template {AssetKind} K
|
|
55
|
-
* @typedef {K extends 'nat'
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* : K extends 'copyBag'
|
|
62
|
-
* ? CopyBag
|
|
63
|
-
* : never} AssetValueForKind
|
|
54
|
+
* @typedef {K extends 'nat' ? NatValue :
|
|
55
|
+
* K extends 'set' ? SetValue :
|
|
56
|
+
* K extends 'copySet' ? CopySet:
|
|
57
|
+
* K extends 'copyBag' ? CopyBag :
|
|
58
|
+
* never
|
|
59
|
+
* } AssetValueForKind
|
|
64
60
|
*/
|
|
65
61
|
|
|
66
62
|
/**
|
|
67
63
|
* @template {AmountValue} V
|
|
68
|
-
* @typedef {V extends NatValue
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* ? 'copySet'
|
|
74
|
-
* : V extends CopyBag
|
|
75
|
-
* ? 'copyBag'
|
|
76
|
-
* : never} AssetKindForValue
|
|
64
|
+
* @typedef {V extends NatValue ? 'nat' :
|
|
65
|
+
* V extends SetValue ? 'set' :
|
|
66
|
+
* V extends CopySet ? 'copySet' :
|
|
67
|
+
* V extends CopyBag ? 'copyBag' :
|
|
68
|
+
* never} AssetKindForValue
|
|
77
69
|
*/
|
|
78
70
|
|
|
79
71
|
/**
|
|
80
72
|
* @template {AssetKind} [K=AssetKind]
|
|
81
73
|
* @typedef {object} DisplayInfo
|
|
82
|
-
* @property {number} [decimalPlaces] Tells the display software how
|
|
83
|
-
* decimal places to move the decimal over to the left, or in
|
|
84
|
-
* which position corresponds to whole numbers. We
|
|
85
|
-
* assets to be represented in integers, in
|
|
86
|
-
* be represented in mill, a
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
74
|
+
* @property {number} [decimalPlaces] Tells the display software how
|
|
75
|
+
* many decimal places to move the decimal over to the left, or in
|
|
76
|
+
* other words, which position corresponds to whole numbers. We
|
|
77
|
+
* require fungible digital assets to be represented in integers, in
|
|
78
|
+
* the smallest unit (i.e. USD might be represented in mill, a
|
|
79
|
+
* thousandth of a dollar. In that case, `decimalPlaces` would be
|
|
80
|
+
* 3.) This property is optional, and for non-fungible digital
|
|
81
|
+
* assets, should not be specified. The decimalPlaces property
|
|
82
|
+
* should be used for *display purposes only*. Any other use is an
|
|
90
83
|
* anti-pattern.
|
|
91
|
-
* @property {K} assetKind - the kind of asset, either
|
|
92
|
-
*
|
|
84
|
+
* @property {K} assetKind - the kind of asset, either
|
|
85
|
+
* AssetKind.NAT (fungible) or
|
|
86
|
+
* AssetKind.SET or AssetKind.COPY_SET (non-fungible)
|
|
93
87
|
*/
|
|
94
88
|
|
|
95
89
|
/**
|
|
96
90
|
* @template {AssetKind} [K=AssetKind]
|
|
97
|
-
* @typedef {object} Brand
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
91
|
+
* @typedef {object} Brand
|
|
92
|
+
* The brand identifies the kind of issuer, and has a function to get the
|
|
93
|
+
* alleged name for the kind of asset described. The alleged name (such
|
|
94
|
+
* as 'BTC' or 'moola') is provided by the maker of the issuer and should
|
|
95
|
+
* not be trusted as accurate.
|
|
96
|
+
*
|
|
97
|
+
* Every amount created by a particular AmountMath will share the same brand,
|
|
98
|
+
* but recipients cannot rely on the brand to verify that a purported amount
|
|
99
|
+
* represents the issuer they intended, since the same brand can be reused by
|
|
100
|
+
* a misbehaving issuer.
|
|
101
|
+
*
|
|
106
102
|
* @property {(allegedIssuer: ERef<Issuer>) => Promise<boolean>} isMyIssuer
|
|
107
|
-
*
|
|
103
|
+
* Should be used with `issuer.getBrand` to ensure an issuer and brand match.
|
|
108
104
|
* @property {() => string} getAllegedName
|
|
109
|
-
* @property {() => DisplayInfo<K>} getDisplayInfo
|
|
110
|
-
*
|
|
105
|
+
* @property {() => DisplayInfo<K>} getDisplayInfo
|
|
106
|
+
* Give information to UI on how to display the amount.
|
|
111
107
|
* @property {() => Pattern} getAmountShape
|
|
112
108
|
*/
|
|
113
109
|
|
|
114
110
|
// /////////////////////////// Issuer //////////////////////////////////////////
|
|
115
111
|
|
|
116
112
|
/**
|
|
117
|
-
* @callback IssuerIsLive
|
|
113
|
+
* @callback IssuerIsLive
|
|
114
|
+
*
|
|
115
|
+
* Return true if the payment continues to exist.
|
|
116
|
+
*
|
|
117
|
+
* If the payment is a promise, the operation will proceed upon
|
|
118
|
+
* resolution.
|
|
118
119
|
*
|
|
119
|
-
* If the payment is a promise, the operation will proceed upon resolution.
|
|
120
120
|
* @param {ERef<Payment>} payment
|
|
121
121
|
* @returns {Promise<boolean>}
|
|
122
122
|
*/
|
|
123
123
|
/**
|
|
124
124
|
* @template {AssetKind} K
|
|
125
|
-
* @callback IssuerGetAmountOf
|
|
126
|
-
*
|
|
127
|
-
*
|
|
125
|
+
* @callback IssuerGetAmountOf
|
|
126
|
+
*
|
|
127
|
+
* Get the amount of digital assets in the payment. Because the
|
|
128
|
+
* payment is not trusted, we cannot call a method on it directly, and
|
|
129
|
+
* must use the issuer instead.
|
|
130
|
+
*
|
|
131
|
+
* If the payment is a promise, the operation will proceed upon
|
|
132
|
+
* resolution.
|
|
128
133
|
*
|
|
129
|
-
* If the payment is a promise, the operation will proceed upon resolution.
|
|
130
134
|
* @param {ERef<Payment>} payment
|
|
131
135
|
* @returns {Promise<Amount<K>>}
|
|
132
136
|
*/
|
|
133
137
|
|
|
134
138
|
/**
|
|
135
|
-
* @callback IssuerBurn
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
+
* @callback IssuerBurn
|
|
140
|
+
*
|
|
141
|
+
* Burn all of the digital assets in the
|
|
142
|
+
* payment. `optAmount` is optional. If `optAmount` is present, the
|
|
143
|
+
* code will insist that the amount of the digital assets in the
|
|
144
|
+
* payment is equal to `optAmount`, to prevent sending the wrong
|
|
145
|
+
* payment and other confusion.
|
|
146
|
+
*
|
|
147
|
+
* If the payment is a promise, the operation will proceed upon
|
|
148
|
+
* resolution.
|
|
139
149
|
*
|
|
140
|
-
* If the payment is a promise, the operation will proceed upon resolution.
|
|
141
150
|
* @param {ERef<Payment>} payment
|
|
142
151
|
* @param {Pattern} [optAmountShape]
|
|
143
152
|
* @returns {Promise<Amount>}
|
|
@@ -145,13 +154,17 @@ export {};
|
|
|
145
154
|
|
|
146
155
|
/**
|
|
147
156
|
* @template {AssetKind} K
|
|
148
|
-
* @callback IssuerClaim
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
157
|
+
* @callback IssuerClaim
|
|
158
|
+
*
|
|
159
|
+
* Transfer all digital assets from the payment to a new payment and
|
|
160
|
+
* delete the original. `optAmount` is optional. If `optAmount` is
|
|
161
|
+
* present, the code will insist that the amount of digital assets in
|
|
162
|
+
* the payment is equal to `optAmount`, to prevent sending the wrong
|
|
163
|
+
* payment and other confusion.
|
|
164
|
+
*
|
|
165
|
+
* If the payment is a promise, the operation will proceed upon
|
|
166
|
+
* resolution.
|
|
153
167
|
*
|
|
154
|
-
* If the payment is a promise, the operation will proceed upon resolution.
|
|
155
168
|
* @param {ERef<Payment<K>>} payment
|
|
156
169
|
* @param {Pattern} [optAmountShape]
|
|
157
170
|
* @returns {Promise<Payment<K>>}
|
|
@@ -159,10 +172,13 @@ export {};
|
|
|
159
172
|
|
|
160
173
|
/**
|
|
161
174
|
* @template {AssetKind} K
|
|
162
|
-
* @callback IssuerCombine
|
|
175
|
+
* @callback IssuerCombine
|
|
176
|
+
*
|
|
177
|
+
* Combine multiple payments into one payment.
|
|
178
|
+
*
|
|
179
|
+
* If any of the payments is a promise, the operation will proceed
|
|
180
|
+
* upon resolution.
|
|
163
181
|
*
|
|
164
|
-
* If any of the payments is a promise, the operation will proceed upon
|
|
165
|
-
* resolution.
|
|
166
182
|
* @param {ERef<Payment<K>>[]} paymentsArray
|
|
167
183
|
* @param {Amount<K>} [optTotalAmount]
|
|
168
184
|
* @returns {Promise<Payment<K>>}
|
|
@@ -170,20 +186,28 @@ export {};
|
|
|
170
186
|
|
|
171
187
|
/**
|
|
172
188
|
* @template {AssetKind} K
|
|
173
|
-
* @callback IssuerSplit
|
|
174
|
-
*
|
|
189
|
+
* @callback IssuerSplit
|
|
190
|
+
*
|
|
191
|
+
* Split a single payment into two payments,
|
|
192
|
+
* A and B, according to the paymentAmountA passed in.
|
|
193
|
+
*
|
|
194
|
+
* If the payment is a promise, the operation will proceed upon
|
|
195
|
+
* resolution.
|
|
175
196
|
*
|
|
176
|
-
* If the payment is a promise, the operation will proceed upon resolution.
|
|
177
197
|
* @param {ERef<Payment<K>>} payment
|
|
178
198
|
* @param {Amount<K>} paymentAmountA
|
|
179
199
|
* @returns {Promise<Payment<K>[]>}
|
|
180
200
|
*/
|
|
181
201
|
|
|
182
202
|
/**
|
|
183
|
-
* @callback IssuerSplitMany
|
|
184
|
-
*
|
|
203
|
+
* @callback IssuerSplitMany
|
|
204
|
+
*
|
|
205
|
+
* Split a single payment into many payments, according to the amounts
|
|
206
|
+
* passed in.
|
|
207
|
+
*
|
|
208
|
+
* If the payment is a promise, the operation will proceed upon
|
|
209
|
+
* resolution.
|
|
185
210
|
*
|
|
186
|
-
* If the payment is a promise, the operation will proceed upon resolution.
|
|
187
211
|
* @param {ERef<Payment>} payment
|
|
188
212
|
* @param {Amount[]} amounts
|
|
189
213
|
* @returns {Promise<Payment[]>}
|
|
@@ -191,24 +215,30 @@ export {};
|
|
|
191
215
|
|
|
192
216
|
/**
|
|
193
217
|
* @template {AssetKind} [K=AssetKind]
|
|
194
|
-
* @typedef {object} Issuer
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
218
|
+
* @typedef {object} Issuer
|
|
219
|
+
*
|
|
220
|
+
* The issuer cannot mint a new amount, but it can create empty purses
|
|
221
|
+
* and payments. The issuer can also transform payments (splitting
|
|
222
|
+
* payments, combining payments, burning payments, and claiming
|
|
223
|
+
* payments exclusively). The issuer should be gotten from a trusted
|
|
224
|
+
* source and then relied upon as the decider of whether an untrusted
|
|
225
|
+
* payment is valid.
|
|
226
|
+
*
|
|
227
|
+
* @property {() => Brand<K>} getBrand Get the Brand for this Issuer. The
|
|
228
|
+
* Brand indicates the type of digital asset and is shared by the
|
|
229
|
+
* mint, the issuer, and any purses and payments of this particular
|
|
230
|
+
* kind. The brand is not closely held, so this function should not be
|
|
231
|
+
* trusted to identify an issuer alone. Fake digital assets and amount
|
|
232
|
+
* can use another issuer's brand.
|
|
233
|
+
*
|
|
234
|
+
* @property {() => string} getAllegedName Get the allegedName for
|
|
235
|
+
* this mint/issuer
|
|
236
|
+
* @property {() => AssetKind} getAssetKind Get the kind of
|
|
237
|
+
* MathHelpers used by this Issuer.
|
|
238
|
+
* @property {() => DisplayInfo<K>} getDisplayInfo Give information to UI
|
|
239
|
+
* on how to display amounts for this issuer.
|
|
240
|
+
* @property {() => Purse<K>} makeEmptyPurse Make an empty purse of this
|
|
241
|
+
* brand.
|
|
212
242
|
* @property {IssuerIsLive} isLive
|
|
213
243
|
* @property {IssuerGetAmountOf<K>} getAmountOf
|
|
214
244
|
* @property {IssuerBurn} burn
|
|
@@ -235,27 +265,33 @@ export {};
|
|
|
235
265
|
|
|
236
266
|
/**
|
|
237
267
|
* @typedef {object} AdditionalDisplayInfo
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
* property
|
|
268
|
+
*
|
|
269
|
+
* @property {number} [decimalPlaces] Tells the display software how
|
|
270
|
+
* many decimal places to move the decimal over to the left, or in
|
|
271
|
+
* other words, which position corresponds to whole numbers. We
|
|
272
|
+
* require fungible digital assets to be represented in integers, in
|
|
273
|
+
* the smallest unit (i.e. USD might be represented in mill, a
|
|
274
|
+
* thousandth of a dollar. In that case, `decimalPlaces` would be
|
|
275
|
+
* 3.) This property is optional, and for non-fungible digital
|
|
276
|
+
* assets, should not be specified. The decimalPlaces property
|
|
277
|
+
* should be used for *display purposes only*. Any other use is an
|
|
246
278
|
* anti-pattern.
|
|
247
279
|
* @property {AssetKind} [assetKind]
|
|
248
280
|
*/
|
|
249
281
|
|
|
250
|
-
/**
|
|
282
|
+
/**
|
|
283
|
+
* @typedef {import('@agoric/swingset-vat').ShutdownWithFailure} ShutdownWithFailure
|
|
284
|
+
*/
|
|
251
285
|
|
|
252
286
|
/**
|
|
253
287
|
* @template {AssetKind} [K=AssetKind]
|
|
254
|
-
* @typedef {object} Mint
|
|
255
|
-
*
|
|
288
|
+
* @typedef {object} Mint
|
|
289
|
+
* Holding a Mint carries the right to issue new digital assets. These
|
|
290
|
+
* assets all have the same kind, which is called a Brand.
|
|
291
|
+
*
|
|
256
292
|
* @property {() => Issuer<K>} getIssuer Gets the Issuer for this mint.
|
|
257
|
-
* @property {(newAmount: Amount<K>) => Payment<K>} mintPayment
|
|
258
|
-
*
|
|
293
|
+
* @property {(newAmount: Amount<K>) => Payment<K>} mintPayment
|
|
294
|
+
* Creates a new Payment containing newly minted amount.
|
|
259
295
|
*/
|
|
260
296
|
|
|
261
297
|
/**
|
|
@@ -267,12 +303,12 @@ export {};
|
|
|
267
303
|
|
|
268
304
|
/**
|
|
269
305
|
* @typedef {object} DepositFacet
|
|
270
|
-
* @property {DepositFacetReceive} receive
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
306
|
+
* @property {DepositFacetReceive} receive
|
|
307
|
+
* Deposit all the contents of payment into the purse that made this facet,
|
|
308
|
+
* returning the amount. If the optional argument `optAmount` does not equal the
|
|
309
|
+
* amount of digital assets in the payment, throw an error.
|
|
274
310
|
*
|
|
275
|
-
*
|
|
311
|
+
* If payment is a promise, throw an error.
|
|
276
312
|
*/
|
|
277
313
|
|
|
278
314
|
/**
|
|
@@ -285,94 +321,121 @@ export {};
|
|
|
285
321
|
|
|
286
322
|
/**
|
|
287
323
|
* @template {AssetKind} [K=AssetKind]
|
|
288
|
-
* @typedef {object} Purse
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
* @property {
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
+
* @typedef {object} Purse
|
|
325
|
+
* Purses hold amount of digital assets of the same brand, but unlike Payments,
|
|
326
|
+
* they are not meant to be sent to others. To transfer digital assets, a
|
|
327
|
+
* Payment should be withdrawn from a Purse. The amount of digital
|
|
328
|
+
* assets in a purse can change through the action of deposit() and withdraw().
|
|
329
|
+
*
|
|
330
|
+
* The primary use for Purses and Payments is for currency-like and goods-like
|
|
331
|
+
* digital assets, but they can also be used to represent other kinds of rights,
|
|
332
|
+
* such as the right to participate in a particular contract.
|
|
333
|
+
*
|
|
334
|
+
* @property {() => Brand<K>} getAllegedBrand Get the alleged Brand for this Purse
|
|
335
|
+
*
|
|
336
|
+
* @property {() => Amount<K>} getCurrentAmount
|
|
337
|
+
* Get the amount contained in this purse.
|
|
338
|
+
*
|
|
339
|
+
* @property {() => LatestTopic<Amount<K>>} getCurrentAmountNotifier
|
|
340
|
+
* Get a lossy notifier for changes to this purse's balance.
|
|
341
|
+
*
|
|
342
|
+
* @property {PurseDeposit<K>} deposit
|
|
343
|
+
* Deposit all the contents of payment into this purse, returning the
|
|
344
|
+
* amount. If the optional argument `optAmount` does not equal the
|
|
345
|
+
* amount of digital assets in the payment, throw an error.
|
|
346
|
+
*
|
|
347
|
+
* If payment is a promise, throw an error.
|
|
348
|
+
*
|
|
349
|
+
* @property {() => DepositFacet} getDepositFacet
|
|
350
|
+
* Return an object whose `receive` method deposits to the current Purse.
|
|
351
|
+
*
|
|
352
|
+
* @property {(amount: Amount<K>) => Payment<K>} withdraw
|
|
353
|
+
* Withdraw amount from this purse into a new Payment.
|
|
354
|
+
*
|
|
355
|
+
* @property {() => CopySet<Payment<K>>} getRecoverySet
|
|
356
|
+
* The set of payments withdrawn from this purse that are still live. These
|
|
357
|
+
* are the payments that can still be recovered in emergencies by, for example,
|
|
358
|
+
* depositing into this purse. Such a deposit action is like canceling an
|
|
359
|
+
* outstanding check because you're tired of waiting for it. Once your
|
|
360
|
+
* cancellation is acknowledged, you can spend the assets at stake on other
|
|
361
|
+
* things. Afterwards, if the recipient of the original check finally gets
|
|
362
|
+
* around to depositing it, their deposit fails.
|
|
363
|
+
*
|
|
364
|
+
* @property {() => Amount<K>} recoverAll
|
|
365
|
+
* For use in emergencies, such as coming back from a traumatic crash and
|
|
366
|
+
* upgrade. This deposits all the payments in this purse's recovery set
|
|
367
|
+
* into the purse itself, returning the total amount of assets recovered.
|
|
324
368
|
*/
|
|
325
369
|
|
|
326
370
|
/**
|
|
327
371
|
* @template {AssetKind} [K=AssetKind]
|
|
328
|
-
* @typedef {object} Payment
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
*
|
|
372
|
+
* @typedef {object} Payment
|
|
373
|
+
* Payments hold amount of digital assets of the same brand in transit. Payments
|
|
374
|
+
* can be deposited in purses, split into multiple payments, combined, and
|
|
375
|
+
* claimed (getting an exclusive payment). Payments are linear, meaning
|
|
376
|
+
* that either a payment has the same amount of digital assets it
|
|
377
|
+
* started with, or it is used up entirely. It is impossible to partially use a
|
|
378
|
+
* payment.
|
|
379
|
+
*
|
|
380
|
+
* Payments are often received from other actors and therefore should
|
|
381
|
+
* not be trusted themselves. To get the amount of digital assets in a payment,
|
|
382
|
+
* use the trusted issuer: issuer.getAmountOf(payment),
|
|
383
|
+
*
|
|
384
|
+
* Payments can be converted to Purses by getting a trusted issuer and
|
|
385
|
+
* calling `issuer.makeEmptyPurse()` to create a purse, then
|
|
386
|
+
* `purse.deposit(payment)`.
|
|
387
|
+
*
|
|
388
|
+
* @property {() => Brand<K>} getAllegedBrand
|
|
389
|
+
* Get the allegedBrand, indicating the type of digital asset this
|
|
390
|
+
* payment purports to be, and which issuer to use. Because payments
|
|
391
|
+
* are not trusted, any method calls on payments should be treated
|
|
392
|
+
* with suspicion and verified elsewhere.
|
|
346
393
|
*/
|
|
347
394
|
|
|
348
395
|
/**
|
|
349
396
|
* @template {AmountValue} V
|
|
350
|
-
* @typedef {object} MathHelpers
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
* @property {(
|
|
372
|
-
*
|
|
373
|
-
*
|
|
397
|
+
* @typedef {object} MathHelpers
|
|
398
|
+
* All of the difference in how digital asset amount are manipulated can be
|
|
399
|
+
* reduced to the behavior of the math on values. We extract this
|
|
400
|
+
* custom logic into mathHelpers. MathHelpers are about value
|
|
401
|
+
* arithmetic, whereas AmountMath is about amounts, which are the
|
|
402
|
+
* values labeled with a brand. AmountMath use mathHelpers to do their value
|
|
403
|
+
* arithmetic, and then brand the results, making a new amount.
|
|
404
|
+
*
|
|
405
|
+
* The MathHelpers are designed to be called only from AmountMath, and so
|
|
406
|
+
* all methods but coerce can assume their inputs are valid. They only
|
|
407
|
+
* need to do output validation, and only when there is a possibility of
|
|
408
|
+
* invalid output.
|
|
409
|
+
*
|
|
410
|
+
* @property {(allegedValue: V) => V} doCoerce
|
|
411
|
+
* Check the kind of this value and throw if it is not the
|
|
412
|
+
* expected kind.
|
|
413
|
+
*
|
|
414
|
+
* @property {() => V} doMakeEmpty
|
|
415
|
+
* Get the representation for the identity element (often 0 or an
|
|
416
|
+
* empty array)
|
|
417
|
+
*
|
|
418
|
+
* @property {(value: V) => boolean} doIsEmpty
|
|
419
|
+
* Is the value the identity element?
|
|
420
|
+
*
|
|
421
|
+
* @property {(left: V, right: V) => boolean} doIsGTE
|
|
422
|
+
* Is the left greater than or equal to the right?
|
|
423
|
+
*
|
|
424
|
+
* @property {(left: V, right: V) => boolean} doIsEqual
|
|
425
|
+
* Does left equal right?
|
|
426
|
+
*
|
|
427
|
+
* @property {(left: V, right: V) => V} doAdd
|
|
428
|
+
* Return the left combined with the right.
|
|
429
|
+
*
|
|
430
|
+
* @property {(left: V, right: V) => V} doSubtract
|
|
431
|
+
* Return what remains after removing the right from the left. If
|
|
432
|
+
* something in the right was not in the left, we throw an error.
|
|
374
433
|
*/
|
|
375
434
|
|
|
376
|
-
/**
|
|
435
|
+
/**
|
|
436
|
+
* @typedef {bigint} NatValue
|
|
437
|
+
*/
|
|
377
438
|
|
|
378
|
-
/**
|
|
439
|
+
/**
|
|
440
|
+
* @typedef {Array<Key>} SetValue
|
|
441
|
+
*/
|