@agoric/inter-protocol 0.16.2-other-dev-8f8782b.0 → 0.16.2-other-dev-3eb1a1d.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 (191) hide show
  1. package/README.md +6 -6
  2. package/package.json +42 -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 +156 -150
  7. package/src/auction/auctionMath.d.ts +17 -0
  8. package/src/auction/auctionMath.d.ts.map +1 -0
  9. package/src/auction/auctionMath.js +81 -0
  10. package/src/auction/auctioneer.d.ts +69 -0
  11. package/src/auction/auctioneer.d.ts.map +1 -0
  12. package/src/auction/auctioneer.js +70 -59
  13. package/src/auction/offerBook.d.ts +45 -0
  14. package/src/auction/offerBook.d.ts.map +1 -0
  15. package/src/auction/offerBook.js +13 -12
  16. package/src/auction/params.d.ts +144 -0
  17. package/src/auction/params.d.ts.map +1 -0
  18. package/src/auction/params.js +10 -9
  19. package/src/auction/scheduleMath.d.ts +5 -0
  20. package/src/auction/scheduleMath.d.ts.map +1 -0
  21. package/src/auction/scheduleMath.js +18 -16
  22. package/src/auction/scheduler.d.ts +50 -0
  23. package/src/auction/scheduler.d.ts.map +1 -0
  24. package/src/auction/scheduler.js +53 -47
  25. package/src/auction/sortedOffers.d.ts +8 -0
  26. package/src/auction/sortedOffers.d.ts.map +1 -0
  27. package/src/auction/sortedOffers.js +10 -9
  28. package/src/auction/util.d.ts +30 -0
  29. package/src/auction/util.d.ts.map +1 -0
  30. package/src/auction/util.js +9 -6
  31. package/src/clientSupport.d.ts +167 -0
  32. package/src/clientSupport.d.ts.map +1 -0
  33. package/src/clientSupport.js +155 -97
  34. package/src/collectFees.d.ts +2 -0
  35. package/src/collectFees.d.ts.map +1 -0
  36. package/src/contractSupport.d.ts +28 -0
  37. package/src/contractSupport.d.ts.map +1 -0
  38. package/src/contractSupport.js +19 -13
  39. package/src/econCommitteeCharter.d.ts +40 -0
  40. package/src/econCommitteeCharter.d.ts.map +1 -0
  41. package/src/econCommitteeCharter.js +21 -20
  42. package/src/feeDistributor.d.ts +224 -0
  43. package/src/feeDistributor.d.ts.map +1 -0
  44. package/src/feeDistributor.js +37 -33
  45. package/src/index.d.ts +2 -0
  46. package/src/index.d.ts.map +1 -0
  47. package/src/index.js +1 -0
  48. package/src/interest-math.d.ts +3 -0
  49. package/src/interest-math.d.ts.map +1 -0
  50. package/src/interest.d.ts +28 -0
  51. package/src/interest.d.ts.map +1 -0
  52. package/src/interest.js +23 -18
  53. package/src/price/README.md +13 -0
  54. package/src/price/fluxAggregatorContract.d.ts +71 -0
  55. package/src/price/fluxAggregatorContract.d.ts.map +1 -0
  56. package/src/price/fluxAggregatorContract.js +64 -55
  57. package/src/price/fluxAggregatorKit.d.ts +103 -0
  58. package/src/price/fluxAggregatorKit.d.ts.map +1 -0
  59. package/src/price/fluxAggregatorKit.js +52 -40
  60. package/src/price/priceOracleKit.d.ts +38 -0
  61. package/src/price/priceOracleKit.d.ts.map +1 -0
  62. package/src/price/priceOracleKit.js +12 -14
  63. package/src/price/roundsManager.d.ts +204 -0
  64. package/src/price/roundsManager.d.ts.map +1 -0
  65. package/src/price/roundsManager.js +131 -85
  66. package/src/proposals/README.md +2 -3
  67. package/src/proposals/add-auction.d.ts +109 -0
  68. package/src/proposals/add-auction.d.ts.map +1 -0
  69. package/src/proposals/add-auction.js +256 -0
  70. package/src/proposals/addAssetToVault.d.ts +173 -0
  71. package/src/proposals/addAssetToVault.d.ts.map +1 -0
  72. package/src/proposals/addAssetToVault.js +192 -40
  73. package/src/proposals/committee-proposal.d.ts +113 -0
  74. package/src/proposals/committee-proposal.d.ts.map +1 -0
  75. package/src/proposals/committee-proposal.js +25 -31
  76. package/src/proposals/core-proposal.d.ts +149 -0
  77. package/src/proposals/core-proposal.d.ts.map +1 -0
  78. package/src/proposals/core-proposal.js +9 -11
  79. package/src/proposals/deploy-price-feeds.d.ts +76 -0
  80. package/src/proposals/deploy-price-feeds.d.ts.map +1 -0
  81. package/src/proposals/deploy-price-feeds.js +316 -0
  82. package/src/proposals/econ-behaviors.d.ts +541 -0
  83. package/src/proposals/econ-behaviors.d.ts.map +1 -0
  84. package/src/proposals/econ-behaviors.js +64 -45
  85. package/src/proposals/price-feed-proposal.d.ts +84 -0
  86. package/src/proposals/price-feed-proposal.d.ts.map +1 -0
  87. package/src/proposals/price-feed-proposal.js +109 -51
  88. package/src/proposals/replace-fee-distributor.d.ts +48 -0
  89. package/src/proposals/replace-fee-distributor.d.ts.map +1 -0
  90. package/src/proposals/replace-fee-distributor.js +195 -0
  91. package/src/proposals/replace-scaledPriceAuthorities.d.ts +30 -0
  92. package/src/proposals/replace-scaledPriceAuthorities.d.ts.map +1 -0
  93. package/src/proposals/replace-scaledPriceAuthorities.js +124 -0
  94. package/src/proposals/replaceElectorate.d.ts +55 -0
  95. package/src/proposals/replaceElectorate.d.ts.map +1 -0
  96. package/src/proposals/replaceElectorate.js +521 -0
  97. package/src/proposals/startEconCommittee.d.ts +34 -0
  98. package/src/proposals/startEconCommittee.d.ts.map +1 -0
  99. package/src/proposals/startEconCommittee.js +2 -2
  100. package/src/proposals/startPSM.d.ts +59 -0
  101. package/src/proposals/startPSM.d.ts.map +1 -0
  102. package/src/proposals/startPSM.js +44 -29
  103. package/src/proposals/upgrade-scaledPriceAuthorities.d.ts +24 -0
  104. package/src/proposals/upgrade-scaledPriceAuthorities.d.ts.map +1 -0
  105. package/src/proposals/upgrade-scaledPriceAuthorities.js +78 -0
  106. package/src/proposals/upgrade-vaults.d.ts +41 -0
  107. package/src/proposals/upgrade-vaults.d.ts.map +1 -0
  108. package/src/proposals/upgrade-vaults.js +202 -0
  109. package/src/proposals/utils.d.ts +19 -0
  110. package/src/proposals/utils.d.ts.map +1 -0
  111. package/src/proposals/utils.js +43 -9
  112. package/src/provisionPool.d.ts +163 -0
  113. package/src/provisionPool.d.ts.map +1 -0
  114. package/src/provisionPool.js +122 -0
  115. package/src/provisionPoolKit.d.ts +359 -0
  116. package/src/provisionPoolKit.d.ts.map +1 -0
  117. package/src/provisionPoolKit.js +522 -0
  118. package/src/psm/psm.d.ts +125 -0
  119. package/src/psm/psm.d.ts.map +1 -0
  120. package/src/psm/psm.js +80 -79
  121. package/src/psm/types-ambient.d.ts +2 -0
  122. package/src/psm/types-ambient.d.ts.map +1 -0
  123. package/src/psm/types-ambient.js +3 -0
  124. package/src/reserve/assetReserve.d.ts +47 -0
  125. package/src/reserve/assetReserve.d.ts.map +1 -0
  126. package/src/reserve/assetReserve.js +28 -19
  127. package/src/reserve/assetReserveKit.d.ts +74 -0
  128. package/src/reserve/assetReserveKit.d.ts.map +1 -0
  129. package/src/reserve/assetReserveKit.js +24 -30
  130. package/src/reserve/params.d.ts +10 -0
  131. package/src/reserve/params.d.ts.map +1 -0
  132. package/src/tokens.d.ts +3 -0
  133. package/src/tokens.d.ts.map +1 -0
  134. package/src/tokens.js +5 -0
  135. package/src/vaultFactory/burn.d.ts +2 -0
  136. package/src/vaultFactory/burn.d.ts.map +1 -0
  137. package/src/vaultFactory/burn.js +1 -1
  138. package/src/vaultFactory/liquidation.d.ts +23 -0
  139. package/src/vaultFactory/liquidation.d.ts.map +1 -0
  140. package/src/vaultFactory/liquidation.js +37 -24
  141. package/src/vaultFactory/math.d.ts +11 -0
  142. package/src/vaultFactory/math.d.ts.map +1 -0
  143. package/src/vaultFactory/math.js +10 -9
  144. package/src/vaultFactory/orderedVaultStore.d.ts +93 -0
  145. package/src/vaultFactory/orderedVaultStore.d.ts.map +1 -0
  146. package/src/vaultFactory/orderedVaultStore.js +8 -11
  147. package/src/vaultFactory/params.d.ts +140 -0
  148. package/src/vaultFactory/params.d.ts.map +1 -0
  149. package/src/vaultFactory/params.js +52 -24
  150. package/src/vaultFactory/prioritizedVaults.d.ts +279 -0
  151. package/src/vaultFactory/prioritizedVaults.d.ts.map +1 -0
  152. package/src/vaultFactory/prioritizedVaults.js +4 -4
  153. package/src/vaultFactory/proceeds.d.ts +35 -0
  154. package/src/vaultFactory/proceeds.d.ts.map +1 -0
  155. package/src/vaultFactory/proceeds.js +26 -18
  156. package/src/vaultFactory/storeUtils.d.ts +25 -0
  157. package/src/vaultFactory/storeUtils.d.ts.map +1 -0
  158. package/src/vaultFactory/storeUtils.js +10 -12
  159. package/src/vaultFactory/types-ambient.d.ts +137 -0
  160. package/src/vaultFactory/types-ambient.d.ts.map +1 -0
  161. package/src/vaultFactory/{types.js → types-ambient.js} +42 -42
  162. package/src/vaultFactory/vault.d.ts +343 -0
  163. package/src/vaultFactory/vault.d.ts.map +1 -0
  164. package/src/vaultFactory/vault.js +105 -99
  165. package/src/vaultFactory/vaultDirector.d.ts +341 -0
  166. package/src/vaultFactory/vaultDirector.d.ts.map +1 -0
  167. package/src/vaultFactory/vaultDirector.js +86 -64
  168. package/src/vaultFactory/vaultFactory.d.ts +202 -0
  169. package/src/vaultFactory/vaultFactory.d.ts.map +1 -0
  170. package/src/vaultFactory/vaultFactory.js +52 -33
  171. package/src/vaultFactory/vaultHolder.d.ts +126 -0
  172. package/src/vaultFactory/vaultHolder.d.ts.map +1 -0
  173. package/src/vaultFactory/vaultHolder.js +11 -16
  174. package/src/vaultFactory/vaultKit.d.ts +32 -0
  175. package/src/vaultFactory/vaultKit.d.ts.map +1 -0
  176. package/src/vaultFactory/vaultKit.js +5 -4
  177. package/src/vaultFactory/vaultManager.d.ts +674 -0
  178. package/src/vaultFactory/vaultManager.d.ts.map +1 -0
  179. package/src/vaultFactory/vaultManager.js +257 -158
  180. package/CHANGELOG.md +0 -1041
  181. package/exported.js +0 -2
  182. package/scripts/add-collateral-core.js +0 -112
  183. package/scripts/deploy-contracts.js +0 -100
  184. package/scripts/init-core.js +0 -198
  185. package/scripts/invite-committee-core.js +0 -42
  186. package/scripts/manual-price-feed.js +0 -117
  187. package/scripts/price-feed-core.js +0 -104
  188. package/scripts/start-local-chain.sh +0 -84
  189. package/src/psm/types.js +0 -3
  190. package/src/typeGuards.js +0 -13
  191. package/src/vaultFactory/type-imports.js +0 -4
