@agoric/inter-protocol 0.16.2-other-dev-8f8782b.0 → 0.16.2-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/README.md +6 -6
- package/package.json +46 -39
- package/scripts/build-bundles.js +5 -21
- package/src/auction/auctionBook.d.ts +147 -0
- package/src/auction/auctionBook.d.ts.map +1 -0
- package/src/auction/auctionBook.js +182 -151
- package/src/auction/auctionMath.d.ts +17 -0
- package/src/auction/auctionMath.d.ts.map +1 -0
- package/src/auction/auctionMath.js +81 -0
- package/src/auction/auctioneer.d.ts +70 -0
- package/src/auction/auctioneer.d.ts.map +1 -0
- package/src/auction/auctioneer.js +72 -59
- package/src/auction/offerBook.d.ts +46 -0
- package/src/auction/offerBook.d.ts.map +1 -0
- package/src/auction/offerBook.js +17 -12
- package/src/auction/params.d.ts +145 -0
- package/src/auction/params.d.ts.map +1 -0
- package/src/auction/params.js +11 -9
- package/src/auction/scheduleMath.d.ts +5 -0
- package/src/auction/scheduleMath.d.ts.map +1 -0
- package/src/auction/scheduleMath.js +18 -16
- package/src/auction/scheduler.d.ts +50 -0
- package/src/auction/scheduler.d.ts.map +1 -0
- package/src/auction/scheduler.js +53 -47
- package/src/auction/sortedOffers.d.ts +8 -0
- package/src/auction/sortedOffers.d.ts.map +1 -0
- package/src/auction/sortedOffers.js +10 -9
- package/src/auction/util.d.ts +31 -0
- package/src/auction/util.d.ts.map +1 -0
- package/src/auction/util.js +12 -6
- package/src/clientSupport.d.ts +168 -0
- package/src/clientSupport.d.ts.map +1 -0
- package/src/clientSupport.js +161 -98
- package/src/collectFees.d.ts +2 -0
- package/src/collectFees.d.ts.map +1 -0
- package/src/contractSupport.d.ts +28 -0
- package/src/contractSupport.d.ts.map +1 -0
- package/src/contractSupport.js +19 -13
- package/src/econCommitteeCharter.d.ts +43 -0
- package/src/econCommitteeCharter.d.ts.map +1 -0
- package/src/econCommitteeCharter.js +25 -20
- package/src/feeDistributor.d.ts +224 -0
- package/src/feeDistributor.d.ts.map +1 -0
- package/src/feeDistributor.js +41 -33
- package/src/index.d.ts +2 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +1 -0
- package/src/interest-math.d.ts +4 -0
- package/src/interest-math.d.ts.map +1 -0
- package/src/interest-math.js +5 -1
- package/src/interest.d.ts +30 -0
- package/src/interest.d.ts.map +1 -0
- package/src/interest.js +25 -23
- package/src/price/README.md +14 -1
- package/src/price/fluxAggregatorContract.d.ts +71 -0
- package/src/price/fluxAggregatorContract.d.ts.map +1 -0
- package/src/price/fluxAggregatorContract.js +64 -55
- package/src/price/fluxAggregatorKit.d.ts +104 -0
- package/src/price/fluxAggregatorKit.d.ts.map +1 -0
- package/src/price/fluxAggregatorKit.js +55 -42
- package/src/price/priceOracleKit.d.ts +39 -0
- package/src/price/priceOracleKit.d.ts.map +1 -0
- package/src/price/priceOracleKit.js +17 -15
- package/src/price/roundsManager.d.ts +204 -0
- package/src/price/roundsManager.d.ts.map +1 -0
- package/src/price/roundsManager.js +132 -85
- package/src/proposals/README.md +2 -3
- package/src/proposals/add-auction.js +285 -0
- package/src/proposals/addAssetToVault.js +192 -40
- package/src/proposals/committee-proposal.js +25 -31
- package/src/proposals/core-proposal.js +9 -11
- package/src/proposals/deploy-price-feeds.js +341 -0
- package/src/proposals/econ-behaviors.js +84 -49
- package/src/proposals/price-feed-proposal.js +109 -51
- package/src/proposals/replace-fee-distributor.js +198 -0
- package/src/proposals/replace-scaledPriceAuthorities.js +124 -0
- package/src/proposals/replaceElectorate.js +610 -0
- package/src/proposals/startEconCommittee.js +2 -2
- package/src/proposals/startPSM.js +44 -29
- package/src/proposals/upgrade-scaledPriceAuthorities.js +78 -0
- package/src/proposals/upgrade-vaults.js +207 -0
- package/src/proposals/utils.d.ts +21 -0
- package/src/proposals/utils.d.ts.map +1 -0
- package/src/proposals/utils.js +66 -9
- package/src/proposals/withdraw-reserve-proposal.js +63 -0
- package/src/provisionPool.d.ts +69 -0
- package/src/provisionPool.d.ts.map +1 -0
- package/src/provisionPool.js +138 -0
- package/src/provisionPoolKit.d.ts +129 -0
- package/src/provisionPoolKit.d.ts.map +1 -0
- package/src/provisionPoolKit.js +608 -0
- package/src/psm/psm.d.ts +133 -0
- package/src/psm/psm.d.ts.map +1 -0
- package/src/psm/psm.js +85 -79
- package/src/psm/types-ambient.d.ts +2 -0
- package/src/psm/types-ambient.d.ts.map +1 -0
- package/src/psm/types-ambient.js +3 -0
- package/src/reserve/assetReserve.d.ts +58 -0
- package/src/reserve/assetReserve.d.ts.map +1 -0
- package/src/reserve/assetReserve.js +42 -34
- package/src/reserve/assetReserveKit.d.ts +103 -0
- package/src/reserve/assetReserveKit.d.ts.map +1 -0
- package/src/reserve/assetReserveKit.js +134 -32
- package/src/reserve/params.d.ts +16 -0
- package/src/reserve/params.d.ts.map +1 -0
- package/src/reserve/params.js +8 -2
- package/src/tokens.d.ts +3 -0
- package/src/tokens.d.ts.map +1 -0
- package/src/tokens.js +5 -0
- package/src/vaultFactory/burn.d.ts +2 -0
- package/src/vaultFactory/burn.d.ts.map +1 -0
- package/src/vaultFactory/burn.js +1 -1
- package/src/vaultFactory/liquidation.d.ts +25 -0
- package/src/vaultFactory/liquidation.d.ts.map +1 -0
- package/src/vaultFactory/liquidation.js +37 -24
- package/src/vaultFactory/math.d.ts +11 -0
- package/src/vaultFactory/math.d.ts.map +1 -0
- package/src/vaultFactory/math.js +11 -10
- package/src/vaultFactory/orderedVaultStore.d.ts +94 -0
- package/src/vaultFactory/orderedVaultStore.d.ts.map +1 -0
- package/src/vaultFactory/orderedVaultStore.js +9 -10
- package/src/vaultFactory/params.d.ts +143 -0
- package/src/vaultFactory/params.d.ts.map +1 -0
- package/src/vaultFactory/params.js +56 -25
- package/src/vaultFactory/prioritizedVaults.d.ts +280 -0
- package/src/vaultFactory/prioritizedVaults.d.ts.map +1 -0
- package/src/vaultFactory/prioritizedVaults.js +7 -4
- package/src/vaultFactory/proceeds.d.ts +35 -0
- package/src/vaultFactory/proceeds.d.ts.map +1 -0
- package/src/vaultFactory/proceeds.js +26 -18
- package/src/vaultFactory/storeUtils.d.ts +25 -0
- package/src/vaultFactory/storeUtils.d.ts.map +1 -0
- package/src/vaultFactory/storeUtils.js +10 -12
- package/src/vaultFactory/types-ambient.d.ts +137 -0
- package/src/vaultFactory/types-ambient.d.ts.map +1 -0
- package/src/vaultFactory/{types.js → types-ambient.js} +47 -44
- package/src/vaultFactory/vault.d.ts +344 -0
- package/src/vaultFactory/vault.d.ts.map +1 -0
- package/src/vaultFactory/vault.js +107 -100
- package/src/vaultFactory/vaultDirector.d.ts +347 -0
- package/src/vaultFactory/vaultDirector.d.ts.map +1 -0
- package/src/vaultFactory/vaultDirector.js +94 -64
- package/src/vaultFactory/vaultFactory.d.ts +250 -0
- package/src/vaultFactory/vaultFactory.d.ts.map +1 -0
- package/src/vaultFactory/vaultFactory.js +56 -33
- package/src/vaultFactory/vaultHolder.d.ts +170 -0
- package/src/vaultFactory/vaultHolder.d.ts.map +1 -0
- package/src/vaultFactory/vaultHolder.js +14 -15
- package/src/vaultFactory/vaultKit.d.ts +33 -0
- package/src/vaultFactory/vaultKit.d.ts.map +1 -0
- package/src/vaultFactory/vaultKit.js +9 -4
- package/src/vaultFactory/vaultManager.d.ts +676 -0
- package/src/vaultFactory/vaultManager.d.ts.map +1 -0
- package/src/vaultFactory/vaultManager.js +286 -167
- package/CHANGELOG.md +0 -1041
- package/exported.js +0 -2
- package/scripts/add-collateral-core.js +0 -112
- package/scripts/deploy-contracts.js +0 -100
- package/scripts/init-core.js +0 -198
- package/scripts/invite-committee-core.js +0 -42
- package/scripts/manual-price-feed.js +0 -117
- package/scripts/price-feed-core.js +0 -104
- package/scripts/start-local-chain.sh +0 -84
- package/src/psm/types.js +0 -3
- package/src/typeGuards.js +0 -13
- package/src/vaultFactory/type-imports.js +0 -4
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { q, Fail } from '@endo/errors';
|
|
1
2
|
import { AmountMath, AmountShape } from '@agoric/ertp';
|
|
2
|
-
import {
|
|
3
|
+
import { StorageNodeShape, makeTracer } from '@agoric/internal';
|
|
4
|
+
import { UnguardedHelperI } from '@agoric/internal/src/typeGuards.js';
|
|
3
5
|
import { M, prepareExoClassKit } from '@agoric/vat-data';
|
|
4
6
|
import { atomicTransfer } from '@agoric/zoe/src/contractSupport/index.js';
|
|
5
7
|
import { SeatShape } from '@agoric/zoe/src/typeGuards.js';
|
|
@@ -9,44 +11,50 @@ import {
|
|
|
9
11
|
makeNatAmountShape,
|
|
10
12
|
} from '../contractSupport.js';
|
|
11
13
|
import { calculateCurrentDebt, reverseInterest } from '../interest-math.js';
|
|
12
|
-
import { UnguardedHelperI } from '../typeGuards.js';
|
|
13
|
-
import { prepareVaultKit } from './vaultKit.js';
|
|
14
|
-
|
|
15
|
-
import '@agoric/zoe/exported.js';
|
|
16
14
|
import { calculateDebtCosts } from './math.js';
|
|
17
|
-
|
|
18
|
-
const { quote: q, Fail } = assert;
|
|
15
|
+
import { prepareVaultKit } from './vaultKit.js';
|
|
19
16
|
|
|
20
17
|
const trace = makeTracer('Vault', true);
|
|
21
18
|
|
|
22
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* @import {EReturn} from '@endo/far';
|
|
21
|
+
* @import {Brand} from '@agoric/ertp/src/types.js';
|
|
22
|
+
* @import {NormalizedDebt} from './storeUtils.js';
|
|
23
|
+
*/
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
|
-
* @file This has most of the logic for a Vault, to borrow Minted against
|
|
26
|
+
* @file This has most of the logic for a Vault, to borrow Minted against
|
|
27
|
+
* collateral.
|
|
28
|
+
*
|
|
29
|
+
* The logic here is for Vault which is the majority of logic of vaults but the
|
|
30
|
+
* user view is the `vault` value contained in VaultKit.
|
|
26
31
|
*
|
|
27
|
-
*
|
|
28
|
-
* the user view is the `vault` value contained in VaultKit.
|
|
32
|
+
* A note on naming convention:
|
|
29
33
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
34
|
+
* - `Pre` is used as a postfix for any mutable value retrieved _before_ an
|
|
35
|
+
* `await`, to flag values that must used very carefully after the
|
|
36
|
+
* `await`
|
|
37
|
+
* - `new` is a prefix for values that describe the result of executing a
|
|
38
|
+
* transaction; e.g., `debt` is the value before the txn, and `newDebt`
|
|
39
|
+
* will be value if the txn completes.
|
|
40
|
+
* - the absence of one of these implies the opposite, so `newDebt` is the future
|
|
41
|
+
* value fo `debt`, as computed based on values after any `await`
|
|
38
42
|
*/
|
|
39
43
|
|
|
40
44
|
/**
|
|
41
45
|
* Constants for vault phase.
|
|
42
46
|
*
|
|
43
|
-
* ACTIVE
|
|
44
|
-
* LIQUIDATING
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* TRANSFER
|
|
48
|
-
*
|
|
49
|
-
*
|
|
47
|
+
* - ACTIVE - vault is in use and can be changed
|
|
48
|
+
* - LIQUIDATING - vault is being liquidated by the vault manager, and cannot be
|
|
49
|
+
* changed by the user. If liquidation fails, vaults may remain in this state.
|
|
50
|
+
* An upgrade to the contract might be able to recover them.
|
|
51
|
+
* - TRANSFER - vault is able to be transferred (payments and debits frozen until
|
|
52
|
+
* it has a new owner)
|
|
53
|
+
* - CLOSED - vault was closed by the user and all assets have been paid out
|
|
54
|
+
* - LIQUIDATED - vault was closed by the manager, with remaining assets paid to
|
|
55
|
+
* owner
|
|
56
|
+
*
|
|
57
|
+
* @enum {(typeof Phase)[keyof typeof Phase]}
|
|
50
58
|
*/
|
|
51
59
|
export const Phase = /** @type {const} */ ({
|
|
52
60
|
ACTIVE: 'active',
|
|
@@ -55,10 +63,11 @@ export const Phase = /** @type {const} */ ({
|
|
|
55
63
|
LIQUIDATED: 'liquidated',
|
|
56
64
|
TRANSFER: 'transfer',
|
|
57
65
|
});
|
|
66
|
+
harden(Phase);
|
|
58
67
|
|
|
59
68
|
/**
|
|
60
|
-
* @typedef {
|
|
61
|
-
* @type {{[K in VaultPhase]:
|
|
69
|
+
* @typedef {Exclude<Phase, 'transfer'>} VaultPhase
|
|
70
|
+
* @type {{ [K in VaultPhase]: VaultPhase[] }}
|
|
62
71
|
*/
|
|
63
72
|
const validTransitions = {
|
|
64
73
|
[Phase.ACTIVE]: [Phase.LIQUIDATING, Phase.CLOSED],
|
|
@@ -68,46 +77,54 @@ const validTransitions = {
|
|
|
68
77
|
};
|
|
69
78
|
|
|
70
79
|
/**
|
|
71
|
-
* @typedef {Phase[keyof typeof Phase]} HolderPhase
|
|
72
|
-
*
|
|
73
80
|
* @typedef {object} VaultNotification
|
|
74
81
|
* @property {Amount<'nat'>} locked Amount of Collateral locked
|
|
75
|
-
* @property {{debt: Amount<'nat'
|
|
76
|
-
*
|
|
82
|
+
* @property {{ debt: Amount<'nat'>; interest: Ratio }} debtSnapshot 'debt' at
|
|
83
|
+
* the point the compounded interest was 'interest'
|
|
84
|
+
* @property {Phase} vaultState
|
|
77
85
|
*/
|
|
78
86
|
|
|
79
87
|
// XXX masks typedef from types.js, but using that causes circular def problems
|
|
80
88
|
/**
|
|
81
89
|
* @typedef {object} VaultManager
|
|
82
|
-
* @property {() => Subscriber<import('./vaultManager').AssetState>} getAssetSubscriber
|
|
90
|
+
* @property {() => Subscriber<import('./vaultManager.js').AssetState>} getAssetSubscriber
|
|
83
91
|
* @property {(collateralAmount: Amount) => Amount<'nat'>} maxDebtFor
|
|
84
|
-
* @property {() => Brand} getCollateralBrand
|
|
92
|
+
* @property {() => Brand<'nat'>} getCollateralBrand
|
|
85
93
|
* @property {(base: string) => string} scopeDescription
|
|
86
94
|
* @property {() => Brand<'nat'>} getDebtBrand
|
|
87
95
|
* @property {MintAndTransfer} mintAndTransfer
|
|
88
96
|
* @property {(amount: Amount, seat: ZCFSeat) => void} burn
|
|
89
97
|
* @property {() => Ratio} getCompoundedInterest
|
|
90
|
-
* @property {(
|
|
98
|
+
* @property {(
|
|
99
|
+
* oldDebt: import('./storeUtils.js').NormalizedDebt,
|
|
100
|
+
* oldCollateral: Amount<'nat'>,
|
|
101
|
+
* vaultId: VaultId,
|
|
102
|
+
* vaultPhase: VaultPhase,
|
|
103
|
+
* vault: Vault,
|
|
104
|
+
* ) => void} handleBalanceChange
|
|
91
105
|
* @property {() => import('./vaultManager.js').GovernedParamGetters} getGovernedParams
|
|
92
106
|
*/
|
|
93
107
|
|
|
94
108
|
/**
|
|
95
109
|
* @typedef {Readonly<{
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
110
|
+
* idInManager: VaultId;
|
|
111
|
+
* manager: VaultManager;
|
|
112
|
+
* storageNode: StorageNode;
|
|
113
|
+
* vaultSeat: ZCFSeat;
|
|
100
114
|
* }>} ImmutableState
|
|
101
115
|
*/
|
|
102
116
|
|
|
103
117
|
/**
|
|
104
|
-
* Snapshot is of the debt and compounded interest when the principal was last
|
|
118
|
+
* Snapshot is of the debt and compounded interest when the principal was last
|
|
119
|
+
* changed.
|
|
105
120
|
*
|
|
106
121
|
* @typedef {{
|
|
107
|
-
* interestSnapshot: Ratio
|
|
108
|
-
* phase: VaultPhase
|
|
109
|
-
* debtSnapshot: Amount<'nat'
|
|
110
|
-
* outerUpdater:
|
|
122
|
+
* interestSnapshot: Ratio;
|
|
123
|
+
* phase: VaultPhase;
|
|
124
|
+
* debtSnapshot: Amount<'nat'>;
|
|
125
|
+
* outerUpdater:
|
|
126
|
+
* | import('@agoric/zoe/src/contractSupport/recorder.js').Recorder<VaultNotification>
|
|
127
|
+
* | null;
|
|
111
128
|
* }} MutableState
|
|
112
129
|
*/
|
|
113
130
|
|
|
@@ -137,7 +154,7 @@ const VaultStateShape = harden({
|
|
|
137
154
|
});
|
|
138
155
|
|
|
139
156
|
/**
|
|
140
|
-
* @param {import('@agoric/
|
|
157
|
+
* @param {import('@agoric/swingset-liveslots').Baggage} baggage
|
|
141
158
|
* @param {import('@agoric/zoe/src/contractSupport/recorder.js').MakeRecorderKit} makeRecorderKit
|
|
142
159
|
* @param {ZCF} zcf
|
|
143
160
|
*/
|
|
@@ -195,7 +212,10 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
195
212
|
return AmountMath.makeEmpty(this.facets.helper.debtBrand());
|
|
196
213
|
},
|
|
197
214
|
/**
|
|
198
|
-
* @typedef {{
|
|
215
|
+
* @typedef {{
|
|
216
|
+
* give: { Collateral: Amount<'nat'>; Minted: Amount<'nat'> };
|
|
217
|
+
* want: { Collateral: Amount<'nat'>; Minted: Amount<'nat'> };
|
|
218
|
+
* }} FullProposal
|
|
199
219
|
*/
|
|
200
220
|
/**
|
|
201
221
|
* @param {ProposalRecord} partial
|
|
@@ -220,9 +240,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
220
240
|
//#endregion
|
|
221
241
|
|
|
222
242
|
//#region Phase logic
|
|
223
|
-
/**
|
|
224
|
-
* @param {VaultPhase} newPhase
|
|
225
|
-
*/
|
|
243
|
+
/** @param {VaultPhase} newPhase */
|
|
226
244
|
assignPhase(newPhase) {
|
|
227
245
|
const { state } = this;
|
|
228
246
|
|
|
@@ -261,12 +279,14 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
261
279
|
},
|
|
262
280
|
|
|
263
281
|
/**
|
|
264
|
-
* Update the debt balance and propagate upwards to
|
|
265
|
-
*
|
|
282
|
+
* Update the debt balance and propagate upwards to maintain aggregate
|
|
283
|
+
* debt and liquidation order.
|
|
266
284
|
*
|
|
267
|
-
* @param {NormalizedDebt} oldDebtNormalized - prior principal and all
|
|
285
|
+
* @param {NormalizedDebt} oldDebtNormalized - prior principal and all
|
|
286
|
+
* accrued interest, normalized to the launch of the vaultManager
|
|
268
287
|
* @param {Amount<'nat'>} oldCollateral - actual collateral
|
|
269
|
-
* @param {Amount<'nat'>} newDebtActual - actual principal and all
|
|
288
|
+
* @param {Amount<'nat'>} newDebtActual - actual principal and all
|
|
289
|
+
* accrued interest
|
|
270
290
|
*/
|
|
271
291
|
updateDebtAccounting(oldDebtNormalized, oldCollateral, newDebtActual) {
|
|
272
292
|
const { state, facets } = this;
|
|
@@ -283,8 +303,8 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
283
303
|
},
|
|
284
304
|
|
|
285
305
|
/**
|
|
286
|
-
*
|
|
287
306
|
* @param {ZCFSeat} seat
|
|
307
|
+
* @returns {Amount<'nat'>}
|
|
288
308
|
*/
|
|
289
309
|
getCollateralAllocated(seat) {
|
|
290
310
|
return seat.getAmountAllocated(
|
|
@@ -292,6 +312,10 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
292
312
|
this.facets.helper.collateralBrand(),
|
|
293
313
|
);
|
|
294
314
|
},
|
|
315
|
+
/**
|
|
316
|
+
* @param {ZCFSeat} seat
|
|
317
|
+
* @returns {Amount<'nat'>}
|
|
318
|
+
*/
|
|
295
319
|
getMintedAllocated(seat) {
|
|
296
320
|
return seat.getAmountAllocated(
|
|
297
321
|
'Minted',
|
|
@@ -307,7 +331,6 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
307
331
|
},
|
|
308
332
|
|
|
309
333
|
/**
|
|
310
|
-
*
|
|
311
334
|
* @param {Amount<'nat'>} collateralAmount
|
|
312
335
|
* @param {Amount<'nat'>} proposedDebt
|
|
313
336
|
*/
|
|
@@ -320,10 +343,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
320
343
|
)} for ${q(collateralAmount)} collateral`;
|
|
321
344
|
},
|
|
322
345
|
|
|
323
|
-
/**
|
|
324
|
-
*
|
|
325
|
-
* @param {HolderPhase} newPhase
|
|
326
|
-
*/
|
|
346
|
+
/** @param {Phase} newPhase */
|
|
327
347
|
getStateSnapshot(newPhase) {
|
|
328
348
|
const { state, facets } = this;
|
|
329
349
|
|
|
@@ -338,9 +358,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
338
358
|
});
|
|
339
359
|
},
|
|
340
360
|
|
|
341
|
-
/**
|
|
342
|
-
* call this whenever anything changes!
|
|
343
|
-
*/
|
|
361
|
+
/** call this whenever anything changes! */
|
|
344
362
|
updateUiState() {
|
|
345
363
|
const { state, facets } = this;
|
|
346
364
|
const { outerUpdater } = state;
|
|
@@ -368,9 +386,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
368
386
|
}
|
|
369
387
|
},
|
|
370
388
|
|
|
371
|
-
/**
|
|
372
|
-
* @param {ZCFSeat} seat
|
|
373
|
-
*/
|
|
389
|
+
/** @param {ZCFSeat} seat */
|
|
374
390
|
async closeHook(seat) {
|
|
375
391
|
const { state, facets } = this;
|
|
376
392
|
|
|
@@ -440,11 +456,11 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
440
456
|
},
|
|
441
457
|
|
|
442
458
|
/**
|
|
443
|
-
* Calculate the fee, the amount to mint and the resulting debt.
|
|
444
|
-
*
|
|
445
|
-
*
|
|
446
|
-
*
|
|
447
|
-
*
|
|
459
|
+
* Calculate the fee, the amount to mint and the resulting debt. The
|
|
460
|
+
* give and the want together reflect a delta, where typically one is
|
|
461
|
+
* zero because they come from the gave/want of an offer proposal. If
|
|
462
|
+
* the `want` is zero, the `fee` will also be zero, so the simple math
|
|
463
|
+
* works.
|
|
448
464
|
*
|
|
449
465
|
* @param {Amount<'nat'>} currentDebt
|
|
450
466
|
* @param {Amount<'nat'>} giveAmount
|
|
@@ -522,7 +538,6 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
522
538
|
},
|
|
523
539
|
|
|
524
540
|
/**
|
|
525
|
-
*
|
|
526
541
|
* @param {ZCFSeat} clientSeat
|
|
527
542
|
* @param {FullProposal} fp
|
|
528
543
|
* @param {ReturnType<typeof calculateDebtCosts>} costs
|
|
@@ -543,7 +558,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
543
558
|
|
|
544
559
|
const giveMintedTaken = AmountMath.subtract(fp.give.Minted, surplus);
|
|
545
560
|
|
|
546
|
-
/** @type {
|
|
561
|
+
/** @type {TransferPart[]} */
|
|
547
562
|
const transfers = harden([
|
|
548
563
|
[clientSeat, vaultSeat, { Collateral: fp.give.Collateral }],
|
|
549
564
|
[vaultSeat, clientSeat, { Collateral: fp.want.Collateral }],
|
|
@@ -568,7 +583,6 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
568
583
|
},
|
|
569
584
|
|
|
570
585
|
/**
|
|
571
|
-
*
|
|
572
586
|
* @param {ZCFSeat} seat
|
|
573
587
|
* @returns {VaultKit}
|
|
574
588
|
*/
|
|
@@ -579,7 +593,6 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
579
593
|
helper.assertCloseable();
|
|
580
594
|
seat.exit();
|
|
581
595
|
|
|
582
|
-
// eslint-disable-next-line no-use-before-define
|
|
583
596
|
const vaultKit = makeVaultKit(self, state.storageNode);
|
|
584
597
|
state.outerUpdater = vaultKit.vaultUpdater;
|
|
585
598
|
helper.updateUiState();
|
|
@@ -669,9 +682,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
669
682
|
return vaultKit;
|
|
670
683
|
},
|
|
671
684
|
|
|
672
|
-
/**
|
|
673
|
-
* Called by manager at start of liquidation.
|
|
674
|
-
*/
|
|
685
|
+
/** Called by manager at start of liquidation. */
|
|
675
686
|
liquidating() {
|
|
676
687
|
const { facets } = this;
|
|
677
688
|
|
|
@@ -681,8 +692,8 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
681
692
|
},
|
|
682
693
|
|
|
683
694
|
/**
|
|
684
|
-
* Called by manager at end of liquidation, at which point all debts
|
|
685
|
-
* covered.
|
|
695
|
+
* Called by manager at end of liquidation, at which point all debts
|
|
696
|
+
* have been covered.
|
|
686
697
|
*/
|
|
687
698
|
liquidated() {
|
|
688
699
|
const { facets } = this;
|
|
@@ -774,9 +785,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
774
785
|
);
|
|
775
786
|
},
|
|
776
787
|
|
|
777
|
-
/**
|
|
778
|
-
* @returns {Promise<Invitation>}
|
|
779
|
-
*/
|
|
788
|
+
/** @returns {Promise<Invitation<VaultKit>>} */
|
|
780
789
|
makeTransferInvitation() {
|
|
781
790
|
const { state, facets } = this;
|
|
782
791
|
const { outerUpdater } = state;
|
|
@@ -808,10 +817,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
808
817
|
|
|
809
818
|
// for status/debugging
|
|
810
819
|
|
|
811
|
-
/**
|
|
812
|
-
*
|
|
813
|
-
* @returns {Amount<'nat'>}
|
|
814
|
-
*/
|
|
820
|
+
/** @returns {Amount<'nat'>} */
|
|
815
821
|
getCollateralAmount() {
|
|
816
822
|
const { state, facets } = this;
|
|
817
823
|
const { vaultSeat } = state;
|
|
@@ -825,15 +831,15 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
825
831
|
/**
|
|
826
832
|
* The actual current debt, including accrued interest.
|
|
827
833
|
*
|
|
828
|
-
* This looks like a simple getter but it does a lot of the heavy
|
|
829
|
-
* interest accrual. Rather than updating all records when
|
|
830
|
-
* the vault manager updates just its rolling
|
|
831
|
-
* calculate what the current debt is given
|
|
832
|
-
* what
|
|
833
|
-
*
|
|
834
|
-
* @see getNormalizedDebt
|
|
834
|
+
* This looks like a simple getter but it does a lot of the heavy
|
|
835
|
+
* lifting for interest accrual. Rather than updating all records when
|
|
836
|
+
* interest accrues, the vault manager updates just its rolling
|
|
837
|
+
* compounded interest. Here we calculate what the current debt is given
|
|
838
|
+
* what's recorded in this vault and what interest has compounded since
|
|
839
|
+
* this vault record was written.
|
|
835
840
|
*
|
|
836
841
|
* @returns {Amount<'nat'>}
|
|
842
|
+
* @see getNormalizedDebt
|
|
837
843
|
*/
|
|
838
844
|
getCurrentDebt() {
|
|
839
845
|
const { state } = this;
|
|
@@ -845,14 +851,15 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
845
851
|
},
|
|
846
852
|
|
|
847
853
|
/**
|
|
848
|
-
* The normalization puts all debts on a common time-independent scale
|
|
849
|
-
* the launch of this vault manager. This allows the manager to
|
|
850
|
-
* by their debt-to-collateral ratios without having to
|
|
851
|
-
* the interest accrues.
|
|
854
|
+
* The normalization puts all debts on a common time-independent scale
|
|
855
|
+
* since the launch of this vault manager. This allows the manager to
|
|
856
|
+
* order vaults by their debt-to-collateral ratios without having to
|
|
857
|
+
* mutate the debts as the interest accrues.
|
|
852
858
|
*
|
|
859
|
+
* @returns {import('./storeUtils.js').NormalizedDebt} as if the vault
|
|
860
|
+
* was open at the launch of this manager, before any interest
|
|
861
|
+
* accrued
|
|
853
862
|
* @see getActualDebAmount
|
|
854
|
-
*
|
|
855
|
-
* @returns {import('./storeUtils.js').NormalizedDebt} as if the vault was open at the launch of this manager, before any interest accrued
|
|
856
863
|
*/
|
|
857
864
|
getNormalizedDebt() {
|
|
858
865
|
const { state } = this;
|
|
@@ -868,4 +875,4 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
868
875
|
return maker;
|
|
869
876
|
};
|
|
870
877
|
|
|
871
|
-
/** @typedef {
|
|
878
|
+
/** @typedef {EReturn<EReturn<typeof prepareVault>>['self']} Vault */
|