@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
@@ -1,8 +1,8 @@
1
- import '@agoric/governance/exported.js';
2
- import '@agoric/zoe/exported.js';
3
- import '@agoric/zoe/src/contracts/exported.js';
1
+ /// <reference types="@agoric/internal/exported" />
2
+ /// <reference types="@agoric/governance/exported" />
3
+ /// <reference types="@agoric/zoe/exported" />
4
4
 
5
- import { AmountMath } from '@agoric/ertp';
5
+ import { AmountMath, RatioShape } from '@agoric/ertp';
6
6
  import { mustMatch } from '@agoric/store';
7
7
  import { M, prepareExoClassKit } from '@agoric/vat-data';
8
8
 
@@ -27,6 +27,11 @@ import {
27
27
  priceFrom,
28
28
  } from './util.js';
29
29
 
30
+ /**
31
+ * @import {Baggage} from '@agoric/vat-data';
32
+ * @import {PriceAuthority, PriceDescription, PriceQuote, PriceQuoteValue, PriceQuery,} from '@agoric/zoe/tools/types.js';
33
+ */
34
+
30
35
  const { Fail } = assert;
31
36
  const { makeEmpty } = AmountMath;
32
37
 
@@ -34,34 +39,38 @@ const DEFAULT_DECIMALS = 9;
34
39
 
35
40
  /**
36
41
  * @file The book represents the collateral-specific state of an ongoing
37
- * auction. It holds the book, the capturedPrice, and the collateralSeat that has
38
- * the allocation of assets for sale.
42
+ * auction. It holds the book, the capturedPrice, and the collateralSeat that
43
+ * has the allocation of assets for sale.
44
+ *
45
+ * The book contains orders for the collateral. It holds two kinds of orders:
39
46
  *
40
- * The book contains orders for the collateral. It holds two kinds of
41
- * orders:
42
47
  * - Prices express the bidding offer in terms of a Bid amount
43
- * - ScaledBids express the offer in terms of a discount (or markup) from the
44
- * most recent oracle price.
48
+ * - ScaledBids express the offer in terms of a discount (or markup) from the most
49
+ * recent oracle price.
45
50
  *
46
- * Offers can be added in three ways. 1) When the auction is not active, prices
47
- * are automatically added to the appropriate collection. When the auction is
48
- * active, 2) if a new offer is at or above the current price, it will be
49
- * settled immediately; 2) If the offer is below the current price, it will be
50
- * added in the appropriate place and settled when the price reaches that level.
51
+ * Offers can be added in three ways. 1) When the auction is not active, prices
52
+ * are automatically added to the appropriate collection. When the auction is
53
+ * active, 2) if a new offer is at or above the current price, it will be
54
+ * settled immediately; 2) If the offer is below the current price, it will be
55
+ * added in the appropriate place and settled when the price reaches that
56
+ * level.
51
57
  */
52
58
 
53
59
  const trace = makeTracer('AucBook', true);
54
60
 
55
61
  /**
56
62
  * @typedef {{
57
- * maxBuy: Amount<'nat'>
63
+ * maxBuy: Amount<'nat'>;
58
64
  * } & {
59
- * exitAfterBuy?: boolean,
60
- * } & ({
61
- * offerPrice: Ratio,
62
- * } | {
63
- * offerBidScaling: Ratio,
64
- * })} OfferSpec
65
+ * exitAfterBuy?: boolean;
66
+ * } & (
67
+ * | {
68
+ * offerPrice: Ratio;
69
+ * }
70
+ * | {
71
+ * offerBidScaling: Ratio;
72
+ * }
73
+ * )} OfferSpec
65
74
  */
