@agoric/inter-protocol 0.16.2-upgrade-14-dev-0169c7e.0 → 0.16.2-upgrade-16-dev-8879538.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/package.json +41 -34
  2. package/scripts/build-bundles.js +5 -21
  3. package/src/auction/auctionBook.d.ts +84 -0
  4. package/src/auction/auctionBook.d.ts.map +1 -0
  5. package/src/auction/auctionBook.js +135 -103
  6. package/src/auction/auctioneer.d.ts +83 -0
  7. package/src/auction/auctioneer.d.ts.map +1 -0
  8. package/src/auction/auctioneer.js +63 -49
  9. package/src/auction/offerBook.d.ts +45 -0
  10. package/src/auction/offerBook.d.ts.map +1 -0
  11. package/src/auction/offerBook.js +13 -12
  12. package/src/auction/params.d.ts +149 -0
  13. package/src/auction/params.d.ts.map +1 -0
  14. package/src/auction/params.js +10 -9
  15. package/src/auction/scheduleMath.d.ts +5 -0
  16. package/src/auction/scheduleMath.d.ts.map +1 -0
  17. package/src/auction/scheduleMath.js +17 -15
  18. package/src/auction/scheduler.d.ts +49 -0
  19. package/src/auction/scheduler.d.ts.map +1 -0
  20. package/src/auction/scheduler.js +51 -43
  21. package/src/auction/sortedOffers.d.ts +8 -0
  22. package/src/auction/sortedOffers.d.ts.map +1 -0
  23. package/src/auction/sortedOffers.js +9 -7
  24. package/src/auction/util.d.ts +32 -0
  25. package/src/auction/util.d.ts.map +1 -0
  26. package/src/auction/util.js +6 -4
  27. package/src/clientSupport.d.ts +167 -0
  28. package/src/clientSupport.d.ts.map +1 -0
  29. package/src/clientSupport.js +97 -40
  30. package/src/collectFees.d.ts +2 -0
  31. package/src/collectFees.d.ts.map +1 -0
  32. package/src/contractSupport.d.ts +28 -0
  33. package/src/contractSupport.d.ts.map +1 -0
  34. package/src/contractSupport.js +14 -12
  35. package/src/econCommitteeCharter.d.ts +39 -0
  36. package/src/econCommitteeCharter.d.ts.map +1 -0
  37. package/src/econCommitteeCharter.js +21 -20
  38. package/src/feeDistributor.d.ts +224 -0
  39. package/src/feeDistributor.d.ts.map +1 -0
  40. package/src/feeDistributor.js +37 -33
  41. package/src/index.d.ts +2 -0
  42. package/src/index.d.ts.map +1 -0
  43. package/src/index.js +1 -0
  44. package/src/interest-math.d.ts +3 -0
  45. package/src/interest-math.d.ts.map +1 -0
  46. package/src/interest.d.ts +28 -0
  47. package/src/interest.d.ts.map +1 -0
  48. package/src/interest.js +21 -16
  49. package/src/price/README.md +13 -0
  50. package/src/price/fluxAggregatorContract.d.ts +70 -0
  51. package/src/price/fluxAggregatorContract.d.ts.map +1 -0
  52. package/src/price/fluxAggregatorContract.js +62 -55
  53. package/src/price/fluxAggregatorKit.d.ts +103 -0
  54. package/src/price/fluxAggregatorKit.d.ts.map +1 -0
  55. package/src/price/fluxAggregatorKit.js +50 -37
  56. package/src/price/priceOracleKit.d.ts +38 -0
  57. package/src/price/priceOracleKit.d.ts.map +1 -0
  58. package/src/price/priceOracleKit.js +11 -13
  59. package/src/price/roundsManager.d.ts +238 -0
  60. package/src/price/roundsManager.d.ts.map +1 -0
  61. package/src/price/roundsManager.js +77 -82
  62. package/src/proposals/README.md +2 -3
  63. package/src/proposals/add-auction.d.ts +69 -0
  64. package/src/proposals/add-auction.d.ts.map +1 -0
  65. package/src/proposals/add-auction.js +181 -0
  66. package/src/proposals/addAssetToVault.d.ts +160 -0
  67. package/src/proposals/addAssetToVault.d.ts.map +1 -0
  68. package/src/proposals/addAssetToVault.js +172 -38
  69. package/src/proposals/committee-proposal.d.ts +113 -0
  70. package/src/proposals/committee-proposal.d.ts.map +1 -0
  71. package/src/proposals/committee-proposal.js +25 -31
  72. package/src/proposals/core-proposal.d.ts +149 -0
  73. package/src/proposals/core-proposal.d.ts.map +1 -0
  74. package/src/proposals/core-proposal.js +9 -11
  75. package/src/proposals/econ-behaviors.d.ts +1169 -0
  76. package/src/proposals/econ-behaviors.d.ts.map +1 -0
  77. package/src/proposals/econ-behaviors.js +66 -45
  78. package/src/proposals/price-feed-proposal.d.ts +84 -0
  79. package/src/proposals/price-feed-proposal.d.ts.map +1 -0
  80. package/src/proposals/price-feed-proposal.js +108 -51
  81. package/src/proposals/startEconCommittee.d.ts +34 -0
  82. package/src/proposals/startEconCommittee.d.ts.map +1 -0
  83. package/src/proposals/startEconCommittee.js +2 -2
  84. package/src/proposals/startPSM.d.ts +59 -0
  85. package/src/proposals/startPSM.d.ts.map +1 -0
  86. package/src/proposals/startPSM.js +38 -27
  87. package/src/proposals/upgrade-scaledPriceAuthorities.d.ts +24 -0
  88. package/src/proposals/upgrade-scaledPriceAuthorities.d.ts.map +1 -0
  89. package/src/proposals/upgrade-scaledPriceAuthorities.js +78 -0
  90. package/src/proposals/upgrade-vaults.d.ts +35 -0
  91. package/src/proposals/upgrade-vaults.d.ts.map +1 -0
  92. package/src/proposals/upgrade-vaults.js +202 -0
  93. package/src/proposals/utils.d.ts +17 -0
  94. package/src/proposals/utils.d.ts.map +1 -0
  95. package/src/proposals/utils.js +34 -7
  96. package/src/provisionPool.d.ts +167 -0
  97. package/src/provisionPool.d.ts.map +1 -0
  98. package/src/provisionPool.js +122 -0
  99. package/src/provisionPoolKit.d.ts +770 -0
  100. package/src/provisionPoolKit.d.ts.map +1 -0
  101. package/src/provisionPoolKit.js +463 -0
  102. package/src/psm/psm.d.ts +122 -0
  103. package/src/psm/psm.d.ts.map +1 -0
  104. package/src/psm/psm.js +73 -69
  105. package/src/psm/types-ambient.d.ts +2 -0
  106. package/src/psm/types-ambient.d.ts.map +1 -0
  107. package/src/psm/types-ambient.js +3 -0
  108. package/src/reserve/assetReserve.d.ts +47 -0
  109. package/src/reserve/assetReserve.d.ts.map +1 -0
  110. package/src/reserve/assetReserve.js +28 -19
  111. package/src/reserve/assetReserveKit.d.ts +74 -0
  112. package/src/reserve/assetReserveKit.d.ts.map +1 -0
  113. package/src/reserve/assetReserveKit.js +18 -24
  114. package/src/reserve/params.d.ts +10 -0
  115. package/src/reserve/params.d.ts.map +1 -0
  116. package/src/tokens.d.ts +3 -0
  117. package/src/tokens.d.ts.map +1 -0
  118. package/src/tokens.js +5 -0
  119. package/src/vaultFactory/burn.d.ts +2 -0
  120. package/src/vaultFactory/burn.d.ts.map +1 -0
  121. package/src/vaultFactory/burn.js +1 -1
  122. package/src/vaultFactory/liquidation.d.ts +163 -0
  123. package/src/vaultFactory/liquidation.d.ts.map +1 -0
  124. package/src/vaultFactory/liquidation.js +36 -22
  125. package/src/vaultFactory/math.d.ts +11 -0
  126. package/src/vaultFactory/math.d.ts.map +1 -0
  127. package/src/vaultFactory/math.js +10 -9
  128. package/src/vaultFactory/orderedVaultStore.d.ts +360 -0
  129. package/src/vaultFactory/orderedVaultStore.d.ts.map +1 -0
  130. package/src/vaultFactory/orderedVaultStore.js +8 -11
  131. package/src/vaultFactory/params.d.ts +145 -0
  132. package/src/vaultFactory/params.d.ts.map +1 -0
  133. package/src/vaultFactory/params.js +52 -24
  134. package/src/vaultFactory/prioritizedVaults.d.ts +992 -0
  135. package/src/vaultFactory/prioritizedVaults.d.ts.map +1 -0
  136. package/src/vaultFactory/prioritizedVaults.js +4 -4
  137. package/src/vaultFactory/proceeds.d.ts +35 -0
  138. package/src/vaultFactory/proceeds.d.ts.map +1 -0
  139. package/src/vaultFactory/proceeds.js +26 -18
  140. package/src/vaultFactory/storeUtils.d.ts +25 -0
  141. package/src/vaultFactory/storeUtils.d.ts.map +1 -0
  142. package/src/vaultFactory/storeUtils.js +10 -12
  143. package/src/vaultFactory/types-ambient.d.ts +234 -0
  144. package/src/vaultFactory/types-ambient.d.ts.map +1 -0
  145. package/src/vaultFactory/{types.js → types-ambient.js} +42 -42
  146. package/src/vaultFactory/vault.d.ts +402 -0
  147. package/src/vaultFactory/vault.d.ts.map +1 -0
  148. package/src/vaultFactory/vault.js +99 -93
  149. package/src/vaultFactory/vaultDirector.d.ts +388 -0
  150. package/src/vaultFactory/vaultDirector.d.ts.map +1 -0
  151. package/src/vaultFactory/vaultDirector.js +61 -50
  152. package/src/vaultFactory/vaultFactory.d.ts +277 -0
  153. package/src/vaultFactory/vaultFactory.d.ts.map +1 -0
  154. package/src/vaultFactory/vaultFactory.js +49 -32
  155. package/src/vaultFactory/vaultHolder.d.ts +270 -0
  156. package/src/vaultFactory/vaultHolder.d.ts.map +1 -0
  157. package/src/vaultFactory/vaultHolder.js +10 -14
  158. package/src/vaultFactory/vaultKit.d.ts +102 -0
  159. package/src/vaultFactory/vaultKit.d.ts.map +1 -0
  160. package/src/vaultFactory/vaultKit.js +5 -4
  161. package/src/vaultFactory/vaultManager.d.ts +819 -0
  162. package/src/vaultFactory/vaultManager.d.ts.map +1 -0
  163. package/src/vaultFactory/vaultManager.js +248 -151
  164. package/CHANGELOG.md +0 -1066
  165. package/exported.js +0 -2
  166. package/scripts/add-collateral-core.js +0 -113
  167. package/scripts/deploy-contracts.js +0 -100
  168. package/scripts/init-core.js +0 -200
  169. package/scripts/invite-committee-core.js +0 -42
  170. package/scripts/manual-price-feed.js +0 -117
  171. package/scripts/price-feed-core.js +0 -104
  172. package/scripts/start-local-chain.sh +0 -84
  173. package/src/psm/types.js +0 -3
  174. package/src/typeGuards.js +0 -13
  175. package/src/vaultFactory/type-imports.js +0 -4
