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