@agoric/inter-protocol 0.13.2-dev-2354e8d.0 → 0.13.2-dev-f243a2c.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.
@@ -4,12 +4,12 @@ import '@agoric/zoe/src/contracts/exported.js';
4
4
  import '@agoric/governance/exported.js';
5
5
 
6
6
  import { AmountMath, AmountShape, BrandShape, IssuerShape } from '@agoric/ertp';
7
+ import { GovernorFacetShape } from '@agoric/governance/src/typeGuards.js';
7
8
  import { makeTracer } from '@agoric/internal';
8
- import { makeStoredPublisherKit } from '@agoric/notifier';
9
- import { M, makeScalarMapStore, mustMatch } from '@agoric/store';
9
+ import { M, mustMatch } from '@agoric/store';
10
10
  import {
11
- defineDurableExoClassKit,
12
- makeKindHandle,
11
+ prepareExoClassKit,
12
+ provide,
13
13
  provideDurableMapStore,
14
14
  } from '@agoric/vat-data';
15
15
  import { assertKeywordName } from '@agoric/zoe/src/cleanProposal.js';
@@ -17,25 +17,26 @@ import {
17
17
  atomicRearrange,
18
18
  getAmountIn,
19
19
  getAmountOut,
20
- makeRecorderTopic,
21
20
  makeRatioFromAmounts,
22
- provideChildBaggage,
21
+ makeRecorderTopic,
23
22
  provideEmptySeat,
24
- unitAmount,
25
23
  SubscriberShape,
26
24
  TopicsRecordShape,
25
+ unitAmount,
27
26
  } from '@agoric/zoe/src/contractSupport/index.js';
28
27
  import { E } from '@endo/eventual-send';
29
28
  import { Far } from '@endo/marshal';
30
- import { GovernorFacetShape } from '@agoric/governance/src/typeGuards.js';
31
29
  import { makeCollectFeesInvitation } from '../collectFees.js';
32
30
  import { scheduleLiquidationWakeups } from './liquidation.js';
33
31
  import {
34
- makeVaultParamManager,
32
+ provideVaultParamManagers,
35
33
  SHORTFALL_INVITATION_KEY,
36
34
  vaultParamPattern,
37
35
  } from './params.js';
38
- import { prepareVaultManagerKit } from './vaultManager.js';
36
+ import {
37
+ prepareVaultManagerKit,
38
+ provideAndStartVaultManagerKits,
39
+ } from './vaultManager.js';
39
40
 
40
41
  const { Fail, quote: q } = assert;
41
42
 
@@ -51,14 +52,13 @@ const trace = makeTracer('VD', false);
51
52
  * }>} ImmutableState
52
53
  *
53
54
  * @typedef {{
54
- * managerCounter: number,
55
55
  * }} MutableState
56
56
  *
57
57
  * @typedef {ImmutableState & MutableState} State
58
58
  *
59
59
  * @typedef {{
60
60
  * burnDebt: BurnDebt,
61
- * getGovernedParams: () => import('./vaultManager.js').GovernedParamGetters,
61
+ * getGovernedParams: (collateralBrand: Brand) => import('./vaultManager.js').GovernedParamGetters,
62
62
  * mintAndTransfer: MintAndTransfer,
63
63
  * getShortfallReporter: () => Promise<import('../reserve/assetReserve.js').ShortfallReporter>,
64
64
  * }} FactoryPowersFacet
@@ -69,7 +69,6 @@ const trace = makeTracer('VD', false);
69
69
  *
70
70
  * @typedef {import('@agoric/governance/src/contractGovernance/typedParamManager').TypedParamManager<import('./params.js').VaultDirectorParams>} VaultDirectorParamManager
71
71
  */
72
- // TODO find a way to type 'finish' with the context (state and facets)
73
72
 
74
73
  const shortfallInvitationKey = 'shortfallInvitation';
75
74
 
