@agoric/inter-protocol 0.16.2-upgrade-14-dev-0169c7e.0 → 0.16.2-upgrade-16-dev-8879538.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/package.json +41 -34
- package/scripts/build-bundles.js +5 -21
- package/src/auction/auctionBook.d.ts +84 -0
- package/src/auction/auctionBook.d.ts.map +1 -0
- package/src/auction/auctionBook.js +135 -103
- package/src/auction/auctioneer.d.ts +83 -0
- package/src/auction/auctioneer.d.ts.map +1 -0
- package/src/auction/auctioneer.js +63 -49
- package/src/auction/offerBook.d.ts +45 -0
- package/src/auction/offerBook.d.ts.map +1 -0
- package/src/auction/offerBook.js +13 -12
- package/src/auction/params.d.ts +149 -0
- package/src/auction/params.d.ts.map +1 -0
- package/src/auction/params.js +10 -9
- package/src/auction/scheduleMath.d.ts +5 -0
- package/src/auction/scheduleMath.d.ts.map +1 -0
- package/src/auction/scheduleMath.js +17 -15
- package/src/auction/scheduler.d.ts +49 -0
- package/src/auction/scheduler.d.ts.map +1 -0
- package/src/auction/scheduler.js +51 -43
- package/src/auction/sortedOffers.d.ts +8 -0
- package/src/auction/sortedOffers.d.ts.map +1 -0
- package/src/auction/sortedOffers.js +9 -7
- package/src/auction/util.d.ts +32 -0
- package/src/auction/util.d.ts.map +1 -0
- package/src/auction/util.js +6 -4
- package/src/clientSupport.d.ts +167 -0
- package/src/clientSupport.d.ts.map +1 -0
- package/src/clientSupport.js +97 -40
- 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 +14 -12
- package/src/econCommitteeCharter.d.ts +39 -0
- package/src/econCommitteeCharter.d.ts.map +1 -0
- package/src/econCommitteeCharter.js +21 -20
- package/src/feeDistributor.d.ts +224 -0
- package/src/feeDistributor.d.ts.map +1 -0
- package/src/feeDistributor.js +37 -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 +3 -0
- package/src/interest-math.d.ts.map +1 -0
- package/src/interest.d.ts +28 -0
- package/src/interest.d.ts.map +1 -0
- package/src/interest.js +21 -16
- package/src/price/README.md +13 -0
- package/src/price/fluxAggregatorContract.d.ts +70 -0
- package/src/price/fluxAggregatorContract.d.ts.map +1 -0
- package/src/price/fluxAggregatorContract.js +62 -55
- package/src/price/fluxAggregatorKit.d.ts +103 -0
- package/src/price/fluxAggregatorKit.d.ts.map +1 -0
- package/src/price/fluxAggregatorKit.js +50 -37
- package/src/price/priceOracleKit.d.ts +38 -0
- package/src/price/priceOracleKit.d.ts.map +1 -0
- package/src/price/priceOracleKit.js +11 -13
- package/src/price/roundsManager.d.ts +238 -0
- package/src/price/roundsManager.d.ts.map +1 -0
- package/src/price/roundsManager.js +77 -82
- package/src/proposals/README.md +2 -3
- package/src/proposals/add-auction.d.ts +69 -0
- package/src/proposals/add-auction.d.ts.map +1 -0
- package/src/proposals/add-auction.js +181 -0
- package/src/proposals/addAssetToVault.d.ts +160 -0
- package/src/proposals/addAssetToVault.d.ts.map +1 -0
- package/src/proposals/addAssetToVault.js +172 -38
- package/src/proposals/committee-proposal.d.ts +113 -0
- package/src/proposals/committee-proposal.d.ts.map +1 -0
- package/src/proposals/committee-proposal.js +25 -31
- package/src/proposals/core-proposal.d.ts +149 -0
- package/src/proposals/core-proposal.d.ts.map +1 -0
- package/src/proposals/core-proposal.js +9 -11
- package/src/proposals/econ-behaviors.d.ts +1169 -0
- package/src/proposals/econ-behaviors.d.ts.map +1 -0
- package/src/proposals/econ-behaviors.js +66 -45
- package/src/proposals/price-feed-proposal.d.ts +84 -0
- package/src/proposals/price-feed-proposal.d.ts.map +1 -0
- package/src/proposals/price-feed-proposal.js +108 -51
- package/src/proposals/startEconCommittee.d.ts +34 -0
- package/src/proposals/startEconCommittee.d.ts.map +1 -0
- package/src/proposals/startEconCommittee.js +2 -2
- package/src/proposals/startPSM.d.ts +59 -0
- package/src/proposals/startPSM.d.ts.map +1 -0
- package/src/proposals/startPSM.js +38 -27
- package/src/proposals/upgrade-scaledPriceAuthorities.d.ts +24 -0
- package/src/proposals/upgrade-scaledPriceAuthorities.d.ts.map +1 -0
- package/src/proposals/upgrade-scaledPriceAuthorities.js +78 -0
- package/src/proposals/upgrade-vaults.d.ts +35 -0
- package/src/proposals/upgrade-vaults.d.ts.map +1 -0
- package/src/proposals/upgrade-vaults.js +202 -0
- package/src/proposals/utils.d.ts +17 -0
- package/src/proposals/utils.d.ts.map +1 -0
- package/src/proposals/utils.js +34 -7
- package/src/provisionPool.d.ts +167 -0
- package/src/provisionPool.d.ts.map +1 -0
- package/src/provisionPool.js +122 -0
- package/src/provisionPoolKit.d.ts +770 -0
- package/src/provisionPoolKit.d.ts.map +1 -0
- package/src/provisionPoolKit.js +463 -0
- package/src/psm/psm.d.ts +122 -0
- package/src/psm/psm.d.ts.map +1 -0
- package/src/psm/psm.js +73 -69
- 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 +47 -0
- package/src/reserve/assetReserve.d.ts.map +1 -0
- package/src/reserve/assetReserve.js +28 -19
- package/src/reserve/assetReserveKit.d.ts +74 -0
- package/src/reserve/assetReserveKit.d.ts.map +1 -0
- package/src/reserve/assetReserveKit.js +18 -24
- package/src/reserve/params.d.ts +10 -0
- package/src/reserve/params.d.ts.map +1 -0
- 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 +163 -0
- package/src/vaultFactory/liquidation.d.ts.map +1 -0
- package/src/vaultFactory/liquidation.js +36 -22
- package/src/vaultFactory/math.d.ts +11 -0
- package/src/vaultFactory/math.d.ts.map +1 -0
- package/src/vaultFactory/math.js +10 -9
- package/src/vaultFactory/orderedVaultStore.d.ts +360 -0
- package/src/vaultFactory/orderedVaultStore.d.ts.map +1 -0
- package/src/vaultFactory/orderedVaultStore.js +8 -11
- package/src/vaultFactory/params.d.ts +145 -0
- package/src/vaultFactory/params.d.ts.map +1 -0
- package/src/vaultFactory/params.js +52 -24
- package/src/vaultFactory/prioritizedVaults.d.ts +992 -0
- package/src/vaultFactory/prioritizedVaults.d.ts.map +1 -0
- package/src/vaultFactory/prioritizedVaults.js +4 -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 +234 -0
- package/src/vaultFactory/types-ambient.d.ts.map +1 -0
- package/src/vaultFactory/{types.js → types-ambient.js} +42 -42
- package/src/vaultFactory/vault.d.ts +402 -0
- package/src/vaultFactory/vault.d.ts.map +1 -0
- package/src/vaultFactory/vault.js +99 -93
- package/src/vaultFactory/vaultDirector.d.ts +388 -0
- package/src/vaultFactory/vaultDirector.d.ts.map +1 -0
- package/src/vaultFactory/vaultDirector.js +61 -50
- package/src/vaultFactory/vaultFactory.d.ts +277 -0
- package/src/vaultFactory/vaultFactory.d.ts.map +1 -0
- package/src/vaultFactory/vaultFactory.js +49 -32
- package/src/vaultFactory/vaultHolder.d.ts +270 -0
- package/src/vaultFactory/vaultHolder.d.ts.map +1 -0
- package/src/vaultFactory/vaultHolder.js +10 -14
- package/src/vaultFactory/vaultKit.d.ts +102 -0
- package/src/vaultFactory/vaultKit.d.ts.map +1 -0
- package/src/vaultFactory/vaultKit.js +5 -4
- package/src/vaultFactory/vaultManager.d.ts +819 -0
- package/src/vaultFactory/vaultManager.d.ts.map +1 -0
- package/src/vaultFactory/vaultManager.js +248 -151
- package/CHANGELOG.md +0 -1066
- package/exported.js +0 -2
- package/scripts/add-collateral-core.js +0 -113
- package/scripts/deploy-contracts.js +0 -100
- package/scripts/init-core.js +0 -200
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vaultManager.d.ts","sourceRoot":"","sources":["vaultManager.js"],"names":[],"mappings":"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"}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
/* eslint-disable consistent-return */
|
|
2
1
|
/**
|
|
3
2
|
* @file Vault Manager object manages vault-based debts for a collateral type.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
* - opening a new vault backed by the collateral
|
|
7
|
-
* - publishing metrics on the vault economy for that collateral
|
|
8
|
-
* - charging interest on all active vaults
|
|
9
|
-
* - liquidating active vaults that have exceeded the debt ratio
|
|
4
|
+
* The responsibilities include:
|
|
10
5
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
6
|
+
* - opening a new vault backed by the collateral
|
|
7
|
+
* - publishing metrics on the vault economy for that collateral
|
|
8
|
+
* - charging interest on all active vaults
|
|
9
|
+
* - liquidating active vaults that have exceeded the debt ratio
|
|
14
10
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
11
|
+
* Once a vault is settled (liquidated or closed) it can still be used, traded,
|
|
12
|
+
* etc. but is no longer the concern of the manager. It can't be liquidated,
|
|
13
|
+
* have interest charged, or be counted in the metrics.
|
|
14
|
+
*
|
|
15
|
+
* Undercollateralized vaults can have their assets sent to the auctioneer to be
|
|
16
|
+
* liquidated. If the auction is unsuccessful, the liquidation may be
|
|
17
|
+
* reverted.
|
|
17
18
|
*/
|
|
18
|
-
|
|
19
|
+
/// <reference types="@agoric/zoe/exported" />
|
|
19
20
|
|
|
20
21
|
import {
|
|
21
22
|
AmountMath,
|
|
@@ -50,7 +51,6 @@ import {
|
|
|
50
51
|
} from '@agoric/zoe/src/contractSupport/index.js';
|
|
51
52
|
import { PriceQuoteShape, SeatShape } from '@agoric/zoe/src/typeGuards.js';
|
|
52
53
|
import { E } from '@endo/eventual-send';
|
|
53
|
-
import { AuctionPFShape } from '../auction/auctioneer.js';
|
|
54
54
|
import {
|
|
55
55
|
checkDebtLimit,
|
|
56
56
|
makeNatAmountShape,
|
|
@@ -62,117 +62,164 @@ import { calculateMinimumCollateralization, minimumPrice } from './math.js';
|
|
|
62
62
|
import { makePrioritizedVaults } from './prioritizedVaults.js';
|
|
63
63
|
import { Phase, prepareVault } from './vault.js';
|
|
64
64
|
import { calculateDistributionPlan } from './proceeds.js';
|
|
65
|
+
import { AuctionPFShape } from '../auction/auctioneer.js';
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @import {Baggage} from '@agoric/vat-data';
|
|
69
|
+
* @import {PriceAuthority, PriceDescription, PriceQuote, PriceQuoteValue, PriceQuery,} from '@agoric/zoe/tools/types.js';
|
|
70
|
+
*/
|
|
65
71
|
|
|
66
72
|
const { details: X, Fail, quote: q } = assert;
|
|
67
73
|
|
|
68
74
|
const trace = makeTracer('VM');
|
|
69
75
|
|
|
70
|
-
/**
|
|
71
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Watch a notifier that isn't expected to fail or finish unless the vat hosting
|
|
78
|
+
* the notifier is upgraded. This watcher supports that by providing a
|
|
79
|
+
* straightforward way to get a replacement if the notifier breaks.
|
|
80
|
+
*
|
|
81
|
+
* @template T notifier topic
|
|
82
|
+
* @template {any[]} [A=unknown[]] arbitrary arguments
|
|
83
|
+
* @param {ERef<LatestTopic<T>>} notifierP
|
|
84
|
+
* @param {import('@agoric/swingset-liveslots').PromiseWatcher<T, A>} watcher
|
|
85
|
+
* @param {A} args
|
|
86
|
+
*/
|
|
87
|
+
export const watchQuoteNotifier = async (notifierP, watcher, ...args) => {
|
|
88
|
+
await undefined;
|
|
89
|
+
|
|
90
|
+
let updateCount;
|
|
91
|
+
for (;;) {
|
|
92
|
+
let value;
|
|
93
|
+
try {
|
|
94
|
+
({ value, updateCount } = await E(notifierP).getUpdateSince(updateCount));
|
|
95
|
+
watcher.onFulfilled && watcher.onFulfilled(value, ...args);
|
|
96
|
+
} catch (e) {
|
|
97
|
+
watcher.onRejected && watcher.onRejected(e, ...args);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
if (updateCount === undefined) {
|
|
101
|
+
watcher.onRejected &&
|
|
102
|
+
watcher.onRejected(Error('stream finished'), ...args);
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/** @import {NormalizedDebt} from './storeUtils.js' */
|
|
109
|
+
/** @import {RelativeTime} from '@agoric/time' */
|
|
72
110
|
|
|
73
111
|
// Metrics naming scheme: nouns are present values; past-participles are accumulative.
|
|
74
112
|
/**
|
|
75
113
|
* @typedef {object} MetricsNotification
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* @property {number}
|
|
80
|
-
* @property {number}
|
|
81
|
-
* @property {Amount<'nat'>}
|
|
82
|
-
*
|
|
83
|
-
* @property {Amount<'nat'>}
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* @property {Amount<'nat'>}
|
|
90
|
-
*
|
|
91
|
-
* @property {Amount<'nat'>}
|
|
92
|
-
*
|
|
93
|
-
* @property {
|
|
114
|
+
* @property {Ratio | null} lockedQuote priceQuote that will be used for
|
|
115
|
+
* liquidation. Non-null from priceLock time until liquidation has taken
|
|
116
|
+
* place.
|
|
117
|
+
* @property {number} numActiveVaults present count of vaults
|
|
118
|
+
* @property {number} numLiquidatingVaults present count of liquidating vaults
|
|
119
|
+
* @property {Amount<'nat'>} totalCollateral present sum of collateral across
|
|
120
|
+
* all vaults
|
|
121
|
+
* @property {Amount<'nat'>} totalDebt present sum of debt across all vaults
|
|
122
|
+
* @property {Amount<'nat'>} retainedCollateral collateral held as a result of
|
|
123
|
+
* not returning excess refunds to owners of vaults liquidated with
|
|
124
|
+
* shortfalls
|
|
125
|
+
* @property {Amount<'nat'>} liquidatingCollateral present sum of collateral in
|
|
126
|
+
* vaults sent for liquidation
|
|
127
|
+
* @property {Amount<'nat'>} liquidatingDebt present sum of debt in vaults sent
|
|
128
|
+
* for liquidation
|
|
129
|
+
* @property {Amount<'nat'>} totalCollateralSold running sum of collateral sold
|
|
130
|
+
* in liquidation
|
|
131
|
+
* @property {Amount<'nat'>} totalOverageReceived running sum of overages,
|
|
132
|
+
* central received greater than debt
|
|
133
|
+
* @property {Amount<'nat'>} totalProceedsReceived running sum of minted
|
|
134
|
+
* received from liquidation
|
|
135
|
+
* @property {Amount<'nat'>} totalShortfallReceived running sum of shortfalls,
|
|
136
|
+
* minted received less than debt
|
|
137
|
+
* @property {number} numLiquidationsCompleted running count of liquidated
|
|
138
|
+
* vaults
|
|
139
|
+
* @property {number} numLiquidationsAborted running count of vault liquidations
|
|
140
|
+
* that were reverted.
|
|
94
141
|
*/
|
|
95
142
|
|
|
96
143
|
/**
|
|
97
144
|
* @typedef {{
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
145
|
+
* compoundedInterest: Ratio;
|
|
146
|
+
* interestRate: Ratio;
|
|
147
|
+
* latestInterestUpdate: Timestamp;
|
|
101
148
|
* }} AssetState
|
|
102
149
|
*
|
|
103
150
|
* @typedef {{
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
151
|
+
* getChargingPeriod: () => RelativeTime;
|
|
152
|
+
* getRecordingPeriod: () => RelativeTime;
|
|
153
|
+
* getDebtLimit: () => Amount<'nat'>;
|
|
154
|
+
* getInterestRate: () => Ratio;
|
|
155
|
+
* getLiquidationPadding: () => Ratio;
|
|
156
|
+
* getLiquidationMargin: () => Ratio;
|
|
157
|
+
* getLiquidationPenalty: () => Ratio;
|
|
158
|
+
* getMintFee: () => Ratio;
|
|
159
|
+
* getMinInitialDebt: () => Amount<'nat'>;
|
|
113
160
|
* }} GovernedParamGetters
|
|
114
161
|
*/
|
|
115
162
|
|
|
116
163
|
/**
|
|
117
164
|
* @typedef {Readonly<{
|
|
118
|
-
* debtMint: ZCFMint<'nat'
|
|
119
|
-
* collateralBrand: Brand<'nat'
|
|
120
|
-
* collateralUnit: Amount<'nat'
|
|
121
|
-
* descriptionScope: string
|
|
122
|
-
* startTimeStamp: Timestamp
|
|
123
|
-
* storageNode: StorageNode
|
|
165
|
+
* debtMint: ZCFMint<'nat'>;
|
|
166
|
+
* collateralBrand: Brand<'nat'>;
|
|
167
|
+
* collateralUnit: Amount<'nat'>;
|
|
168
|
+
* descriptionScope: string;
|
|
169
|
+
* startTimeStamp: Timestamp;
|
|
170
|
+
* storageNode: StorageNode;
|
|
124
171
|
* }>} HeldParams
|
|
125
172
|
*/
|
|
126
173
|
|
|
127
174
|
/**
|
|
128
175
|
* @typedef {{
|
|
129
|
-
* assetTopicKit: import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<AssetState
|
|
130
|
-
* debtBrand: Brand<'nat'
|
|
131
|
-
* liquidatingVaults: SetStore<Vault
|
|
132
|
-
* metricsTopicKit: import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<MetricsNotification
|
|
133
|
-
* poolIncrementSeat: ZCFSeat
|
|
134
|
-
* retainedCollateralSeat: ZCFSeat
|
|
135
|
-
* unsettledVaults: MapStore<string, Vault
|
|
176
|
+
* assetTopicKit: import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<AssetState>;
|
|
177
|
+
* debtBrand: Brand<'nat'>;
|
|
178
|
+
* liquidatingVaults: SetStore<Vault>;
|
|
179
|
+
* metricsTopicKit: import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<MetricsNotification>;
|
|
180
|
+
* poolIncrementSeat: ZCFSeat;
|
|
181
|
+
* retainedCollateralSeat: ZCFSeat;
|
|
182
|
+
* unsettledVaults: MapStore<string, Vault>;
|
|
136
183
|
* }} ImmutableState
|
|
137
184
|
*/
|
|
138
185
|
|
|
139
186
|
/**
|
|
140
187
|
* @typedef {{
|
|
141
|
-
* compoundedInterest: Ratio
|
|
142
|
-
* latestInterestUpdate: Timestamp
|
|
143
|
-
* numLiquidationsCompleted: number
|
|
144
|
-
* numLiquidationsAborted: number
|
|
145
|
-
* totalCollateral: Amount<'nat'
|
|
146
|
-
* totalCollateralSold: Amount<'nat'
|
|
147
|
-
* totalDebt: Amount<'nat'
|
|
148
|
-
* liquidatingCollateral: Amount<'nat'
|
|
149
|
-
* liquidatingDebt: Amount<'nat'
|
|
150
|
-
* totalOverageReceived: Amount<'nat'
|
|
151
|
-
* totalProceedsReceived: Amount<'nat'
|
|
152
|
-
* totalShortfallReceived: Amount<'nat'
|
|
153
|
-
* vaultCounter: number
|
|
154
|
-
* lockedQuote: PriceQuote | undefined
|
|
188
|
+
* compoundedInterest: Ratio;
|
|
189
|
+
* latestInterestUpdate: Timestamp;
|
|
190
|
+
* numLiquidationsCompleted: number;
|
|
191
|
+
* numLiquidationsAborted: number;
|
|
192
|
+
* totalCollateral: Amount<'nat'>;
|
|
193
|
+
* totalCollateralSold: Amount<'nat'>;
|
|
194
|
+
* totalDebt: Amount<'nat'>;
|
|
195
|
+
* liquidatingCollateral: Amount<'nat'>;
|
|
196
|
+
* liquidatingDebt: Amount<'nat'>;
|
|
197
|
+
* totalOverageReceived: Amount<'nat'>;
|
|
198
|
+
* totalProceedsReceived: Amount<'nat'>;
|
|
199
|
+
* totalShortfallReceived: Amount<'nat'>;
|
|
200
|
+
* vaultCounter: number;
|
|
201
|
+
* lockedQuote: PriceQuote | undefined;
|
|
155
202
|
* }} MutableState
|
|
156
203
|
*/
|
|
157
204
|
|
|
158
205
|
/**
|
|
159
206
|
* @type {(brand: Brand) => {
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
207
|
+
* prioritizedVaults: ReturnType<typeof makePrioritizedVaults>;
|
|
208
|
+
* storedQuotesNotifier: import('@agoric/notifier').StoredNotifier<PriceQuote>;
|
|
209
|
+
* storedCollateralQuote: PriceQuote | null;
|
|
163
210
|
* }}
|
|
164
211
|
*/
|
|
165
212
|
// any b/c will be filled after start()
|
|
166
213
|
const collateralEphemera = makeEphemeraProvider(() => /** @type {any} */ ({}));
|
|
167
214
|
|
|
168
215
|
/**
|
|
169
|
-
* @param {import('@agoric/
|
|
216
|
+
* @param {import('@agoric/swingset-liveslots').Baggage} baggage
|
|
170
217
|
* @param {{
|
|
171
|
-
* zcf: import('./vaultFactory.js').VaultFactoryZCF
|
|
172
|
-
* marshaller: ERef<Marshaller
|
|
173
|
-
* makeRecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').MakeRecorderKit
|
|
174
|
-
* makeERecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').MakeERecorderKit
|
|
175
|
-
* factoryPowers: import('./vaultDirector.js').FactoryPowersFacet
|
|
218
|
+
* zcf: import('./vaultFactory.js').VaultFactoryZCF;
|
|
219
|
+
* marshaller: ERef<Marshaller>;
|
|
220
|
+
* makeRecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').MakeRecorderKit;
|
|
221
|
+
* makeERecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').MakeERecorderKit;
|
|
222
|
+
* factoryPowers: import('./vaultDirector.js').FactoryPowersFacet;
|
|
176
223
|
* }} powers
|
|
177
224
|
*/
|
|
178
225
|
export const prepareVaultManagerKit = (
|
|
@@ -203,8 +250,9 @@ export const prepareVaultManagerKit = (
|
|
|
203
250
|
poolIncrementSeat: zcf.makeEmptySeatKit().zcfSeat,
|
|
204
251
|
|
|
205
252
|
/**
|
|
206
|
-
* Vaults that have been sent for liquidation. When we get proceeds (or
|
|
207
|
-
* thereof) back from the liquidator, we will allocate them among the
|
|
253
|
+
* Vaults that have been sent for liquidation. When we get proceeds (or
|
|
254
|
+
* lack thereof) back from the liquidator, we will allocate them among the
|
|
255
|
+
* vaults.
|
|
208
256
|
*
|
|
209
257
|
* @type {SetStore<Vault>}
|
|
210
258
|
*/
|
|
@@ -292,7 +340,7 @@ export const prepareVaultManagerKit = (
|
|
|
292
340
|
getCollateralQuote: M.call().returns(PriceQuoteShape),
|
|
293
341
|
getPublicFacet: M.call().returns(M.remotable('publicFacet')),
|
|
294
342
|
lockOraclePrices: M.call().returns(PriceQuoteShape),
|
|
295
|
-
liquidateVaults: M.call(AuctionPFShape).returns(M.promise()),
|
|
343
|
+
liquidateVaults: M.call(M.eref(AuctionPFShape)).returns(M.promise()),
|
|
296
344
|
}),
|
|
297
345
|
},
|
|
298
346
|
initState,
|
|
@@ -339,19 +387,11 @@ export const prepareVaultManagerKit = (
|
|
|
339
387
|
|
|
340
388
|
// Some of these could go in closures but are kept on a facet anticipating future durability options.
|
|
341
389
|
helper: {
|
|
342
|
-
/**
|
|
343
|
-
* Start non-durable processes (or restart if needed after vat restart)
|
|
344
|
-
*/
|
|
390
|
+
/** Start non-durable processes (or restart if needed after vat restart) */
|
|
345
391
|
start() {
|
|
346
392
|
const { state, facets } = this;
|
|
347
393
|
trace(state.collateralBrand, 'helper.start()', state.vaultCounter);
|
|
348
|
-
const {
|
|
349
|
-
collateralBrand,
|
|
350
|
-
collateralUnit,
|
|
351
|
-
debtBrand,
|
|
352
|
-
storageNode,
|
|
353
|
-
unsettledVaults,
|
|
354
|
-
} = state;
|
|
394
|
+
const { collateralBrand, unsettledVaults } = state;
|
|
355
395
|
|
|
356
396
|
const ephemera = collateralEphemera(collateralBrand);
|
|
357
397
|
ephemera.prioritizedVaults = makePrioritizedVaults(unsettledVaults);
|
|
@@ -384,34 +424,53 @@ export const prepareVaultManagerKit = (
|
|
|
384
424
|
},
|
|
385
425
|
});
|
|
386
426
|
|
|
387
|
-
|
|
427
|
+
void facets.helper.observeQuoteNotifier();
|
|
428
|
+
|
|
429
|
+
trace('helper.start() done');
|
|
430
|
+
},
|
|
431
|
+
observeQuoteNotifier() {
|
|
432
|
+
const { state } = this;
|
|
433
|
+
|
|
434
|
+
const { collateralBrand, collateralUnit, debtBrand, storageNode } =
|
|
435
|
+
state;
|
|
436
|
+
const ephemera = collateralEphemera(collateralBrand);
|
|
437
|
+
|
|
388
438
|
const quoteNotifier = E(priceAuthority).makeQuoteNotifier(
|
|
389
439
|
collateralUnit,
|
|
390
440
|
debtBrand,
|
|
391
441
|
);
|
|
442
|
+
// @ts-expect-error XXX quotes
|
|
392
443
|
ephemera.storedQuotesNotifier = makeStoredNotifier(
|
|
444
|
+
// @ts-expect-error XXX quotes
|
|
393
445
|
quoteNotifier,
|
|
394
446
|
E(storageNode).makeChildNode('quotes'),
|
|
395
447
|
marshaller,
|
|
396
448
|
);
|
|
397
|
-
trace(
|
|
449
|
+
trace(
|
|
450
|
+
'helper.start() awaiting observe storedQuotesNotifier',
|
|
451
|
+
collateralBrand,
|
|
452
|
+
);
|
|
398
453
|
// NB: upon restart, there may not be a price for a while. If manager
|
|
399
|
-
// operations are permitted, ones
|
|
400
|
-
// throw. See https://github.com/Agoric/agoric-sdk/issues/4317
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
trace('vaultManager got new collateral quote', value);
|
|
454
|
+
// operations are permitted, ones that depend on price information
|
|
455
|
+
// will throw. See https://github.com/Agoric/agoric-sdk/issues/4317
|
|
456
|
+
const quoteWatcher = harden({
|
|
457
|
+
onFulfilled(value) {
|
|
404
458
|
ephemera.storedCollateralQuote = value;
|
|
405
459
|
},
|
|
406
|
-
|
|
407
|
-
|
|
460
|
+
onRejected() {
|
|
461
|
+
// NOTE: drastic action, if the quoteNotifier fails, we don't know
|
|
462
|
+
// the value of the asset, nor do we know how long we'll be in
|
|
463
|
+
// ignorance. Best choice is to disable actions that require
|
|
464
|
+
// prices and restart when we have a new price. If we restart the
|
|
465
|
+
// notifier immediately, we'll trigger an infinite loop, so try
|
|
466
|
+
// to restart each time we get a request.
|
|
467
|
+
|
|
468
|
+
ephemera.storedCollateralQuote = null;
|
|
408
469
|
},
|
|
409
470
|
});
|
|
410
|
-
|
|
471
|
+
void watchQuoteNotifier(quoteNotifier, quoteWatcher);
|
|
411
472
|
},
|
|
412
|
-
/**
|
|
413
|
-
* @param {Timestamp} updateTime
|
|
414
|
-
*/
|
|
473
|
+
/** @param {Timestamp} updateTime */
|
|
415
474
|
async chargeAllVaults(updateTime) {
|
|
416
475
|
const { state, facets } = this;
|
|
417
476
|
const { collateralBrand, debtMint, poolIncrementSeat } = state;
|
|
@@ -515,7 +574,6 @@ export const prepareVaultManagerKit = (
|
|
|
515
574
|
state.liquidatingDebt = AmountMath.add(state.liquidatingDebt, debt);
|
|
516
575
|
},
|
|
517
576
|
/**
|
|
518
|
-
*
|
|
519
577
|
* @param {Amount<'nat'>} debt
|
|
520
578
|
* @param {Amount<'nat'>} collateral
|
|
521
579
|
* @param {Amount<'nat'>} overage
|
|
@@ -598,14 +656,18 @@ export const prepareVaultManagerKit = (
|
|
|
598
656
|
},
|
|
599
657
|
|
|
600
658
|
/**
|
|
601
|
-
* This is designed to tolerate an incomplete plan, in case
|
|
602
|
-
* an error during its calculation.
|
|
603
|
-
*
|
|
659
|
+
* This is designed to tolerate an incomplete plan, in case
|
|
660
|
+
* calculateDistributionPlan encounters an error during its calculation.
|
|
661
|
+
* We don't have a way to induce such errors in CI so we've done so
|
|
662
|
+
* manually in dev and verified this function recovers as expected.
|
|
604
663
|
*
|
|
605
664
|
* @param {AmountKeywordRecord} proceeds
|
|
606
665
|
* @param {Amount<'nat'>} totalDebt
|
|
607
666
|
* @param {Pick<PriceQuote, 'quoteAmount'>} oraclePriceAtStart
|
|
608
|
-
* @param {MapStore<
|
|
667
|
+
* @param {MapStore<
|
|
668
|
+
* Vault,
|
|
669
|
+
* { collateralAmount: Amount<'nat'>; debtAmount: Amount<'nat'> }
|
|
670
|
+
* >} vaultData
|
|
609
671
|
* @param {Amount<'nat'>} totalCollateral
|
|
610
672
|
*/
|
|
611
673
|
planProceedsDistribution(
|
|
@@ -661,13 +723,14 @@ export const prepareVaultManagerKit = (
|
|
|
661
723
|
},
|
|
662
724
|
|
|
663
725
|
/**
|
|
664
|
-
* This is designed to tolerate an incomplete plan, in case
|
|
665
|
-
* an error during its calculation.
|
|
666
|
-
*
|
|
726
|
+
* This is designed to tolerate an incomplete plan, in case
|
|
727
|
+
* calculateDistributionPlan encounters an error during its calculation.
|
|
728
|
+
* We don't have a way to induce such errors in CI so we've done so
|
|
729
|
+
* manually in dev and verified this function recovers as expected.
|
|
667
730
|
*
|
|
668
731
|
* @param {object} obj
|
|
669
732
|
* @param {import('./proceeds.js').DistributionPlan} obj.plan
|
|
670
|
-
* @param {
|
|
733
|
+
* @param {Vault[]} obj.vaultsInPlan
|
|
671
734
|
* @param {ZCFSeat} obj.liqSeat
|
|
672
735
|
* @param {Amount<'nat'>} obj.totalCollateral
|
|
673
736
|
* @param {Amount<'nat'>} obj.totalDebt
|
|
@@ -687,7 +750,7 @@ export const prepareVaultManagerKit = (
|
|
|
687
750
|
if (plan.transfersToVault.length > 0) {
|
|
688
751
|
const transfers = plan.transfersToVault.map(
|
|
689
752
|
([vaultIndex, amounts]) =>
|
|
690
|
-
/** @type {
|
|
753
|
+
/** @type {TransferPart} */ ([
|
|
691
754
|
liqSeat,
|
|
692
755
|
vaultsInPlan[vaultIndex].getVaultSeat(),
|
|
693
756
|
amounts,
|
|
@@ -773,10 +836,15 @@ export const prepareVaultManagerKit = (
|
|
|
773
836
|
* @param {Amount<'nat'>} collateralAmount
|
|
774
837
|
*/
|
|
775
838
|
maxDebtFor(collateralAmount) {
|
|
776
|
-
const {
|
|
839
|
+
const { state, facets } = this;
|
|
840
|
+
const { collateralBrand } = state;
|
|
777
841
|
const { storedCollateralQuote } = collateralEphemera(collateralBrand);
|
|
778
|
-
if (!storedCollateralQuote)
|
|
779
|
-
|
|
842
|
+
if (!storedCollateralQuote) {
|
|
843
|
+
facets.helper.observeQuoteNotifier();
|
|
844
|
+
|
|
845
|
+
// it might take an arbitrary amount of time to get a new quote
|
|
846
|
+
throw Fail`maxDebtFor called before a collateral quote was available for ${collateralBrand}`;
|
|
847
|
+
}
|
|
780
848
|
// use the lower price to prevent vault adjustments that put them imminently underwater
|
|
781
849
|
const collateralPrice = minimumPrice(
|
|
782
850
|
storedCollateralQuote,
|
|
@@ -840,9 +908,7 @@ export const prepareVaultManagerKit = (
|
|
|
840
908
|
const { descriptionScope } = this.state;
|
|
841
909
|
return `${descriptionScope}: ${base}`;
|
|
842
910
|
},
|
|
843
|
-
/**
|
|
844
|
-
* coefficient on existing debt to calculate new debt
|
|
845
|
-
*/
|
|
911
|
+
/** coefficient on existing debt to calculate new debt */
|
|
846
912
|
getCompoundedInterest() {
|
|
847
913
|
return this.state.compoundedInterest;
|
|
848
914
|
},
|
|
@@ -852,7 +918,8 @@ export const prepareVaultManagerKit = (
|
|
|
852
918
|
* @param {NormalizedDebt} oldDebtNormalized
|
|
853
919
|
* @param {Amount<'nat'>} oldCollateral
|
|
854
920
|
* @param {VaultId} vaultId
|
|
855
|
-
* @param {import('./vault.js').VaultPhase} vaultPhase at the end of
|
|
921
|
+
* @param {import('./vault.js').VaultPhase} vaultPhase at the end of
|
|
922
|
+
* whatever change updated balances
|
|
856
923
|
* @param {Vault} vault
|
|
857
924
|
* @returns {void}
|
|
858
925
|
*/
|
|
@@ -937,9 +1004,7 @@ export const prepareVaultManagerKit = (
|
|
|
937
1004
|
return factoryPowers.getGovernedParams(collateralBrand);
|
|
938
1005
|
},
|
|
939
1006
|
|
|
940
|
-
/**
|
|
941
|
-
* @param {ZCFSeat} seat
|
|
942
|
-
*/
|
|
1007
|
+
/** @param {ZCFSeat} seat */
|
|
943
1008
|
async makeVaultKit(seat) {
|
|
944
1009
|
const {
|
|
945
1010
|
state,
|
|
@@ -963,7 +1028,6 @@ export const prepareVaultManagerKit = (
|
|
|
963
1028
|
|
|
964
1029
|
try {
|
|
965
1030
|
// TODO `await` is allowed until the above ordering is fixed
|
|
966
|
-
// eslint-disable-next-line @jessie.js/no-nested-await
|
|
967
1031
|
const vaultKit = await vault.initVaultKit(seat, vaultStorageNode);
|
|
968
1032
|
// initVaultKit calls back to handleBalanceChange() which will add the
|
|
969
1033
|
// vault to prioritizedVaults
|
|
@@ -1017,11 +1081,17 @@ export const prepareVaultManagerKit = (
|
|
|
1017
1081
|
},
|
|
1018
1082
|
|
|
1019
1083
|
getCollateralQuote() {
|
|
1084
|
+
const { state, facets } = this;
|
|
1020
1085
|
const { storedCollateralQuote } = collateralEphemera(
|
|
1021
|
-
|
|
1086
|
+
state.collateralBrand,
|
|
1022
1087
|
);
|
|
1023
|
-
if (!storedCollateralQuote)
|
|
1088
|
+
if (!storedCollateralQuote) {
|
|
1089
|
+
facets.helper.observeQuoteNotifier();
|
|
1090
|
+
|
|
1091
|
+
// it might take an arbitrary amount of time to get a new quote
|
|
1024
1092
|
throw Fail`getCollateralQuote called before a collateral quote was available`;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1025
1095
|
return storedCollateralQuote;
|
|
1026
1096
|
},
|
|
1027
1097
|
|
|
@@ -1034,21 +1104,24 @@ export const prepareVaultManagerKit = (
|
|
|
1034
1104
|
const { storedCollateralQuote } = collateralEphemera(
|
|
1035
1105
|
state.collateralBrand,
|
|
1036
1106
|
);
|
|
1037
|
-
if (!storedCollateralQuote)
|
|
1038
|
-
|
|
1107
|
+
if (!storedCollateralQuote) {
|
|
1108
|
+
facets.helper.observeQuoteNotifier();
|
|
1109
|
+
|
|
1110
|
+
// it might take an arbitrary amount of time to get a new quote
|
|
1111
|
+
throw Fail`lockOraclePrices called before a collateral quote was available for ${state.collateralBrand}`;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1039
1114
|
trace(
|
|
1040
|
-
`
|
|
1115
|
+
`lockOraclePrices`,
|
|
1041
1116
|
getAmountIn(storedCollateralQuote),
|
|
1042
1117
|
getAmountOut(storedCollateralQuote),
|
|
1043
1118
|
);
|
|
1044
1119
|
|
|
1045
1120
|
state.lockedQuote = storedCollateralQuote;
|
|
1046
|
-
facets.helper.writeMetrics();
|
|
1121
|
+
void facets.helper.writeMetrics();
|
|
1047
1122
|
return storedCollateralQuote;
|
|
1048
1123
|
},
|
|
1049
|
-
/**
|
|
1050
|
-
* @param {AuctioneerPublicFacet} auctionPF
|
|
1051
|
-
*/
|
|
1124
|
+
/** @param {ERef<AuctioneerPublicFacet>} auctionPF */
|
|
1052
1125
|
async liquidateVaults(auctionPF) {
|
|
1053
1126
|
const { state, facets } = this;
|
|
1054
1127
|
const { self, helper } = facets;
|
|
@@ -1061,11 +1134,28 @@ export const prepareVaultManagerKit = (
|
|
|
1061
1134
|
} = state;
|
|
1062
1135
|
trace(collateralBrand, 'considering liquidation');
|
|
1063
1136
|
|
|
1137
|
+
if (!lockedQuote) {
|
|
1138
|
+
// By design, the first cycle of auction may call this before a quote is locked
|
|
1139
|
+
// because the schedule is global at the vaultDirector level, and if a manager
|
|
1140
|
+
// starts after the price lock time there's nothing to be done.
|
|
1141
|
+
// NB: this message should not log repeatedly.
|
|
1142
|
+
console.error(
|
|
1143
|
+
'Skipping liquidation because no quote is locked yet (may happen with new manager)',
|
|
1144
|
+
);
|
|
1145
|
+
return;
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
const { storedCollateralQuote: collateralQuoteBefore } =
|
|
1149
|
+
collateralEphemera(this.state.collateralBrand);
|
|
1150
|
+
if (!collateralQuoteBefore) {
|
|
1151
|
+
console.error(
|
|
1152
|
+
'Skipping liquidation because collateralQuote is missing',
|
|
1153
|
+
);
|
|
1154
|
+
return;
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1064
1157
|
const { prioritizedVaults } = collateralEphemera(collateralBrand);
|
|
1065
|
-
|
|
1066
|
-
lockedQuote ||
|
|
1067
|
-
Fail`Must have locked a quote before liquidating vaults.`;
|
|
1068
|
-
assert(lockedQuote); // redundant with previous line
|
|
1158
|
+
prioritizedVaults || Fail`prioritizedVaults missing from ephemera`;
|
|
1069
1159
|
|
|
1070
1160
|
const liqMargin = self.getGovernedParams().getLiquidationMargin();
|
|
1071
1161
|
|
|
@@ -1087,6 +1177,7 @@ export const prepareVaultManagerKit = (
|
|
|
1087
1177
|
state.lockedQuote = undefined;
|
|
1088
1178
|
|
|
1089
1179
|
if (vaultData.getSize() === 0) {
|
|
1180
|
+
void helper.writeMetrics();
|
|
1090
1181
|
return;
|
|
1091
1182
|
}
|
|
1092
1183
|
trace(
|
|
@@ -1126,7 +1217,10 @@ export const prepareVaultManagerKit = (
|
|
|
1126
1217
|
const { plan, vaultsInPlan } = helper.planProceedsDistribution(
|
|
1127
1218
|
proceeds,
|
|
1128
1219
|
totalDebt,
|
|
1129
|
-
|
|
1220
|
+
// If a quote was available at the start of liquidation, but is no
|
|
1221
|
+
// longer, using the earlier price is better than failing to
|
|
1222
|
+
// distribute proceeds
|
|
1223
|
+
storedCollateralQuote || collateralQuoteBefore,
|
|
1130
1224
|
vaultData,
|
|
1131
1225
|
totalCollateral,
|
|
1132
1226
|
);
|
|
@@ -1150,7 +1244,7 @@ export const prepareVaultManagerKit = (
|
|
|
1150
1244
|
liquidatingVaults.delete(vault);
|
|
1151
1245
|
}
|
|
1152
1246
|
|
|
1153
|
-
|
|
1247
|
+
void helper.writeMetrics();
|
|
1154
1248
|
},
|
|
1155
1249
|
},
|
|
1156
1250
|
},
|
|
@@ -1174,7 +1268,12 @@ export const prepareVaultManagerKit = (
|
|
|
1174
1268
|
},
|
|
1175
1269
|
);
|
|
1176
1270
|
|
|
1177
|
-
/**
|
|
1271
|
+
/**
|
|
1272
|
+
* @param {Omit<
|
|
1273
|
+
* Parameters<typeof makeVaultManagerKitInternal>[0],
|
|
1274
|
+
* 'metricsStorageNode'
|
|
1275
|
+
* >} externalParams
|
|
1276
|
+
*/
|
|
1178
1277
|
const makeVaultManagerKit = async externalParams => {
|
|
1179
1278
|
const metricsStorageNode = await E(
|
|
1180
1279
|
externalParams.storageNode,
|
|
@@ -1187,15 +1286,13 @@ export const prepareVaultManagerKit = (
|
|
|
1187
1286
|
return makeVaultManagerKit;
|
|
1188
1287
|
};
|
|
1189
1288
|
|
|
1289
|
+
/** @typedef {Awaited<ReturnType<ReturnType<typeof prepareVaultManagerKit>>>} VaultManagerKit */
|
|
1190
1290
|
/**
|
|
1191
|
-
* @typedef {
|
|
1192
|
-
|
|
1193
|
-
/**
|
|
1194
|
-
* @typedef {VaultManagerKit['self']} VaultManager
|
|
1195
|
-
* Each VaultManager manages a single collateral type.
|
|
1291
|
+
* @typedef {VaultManagerKit['self']} VaultManager Each VaultManager manages a
|
|
1292
|
+
* single collateral type.
|
|
1196
1293
|
*
|
|
1197
|
-
*
|
|
1198
|
-
*
|
|
1294
|
+
* It manages some number of outstanding debt positions, each called a Vault,
|
|
1295
|
+
* for which the collateral is provided in exchange for borrowed Minted.
|
|
1199
1296
|
*/
|
|
1200
1297
|
/** @typedef {VaultManagerKit['collateral']} CollateralManager */
|
|
1201
1298
|
|