@agoric/inter-protocol 0.13.3 → 0.13.4-dev-d32a66a.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 (140) hide show
  1. package/README.md +26 -20
  2. package/bundles/bundle-auctioneer-js-meta.json +722 -0
  3. package/bundles/bundle-auctioneer.js +1 -0
  4. package/bundles/bundle-econCommitteeCharter-js-meta.json +514 -0
  5. package/bundles/bundle-econCommitteeCharter.js +1 -0
  6. package/bundles/bundle-feeDistributor-js-meta.json +458 -0
  7. package/bundles/bundle-feeDistributor.js +1 -1
  8. package/bundles/bundle-fluxAggregatorKit-js-meta.json +674 -0
  9. package/bundles/bundle-fluxAggregatorKit.js +1 -0
  10. package/bundles/bundle-psm-js-meta.json +666 -0
  11. package/bundles/bundle-psm.js +1 -1
  12. package/bundles/bundle-reserve-js-meta.json +662 -0
  13. package/bundles/bundle-reserve.js +1 -1
  14. package/bundles/bundle-scaledPriceAuthority-js-meta.json +542 -0
  15. package/bundles/bundle-scaledPriceAuthority.js +1 -1
  16. package/bundles/bundle-vaultFactory-js-meta.json +786 -0
  17. package/bundles/bundle-vaultFactory.js +1 -1
  18. package/exported.js +0 -2
  19. package/package.json +34 -31
  20. package/scripts/add-collateral-core.js +14 -4
  21. package/scripts/build-bundles.js +9 -2
  22. package/scripts/deploy-contracts.js +1 -4
  23. package/scripts/init-core.js +20 -38
  24. package/scripts/invite-committee-core.js +1 -1
  25. package/scripts/manual-price-feed.js +2 -2
  26. package/scripts/price-feed-core.js +7 -6
  27. package/scripts/start-local-chain.sh +84 -0
  28. package/src/auction/auctionBook.js +755 -0
  29. package/src/auction/auctioneer.js +720 -0
  30. package/src/auction/offerBook.js +221 -0
  31. package/src/auction/params.js +174 -0
  32. package/src/auction/scheduleMath.js +167 -0
  33. package/src/auction/scheduler.js +370 -0
  34. package/src/auction/sortedOffers.js +136 -0
  35. package/src/auction/util.js +55 -0
  36. package/src/clientSupport.js +324 -0
  37. package/src/collectFees.js +8 -14
  38. package/src/contractSupport.js +24 -68
  39. package/src/econCommitteeCharter.js +161 -77
  40. package/src/feeDistributor.js +60 -20
  41. package/src/index.js +2 -0
  42. package/src/interest-math.js +1 -4
  43. package/src/interest.js +20 -13
  44. package/src/price/README.md +57 -0
  45. package/src/price/fluxAggregatorContract.js +190 -0
  46. package/src/price/fluxAggregatorKit.js +375 -0
  47. package/src/price/priceOracleKit.js +127 -0
  48. package/src/price/roundsManager.js +726 -0
  49. package/src/proposals/addAssetToVault.js +89 -94
  50. package/src/proposals/committee-proposal.js +141 -40
  51. package/src/proposals/core-proposal.js +100 -167
  52. package/src/proposals/econ-behaviors.js +320 -564
  53. package/src/proposals/price-feed-proposal.js +175 -78
  54. package/src/proposals/startEconCommittee.js +25 -12
  55. package/src/proposals/startPSM.js +231 -211
  56. package/src/proposals/utils.js +31 -17
  57. package/src/psm/README.md +71 -0
  58. package/src/psm/psm.js +272 -160
  59. package/src/psm/types.js +2 -0
  60. package/src/reserve/assetReserve.js +56 -413
  61. package/src/reserve/assetReserveKit.js +303 -0
  62. package/src/reserve/doc.md +1 -3
  63. package/src/reserve/params.js +2 -5
  64. package/src/typeGuards.js +13 -0
  65. package/src/vaultFactory/Liquidation.md +100 -0
  66. package/src/vaultFactory/burn.js +2 -1
  67. package/src/vaultFactory/liquidation.js +270 -108
  68. package/src/vaultFactory/math.js +95 -0
  69. package/src/vaultFactory/orderedVaultStore.js +0 -1
  70. package/src/vaultFactory/params.js +133 -112
  71. package/src/vaultFactory/prioritizedVaults.js +36 -79
  72. package/src/vaultFactory/storeUtils.js +67 -9
  73. package/src/vaultFactory/type-imports.js +2 -0
  74. package/src/vaultFactory/types.js +22 -26
  75. package/src/vaultFactory/vault.js +772 -709
  76. package/src/vaultFactory/vaultDirector.js +480 -483
  77. package/src/vaultFactory/vaultFactory.js +99 -60
  78. package/src/vaultFactory/vaultHolder.js +121 -95
  79. package/src/vaultFactory/vaultKit.js +39 -31
  80. package/src/vaultFactory/vaultManager.js +1249 -868
  81. package/bundles/bundle-amm-meta.js +0 -618
  82. package/bundles/bundle-amm.js +0 -1
  83. package/bundles/bundle-feeDistributor-meta.js +0 -346
  84. package/bundles/bundle-interchainPool-meta.js +0 -534
  85. package/bundles/bundle-interchainPool.js +0 -1
  86. package/bundles/bundle-liquidateIncrementally-meta.js +0 -442
  87. package/bundles/bundle-liquidateIncrementally.js +0 -1
  88. package/bundles/bundle-liquidateMinimum-meta.js +0 -442
  89. package/bundles/bundle-liquidateMinimum.js +0 -1
  90. package/bundles/bundle-psm-meta.js +0 -538
  91. package/bundles/bundle-psmCharter-meta.js +0 -418
  92. package/bundles/bundle-psmCharter.js +0 -1
  93. package/bundles/bundle-reserve-meta.js +0 -542
  94. package/bundles/bundle-scaledPriceAuthority-meta.js +0 -442
  95. package/bundles/bundle-stakeFactory-meta.js +0 -574
  96. package/bundles/bundle-stakeFactory.js +0 -1
  97. package/bundles/bundle-vaultFactory-meta.js +0 -598
  98. package/scripts/add-initial-liquidity.js +0 -180
  99. package/src/collect.js +0 -13
  100. package/src/interchainPool.js +0 -135
  101. package/src/makeTracer.js +0 -36
  102. package/src/my-lien.js +0 -85
  103. package/src/proposals/demoIssuers.js +0 -685
  104. package/src/proposals/sim-behaviors.js +0 -40
  105. package/src/psm/psmCharter.js +0 -139
  106. package/src/stakeFactory/README.md +0 -62
  107. package/src/stakeFactory/attestation.js +0 -267
  108. package/src/stakeFactory/attestationTool.js +0 -66
  109. package/src/stakeFactory/constants.js +0 -16
  110. package/src/stakeFactory/params.js +0 -31
  111. package/src/stakeFactory/stakeFactory.js +0 -236
  112. package/src/stakeFactory/stakeFactoryKit.js +0 -455
  113. package/src/stakeFactory/stakeFactoryManager.js +0 -296
  114. package/src/stakeFactory/types.js +0 -42
  115. package/src/vaultFactory/liquidateIncrementally.js +0 -350
  116. package/src/vaultFactory/liquidateMinimum.js +0 -100
  117. package/src/vpool-xyk-amm/AttackersGuide.md +0 -89
  118. package/src/vpool-xyk-amm/addLiquidity.js +0 -222
  119. package/src/vpool-xyk-amm/addPool.js +0 -197
  120. package/src/vpool-xyk-amm/constantProduct/AMM-Trade.jpeg +0 -0
  121. package/src/vpool-xyk-amm/constantProduct/README.md +0 -204
  122. package/src/vpool-xyk-amm/constantProduct/calcFees.js +0 -99
  123. package/src/vpool-xyk-amm/constantProduct/calcSwapPrices.js +0 -85
  124. package/src/vpool-xyk-amm/constantProduct/core.js +0 -153
  125. package/src/vpool-xyk-amm/constantProduct/defaults.js +0 -5
  126. package/src/vpool-xyk-amm/constantProduct/getXY.js +0 -52
  127. package/src/vpool-xyk-amm/constantProduct/internal-types.js +0 -116
  128. package/src/vpool-xyk-amm/constantProduct/invariants.js +0 -43
  129. package/src/vpool-xyk-amm/constantProduct/swap.js +0 -272
  130. package/src/vpool-xyk-amm/constantProduct/types.js +0 -32
  131. package/src/vpool-xyk-amm/doublePool.js +0 -194
  132. package/src/vpool-xyk-amm/estimate.js +0 -155
  133. package/src/vpool-xyk-amm/multipoolMarketMaker.js +0 -520
  134. package/src/vpool-xyk-amm/params.js +0 -61
  135. package/src/vpool-xyk-amm/pool.js +0 -396
  136. package/src/vpool-xyk-amm/priceAuthority.js +0 -94
  137. package/src/vpool-xyk-amm/removeLiquidity.js +0 -31
  138. package/src/vpool-xyk-amm/singlePool.js +0 -73
  139. package/src/vpool-xyk-amm/swap.js +0 -69
  140. package/src/vpool-xyk-amm/types.js +0 -154