@@ -97,20 +96,24 @@ export const prepareVaultDirector = (
97
96
  makeRecorderKit,
98
97
  makeERecorderKit,
99
98
  ) => {
99
+ /** @type {import('../reserve/assetReserve.js').ShortfallReporter} */
100
+ let shortfallReporter;
101
+
100
102
  /** For holding newly minted tokens until transferred */
101
103
  const { zcfSeat: mintSeat } = zcf.makeEmptySeatKit();
102
104
 
103
105
  const rewardPoolSeat = provideEmptySeat(zcf, baggage, 'rewardPoolSeat');
104
106
 
105
- /** @type {MapStore<Brand, VaultManager>} */
106
- const collateralTypes = provideDurableMapStore(baggage, 'collateralTypes');
107
+ /** @type {MapStore<Brand, number>} index of manager for the given collateral */
108
+ const collateralManagers = provideDurableMapStore(
109
+ baggage,
110
+ 'collateralManagers',
111
+ );
107
112
 
108
113
  // Non-durable map because param managers aren't durable.
109
114
  // In the event they're needed they can be reconstructed from contract terms and off-chain data.
110
- /**
111
- * @type {MapStore<Brand, ReturnType<typeof makeVaultParamManager>>}
112
- */
113
- const vaultParamManagers = makeScalarMapStore('vaultParamManagers');
115
+ /** a powerful object; can modify parameters */
116
+ const vaultParamManagers = provideVaultParamManagers(baggage, marshaller);
114
117
 
115
118
  const metricsNode = E(storageNode).makeChildNode('metrics');
116
119
 
@@ -121,47 +124,18 @@ export const prepareVaultDirector = (
121
124
  ),
122
125
  );
123
126
 
124
- // TODO helper to make all the topics at once
125
- const topics = harden({
126
- metrics: makeRecorderTopic('Vault Factory metrics', metricsKit),
127
- });
128
-
129
- const allManagersDo = fn => {
130
- for (const vm of collateralTypes.values()) {
131
- fn(vm);
132
- }
133
- };
134
-
135
- const makeWaker = (name, func) => {
136
- return Far(name, {
137
- wake: timestamp => func(timestamp),
138
- });
139
- };
140
127
  const managersNode = E(storageNode).makeChildNode('managers');
141
128
 
142
- const managerBaggages = provideChildBaggage(baggage, 'Vault Manager baggage');
143
-
144
- /** @type {import('../reserve/assetReserve.js').ShortfallReporter} */
145
- let shortfallReporter;
146
-
147
- /**
148
- * @returns {State}
149
- */
150
- const initState = () => {
151
- return {
152
- managerCounter: 0,
153
- };
154
- };
155
-
156
129
  /**
157
130
  * @returns {MetricsNotification}
158
131
  */
159
132
  const sampleMetrics = () => {
160
133
  return harden({
161
- collaterals: Array.from(collateralTypes.keys()),
134
+ collaterals: Array.from(collateralManagers.keys()),
162
135
  rewardPoolAllocation: rewardPoolSeat.getCurrentAllocation(),
163
136
  });
164
137
  };
138
+ const updateMetrics = () => E(metricsKit.recorderP).write(sampleMetrics());
165
139
 
166
140
  const updateShortfallReporter = async () => {
167
141
  const oldInvitation = baggage.has(shortfallInvitationKey)
@@ -188,6 +162,114 @@ export const prepareVaultDirector = (
188
162
  }
189
163
  };
190
164
 