66
75
  /**
67
76
  * @param {Brand<'nat'>} bidBrand
@@ -84,21 +93,21 @@ export const makeOfferSpecShape = (bidBrand, collateralBrand) => {
84
93
  );
85
94
  };
86
95
 
87
- /** @typedef {import('@agoric/vat-data').Baggage} Baggage */
88
-
89
96
  /**
90
97
  * @typedef {object} BookDataNotification
91
- *
92
- * @property {Ratio | null} startPrice identifies the priceAuthority and price
93
- * @property {Ratio | null} currentPriceLevel the price at the current auction tier
94
- * @property {Amount<'nat'> | null} startProceedsGoal The proceeds the sellers were targeting to raise
95
- * @property {Amount<'nat'> | null} remainingProceedsGoal The remainder of
96
- * the proceeds the sellers were targeting to raise
97
- * @property {Amount<'nat'> | undefined} proceedsRaised The proceeds raised so far in the auction
98
- * @property {Amount<'nat'>} startCollateral How much collateral was
99
- * available for sale at the start. (If more is deposited later, it'll be
100
- * added in.)
101
- * @property {Amount<'nat'> | null} collateralAvailable The amount of collateral remaining
98
+ * @property {Ratio | null} startPrice identifies the priceAuthority and price
99
+ * @property {Ratio | null} currentPriceLevel the price at the current auction
100
+ * tier
101
+ * @property {Amount<'nat'> | null} startProceedsGoal The proceeds the sellers
102
+ * were targeting to raise
103
+ * @property {Amount<'nat'> | null} remainingProceedsGoal The remainder of the
104
+ * proceeds the sellers were targeting to raise
105
+ * @property {Amount<'nat'> | undefined} proceedsRaised The proceeds raised so
106
+ * far in the auction
107
+ * @property {Amount<'nat'>} startCollateral How much collateral was available
108
+ * for sale at the start. (If more is deposited later, it'll be added in.)
109
+ * @property {Amount<'nat'> | null} collateralAvailable The amount of collateral
110
+ * remaining
102
111
  */
103
112
 
104
113
  /**
@@ -118,7 +127,7 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
118
127
  bidHoldingSeat: M.any(),
119
128
  bidAmountShape: M.any(),
120
129
  priceAuthority: M.any(),
121
- updatingOracleQuote: M.any(),
130
+ updatingOracleQuote: M.or(RatioShape, M.null()),
122
131
  bookDataKit: M.any(),
123
132
  priceBook: M.any(),
124
133
  scaledBidBook: M.any(),
@@ -141,11 +150,6 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
141
150
  */