@@ -1,45 +1,105 @@
1
- // @ts-check
1
+ // @jessie-check
2
2
 
3
+ import { makeMap } from 'jessie.js';
3
4
  import { AmountMath, AssetKind } from '@agoric/ertp';
4
5
  import { CONTRACT_ELECTORATE, ParamTypes } from '@agoric/governance';
5
- import { makeStorageNodeChild } from '@agoric/vats/src/lib-chainStorage.js';
6
+ import { makeStorageNodeChild } from '@agoric/internal/src/lib-chainStorage.js';
6
7
  import { makeRatio } from '@agoric/zoe/src/contractSupport/index.js';
7
8
  import { E } from '@endo/far';
8
9
  import { Stable } from '@agoric/vats/src/tokens.js';
10
+ import {
11
+ makeHistoryReviver,
12
+ makeBoardRemote,
13
+ slotToBoardRemote,
14
+ } from '@agoric/vats/tools/board-utils.js';
9
15
  import { deeplyFulfilledObject } from '@agoric/internal';
10
- import { makeScalarMapStore } from '@agoric/vat-data';
16
+ import { makeScalarBigMapStore } from '@agoric/vat-data';
11
17
 
12
- import { reserveThenDeposit, reserveThenGetNamePaths } from './utils.js';
18
+ import { reserveThenGetNamePaths } from './utils.js';
19
+
20
+ import {
21
+ inviteCommitteeMembers,
22
+ startEconCharter,
23
+ inviteToEconCharter,
24
+ } from './committee-proposal.js';
25
+
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 */
13
29
 