165
+ const factoryPowers = Far('vault factory powers', {
166
+ /**
167
+ * Get read-only params for this manager and its director. This grants all
168
+ * managers access to params from all managers. It's not POLA but it's a
169
+ * public authority and it reduces the number of distinct power objects to
170
+ * create.
171
+ *
172
+ * @param {Brand} brand
173
+ */
174
+ getGovernedParams: brand => {
175
+ const vaultParamManager = vaultParamManagers.get(brand);
176
+ return Far('vault manager param manager', {
177
+ // merge director and manager params
178
+ ...directorParamManager.readonly(),
179
+ ...vaultParamManager.readonly(),
180
+ // redeclare these getters as to specify the kind of the Amount
181
+ getMinInitialDebt: /** @type {() => Amount<'nat'>} */ (
182
+ directorParamManager.readonly().getMinInitialDebt
183
+ ),
184
+ getDebtLimit: /** @type {() => Amount<'nat'>} */ (
185
+ vaultParamManager.readonly().getDebtLimit
186
+ ),
187
+ });
188
+ },
189
+
190
+ /**
191
+ * Let the manager add rewards to the rewardPoolSeat without
192
+ * exposing the rewardPoolSeat to them.
193
+ *
194
+ * @type {MintAndTransfer}
195
+ */
196
+ mintAndTransfer: (mintReceiver, toMint, fee, nonMintTransfers) => {
197
+ const kept = AmountMath.subtract(toMint, fee);
198
+ debtMint.mintGains(harden({ Minted: toMint }), mintSeat);
199
+ /** @type {import('@agoric/zoe/src/contractSupport/atomicTransfer.js').TransferPart[]} */
200
+ const transfers = [
201
+ ...nonMintTransfers,
202
+ [mintSeat, rewardPoolSeat, { Minted: fee }],
203
+ [mintSeat, mintReceiver, { Minted: kept }],
204
+ ];
205
+ try {
206
+ atomicRearrange(zcf, harden(transfers));
207
+ } catch (e) {
208
+ console.error('mintAndTransfer failed to rearrange', e);
209
+ // If the rearrange fails, burn the newly minted tokens.
210
+ // Assume this won't fail because it relies on the internal mint.
211
+ // (Failure would imply much larger problems.)
212
+ debtMint.burnLosses(harden({ Minted: toMint }), mintSeat);
213
+ throw e;
214
+ }
215
+ void updateMetrics();
216
+ },
217
+ getShortfallReporter: async () => {
218
+ await updateShortfallReporter();
219
+ return shortfallReporter;
220
+ },
221
+ /**
222
+ * @param {Amount<'nat'>} toBurn
223
+ * @param {ZCFSeat} seat
224
+ */
225
+ burnDebt: (toBurn, seat) => {
226
+ debtMint.burnLosses(harden({ Minted: toBurn }), seat);
227
+ },
228
+ });
229
+
230
+ const makeVaultManagerKit = prepareVaultManagerKit(baggage, {
231
+ makeERecorderKit,
232
+ makeRecorderKit,
233
+ marshaller,
234
+ factoryPowers,
235
+ zcf,
236
+ });
237
+
238
+ const vaultManagers = provideAndStartVaultManagerKits(baggage);
239
+
240
+ /** @type {(brand: Brand) => VaultManager} */
241
+ const managerForCollateral = brand => {
242
+ const managerIndex = collateralManagers.get(brand);
243
+ const manager = vaultManagers.get(managerIndex).self;
244
+ manager || Fail`no manager ${managerIndex} for collateral ${brand}`;
245
+ return manager;
246
+ };
247
+
248
+ // TODO helper to make all the topics at once
249
+ const topics = harden({
250
+ metrics: makeRecorderTopic('Vault Factory metrics', metricsKit),
251
+ });
252
+
253
+ const allManagersDo = fn => {
254
+ for (const managerIndex of collateralManagers.values()) {
255
+ const vm = vaultManagers.get(managerIndex).self;
256
+ fn(vm);
257
+ }
258
+ };
259
+
260
+ const makeWaker = (name, func) => {
261
+ return Far(name, {
262
+ wake: timestamp => func(timestamp),
263
+ });
264
+ };
265
+
266
+ /**
267
+ * @returns {State}
268
+ */
269
+ const initState = () => {
270
+ return {};
271
+ };
272
+
191
273
  /**
192
274
  * "Director" of the vault factory, overseeing "vault managers".
193
275
  *
@@ -195,8 +277,9 @@ export const prepareVaultDirector = (
195
277
  * @param {VaultDirectorParamManager} directorParamManager
196
278
  * @param {ZCFMint<"nat">} debtMint
197
279
  */