142
151
  (bidBrand, collateralBrand, pAuthority, node) => {
143
152
  assertAllDefined({ bidBrand, collateralBrand, pAuthority });
144
- const zeroBid = makeEmpty(bidBrand);
145
- const zeroRatio = makeRatioFromAmounts(
146
- zeroBid,
147
- AmountMath.make(collateralBrand, 1n),
148
- );
149
153
 
150
154
  // these don't have to be durable, since we're currently assuming that upgrade
151
155
  // from a quiescent state is sufficient. When the auction is quiescent, there
@@ -182,7 +186,7 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
182
186
  bidAmountShape,
183
187
 
184
188
  priceAuthority: pAuthority,
185
- updatingOracleQuote: zeroRatio,
189
+ updatingOracleQuote: /** @type {Ratio | null} */ (null),
186
190
 
187
191
  bookDataKit,
188
192
 
@@ -231,8 +235,8 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
231
235
  {
232
236
  helper: {
233
237
  /**
234
- * remove the key from the appropriate book, indicated by whether the price
235
- * is defined.
238
+ * remove the key from the appropriate book, indicated by whether the
239
+ * price is defined.
236
240
  *
237
241
  * @param {string} key
238
242
  * @param {Ratio | undefined} price
@@ -247,8 +251,8 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
247
251
  },
248
252
 
249
253
  /**
250
- * Update the entry in the appropriate book, indicated by whether the price
251
- * is defined.
254
+ * Update the entry in the appropriate book, indicated by whether the
255
+ * price is defined.
252
256
  *
253
257
  * @param {string} key
254
258
  * @param {Amount} collateralSold
@@ -264,7 +268,8 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
264
268
  },
265
269
 
266
270
  /**
267
- * Settle with seat. The caller is responsible for updating the book, if any.
271
+ * Settle with seat. The caller is responsible for updating the book, if
272
+ * any.
268
273
  *
269
274
  * @param {ZCFSeat} seat
270
275
  * @param {Amount<'nat'>} collateralWanted
@@ -341,15 +346,16 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
341
346
  },
342
347
 
343
348
  /**
344
- * Accept an offer expressed as a price. If the auction is active, attempt to
345
- * buy collateral. If any of the offer remains add it to the book.
349
+ * Accept an offer expressed as a price. If the auction is active,
350
+ * attempt to buy collateral. If any of the offer remains add it to the
351
+ * book.
346
352
  *
347
- * @param {ZCFSeat} seat
348
- * @param {Ratio} price
349
- * @param {Amount<'nat'>} maxBuy
350
- * @param {object} opts
351
- * @param {boolean} opts.trySettle
352
- * @param {boolean} [opts.exitAfterBuy]
353
+ * @param {ZCFSeat} seat
354
+ * @param {Ratio} price
355
+ * @param {Amount<'nat'>} maxBuy
356
+ * @param {object} opts
357
+ * @param {boolean} opts.trySettle
358
+ * @param {boolean} [opts.exitAfterBuy]
353
359
  */
354
360
  acceptPriceOffer(
355
361
  seat,
@@ -388,16 +394,16 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
388
394
  },
389
395
 
390
396
  /**
391
- * Accept an offer expressed as a discount (or markup). If the auction is
392
- * active, attempt to buy collateral. If any of the offer remains add it to
393
- * the book.
397
+ * Accept an offer expressed as a discount (or markup). If the auction
398
+ * is active, attempt to buy collateral. If any of the offer remains add
399
+ * it to the book.
394
400
  *
395
- * @param {ZCFSeat} seat
396
- * @param {Ratio} bidScaling
397
- * @param {Amount<'nat'>} maxBuy
398
- * @param {object} opts
399
- * @param {boolean} opts.trySettle
400
- * @param {boolean} [opts.exitAfterBuy]
401
+ * @param {ZCFSeat} seat
402
+ * @param {Ratio} bidScaling
403
+ * @param {Amount<'nat'>} maxBuy
404
+ * @param {object} opts
405
+ * @param {boolean} opts.trySettle
406
+ * @param {boolean} [opts.exitAfterBuy]
401
407
  */
402
408
  acceptScaledBidOffer(
403
409
  seat,
@@ -460,16 +466,58 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
460
466
  });
461
467
  return state.bookDataKit.recorder.write(bookData);
462
468
  },
469
+ observeQuoteNotifier() {
470
+ const { state, facets } = this;
471
+ const { collateralBrand, bidBrand, priceAuthority } = state;
472
+
473
+ trace('observing');
474
+
475
+ void E.when(
476
+ E(collateralBrand).getDisplayInfo(),
477
+ ({ decimalPlaces = DEFAULT_DECIMALS }) => {
478
+ const quoteNotifier = E(priceAuthority).makeQuoteNotifier(
479
+ AmountMath.make(collateralBrand, 10n ** BigInt(decimalPlaces)),
480
+ bidBrand,
481
+ );
482
+ void observeNotifier(quoteNotifier, {
483
+ updateState: quote => {
484
+ trace(
485
+ `BOOK notifier ${priceFrom(quote).numerator.value}/${
486
+ priceFrom(quote).denominator.value
487
+ }`,
488
+ );
489
+ state.updatingOracleQuote = priceFrom(quote);
490
+ },
491
+ fail: reason => {
492
+ trace(
493
+ `Failure from quoteNotifier (${reason}) setting to null`,
494
+ );
495
+ // lack of quote will trigger restart
496
+ state.updatingOracleQuote = null;
497
+ },
498
+ finish: done => {
499
+ trace(
500
+ `quoteNotifier invoked finish(${done}). setting quote to null`,
501
+ );
502
+ // lack of quote will trigger restart
503
+ state.updatingOracleQuote = null;
504
+ },
505
+ });
506
+ },
507
+ );
508
+
509
+ void facets.helper.publishBookData();
510
+ },
463
511
  },
