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