@agoric/inter-protocol 0.16.2-other-dev-8f8782b.0 → 0.16.2-other-dev-fbe72e7.0.fbe72e7

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 (166) hide show
  1. package/README.md +6 -6
  2. package/package.json +46 -39
  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 +182 -151
  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 +70 -0
  11. package/src/auction/auctioneer.d.ts.map +1 -0
  12. package/src/auction/auctioneer.js +72 -59
  13. package/src/auction/offerBook.d.ts +46 -0
  14. package/src/auction/offerBook.d.ts.map +1 -0
  15. package/src/auction/offerBook.js +17 -12
  16. package/src/auction/params.d.ts +145 -0
  17. package/src/auction/params.d.ts.map +1 -0
  18. package/src/auction/params.js +11 -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 +31 -0
  29. package/src/auction/util.d.ts.map +1 -0
  30. package/src/auction/util.js +12 -6
  31. package/src/clientSupport.d.ts +168 -0
  32. package/src/clientSupport.d.ts.map +1 -0
  33. package/src/clientSupport.js +161 -98
  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 +43 -0
  40. package/src/econCommitteeCharter.d.ts.map +1 -0
  41. package/src/econCommitteeCharter.js +25 -20
  42. package/src/feeDistributor.d.ts +224 -0
  43. package/src/feeDistributor.d.ts.map +1 -0
  44. package/src/feeDistributor.js +41 -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 +4 -0
  49. package/src/interest-math.d.ts.map +1 -0
  50. package/src/interest-math.js +5 -1
  51. package/src/interest.d.ts +30 -0
  52. package/src/interest.d.ts.map +1 -0
  53. package/src/interest.js +25 -23
  54. package/src/price/README.md +14 -1
  55. package/src/price/fluxAggregatorContract.d.ts +71 -0
  56. package/src/price/fluxAggregatorContract.d.ts.map +1 -0
  57. package/src/price/fluxAggregatorContract.js +64 -55
  58. package/src/price/fluxAggregatorKit.d.ts +104 -0
  59. package/src/price/fluxAggregatorKit.d.ts.map +1 -0
  60. package/src/price/fluxAggregatorKit.js +55 -42
  61. package/src/price/priceOracleKit.d.ts +39 -0
  62. package/src/price/priceOracleKit.d.ts.map +1 -0
  63. package/src/price/priceOracleKit.js +17 -15
  64. package/src/price/roundsManager.d.ts +204 -0
  65. package/src/price/roundsManager.d.ts.map +1 -0
  66. package/src/price/roundsManager.js +132 -85
  67. package/src/proposals/README.md +2 -3
  68. package/src/proposals/add-auction.js +285 -0
  69. package/src/proposals/addAssetToVault.js +192 -40
  70. package/src/proposals/committee-proposal.js +25 -31
  71. package/src/proposals/core-proposal.js +9 -11
  72. package/src/proposals/deploy-price-feeds.js +341 -0
  73. package/src/proposals/econ-behaviors.js +84 -49
  74. package/src/proposals/price-feed-proposal.js +109 -51
  75. package/src/proposals/replace-fee-distributor.js +198 -0
  76. package/src/proposals/replace-scaledPriceAuthorities.js +124 -0
  77. package/src/proposals/replaceElectorate.js +610 -0
  78. package/src/proposals/startEconCommittee.js +2 -2
  79. package/src/proposals/startPSM.js +44 -29
  80. package/src/proposals/upgrade-scaledPriceAuthorities.js +78 -0
  81. package/src/proposals/upgrade-vaults.js +207 -0
  82. package/src/proposals/utils.d.ts +21 -0
  83. package/src/proposals/utils.d.ts.map +1 -0
  84. package/src/proposals/utils.js +66 -9
  85. package/src/proposals/withdraw-reserve-proposal.js +63 -0
  86. package/src/provisionPool.d.ts +69 -0
  87. package/src/provisionPool.d.ts.map +1 -0
  88. package/src/provisionPool.js +138 -0
  89. package/src/provisionPoolKit.d.ts +129 -0
  90. package/src/provisionPoolKit.d.ts.map +1 -0
  91. package/src/provisionPoolKit.js +608 -0
  92. package/src/psm/psm.d.ts +133 -0
  93. package/src/psm/psm.d.ts.map +1 -0
  94. package/src/psm/psm.js +85 -79
  95. package/src/psm/types-ambient.d.ts +2 -0
  96. package/src/psm/types-ambient.d.ts.map +1 -0
  97. package/src/psm/types-ambient.js +3 -0
  98. package/src/reserve/assetReserve.d.ts +58 -0
  99. package/src/reserve/assetReserve.d.ts.map +1 -0
  100. package/src/reserve/assetReserve.js +42 -34
  101. package/src/reserve/assetReserveKit.d.ts +103 -0
  102. package/src/reserve/assetReserveKit.d.ts.map +1 -0
  103. package/src/reserve/assetReserveKit.js +134 -32
  104. package/src/reserve/params.d.ts +16 -0
  105. package/src/reserve/params.d.ts.map +1 -0
  106. package/src/reserve/params.js +8 -2
  107. package/src/tokens.d.ts +3 -0
  108. package/src/tokens.d.ts.map +1 -0
  109. package/src/tokens.js +5 -0
  110. package/src/vaultFactory/burn.d.ts +2 -0
  111. package/src/vaultFactory/burn.d.ts.map +1 -0
  112. package/src/vaultFactory/burn.js +1 -1
  113. package/src/vaultFactory/liquidation.d.ts +25 -0
  114. package/src/vaultFactory/liquidation.d.ts.map +1 -0
  115. package/src/vaultFactory/liquidation.js +37 -24
  116. package/src/vaultFactory/math.d.ts +11 -0
  117. package/src/vaultFactory/math.d.ts.map +1 -0
  118. package/src/vaultFactory/math.js +11 -10
  119. package/src/vaultFactory/orderedVaultStore.d.ts +94 -0
  120. package/src/vaultFactory/orderedVaultStore.d.ts.map +1 -0
  121. package/src/vaultFactory/orderedVaultStore.js +9 -10
  122. package/src/vaultFactory/params.d.ts +143 -0
  123. package/src/vaultFactory/params.d.ts.map +1 -0
  124. package/src/vaultFactory/params.js +56 -25
  125. package/src/vaultFactory/prioritizedVaults.d.ts +280 -0
  126. package/src/vaultFactory/prioritizedVaults.d.ts.map +1 -0
  127. package/src/vaultFactory/prioritizedVaults.js +7 -4
  128. package/src/vaultFactory/proceeds.d.ts +35 -0
  129. package/src/vaultFactory/proceeds.d.ts.map +1 -0
  130. package/src/vaultFactory/proceeds.js +26 -18
  131. package/src/vaultFactory/storeUtils.d.ts +25 -0
  132. package/src/vaultFactory/storeUtils.d.ts.map +1 -0
  133. package/src/vaultFactory/storeUtils.js +10 -12
  134. package/src/vaultFactory/types-ambient.d.ts +137 -0
  135. package/src/vaultFactory/types-ambient.d.ts.map +1 -0
  136. package/src/vaultFactory/{types.js → types-ambient.js} +47 -44
  137. package/src/vaultFactory/vault.d.ts +344 -0
  138. package/src/vaultFactory/vault.d.ts.map +1 -0
  139. package/src/vaultFactory/vault.js +107 -100
  140. package/src/vaultFactory/vaultDirector.d.ts +347 -0
  141. package/src/vaultFactory/vaultDirector.d.ts.map +1 -0
  142. package/src/vaultFactory/vaultDirector.js +94 -64
  143. package/src/vaultFactory/vaultFactory.d.ts +250 -0
  144. package/src/vaultFactory/vaultFactory.d.ts.map +1 -0
  145. package/src/vaultFactory/vaultFactory.js +56 -33
  146. package/src/vaultFactory/vaultHolder.d.ts +170 -0
  147. package/src/vaultFactory/vaultHolder.d.ts.map +1 -0
  148. package/src/vaultFactory/vaultHolder.js +14 -15
  149. package/src/vaultFactory/vaultKit.d.ts +33 -0
  150. package/src/vaultFactory/vaultKit.d.ts.map +1 -0
  151. package/src/vaultFactory/vaultKit.js +9 -4
  152. package/src/vaultFactory/vaultManager.d.ts +676 -0
  153. package/src/vaultFactory/vaultManager.d.ts.map +1 -0
  154. package/src/vaultFactory/vaultManager.js +286 -167
  155. package/CHANGELOG.md +0 -1041
  156. package/exported.js +0 -2
  157. package/scripts/add-collateral-core.js +0 -112
  158. package/scripts/deploy-contracts.js +0 -100
  159. package/scripts/init-core.js +0 -198
  160. package/scripts/invite-committee-core.js +0 -42
  161. package/scripts/manual-price-feed.js +0 -117
  162. package/scripts/price-feed-core.js +0 -104
  163. package/scripts/start-local-chain.sh +0 -84
  164. package/src/psm/types.js +0 -3
  165. package/src/typeGuards.js +0 -13
  166. package/src/vaultFactory/type-imports.js +0 -4