464
512
  self: {
465
513
  /**
466
514
  * @param {Amount<'nat'>} assetAmount
467
515
  * @param {ZCFSeat} sourceSeat
468
516
  * @param {Amount<'nat'>} [proceedsGoal] an amount that the depositor
469
- * would like to raise. The auction is requested to not sell more
470
- * collateral than required to raise that much. The auctioneer might
471
- * sell more if there is more than one supplier of collateral, and
472
- * they request inconsistent limits.
517
+ * would like to raise. The auction is requested to not sell more
518
+ * collateral than required to raise that much. The auctioneer might
519
+ * sell more if there is more than one supplier of collateral, and
520
+ * they request inconsistent limits.
473
521
  */
474
522
  addAssets(assetAmount, sourceSeat, proceedsGoal) {
475
523
  const { state, facets } = this;
@@ -547,9 +595,12 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
547
595
 
548
596
  trace(this.state.collateralBrand, 'settleAtNewRate', reduction);
549
597
  const { capturedPriceForRound, priceBook, scaledBidBook } = state;
550
- capturedPriceForRound !== null ||
551
- Fail`price must be captured before auction starts`;
552
- assert(capturedPriceForRound);
598
+ if (!capturedPriceForRound) {
599
+ console.error(
600
+ `⚠️No price for ${this.state.collateralBrand}, skipping auction.`,
601
+ );
602
+ return;
603
+ }
553
604
 
554
605
  state.curAuctionPrice = multiplyRatios(
555
606
  reduction,
@@ -619,6 +670,12 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
619
670
  const { facets, state } = this;
620
671
 
621
672
  trace(`capturing oracle price `, state.updatingOracleQuote);
673
+ if (!state.updatingOracleQuote) {
674
+ // if the price has feed has died, try restarting it.
675
+ facets.helper.observeQuoteNotifier();
676
+ return;
677
+ }
678
+
622
679
  state.capturedPriceForRound = state.updatingOracleQuote;
623
680
  void facets.helper.publishBookData();
624
681
  },
@@ -718,43 +775,18 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
718
775
  finish: ({ state, facets }) => {
719
776
  const { collateralBrand, bidBrand, priceAuthority } = state;
720
777
  assertAllDefined({ collateralBrand, bidBrand, priceAuthority });
721
- void E.when(
722
- E(collateralBrand).getDisplayInfo(),
723
- ({ decimalPlaces = DEFAULT_DECIMALS }) => {
724
- // TODO(#6946) use this to keep a current price that can be published in state.
725
- const quoteNotifier = E(priceAuthority).makeQuoteNotifier(
726
- AmountMath.make(collateralBrand, 10n ** BigInt(decimalPlaces)),
727
- bidBrand,
728
- );
729
- void observeNotifier(quoteNotifier, {
730
- updateState: quote => {
731
- trace(
732
- `BOOK notifier ${priceFrom(quote).numerator.value}/${
733
- priceFrom(quote).denominator.value
734
- }`,
735
- );
736
- state.updatingOracleQuote = priceFrom(quote);
737
- },
738
- fail: reason => {
739
- throw Error(
740
- `auction observer of ${collateralBrand} failed: ${reason}`,
741
- );
742
- },
743
- finish: done => {
744
- throw Error(
745
- `auction observer for ${collateralBrand} died: ${done}`,
746
- );
747
- },
748
- });
749
- },
750
- );
751
- void facets.helper.publishBookData();
778
+
779
+ facets.helper.observeQuoteNotifier();
752
780
  },
753
781
  stateShape: AuctionBookStateShape,
754
782
  },
755
783
  );
756
784
 
757
- /** @type {(...args: Parameters<typeof makeAuctionBookKit>) => ReturnType<typeof makeAuctionBookKit>['self']} */
785
+ /**
786
+ * @type {(
787
+ * ...args: Parameters<typeof makeAuctionBookKit>
788
+ * ) => ReturnType<typeof makeAuctionBookKit>['self']}
789
+ */
758
790
  const makeAuctionBook = (...args) => makeAuctionBookKit(...args).self;
759
791
  return makeAuctionBook;
760
792
  };