14
30
  const BASIS_POINTS = 10000n;
15
31
  const { details: X } = assert;
16
32
 
17
- const { values } = Object;
33
+ export { inviteCommitteeMembers, startEconCharter, inviteToEconCharter };
34
+
35
+ const stablePsmKey = `published.psm.${Stable.symbol}`;
18
36
 
19
37
  /**
20
- * @param {EconomyBootstrapPowers & WellKnownSpaces} powers
38
+ * @param {Array<[key: string, value: string]>} chainStorageEntries
39
+ * @param {string} keyword
40
+ * @param {{ minted: Brand<'nat'>, anchor: Brand<'nat'> }} brands
41
+ * @returns {{ metrics?: MetricsNotification, governance?: GovernanceSubscriptionState }}
42
+ */
43
+ const findOldPSMState = (chainStorageEntries, keyword, brands) => {
44
+ // In this reviver, object references are revived as boardIDs
45
+ // from the pre-bulldozer board.
46
+ const toSlotReviver = makeHistoryReviver(
47
+ chainStorageEntries,
48
+ slotToBoardRemote,
49
+ );
50
+ if (!toSlotReviver.has(`${stablePsmKey}.${keyword}.metrics`)) {
51
+ return {};
52
+ }
53
+ const metricsWithOldBoardIDs = toSlotReviver.getItem(
54
+ `${stablePsmKey}.${keyword}.metrics`,
55
+ );
56
+ const oldIDtoNewBrand = makeMap([
57
+ [metricsWithOldBoardIDs.feePoolBalance.brand.getBoardId(), brands.minted],
58
+ [
59
+ metricsWithOldBoardIDs.anchorPoolBalance.brand.getBoardId(),
60
+ brands.anchor,
61
+ ],
62
+ ]);
63
+ // revive brands; other object references map to dummy remotables
64
+ const brandReviver = makeHistoryReviver(
65
+ chainStorageEntries,
66
+ (slotID, iface) => {
67
+ const newBrand = oldIDtoNewBrand.get(slotID);
68
+ return newBrand || makeBoardRemote({ boardId: slotID, iface });
69
+ },
70
+ );
71
+ return {
72
+ metrics: brandReviver.getItem(`${stablePsmKey}.${keyword}.metrics`),
73
+ governance: brandReviver.getItem(`${stablePsmKey}.${keyword}.governance`),
74
+ };
75
+ };
76
+
77
+ /**
78
+ * @param {EconomyBootstrapPowers & WellKnownSpaces & ChainStorageVatParams} powers
21
79
  * @param {object} [config]
22
80
  * @param {bigint} [config.WantMintedFeeBP]
23
81
  * @param {bigint} [config.GiveMintedFeeBP]
24
82
  * @param {bigint} [config.MINT_LIMIT]
25
83
  * @param {{ anchorOptions?: AnchorOptions } } [config.options]
26
- *
27
- * @typedef {import('./econ-behaviors.js').EconomyBootstrapPowers} EconomyBootstrapPowers
28
84
  */
