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