@@ -0,0 +1,69 @@
1
+ export function distributeProportionalSharesWithLimits(unsoldCollateral: Amount<"nat">, proceeds: Amount<"nat">, deposits: {
2
+ seat: ZCFSeat;
3
+ amount: Amount<"nat">;
4
+ goal: Amount<"nat">;
5
+ }[], collateralSeat: ZCFSeat, bidHoldingSeat: ZCFSeat, collateralKeyword: string, reserveSeat: ZCFSeat, brand: Brand): TransferPart[];
6
+ export function start(zcf: ZCF<GovernanceTerms<typeof auctioneerParamTypes> & {
7
+ timerService: import("@agoric/time").TimerService;
8
+ reservePublicFacet: AssetReservePublicFacet;
9
+ priceAuthority: PriceAuthority;
10
+ }>, privateArgs: {
11
+ initialPoserInvitation: Invitation;
12
+ storageNode: StorageNode;
13
+ marshaller: Marshaller;
14
+ }, baggage: Baggage): Promise<{
15
+ publicFacet: globalThis.GovernedPublicFacet<{
16
+ getElectorate: () => import("@agoric/governance/src/types.js").ParamValueForType<"invitation">;
17
+ getStartFrequency: () => import("@agoric/governance/src/types.js").ParamValueForType<"relativeTime">;
18
+ getClockStep: () => import("@agoric/governance/src/types.js").ParamValueForType<"relativeTime">;
19
+ getStartingRate: () => import("@agoric/governance/src/types.js").ParamValueForType<"nat">;
20
+ getLowestRate: () => import("@agoric/governance/src/types.js").ParamValueForType<"nat">;
21
+ getDiscountStep: () => import("@agoric/governance/src/types.js").ParamValueForType<"nat">;
22
+ getAuctionStartDelay: () => import("@agoric/governance/src/types.js").ParamValueForType<"relativeTime">;
23
+ getPriceLockPeriod: () => import("@agoric/governance/src/types.js").ParamValueForType<"relativeTime">;
24
+ /** @param {Brand<'nat'>} collateralBrand */
25
+ makeBidInvitation(collateralBrand: Brand<"nat">): Promise<Invitation<string, import("./auctionBook.js").OfferSpec>>;
26
+ getSchedules(): {
27
+ liveAuctionSchedule: import("./scheduler.js").Schedule | null;
28
+ nextAuctionSchedule: import("./scheduler.js").Schedule | null;
29
+ };
30
+ getScheduleUpdates(): globalThis.Subscriber<import("./scheduler.js").ScheduleNotification>;
31
+ getBookDataUpdates(brand: any): globalThis.Subscriber<import("./auctionBook.js").BookDataNotification>;
32
+ getPublicTopics(brand: any): {
33
+ bookData: import("@agoric/zoe/src/contractSupport/topics.js").PublicTopic<import("./auctionBook.js").BookDataNotification>;
34
+ } | {
35
+ schedule: import("@agoric/zoe/src/contractSupport/topics.js").PublicTopic<import("./scheduler.js").ScheduleNotification>;
36
+ };
37
+ makeDepositInvitation: () => Promise<Invitation<string, {
38
+ goal: Amount<"nat">;
39
+ }>>;
40
+ }>;
41
+ creatorFacet: globalThis.GovernedCreatorFacet<{
42
+ /**
43
+ * @param {Issuer<'nat'>} issuer
44
+ * @param {Keyword} kwd
45
+ */
46
+ addBrand(issuer: Issuer<"nat">, kwd: Keyword): Promise<void>;
47
+ /** @returns {Promise<import('./scheduler.js').FullSchedule>} */
48
+ getSchedule(): Promise<import("./scheduler.js").FullSchedule>;
49
+ } & import("@endo/marshal").RemotableObject<`Alleged: ${string}`> & import("@endo/eventual-send").RemotableBrand<{}, {
50
+ /**
51
+ * @param {Issuer<'nat'>} issuer
52
+ * @param {Keyword} kwd
53
+ */
54
+ addBrand(issuer: Issuer<"nat">, kwd: Keyword): Promise<void>;
55
+ /** @returns {Promise<import('./scheduler.js').FullSchedule>} */
56
+ getSchedule(): Promise<import("./scheduler.js").FullSchedule>;
57
+ }>>;
58
+ }>;
59
+ /** @typedef {ContractOf<typeof start>} AuctioneerContract */
60
+ /** @typedef {AuctioneerContract['publicFacet']} AuctioneerPublicFacet */
61
+ /** @typedef {AuctioneerContract['creatorFacet']} AuctioneerCreatorFacet */
62
+ export const AuctionPFShape: import("@endo/patterns").Matcher;
63
+ export type AuctioneerContract = ContractOf<typeof start>;
64
+ export type AuctioneerPublicFacet = AuctioneerContract["publicFacet"];
65
+ export type AuctioneerCreatorFacet = AuctioneerContract["creatorFacet"];
66
+ import { auctioneerParamTypes } from './params.js';
67
+ import type { PriceAuthority } from '@agoric/zoe/tools/types.js';
68
+ import type { Baggage } from '@agoric/vat-data';
69
+ //# sourceMappingURL=auctioneer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auctioneer.d.ts","sourceRoot":"","sources":["auctioneer.js"],"names":[],"mappings":"AAgLO,yEAXI,MAAM,CAAC,KAAK,CAAC,YACb,MAAM,CAAC,KAAK,CAAC,YACb;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;CAAE,EAAE,kBAC/D,OAAO,kBACP,OAAO,qBAEP,MAAM,eAEN,OAAO,SACP,KAAK,kBAgNf;AAiBM,2BAdI,GAAG,CACb,eAAmB,CAAC,OAAO,oBAAoB,CAAC,GAAG;IACnD,YAAkB,EAAE,OAAO,cAAc,EAAE,YAAY,CAAC;IACxD,kBAAwB,EAAE,uBAAuB,CAAC;IAClD,cAAoB,EAAE,cAAc,CAAC;CAChC,CACF,eACO;IACV,sBAA0B,EAAE,UAAU,CAAC;IACvC,WAAe,EAAE,WAAW,CAAC;IAC7B,UAAc,EAAE,UAAU,CAAC;CACxB,WACO,OAAO;;;;;;;;;;QAyOZ,4CAA4C;2CAAhC,KAAK,CAAC,KAAK,CAAC;;;;;;;;;;;;;kBApCT,MAAM,CAAC,KAAK,CAAC;;;;QAmG5B;;;WAGG;yBAFQ,MAAM,CAAC,KAAK,CAAC,OACb,OAAO;QAwBlB,gEAAgE;uBAAlD,OAAO,CAAC,OAAO,gBAAgB,EAAE,YAAY,CAAC;;QA1B5D;;;WAGG;yBAFQ,MAAM,CAAC,KAAK,CAAC,OACb,OAAO;QAwBlB,gEAAgE;uBAAlD,OAAO,CAAC,OAAO,gBAAgB,EAAE,YAAY,CAAC;;GAQjE;AAED,6DAA6D;AAC7D,yEAAyE;AACzE,2EAA2E;AAE3E,8DAAkE;iCAJpD,UAAU,CAAC,OAAO,KAAK,CAAC;oCACxB,kBAAkB,CAAC,aAAa,CAAC;qCACjC,kBAAkB,CAAC,cAAc,CAAC;qCA3rBX,aAAa;oCAM2C,4BAA4B;6BAD/F,kBAAkB"}
@@ -1,6 +1,5 @@
1
- import '@agoric/governance/exported.js';
2
- import '@agoric/zoe/exported.js';
3
- import '@agoric/zoe/src/contracts/exported.js';
1
+ /// <reference types="@agoric/governance/exported" />
2
+ /// <reference types="@agoric/zoe/exported" />
4
3
 