29
85
  export const startPSM = async (
30
86
  {
87
+ vatParameters: { chainStorageEntries = [] },
31
88
  consume: {
32
89
  agoricNamesAdmin,
33
90
  board,
91
+ diagnostics,
34
92
  zoe,
35
93
  feeMintAccess: feeMintAccessP,
36
94
  economicCommitteeCreatorFacet,
37
- psmCharterCreatorFacet,
95
+ econCharterKit,
38
96
  provisionPoolStartResult,
39
97
  chainStorage,
40
98
  chainTimerService,
41
- psmFacets,
99
+ psmKit,
100
+ anchorBalancePayments: anchorBalancePaymentsP,
42
101
  },
102
+ produce: { psmKit: producepsmKit },
43
103
  installation: {
44
104
  consume: { contractGovernor, psm: psmInstall },
45
105
  },
@@ -88,6 +148,12 @@ export const startPSM = async (
88
148
  const mintLimit = AmountMath.make(minted, MINT_LIMIT);
89
149
  const anchorDecimalPlaces = anchorInfo.decimalPlaces || 1n;
90
150
  const mintedDecimalPlaces = mintedInfo.decimalPlaces || 1n;
151
+
152
+ const oldState = findOldPSMState(chainStorageEntries, keyword, {
153
+ minted,
154
+ anchor: anchorBrand,
155
+ });
156
+
91
157
  const terms = await deeplyFulfilledObject(
92
158
  harden({
93
159
  anchorBrand,
@@ -98,10 +164,6 @@ export const startPSM = async (
98
164
  minted,
99
165
  ),
100
166
  governedParams: {
101
- [CONTRACT_ELECTORATE]: {
102
- type: ParamTypes.INVITATION,
103
- value: electorateInvitationAmount,
104
- },
105
167
  WantMintedFee: {
106
168
  type: ParamTypes.RATIO,
107
169
  value: makeRatio(WantMintedFeeBP, minted, BASIS_POINTS),
@@ -111,21 +173,26 @@ export const startPSM = async (
111
173
  value: makeRatio(GiveMintedFeeBP, minted, BASIS_POINTS),
112
174
  },
113
175
  MintLimit: { type: ParamTypes.AMOUNT, value: mintLimit },
114
- },
115
- [CONTRACT_ELECTORATE]: {
116
- type: ParamTypes.INVITATION,
117
- value: electorateInvitationAmount,
176
+ // Override numeric config values from restored state.
177
+ ...oldState.governance?.current,
178
+ // Don't override the invitation amount;
179
+ // the electorate is re-constituted rather than restored.
180
+ [CONTRACT_ELECTORATE]: {
181
+ type: ParamTypes.INVITATION,
182
+ value: electorateInvitationAmount,
183
+ },
118
184
  },
119
185
  }),
120
186
  );
121
187
 
122
188
  const psmStorageNode = await makeStorageNodeChild(chainStorage, 'psm');
123
- const storageNode = E(
189
+ const storageNode = await E(
124
190
  E(psmStorageNode).makeChildNode(Stable.symbol),
125
191
  ).makeChildNode(keyword);
126
192
 
127
193
  const marshaller = await E(board).getPublishingMarshaller();
128
194
 
195
+ const instanceKey = `psm-${Stable.symbol}-${keyword}`;
129
196
  const governorTerms = await deeplyFulfilledObject(
130
197
  harden({
131
198
  timer: chainTimerService,
@@ -133,22 +200,26 @@ export const startPSM = async (
133
200
  governed: {
134
201
  terms,
135
202
  issuerKeywordRecord: { [keyword]: anchorIssuer },
203
+ label: instanceKey,
136
204
  },
137
205
  }),
138
206
  );
207
+ const psmPrivateArgs = {
208
+ feeMintAccess,
209
+ initialPoserInvitation,
210
+ marshaller,
211
+ storageNode,
212
+ };
213
+ /** @type {GovernorStartedInstallationKit<typeof psmInstall>} */
139
214
  const governorFacets = await E(zoe).startInstance(
140
215
  contractGovernor,
141
216
  {},
142
217
  governorTerms,
143
218
  harden({
144
219
  economicCommitteeCreatorFacet,
145
- governed: {
146
- feeMintAccess,
147
- initialPoserInvitation,
148
- marshaller,
149
- storageNode,
150
- },
220
+ governed: psmPrivateArgs,
151
221
  }),
222
+ `${instanceKey}.governor`,
152
223
  );
153
224
 
154
225
  const [psm, psmCreatorFacet, psmAdminFacet] = await Promise.all([
@@ -156,36 +227,56 @@ export const startPSM = async (
156
227
  E(governorFacets.creatorFacet).getCreatorFacet(),
157
228
  E(governorFacets.creatorFacet).getAdminFacet(),
158
229
  ]);
230
+ await E(diagnostics).savePrivateArgs(psm, psmPrivateArgs);
231
+
232
+ /** @param {MetricsNotification} metrics */
233
+ const restoreMetrics = async metrics => {
234
+ const anchorBalancePayments = await anchorBalancePaymentsP;
235
+ const anchorPmt = anchorBalancePayments.get(anchorBrand);
236
+
237
+ const { anchorPoolBalance: _a, ...nonPaymentMetrics } = metrics;
238
+
239
+ const seat = E(zoe).offer(
240
+ E(psmCreatorFacet).makeRestoreMetricsInvitation(),
241
+ harden({ give: { Anchor: metrics.anchorPoolBalance } }),
242
+ harden({ Anchor: anchorPmt }),
243
+ harden(nonPaymentMetrics),
244
+ );
245
+ await E(seat).getPayouts();
246
+ };
247
+ await (oldState.metrics && restoreMetrics(oldState.metrics));
159
248
 
160
- /** @typedef {import('./econ-behaviors.js').PSMFacets} PSMFacets */
161
- /** @type {PSMFacets} */
162
- const newPsmFacets = {
249
+ /** @type {import('./econ-behaviors.js').PSMKit} */
250
+ const newpsmKit = harden({
251
+ label: instanceKey,
163
252
  psm,
164
253
  psmGovernor: governorFacets.instance,
165
254
  psmCreatorFacet,
166
255
  psmAdminFacet,
167
256
  psmGovernorCreatorFacet: governorFacets.creatorFacet,
168
- };
257
+ });
169
258
 
170
- /** @type {MapStore<Brand,PSMFacets>} */
171
- const psmFacetsMap = await psmFacets;
259
+ // Provide pattern with a promise.
260
+ producepsmKit.resolve(makeScalarBigMapStore('PSM Kits', { durable: true }));
172
261
 
173
- psmFacetsMap.init(anchorBrand, newPsmFacets);
174
- const instanceKey = `psm-${Stable.symbol}-${keyword}`;
262
+ /** @type {MapStore<Brand, import('./econ-behaviors.js').PSMKit>} */
263
+ const psmKitMap = await psmKit;
264
+
265
+ // TODO init into governedContractKits too to simplify testing
266
+ psmKitMap.init(anchorBrand, newpsmKit);
175
267
  const instanceAdmin = E(agoricNamesAdmin).lookupAdmin('instance');
176
268
 
177
269
  await Promise.all([
178
- E(instanceAdmin).update(instanceKey, newPsmFacets.psm),
179
- E(psmCharterCreatorFacet).addInstance(
270
+ E(instanceAdmin).update(instanceKey, newpsmKit.psm),
271
+ E(E.get(econCharterKit).creatorFacet).addInstance(
180
272
  psm,
181
273
  governorFacets.creatorFacet,
182
- anchorBrand,
183
- minted,
274
+ instanceKey,
184
275
  ),
185
276
  // @ts-expect-error TODO type for provisionPoolStartResult
186
277
  E(E.get(provisionPoolStartResult).creatorFacet).initPSM(
187
278
  anchorBrand,
188
- newPsmFacets.psm,
279
+ newpsmKit.psm,
189
280
  ),
190
281
  ]);
191
282
  };
@@ -203,16 +294,30 @@ harden(startPSM);
203
294
  * Make anchor issuer out of a Cosmos asset; presumably
204
295
  * USDC over IBC. Add it to BankManager.
205
296
  *
206
- * @param {EconomyBootstrapPowers & WellKnownSpaces} powers
297
+ * Also, if vatParameters shows an anchorPoolBalance for this asset,
298
+ * mint a payment for that balance.
299
+ *
300
+ * TODO: address redundancy with publishInterchainAssetFromBank
301
+ *
302
+ * @param {EconomyBootstrapPowers & WellKnownSpaces & ChainStorageVatParams} powers
207
303
  * @param {{options?: { anchorOptions?: AnchorOptions } }} [config]
208
304
  */
209
305
  export const makeAnchorAsset = async (
210
306
  {
211
- consume: { agoricNamesAdmin, bankManager, zoe },
307
+ vatParameters: { chainStorageEntries = [] },
308
+ consume: {
309
+ agoricNamesAdmin,
310
+ bankManager,
311
+ startUpgradable,
312
+ anchorBalancePayments,
313
+ },
212
314
  installation: {
213
315
  consume: { mintHolder },
214
316
  },
215
- produce: { testFirstAnchorKit },
317
+ produce: {
318
+ testFirstAnchorKit,
319
+ anchorBalancePayments: produceAnchorBalancePayments,
320
+ },
216
321
  },
217
322
  { options: { anchorOptions = {} } = {} },
218
323
  ) => {
@@ -239,17 +344,44 @@ export const makeAnchorAsset = async (
239
344
  },
240
345
  }),
241
346
  );
242
- const { creatorFacet: mint, publicFacet: issuerP } = E.get(
243
- E(zoe).startInstance(mintHolder, {}, terms),
244
- );
245
- const issuer = await issuerP; // identity of issuers is important
347
+
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
+ });
246
355
 
247
356
  const brand = await E(issuer).getBrand();
248
- const kit = { mint, issuer, brand };
357
+ const kit = harden({ mint, issuer, brand });
249
358
 
250
359
  testFirstAnchorKit.resolve(kit);
251
360
 
252
- return Promise.all([
361
+ const toSlotReviver = makeHistoryReviver(
362
+ chainStorageEntries,
363
+ slotToBoardRemote,
364
+ );
365
+ const metricsKey = `${stablePsmKey}.${keyword}.metrics`;
366
+ if (toSlotReviver.has(metricsKey)) {
367
+ const metrics = toSlotReviver.getItem(metricsKey);
368
+ produceAnchorBalancePayments.resolve(
369
+ makeScalarBigMapStore('Anchor balance payments', { durable: true }),
370
+ );
371
+ // XXX this rule should only apply to the 1st await
372
+ // eslint-disable-next-line @jessie.js/no-nested-await
373
+ const anchorPaymentMap = await anchorBalancePayments;
374
+
375
+ // TODO: validate that `metrics.anchorPoolBalance.value` is
376
+ // pass-by-copy PureData (e.g., contains no remotables).
377
+ // eslint-disable-next-line @jessie.js/no-nested-await
378
+ const pmt = await E(mint).mintPayment(
379
+ AmountMath.make(brand, metrics.anchorPoolBalance.value),
380
+ );
381
+ anchorPaymentMap.init(brand, pmt);
382
+ }
383
+
384
+ await Promise.all([
253
385
  E(E(agoricNamesAdmin).lookupAdmin('issuer')).update(keyword, kit.issuer),
254
386
  E(E(agoricNamesAdmin).lookupAdmin('brand')).update(keyword, kit.brand),
255
387
  E(bankManager).addAsset(
@@ -264,185 +396,60 @@ harden(makeAnchorAsset);
264
396
 
265
397
  /** @typedef {import('./econ-behaviors.js').EconomyBootstrapSpace} EconomyBootstrapSpace */
266
398
 
267
- /** @param {BootstrapSpace & EconomyBootstrapSpace & { devices: { vatAdmin: any }, vatPowers: { D: DProxy }, }} powers */
268
- export const installGovAndPSMContracts = async ({
269
- vatPowers: { D },
270
- devices: { vatAdmin },
271
- consume: { zoe },
272
- produce: { psmFacets },
273
- installation: {
274
- produce: {
275
- contractGovernor,
276
- committee,
277
- binaryVoteCounter,
278
- psm,
279
- psmCharter,
280
- },
281
- },
282
- }) => {
283
- // In order to support multiple instances of the PSM, we store all the facets
284
- // indexed by the brand. Since each name in the BootstrapSpace can only be
285
- // produced once, we produce an empty store here, and each time a PSM is
286
- // started up, the details are added to the store.
287
- psmFacets.resolve(makeScalarMapStore());
288
-
289
- return Promise.all(
290
- Object.entries({
291
- contractGovernor,
292
- committee,
293
- binaryVoteCounter,
294
- psm,
295
- psmCharter,
296
- }).map(async ([name, producer]) => {
297
- const bundleCap = D(vatAdmin).getNamedBundleCap(name);
298
- const bundle = D(bundleCap).getBundle();
299
- const installation = E(zoe).install(bundle);
300
-
301
- producer.resolve(installation);
302
- }),
303
- );
304
- };
305
-
306
- /** @param {EconomyBootstrapPowers} powers */
307
- export const startPSMCharter = async ({
308
- consume: { zoe },
309
- produce: { psmCharterCreatorFacet, psmCharterAdminFacet },
310
- installation: {
311
- consume: { binaryVoteCounter, psmCharter: installP },
312
- },
313
- instance: {
314
- produce: { psmCharter: instanceP },
315
- },
316
- }) => {
317
- const [charterR, counterR] = await Promise.all([installP, binaryVoteCounter]);
318
-
319
- const terms = { binaryVoteCounterInstallation: counterR };
320
- const facets = await E(zoe).startInstance(charterR, {}, terms);
321
-
322
- instanceP.resolve(facets.instance);
323
- psmCharterCreatorFacet.resolve(facets.creatorFacet);
324
- psmCharterAdminFacet.resolve(facets.adminFacet);
325
- };
326
-
327
- /**
328
- * PSM and gov contracts are available as
329
- * named swingset bundles only in
330
- * decentral-psm-config.json
331
- */
332
- export const PSM_GOV_MANIFEST = {
333
- [installGovAndPSMContracts.name]: {
334
- vatPowers: { D: true },
335
- devices: { vatAdmin: true },
336
- consume: { zoe: 'zoe' },
337
- produce: { psmFacets: 'true' },
338
- installation: {
339
- produce: {
340
- contractGovernor: 'zoe',
341
- committee: 'zoe',
342
- binaryVoteCounter: 'zoe',
343
- psm: 'zoe',
344
- psmCharter: 'zoe',
399
+ export const INVITE_PSM_COMMITTEE_MANIFEST = harden(
400
+ /** @type {BootstrapManifest} */ ({
401
+ [inviteCommitteeMembers.name]: {
402
+ consume: {
403
+ namesByAddressAdmin: true,
404
+ economicCommitteeCreatorFacet: true,
405
+ econCharterKit: true,
406
+ highPrioritySendersManager: true,
345
407
  },
346
408
  },
347
- },
348
- [startPSMCharter.name]: {
349
- consume: { zoe: 'zoe' },
350
- produce: {
351
- psmCharterCreatorFacet: 'psmCharter',
352
- psmCharterAdminFacet: 'psmCharter',
353
- },
354
- installation: {
355
- consume: { binaryVoteCounter: 'zoe', psmCharter: 'zoe' },
356
- },
357
- instance: {
358
- produce: { psmCharter: 'psmCharter' },
359
- },
360
- },
361
- };
362
-
363
- /** @type { <X, Y>(xs: X[], ys: Y[]) => [X, Y][]} */
364
- const zip = (xs, ys) => xs.map((x, i) => [x, ys[i]]);
365
-
366
- /**
367
- * @param {import('./econ-behaviors').EconomyBootstrapPowers} powers
368
- * @param {{ options: { voterAddresses: Record<string, string> }}} param1
369
- */
370
- export const invitePSMCommitteeMembers = async (
371
- {
372
- consume: {
373
- namesByAddressAdmin,
374
- economicCommitteeCreatorFacet,
375
- psmCharterCreatorFacet,
409
+ [inviteToEconCharter.name]: {
410
+ consume: {
411
+ namesByAddressAdmin: true,
412
+ econCharterKit: true,
413
+ },
376
414
  },
377
- },
378
- { options: { voterAddresses = {} } },
379
- ) => {
380
- const invitations = await E(
381
- economicCommitteeCreatorFacet,
382
- ).getVoterInvitations();
383
- assert.equal(invitations.length, values(voterAddresses).length);
384
-
385
- /**
386
- * @param {[string, Promise<Invitation>][]} addrInvitations
387
- */
388
- const distributeInvitations = async addrInvitations => {
389
- await Promise.all(
390
- addrInvitations.map(async ([addr, invitationP]) => {
391
- const [voterInvitation, charterMemberInvitation] = await Promise.all([
392
- invitationP,
393
- E(psmCharterCreatorFacet).makeCharterMemberInvitation(),
394
- ]);
395
- console.log('sending charter, voting invitations to', addr);
396
- await reserveThenDeposit(
397
- `econ committee member ${addr}`,
398
- namesByAddressAdmin,
399
- addr,
400
- [voterInvitation, charterMemberInvitation],
401
- );
402
- console.log('sent charter, voting invitations to', addr);
403
- }),
404
- );
405
- };
406
-
407
- await distributeInvitations(zip(values(voterAddresses), invitations));
408
- };
409
- harden(invitePSMCommitteeMembers);
415
+ }),
416
+ );
410
417
 
411
- export const INVITE_PSM_COMMITTEE_MANIFEST = harden({
412
- [invitePSMCommitteeMembers.name]: {
418
+ /** @type {BootstrapManifest} */
419
+ export const PSM_MANIFEST = {
420
+ [makeAnchorAsset.name]: {
421
+ vatParameters: { chainStorageEntries: true },
413
422
  consume: {
414
- namesByAddressAdmin: true,
415
- economicCommitteeCreatorFacet: true,
416
- psmCharterCreatorFacet: true,
423
+ agoricNamesAdmin: true,
424
+ bankManager: 'bank',
425
+ startUpgradable: true,
426
+ anchorBalancePayments: true,
427
+ anchorKits: true,
417
428
  },
418
- },
419
- });
420
-
421
- export const PSM_MANIFEST = harden({
422
- [makeAnchorAsset.name]: {
423
- consume: { agoricNamesAdmin: true, bankManager: 'bank', zoe: 'zoe' },
424
429
  installation: { consume: { mintHolder: 'zoe' } },
425
- issuer: {
426
- produce: { AUSD: true },
427
- },
428
- brand: {
429
- produce: { AUSD: true },
430
+ produce: {
431
+ testFirstAnchorKit: true,
432
+ anchorBalancePayments: true,
433
+ anchorKits: true,
430
434
  },
431
- produce: { testFirstAnchorKit: true },
432
435
  },
433
436
  [startPSM.name]: {
437
+ vatParameters: { chainStorageEntries: true },
434
438
  consume: {
435
439
  agoricNamesAdmin: true,
436
440
  board: true,
437
441
  chainStorage: true,
442
+ diagnostics: true,
438
443
  zoe: 'zoe',
439
444
  feeMintAccess: 'zoe',
440
445
  economicCommitteeCreatorFacet: 'economicCommittee',
441
446
  provisionPoolStartResult: true,
442
- psmCharterCreatorFacet: 'psmCharter',
447
+ econCharterKit: 'econCommitteeCharter',
443
448
  chainTimerService: 'timer',
444
- psmFacets: true,
449
+ psmKit: true,
450
+ anchorBalancePayments: true,
445
451
  },
452
+ produce: { psmKit: 'true' },
446
453
  installation: {
447
454
  consume: { contractGovernor: 'zoe', psm: 'zoe' },
448
455
  },
@@ -450,13 +457,26 @@ export const PSM_MANIFEST = harden({
450
457
  consume: { economicCommittee: 'economicCommittee' },
451
458
  },
452
459
  brand: {
453
- consume: { AUSD: 'bank', IST: 'zoe' },
454
- },
455
- issuer: {
456
- consume: { AUSD: 'bank' },
460
+ consume: { [Stable.symbol]: 'zoe' },
457
461
  },
458
462
  },
459
- });
463
+ };
464
+ harden(PSM_MANIFEST);
465
+
466
+ export const getManifestForPsmGovernance = (
467
+ { restoreRef },
468
+ { installKeys },
469
+ ) => {
470
+ return {
471
+ manifest: {},
472
+ installations: {
473
+ econCommitteeCharter: restoreRef(installKeys.econCommitteeCharter),
474
+ contractGovernor: restoreRef(installKeys.contractGovernor),
475
+ committee: restoreRef(installKeys.committee),
476
+ binaryVoteCounter: restoreRef(installKeys.binaryVoteCounter),
477
+ },
478
+ };
479
+ };
460
480
 
461
481
  export const getManifestForPsm = (
462
482
  { restoreRef },