@@ -1,19 +1,20 @@
1
1
  // @jessie-check
2
2
 
3
3
  import { makeMap } from 'jessie.js';
4
+ import { X } from '@endo/errors';
5
+ import { E } from '@endo/far';
4
6
  import { AmountMath, AssetKind } from '@agoric/ertp';
5
7
  import { CONTRACT_ELECTORATE, ParamTypes } from '@agoric/governance';
6
8
  import { makeStorageNodeChild } from '@agoric/internal/src/lib-chainStorage.js';
7
9
  import { makeRatio } from '@agoric/zoe/src/contractSupport/index.js';
8
- import { E } from '@endo/far';
9
- import { Stable } from '@agoric/vats/src/tokens.js';
10
10
  import {
11
11
  makeHistoryReviver,
12
12
  makeBoardRemote,
13
13
  slotToBoardRemote,
14
- } from '@agoric/vats/tools/board-utils.js';
14
+ } from '@agoric/internal/src/marshal.js';
15
15
  import { deeplyFulfilledObject } from '@agoric/internal';
16
16
  import { makeScalarBigMapStore } from '@agoric/vat-data';
17
+ import { Stable } from '@agoric/internal/src/tokens.js';
17
18
 
18
19
  import { reserveThenGetNamePaths } from './utils.js';