@@ -4,6 +4,8 @@ import { TimeMath } from '@agoric/time';
4
4
  import { natSafeMath } from '@agoric/zoe/src/contractSupport/index.js';
5
5
  import { assertAllDefined, makeTracer } from '@agoric/internal';
6
6
 
7
+ /** @import {TimestampRecord} from '@agoric/time'; */
8
+
7
9
  const { subtract, multiply, floorDivide } = natSafeMath;
8
10
  const { Fail } = assert;
9
11
 
@@ -18,23 +20,24 @@ const subtract1 = relTime =>
18
20
  /**
19
21
  * The length of the auction has to be inferred from the governed params.
20
22
  *
21
- * 1. The auction starts by offering collateral at a `StartingRate` (e.g., 105%)
22
- * of the market price at auction start, and continues until it reaches
23
- * (or would exceed on its next step) LowestRate (e.g., 65%)
23
+ * 1. The auction starts by offering collateral at a `StartingRate` (e.g., 105%) of
24
+ * the market price at auction start, and continues until it reaches (or
25
+ * would exceed on its next step) LowestRate (e.g., 65%)
24
26
  * 2. The offer price changes every `ClockStep` seconds
25
- * 3. The offer price changes by `DiscountStep` amount (e.g., 5%) each step So
26
- * it must run however many `ClockSteps` are required to get from
27
- * `StartingRate` to `LowestRate` changing by `DiscountStep` each time.
27
+ * 3. The offer price changes by `DiscountStep` amount (e.g., 5%) each step So it
28
+ * must run however many `ClockSteps` are required to get from `StartingRate`
29
+ * to `LowestRate` changing by `DiscountStep` each time.
28
30
  *
29
- * Therefore, the duration is `(StartingRate - LowestRate) / DiscountStep * ClockStep`.
31
+ * Therefore, the duration is `(StartingRate - LowestRate) / DiscountStep *
32
+ * ClockStep`.
30
33
  *
31
- * Note that this is what's *scheduled*. More than one auction can be running
34
+ * Note that this is what's _scheduled_. More than one auction can be running
32
35
  * simultaneously, and some conditions can cause some of the auctions to stop
33
36
  * selling early (e.g. reaching their target debt to raise or selling all of
34
37
  * their collateral).
35
38
  *
36
39
  * @param {Awaited<import('./params.js').AuctionParamManager>} params
37
- * @param {Timestamp} baseTime
40
+ * @param {TimestampRecord} baseTime
38
41
  * @returns {import('./scheduler.js').Schedule}
39
42
  */
