@agoric/ertp 0.16.3-other-dev-8f8782b.0 → 0.16.3-other-dev-fbe72e7.0.fbe72e7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/exported.d.ts +37 -0
- package/exported.js +2 -1
- package/package.json +37 -37
- package/src/amountMath.d.ts +46 -38
- package/src/amountMath.d.ts.map +1 -1
- package/src/amountMath.js +136 -128
- package/src/amountStore.d.ts +9 -0
- package/src/amountStore.d.ts.map +1 -0
- package/src/amountStore.js +34 -0
- package/src/displayInfo.d.ts +3 -0
- package/src/displayInfo.d.ts.map +1 -1
- package/src/displayInfo.js +3 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +4 -0
- package/src/issuerKit.d.ts +29 -9
- package/src/issuerKit.d.ts.map +1 -1
- package/src/issuerKit.js +230 -75
- package/src/legacy-payment-helpers.d.ts +9 -2
- package/src/legacy-payment-helpers.d.ts.map +1 -1
- package/src/legacy-payment-helpers.js +43 -37
- package/src/mathHelpers/copyBagMathHelpers.d.ts +3 -4
- package/src/mathHelpers/copyBagMathHelpers.d.ts.map +1 -1
- package/src/mathHelpers/copyBagMathHelpers.js +4 -5
- package/src/mathHelpers/copySetMathHelpers.d.ts +3 -3
- package/src/mathHelpers/copySetMathHelpers.d.ts.map +1 -1
- package/src/mathHelpers/copySetMathHelpers.js +6 -4
- package/src/mathHelpers/natMathHelpers.d.ts +8 -7
- package/src/mathHelpers/natMathHelpers.d.ts.map +1 -1
- package/src/mathHelpers/natMathHelpers.js +8 -9
- package/src/mathHelpers/setMathHelpers.d.ts +2 -0
- package/src/mathHelpers/setMathHelpers.d.ts.map +1 -1
- package/src/mathHelpers/setMathHelpers.js +2 -1
- package/src/payment.d.ts +4 -2
- package/src/payment.d.ts.map +1 -1
- package/src/payment.js +8 -8
- package/src/paymentLedger.d.ts +8 -2
- package/src/paymentLedger.d.ts.map +1 -1
- package/src/paymentLedger.js +80 -97
- package/src/purse.d.ts +19 -9
- package/src/purse.d.ts.map +1 -1
- package/src/purse.js +86 -26
- package/src/ratio.d.ts +48 -0
- package/src/ratio.d.ts.map +1 -0
- package/src/ratio.js +441 -0
- package/src/safeMath.d.ts +11 -0
- package/src/safeMath.d.ts.map +1 -0
- package/src/safeMath.js +50 -0
- package/src/transientNotifier.d.ts +1 -1
- package/src/transientNotifier.d.ts.map +1 -1
- package/src/transientNotifier.js +5 -0
- package/src/typeGuards.d.ts +64 -13
- package/src/typeGuards.d.ts.map +1 -1
- package/src/typeGuards.js +70 -57
- package/src/types-index.d.ts +2 -0
- package/src/types-index.js +2 -0
- package/src/types.d.ts +254 -220
- package/src/types.d.ts.map +1 -1
- package/src/types.ts +474 -0
- package/CHANGELOG.md +0 -743
- package/src/types-ambient.d.ts +0 -376
- package/src/types-ambient.d.ts.map +0 -1
- package/src/types-ambient.js +0 -440
- package/src/types.js +0 -441
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Fungible digital assets use the natMathHelpers to manage balances -
|
|
3
|
-
*
|
|
4
|
-
* numbers.
|
|
2
|
+
* Fungible digital assets use the natMathHelpers to manage balances - the
|
|
3
|
+
* operations are merely arithmetic on natural, non-negative numbers.
|
|
5
4
|
*
|
|
6
|
-
* Natural numbers are used for fungible erights such as money because
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* Natural numbers are used for fungible erights such as money because rounding
|
|
6
|
+
* issues make floats problematic. All operations should be done with the
|
|
7
|
+
* smallest whole unit such that the `natMathHelpers` never deals with
|
|
8
|
+
* fractional parts.
|
|
10
9
|
*
|
|
11
10
|
* @type {MathHelpers<NatValue>}
|
|
12
11
|
*/
|
|
13
12
|
export const natMathHelpers: MathHelpers<NatValue>;
|
|
13
|
+
import type { NatValue } from '../types.js';
|
|
14
|
+
import type { MathHelpers } from '../types.js';
|
|
14
15
|
//# sourceMappingURL=natMathHelpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"natMathHelpers.d.ts","sourceRoot":"","sources":["natMathHelpers.js"],"names":[],"mappings":"AASA
|
|
1
|
+
{"version":3,"file":"natMathHelpers.d.ts","sourceRoot":"","sources":["natMathHelpers.js"],"names":[],"mappings":"AASA;;;;;;;;;;GAUG;AACH,6BAFU,YAAY,QAAQ,CAAC,CAgB5B;8BA7BsC,aAAa;iCAAb,aAAa"}
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
// @jessie-check
|
|
2
2
|
|
|
3
|
+
import { Fail } from '@endo/errors';
|
|
3
4
|
import { Nat, isNat } from '@endo/nat';
|
|
4
5
|
|
|
5
|
-
import '../types
|
|
6
|
+
/** @import {MathHelpers, NatValue} from '../types.js' */
|
|
6
7
|
|
|
7
|
-
const { Fail } = assert;
|
|
8
8
|
const empty = 0n;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Fungible digital assets use the natMathHelpers to manage balances -
|
|
12
|
-
*
|
|
13
|
-
* numbers.
|
|
11
|
+
* Fungible digital assets use the natMathHelpers to manage balances - the
|
|
12
|
+
* operations are merely arithmetic on natural, non-negative numbers.
|
|
14
13
|
*
|
|
15
|
-
* Natural numbers are used for fungible erights such as money because
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
14
|
+
* Natural numbers are used for fungible erights such as money because rounding
|
|
15
|
+
* issues make floats problematic. All operations should be done with the
|
|
16
|
+
* smallest whole unit such that the `natMathHelpers` never deals with
|
|
17
|
+
* fractional parts.
|
|
19
18
|
*
|
|
20
19
|
* @type {MathHelpers<NatValue>}
|
|
21
20
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setMathHelpers.d.ts","sourceRoot":"","sources":["setMathHelpers.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"setMathHelpers.d.ts","sourceRoot":"","sources":["setMathHelpers.js"],"names":[],"mappings":"AAmBA;;;GAGG;AACH,6BAFU,YAAY,QAAQ,CAAC,CAkB5B;8BA3BsC,aAAa;iCAAb,aAAa"}
|
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
coerceToElements,
|
|
10
10
|
elementsCompare,
|
|
11
11
|
} from '@agoric/store';
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
/** @import {MathHelpers, SetValue} from '../types.js' */
|
|
13
14
|
|
|
14
15
|
// Operations for arrays with unique objects identifying and providing
|
|
15
16
|
// information about digital assets. Used for Zoe invites.
|
package/src/payment.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export function preparePaymentKind<K extends AssetKind>(
|
|
2
|
-
|
|
1
|
+
export function preparePaymentKind<K extends AssetKind>(issuerZone: import("@agoric/zone").Zone, name: string, brand: Brand<K>, PaymentI: import("@endo/patterns").InterfaceGuard<any>): () => Payment<K, any>;
|
|
2
|
+
import type { AssetKind } from './types.js';
|
|
3
|
+
import type { Brand } from './types.js';
|
|
4
|
+
import type { Payment } from './types.js';
|
|
3
5
|
//# sourceMappingURL=payment.d.ts.map
|
package/src/payment.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["payment.js"],"names":[],"mappings":"AAeO,
|
|
1
|
+
{"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["payment.js"],"names":[],"mappings":"AAeO,mCAPkB,CAAC,SAAb,SAAW,cACb,OAAO,cAAc,EAAE,IAAI,QAC3B,MAAM,SACN,MAAM,CAAC,CAAC,YACR,OAAO,gBAAgB,EAAE,cAAc,CAAC,GAAG,CAAC,GAC1C,MAAM,QAAQ,CAAC,EAAE,GAAG,CAAC,CAejC;+BAxB4C,YAAY;2BAAZ,YAAY;6BAAZ,YAAY"}
|
package/src/payment.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
// @jessie-check
|
|
2
2
|
|
|
3
3
|
import { initEmpty } from '@agoric/store';
|
|
4
|
-
import { prepareExoClass } from '@agoric/vat-data';
|
|
5
4
|
|
|
6
|
-
/** @
|
|
5
|
+
/** @import {AssetKind, Brand, Payment} from './types.js' */
|
|
7
6
|
|
|
7
|
+
// TODO Type InterfaceGuard better than InterfaceGuard<any>
|
|
8
8
|
/**
|
|
9
9
|
* @template {AssetKind} K
|
|
10
|
-
* @param {
|
|
10
|
+
* @param {import('@agoric/zone').Zone} issuerZone
|
|
11
11
|
* @param {string} name
|
|
12
12
|
* @param {Brand<K>} brand
|
|
13
|
-
* @param {InterfaceGuard} PaymentI
|
|
14
|
-
* @returns {() => Payment<K>}
|
|
13
|
+
* @param {import('@endo/patterns').InterfaceGuard<any>} PaymentI
|
|
14
|
+
* @returns {() => Payment<K, any>}
|
|
15
15
|
*/
|
|
16
|
-
export const preparePaymentKind = (
|
|
17
|
-
const makePayment =
|
|
18
|
-
issuerBaggage,
|
|
16
|
+
export const preparePaymentKind = (issuerZone, name, brand, PaymentI) => {
|
|
17
|
+
const makePayment = issuerZone.exoClass(
|
|
19
18
|
`${name} payment`,
|
|
20
19
|
PaymentI,
|
|
21
20
|
initEmpty,
|
|
@@ -25,6 +24,7 @@ export const preparePaymentKind = (issuerBaggage, name, brand, PaymentI) => {
|
|
|
25
24
|
},
|
|
26
25
|
},
|
|
27
26
|
);
|
|
27
|
+
// @ts-expect-error [tag] for tagged type not defined in runtime
|
|
28
28
|
return makePayment;
|
|
29
29
|
};
|
|
30
30
|
harden(preparePaymentKind);
|
package/src/paymentLedger.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
export function preparePaymentLedger<K extends AssetKind>(
|
|
2
|
-
|
|
1
|
+
export function preparePaymentLedger<K extends AssetKind>(issuerZone: Zone, name: string, assetKind: K, displayInfo: DisplayInfo<K>, elementShape: Pattern, recoverySetsState: RecoverySetsOption, optShutdownWithFailure?: ShutdownWithFailure): PaymentLedger<K>;
|
|
2
|
+
import type { AssetKind } from './types.js';
|
|
3
|
+
import type { Zone } from '@agoric/base-zone';
|
|
4
|
+
import type { DisplayInfo } from './types.js';
|
|
5
|
+
import type { Pattern } from '@endo/patterns';
|
|
6
|
+
import type { RecoverySetsOption } from './types.js';
|
|
7
|
+
import type { ShutdownWithFailure } from '@agoric/swingset-vat';
|
|
8
|
+
import type { PaymentLedger } from './types.js';
|
|
3
9
|
//# sourceMappingURL=paymentLedger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paymentLedger.d.ts","sourceRoot":"","sources":["paymentLedger.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"paymentLedger.d.ts","sourceRoot":"","sources":["paymentLedger.js"],"names":[],"mappings":"AAuFO,qCAVkB,CAAC,SAAb,SAAW,cACb,IAAI,QACJ,MAAM,aACN,CAAC,eACD,YAAY,CAAC,CAAC,gBACd,OAAO,qBACP,kBAAkB,2BAClB,mBAAmB,GACjB,cAAc,CAAC,CAAC,CAyT5B;+BA5XwH,YAAY;0BAJ9G,mBAAmB;iCAI+E,YAAY;6BALtG,gBAAgB;wCAK0E,YAAY;yCAF/F,sBAAsB;mCAE6D,YAAY"}
|
package/src/paymentLedger.js
CHANGED
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
// @jessie-check
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/// <reference types="@agoric/store/exported.js" />
|
|
4
|
+
|
|
5
|
+
import { q, Fail, annotateError, X } from '@endo/errors';
|
|
4
6
|
import { isPromise } from '@endo/promise-kit';
|
|
5
|
-
import { mustMatch, M, keyEQ } from '@
|
|
6
|
-
import {
|
|
7
|
-
provideDurableWeakMapStore,
|
|
8
|
-
prepareExo,
|
|
9
|
-
provide,
|
|
10
|
-
} from '@agoric/vat-data';
|
|
7
|
+
import { mustMatch, M, keyEQ } from '@endo/patterns';
|
|
11
8
|
import { AmountMath } from './amountMath.js';
|
|
12
9
|
import { preparePaymentKind } from './payment.js';
|
|
13
10
|
import { preparePurseKind } from './purse.js';
|
|
14
|
-
|
|
15
|
-
import '@agoric/store/exported.js';
|
|
16
11
|
import { BrandI, makeIssuerInterfaces } from './typeGuards.js';
|
|
17
12
|
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
/**
|
|
14
|
+
* @import {Key, Pattern} from '@endo/patterns';
|
|
15
|
+
* @import {Zone} from '@agoric/base-zone';
|
|
16
|
+
* @import {TypedPattern} from '@agoric/internal';
|
|
17
|
+
* @import {ShutdownWithFailure} from '@agoric/swingset-vat';
|
|
18
|
+
* @import {AmountStore} from './amountStore.js';
|
|
19
|
+
* @import {Amount, AssetKind, DisplayInfo, PaymentLedger, Payment, Brand, RecoverySetsOption, Purse, Issuer, Mint} from './types.js';
|
|
20
|
+
*/
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
+
* @template {AssetKind} K
|
|
23
24
|
* @param {Brand} brand
|
|
24
|
-
* @param {
|
|
25
|
+
* @param {K} assetKind
|
|
25
26
|
* @param {Pattern} elementShape
|
|
27
|
+
* @returns {TypedPattern<Amount<K>>}
|
|
26
28
|
*/
|
|
27
29
|
const amountShapeFromElementShape = (brand, assetKind, elementShape) => {
|
|
28
30
|
let valueShape;
|
|
@@ -70,29 +72,31 @@ const amountShapeFromElementShape = (brand, assetKind, elementShape) => {
|
|
|
70
72
|
};
|
|
71
73
|
|
|
72
74
|
/**
|
|
73
|
-
* Make the paymentLedger, the source of truth for the balances of
|
|
74
|
-
*
|
|
75
|
+
* Make the paymentLedger, the source of truth for the balances of payments. All
|
|
76
|
+
* minting and transfer authority originates here.
|
|
75
77
|
*
|
|
76
78
|
* @template {AssetKind} K
|
|
77
|
-
* @param {
|
|
79
|
+
* @param {Zone} issuerZone
|
|
78
80
|
* @param {string} name
|
|
79
81
|
* @param {K} assetKind
|
|
80
82
|
* @param {DisplayInfo<K>} displayInfo
|
|
81
83
|
* @param {Pattern} elementShape
|
|
84
|
+
* @param {RecoverySetsOption} recoverySetsState
|
|
82
85
|
* @param {ShutdownWithFailure} [optShutdownWithFailure]
|
|
83
86
|
* @returns {PaymentLedger<K>}
|
|
84
87
|
*/
|
|
85
88
|
export const preparePaymentLedger = (
|
|
86
|
-
|
|
89
|
+
issuerZone,
|
|
87
90
|
name,
|
|
88
91
|
assetKind,
|
|
89
92
|
displayInfo,
|
|
90
93
|
elementShape,
|
|
94
|
+
recoverySetsState,
|
|
91
95
|
optShutdownWithFailure = undefined,
|
|
92
96
|
) => {
|
|
93
97
|
/** @type {Brand<K>} */
|
|
94
98
|
// @ts-expect-error XXX callWhen
|
|
95
|
-
const brand =
|
|
99
|
+
const brand = issuerZone.exo(`${name} brand`, BrandI, {
|
|
96
100
|
isMyIssuer(allegedIssuer) {
|
|
97
101
|
// BrandI delays calling this method until `allegedIssuer` is a Remotable
|
|
98
102
|
return allegedIssuer === issuer;
|
|
@@ -121,7 +125,7 @@ export const preparePaymentLedger = (
|
|
|
121
125
|
amountShape,
|
|
122
126
|
);
|
|
123
127
|
|
|
124
|
-
const makePayment = preparePaymentKind(
|
|
128
|
+
const makePayment = preparePaymentKind(issuerZone, name, brand, PaymentI);
|
|
125
129
|
|
|
126
130
|
/** @type {ShutdownWithFailure} */
|
|
127
131
|
const shutdownLedgerWithFailure = reason => {
|
|
@@ -131,7 +135,7 @@ export const preparePaymentLedger = (
|
|
|
131
135
|
try {
|
|
132
136
|
optShutdownWithFailure(reason);
|
|
133
137
|
} catch (errInShutdown) {
|
|
134
|
-
|
|
138
|
+
annotateError(errInShutdown, X`Caused by: ${reason}`);
|
|
135
139
|
throw errInShutdown;
|
|
136
140
|
}
|
|
137
141
|
}
|
|
@@ -139,48 +143,48 @@ export const preparePaymentLedger = (
|
|
|
139
143
|
};
|
|
140
144
|
|
|
141
145
|
/** @type {WeakMapStore<Payment, Amount>} */
|
|
142
|
-
const paymentLedger =
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
{ valueShape: amountShape },
|
|
146
|
-
);
|
|
146
|
+
const paymentLedger = issuerZone.weakMapStore('paymentLedger', {
|
|
147
|
+
valueShape: amountShape,
|
|
148
|
+
});
|
|
147
149
|
|
|
148
150
|
/**
|
|
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
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
151
|
+
* A (non-empty) withdrawn live payment is associated with the recovery set of
|
|
152
|
+
* the purse it was withdrawn from. Let's call these "recoverable" payments.
|
|
153
|
+
* All recoverable payments are live, but not all live payments are
|
|
154
|
+
* recoverable. We do the bookkeeping for payment recovery with this weakmap
|
|
155
|
+
* from recoverable payments to the recovery set they are in. A bunch of
|
|
156
|
+
* interesting invariants here:
|
|
157
|
+
*
|
|
158
|
+
* - Every payment that is a key in the outer `paymentRecoverySets` weakMap is
|
|
159
|
+
* also in the recovery set indexed by that payment.
|
|
160
|
+
* - Implied by the above but worth stating: the payment is only in at most one
|
|
161
|
+
* recovery set.
|
|
162
|
+
* - A recovery set only contains such payments.
|
|
163
|
+
* - Every purse is associated with exactly one recovery set unique to it.
|
|
164
|
+
* - A purse's recovery set only contains payments withdrawn from that purse and
|
|
165
|
+
* not yet consumed.
|
|
166
|
+
*
|
|
167
|
+
* If `recoverySetsState === 'noRecoverySets'`, then nothing should ever be
|
|
168
|
+
* added to this WeakStore.
|
|
165
169
|
*
|
|
166
170
|
* @type {WeakMapStore<Payment, SetStore<Payment>>}
|
|
167
171
|
*/
|
|
168
|
-
const paymentRecoverySets =
|
|
169
|
-
issuerBaggage,
|
|
170
|
-
'paymentRecoverySets',
|
|
171
|
-
);
|
|
172
|
+
const paymentRecoverySets = issuerZone.weakMapStore('paymentRecoverySets');
|
|
172
173
|
|
|
173
174
|
/**
|
|
174
175
|
* To maintain the invariants listed in the `paymentRecoverySets` comment,
|
|
175
|
-
* `initPayment` should contain the only
|
|
176
|
-
* call to `paymentLedger.init`.
|
|
176
|
+
* `initPayment` should contain the only call to `paymentLedger.init`.
|
|
177
177
|
*
|
|
178
178
|
* @param {Payment} payment
|
|
179
179
|
* @param {Amount} amount
|
|
180
180
|
* @param {SetStore<Payment>} [optRecoverySet]
|
|
181
181
|
*/
|
|
182
182
|
const initPayment = (payment, amount, optRecoverySet = undefined) => {
|
|
183
|
-
if (
|
|
183
|
+
if (recoverySetsState === 'noRecoverySets') {
|
|
184
|
+
optRecoverySet === undefined ||
|
|
185
|
+
Fail`when recoverSetsState === 'noRecoverySets', optRecoverySet must be empty`;
|
|
186
|
+
}
|
|
187
|
+
if (optRecoverySet !== undefined && !AmountMath.isEmpty(amount)) {
|
|
184
188
|
optRecoverySet.add(payment);
|
|
185
189
|
paymentRecoverySets.init(payment, optRecoverySet);
|
|
186
190
|
}
|
|
@@ -189,8 +193,7 @@ export const preparePaymentLedger = (
|
|
|
189
193
|
|
|
190
194
|
/**
|
|
191
195
|
* To maintain the invariants listed in the `paymentRecoverySets` comment,
|
|
192
|
-
* `deletePayment` should contain the only
|
|
193
|
-
* call to `paymentLedger.delete`.
|
|
196
|
+
* `deletePayment` should contain the only call to `paymentLedger.delete`.
|
|
194
197
|
*
|
|
195
198
|
* @param {Payment} payment
|
|
196
199
|
*/
|
|
@@ -203,19 +206,14 @@ export const preparePaymentLedger = (
|
|
|
203
206
|
}
|
|
204
207
|
};
|
|
205
208
|
|
|
206
|
-
/** @type {(left: Amount, right: Amount) => Amount } */
|
|
207
|
-
const add = (left, right) => AmountMath.add(left, right, brand);
|
|
208
|
-
/** @type {(left: Amount, right: Amount) => Amount } */
|
|
209
|
-
const subtract = (left, right) => AmountMath.subtract(left, right, brand);
|
|
210
209
|
/** @type {(allegedAmount: Amount) => Amount} */
|
|
211
210
|
const coerce = allegedAmount => AmountMath.coerce(brand, allegedAmount);
|
|
212
|
-
/** @type {(left: Amount, right: Amount) => boolean
|
|
211
|
+
/** @type {(left: Amount, right: Amount) => boolean} */
|
|
213
212
|
|
|
214
213
|
/**
|
|
215
|
-
* Methods like deposit() have an optional second parameter
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
* payment. This helper function does that check.
|
|
214
|
+
* Methods like deposit() have an optional second parameter `optAmountShape`
|
|
215
|
+
* which, if present, is supposed to match the balance of the payment. This
|
|
216
|
+
* helper function does that check.
|
|
219
217
|
*
|
|
220
218
|
* Note: `optAmountShape` is user-supplied with no previous validation.
|
|
221
219
|
*
|
|
@@ -243,17 +241,13 @@ export const preparePaymentLedger = (
|
|
|
243
241
|
/**
|
|
244
242
|
* Used by the purse code to implement purse.deposit
|
|
245
243
|
*
|
|
246
|
-
* @param {
|
|
247
|
-
* before a deposit
|
|
248
|
-
* @param {(newPurseBalance: Amount) => void} updatePurseBalance -
|
|
249
|
-
* commit the purse balance
|
|
244
|
+
* @param {AmountStore} balanceStore
|
|
250
245
|
* @param {Payment} srcPayment
|
|
251
246
|
* @param {Pattern} [optAmountShape]
|
|
252
247
|
* @returns {Amount}
|
|
253
248
|
*/
|
|
254
249
|
const depositInternal = (
|
|
255
|
-
|
|
256
|
-
updatePurseBalance,
|
|
250
|
+
balanceStore,
|
|
257
251
|
srcPayment,
|
|
258
252
|
optAmountShape = undefined,
|
|
259
253
|
) => {
|
|
@@ -265,13 +259,12 @@ export const preparePaymentLedger = (
|
|
|
265
259
|
assertLivePayment(srcPayment);
|
|
266
260
|
const srcPaymentBalance = paymentLedger.get(srcPayment);
|
|
267
261
|
assertAmountConsistent(srcPaymentBalance, optAmountShape);
|
|
268
|
-
const newPurseBalance = add(srcPaymentBalance, currentBalance);
|
|
269
262
|
try {
|
|
270
263
|
// COMMIT POINT
|
|
271
264
|
// Move the assets in `srcPayment` into this purse, using up the
|
|
272
265
|
// source payment, such that total assets are conserved.
|
|
273
266
|
deletePayment(srcPayment);
|
|
274
|
-
|
|
267
|
+
balanceStore.increment(srcPaymentBalance);
|
|
275
268
|
} catch (err) {
|
|
276
269
|
shutdownLedgerWithFailure(err);
|
|
277
270
|
throw err;
|
|
@@ -282,30 +275,19 @@ export const preparePaymentLedger = (
|
|
|
282
275
|
/**
|
|
283
276
|
* Used by the purse code to implement purse.withdraw
|
|
284
277
|
*
|
|
285
|
-
* @param {
|
|
286
|
-
* before a withdrawal
|
|
287
|
-
* @param {(newPurseBalance: Amount) => void} updatePurseBalance -
|
|
288
|
-
* commit the purse balance
|
|
278
|
+
* @param {AmountStore} balanceStore
|
|
289
279
|
* @param {Amount} amount - the amount to be withdrawn
|
|
290
|
-
* @param {SetStore<Payment>} recoverySet
|
|
280
|
+
* @param {SetStore<Payment>} [recoverySet]
|
|
291
281
|
* @returns {Payment}
|
|
292
282
|
*/
|
|
293
|
-
const withdrawInternal = (
|
|
294
|
-
currentBalance,
|
|
295
|
-
updatePurseBalance,
|
|
296
|
-
amount,
|
|
297
|
-
recoverySet,
|
|
298
|
-
) => {
|
|
283
|
+
const withdrawInternal = (balanceStore, amount, recoverySet = undefined) => {
|
|
299
284
|
amount = coerce(amount);
|
|
300
|
-
AmountMath.isGTE(currentBalance, amount) ||
|
|
301
|
-
Fail`Withdrawal of ${amount} failed because the purse only contained ${currentBalance}`;
|
|
302
|
-
const newPurseBalance = subtract(currentBalance, amount);
|
|
303
|
-
|
|
304
285
|
const payment = makePayment();
|
|
286
|
+
// COMMIT POINT Move the withdrawn assets from this purse into
|
|
287
|
+
// payment. Total assets must remain conserved.
|
|
288
|
+
balanceStore.decrement(amount) ||
|
|
289
|
+
Fail`Withdrawal of ${amount} failed because the purse only contained ${balanceStore.getAmount()}`;
|
|
305
290
|
try {
|
|
306
|
-
// COMMIT POINT Move the withdrawn assets from this purse into
|
|
307
|
-
// payment. Total assets must remain conserved.
|
|
308
|
-
updatePurseBalance(newPurseBalance);
|
|
309
291
|
initPayment(payment, amount, recoverySet);
|
|
310
292
|
} catch (err) {
|
|
311
293
|
shutdownLedgerWithFailure(err);
|
|
@@ -314,8 +296,10 @@ export const preparePaymentLedger = (
|
|
|
314
296
|
return payment;
|
|
315
297
|
};
|
|
316
298
|
|
|
299
|
+
/** @type {() => Purse<K>} */
|
|
300
|
+
// @ts-expect-error XXX amount kinds
|
|
317
301
|
const makeEmptyPurse = preparePurseKind(
|
|
318
|
-
|
|
302
|
+
issuerZone,
|
|
319
303
|
name,
|
|
320
304
|
assetKind,
|
|
321
305
|
brand,
|
|
@@ -324,11 +308,13 @@ export const preparePaymentLedger = (
|
|
|
324
308
|
depositInternal,
|
|
325
309
|
withdrawInternal,
|
|
326
310
|
}),
|
|
311
|
+
recoverySetsState,
|
|
312
|
+
paymentRecoverySets,
|
|
327
313
|
);
|
|
328
314
|
|
|
329
315
|
/** @type {Issuer<K>} */
|
|
330
|
-
// @ts-expect-error
|
|
331
|
-
const issuer =
|
|
316
|
+
// @ts-expect-error XXX callWhen
|
|
317
|
+
const issuer = issuerZone.exo(`${name} issuer`, IssuerI, {
|
|
332
318
|
getBrand() {
|
|
333
319
|
return brand;
|
|
334
320
|
},
|
|
@@ -378,23 +364,20 @@ export const preparePaymentLedger = (
|
|
|
378
364
|
/**
|
|
379
365
|
* Provides for the recovery of newly minted but not-yet-deposited payments.
|
|
380
366
|
*
|
|
381
|
-
* Because the `mintRecoveryPurse` is placed in baggage, even if the
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
* @type {Purse<K>}
|
|
367
|
+
* Because the `mintRecoveryPurse` is placed in baggage, even if the caller of
|
|
368
|
+
* `makeIssuerKit` drops it on the floor, it can still be recovered in an
|
|
369
|
+
* emergency upgrade.
|
|
386
370
|
*/
|
|
387
|
-
const mintRecoveryPurse =
|
|
388
|
-
makeEmptyPurse()
|
|
371
|
+
const mintRecoveryPurse = /** @type {Purse<K>} */ (
|
|
372
|
+
issuerZone.makeOnce('mintRecoveryPurse', () => makeEmptyPurse())
|
|
389
373
|
);
|
|
390
374
|
|
|
391
375
|
/** @type {Mint<K>} */
|
|
392
|
-
const mint =
|
|
376
|
+
const mint = issuerZone.exo(`${name} mint`, MintI, {
|
|
393
377
|
getIssuer() {
|
|
394
378
|
return issuer;
|
|
395
379
|
},
|
|
396
380
|
mintPayment(newAmount) {
|
|
397
|
-
// @ts-expect-error checked cast
|
|
398
381
|
newAmount = coerce(newAmount);
|
|
399
382
|
mustMatch(newAmount, amountShape, 'minted amount');
|
|
400
383
|
// `rawPayment` is not associated with any recovery set, and
|
package/src/purse.d.ts
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
|
-
export function preparePurseKind(
|
|
1
|
+
export function preparePurseKind(issuerZone: import("@agoric/zone").Zone, name: string, assetKind: AssetKind, brand: Brand, PurseIKit: {
|
|
2
|
+
purse: import("@endo/patterns").InterfaceGuard<any>;
|
|
3
|
+
depositFacet: import("@endo/patterns").InterfaceGuard<any>;
|
|
4
|
+
}, purseMethods: {
|
|
5
|
+
depositInternal: any;
|
|
6
|
+
withdrawInternal: any;
|
|
7
|
+
}, recoverySetsState: RecoverySetsOption, paymentRecoverySets: WeakMapStore<Payment, SetStore<Payment>>): () => import("@endo/exo").Guarded<{
|
|
2
8
|
deposit(srcPayment: any, optAmountShape?: undefined): any;
|
|
3
9
|
withdraw(amount: any): any;
|
|
4
|
-
getCurrentAmount():
|
|
5
|
-
getCurrentAmountNotifier(): Notifier<any>;
|
|
6
|
-
getAllegedBrand():
|
|
7
|
-
getDepositFacet(): {
|
|
10
|
+
getCurrentAmount(): import("./types.js").NatAmount | import("./types.js").CopySetAmount<import("@endo/patterns").Key> | import("./types.js").CopyBagAmount<import("@endo/patterns").Key> | import("./types.js").SetAmount<import("@endo/patterns").Key>;
|
|
11
|
+
getCurrentAmountNotifier(): import("@agoric/notifier").Notifier<any>;
|
|
12
|
+
getAllegedBrand(): Brand;
|
|
13
|
+
getDepositFacet(): import("@endo/exo").Guarded<{
|
|
8
14
|
receive(...args: any[]): any;
|
|
9
|
-
}
|
|
10
|
-
getRecoverySet(): CopySet<
|
|
11
|
-
recoverAll():
|
|
12
|
-
}
|
|
15
|
+
}>;
|
|
16
|
+
getRecoverySet(): import("@endo/patterns").CopySet<any>;
|
|
17
|
+
recoverAll(): import("./types.js").NatAmount | import("./types.js").CopySetAmount<import("@endo/patterns").Key> | import("./types.js").CopyBagAmount<import("@endo/patterns").Key> | import("./types.js").SetAmount<import("@endo/patterns").Key>;
|
|
18
|
+
}>;
|
|
19
|
+
import type { AssetKind } from './types.js';
|
|
20
|
+
import type { Brand } from './types.js';
|
|
21
|
+
import type { RecoverySetsOption } from './types.js';
|
|
22
|
+
import type { Payment } from './types.js';
|
|
13
23
|
//# sourceMappingURL=purse.d.ts.map
|
package/src/purse.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"purse.d.ts","sourceRoot":"","sources":["purse.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"purse.d.ts","sourceRoot":"","sources":["purse.js"],"names":[],"mappings":"AA2BO,6CAfI,OAAO,cAAc,EAAE,IAAI,QAC3B,MAAM,aACN,SAAS,SACT,KAAK,aACL;IACN,KAAK,EAAE,OAAO,gBAAgB,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC;IACpD,YAAY,EAAE,OAAO,gBAAgB,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC;CAC5D,gBACO;IACN,eAAe,EAAE,GAAG,CAAC;IACrB,gBAAgB,EAAE,GAAG,CAAC;CACvB,qBACO,kBAAkB,uBAClB,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;;;;;;;;;;;GA4JlD;+BA/KgE,YAAY;2BAAZ,YAAY;wCAAZ,YAAY;6BAAZ,YAAY"}
|