19
20
 
@@ -23,22 +24,24 @@ import {
23
24
  inviteToEconCharter,
24
25
  } from './committee-proposal.js';
25
26
 
26
- /** @typedef {import('@agoric/vats/src/core/lib-boot.js').BootstrapManifest} BootstrapManifest */
27
- /** @typedef {import('../psm/psm.js').MetricsNotification} MetricsNotification */
28
- /** @typedef {import('./econ-behaviors.js').EconomyBootstrapPowers} EconomyBootstrapPowers */
27
+ /** @import {BootstrapManifest} from '@agoric/vats/src/core/lib-boot.js' */
28
+ /** @import {MetricsNotification} from '../psm/psm.js' */
29
+ /** @import {EconomyBootstrapPowers} from './econ-behaviors.js' */
29
30
 
30
31
  const BASIS_POINTS = 10000n;
31
- const { details: X } = assert;
32
32
 
33
33
  export { inviteCommitteeMembers, startEconCharter, inviteToEconCharter };
34
34
 
35
35
  const stablePsmKey = `published.psm.${Stable.symbol}`;
36
36
 
37
37
  /**
38
- * @param {Array<[key: string, value: string]>} chainStorageEntries
38
+ * @param {[key: string, value: string][]} chainStorageEntries
39
39
  * @param {string} keyword
40
- * @param {{ minted: Brand<'nat'>, anchor: Brand<'nat'> }} brands
41
- * @returns {{ metrics?: MetricsNotification, governance?: GovernanceSubscriptionState }}
40
+ * @param {{ minted: Brand<'nat'>; anchor: Brand<'nat'> }} brands
41
+ * @returns {{
42
+ * metrics?: MetricsNotification;
43
+ * governance?: GovernanceSubscriptionState;
44
+ * }}
42
45
  */