5
4
  import { AmountMath, AmountShape, BrandShape } from '@agoric/ertp';
6
5
  import { handleParamGovernance } from '@agoric/governance';
@@ -35,7 +34,10 @@ import { auctioneerParamTypes } from './params.js';
35
34
  import { makeScheduler } from './scheduler.js';
36
35
  import { AuctionState } from './util.js';
37
36
 
38
- /** @typedef {import('@agoric/vat-data').Baggage} Baggage */
37
+ /**
38
+ * @import {Baggage} from '@agoric/vat-data';
39
+ * @import {PriceAuthority, PriceDescription, PriceQuote, PriceQuoteValue, PriceQuery,} from '@agoric/zoe/tools/types.js';
40
+ */
39
41
 
40
42
  const { Fail, quote: q } = assert;
41
43
  const { add, multiply } = natSafeMath;
@@ -43,11 +45,10 @@ const { add, multiply } = natSafeMath;
43
45
  const trace = makeTracer('Auction', true);
44
46
 
45
47
  /**
46
- * @file
47
- * In this file, 'Bid' is the name of the ERTP issuer used to purchase
48
- * collateral from various issuers. It's too confusing to also use Bid as a verb
49
- * or a description of amounts offered, so we've tried to find alternatives in
50
- * all those cases.
48
+ * @file In this file, 'Bid' is the name of the ERTP issuer used to purchase
49
+ * collateral from various issuers. It's too confusing to also use Bid as a
50
+ * verb or a description of amounts offered, so we've tried to find
51
+ * alternatives in all those cases.
51
52
  */
52
53
 
53
54
  const MINIMUM_BID_GIVE = 1n;
@@ -67,17 +68,19 @@ const makeBPRatio = (rate, bidBrand, collateralBrand = bidBrand) =>
67
68
  * The auction sold some amount of collateral, and raised a certain amount of
68
69
  * Bid. The excess collateral was returned as `unsoldCollateral`. The Bid amount
69
70
  * collected from the auction participants is `proceeds`.
71
+ *
70
72
  * Return a set of transfers for atomicRearrange() that distribute
71
73
  * `unsoldCollateral` and `proceeds` proportionally to each seat's deposited
72
74
  * amount. Any uneven split should be allocated to the reserve.
73
75
  *
74
76
  * @param {Amount} unsoldCollateral
75
77
  * @param {Amount} proceeds
76
- * @param {{seat: ZCFSeat, amount: Amount<'nat'>, goal: Amount<'nat'>}[]} deposits
78
+ * @param {{ seat: ZCFSeat; amount: Amount<'nat'>; goal: Amount<'nat'> }[]} deposits
77
79
  * @param {ZCFSeat} collateralSeat
78
- * @param {ZCFSeat} bidHoldingSeat seat with the Bid allocation to be distributed
80
+ * @param {ZCFSeat} bidHoldingSeat seat with the Bid allocation to be
81
+ * distributed
79
82
  * @param {string} collateralKeyword The Reserve will hold multiple collaterals,
80
- * so they need distinct keywords
83
+ * so they need distinct keywords
81
84
  * @param {ZCFSeat} reserveSeat
82
85
  * @param {Brand} brand
83
86
  */