40
43
  export const computeRoundTiming = (params, baseTime) => {
@@ -82,7 +85,7 @@ export const computeRoundTiming = (params, baseTime) => {
82
85
  // computed start is `startDelay + baseTime + freq - (baseTime mod freq)`.
83
86
  // That is, if there are hourly starts, we add an hour to the time, and
84
87
  // subtract baseTime mod freq. Then we add the delay.
85
- /** @type {import('@agoric/time/src/types').TimestampRecord} */
88
+ /** @type {TimestampRecord} */
86
89
  const startTime = TimeMath.addAbsRel(
87
90
  TimeMath.addAbsRel(
88
91
  baseTime,
@@ -108,10 +111,10 @@ export const computeRoundTiming = (params, baseTime) => {
108
111
  harden(computeRoundTiming);
109
112
 
110
113
  /**
111
- * Calculate when the next descending step will start. If we're between
112
- * auctions (i.e. liveSchedule is undefined), or the last step of the current
113
- * auction has started, then it'll be nextSchedule.startTime. Otherwise, it's
114
- * the start of the step following the current step.
114
+ * Calculate when the next descending step will start. If we're between auctions
115
+ * (i.e. liveSchedule is undefined), or the last step of the current auction has
116
+ * started, then it'll be nextSchedule.startTime. Otherwise, it's the start of
117
+ * the step following the current step.
115
118
  *
116
119
  * @param {import('./scheduler.js').Schedule | null} liveSchedule
117
120
  * @param {import('./scheduler.js').Schedule | null} nextSchedule
@@ -143,7 +146,6 @@ export const nextDescendingStepTime = (liveSchedule, nextSchedule, now) => {
143
146
  harden(nextDescendingStepTime);
144
147
 
145
148
  /**
146
- *
147
149
  * @param {Timestamp} time
148
150
  * @param {import('./scheduler.js').Schedule} schedule
149
151
  * @returns {'before' | 'during' | 'endExactly' | 'after'}
@@ -0,0 +1,49 @@
1
+ export function makeScheduler(auctionDriver: AuctionDriver, timer: import("@agoric/time").TimerService, params: Awaited<import("./params.js").AuctionParamManager>, timerBrand: import("@agoric/time").TimerBrand, scheduleRecorder: import("@agoric/zoe/src/contractSupport/recorder.js").Recorder<ScheduleNotification>, paramUpdateSubscription: StoredSubscription<GovernanceSubscriptionState>): Promise<{
2
+ getSchedule: () => {
3
+ liveAuctionSchedule: Schedule | null;
4
+ nextAuctionSchedule: Schedule | null;
5
+ };
6
+ getAuctionState: () => "active" | "waiting";
7
+ } & import("@endo/marshal").RemotableObject<`Alleged: ${string}`> & import("@endo/eventual-send").RemotableBrand<{}, {
8
+ getSchedule: () => {
9
+ liveAuctionSchedule: Schedule | null;
10
+ nextAuctionSchedule: Schedule | null;
11
+ };
12
+ getAuctionState: () => "active" | "waiting";
13
+ }>>;
14
+ export type AuctionDriver = {
15
+ reducePriceAndTrade: () => void;
16
+ finalize: () => void;
17
+ startRound: () => void;
18
+ capturePrices: () => void;
19
+ };
20
+ export type ScheduleNotification = {
21
+ /**
22
+ * start time of current auction if
23
+ * auction is active
24
+ */
25
+ activeStartTime: Timestamp | null;
26
+ /**
27
+ * start time of next auction
28
+ */
29
+ nextStartTime: Timestamp | null;
30
+ /**
31
+ * when the next descending
32
+ * step will take place
33
+ */
34
+ nextDescendingStepTime: Timestamp | null;
35
+ };
36
+ export type Schedule = {
37
+ startTime: import("@agoric/time").TimestampRecord;
38
+ endTime: import("@agoric/time").TimestampRecord;
39
+ steps: NatValue;
40
+ endRate: NatValue;
41
+ startDelay: RelativeTime;
42
+ clockStep: RelativeTime;
43
+ lockTime?: Timestamp | undefined;
44
+ };
45
+ export type FullSchedule = {
46
+ nextAuctionSchedule: Schedule | null;
47
+ liveAuctionSchedule: Schedule | null;
48
+ };
49
+ //# sourceMappingURL=scheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["scheduler.js"],"names":[],"mappings":"AA+EO,6CAPI,aAAa,SACb,OAAO,cAAc,EAAE,YAAY,UACnC,OAAO,CAAC,OAAO,aAAa,EAAE,mBAAmB,CAAC,cAClD,OAAO,cAAc,EAAE,UAAU,oBACjC,OAAO,6CAA6C,EAAE,QAAQ,CAAC,oBAAoB,CAAC,2BACpF,kBAAkB,CAAC,2BAA2B,CAAC;;;;;;;;;;;;IA2RzD;;yBA5Ta,MAAM,IAAI;cACV,MAAM,IAAI;gBACV,MAAM,IAAI;mBACV,MAAM,IAAI;;;;;;;;;;;;;;;;;;;eA6TV,OAAO,cAAc,EAAE,eAAe;aACtC,OAAO,cAAc,EAAE,eAAe;WACtC,QAAQ;aACR,QAAQ;;;;;;yBAQR,QAAQ,GAAG,IAAI;yBACf,QAAQ,GAAG,IAAI"}
@@ -20,21 +20,22 @@ const MAX_LATE_TICK = 300n;
20
20
 
21
21
  /**
22
22
  * @file The scheduler is presumed to be quiescent between auction rounds. Each
23
- * Auction round consists of a sequence of steps with decreasing prices. There
24
- * should always be a next schedule, but between rounds, liveSchedule is null.
23
+ * Auction round consists of a sequence of steps with decreasing prices. There
24
+ * should always be a next schedule, but between rounds, liveSchedule is
25
+ * null.
25
26
  *
26
- * The lock period that the liquidators use might start before the previous
27
- * round has finished, so we need to schedule the next round each time an
28
- * auction starts. This means if the scheduling parameters change, it'll be a
29
- * full cycle before we switch. Otherwise, the vaults wouldn't know when to
30
- * start their lock period. If the lock period for the next auction hasn't
31
- * started when each aucion ends, we recalculate it, in case the parameters have
32
- * changed.
27
+ * The lock period that the liquidators use might start before the previous
28
+ * round has finished, so we need to schedule the next round each time an
29
+ * auction starts. This means if the scheduling parameters change, it'll be a
30
+ * full cycle before we switch. Otherwise, the vaults wouldn't know when to
31
+ * start their lock period. If the lock period for the next auction hasn't
32
+ * started when each aucion ends, we recalculate it, in case the parameters
33
+ * have changed.
33
34
  *
34
- * If the clock skips forward (because of a chain halt, for instance), the
35
- * scheduler will try to cleanly and quickly finish any round already in
36
- * progress. It would take additional work on the manual timer to test this
37
- * thoroughly.
35
+ * If the clock skips forward (because of a chain halt, for instance), the
36
+ * scheduler will try to cleanly and quickly finish any round already in
37
+ * progress. It would take additional work on the manual timer to test this
38
+ * thoroughly.
38
39
  */
39
40
 
40
41
  const makeCancelToken = makeCancelTokenMaker('scheduler');
@@ -49,12 +50,11 @@ const makeCancelToken = makeCancelTokenMaker('scheduler');
49
50
 
50
51
  /**
51
52
  * @typedef {object} ScheduleNotification
52
- *
53
- * @property {Timestamp | null} activeStartTime start time of current
54
- * auction if auction is active
53
+ * @property {Timestamp | null} activeStartTime start time of current auction if
54
+ * auction is active
55
55
  * @property {Timestamp | null} nextStartTime start time of next auction
56
- * @property {Timestamp | null} nextDescendingStepTime when the next descending step
57
- * will take place
56
+ * @property {Timestamp | null} nextDescendingStepTime when the next descending
57
+ * step will take place
58
58
  */
59
59
 
60
60
  const safelyComputeRoundTiming = (params, baseTime) => {
@@ -71,9 +71,9 @@ const nominalStartTime = nextSchedule =>
71
71
 
72
72
  /**
73
73
  * @param {AuctionDriver} auctionDriver
74
- * @param {import('@agoric/time/src/types').TimerService} timer
74
+ * @param {import('@agoric/time').TimerService} timer
75
75
  * @param {Awaited<import('./params.js').AuctionParamManager>} params
76
- * @param {import('@agoric/time/src/types').TimerBrand} timerBrand
76
+ * @param {import('@agoric/time').TimerBrand} timerBrand
77
77
  * @param {import('@agoric/zoe/src/contractSupport/recorder.js').Recorder<ScheduleNotification>} scheduleRecorder
78
78
  * @param {StoredSubscription<GovernanceSubscriptionState>} paramUpdateSubscription
79
79
  */
@@ -92,7 +92,7 @@ export const makeScheduler = async (
92
92
  */
93
93
  let liveSchedule = null;
94
94
 
95
- /** @returns {Promise<{ now: Timestamp, nextSchedule: Schedule | null }>} */
95
+ /** @returns {Promise<{ now: Timestamp; nextSchedule: Schedule | null }>} */
96
96
  const initializeNextSchedule = async () => {
97
97
  return E.when(
98
98
  // XXX manualTimer returns a bigint, not a timeRecord.
@@ -114,7 +114,7 @@ export const makeScheduler = async (
114
114
 
115
115
  const stepCancelToken = makeCancelToken();
116
116
 
117
- /** @type {typeof AuctionState[keyof typeof AuctionState]} */
117
+ /** @type {(typeof AuctionState)[keyof typeof AuctionState]} */
118
118
  let auctionState = AuctionState.WAITING;
119
119
 
120
120
  /**
@@ -149,18 +149,7 @@ export const makeScheduler = async (
149
149
  auctionState = AuctionState.WAITING;
150
150
  auctionDriver.finalize();
151
151
 
152
- if (nextSchedule) {
153
- // only recalculate the next schedule at this point if the lock time has
154
- // not been reached.
155
- const nextLock = nextSchedule.lockTime;
156
- if (nextLock && TimeMath.compareAbs(now, nextLock) < 0) {
157
- const afterNow = TimeMath.addAbsRel(
158
- now,
159
- TimeMath.coerceRelativeTimeRecord(1n, timerBrand),
160
- );
161
- nextSchedule = safelyComputeRoundTiming(params, afterNow);
162
- }
163
- } else {
152
+ if (!nextSchedule) {
164
153
  console.error(
165
154
  '🛠️ finishAuctionRound without scheduling the next; repair with new auctioneer params',
166
155
  );
@@ -233,9 +222,13 @@ export const makeScheduler = async (
233
222
  liveSchedule.clockStep,
234
223
  Far('PriceStepWaker', {
235
224
  wake(time) {
236
- setTimeMonotonically(time);
237
- trace('wake step', now);
238
- void clockTick(liveSchedule);
225
+ try {
226
+ setTimeMonotonically(time);
227
+ trace('wake step', now);
228
+ clockTick(liveSchedule);
229
+ } catch (e) {
230
+ console.error(`⚠️ Auction threw ${e}. Caught in PriceStepWaker.`);
231
+ }
239
232
  },
240
233
  }),
241
234
  stepCancelToken,
@@ -249,10 +242,14 @@ export const makeScheduler = async (
249
242
  start,
250
243
  Far('SchedulerWaker', {
251
244
  wake(time) {
252
- setTimeMonotonically(time);
253
- auctionDriver.capturePrices();
254
- // eslint-disable-next-line no-use-before-define
255
- return startAuction();
245
+ try {
246
+ setTimeMonotonically(time);
247
+ auctionDriver.capturePrices();
248
+ // eslint-disable-next-line no-use-before-define
249
+ return startAuction();
250
+ } catch (e) {
251
+ console.error(`⚠️ Auction threw ${e}. Caught in SchedulerWaker.`);
252
+ }
256
253
  },
257
254
  }),
258
255
  );
@@ -333,7 +330,18 @@ export const makeScheduler = async (
333
330
  // NB: may be fired with the initial params as well
334
331
  async updateState(_newState) {
335
332
  trace('received param update', _newState);
333
+ await null;
334
+
335
+ let fixableSchedule;
336
336
  if (!nextSchedule) {
337
+ fixableSchedule = true;
338
+ } else {
339
+ now = await E(timer).getCurrentTimestamp();
340
+ fixableSchedule =
341
+ TimeMath.compareAbs(nextSchedule.startTime, now) < 0;
342
+ }
343
+
344
+ if (fixableSchedule) {
337
345
  trace('repairing nextSchedule and restarting');
338
346
  ({ nextSchedule } = await initializeNextSchedule());
339
347
  startSchedulingFromScratch();
@@ -354,8 +362,8 @@ export const makeScheduler = async (
354
362
 
355
363
  /**
356
364
  * @typedef {object} Schedule
357
- * @property {import('@agoric/time/src/types').TimestampRecord} startTime
358
- * @property {import('@agoric/time/src/types').TimestampRecord} endTime
365
+ * @property {import('@agoric/time').TimestampRecord} startTime
366
+ * @property {import('@agoric/time').TimestampRecord} endTime
359
367
  * @property {NatValue} steps
360
368
  * @property {NatValue} endRate
361
369
  * @property {RelativeTime} startDelay
@@ -0,0 +1,8 @@
1
+ export function toPartialOfferKey(offerPrice: Ratio): string;
2
+ export function toPriceOfferKey(offerPrice: Ratio, sequenceNumber: bigint): string;
3
+ export function fromPriceOfferKey(key: string, numBrand: Brand<"nat">, denomBrand: Brand<"nat">, useDecimals: number): [normalizedPrice: Ratio, sequenceNumber: bigint];
4
+ /** @type {(rate: Ratio) => string} */
5
+ export const toBidScalingComparator: (rate: Ratio) => string;
6
+ export function toScaledRateOfferKey(rate: Ratio, sequenceNumber: bigint): string;
7
+ export function fromScaledRateOfferKey(key: string, brand: Brand, useDecimals: number): [normalizedPrice: Ratio, sequenceNumber: bigint];
8
+ //# sourceMappingURL=sortedOffers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sortedOffers.d.ts","sourceRoot":"","sources":["sortedOffers.js"],"names":[],"mappings":"AA8BO,8CAFI,KAAK,UAMf;AAUM,4CALI,KAAK,kBACL,MAAM,GACJ,MAAM,CAWlB;AAqCM,uCANI,MAAM,YACN,KAAK,CAAC,KAAK,CAAC,cACZ,KAAK,CAAC,KAAK,CAAC,eACZ,MAAM,GACJ,CAAC,eAAe,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,CAAC,CAS5D;AAED,sCAAsC;AACtC,qCADW,CAAC,IAAI,EAAE,KAAK,KAAK,MAAM,CAKhC;AAUK,2CALI,KAAK,kBACL,MAAM,GACJ,MAAM,CAWlB;AAUM,4CALI,MAAM,SACN,KAAK,eACL,MAAM,GACJ,CAAC,eAAe,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,CAAC,CAQ5D"}
@@ -13,12 +13,13 @@ const { Fail } = assert;
13
13
 
14
14
  /**
15
15
  * @file we use a floating point representation of the price or rate as the
16
- * first part of the key in the store. The second part is the sequence number of
17
- * the bid, but it doesn't matter for sorting. When we retrieve multiple bids,
18
- * it's only by bid value, so we don't care how the sequence numbers sort.
16
+ * first part of the key in the store. The second part is the sequence number
17
+ * of the bid, but it doesn't matter for sorting. When we retrieve multiple
18
+ * bids, it's only by bid value, so we don't care how the sequence numbers
19
+ * sort.
19
20
  *
20
- * We take advantage of the fact that encodeData takes a passable and turns it
21
- * into a sort key. Arrays of passable data sort like composite keys.
21
+ * We take advantage of the fact that encodeData takes a passable and turns it
22
+ * into a sort key. Arrays of passable data sort like composite keys.
22
23
  */
23
24
 
24
25
  /**
@@ -39,7 +40,7 @@ export const toPartialOfferKey = offerPrice => {
39
40
  * @param {Ratio} offerPrice IST/collateral
40
41
  * @param {bigint} sequenceNumber
41
42
  * @returns {string} lexically sortable string in which highest price is first,
42
- * ties will be broken by sequenceNumber of offer
43
+ * ties will be broken by sequenceNumber of offer
43
44
  */
44
45
  export const toPriceOfferKey = (offerPrice, sequenceNumber) => {
45
46
  mustMatch(offerPrice, RatioShape);
@@ -87,6 +88,7 @@ const bidScalingRatioFromKey = (bidScaleFloat, numBrand, useDecimals) => {
87
88
  * @returns {[normalizedPrice: Ratio, sequenceNumber: bigint]}
88
89
  */
89
90
  export const fromPriceOfferKey = (key, numBrand, denomBrand, useDecimals) => {
91
+ // @ts-expect-error XXX
90
92
  const [pricePart, sequenceNumberPart] = decodeData(key);
91
93
  return [
92
94
  priceRatioFromFloat(pricePart, numBrand, denomBrand, useDecimals),
@@ -107,7 +109,7 @@ export const toBidScalingComparator = rate => {
107
109
  * @param {Ratio} rate discount/markup rate expressed as a ratio IST/IST
108
110
  * @param {bigint} sequenceNumber
109
111
  * @returns {string} lexically sortable string in which highest price is first,
110
- * ties will be broken by sequenceNumber of offer
112
+ * ties will be broken by sequenceNumber of offer
111
113
  */
112
114
  export const toScaledRateOfferKey = (rate, sequenceNumber) => {
113
115
  mustMatch(rate, RatioShape);
@@ -0,0 +1,32 @@
1
+ /** @import {PriceAuthority, PriceDescription, PriceQuote, PriceQuoteValue, PriceQuery,} from '@agoric/zoe/tools/types.js'; */
2
+ /**
3
+ * Constants for Auction State.
4
+ *
5
+ * @type {{ ACTIVE: 'active'; WAITING: 'waiting' }}
6
+ */
7
+ export const AuctionState: {
8
+ ACTIVE: "active";
9
+ WAITING: "waiting";
10
+ };
11
+ export function makeBrandedRatioPattern(numeratorAmountShape: {
12
+ brand: Brand;
13
+ value: Pattern;
14
+ }, denominatorAmountShape: {
15
+ brand: Brand;
16
+ value: Pattern;
17
+ }): {
18
+ numerator: {
19
+ brand: Brand;
20
+ value: Pattern;
21
+ };
22
+ denominator: {
23
+ brand: Brand;
24
+ value: Pattern;
25
+ };
26
+ };
27
+ export function isScaledBidPriceHigher(bidScaling: Ratio, currentPrice: Ratio, oraclePrice: Ratio): boolean;
28
+ /** @type {(quote: PriceQuote) => Ratio} */
29
+ export const priceFrom: (quote: PriceQuote) => Ratio;
30
+ export function makeCancelTokenMaker(name: any): () => import("@endo/marshal").RemotableObject<`Alleged: ${string}`> & import("@endo/eventual-send").RemotableBrand<{}, {}>;
31
+ import type { PriceQuote } from '@agoric/zoe/tools/types.js';
32
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["util.js"],"names":[],"mappings":"AASA,8HAA8H;AAE9H;;;;GAIG;AACH,2BAFU;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,SAAS,CAAA;CAAE,CAKhD;AAMK,8DAHI;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,0BAChC;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE;;eADvB,KAAK;eAAS,OAAO;;;eACrB,KAAK;eAAS,OAAO;;EAUxC;AASM,mDANI,KAAK,gBACL,KAAK,eACL,KAAK,GACH,OAAO,CAI6C;AAEjE,2CAA2C;AAC3C,+CADkC,KAAK,CAKnC;AAEG,4KAIN;gCA/C6F,4BAA4B"}
@@ -7,10 +7,12 @@ import {
7
7
  } from '@agoric/zoe/src/contractSupport/index.js';
8
8
  import { Far } from '@endo/marshal';
9
9
 
10
+ /** @import {PriceAuthority, PriceDescription, PriceQuote, PriceQuoteValue, PriceQuery,} from '@agoric/zoe/tools/types.js'; */
11
+
10
12
  /**
11
13
  * Constants for Auction State.
12
14
  *
13
- * @type {{ ACTIVE: 'active', WAITING: 'waiting' }}
15
+ * @type {{ ACTIVE: 'active'; WAITING: 'waiting' }}
14
16
  */
15
17
  export const AuctionState = {
16
18
  ACTIVE: 'active',
@@ -18,8 +20,8 @@ export const AuctionState = {
18
20
  };
19
21
 
20
22
  /**
21
- * @param {{ brand: Brand, value: Pattern }} numeratorAmountShape
22
- * @param {{ brand: Brand, value: Pattern }} denominatorAmountShape
23
+ * @param {{ brand: Brand; value: Pattern }} numeratorAmountShape
24
+ * @param {{ brand: Brand; value: Pattern }} denominatorAmountShape
23
25
  */
24
26
  export const makeBrandedRatioPattern = (
25
27
  numeratorAmountShape,
@@ -36,7 +38,7 @@ export const makeBrandedRatioPattern = (
36
38
  * @param {Ratio} currentPrice
37
39
  * @param {Ratio} oraclePrice
38
40
  * @returns {boolean} TRUE iff the discount(/markup) applied to the price is
39
- * higher than the quote.
41
+ * higher than the quote.
40
42
  */
41
43
  export const isScaledBidPriceHigher = (bidScaling, currentPrice, oraclePrice) =>
42
44
  ratioGTE(multiplyRatios(oraclePrice, bidScaling), currentPrice);
@@ -0,0 +1,167 @@
1
+ export function lookupOfferIdForVault(vaultId: string, currentP: Promise<import("@agoric/smart-wallet/src/smartWallet.js").CurrentWalletRecord>): Promise<string>;
2
+ export function makeParseAmount(agoricNames: Pick<import("@agoric/vats/tools/board-utils.js").AgoricNamesRemotes, "brand" | "vbankAsset">, makeError?: (msg: string) => Error): (a: string) => Amount<"nat">;
3
+ export namespace Offers {
4
+ namespace auction {
5
+ export { makeBidOffer as Bid };
6
+ }
7
+ namespace fluxAggregator {
8
+ export { makePushPriceOffer as PushPrice };
9
+ }
10
+ namespace psm {
11
+ export { makePsmSwapOffer as swap };
12
+ }
13
+ namespace vaults {
14
+ export { makeOpenOffer as OpenVault };
15
+ export { makeAdjustOffer as AdjustBalances };
16
+ export { makeCloseOffer as CloseVault };
17
+ }
18
+ namespace reserve {
19
+ export { makeAddCollateralOffer as AddCollateral };
20
+ }
21
+ }
22
+ /**
23
+ * @param {Pick<
24
+ * import('@agoric/vats/tools/board-utils.js').AgoricNamesRemotes,
25
+ * 'brand' | 'vbankAsset'
26
+ * >} agoricNames
27
+ * @param {{
28
+ * offerId: string;
29
+ * give: string;
30
+ * maxBuy: string;
31
+ * wantMinimum?: string;
32
+ * } & (
33
+ * | {
34
+ * price: number;
35
+ * }
36
+ * | {
37
+ * discount: number; // -1 to 1. e.g. 0.10 for 10% discount, -0.05 for 5% markup
38
+ * }
39
+ * )} opts
40
+ * @returns {import('@agoric/smart-wallet/src/offers.js').OfferSpec}
41
+ */
42
+ declare function makeBidOffer(agoricNames: Pick<import("@agoric/vats/tools/board-utils.js").AgoricNamesRemotes, "brand" | "vbankAsset">, opts: {
43
+ offerId: string;
44
+ give: string;
45
+ maxBuy: string;
46
+ wantMinimum?: string;
47
+ } & ({
48
+ price: number;
49
+ } | {
50
+ discount: number;
51
+ })): import("@agoric/smart-wallet/src/offers.js").OfferSpec;
52
+ /**
53
+ * @param {unknown} _agoricNames
54
+ * @param {{
55
+ * offerId: string;
56
+ * roundId?: bigint;
57
+ * unitPrice: bigint;
58
+ * }} opts
59
+ * @param {string} previousOffer
60
+ * @returns {import('@agoric/smart-wallet/src/offers.js').OfferSpec}
61
+ */
62
+ declare function makePushPriceOffer(_agoricNames: unknown, opts: {
63
+ offerId: string;
64
+ roundId?: bigint;
65
+ unitPrice: bigint;
66
+ }, previousOffer: string): import("@agoric/smart-wallet/src/offers.js").OfferSpec;
67
+ /**
68
+ * @param {Pick<
69
+ * import('@agoric/vats/tools/board-utils.js').AgoricNamesRemotes,
70
+ * 'brand'
71
+ * >} agoricNames
72
+ * @param {Instance} instance
73
+ * @param {{ offerId: string; feePct?: number; pair: [string, string] } & (
74
+ * | { wantMinted: number }
75
+ * | { giveMinted: number }
76
+ * )} opts
77
+ * @returns {import('@agoric/smart-wallet/src/offers.js').OfferSpec}
78
+ */
79
+ declare function makePsmSwapOffer({ brand }: Pick<import("@agoric/vats/tools/board-utils.js").AgoricNamesRemotes, "brand">, instance: Instance, opts: {
80
+ offerId: string;
81
+ feePct?: number;
82
+ pair: [string, string];
83
+ } & ({
84
+ wantMinted: number;
85
+ } | {
86
+ giveMinted: number;
87
+ })): import("@agoric/smart-wallet/src/offers.js").OfferSpec;
88
+ /**
89
+ * @param {Pick<
90
+ * import('@agoric/vats/tools/board-utils.js').AgoricNamesRemotes,
91
+ * 'brand'
92
+ * >} agoricNames
93
+ * @param {{
94
+ * offerId: string;
95
+ * wantMinted: number;
96
+ * giveCollateral: number;
97
+ * collateralBrandKey: string;
98
+ * }} opts
99
+ * @returns {import('@agoric/smart-wallet/src/offers.js').OfferSpec}
100
+ */
101
+ declare function makeOpenOffer({ brand }: Pick<import("@agoric/vats/tools/board-utils.js").AgoricNamesRemotes, "brand">, opts: {
102
+ offerId: string;
103
+ wantMinted: number;
104
+ giveCollateral: number;
105
+ collateralBrandKey: string;
106
+ }): import("@agoric/smart-wallet/src/offers.js").OfferSpec;
107
+ /**
108
+ * @param {Pick<
109
+ * import('@agoric/vats/tools/board-utils.js').AgoricNamesRemotes,
110
+ * 'brand'
111
+ * >} agoricNames
112
+ * @param {{
113
+ * offerId: string;
114
+ * collateralBrandKey?: string;
115
+ * giveCollateral?: number;
116
+ * wantCollateral?: number;
117
+ * giveMinted?: number;
118
+ * wantMinted?: number;
119
+ * }} opts
120
+ * @param {string} previousOffer
121
+ * @returns {import('@agoric/smart-wallet/src/offers.js').OfferSpec}
122
+ */
123
+ declare function makeAdjustOffer({ brand }: Pick<import("@agoric/vats/tools/board-utils.js").AgoricNamesRemotes, "brand">, opts: {
124
+ offerId: string;
125
+ collateralBrandKey?: string;
126
+ giveCollateral?: number;
127
+ wantCollateral?: number;
128
+ giveMinted?: number;
129
+ wantMinted?: number;
130
+ }, previousOffer: string): import("@agoric/smart-wallet/src/offers.js").OfferSpec;
131
+ /**
132
+ * @param {Pick<
133
+ * import('@agoric/vats/tools/board-utils.js').AgoricNamesRemotes,
134
+ * 'brand'
135
+ * >} agoricNames
136
+ * @param {{
137
+ * offerId: string;
138
+ * collateralBrandKey?: string;
139
+ * giveMinted: number;
140
+ * }} opts
141
+ * @param {string} previousOffer
142
+ * @returns {import('@agoric/smart-wallet/src/offers.js').OfferSpec}
143
+ */
144
+ declare function makeCloseOffer({ brand }: Pick<import("@agoric/vats/tools/board-utils.js").AgoricNamesRemotes, "brand">, opts: {
145
+ offerId: string;
146
+ collateralBrandKey?: string;
147
+ giveMinted: number;
148
+ }, previousOffer: string): import("@agoric/smart-wallet/src/offers.js").OfferSpec;
149
+ /**
150
+ * @param {Pick<
151
+ * import('@agoric/vats/tools/board-utils.js').AgoricNamesRemotes,
152
+ * 'brand'
153
+ * >} agoricNames
154
+ * @param {{
155
+ * offerId: string;
156
+ * give: number;
157
+ * collateralBrandKey: string;
158
+ * }} opts
159
+ * @returns {import('@agoric/smart-wallet/src/offers.js').OfferSpec}
160
+ */
161
+ declare function makeAddCollateralOffer({ brand }: Pick<import("@agoric/vats/tools/board-utils.js").AgoricNamesRemotes, "brand">, opts: {
162
+ offerId: string;
163
+ give: number;
164
+ collateralBrandKey: string;
165
+ }): import("@agoric/smart-wallet/src/offers.js").OfferSpec;
166
+ export {};
167
+ //# sourceMappingURL=clientSupport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientSupport.d.ts","sourceRoot":"","sources":["clientSupport.js"],"names":[],"mappings":"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"}