43
46
  const findOldPSMState = (chainStorageEntries, keyword, brands) => {
44
47
  // In this reviver, object references are revived as boardIDs
@@ -80,7 +83,7 @@ const findOldPSMState = (chainStorageEntries, keyword, brands) => {
80
83
  * @param {bigint} [config.WantMintedFeeBP]
81
84
  * @param {bigint} [config.GiveMintedFeeBP]
82
85
  * @param {bigint} [config.MINT_LIMIT]
83
- * @param {{ anchorOptions?: AnchorOptions } } [config.options]
86
+ * @param {{ anchorOptions?: AnchorOptions }} [config.options]
84
87
  */
85
88
  export const startPSM = async (
86
89
  {
@@ -273,7 +276,6 @@ export const startPSM = async (
273
276
  governorFacets.creatorFacet,
274
277
  instanceKey,
275
278
  ),
276
- // @ts-expect-error TODO type for provisionPoolStartResult
277
279
  E(E.get(provisionPoolStartResult).creatorFacet).initPSM(
278
280
  anchorBrand,
279
281
  newpsmKit.psm,
@@ -291,16 +293,16 @@ harden(startPSM);
291
293
  */
292
294
 
293
295
  /**
294
- * Make anchor issuer out of a Cosmos asset; presumably
295
- * USDC over IBC. Add it to BankManager.
296
+ * Make anchor issuer out of a Cosmos asset; presumably USDC over IBC. Add it to
297
+ * BankManager.
296
298
  *
297
- * Also, if vatParameters shows an anchorPoolBalance for this asset,
298
- * mint a payment for that balance.
299
+ * Also, if vatParameters shows an anchorPoolBalance for this asset, mint a
300
+ * payment for that balance.
299
301
  *
300
302
  * TODO: address redundancy with publishInterchainAssetFromBank
301
303
  *
302
304
  * @param {EconomyBootstrapPowers & WellKnownSpaces & ChainStorageVatParams} powers
303
- * @param {{options?: { anchorOptions?: AnchorOptions } }} [config]
305
+ * @param {{ options: { anchorOptions?: AnchorOptions } }} config
304
306
  */
305
307
  export const makeAnchorAsset = async (
306
308
  {
@@ -345,17 +347,27 @@ export const makeAnchorAsset = async (
345
347
  }),
346
348
  );
347
349
 
348
- /** @type {{ creatorFacet: ERef<Mint<'nat'>>, publicFacet: ERef<Issuer<'nat'>> }} */
349
- // @ts-expect-error cast
350
- const { creatorFacet: mint, publicFacet: issuer } = await E(startUpgradable)({
351
- installation: mintHolder,
352
- label: keyword,
353
- terms,
354
- });
350
+ /**
351
+ * @typedef {{
352
+ * creatorFacet: ERef<Mint<'nat'>>;
353
+ * publicFacet: ERef<Issuer<'nat'>>;
354
+ * }} PsmKit
355
+ */
356
+
357
+ const { creatorFacet: mint, publicFacet: issuer } =
358
+ /** @type {PsmKit} */
359
+ (
360
+ await E(startUpgradable)({
361
+ installation: mintHolder,
362
+ label: keyword,
363
+ terms,
364
+ })
365
+ );
355
366
 
356
367
  const brand = await E(issuer).getBrand();
357
368
  const kit = harden({ mint, issuer, brand });
358
369
 
370
+ // @ts-expect-error XXX AssetIssuerKit
359
371
  testFirstAnchorKit.resolve(kit);
360
372
 
361
373
  const toSlotReviver = makeHistoryReviver(
@@ -363,23 +375,25 @@ export const makeAnchorAsset = async (
363
375
  slotToBoardRemote,
364
376
  );
365
377
  const metricsKey = `${stablePsmKey}.${keyword}.metrics`;
366
- if (toSlotReviver.has(metricsKey)) {
378
+ const maybeReviveMetrics = async () => {
379
+ if (!toSlotReviver.has(metricsKey)) {
380
+ return;
381
+ }
367
382
  const metrics = toSlotReviver.getItem(metricsKey);
368
383
  produceAnchorBalancePayments.resolve(
369
384
  makeScalarBigMapStore('Anchor balance payments', { durable: true }),
370
385
  );
371
386
  // XXX this rule should only apply to the 1st await
372
- // eslint-disable-next-line @jessie.js/no-nested-await
373
387
  const anchorPaymentMap = await anchorBalancePayments;
374
388
 
375
389
  // TODO: validate that `metrics.anchorPoolBalance.value` is
376
390
  // pass-by-copy PureData (e.g., contains no remotables).
377
- // eslint-disable-next-line @jessie.js/no-nested-await
378
391
  const pmt = await E(mint).mintPayment(
379
392
  AmountMath.make(brand, metrics.anchorPoolBalance.value),
380
393
  );
381
394
  anchorPaymentMap.init(brand, pmt);
382
- }
395
+ };
396
+ await maybeReviveMetrics();
383
397
 
384
398
  await Promise.all([
385
399
  E(E(agoricNamesAdmin).lookupAdmin('issuer')).update(keyword, kit.issuer),
@@ -388,13 +402,14 @@ export const makeAnchorAsset = async (
388
402
  denom,
389
403
  keyword,
390
404
  proposedName,
405
+ // @ts-expect-error XXX AssetIssuerKit
391
406
  kit, // with mint
392
407
  ),
393
408
  ]);
394
409
  };
395
410
  harden(makeAnchorAsset);
396
411
 
397
- /** @typedef {import('./econ-behaviors.js').EconomyBootstrapSpace} EconomyBootstrapSpace */
412
+ /** @import {EconomyBootstrapSpace} from './econ-behaviors.js' */
398
413
 
399
414
  export const INVITE_PSM_COMMITTEE_MANIFEST = harden(
400
415
  /** @type {BootstrapManifest} */ ({
@@ -0,0 +1,78 @@
1
+ import { makeTracer } from '@agoric/internal';
2
+ import { E } from '@endo/far';
3
+
4
+ const trace = makeTracer('upgradeScaledPA', true);
5
+
6
+ /**
7
+ * @param {ChainBootstrapSpace} powers
8
+ * @param {{ options: { scaledPARef: { bundleID: string } } }} options
9
+ */
10
+ export const upgradeScaledPriceAuthorities = async (
11
+ {
12
+ consume: {
13
+ agoricNamesAdmin,
14
+ contractKits: contractKitsP,
15
+ instancePrivateArgs: instancePrivateArgsP,
16
+ zoe,
17
+ },
18
+ },
19
+ { options },
20
+ ) => {
21
+ trace('start');
22
+ const { scaledPARef } = options;
23
+ await null;
24
+
25
+ const bundleID = scaledPARef.bundleID;
26
+ if (scaledPARef && bundleID) {
27
+ await E.when(
28
+ E(zoe).installBundleID(bundleID),
29
+ installation =>
30
+ E(E(agoricNamesAdmin).lookupAdmin('installation')).update(
31
+ 'scaledPriceAuthority',
32
+ installation,
33
+ ),
34
+ err =>
35
+ console.error(
36
+ `🚨 failed to update scaledPriceAuthority installation`,
37
+ err,
38
+ ),
39
+ );
40
+ }
41
+
42
+ const [contractKits, instancePrivateArgs] = await Promise.all([
43
+ contractKitsP,
44
+ instancePrivateArgsP,
45
+ ]);
46
+ /** @type {StartedInstanceKit<any>[]} */
47
+ const scaledPAKitEntries = Array.from(contractKits.values()).filter(
48
+ kit => kit.label && kit.label.match(/scaledPriceAuthority/),
49
+ );
50
+
51
+ for (const kitEntry of scaledPAKitEntries) {
52
+ const { instance } = kitEntry;
53
+ const privateArgs = instancePrivateArgs.get(instance);
54
+ trace('upgrade scaledPriceAuthority', kitEntry.label);
55
+ await E(kitEntry.adminFacet).upgradeContract(bundleID, privateArgs);
56
+ }
57
+ };
58
+
59
+ const t = 'upgradeScaledPriceAuthority';
60
+ export const getManifestForUpgradeScaledPriceAuthorities = async (
61
+ _ign,
62
+ upgradeSPAOptions,
63
+ ) => ({
64
+ manifest: {
65
+ [upgradeScaledPriceAuthorities.name]: {
66
+ consume: {
67
+ agoricNamesAdmin: t,
68
+ contractKits: t,
69
+ instancePrivateArgs: t,
70
+ zoe: t,
71
+ },
72
+ instance: {
73
+ produce: t,
74
+ },
75
+ },
76
+ },
77
+ options: { ...upgradeSPAOptions },
78
+ });
@@ -0,0 +1,207 @@
1
+ /**
2
+ * @file this core-eval proposal is specific to the upgrade-18 scenario,
3
+ * handling tasks beyond generic Vault Factory null upgrade. For a reusable
4
+ * proposal, see upgrade-vaultFactory-proposal.js.
5
+ */
6
+
7
+ import { E } from '@endo/far';
8
+ import { makeNotifierFromAsyncIterable } from '@agoric/notifier';
9
+ import { makeTracer } from '@agoric/internal/src/index.js';
10
+ import { Fail } from '@endo/errors';
11
+ import { TimeMath } from '@agoric/time';
12
+
13
+ const trace = makeTracer('upgrade Vaults proposal');
14
+
15
+ /**
16
+ * @typedef {PromiseSpaceOf<{
17
+ * priceAuthority8400: Instance;
18
+ * auctionUpgradeNewInstance: Instance;
19
+ * newContractGovBundleId: string;
20
+ * }>} interlockPowers
21
+ */
22
+
23
+ /**
24
+ * @param {import('../../src/proposals/econ-behaviors').EconomyBootstrapPowers &
25
+ * interlockPowers} powers
26
+ * @param {{
27
+ * options: {
28
+ * VaultFactoryBundle: { bundleID: string };
29
+ * };
30
+ * }} options
31
+ */
32
+ export const upgradeVaults = async (
33
+ {
34
+ consume: {
35
+ auctionUpgradeNewInstance,
36
+ chainTimerService,
37
+ economicCommitteeCreatorFacet: electorateCreatorFacet,
38
+ reserveKit,
39
+ vaultFactoryKit,
40
+ zoe,
41
+ priceAuthority8400,
42
+ newContractGovBundleId: newContractGovBundleIdP,
43
+ },
44
+ produce: {
45
+ auctionUpgradeNewInstance: auctionUpgradeNewInstanceProducer,
46
+ newContractGovBundleId: newContractGovBundleIdErasor,
47
+ },
48
+ },
49
+ { options: { VaultFactoryBundle: vaultBundleRef } },
50
+ ) => {
51
+ const kit = await vaultFactoryKit;
52
+ const { instance: directorInstance } = kit;
53
+ const allBrands = await E(zoe).getBrands(directorInstance);
54
+ const { Minted: _istBrand, ...vaultBrands } = allBrands;
55
+
56
+ await priceAuthority8400;
57
+
58
+ /** @type {Instance<import('../auction/auctioneer.js').start>} */
59
+ const auctionNewInstance = await auctionUpgradeNewInstance;
60
+ auctionUpgradeNewInstanceProducer.reset();
61
+ const publicFacet = E(zoe).getPublicFacet(auctionNewInstance);
62
+ const schedules = await E(publicFacet).getSchedules();
63
+ const now = await E(chainTimerService).getCurrentTimestamp();
64
+ (schedules.nextAuctionSchedule &&
65
+ TimeMath.compareAbs(schedules.nextAuctionSchedule.startTime, now) > 0) ||
66
+ Fail`Expected next start time in the future ${schedules.nextAuctionSchedule?.startTime}`;
67
+
68
+ const readCurrentDirectorParams = async () => {
69
+ const { publicFacet: directorPF } = kit;
70
+
71
+ await null;
72
+
73
+ const subscription = E(directorPF).getElectorateSubscription();
74
+ const notifier = makeNotifierFromAsyncIterable(subscription);
75
+ const { updateCount } = await notifier.getUpdateSince();
76
+
77
+ // subscribeAfter(<some known state>) retrieves the latest value.
78
+ const after = await E(subscription).subscribeAfter(updateCount);
79
+ const { current } = after.head.value;
80
+
81
+ return harden({
82
+ MinInitialDebt: current.MinInitialDebt.value,
83
+ ReferencedUI: current.ReferencedUI.value,
84
+ RecordingPeriod: current.RecordingPeriod.value,
85
+ ChargingPeriod: current.ChargingPeriod.value,
86
+ });
87
+ };
88
+ const directorParamOverrides = await readCurrentDirectorParams();
89
+ trace({ directorParamOverrides });
90
+
91
+ const readManagerParams = async () => {
92
+ const { publicFacet: directorPF } = kit;
93
+
94
+ await null;
95
+
96
+ const params = {};
97
+ for (const kwd of Object.keys(vaultBrands)) {
98
+ const collateralBrand = vaultBrands[kwd];
99
+
100
+ const governedParams = await E(directorPF).getGovernedParams({
101
+ collateralBrand,
102
+ });
103
+ trace({ kwd, governedParams });
104
+ params[kwd] = harden({
105
+ brand: collateralBrand,
106
+ debtLimit: governedParams.DebtLimit.value,
107
+ interestRate: governedParams.InterestRate.value,
108
+ liquidationMargin: governedParams.LiquidationMargin.value,
109
+ liquidationPadding: governedParams.LiquidationPadding.value,
110
+ liquidationPenalty: governedParams.LiquidationPenalty.value,
111
+ mintFee: governedParams.MintFee.value,
112
+ });
113
+ trace(kwd, params[kwd]);
114
+ }
115
+ return params;
116
+ };
117
+ const managerParamValues = await readManagerParams();
118
+
119
+ // upgrade the vaultFactory
120
+ const upgradeVaultFactory = async () => {
121
+ // @ts-expect-error cast XXX privateArgs missing from type
122
+ const { privateArgs } = kit;
123
+
124
+ const shortfallInvitation = await E(
125
+ E.get(reserveKit).creatorFacet,
126
+ ).makeShortfallReportingInvitation();
127
+
128
+ const poserInvitation = await E(
129
+ electorateCreatorFacet,
130
+ ).getPoserInvitation();
131
+
132
+ /** @type {import('../../src/vaultFactory/vaultFactory').VaultFactoryContract['privateArgs']} */
133
+ const newPrivateArgs = harden({
134
+ ...privateArgs,
135
+ auctioneerInstance: auctionNewInstance,
136
+ initialPoserInvitation: poserInvitation,
137
+ initialShortfallInvitation: shortfallInvitation,
138
+ managerParams: managerParamValues,
139
+ directorParamOverrides,
140
+ });
141
+
142
+ const upgradeResult = await E(kit.adminFacet).upgradeContract(
143
+ vaultBundleRef.bundleID,
144
+ newPrivateArgs,
145
+ );
146
+
147
+ trace('upgraded vaultFactory.', upgradeResult);
148
+ };
149
+ await upgradeVaultFactory();
150
+
151
+ // @ts-expect-error It's saved in econ-behaviors.js:startVaultFactory()
152
+ const vaultFactoryPrivateArgs = kit.privateArgs;
153
+ trace('restarting governor');
154
+
155
+ const [ecf, newContractGovBundleId] = await Promise.all([
156
+ electorateCreatorFacet,
157
+ newContractGovBundleIdP,
158
+ ]);
159
+ newContractGovBundleIdErasor.reset();
160
+
161
+ // upgrade vaultFactory governor. Won't be needed next time: see #10063
162
+ await E(kit.governorAdminFacet).upgradeContract(
163
+ newContractGovBundleId,
164
+ harden({
165
+ electorateCreatorFacet: ecf,
166
+ governed: vaultFactoryPrivateArgs,
167
+ }),
168
+ );
169
+
170
+ trace('restarted governor');
171
+ };
172
+
173
+ const uV = 'upgradeVaults';
174
+ /**
175
+ * Return the manifest, installations, and options for upgrading Vaults.
176
+ *
177
+ * @param {object} utils
178
+ * @param {any} utils.restoreRef
179
+ * @param {any} vaultUpgradeOptions
180
+ */
181
+ export const getManifestForUpgradeVaults = async (
182
+ { restoreRef },
183
+ { VaultFactoryRef },
184
+ ) => {
185
+ return {
186
+ manifest: {
187
+ [upgradeVaults.name]: {
188
+ consume: {
189
+ priceAuthority8400: uV,
190
+ auctionUpgradeNewInstance: uV,
191
+ chainTimerService: uV,
192
+ economicCommitteeCreatorFacet: uV,
193
+ reserveKit: uV,
194
+ vaultFactoryKit: uV,
195
+ zoe: uV,
196
+ newContractGovBundleId: uV,
197
+ },
198
+ produce: {
199
+ auctionUpgradeNewInstance: uV,
200
+ newContractGovBundleId: uV,
201
+ },
202
+ },
203
+ },
204
+ installations: { VaultFactory: restoreRef(VaultFactoryRef) },
205
+ options: { VaultFactoryBundle: VaultFactoryRef },
206
+ };
207
+ };
@@ -0,0 +1,21 @@
1
+ export function reserveThenGetNamePaths(nameAdmin: ERef<import("@agoric/vats").NameAdmin>, paths: string[][]): Promise<any[]>;
2
+ export function reserveThenGetNames(nameAdmin: ERef<import("@agoric/vats").NameAdmin>, names: string[]): Promise<any[]>;
3
+ export function reserveThenDeposit(debugName: string, namesByAddressAdmin: ERef<import("@agoric/vats").NameAdmin>, addr: string, payments: ERef<Payment>[]): Promise<void>;
4
+ export function makeInstallCache(homeP: Promise<{
5
+ scratch: ERef<import("@agoric/internal/src/scratch.js").ScratchPad>;
6
+ }>, { installCacheKey, loadBundle }: {
7
+ loadBundle: (specifier: string) => Promise<{
8
+ default: Bundle;
9
+ }>;
10
+ installCacheKey?: string | undefined;
11
+ }): Promise<{
12
+ wrapInstall: (install: any) => (mPath: any, bPath: any, opts: any) => Promise<any>;
13
+ saveCache: () => Promise<void>;
14
+ }>;
15
+ export function oracleBrandFeedName(inBrandName: any, outBrandName: any): string;
16
+ export function scaledPriceFeedName(issuerName: any): string;
17
+ /** @type {(name: string) => string} */
18
+ export const sanitizePathSegment: (name: string) => string;
19
+ export function provideRetiredInstances(consume: Promise<MapStore>, produce: Producer<MapStore>): Promise<MapStore>;
20
+ import type { MapStore } from '@agoric/store';
21
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["utils.js"],"names":[],"mappings":"AAgBO,mDAHI,IAAI,CAAC,OAAO,cAAc,EAAE,SAAS,CAAC,SACtC,MAAM,EAAE,EAAE,kBA+BpB;AAMM,+CAHI,IAAI,CAAC,OAAO,cAAc,EAAE,SAAS,CAAC,SACtC,MAAM,EAAE,kBAMhB;AAQI,8CALI,MAAM,uBACN,IAAI,CAAC,OAAO,cAAc,EAAE,SAAS,CAAC,QACtC,MAAM,YACN,IAAI,CAAC,OAAO,CAAC,EAAE,iBAuBzB;AA6BM,wCAPI,OAAO,CAAC;IACd,OAAO,EAAE,IAAI,CAAC,OAAO,iCAAiC,EAAE,UAAU,CAAC,CAAC;CACrE,CAAC,mCAEF;IAAkE,UAAU,EAApE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IACrC,eAAe;CAAC;oCAkCD,UAAK,EAAE,UAAK,EAAE,SAAI;;GAkBzD;AAEM,iFACsC;AAEtC,6DAC+B;AAEtC,uCAAuC;AACvC,kCADW,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAKjC;AAUK,iDAJI,OAAO,CAAC,QAAQ,CAAC,WACjB,QAAQ,CAAC,QAAQ,CAAC,GAChB,OAAO,CAAC,QAAQ,CAAC,CAW7B;8BA1LoC,eAAe"}
@@ -1,8 +1,14 @@
1
+ import { Fail } from '@endo/errors';
2
+ import { E } from '@endo/far';
1
3
  import { WalletName } from '@agoric/internal';
2
4
  import { getCopyMapEntries, makeCopyMap } from '@agoric/store';
3
- import { E } from '@endo/far';
5
+ import { assertPathSegment } from '@agoric/internal/src/lib-chainStorage.js';
6
+ import { makeScalarBigMapStore } from '@agoric/vat-data';
4
7
 
5
- const { Fail } = assert;
8
+ /**
9
+ * @import {CopyMap} from '@endo/patterns';
10
+ * @import {MapStore, SetStore} from '@agoric/store';
11
+ */
6
12
 
7
13
  /**
8
14
  * @param {ERef<import('@agoric/vats').NameAdmin>} nameAdmin
@@ -10,7 +16,6 @@ const { Fail } = assert;
10
16
  */
11
17
  export const reserveThenGetNamePaths = async (nameAdmin, paths) => {
12
18
  /**
13
- *
14
19
  * @param {ERef<import('@agoric/vats').NameAdmin>} nextAdmin
15
20
  * @param {string[]} path
16
21
  */
@@ -54,7 +59,7 @@ export const reserveThenGetNames = async (nameAdmin, names) =>
54
59
  * @param {string} debugName
55
60
  * @param {ERef<import('@agoric/vats').NameAdmin>} namesByAddressAdmin
56
61
  * @param {string} addr
57
- * @param {Array<ERef<Payment>>} payments
62
+ * @param {ERef<Payment>[]} payments
58
63
  */
59
64
  export const reserveThenDeposit = async (
60
65
  debugName,
@@ -79,7 +84,15 @@ export const reserveThenDeposit = async (
79
84
  );
80
85
  };
81
86
 
82
- /** @type {<T>(store: ERef<Map<string, T> | import('@agoric/internal/src/scratch.js').ScratchPad>, key: string, make: () => T) => Promise<T>} */
87
+ /**
88
+ * @type {<T>(
89
+ * store: ERef<
90
+ * Map<string, T> | import('@agoric/internal/src/scratch.js').ScratchPad
91
+ * >,
92
+ * key: string,
93
+ * make: () => T,
94
+ * ) => Promise<T>}
95
+ */
83
96
  const provideWhen = async (store, key, make) => {
84
97
  const found = await E(store).get(key);
85
98
  if (found) {
@@ -91,21 +104,33 @@ const provideWhen = async (store, key, make) => {
91
104
  };
92
105
 
93
106
  /**
94
- * @param {{ scratch: ERef<import('@agoric/internal/src/scratch.js').ScratchPad> }} homeP
107
+ * @param {Promise<{
108
+ * scratch: ERef<import('@agoric/internal/src/scratch.js').ScratchPad>;
109
+ * }>} homeP
95
110
  * @param {object} opts
96
- * @param {(specifier: string) => Promise<{default: Bundle}>} opts.loadBundle
111
+ * @param {(specifier: string) => Promise<{ default: Bundle }>} opts.loadBundle
97
112
  * @param {string} [opts.installCacheKey]
98
113
  */
99
114
  export const makeInstallCache = async (
100
115
  homeP,
101
116
  { installCacheKey = 'installCache', loadBundle },
102
117
  ) => {
103
- /** @type {CopyMap<string, {installation: Installation, boardId: string, path?: string}>} */
118
+ /**
119
+ * @type {CopyMap<
120
+ * string,
121
+ * { installation: Installation; boardId: string; path?: string }
122
+ * >}
123
+ */
104
124
  const initial = await provideWhen(E.get(homeP).scratch, installCacheKey, () =>
105
125
  makeCopyMap([]),
106
126
  );
107
127
  // ISSUE: getCopyMapEntries of CopyMap<K, V> loses K, V.
108
- /** @type {Map<string, {installation: Installation, boardId: string, path?: string}>} */
128
+ /**
129
+ * @type {Map<
130
+ * string,
131
+ * { installation: Installation; boardId: string; path?: string }
132
+ * >}
133
+ */
109
134
  const working = new Map(getCopyMapEntries(initial));
110
135
 
111
136
  const saveCache = async () => {
@@ -137,3 +162,35 @@ export const makeInstallCache = async (
137
162
 
138
163
  return { wrapInstall, saveCache };
139
164
  };
165
+
166
+ export const oracleBrandFeedName = (inBrandName, outBrandName) =>
167
+ `${inBrandName}-${outBrandName} price feed`;
168
+
169
+ export const scaledPriceFeedName = issuerName =>
170
+ `scaledPriceAuthority-${issuerName}`;
171
+
172
+ /** @type {(name: string) => string} */
173
+ export const sanitizePathSegment = name => {
174
+ const candidate = name.replace(/ /g, '_');
175
+ assertPathSegment(candidate);
176
+ return candidate;
177
+ };
178
+
179
+ /**
180
+ * Idempotently provide an empty MapStore for the `retiredContractInstances`
181
+ * value in promise space
182
+ *
183
+ * @param {Promise<MapStore>} consume
184
+ * @param {Producer<MapStore>} produce
185
+ * @returns {Promise<MapStore>}
186
+ */
187
+ export const provideRetiredInstances = async (consume, produce) => {
188
+ // Promise space has no way to look for an existing value other than awaiting a promise,
189
+ // but it does allow extra production so it's safe to do this redundantly.
190
+ produce.resolve(
191
+ makeScalarBigMapStore('retiredContractInstances', {
192
+ durable: true,
193
+ }),
194
+ );
195
+ return consume;
196
+ };
@@ -0,0 +1,63 @@
1
+ import { E } from '@endo/far';
2
+ import { makeTracer } from '@agoric/internal/src/debug.js';
3
+ import { reserveThenDeposit } from './utils.js';
4
+
5
+ /**
6
+ * @param {BootstrapPowers & {
7
+ * consume: {
8
+ * reserveKit: Promise<
9
+ * ReturnType<import('../reserve/assetReserve.js')['start']>
10
+ * >;
11
+ * };
12
+ * }} powers
13
+ * @param {{ options: { address: string; count?: number } }} namedArgs
14
+ */
15
+ export const inviteReserveWithdrawer = async (
16
+ { consume: { namesByAddressAdmin, reserveKit } },
17
+ { options: { address, count = 1 } },
18
+ ) => {
19
+ const trace = makeTracer('InviteReserveWithdrawer');
20
+
21
+ const maybeGovernedCreatorFacetP = E.get(reserveKit).creatorFacet;
22
+ const creatorFacetP = E(maybeGovernedCreatorFacetP)
23
+ .getLimitedCreatorFacet()
24
+ .catch(err => {
25
+ trace('Failed to get limited creator facet:', err);
26
+ return maybeGovernedCreatorFacetP;
27
+ });
28
+
29
+ const makeInvitation = () =>
30
+ // @ts-expect-error tolerate translation from governed to limited creatorFacet
31
+ E(creatorFacetP).makeSingleWithdrawalInvitation();
32
+
33
+ const invitations = await Promise.all(
34
+ Array.from({ length: count }, makeInvitation),
35
+ );
36
+
37
+ // Deposit the invitations, but don't block in case the address does not yet
38
+ // have a smart wallet.
39
+ void reserveThenDeposit(
40
+ `reserve withdrawer ${address}`,
41
+ namesByAddressAdmin,
42
+ address,
43
+ invitations,
44
+ );
45
+ };
46
+ harden(inviteReserveWithdrawer);
47
+
48
+ export const getManifestForInviteWithdrawer = async (
49
+ { restoreRef: _ },
50
+ { address, count },
51
+ ) => {
52
+ return {
53
+ manifest: {
54
+ [inviteReserveWithdrawer.name]: /** @type {const} */ ({
55
+ consume: {
56
+ namesByAddressAdmin: true,
57
+ reserveKit: true,
58
+ },
59
+ }),
60
+ },
61
+ options: { address, count },
62
+ };
63
+ };