@@ -97,7 +100,7 @@ const distributeProportionalShares = (
97
100
 
98
101
  const collShare = makeRatioFromAmounts(unsoldCollateral, totalCollDeposited);
99
102
  const currShare = makeRatioFromAmounts(proceeds, totalCollDeposited);
100
- /** @type {import('@agoric/zoe/src/contractSupport/atomicTransfer.js').TransferPart[]} */
103
+ /** @type {TransferPart[]} */
101
104
  const transfers = [];
102
105
  let proceedsLeft = proceeds;
103
106
  let collateralLeft = unsoldCollateral;
@@ -132,6 +135,7 @@ const distributeProportionalShares = (
132
135
  * The auction sold some amount of collateral, and raised a certain amount of
133
136
  * Bid. The excess collateral was returned as `unsoldCollateral`. The Bid amount
134
137
  * collected from the auction participants is `proceeds`.
138
+ *
135
139
  * Return a set of transfers for atomicRearrange() that distribute
136
140
  * `unsoldCollateral` and `proceeds` proportionally to each seat's deposited
137
141
  * amount. Any uneven split should be allocated to the reserve.
@@ -140,32 +144,33 @@ const distributeProportionalShares = (
140
144
  * outside the contract below.
141
145
  *
142
146
  * Some or all of the depositors may have specified a goal amount.
143
- * * A if none did, return collateral and Bid prorated to deposits.
144
- * * B if proceeds < proceedsGoal everyone gets prorated amounts of both.
145
- * * C if proceeds matches proceedsGoal, everyone gets the Bid they
146
- * asked for, plus enough collateral to reach the same proportional payout.
147
- * If any depositor's goal amount exceeded their share of the total,
148
- * we'll fall back to the first approach.
149
- * * D if proceeds > proceedsGoal && all depositors specified a limit,
150
- * all depositors get their goal first, then we distribute the
151
- * remainder (collateral and Bid) to get the same proportional payout.
152
- * * E if proceeds > proceedsGoal && some depositors didn't specify a
153
- * limit, depositors who did will get their goal first, then we distribute
154
- * the remainder (collateral and Bid) to get the same proportional
155
- * payout. If any depositor's goal amount exceeded their share of the
156
- * total, we'll fall back as above.
157
- * Think of it this way: those who specified a limit want as much collateral
158
- * back as possible, consistent with raising a certain amount of Bid. Those
159
- * who didn't specify a limit are trying to sell collateral, and would prefer to
160
- * have as much as possible converted to Bid.
147
+ *
148
+ * - A if none did, return collateral and Bid prorated to deposits.
149
+ * - B if proceeds < proceedsGoal everyone gets prorated amounts of both.
150
+ * - C if proceeds matches proceedsGoal, everyone gets the Bid they asked for,
151
+ * plus enough collateral to reach the same proportional payout. If any
152
+ * depositor's goal amount exceeded their share of the total, we'll fall back
153
+ * to the first approach.
154
+ * - D if proceeds > proceedsGoal && all depositors specified a limit, all
155
+ * depositors get their goal first, then we distribute the remainder
156
+ * (collateral and Bid) to get the same proportional payout.
157
+ * - E if proceeds > proceedsGoal && some depositors didn't specify a limit,
158
+ * depositors who did will get their goal first, then we distribute the
159
+ * remainder (collateral and Bid) to get the same proportional payout. If any
160
+ * depositor's goal amount exceeded their share of the total, we'll fall back
161
+ * as above. Think of it this way: those who specified a limit want as much
162
+ * collateral back as possible, consistent with raising a certain amount of
163
+ * Bid. Those who didn't specify a limit are trying to sell collateral, and
164
+ * would prefer to have as much as possible converted to Bid.
161
165
  *
162
166
  * @param {Amount<'nat'>} unsoldCollateral
163
167
  * @param {Amount<'nat'>} proceeds
164
- * @param {{seat: ZCFSeat, amount: Amount<'nat'>, goal: Amount<'nat'>}[]} deposits
168
+ * @param {{ seat: ZCFSeat; amount: Amount<'nat'>; goal: Amount<'nat'> }[]} deposits
165
169
  * @param {ZCFSeat} collateralSeat
166
- * @param {ZCFSeat} bidHoldingSeat seat with the Bid allocation to be distributed
170
+ * @param {ZCFSeat} bidHoldingSeat seat with the Bid allocation to be
171
+ * distributed
167
172
  * @param {string} collateralKeyword The Reserve will hold multiple collaterals,
168
- * so they need distinct keywords
173
+ * so they need distinct keywords
169
174
  * @param {ZCFSeat} reserveSeat
170
175
  * @param {Brand} brand
171
176
  */
@@ -255,7 +260,7 @@ export const distributeProportionalSharesWithLimits = (
255
260
  // collateral to reach their share. Then see what's left, and allocate it
256
261
  // among the remaining depositors. Escape to distributeProportionalShares if
257
262
  // anything doesn't work.
258
- /** @type {import('@agoric/zoe/src/contractSupport/atomicTransfer.js').TransferPart[]} */
263
+ /** @type {TransferPart[]} */
259
264
  const transfers = [];
260
265
  let proceedsLeft = proceeds;
261
266
  let collateralLeft = unsoldCollateral;
@@ -378,15 +383,17 @@ export const distributeProportionalSharesWithLimits = (
378
383
  };
379
384
 
380
385
  /**
381
- * @param {ZCF<GovernanceTerms<typeof auctioneerParamTypes> & {
382
- * timerService: import('@agoric/time/src/types').TimerService,
383
- * reservePublicFacet: AssetReservePublicFacet,
384
- * priceAuthority: PriceAuthority
385
- * }>} zcf
386
+ * @param {ZCF<
387
+ * GovernanceTerms<typeof auctioneerParamTypes> & {
388
+ * timerService: import('@agoric/time').TimerService;
389
+ * reservePublicFacet: AssetReservePublicFacet;
390
+ * priceAuthority: PriceAuthority;
391
+ * }
392
+ * >} zcf
386
393
  * @param {{
387
- * initialPoserInvitation: Invitation,
388
- * storageNode: StorageNode,
389
- * marshaller: Marshaller
394
+ * initialPoserInvitation: Invitation;
395
+ * storageNode: StorageNode;
396
+ * marshaller: Marshaller;
390
397
  * }} privateArgs
391
398
  * @param {Baggage} baggage
392
399
  */
@@ -399,7 +406,12 @@ export const start = async (zcf, privateArgs, baggage) => {
399
406
 
400
407
  /** @type {MapStore<Brand, import('./auctionBook.js').AuctionBook>} */
401
408
  const books = provideDurableMapStore(baggage, 'auctionBooks');
402
- /** @type {MapStore<Brand, Array<{ seat: ZCFSeat, amount: Amount<'nat'>, goal: Amount<'nat'>}>>} */
409
+ /**
410
+ * @type {MapStore<
411
+ * Brand,
412
+ * { seat: ZCFSeat; amount: Amount<'nat'>; goal: Amount<'nat'> }[]
413
+ * >}
414
+ */
403
415
  const deposits = provideDurableMapStore(baggage, 'deposits');
404
416
  /** @type {MapStore<Brand, Keyword>} */
405
417
  const brandToKeyword = provideDurableMapStore(baggage, 'brandToKeyword');
@@ -427,9 +439,11 @@ export const start = async (zcf, privateArgs, baggage) => {
427
439
  });
428
440
  const scheduleKit = makeERecorderKit(
429
441
  E(privateArgs.storageNode).makeChildNode('schedule'),
430
- /** @type {import('@agoric/zoe/src/contractSupport/recorder.js').TypedMatcher<import('./scheduler.js').ScheduleNotification>} */ (
431
- M.any()
432
- ),
442
+ /**
443
+ * @type {import('@agoric/zoe/src/contractSupport/recorder.js').TypedMatcher<
444
+ * import('./scheduler.js').ScheduleNotification
445
+ * >}
446
+ */ (M.any()),
433
447
  );
434
448
 
435
449
  /**
@@ -578,7 +592,7 @@ export const start = async (zcf, privateArgs, baggage) => {
578
592
 
579
593
  /**
580
594
  * @param {ZCFSeat} zcfSeat
581
- * @param {{ goal: Amount<'nat'>}} offerArgs
595
+ * @param {{ goal: Amount<'nat'> }} offerArgs
582
596
  */
583
597
  const depositOfferHandler = (zcfSeat, offerArgs) => {
584
598
  const goalMatcher = M.or(undefined, { goal: bidAmountShape });
@@ -678,7 +692,7 @@ export const start = async (zcf, privateArgs, baggage) => {
678
692
  const creatorFacet = makeFarGovernorFacet(
679
693
  Far('Auctioneer creatorFacet', {
680
694
  /**
681
- * @param {Issuer} issuer
695
+ * @param {Issuer<'nat'>} issuer
682
696
  * @param {Keyword} kwd
683
697
  */
684
698
  async addBrand(issuer, kwd) {