@agoric/inter-protocol 0.16.2-dev-ecf2d8e.0 → 0.16.2-other-dev-70beeb7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1041 -0
- package/package.json +30 -33
- package/scripts/add-collateral-core.js +112 -0
- package/scripts/build-bundles.js +21 -5
- package/scripts/deploy-contracts.js +100 -0
- package/scripts/init-core.js +198 -0
- package/scripts/invite-committee-core.js +42 -0
- package/scripts/manual-price-feed.js +117 -0
- package/scripts/price-feed-core.js +104 -0
- package/scripts/start-local-chain.sh +84 -0
- package/src/auction/auctionBook.js +59 -74
- package/src/auction/auctioneer.js +44 -56
- package/src/auction/offerBook.js +11 -12
- package/src/auction/params.js +5 -3
- package/src/auction/scheduleMath.js +13 -13
- package/src/auction/scheduler.js +32 -32
- package/src/auction/sortedOffers.js +7 -8
- package/src/auction/util.js +4 -4
- package/src/clientSupport.js +96 -152
- package/src/contractSupport.js +5 -5
- package/src/econCommitteeCharter.js +17 -18
- package/src/feeDistributor.js +33 -34
- package/src/interest.js +14 -20
- package/src/price/fluxAggregatorContract.js +45 -51
- package/src/price/fluxAggregatorKit.js +33 -48
- package/src/price/priceOracleKit.js +13 -11
- package/src/price/roundsManager.js +64 -52
- package/src/proposals/addAssetToVault.js +6 -15
- package/src/proposals/committee-proposal.js +27 -21
- package/src/proposals/core-proposal.js +7 -7
- package/src/proposals/econ-behaviors.js +32 -57
- package/src/proposals/price-feed-proposal.js +34 -66
- package/src/proposals/startEconCommittee.js +1 -1
- package/src/proposals/startPSM.js +22 -32
- package/src/proposals/utils.js +7 -26
- package/src/psm/psm.js +63 -69
- package/src/reserve/assetReserve.js +18 -27
- package/src/reserve/assetReserveKit.js +22 -14
- package/src/typeGuards.js +13 -0
- package/src/vaultFactory/liquidation.js +17 -30
- package/src/vaultFactory/math.js +9 -8
- package/src/vaultFactory/orderedVaultStore.js +9 -6
- package/src/vaultFactory/params.js +18 -24
- package/src/vaultFactory/prioritizedVaults.js +2 -2
- package/src/vaultFactory/proceeds.js +18 -24
- package/src/vaultFactory/storeUtils.js +12 -8
- package/src/vaultFactory/types.js +28 -38
- package/src/vaultFactory/vault.js +89 -88
- package/src/vaultFactory/vaultDirector.js +44 -35
- package/src/vaultFactory/vaultFactory.js +26 -33
- package/src/vaultFactory/vaultHolder.js +13 -8
- package/src/vaultFactory/vaultKit.js +2 -3
- package/src/vaultFactory/vaultManager.js +120 -138
- package/src/auction/auctionBook.d.ts +0 -83
- package/src/auction/auctionBook.d.ts.map +0 -1
- package/src/auction/auctioneer.d.ts +0 -75
- package/src/auction/auctioneer.d.ts.map +0 -1
- package/src/auction/offerBook.d.ts +0 -72
- package/src/auction/offerBook.d.ts.map +0 -1
- package/src/auction/params.d.ts +0 -142
- package/src/auction/params.d.ts.map +0 -1
- package/src/auction/scheduleMath.d.ts +0 -4
- package/src/auction/scheduleMath.d.ts.map +0 -1
- package/src/auction/scheduler.d.ts +0 -49
- package/src/auction/scheduler.d.ts.map +0 -1
- package/src/auction/sortedOffers.d.ts +0 -8
- package/src/auction/sortedOffers.d.ts.map +0 -1
- package/src/auction/util.d.ts +0 -30
- package/src/auction/util.d.ts.map +0 -1
- package/src/clientSupport.d.ts +0 -167
- package/src/clientSupport.d.ts.map +0 -1
- package/src/collectFees.d.ts +0 -2
- package/src/collectFees.d.ts.map +0 -1
- package/src/contractSupport.d.ts +0 -33
- package/src/contractSupport.d.ts.map +0 -1
- package/src/econCommitteeCharter.d.ts +0 -41
- package/src/econCommitteeCharter.d.ts.map +0 -1
- package/src/feeDistributor.d.ts +0 -212
- package/src/feeDistributor.d.ts.map +0 -1
- package/src/index.d.ts +0 -2
- package/src/index.d.ts.map +0 -1
- package/src/interest-math.d.ts +0 -3
- package/src/interest-math.d.ts.map +0 -1
- package/src/interest.d.ts +0 -29
- package/src/interest.d.ts.map +0 -1
- package/src/price/fluxAggregatorContract.d.ts +0 -112
- package/src/price/fluxAggregatorContract.d.ts.map +0 -1
- package/src/price/fluxAggregatorKit.d.ts +0 -155
- package/src/price/fluxAggregatorKit.d.ts.map +0 -1
- package/src/price/priceOracleKit.d.ts +0 -52
- package/src/price/priceOracleKit.d.ts.map +0 -1
- package/src/price/roundsManager.d.ts +0 -330
- package/src/price/roundsManager.d.ts.map +0 -1
- package/src/proposals/addAssetToVault.d.ts +0 -143
- package/src/proposals/addAssetToVault.d.ts.map +0 -1
- package/src/proposals/committee-proposal.d.ts +0 -113
- package/src/proposals/committee-proposal.d.ts.map +0 -1
- package/src/proposals/core-proposal.d.ts +0 -149
- package/src/proposals/core-proposal.d.ts.map +0 -1
- package/src/proposals/econ-behaviors.d.ts +0 -201
- package/src/proposals/econ-behaviors.d.ts.map +0 -1
- package/src/proposals/price-feed-proposal.d.ts +0 -82
- package/src/proposals/price-feed-proposal.d.ts.map +0 -1
- package/src/proposals/startEconCommittee.d.ts +0 -34
- package/src/proposals/startEconCommittee.d.ts.map +0 -1
- package/src/proposals/startPSM.d.ts +0 -61
- package/src/proposals/startPSM.d.ts.map +0 -1
- package/src/proposals/utils.d.ts +0 -15
- package/src/proposals/utils.d.ts.map +0 -1
- package/src/provisionPool.d.ts +0 -165
- package/src/provisionPool.d.ts.map +0 -1
- package/src/provisionPool.js +0 -119
- package/src/provisionPoolKit.d.ts +0 -379
- package/src/provisionPoolKit.d.ts.map +0 -1
- package/src/provisionPoolKit.js +0 -461
- package/src/psm/psm.d.ts +0 -178
- package/src/psm/psm.d.ts.map +0 -1
- package/src/psm/types.d.ts +0 -2
- package/src/psm/types.d.ts.map +0 -1
- package/src/reserve/assetReserve.d.ts +0 -44
- package/src/reserve/assetReserve.d.ts.map +0 -1
- package/src/reserve/assetReserveKit.d.ts +0 -114
- package/src/reserve/assetReserveKit.d.ts.map +0 -1
- package/src/reserve/params.d.ts +0 -10
- package/src/reserve/params.d.ts.map +0 -1
- package/src/tokens.d.ts +0 -3
- package/src/tokens.d.ts.map +0 -1
- package/src/tokens.js +0 -5
- package/src/vaultFactory/burn.d.ts +0 -2
- package/src/vaultFactory/burn.d.ts.map +0 -1
- package/src/vaultFactory/liquidation.d.ts +0 -24
- package/src/vaultFactory/liquidation.d.ts.map +0 -1
- package/src/vaultFactory/math.d.ts +0 -10
- package/src/vaultFactory/math.d.ts.map +0 -1
- package/src/vaultFactory/orderedVaultStore.d.ts +0 -94
- package/src/vaultFactory/orderedVaultStore.d.ts.map +0 -1
- package/src/vaultFactory/params.d.ts +0 -159
- package/src/vaultFactory/params.d.ts.map +0 -1
- package/src/vaultFactory/prioritizedVaults.d.ts +0 -279
- package/src/vaultFactory/prioritizedVaults.d.ts.map +0 -1
- package/src/vaultFactory/proceeds.d.ts +0 -34
- package/src/vaultFactory/proceeds.d.ts.map +0 -1
- package/src/vaultFactory/storeUtils.d.ts +0 -25
- package/src/vaultFactory/storeUtils.d.ts.map +0 -1
- package/src/vaultFactory/type-imports.d.ts +0 -2
- package/src/vaultFactory/type-imports.d.ts.map +0 -1
- package/src/vaultFactory/types.d.ts +0 -137
- package/src/vaultFactory/types.d.ts.map +0 -1
- package/src/vaultFactory/vault.d.ts +0 -529
- package/src/vaultFactory/vault.d.ts.map +0 -1
- package/src/vaultFactory/vaultDirector.d.ts +0 -560
- package/src/vaultFactory/vaultDirector.d.ts.map +0 -1
- package/src/vaultFactory/vaultFactory.d.ts +0 -162
- package/src/vaultFactory/vaultFactory.d.ts.map +0 -1
- package/src/vaultFactory/vaultHolder.d.ts +0 -201
- package/src/vaultFactory/vaultHolder.d.ts.map +0 -1
- package/src/vaultFactory/vaultKit.d.ts +0 -32
- package/src/vaultFactory/vaultKit.d.ts.map +0 -1
- package/src/vaultFactory/vaultManager.d.ts +0 -554
- package/src/vaultFactory/vaultManager.d.ts.map +0 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AmountMath, AmountShape } from '@agoric/ertp';
|
|
2
|
-
import {
|
|
3
|
-
import { UnguardedHelperI } from '@agoric/internal/src/typeGuards.js';
|
|
2
|
+
import { makeTracer, StorageNodeShape } from '@agoric/internal';
|
|
4
3
|
import { M, prepareExoClassKit } from '@agoric/vat-data';
|
|
5
4
|
import { atomicTransfer } from '@agoric/zoe/src/contractSupport/index.js';
|
|
6
5
|
import { SeatShape } from '@agoric/zoe/src/typeGuards.js';
|
|
@@ -10,10 +9,11 @@ import {
|
|
|
10
9
|
makeNatAmountShape,
|
|
11
10
|
} from '../contractSupport.js';
|
|
12
11
|
import { calculateCurrentDebt, reverseInterest } from '../interest-math.js';
|
|
13
|
-
import {
|
|
12
|
+
import { UnguardedHelperI } from '../typeGuards.js';
|
|
14
13
|
import { prepareVaultKit } from './vaultKit.js';
|
|
15
14
|
|
|
16
15
|
import '@agoric/zoe/exported.js';
|
|
16
|
+
import { calculateDebtCosts } from './math.js';
|
|
17
17
|
|
|
18
18
|
const { quote: q, Fail } = assert;
|
|
19
19
|
|
|
@@ -22,36 +22,31 @@ const trace = makeTracer('Vault', true);
|
|
|
22
22
|
/** @typedef {import('./storeUtils.js').NormalizedDebt} NormalizedDebt */
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* @file This has most of the logic for a Vault, to borrow Minted against
|
|
26
|
-
* collateral.
|
|
25
|
+
* @file This has most of the logic for a Vault, to borrow Minted against collateral.
|
|
27
26
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
27
|
+
* The logic here is for Vault which is the majority of logic of vaults but
|
|
28
|
+
* the user view is the `vault` value contained in VaultKit.
|
|
30
29
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* - the absence of one of these implies the opposite, so `newDebt` is the future
|
|
40
|
-
* value fo `debt`, as computed based on values after any `await`
|
|
30
|
+
* A note on naming convention:
|
|
31
|
+
* - `Pre` is used as a postfix for any mutable value retrieved *before* an
|
|
32
|
+
* `await`, to flag values that must used very carefully after the `await`
|
|
33
|
+
* - `new` is a prefix for values that describe the result of executing a
|
|
34
|
+
* transaction; e.g., `debt` is the value before the txn, and `newDebt`
|
|
35
|
+
* will be value if the txn completes.
|
|
36
|
+
* - the absence of one of these implies the opposite, so `newDebt` is the
|
|
37
|
+
* future value fo `debt`, as computed based on values after any `await`
|
|
41
38
|
*/
|
|
42
39
|
|
|
43
40
|
/**
|
|
44
41
|
* Constants for vault phase.
|
|
45
42
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* -
|
|
53
|
-
* - LIQUIDATED - vault was closed by the manager, with remaining assets paid to
|
|
54
|
-
* owner
|
|
43
|
+
* ACTIVE - vault is in use and can be changed
|
|
44
|
+
* LIQUIDATING - vault is being liquidated by the vault manager, and cannot be changed by the user.
|
|
45
|
+
* If liquidation fails, vaults may remain in this state. An upgrade to the contract
|
|
46
|
+
* might be able to recover them.
|
|
47
|
+
* TRANSFER - vault is able to be transferred (payments and debits frozen until it has a new owner)
|
|
48
|
+
* CLOSED - vault was closed by the user and all assets have been paid out
|
|
49
|
+
* LIQUIDATED - vault was closed by the manager, with remaining assets paid to owner
|
|
55
50
|
*/
|
|
56
51
|
export const Phase = /** @type {const} */ ({
|
|
57
52
|
ACTIVE: 'active',
|
|
@@ -63,7 +58,7 @@ export const Phase = /** @type {const} */ ({
|
|
|
63
58
|
|
|
64
59
|
/**
|
|
65
60
|
* @typedef {Phase[keyof Omit<typeof Phase, 'TRANSFER'>]} VaultPhase
|
|
66
|
-
* @type {{
|
|
61
|
+
* @type {{[K in VaultPhase]: Array<VaultPhase>}}
|
|
67
62
|
*/
|
|
68
63
|
const validTransitions = {
|
|
69
64
|
[Phase.ACTIVE]: [Phase.LIQUIDATING, Phase.CLOSED],
|
|
@@ -77,8 +72,7 @@ const validTransitions = {
|
|
|
77
72
|
*
|
|
78
73
|
* @typedef {object} VaultNotification
|
|
79
74
|
* @property {Amount<'nat'>} locked Amount of Collateral locked
|
|
80
|
-
* @property {{
|
|
81
|
-
* the point the compounded interest was 'interest'
|
|
75
|
+
* @property {{debt: Amount<'nat'>, interest: Ratio}} debtSnapshot 'debt' at the point the compounded interest was 'interest'
|
|
82
76
|
* @property {HolderPhase} vaultState
|
|
83
77
|
*/
|
|
84
78
|
|
|
@@ -93,36 +87,27 @@ const validTransitions = {
|
|
|
93
87
|
* @property {MintAndTransfer} mintAndTransfer
|
|
94
88
|
* @property {(amount: Amount, seat: ZCFSeat) => void} burn
|
|
95
89
|
* @property {() => Ratio} getCompoundedInterest
|
|
96
|
-
* @property {(
|
|
97
|
-
* oldDebt: import('./storeUtils.js').NormalizedDebt,
|
|
98
|
-
* oldCollateral: Amount<'nat'>,
|
|
99
|
-
* vaultId: VaultId,
|
|
100
|
-
* vaultPhase: VaultPhase,
|
|
101
|
-
* vault: Vault,
|
|
102
|
-
* ) => void} handleBalanceChange
|
|
90
|
+
* @property {(oldDebt: import('./storeUtils.js').NormalizedDebt, oldCollateral: Amount<'nat'>, vaultId: VaultId, vaultPhase: VaultPhase, vault: Vault) => void} handleBalanceChange
|
|
103
91
|
* @property {() => import('./vaultManager.js').GovernedParamGetters} getGovernedParams
|
|
104
92
|
*/
|
|
105
93
|
|
|
106
94
|
/**
|
|
107
95
|
* @typedef {Readonly<{
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
96
|
+
* idInManager: VaultId,
|
|
97
|
+
* manager: VaultManager,
|
|
98
|
+
* storageNode: StorageNode,
|
|
99
|
+
* vaultSeat: ZCFSeat,
|
|
112
100
|
* }>} ImmutableState
|
|
113
101
|
*/
|
|
114
102
|
|
|
115
103
|
/**
|
|
116
|
-
* Snapshot is of the debt and compounded interest when the principal was last
|
|
117
|
-
* changed.
|
|
104
|
+
* Snapshot is of the debt and compounded interest when the principal was last changed.
|
|
118
105
|
*
|
|
119
106
|
* @typedef {{
|
|
120
|
-
* interestSnapshot: Ratio
|
|
121
|
-
* phase: VaultPhase
|
|
122
|
-
* debtSnapshot: Amount<'nat'
|
|
123
|
-
* outerUpdater:
|
|
124
|
-
* | import('@agoric/zoe/src/contractSupport/recorder.js').Recorder<VaultNotification>
|
|
125
|
-
* | null;
|
|
107
|
+
* interestSnapshot: Ratio,
|
|
108
|
+
* phase: VaultPhase,
|
|
109
|
+
* debtSnapshot: Amount<'nat'>,
|
|
110
|
+
* outerUpdater: import('@agoric/zoe/src/contractSupport/recorder.js').Recorder<VaultNotification> | null,
|
|
126
111
|
* }} MutableState
|
|
127
112
|
*/
|
|
128
113
|
|
|
@@ -210,10 +195,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
210
195
|
return AmountMath.makeEmpty(this.facets.helper.debtBrand());
|
|
211
196
|
},
|
|
212
197
|
/**
|
|
213
|
-
* @typedef {{
|
|
214
|
-
* give: { Collateral: Amount<'nat'>; Minted: Amount<'nat'> };
|
|
215
|
-
* want: { Collateral: Amount<'nat'>; Minted: Amount<'nat'> };
|
|
216
|
-
* }} FullProposal
|
|
198
|
+
* @typedef {{ give: { Collateral: Amount<'nat'>, Minted: Amount<'nat'> }, want: { Collateral: Amount<'nat'>, Minted: Amount<'nat'> } }} FullProposal
|
|
217
199
|
*/
|
|
218
200
|
/**
|
|
219
201
|
* @param {ProposalRecord} partial
|
|
@@ -238,7 +220,9 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
238
220
|
//#endregion
|
|
239
221
|
|
|
240
222
|
//#region Phase logic
|
|
241
|
-
/**
|
|
223
|
+
/**
|
|
224
|
+
* @param {VaultPhase} newPhase
|
|
225
|
+
*/
|
|
242
226
|
assignPhase(newPhase) {
|
|
243
227
|
const { state } = this;
|
|
244
228
|
|
|
@@ -277,14 +261,12 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
277
261
|
},
|
|
278
262
|
|
|
279
263
|
/**
|
|
280
|
-
* Update the debt balance and propagate upwards to
|
|
281
|
-
* debt and liquidation order.
|
|
264
|
+
* Update the debt balance and propagate upwards to
|
|
265
|
+
* maintain aggregate debt and liquidation order.
|
|
282
266
|
*
|
|
283
|
-
* @param {NormalizedDebt} oldDebtNormalized - prior principal and all
|
|
284
|
-
* accrued interest, normalized to the launch of the vaultManager
|
|
267
|
+
* @param {NormalizedDebt} oldDebtNormalized - prior principal and all accrued interest, normalized to the launch of the vaultManager
|
|
285
268
|
* @param {Amount<'nat'>} oldCollateral - actual collateral
|
|
286
|
-
* @param {Amount<'nat'>} newDebtActual - actual principal and all
|
|
287
|
-
* accrued interest
|
|
269
|
+
* @param {Amount<'nat'>} newDebtActual - actual principal and all accrued interest
|
|
288
270
|
*/
|
|
289
271
|
updateDebtAccounting(oldDebtNormalized, oldCollateral, newDebtActual) {
|
|
290
272
|
const { state, facets } = this;
|
|
@@ -300,7 +282,10 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
300
282
|
);
|
|
301
283
|
},
|
|
302
284
|
|
|
303
|
-
/**
|
|
285
|
+
/**
|
|
286
|
+
*
|
|
287
|
+
* @param {ZCFSeat} seat
|
|
288
|
+
*/
|
|
304
289
|
getCollateralAllocated(seat) {
|
|
305
290
|
return seat.getAmountAllocated(
|
|
306
291
|
'Collateral',
|
|
@@ -322,6 +307,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
322
307
|
},
|
|
323
308
|
|
|
324
309
|
/**
|
|
310
|
+
*
|
|
325
311
|
* @param {Amount<'nat'>} collateralAmount
|
|
326
312
|
* @param {Amount<'nat'>} proposedDebt
|
|
327
313
|
*/
|
|
@@ -334,7 +320,10 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
334
320
|
)} for ${q(collateralAmount)} collateral`;
|
|
335
321
|
},
|
|
336
322
|
|
|
337
|
-
/**
|
|
323
|
+
/**
|
|
324
|
+
*
|
|
325
|
+
* @param {HolderPhase} newPhase
|
|
326
|
+
*/
|
|
338
327
|
getStateSnapshot(newPhase) {
|
|
339
328
|
const { state, facets } = this;
|
|
340
329
|
|
|
@@ -349,7 +338,9 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
349
338
|
});
|
|
350
339
|
},
|
|
351
340
|
|
|
352
|
-
/**
|
|
341
|
+
/**
|
|
342
|
+
* call this whenever anything changes!
|
|
343
|
+
*/
|
|
353
344
|
updateUiState() {
|
|
354
345
|
const { state, facets } = this;
|
|
355
346
|
const { outerUpdater } = state;
|
|
@@ -377,7 +368,9 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
377
368
|
}
|
|
378
369
|
},
|
|
379
370
|
|
|
380
|
-
/**
|
|
371
|
+
/**
|
|
372
|
+
* @param {ZCFSeat} seat
|
|
373
|
+
*/
|
|
381
374
|
async closeHook(seat) {
|
|
382
375
|
const { state, facets } = this;
|
|
383
376
|
|
|
@@ -447,11 +440,11 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
447
440
|
},
|
|
448
441
|
|
|
449
442
|
/**
|
|
450
|
-
* Calculate the fee, the amount to mint and the resulting debt.
|
|
451
|
-
* give and the want together reflect a delta, where typically
|
|
452
|
-
* zero because they come from the gave/want of an offer
|
|
453
|
-
* the `want` is zero, the `fee` will also be zero,
|
|
454
|
-
* works.
|
|
443
|
+
* Calculate the fee, the amount to mint and the resulting debt.
|
|
444
|
+
* The give and the want together reflect a delta, where typically
|
|
445
|
+
* one is zero because they come from the gave/want of an offer
|
|
446
|
+
* proposal. If the `want` is zero, the `fee` will also be zero,
|
|
447
|
+
* so the simple math works.
|
|
455
448
|
*
|
|
456
449
|
* @param {Amount<'nat'>} currentDebt
|
|
457
450
|
* @param {Amount<'nat'>} giveAmount
|
|
@@ -529,6 +522,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
529
522
|
},
|
|
530
523
|
|
|
531
524
|
/**
|
|
525
|
+
*
|
|
532
526
|
* @param {ZCFSeat} clientSeat
|
|
533
527
|
* @param {FullProposal} fp
|
|
534
528
|
* @param {ReturnType<typeof calculateDebtCosts>} costs
|
|
@@ -549,7 +543,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
549
543
|
|
|
550
544
|
const giveMintedTaken = AmountMath.subtract(fp.give.Minted, surplus);
|
|
551
545
|
|
|
552
|
-
/** @type {TransferPart[]} */
|
|
546
|
+
/** @type {import('@agoric/zoe/src/contractSupport/atomicTransfer.js').TransferPart[]} */
|
|
553
547
|
const transfers = harden([
|
|
554
548
|
[clientSeat, vaultSeat, { Collateral: fp.give.Collateral }],
|
|
555
549
|
[vaultSeat, clientSeat, { Collateral: fp.want.Collateral }],
|
|
@@ -574,6 +568,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
574
568
|
},
|
|
575
569
|
|
|
576
570
|
/**
|
|
571
|
+
*
|
|
577
572
|
* @param {ZCFSeat} seat
|
|
578
573
|
* @returns {VaultKit}
|
|
579
574
|
*/
|
|
@@ -674,7 +669,9 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
674
669
|
return vaultKit;
|
|
675
670
|
},
|
|
676
671
|
|
|
677
|
-
/**
|
|
672
|
+
/**
|
|
673
|
+
* Called by manager at start of liquidation.
|
|
674
|
+
*/
|
|
678
675
|
liquidating() {
|
|
679
676
|
const { facets } = this;
|
|
680
677
|
|
|
@@ -684,8 +681,8 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
684
681
|
},
|
|
685
682
|
|
|
686
683
|
/**
|
|
687
|
-
* Called by manager at end of liquidation, at which point all debts
|
|
688
|
-
*
|
|
684
|
+
* Called by manager at end of liquidation, at which point all debts have been
|
|
685
|
+
* covered.
|
|
689
686
|
*/
|
|
690
687
|
liquidated() {
|
|
691
688
|
const { facets } = this;
|
|
@@ -777,7 +774,9 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
777
774
|
);
|
|
778
775
|
},
|
|
779
776
|
|
|
780
|
-
/**
|
|
777
|
+
/**
|
|
778
|
+
* @returns {Promise<Invitation>}
|
|
779
|
+
*/
|
|
781
780
|
makeTransferInvitation() {
|
|
782
781
|
const { state, facets } = this;
|
|
783
782
|
const { outerUpdater } = state;
|
|
@@ -809,7 +808,10 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
809
808
|
|
|
810
809
|
// for status/debugging
|
|
811
810
|
|
|
812
|
-
/**
|
|
811
|
+
/**
|
|
812
|
+
*
|
|
813
|
+
* @returns {Amount<'nat'>}
|
|
814
|
+
*/
|
|
813
815
|
getCollateralAmount() {
|
|
814
816
|
const { state, facets } = this;
|
|
815
817
|
const { vaultSeat } = state;
|
|
@@ -823,15 +825,15 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
823
825
|
/**
|
|
824
826
|
* The actual current debt, including accrued interest.
|
|
825
827
|
*
|
|
826
|
-
* This looks like a simple getter but it does a lot of the heavy
|
|
827
|
-
*
|
|
828
|
-
*
|
|
829
|
-
*
|
|
830
|
-
* what
|
|
831
|
-
* this vault record was written.
|
|
828
|
+
* This looks like a simple getter but it does a lot of the heavy lifting for
|
|
829
|
+
* interest accrual. Rather than updating all records when interest accrues,
|
|
830
|
+
* the vault manager updates just its rolling compounded interest. Here we
|
|
831
|
+
* calculate what the current debt is given what's recorded in this vault and
|
|
832
|
+
* what interest has compounded since this vault record was written.
|
|
832
833
|
*
|
|
833
|
-
* @returns {Amount<'nat'>}
|
|
834
834
|
* @see getNormalizedDebt
|
|
835
|
+
*
|
|
836
|
+
* @returns {Amount<'nat'>}
|
|
835
837
|
*/
|
|
836
838
|
getCurrentDebt() {
|
|
837
839
|
const { state } = this;
|
|
@@ -843,15 +845,14 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
843
845
|
},
|
|
844
846
|
|
|
845
847
|
/**
|
|
846
|
-
* The normalization puts all debts on a common time-independent scale
|
|
847
|
-
*
|
|
848
|
-
*
|
|
849
|
-
*
|
|
848
|
+
* The normalization puts all debts on a common time-independent scale since
|
|
849
|
+
* the launch of this vault manager. This allows the manager to order vaults
|
|
850
|
+
* by their debt-to-collateral ratios without having to mutate the debts as
|
|
851
|
+
* the interest accrues.
|
|
850
852
|
*
|
|
851
|
-
* @returns {import('./storeUtils.js').NormalizedDebt} as if the vault
|
|
852
|
-
* was open at the launch of this manager, before any interest
|
|
853
|
-
* accrued
|
|
854
853
|
* @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
|
|
855
856
|
*/
|
|
856
857
|
getNormalizedDebt() {
|
|
857
858
|
const { state } = this;
|
|
@@ -44,34 +44,30 @@ const trace = makeTracer('VD', true);
|
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* @typedef {{
|
|
47
|
-
*
|
|
48
|
-
*
|
|
47
|
+
* collaterals: Brand[],
|
|
48
|
+
* rewardPoolAllocation: AmountKeywordRecord,
|
|
49
49
|
* }} MetricsNotification
|
|
50
50
|
*
|
|
51
|
-
* @typedef {Readonly<{
|
|
51
|
+
* @typedef {Readonly<{
|
|
52
|
+
* }>} ImmutableState
|
|
52
53
|
*
|
|
53
|
-
* @typedef {{
|
|
54
|
+
* @typedef {{
|
|
55
|
+
* }} MutableState
|
|
54
56
|
*
|
|
55
57
|
* @typedef {ImmutableState & MutableState} State
|
|
56
58
|
*
|
|
57
59
|
* @typedef {{
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* mintAndTransfer: MintAndTransfer;
|
|
63
|
-
* getShortfallReporter: () => Promise<
|
|
64
|
-
* import('../reserve/assetReserve.js').ShortfallReporter
|
|
65
|
-
* >;
|
|
60
|
+
* burnDebt: BurnDebt,
|
|
61
|
+
* getGovernedParams: (collateralBrand: Brand) => import('./vaultManager.js').GovernedParamGetters,
|
|
62
|
+
* mintAndTransfer: MintAndTransfer,
|
|
63
|
+
* getShortfallReporter: () => Promise<import('../reserve/assetReserve.js').ShortfallReporter>,
|
|
66
64
|
* }} FactoryPowersFacet
|
|
67
65
|
*
|
|
68
66
|
* @typedef {Readonly<{
|
|
69
67
|
* state: State;
|
|
70
68
|
* }>} MethodContext
|
|
71
69
|
*
|
|
72
|
-
* @typedef {import('@agoric/governance/src/contractGovernance/typedParamManager').TypedParamManager<
|
|
73
|
-
* import('./params.js').VaultDirectorParams
|
|
74
|
-
* >} VaultDirectorParamManager
|
|
70
|
+
* @typedef {import('@agoric/governance/src/contractGovernance/typedParamManager').TypedParamManager<import('./params.js').VaultDirectorParams>} VaultDirectorParamManager
|
|
75
71
|
*/
|
|
76
72
|
|
|
77
73
|
const shortfallInvitationKey = 'shortfallInvitation';
|
|
@@ -80,7 +76,7 @@ const shortfallInvitationKey = 'shortfallInvitation';
|
|
|
80
76
|
* @param {import('@agoric/ertp').Baggage} baggage
|
|
81
77
|
* @param {import('./vaultFactory.js').VaultFactoryZCF} zcf
|
|
82
78
|
* @param {VaultDirectorParamManager} directorParamManager
|
|
83
|
-
* @param {ZCFMint<
|
|
79
|
+
* @param {ZCFMint<"nat">} debtMint
|
|
84
80
|
* @param {ERef<import('@agoric/time/src/types').TimerService>} timer
|
|
85
81
|
* @param {ERef<import('../auction/auctioneer.js').AuctioneerPublicFacet>} auctioneer
|
|
86
82
|
* @param {ERef<StorageNode>} storageNode
|
|
@@ -130,7 +126,9 @@ const prepareVaultDirector = (
|
|
|
130
126
|
|
|
131
127
|
const managersNode = E(storageNode).makeChildNode('managers');
|
|
132
128
|
|
|
133
|
-
/**
|
|
129
|
+
/**
|
|
130
|
+
* @returns {MetricsNotification}
|
|
131
|
+
*/
|
|
134
132
|
const sampleMetrics = () => {
|
|
135
133
|
return harden({
|
|
136
134
|
collaterals: Array.from(collateralManagers.keys()),
|
|
@@ -190,15 +188,15 @@ const prepareVaultDirector = (
|
|
|
190
188
|
},
|
|
191
189
|
|
|
192
190
|
/**
|
|
193
|
-
* Let the manager add rewards to the rewardPoolSeat without
|
|
194
|
-
* rewardPoolSeat to them.
|
|
191
|
+
* Let the manager add rewards to the rewardPoolSeat without
|
|
192
|
+
* exposing the rewardPoolSeat to them.
|
|
195
193
|
*
|
|
196
194
|
* @type {MintAndTransfer}
|
|
197
195
|
*/
|
|
198
196
|
mintAndTransfer: (mintReceiver, toMint, fee, nonMintTransfers) => {
|
|
199
197
|
const kept = AmountMath.subtract(toMint, fee);
|
|
200
198
|
debtMint.mintGains(harden({ Minted: toMint }), mintSeat);
|
|
201
|
-
/** @type {TransferPart[]} */
|
|
199
|
+
/** @type {import('@agoric/zoe/src/contractSupport/atomicTransfer.js').TransferPart[]} */
|
|
202
200
|
const transfers = [
|
|
203
201
|
...nonMintTransfers,
|
|
204
202
|
[mintSeat, rewardPoolSeat, { Minted: fee }],
|
|
@@ -252,7 +250,6 @@ const prepareVaultDirector = (
|
|
|
252
250
|
metrics: makeRecorderTopic('Vault Factory metrics', metricsKit),
|
|
253
251
|
});
|
|
254
252
|
|
|
255
|
-
/** @param {(vm: VaultManager) => void} fn */
|
|
256
253
|
const allManagersDo = fn => {
|
|
257
254
|
for (const managerIndex of collateralManagers.values()) {
|
|
258
255
|
const vm = vaultManagers.get(managerIndex).self;
|
|
@@ -266,7 +263,9 @@ const prepareVaultDirector = (
|
|
|
266
263
|
});
|
|
267
264
|
};
|
|
268
265
|
|
|
269
|
-
/**
|
|
266
|
+
/**
|
|
267
|
+
* @returns {State}
|
|
268
|
+
*/
|
|
270
269
|
const initState = () => {
|
|
271
270
|
return {};
|
|
272
271
|
};
|
|
@@ -276,7 +275,7 @@ const prepareVaultDirector = (
|
|
|
276
275
|
*
|
|
277
276
|
* @param {import('./vaultFactory.js').VaultFactoryZCF} zcf
|
|
278
277
|
* @param {VaultDirectorParamManager} directorParamManager
|
|
279
|
-
* @param {ZCFMint<
|
|
278
|
+
* @param {ZCFMint<"nat">} debtMint
|
|
280
279
|
*/
|
|
281
280
|
const makeVaultDirector = prepareExoClassKit(
|
|
282
281
|
baggage,
|
|
@@ -331,7 +330,9 @@ const prepareVaultDirector = (
|
|
|
331
330
|
}
|
|
332
331
|
},
|
|
333
332
|
}),
|
|
334
|
-
/**
|
|
333
|
+
/**
|
|
334
|
+
* @param {string} name
|
|
335
|
+
*/
|
|
335
336
|
getInvitation(name) {
|
|
336
337
|
return directorParamManager.getInternalParamValue(name);
|
|
337
338
|
},
|
|
@@ -377,8 +378,9 @@ const prepareVaultDirector = (
|
|
|
377
378
|
// zero-based index of the manager being made
|
|
378
379
|
const managerIndex = vaultManagers.length();
|
|
379
380
|
const managerId = `manager${managerIndex}`;
|
|
380
|
-
const managerStorageNode =
|
|
381
|
-
|
|
381
|
+
const managerStorageNode = await E(managersNode).makeChildNode(
|
|
382
|
+
managerId,
|
|
383
|
+
);
|
|
382
384
|
|
|
383
385
|
vaultParamManagers.addParamManager(
|
|
384
386
|
collateralBrand,
|
|
@@ -422,7 +424,6 @@ const prepareVaultDirector = (
|
|
|
422
424
|
|
|
423
425
|
makeLiquidationWaker() {
|
|
424
426
|
return makeWaker('liquidationWaker', _timestamp => {
|
|
425
|
-
// XXX floating promise
|
|
426
427
|
allManagersDo(vm => vm.liquidateVaults(auctioneer));
|
|
427
428
|
});
|
|
428
429
|
},
|
|
@@ -439,7 +440,9 @@ const prepareVaultDirector = (
|
|
|
439
440
|
},
|
|
440
441
|
},
|
|
441
442
|
public: {
|
|
442
|
-
/**
|
|
443
|
+
/**
|
|
444
|
+
* @param {Brand} brandIn
|
|
445
|
+
*/
|
|
443
446
|
getCollateralManager(brandIn) {
|
|
444
447
|
collateralManagers.has(brandIn) ||
|
|
445
448
|
Fail`Not a supported collateral type ${brandIn}`;
|
|
@@ -460,16 +463,22 @@ const prepareVaultDirector = (
|
|
|
460
463
|
getPublicTopics() {
|
|
461
464
|
return topics;
|
|
462
465
|
},
|
|
463
|
-
/**
|
|
466
|
+
/**
|
|
467
|
+
* subscription for the paramManager for the vaultFactory's electorate
|
|
468
|
+
*/
|
|
464
469
|
getElectorateSubscription() {
|
|
465
470
|
return directorParamManager.getSubscription();
|
|
466
471
|
},
|
|
467
|
-
/**
|
|
472
|
+
/**
|
|
473
|
+
* @param {{ collateralBrand: Brand }} selector
|
|
474
|
+
*/
|
|
468
475
|
getGovernedParams({ collateralBrand }) {
|
|
469
476
|
// TODO use named getters of TypedParamManager
|
|
470
477
|
return vaultParamManagers.get(collateralBrand).getParams();
|
|
471
478
|
},
|
|
472
|
-
/**
|
|
479
|
+
/**
|
|
480
|
+
* @param {string} name
|
|
481
|
+
*/
|
|
473
482
|
getInvitationAmount(name) {
|
|
474
483
|
return directorParamManager.getInvitationAmount(name);
|
|
475
484
|
},
|
|
@@ -489,7 +498,9 @@ const prepareVaultDirector = (
|
|
|
489
498
|
rescheduleWaker,
|
|
490
499
|
);
|
|
491
500
|
},
|
|
492
|
-
/**
|
|
501
|
+
/**
|
|
502
|
+
* Start non-durable processes (or restart if needed after vat restart)
|
|
503
|
+
*/
|
|
493
504
|
async start() {
|
|
494
505
|
const { helper, machine } = this.facets;
|
|
495
506
|
|
|
@@ -514,9 +525,7 @@ harden(prepareVaultDirector);
|
|
|
514
525
|
/**
|
|
515
526
|
* Prepare the VaultDirector kind, get or make the singleton
|
|
516
527
|
*
|
|
517
|
-
* @type {(
|
|
518
|
-
* ...pvdArgs: Parameters<typeof prepareVaultDirector>
|
|
519
|
-
* ) => ReturnType<ReturnType<typeof prepareVaultDirector>>}
|
|
528
|
+
* @type {(...pvdArgs: Parameters<typeof prepareVaultDirector>) => ReturnType<ReturnType<typeof prepareVaultDirector>>}
|
|
520
529
|
*/
|
|
521
530
|
export const provideDirector = (...args) => {
|
|
522
531
|
const makeVaultDirector = prepareVaultDirector(...args);
|
|
@@ -34,46 +34,40 @@ import { provideDirector } from './vaultDirector.js';
|
|
|
34
34
|
const trace = makeTracer('VF', true);
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
* @typedef {ZCF<
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* }
|
|
44
|
-
* >} VaultFactoryZCF
|
|
37
|
+
* @typedef {ZCF<GovernanceTerms<import('./params').VaultDirectorParams> & {
|
|
38
|
+
* auctioneerPublicFacet: import('../auction/auctioneer.js').AuctioneerPublicFacet,
|
|
39
|
+
* priceAuthority: ERef<PriceAuthority>,
|
|
40
|
+
* reservePublicFacet: AssetReservePublicFacet,
|
|
41
|
+
* timerService: import('@agoric/time/src/types').TimerService,
|
|
42
|
+
* }>} VaultFactoryZCF
|
|
45
43
|
*/
|
|
46
44
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
),
|
|
61
|
-
upgradability: 'canUpgrade',
|
|
62
|
-
};
|
|
63
|
-
harden(meta);
|
|
45
|
+
export const privateArgsShape = M.splitRecord(
|
|
46
|
+
harden({
|
|
47
|
+
marshaller: M.remotable('Marshaller'),
|
|
48
|
+
storageNode: StorageNodeShape,
|
|
49
|
+
}),
|
|
50
|
+
harden({
|
|
51
|
+
// only necessary on first invocation, not subsequent
|
|
52
|
+
feeMintAccess: FeeMintAccessShape,
|
|
53
|
+
initialPoserInvitation: InvitationShape,
|
|
54
|
+
initialShortfallInvitation: InvitationShape,
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
harden(privateArgsShape);
|
|
64
58
|
|
|
65
59
|
/**
|
|
66
60
|
* @param {VaultFactoryZCF} zcf
|
|
67
61
|
* @param {{
|
|
68
|
-
* feeMintAccess: FeeMintAccess
|
|
69
|
-
* initialPoserInvitation: Invitation
|
|
70
|
-
* initialShortfallInvitation: Invitation
|
|
71
|
-
* storageNode: ERef<StorageNode
|
|
72
|
-
* marshaller: ERef<Marshaller
|
|
62
|
+
* feeMintAccess: FeeMintAccess,
|
|
63
|
+
* initialPoserInvitation: Invitation,
|
|
64
|
+
* initialShortfallInvitation: Invitation,
|
|
65
|
+
* storageNode: ERef<StorageNode>,
|
|
66
|
+
* marshaller: ERef<Marshaller>,
|
|
73
67
|
* }} privateArgs
|
|
74
68
|
* @param {import('@agoric/ertp').Baggage} baggage
|
|
75
69
|
*/
|
|
76
|
-
export const
|
|
70
|
+
export const prepare = async (zcf, privateArgs, baggage) => {
|
|
77
71
|
trace('prepare start', privateArgs, [...baggage.keys()]);
|
|
78
72
|
const {
|
|
79
73
|
initialPoserInvitation,
|
|
@@ -151,6 +145,5 @@ export const start = async (zcf, privateArgs, baggage) => {
|
|
|
151
145
|
publicFacet: director.public,
|
|
152
146
|
});
|
|
153
147
|
};
|
|
154
|
-
harden(start);
|
|
155
148
|
|
|
156
|
-
/** @typedef {ContractOf<typeof
|
|
149
|
+
/** @typedef {ContractOf<typeof prepare>} VaultFactoryContract */
|