198
- const makeVaultDirector = defineDurableExoClassKit(
199
- makeKindHandle('VaultDirector'),
280
+ const makeVaultDirector = prepareExoClassKit(
281
+ baggage,
282
+ 'VaultDirector',
200
283
  {
201
284
  creator: M.interface('creator', {
202
285
  ...GovernorFacetShape,
@@ -206,7 +289,6 @@ export const prepareVaultDirector = (
206
289
  M.promise(),
207
290
  ),
208
291
  makeCollectFeesInvitation: M.call().returns(M.promise()),
209
- updateMetrics: M.call().returns(M.promise()),
210
292
  getRewardAllocation: M.call().returns({ Minted: AmountShape }),
211
293
  makePriceLockWaker: M.call().returns(M.remotable('TimerWaker')),
212
294
  makeLiquidationWaker: M.call().returns(M.remotable('TimerWaker')),
@@ -228,7 +310,8 @@ export const prepareVaultDirector = (
228
310
  getPublicTopics: M.call().returns(TopicsRecordShape),
229
311
  }),
230
312
  helper: M.interface('helper', {
231
- rescheduleLiquidationWakeups: M.call().returns(),
313
+ rescheduleLiquidationWakeups: M.call().returns(M.promise()),
314
+ start: M.call().returns(M.promise()),
232
315
  }),
233
316
  },
234
317
  initState,
@@ -281,7 +364,6 @@ export const prepareVaultDirector = (
281
364
  initialParamValues,
282
365
  ) {
283
366
  trace('addVaultType', collateralKeyword, initialParamValues);
284
- const { state, facets } = this;
285
367
  mustMatch(collateralIssuer, M.remotable(), 'collateralIssuer');
286
368
  assertKeywordName(collateralKeyword);
287
369
  mustMatch(
@@ -292,120 +374,41 @@ export const prepareVaultDirector = (
292
374
  await zcf.saveIssuer(collateralIssuer, collateralKeyword);
293
375
  const collateralBrand = zcf.getBrandForIssuer(collateralIssuer);
294
376
  // We create only one vault per collateralType.
295
- !collateralTypes.has(collateralBrand) ||
377
+ !collateralManagers.has(collateralBrand) ||
296
378
  Fail`Collateral brand ${q(collateralBrand)} has already been added`;
297
379
 
298
- // counter to be incremented at end of addVaultType
299
- const managerId = `manager${state.managerCounter}`;
380
+ // zero-based index of the manager being made
381
+ const managerIndex = vaultManagers.length();
382
+ const managerId = `manager${managerIndex}`;
300
383
  const managerStorageNode = await E(managersNode).makeChildNode(
301
384
  managerId,
302
385
  );
303
386
 
304
- /** a powerful object; can modify parameters */
305
- const vaultParamManager = makeVaultParamManager(
306
- makeStoredPublisherKit(
307
- managerStorageNode,
308
- marshaller,
309
- 'governance',
310
- ),
387
+ vaultParamManagers.addParamManager(
388
+ collateralBrand,
389
+ managerStorageNode,
311
390
  initialParamValues,
312
391
  );
313
- vaultParamManagers.init(collateralBrand, vaultParamManager);
314
392
 
315
393
  const startTimeStamp = await E(timer).getCurrentTimestamp();
316
394
 
317
- /**
318
- * Let the manager add rewards to the rewardPoolSeat without
319
- * exposing the rewardPoolSeat to them.
320
- *
321
- * @type {MintAndTransfer}
322
- */
323
- const mintAndTransfer = (
324
- mintReceiver,
325
- toMint,
326
- fee,
327
- nonMintTransfers,
328
- ) => {
329
- const kept = AmountMath.subtract(toMint, fee);
330
- debtMint.mintGains(harden({ Minted: toMint }), mintSeat);
331
- /** @type {import('@agoric/zoe/src/contractSupport/atomicTransfer.js').TransferPart[]} */
332
- const transfers = [
333
- ...nonMintTransfers,
334
- [mintSeat, rewardPoolSeat, { Minted: fee }],
335
- [mintSeat, mintReceiver, { Minted: kept }],
336
- ];
337
- try {
338
- atomicRearrange(zcf, harden(transfers));
339
- } catch (e) {
340
- console.error('mintAndTransfer failed to rearrange', e);
341
- // If the rearrange fails, burn the newly minted tokens.
342
- // Assume this won't fail because it relies on the internal mint.
343
- // (Failure would imply much larger problems.)
344
- debtMint.burnLosses(harden({ Minted: toMint }), mintSeat);
345
- throw e;
346
- }
347
- void facets.machine.updateMetrics();
348
- };
349
-
350
- /**
351
- * @param {Amount<'nat'>} toBurn
352
- * @param {ZCFSeat} seat
353
- */
354
- const burnDebt = (toBurn, seat) => {
355
- debtMint.burnLosses(harden({ Minted: toBurn }), seat);
356
- };
357
-
358
- const factoryPowers = Far('vault factory powers', {
359
- /**
360
- * @returns read-only params for this manager and its director
361
- */
362
- getGovernedParams: () =>
363
- Far('vault manager param manager', {
364
- // merge direction and manager params
365
- ...directorParamManager.readonly(),
366
- ...vaultParamManager.readonly(),
367
- // redeclare these getters as to specify the kind of the Amount
368
- getMinInitialDebt: /** @type {() => Amount<'nat'>} */ (
369
- directorParamManager.readonly().getMinInitialDebt
370
- ),
371
- getDebtLimit: /** @type {() => Amount<'nat'>} */ (
372
- vaultParamManager.readonly().getDebtLimit
373
- ),
374
- }),
375
- mintAndTransfer,
376
- getShortfallReporter: async () => {
377
- await updateShortfallReporter();
378
- return shortfallReporter;
379
- },
380
- burnDebt,
381
- });
382
-
383
- // alleged okay because used only as a diagnostic tag
384
- const brandName = await E(collateralBrand).getAllegedName();
385
395
  const collateralUnit = await unitAmount(collateralBrand);
386
396
 
387
- const makeVaultManager = managerBaggages.addChild(
388
- brandName,
389
- prepareVaultManagerKit,
390
- zcf,
391
- marshaller,
392
- makeRecorderKit,
393
- makeERecorderKit,
394
- {
395
- debtMint,
396
- collateralBrand,
397
- collateralUnit,
398
- descriptionScope: managerId,
399
- factoryPowers,
400
- startTimeStamp,
401
- storageNode: managerStorageNode,
402
- },
403
- );
404
-
405
- const { self: vm } = makeVaultManager();
406
- collateralTypes.init(collateralBrand, vm);
407
- void facets.machine.updateMetrics();
408
- state.managerCounter += 1;
397
+ const kit = await makeVaultManagerKit({
398
+ debtMint,
399
+ collateralBrand,
400
+ collateralUnit,
401
+ descriptionScope: managerId,
402
+ startTimeStamp,
403
+ storageNode: managerStorageNode,
404
+ });
405
+ vaultManagers.add(kit);
406
+ vaultManagers.length() - 1 === managerIndex ||
407
+ Fail`mismatch VaultManagerKit count`;
408
+ const { self: vm } = kit;
409
+ vm || Fail`no vault`;
410
+ collateralManagers.init(collateralBrand, managerIndex);
411
+ void updateMetrics();
409
412
  return vm;
410
413
  },
411
414
  makeCollectFeesInvitation() {
@@ -416,9 +419,6 @@ export const prepareVaultDirector = (
416
419
  'Minted',
417
420
  );
418
421
  },
419
- updateMetrics() {
420
- return E(metricsKit.recorderP).write(sampleMetrics());
421
- },
422
422
  // XXX accessors for tests
423
423
  getRewardAllocation() {
424
424
  return rewardPoolSeat.getCurrentAllocation();
@@ -432,7 +432,7 @@ export const prepareVaultDirector = (
432
432
  makeReschedulerWaker() {
433
433
  const { facets } = this;
434
434
  return makeWaker('reschedulerWaker', () => {
435
- facets.helper.rescheduleLiquidationWakeups();
435
+ void facets.helper.rescheduleLiquidationWakeups();
436
436
  });
437
437
  },
438
438
  makePriceLockWaker() {
@@ -446,33 +446,36 @@ export const prepareVaultDirector = (
446
446
  * @param {Brand} brandIn
447
447
  */
448
448
  getCollateralManager(brandIn) {
449
- collateralTypes.has(brandIn) ||
449
+ collateralManagers.has(brandIn) ||
450
450
  Fail`Not a supported collateral type ${brandIn}`;
451
451
  /** @type {VaultManager} */
452
- return collateralTypes.get(brandIn).getPublicFacet();
452
+ return managerForCollateral(brandIn).getPublicFacet();
453
453
  },
454
454
  /**
455
455
  * @deprecated get `collaterals` list from metrics
456
456
  */
457
457
  async getCollaterals() {
458
- // should be collateralTypes.map((vm, brand) => ({
458
+ // should be collateralManagers.map((vm, brand) => ({
459
459
  return harden(
460
460
  Promise.all(
461
- [...collateralTypes.entries()].map(async ([brand, vm]) => {
462
- const priceQuote = await vm.getCollateralQuote();
463
- return {
464
- brand,
465
- interestRate: vm.getGovernedParams().getInterestRate(),
466
- liquidationMargin: vm
467
- .getGovernedParams()
468
- .getLiquidationMargin(),
469
- stabilityFee: vm.getGovernedParams().getMintFee(),
470
- marketPrice: makeRatioFromAmounts(
471
- getAmountOut(priceQuote),
472
- getAmountIn(priceQuote),
473
- ),
474
- };
475
- }),
461
+ [...collateralManagers.entries()].map(
462
+ async ([brand, managerIndex]) => {
463
+ const vm = vaultManagers.get(managerIndex).self;
464
+ const priceQuote = await vm.getCollateralQuote();
465
+ return {
466
+ brand,
467
+ interestRate: vm.getGovernedParams().getInterestRate(),
468
+ liquidationMargin: vm
469
+ .getGovernedParams()
470
+ .getLiquidationMargin(),
471
+ stabilityFee: vm.getGovernedParams().getMintFee(),
472
+ marketPrice: makeRatioFromAmounts(
473
+ getAmountOut(priceQuote),
474
+ getAmountIn(priceQuote),
475
+ ),
476
+ };
477
+ },
478
+ ),
476
479
  ),
477
480
  );
478
481
  },
@@ -523,7 +526,7 @@ export const prepareVaultDirector = (
523
526
  const priceLockWaker = facets.machine.makePriceLockWaker();
524
527
  const liquidationWaker = facets.machine.makeLiquidationWaker();
525
528
  const rescheduleWaker = facets.machine.makeReschedulerWaker();
526
- void scheduleLiquidationWakeups(
529
+ return scheduleLiquidationWakeups(
527
530
  auctioneer,
528
531
  timer,
529
532
  priceLockWaker,
@@ -531,15 +534,33 @@ export const prepareVaultDirector = (
531
534
  rescheduleWaker,
532
535
  );
533
536
  },
534
- },
535
- },
536
- {
537
- finish: ({ facets }) => {
538
- facets.helper.rescheduleLiquidationWakeups();
539
- void updateShortfallReporter();
537
+ /**
538
+ * Start non-durable processes (or restart if needed after vat restart)
539
+ */
540
+ async start() {
541
+ const { helper } = this.facets;
542
+ helper.rescheduleLiquidationWakeups();
543
+ await updateShortfallReporter();
544
+ },
540
545
  },
541
546
  },
542
547
  );
543
548
  return makeVaultDirector;
544
549
  };
545
550
  harden(prepareVaultDirector);
551
+
552
+ /**
553
+ * Prepare the VaultDirector kind, get or make the singleton, and call .start() to kick off processes.
554
+ *
555
+ * @type {(...pvdArgs: Parameters<typeof prepareVaultDirector>) => ReturnType<ReturnType<typeof prepareVaultDirector>>}
556
+ */
557
+ export const provideAndStartDirector = (...args) => {
558
+ const makeVaultDirector = prepareVaultDirector(...args);
559
+
560
+ const [baggage] = args;
561
+
562
+ const director = provide(baggage, 'director', makeVaultDirector);
563
+ director.helper.start();
564
+ return director;
565
+ };
566
+ harden(provideAndStartDirector);
@@ -20,12 +20,15 @@ import '@agoric/zoe/src/contracts/exported.js';
20
20
  import { CONTRACT_ELECTORATE } from '@agoric/governance';
21
21
  import { makeParamManagerFromTerms } from '@agoric/governance/src/contractGovernance/typedParamManager.js';
22
22
  import { validateElectorate } from '@agoric/governance/src/contractHelper.js';
23
- import { assertAllDefined } from '@agoric/internal';
23
+ import { assertAllDefined, makeTracer } from '@agoric/internal';
24
24
  import { makeStoredSubscription, makeSubscriptionKit } from '@agoric/notifier';
25
+ import { provideAll } from '@agoric/zoe/src/contractSupport/durability.js';
25
26
  import { prepareRecorderKitMakers } from '@agoric/zoe/src/contractSupport/recorder.js';
26
27
  import { E } from '@endo/eventual-send';
27
28
  import { SHORTFALL_INVITATION_KEY, vaultDirectorParamTypes } from './params.js';
28
- import { prepareVaultDirector } from './vaultDirector.js';
29
+ import { provideAndStartDirector } from './vaultDirector.js';
30
+
31
+ const trace = makeTracer('VF', false);
29
32
 
30
33
  /**
31
34
  * @typedef {ZCF<GovernanceTerms<import('./params').VaultDirectorParams> & {
@@ -47,7 +50,8 @@ import { prepareVaultDirector } from './vaultDirector.js';
47
50
  * }} privateArgs
48
51
  * @param {import('@agoric/ertp').Baggage} baggage
49
52
  */
50
- export const start = async (zcf, privateArgs, baggage) => {
53
+ export const prepare = async (zcf, privateArgs, baggage) => {
54
+ trace('prepare start', privateArgs, [...baggage.keys()]);
51
55
  const {
52
56
  feeMintAccess,
53
57
  initialPoserInvitation,
@@ -62,7 +66,12 @@ export const start = async (zcf, privateArgs, baggage) => {
62
66
  marshaller,
63
67
  storageNode,
64
68
  });
65
- const debtMint = await zcf.registerFeeMint('Minted', feeMintAccess);
69
+
70
+ trace('awaiting debtMint');
71
+ const { debtMint } = await provideAll(baggage, {
72
+ debtMint: () => zcf.registerFeeMint('Minted', privateArgs.feeMintAccess),
73
+ });
74
+
66
75
  zcf.setTestJig(() => ({
67
76
  mintedIssuerRecord: debtMint.getIssuerRecord(),
68
77
  }));
@@ -74,7 +83,8 @@ export const start = async (zcf, privateArgs, baggage) => {
74
83
  marshaller,
75
84
  );
76
85
 
77
- // XXX non-durable
86
+ trace('making non-durable publishers');
87
+ // XXX non-durable, will sever upon vat restart
78
88
  const governanceSubscriptionKit = makeSubscriptionKit();
79
89
  const governanceNode = E(storageNode).makeChildNode('governance');
80
90
  const governanceSubscriber = makeStoredSubscription(
@@ -83,6 +93,7 @@ export const start = async (zcf, privateArgs, baggage) => {
83
93
  marshaller,
84
94
  );
85
95
  /** a powerful object; can modify the invitation */
96
+ trace('awaiting makeParamManagerFromTerms');
86
97
  const vaultDirectorParamManager = await makeParamManagerFromTerms(
87
98
  {
88
99
  publisher: governanceSubscriptionKit.publication,
@@ -96,7 +107,7 @@ export const start = async (zcf, privateArgs, baggage) => {
96
107
  vaultDirectorParamTypes,
97
108
  );
98
109
 
99
- const makeVaultDirector = prepareVaultDirector(
110
+ const director = provideAndStartDirector(
100
111
  baggage,
101
112
  zcf,
102
113
  vaultDirectorParamManager,
@@ -110,16 +121,14 @@ export const start = async (zcf, privateArgs, baggage) => {
110
121
  makeERecorderKit,
111
122
  );
112
123
 
113
- const factory = makeVaultDirector();
114
-
115
124
  // validate async to wait for params to be finished
116
125
  // UNTIL https://github.com/Agoric/agoric-sdk/issues/4343
117
126
  void validateElectorate(zcf, vaultDirectorParamManager);
118
127
 
119
128
  return harden({
120
- creatorFacet: factory.creator,
121
- publicFacet: factory.public,
129
+ creatorFacet: director.creator,
130
+ publicFacet: director.public,
122
131
  });
123
132
  };
124
133
 
125
- /** @typedef {ContractOf<typeof start>} VaultFactoryContract */
134
+ /** @typedef {ContractOf<typeof prepare>} VaultFactoryContract */