@@ -1,25 +1,25 @@
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 { Fail } from '@endo/errors';
6
+ import { E } from '@endo/captp';
7
+ import { AmountMath, RatioShape } from '@agoric/ertp';
6
8
  import { mustMatch } from '@agoric/store';
7
9
  import { M, prepareExoClassKit } from '@agoric/vat-data';
8
10
 
9
11
  import { assertAllDefined, makeTracer } from '@agoric/internal';
10
12
  import {
11
- atomicRearrange,
12
13
  ceilMultiplyBy,
13
- floorDivideBy,
14
14
  makeRatioFromAmounts,
15
15
  makeRecorderTopic,
16
16
  multiplyRatios,
17
17
  ratioGTE,
18
18
  } from '@agoric/zoe/src/contractSupport/index.js';
19
- import { E } from '@endo/captp';
20
19
  import { observeNotifier } from '@agoric/notifier';
21
20
 
22
21
  import { makeNatAmountShape } from '../contractSupport.js';
22
+ import { amountsToSettle } from './auctionMath.js';
23
23
  import { preparePriceBook, prepareScaledBidBook } from './offerBook.js';
24
24
  import {
25
25
  isScaledBidPriceHigher,
@@ -27,41 +27,50 @@ import {
27
27
  priceFrom,
28
28
  } from './util.js';
29
29
 
30
- const { Fail } = assert;
30
+ /**
31
+ * @import {Baggage} from '@agoric/vat-data';
32
+ * @import {PriceAuthority} from '@agoric/zoe/tools/types.js';
33
+ * @import {TypedPattern} from '@agoric/internal';
34
+ */
35
+
31
36
  const { makeEmpty } = AmountMath;
32
37
 
33
- const DEFAULT_DECIMALS = 9;
38
+ const QUOTE_SCALE = 10n ** 9n;
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
@@ -168,9 +172,7 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
168
172
 
169
173
  const bookDataKit = makeRecorderKit(
170
174
  node,
171
- /** @type {import('@agoric/zoe/src/contractSupport/recorder.js').TypedMatcher<BookDataNotification>} */ (
172
- M.any()
173
- ),
175
+ /** @type {TypedPattern<BookDataNotification>} */ (M.any()),
174
176
  );
175
177
 
176
178
  return {
@@ -182,7 +184,7 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
182
184
  bidAmountShape,
183
185
 
184
186
  priceAuthority: pAuthority,
185
- updatingOracleQuote: zeroRatio,
187
+ updatingOracleQuote: /** @type {Ratio | null} */ (null),
186
188
 
187
189
  bookDataKit,
188
190
 
@@ -231,8 +233,8 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
231
233
  {
232
234
  helper: {
233
235
  /**
234
- * remove the key from the appropriate book, indicated by whether the price
235
- * is defined.
236
+ * remove the key from the appropriate book, indicated by whether the
237
+ * price is defined.
236
238
  *
237
239
  * @param {string} key
238
240
  * @param {Ratio | undefined} price
@@ -247,8 +249,8 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
247
249
  },
248
250
 
249
251
  /**
250
- * Update the entry in the appropriate book, indicated by whether the price
251
- * is defined.
252
+ * Update the entry in the appropriate book, indicated by whether the
253
+ * price is defined.
252
254
  *
253
255
  * @param {string} key
254
256
  * @param {Amount} collateralSold
@@ -264,7 +266,8 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
264
266
  },
265
267
 
266
268
  /**
267
- * Settle with seat. The caller is responsible for updating the book, if any.
269
+ * Settle with seat. The caller is responsible for updating the book, if
270
+ * any.
268
271
  *
269
272
  * @param {ZCFSeat} seat
270
273
  * @param {Amount<'nat'>} collateralWanted
@@ -278,46 +281,36 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
278
281
  return makeEmpty(collateralBrand);
279
282
  }
280
283
 
281
- /** @type {Amount<'nat'>} */
282
- const initialCollateralTarget = AmountMath.min(
283
- collateralWanted,
284
- collateralAvailable,
285
- );
286
-
287
284
  const { curAuctionPrice, bidHoldingSeat, remainingProceedsGoal } =
288
285
  this.state;
289
286
  curAuctionPrice !== null ||
290
287
  Fail`auctionPrice must be set before each round`;
291
288
  assert(curAuctionPrice);
292
289
 
293
- const proceedsNeeded = ceilMultiplyBy(
294
- initialCollateralTarget,
295
- curAuctionPrice,
296
- );
297
- if (AmountMath.isEmpty(proceedsNeeded)) {
290
+ const { proceedsExpected, proceedsTarget, collateralTarget } =
291
+ amountsToSettle(
292
+ {
293
+ bidAlloc,
294
+ collateralWanted,
295
+ collateralAvailable,
296
+ curAuctionPrice,
297
+ remainingProceedsGoal,
298
+ },
299
+ trace,
300
+ );
301
+
302
+ if (proceedsExpected === null) {
298
303
  seat.fail(Error('price fell to zero'));
299
304
  return makeEmpty(collateralBrand);
300
305
  }
301
306
 
302
- const minProceedsTarget = AmountMath.min(proceedsNeeded, bidAlloc);
303
- const proceedsLimit = remainingProceedsGoal
304
- ? AmountMath.min(remainingProceedsGoal, minProceedsTarget)
305
- : minProceedsTarget;
306
- const isRaiseLimited =
307
- remainingProceedsGoal ||
308
- !AmountMath.isGTE(proceedsLimit, proceedsNeeded);
309
-
310
- const [proceedsTarget, collateralTarget] = isRaiseLimited
311
- ? [proceedsLimit, floorDivideBy(proceedsLimit, curAuctionPrice)]
312
- : [minProceedsTarget, initialCollateralTarget];
313
-
307
+ // check that the requested amount could be satisfied
314
308
  const { Collateral } = seat.getProposal().want;
315
309
  if (Collateral && AmountMath.isGTE(Collateral, collateralTarget)) {
316
310
  seat.exit('unable to satisfy want');
317
311
  }
318
312
 
319
- atomicRearrange(
320
- zcf,
313
+ zcf.atomicRearrange(
321
314
  harden([
322
315
  [collateralSeat, seat, { Collateral: collateralTarget }],
323
316
  [seat, bidHoldingSeat, { Bid: proceedsTarget }],
@@ -331,7 +324,7 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
331
324
  );
332
325
  }
333
326
 
334
- trace('settle', {
327
+ trace('settled', {
335
328
  collateralTarget,
336
329
  proceedsTarget,
337
330
  remainingProceedsGoal: this.state.remainingProceedsGoal,
@@ -341,15 +334,16 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
341
334
  },
342
335
 
343
336
  /**
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.
337
+ * Accept an offer expressed as a price. If the auction is active,
338
+ * attempt to buy collateral. If any of the offer remains add it to the
339
+ * book.
346
340
  *
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]
341
+ * @param {ZCFSeat} seat
342
+ * @param {Ratio} price
343
+ * @param {Amount<'nat'>} maxBuy
344
+ * @param {object} opts
345
+ * @param {boolean} opts.trySettle
346
+ * @param {boolean} [opts.exitAfterBuy]
353
347
  */
354
348
  acceptPriceOffer(
355
349
  seat,
@@ -388,16 +382,16 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
388
382
  },
389
383
 
390
384
  /**
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.
385
+ * Accept an offer expressed as a discount (or markup). If the auction
386
+ * is active, attempt to buy collateral. If any of the offer remains add
387
+ * it to the book.
394
388
  *
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]
389
+ * @param {ZCFSeat} seat
390
+ * @param {Ratio} bidScaling
391
+ * @param {Amount<'nat'>} maxBuy
392
+ * @param {object} opts
393
+ * @param {boolean} opts.trySettle
394
+ * @param {boolean} [opts.exitAfterBuy]
401
395
  */
402
396
  acceptScaledBidOffer(
403
397
  seat,
@@ -460,16 +454,51 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
460
454
  });
461
455
  return state.bookDataKit.recorder.write(bookData);
462
456
  },
457
+ observeQuoteNotifier() {
458
+ const { state, facets } = this;
459
+ const { collateralBrand, bidBrand, priceAuthority } = state;
460
+
461
+ trace('observing');
462
+
463
+ const quoteNotifier = E(priceAuthority).makeQuoteNotifier(
464
+ AmountMath.make(collateralBrand, QUOTE_SCALE),
465
+ bidBrand,
466
+ );
467
+ void observeNotifier(quoteNotifier, {
468
+ updateState: quote => {
469
+ trace(
470
+ `BOOK notifier ${priceFrom(quote).numerator.value}/${
471
+ priceFrom(quote).denominator.value
472
+ }`,
473
+ );
474
+ state.updatingOracleQuote = priceFrom(quote);
475
+ },
476
+ fail: reason => {
477
+ trace(`Failure from quoteNotifier (${reason}) setting to null`);
478
+ // lack of quote will trigger restart
479
+ state.updatingOracleQuote = null;
480
+ },
481
+ finish: done => {
482
+ trace(
483
+ `quoteNotifier invoked finish(${done}). setting quote to null`,
484
+ );
485
+ // lack of quote will trigger restart
486
+ state.updatingOracleQuote = null;
487
+ },
488
+ });
489
+
490
+ void facets.helper.publishBookData();
491
+ },
463
492
  },
464
493
  self: {
465
494
  /**
466
495
  * @param {Amount<'nat'>} assetAmount
467
496
  * @param {ZCFSeat} sourceSeat
468
497
  * @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.
498
+ * would like to raise. The auction is requested to not sell more
499
+ * collateral than required to raise that much. The auctioneer might
500
+ * sell more if there is more than one supplier of collateral, and
501
+ * they request inconsistent limits.
473
502
  */
474
503
  addAssets(assetAmount, sourceSeat, proceedsGoal) {
475
504
  const { state, facets } = this;
@@ -531,8 +560,7 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
531
560
  state.startProceedsGoal = nextProceedsGoal;
532
561
  }
533
562
 
534
- atomicRearrange(
535
- zcf,
563
+ zcf.atomicRearrange(
536
564
  harden([[sourceSeat, collateralSeat, { Collateral: assetAmount }]]),
537
565
  );
538
566
 
@@ -547,9 +575,12 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
547
575
 
548
576
  trace(this.state.collateralBrand, 'settleAtNewRate', reduction);
549
577
  const { capturedPriceForRound, priceBook, scaledBidBook } = state;
550
- capturedPriceForRound !== null ||
551
- Fail`price must be captured before auction starts`;
552
- assert(capturedPriceForRound);
578
+ if (!capturedPriceForRound) {
579
+ console.error(
580
+ `⚠️No price for ${this.state.collateralBrand}, skipping auction.`,
581
+ );
582
+ return;
583
+ }
553
584
 
554
585
  state.curAuctionPrice = multiplyRatios(
555
586
  reduction,
@@ -561,20 +592,14 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
561
592
  const pricedOffers = priceBook.offersAbove(curAuctionPrice);
562
593
  const scaledBidOffers = scaledBidBook.offersAbove(reduction);
563
594
 
564
- const compareValues = (v1, v2) => {
565
- if (v1 < v2) {
566
- return -1;
567
- } else if (v1 === v2) {
568
- return 0;
569
- } else {
570
- return 1;
571
- }
572
- };
573
- trace(`settling`, pricedOffers.length, scaledBidOffers.length);
574
595
  // requested price or BidScaling gives no priority beyond specifying which
575
596
  // round the order will be serviced in.
576
597
  const prioritizedOffers = [...pricedOffers, ...scaledBidOffers].sort(
577
- (a, b) => compareValues(a[1].seqNum, b[1].seqNum),
598
+ (a, b) => Number(a[1].seqNum - b[1].seqNum),
599
+ );
600
+
601
+ trace(
602
+ `settling ${prioritizedOffers.length} offers at ${curAuctionPrice} (priced ${pricedOffers.length}, scaled ${scaledBidOffers.length}) `,
578
603
  );
579
604
 
580
605
  const { remainingProceedsGoal } = state;
@@ -619,6 +644,12 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
619
644
  const { facets, state } = this;
620
645
 
621
646
  trace(`capturing oracle price `, state.updatingOracleQuote);
647
+ if (!state.updatingOracleQuote) {
648
+ // if the price has feed has died, try restarting it.
649
+ facets.helper.observeQuoteNotifier();
650
+ return;
651
+ }
652
+
622
653
  state.capturedPriceForRound = state.updatingOracleQuote;
623
654
  void facets.helper.publishBookData();
624
655
  },
@@ -718,43 +749,18 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
718
749
  finish: ({ state, facets }) => {
719
750
  const { collateralBrand, bidBrand, priceAuthority } = state;
720
751
  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();
752
+
753
+ facets.helper.observeQuoteNotifier();
752
754
  },
753
755
  stateShape: AuctionBookStateShape,
754
756
  },
755
757
  );
756
758
 
757
- /** @type {(...args: Parameters<typeof makeAuctionBookKit>) => ReturnType<typeof makeAuctionBookKit>['self']} */
759
+ /**
760
+ * @type {(
761
+ * ...args: Parameters<typeof makeAuctionBookKit>
762
+ * ) => ReturnType<typeof makeAuctionBookKit>['self']}
763
+ */
758
764
  const makeAuctionBook = (...args) => makeAuctionBookKit(...args).self;
759
765
  return makeAuctionBook;
760
766
  };
@@ -0,0 +1,17 @@
1
+ export function amountsToSettle({ bidAlloc, collateralWanted, collateralAvailable, curAuctionPrice, remainingProceedsGoal, }: {
2
+ bidAlloc: Amount<"nat">;
3
+ collateralWanted: Amount<"nat">;
4
+ collateralAvailable: Amount<"nat">;
5
+ curAuctionPrice: Ratio;
6
+ remainingProceedsGoal: Amount<"nat"> | null;
7
+ }, log?: ((...msgs: any[]) => void) | undefined): {
8
+ proceedsExpected: null;
9
+ proceedsTarget?: undefined;
10
+ collateralTarget?: undefined;
11
+ } | {
12
+ proceedsExpected: import("@agoric/ertp").NatAmount;
13
+ proceedsTarget: import("@agoric/ertp").NatAmount;
14
+ collateralTarget: import("@agoric/ertp").NatAmount;
15
+ };
16
+ import type { Amount } from '@agoric/ertp/src/types.js';
17
+ //# sourceMappingURL=auctionMath.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auctionMath.d.ts","sourceRoot":"","sources":["auctionMath.js"],"names":[],"mappings":"AAoBO,8HARJ;IAAyB,QAAQ,EAAzB,OAAO,KAAK,CAAC;IACI,gBAAgB,EAAjC,OAAO,KAAK,CAAC;IACI,mBAAmB,EAApC,OAAO,KAAK,CAAC;IACJ,eAAe,EAAxB,KAAK;IACmB,qBAAqB,EAA7C,OAAO,KAAK,CAAC,GAAG,IAAI;CAE5B,mBAAkB,GAAG,EAAE,KAAK,IAAI;;;;;;;;EA6DlC;4BAxEwB,2BAA2B"}
@@ -0,0 +1,81 @@
1
+ import { AmountMath } from '@agoric/ertp';
2
+ import {
3
+ ceilMultiplyBy,
4
+ floorDivideBy,
5
+ } from '@agoric/zoe/src/contractSupport/index.js';
6
+
7
+ /**
8
+ * @import {Amount} from '@agoric/ertp/src/types.js';
9
+ */
10
+
11
+ /**
12
+ * @param {object} p
13
+ * @param {Amount<'nat'>} p.bidAlloc current allocation of the bidding seat
14
+ * @param {Amount<'nat'>} p.collateralWanted want of the offer
15
+ * @param {Amount<'nat'>} p.collateralAvailable available to auction
16
+ * @param {Ratio} p.curAuctionPrice current auction price
17
+ * @param {Amount<'nat'> | null} p.remainingProceedsGoal amount still needing
18
+ * liquidating over multiple rounds; null indicates no limit
19
+ * @param {(...msgs: any[]) => void} [log]
20
+ */
21
+ export const amountsToSettle = (
22
+ {
23
+ bidAlloc,
24
+ collateralWanted,
25
+ collateralAvailable,
26
+ curAuctionPrice,
27
+ remainingProceedsGoal,
28
+ },
29
+ log = () => {},
30
+ ) => {
31
+ log('amountsToSettle', {
32
+ bidAlloc,
33
+ collateralWanted,
34
+ collateralAvailable,
35
+ curAuctionPrice,
36
+ remainingProceedsGoal,
37
+ });
38
+ const initialCollateralTarget = AmountMath.min(
39
+ collateralWanted,
40
+ collateralAvailable,
41
+ );
42
+
43
+ const proceedsExpected = ceilMultiplyBy(
44
+ initialCollateralTarget,
45
+ curAuctionPrice,
46
+ );
47
+ if (AmountMath.isEmpty(proceedsExpected)) {
48
+ return { proceedsExpected: null };
49
+ }
50
+
51
+ const targetByProceeds = proceedsLimit =>
52
+ AmountMath.min(
53
+ collateralAvailable,
54
+ floorDivideBy(proceedsLimit, curAuctionPrice),
55
+ );
56
+
57
+ const [proceedsTarget, collateralTarget] = (() => {
58
+ // proceeds cannot exceed what is needed or being offered
59
+ const proceedsBidded = AmountMath.min(proceedsExpected, bidAlloc);
60
+ if (remainingProceedsGoal) {
61
+ const goalProceeds = AmountMath.min(
62
+ remainingProceedsGoal,
63
+ proceedsBidded,
64
+ );
65
+ return [goalProceeds, targetByProceeds(goalProceeds)];
66
+ } else if (AmountMath.isGTE(proceedsBidded, proceedsExpected)) {
67
+ // initial collateral suffices
68
+ return [proceedsBidded, initialCollateralTarget];
69
+ } else {
70
+ return [proceedsBidded, targetByProceeds(proceedsBidded)];
71
+ }
72
+ })();
73
+
74
+ assert(
75
+ AmountMath.isGTE(collateralAvailable, collateralTarget),
76
+ 'target cannot exceed available',
77
+ );
78
+
79
+ return { proceedsExpected, proceedsTarget, collateralTarget };
80
+ };
81
+ harden(amountsToSettle);
@@ -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/ertp").SetAmount<import("@endo/patterns").Key>;
17
+ getStartFrequency: () => RelativeTime;
18
+ getClockStep: () => RelativeTime;
19
+ getStartingRate: () => bigint;
20
+ getLowestRate: () => bigint;
21
+ getDiscountStep: () => bigint;
22
+ getAuctionStartDelay: () => RelativeTime;
23
+ getPriceLockPeriod: () => 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/pass-style").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