@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,76 +1,67 @@
1
- // @ts-check
1
+ // @jessie-check
2
2
 
3
3
  import '../../exported.js';
4
4
 
5
5
  import { AmountMath } from '@agoric/ertp';
6
6
  import '@agoric/governance/exported.js';
7
+ import { deeplyFulfilledObject, makeTracer } from '@agoric/internal';
8
+ import { makeStorageNodeChild } from '@agoric/internal/src/lib-chainStorage.js';
7
9
  import '@agoric/vats/exported.js';
8
10
  import '@agoric/vats/src/core/types.js';
9
- import { makeStorageNodeChild } from '@agoric/vats/src/lib-chainStorage.js';
10
- import { makeRatio } from '@agoric/zoe/src/contractSupport/index.js';
11
- import { E, Far } from '@endo/far';
12
- import { Stable, Stake } from '@agoric/vats/src/tokens.js';
13
- import { deeplyFulfilledObject } from '@agoric/internal';
14
- import * as Collect from '../collect.js';
15
- import { makeTracer } from '../makeTracer.js';
16
- import { makeStakeReporter } from '../my-lien.js';
11
+ import { Stable } from '@agoric/vats/src/tokens.js';
12
+ import { E } from '@endo/far';
13
+ import { makeScalarBigMapStore } from '@agoric/vat-data';
14
+ import { makeGovernedTerms as makeGovernedATerms } from '../auction/params.js';
17
15
  import { makeReserveTerms } from '../reserve/params.js';
18
- import { makeStakeFactoryTerms } from '../stakeFactory/params.js';
19
- import { liquidationDetailTerms } from '../vaultFactory/liquidation.js';
20
- import { makeGovernedTerms } from '../vaultFactory/params.js';
21
- import { makeAmmTerms } from '../vpool-xyk-amm/params.js';
16
+ import { makeGovernedTerms as makeGovernedVFTerms } from '../vaultFactory/params.js';
22
17
 
23
- const trace = makeTracer('RunEconBehaviors', false);
18
+ const trace = makeTracer('RunEconBehaviors', true);
24
19
 
25
- const { details: X } = assert;
26
-
27
- const SECONDS_PER_HOUR = 60n * 60n;
28
- const SECONDS_PER_DAY = 24n * SECONDS_PER_HOUR;
29
-
30
- const BASIS_POINTS = 10_000n;
31
- const MILLI = 1_000_000n;
20
+ export const SECONDS_PER_HOUR = 60n * 60n;
21
+ export const SECONDS_PER_DAY = 24n * SECONDS_PER_HOUR;
22
+ export const SECONDS_PER_WEEK = 7n * SECONDS_PER_DAY;
32
23
 
33
24
  /**
34
- * @typedef {GovernedCreatorFacet<import('../stakeFactory/stakeFactory.js').StakeFactoryCreator>} StakeFactoryCreator
35
- * @typedef {import('../stakeFactory/stakeFactory.js').StakeFactoryPublic} StakeFactoryPublic
36
- * @typedef {import('../reserve/assetReserve.js').GovernedAssetReserveFacetAccess} GovernedAssetReserveFacetAccess
25
+ * @typedef {import('../vaultFactory/vaultFactory.js').VaultFactoryContract['publicFacet']} VaultFactoryPublicFacet
26
+ * @typedef {import('../auction/auctioneer.js').AuctioneerPublicFacet} AuctioneerPublicFacet
27
+ * @typedef {import('../auction/auctioneer.js').AuctioneerCreatorFacet} AuctioneerCreatorFacet
37
28
  */
38
29
 
39
30
  /**
40
- * @typedef {object} PSMFacets
31
+ * @typedef {object} PSMKit
32
+ * @property {string} label
41
33
  * @property {Instance} psm
42
34
  * @property {Instance} psmGovernor
43
- * @property {Awaited<ReturnType<import('../psm/psm.js').start>>['creatorFacet']} psmCreatorFacet
44
- * @property {GovernedContractFacetAccess<{},{}>} psmGovernorCreatorFacet
35
+ * @property {Awaited<ReturnType<Awaited<ReturnType<import('../psm/psm.js')['prepare']>>['creatorFacet']['getLimitedCreatorFacet']>>} psmCreatorFacet
36
+ * @property {GovernorCreatorFacet<import('../../src/psm/psm.js')['prepare']>} psmGovernorCreatorFacet
45
37
  * @property {AdminFacet} psmAdminFacet
46
38
  */
47
39
 
40
+ /**
41
+ * @typedef {GovernanceFacetKit<import('../auction/auctioneer.js').start>} AuctioneerKit
42
+ */
43
+
48
44
  /**
49
45
  * @typedef { WellKnownSpaces & ChainBootstrapSpace & EconomyBootstrapSpace
50
46
  * } EconomyBootstrapPowers
51
47
  * @typedef {PromiseSpaceOf<{
52
- * ammInstanceWithoutReserve: Instance,
53
- * ammCreatorFacet: XYKAMMCreatorFacet,
54
- * ammGovernorCreatorFacet: GovernedContractFacetAccess<XYKAMMPublicFacet,XYKAMMCreatorFacet>,
55
- * economicCommitteeCreatorFacet: CommitteeElectorateCreatorFacet,
56
- * feeDistributorCreatorFacet: import('../feeDistributor.js').FeeDistributorCreatorFacet,
57
- * feeDistributorPublicFacet: import('../feeDistributor.js').FeeDistributorPublicFacet,
58
- * periodicFeeCollectors: import('../feeDistributor.js').PeriodicFeeCollector[],
59
- * bankMints: Mint[],
60
- * psmFacets: MapStore<Brand, PSMFacets>,
61
- * psmCharterCreatorFacet: Awaited<ReturnType<import('../psm/psmCharter.js').start>>['creatorFacet'],
62
- * psmCharterAdminFacet: AdminFacet,
63
- * reservePublicFacet: import('../reserve/assetReserve.js').AssetReservePublicFacet,
64
- * reserveCreatorFacet: import('../reserve/assetReserve.js').AssetReserveLimitedCreatorFacet,
65
- * reserveGovernorCreatorFacet: GovernedAssetReserveFacetAccess,
66
- * stakeFactoryCreatorFacet: StakeFactoryCreator,
67
- * vaultFactoryCreator: VaultFactoryCreatorFacet,
68
- * vaultFactoryGovernorCreator: GovernedContractFacetAccess<{},{}>,
69
- * vaultFactoryVoteCreator: unknown,
48
+ * economicCommitteeKit: CommitteeStartResult,
49
+ * economicCommitteeCreatorFacet: import('@agoric/governance/src/committee.js').CommitteeElectorateCreatorFacet,
50
+ * feeDistributorKit: StartedInstanceKit<typeof import('../feeDistributor.js').start>,
51
+ * periodicFeeCollectors: MapStore<number, import('../feeDistributor.js').PeriodicFeeCollector>,
52
+ * psmKit: MapStore<Brand, PSMKit>,
53
+ * anchorBalancePayments: MapStore<Brand, Payment<'nat'>>,
54
+ * econCharterKit: EconCharterStartResult,
55
+ * reserveKit: GovernanceFacetKit<import('../reserve/assetReserve.js')['prepare']>,
56
+ * vaultFactoryKit: GovernanceFacetKit<import('../vaultFactory/vaultFactory.js')['prepare']>,
57
+ * auctioneerKit: AuctioneerKit,
70
58
  * minInitialDebt: NatValue,
71
59
  * }>} EconomyBootstrapSpace
72
60
  */
73
61
 
62
+ /** @typedef {import('@agoric/zoe/src/zoeService/utils.js').StartedInstanceKit<import('../econCommitteeCharter')['prepare']>} EconCharterStartResult */
63
+ /** @typedef {import('@agoric/zoe/src/zoeService/utils.js').StartedInstanceKit<import('@agoric/governance/src/committee.js')['prepare']>} CommitteeStartResult */
64
+
74
65
  /**
75
66
  * @file A collection of productions, each of which declares inputs and outputs.
76
67
  * Each function is passed a set of powers for reading from and writing to the vat config.
@@ -80,184 +71,23 @@ const MILLI = 1_000_000n;
80
71
  * In production called by @agoric/vats to bootstrap.
81
72
  */
82
73
 
83
- /**
84
- * @param {EconomyBootstrapPowers} powers
85
- * @param {{
86
- * interchainPoolOptions?: { minimumCentral?: bigint }
87
- * }} [options]
88
- */
89
- export const startInterchainPool = async (
90
- {
91
- consume: { bankManager: mgrP, zoe, agoricNamesAdmin },
92
- installation: {
93
- consume: { interchainPool: installation },
94
- },
95
- instance: {
96
- consume: { amm },
97
- produce: { interchainPool: _viaAgoricNamesAdmin },
98
- },
99
- brand: {
100
- consume: { [Stable.symbol]: centralBrandP },
101
- },
102
- issuer: {
103
- consume: { [Stable.symbol]: centralIssuerP },
104
- },
105
- },
106
- { interchainPoolOptions = {} } = {},
107
- ) => {
108
- trace('startInterchainPool');
109
- // TODO: get minimumCentral dynamically from the AMM
110
- const { minimumCentral = 100n * MILLI } = interchainPoolOptions;
111
- const [centralIssuer, centralBrand, bankManager] = await Promise.all([
112
- centralIssuerP,
113
- centralBrandP,
114
- mgrP,
115
- ]);
116
-
117
- const terms = await deeplyFulfilledObject(
118
- harden({
119
- minimumCentral: AmountMath.make(centralBrand, minimumCentral),
120
- amm,
121
- }),
122
- );
123
- const { instance } = await E(zoe).startInstance(
124
- installation,
125
- { Central: centralIssuer },
126
- terms,
127
- {
128
- bankManager,
129
- },
130
- );
131
-
132
- const instanceAdmin = E(agoricNamesAdmin).lookupAdmin('instance');
133
- await E(instanceAdmin).update('interchainPool', instance);
134
- };
135
- harden(startInterchainPool);
136
-
137
- const AMM_STORAGE_PATH = 'amm'; // TODO: share with agoricNames?
138
-
139
- /**
140
- * @param {EconomyBootstrapPowers} powers
141
- * @param {{ options?: { minInitialPoolLiquidity?: bigint }}} opts
142
- */
143
- export const setupAmm = async (
144
- {
145
- consume: {
146
- board,
147
- chainTimerService,
148
- zoe,
149
- economicCommitteeCreatorFacet: committeeCreator,
150
- chainStorage,
151
- },
152
- produce: {
153
- ammCreatorFacet,
154
- ammInstanceWithoutReserve,
155
- ammGovernorCreatorFacet,
156
- },
157
- brand: {
158
- consume: { [Stable.symbol]: runBrandP },
159
- },
160
- issuer: {
161
- consume: { [Stable.symbol]: centralIssuer },
162
- },
163
- instance: {
164
- produce: { ammGovernor },
165
- },
166
- installation: {
167
- consume: { contractGovernor: governorInstallation, amm: ammInstallation },
168
- },
169
- },
170
- { options = {} } = {},
171
- ) => {
172
- trace('setupAmm');
173
-
174
- const poserInvitationP = E(committeeCreator).getPoserInvitation();
175
- const [poserInvitation, runBrand] = await Promise.all([
176
- poserInvitationP,
177
- runBrandP,
178
- ]);
179
- const { minInitialPoolLiquidity = 1_000_000_000n } = options;
180
-
181
- const ammTerms = makeAmmTerms(
182
- chainTimerService,
183
- E(E(zoe).getInvitationIssuer()).getAmountOf(poserInvitationP),
184
- AmountMath.make(runBrand, minInitialPoolLiquidity),
185
- );
186
-
187
- const storageNode = await makeStorageNodeChild(
188
- chainStorage,
189
- AMM_STORAGE_PATH,
190
- );
191
- const marshaller = await E(board).getPublishingMarshaller();
192
-
193
- const ammGovernorTerms = await deeplyFulfilledObject(
194
- harden({
195
- timer: chainTimerService,
196
- governedContractInstallation: ammInstallation,
197
- governed: {
198
- terms: ammTerms,
199
- issuerKeywordRecord: { Central: centralIssuer },
200
- },
201
- }),
202
- );
203
-
204
- /** @type {{ creatorFacet: GovernedContractFacetAccess<XYKAMMPublicFacet,XYKAMMCreatorFacet>, publicFacet: GovernorPublic, instance: Instance }} */
205
- const g = await E(zoe).startInstance(
206
- governorInstallation,
207
- {},
208
- ammGovernorTerms,
209
- {
210
- electorateCreatorFacet: committeeCreator,
211
- governed: {
212
- initialPoserInvitation: poserInvitation,
213
- storageNode,
214
- marshaller,
215
- },
216
- },
217
- );
218
-
219
- const [creatorFacet, ammPublicFacet, instance] = await Promise.all([
220
- E(g.creatorFacet).getCreatorFacet(),
221
- E(g.creatorFacet).getPublicFacet(),
222
- E(g.publicFacet).getGovernedContract(),
223
- ]);
224
- ammGovernorCreatorFacet.resolve(g.creatorFacet);
225
- ammCreatorFacet.resolve(creatorFacet);
226
-
227
- // Confirm that the amm was indeed setup
228
- assert(ammPublicFacet, X`ammPublicFacet broken ${ammPublicFacet}`);
229
-
230
- ammInstanceWithoutReserve.resolve(instance);
231
- ammGovernor.resolve(g.instance);
232
- return ammInstallation;
233
- };
234
-
235
74
  /** @param {EconomyBootstrapPowers} powers */
236
75
  export const setupReserve = async ({
237
76
  consume: {
238
- ammCreatorFacet,
239
- ammInstanceWithoutReserve,
240
77
  board,
241
78
  feeMintAccess: feeMintAccessP,
242
79
  chainStorage,
243
80
  chainTimerService,
81
+ diagnostics,
244
82
  zoe,
245
83
  economicCommitteeCreatorFacet: committeeCreator,
246
84
  },
247
- produce: {
248
- reserveCreatorFacet,
249
- reserveGovernorCreatorFacet,
250
- reservePublicFacet,
251
- },
85
+ produce: { reserveKit },
252
86
  issuer: {
253
87
  consume: { [Stable.symbol]: centralIssuer },
254
88
  },
255
89
  instance: {
256
- produce: {
257
- amm: ammInstanceProducer,
258
- reserve: reserveInstanceProducer,
259
- reserveGovernor,
260
- },
90
+ produce: { reserve: reserveInstanceProducer, reserveGovernor },
261
91
  },
262
92
  installation: {
263
93
  consume: {
@@ -269,6 +99,7 @@ export const setupReserve = async ({
269
99
  const STORAGE_PATH = 'reserve';
270
100
  trace('setupReserve');
271
101
  const poserInvitationP = E(committeeCreator).getPoserInvitation();
102
+
272
103
  const [poserInvitation, poserInvitationAmount, feeMintAccess] =
273
104
  await Promise.all([
274
105
  poserInvitationP,
@@ -276,14 +107,11 @@ export const setupReserve = async ({
276
107
  feeMintAccessP,
277
108
  ]);
278
109
 
279
- const reserveTerms = makeReserveTerms(
280
- poserInvitationAmount,
281
- ammInstanceWithoutReserve,
282
- );
283
-
284
110
  const storageNode = await makeStorageNodeChild(chainStorage, STORAGE_PATH);
285
111
  const marshaller = await E(board).getReadonlyMarshaller();
286
112
 
113
+ const reserveTerms = makeReserveTerms(poserInvitationAmount);
114
+
287
115
  const reserveGovernorTerms = await deeplyFulfilledObject(
288
116
  harden({
289
117
  timer: chainTimerService,
@@ -291,23 +119,25 @@ export const setupReserve = async ({
291
119
  governed: {
292
120
  terms: reserveTerms,
293
121
  issuerKeywordRecord: { Central: centralIssuer },
122
+ label: 'reserve',
294
123
  },
295
124
  }),
296
125
  );
297
- /** @type {{ creatorFacet: GovernedAssetReserveFacetAccess, publicFacet: GovernorPublic, instance: Instance }} */
126
+ const privateArgs = {
127
+ governed: {
128
+ feeMintAccess,
129
+ initialPoserInvitation: poserInvitation,
130
+ marshaller,
131
+ storageNode,
132
+ },
133
+ };
134
+ /** @type {GovernorStartedInstallationKit<typeof reserveInstallation>} */
298
135
  const g = await E(zoe).startInstance(
299
136
  governorInstallation,
300
137
  {},
301
138
  reserveGovernorTerms,
302
- {
303
- electorateCreatorFacet: committeeCreator,
304
- governed: {
305
- feeMintAccess,
306
- initialPoserInvitation: poserInvitation,
307
- marshaller,
308
- storageNode,
309
- },
310
- },
139
+ privateArgs,
140
+ 'reserve.governor',
311
141
  );
312
142
 
313
143
  const [creatorFacet, publicFacet, instance] = await Promise.all([
@@ -316,159 +146,206 @@ export const setupReserve = async ({
316
146
  E(g.publicFacet).getGovernedContract(),
317
147
  ]);
318
148
 
319
- reserveGovernorCreatorFacet.resolve(g.creatorFacet);
320
- reserveCreatorFacet.resolve(creatorFacet);
321
- reservePublicFacet.resolve(publicFacet);
149
+ reserveKit.resolve(
150
+ harden({
151
+ label: 'AssetReserve',
152
+ instance,
153
+ publicFacet,
154
+ creatorFacet,
155
+ adminFacet: g.adminFacet,
156
+
157
+ governor: g.instance,
158
+ governorCreatorFacet: g.creatorFacet,
159
+ governorAdminFacet: g.adminFacet,
160
+ }),
161
+ );
162
+ await E(diagnostics).savePrivateArgs(instance, privateArgs.governed);
163
+ await E(diagnostics).savePrivateArgs(g.instance, privateArgs);
322
164
 
323
165
  reserveInstanceProducer.resolve(instance);
324
166
  reserveGovernor.resolve(g.instance);
325
167
 
326
- // AMM requires Reserve in order to add pools, but we can't provide it at startInstance
327
- // time because Reserve requires AMM itself in order to be started.
328
- // Now that we have the reserve, provide it to the AMM.
329
- trace('Resolving the reserve public facet on the AMM');
330
- await E(ammCreatorFacet).resolveReserveFacet(publicFacet);
331
- // it now has the reserve
332
- ammInstanceProducer.resolve(ammInstanceWithoutReserve);
333
-
334
168
  return reserveInstallation;
335
169
  };
336
170
 
337
171
  /**
338
- * @param {EconomyBootstrapPowers} powers
172
+ * @param {EconomyBootstrapPowers['consume']} consume
339
173
  * @param {object} config
340
- * @param {LoanTiming} [config.loanParams]
341
- * @param {bigint} minInitialDebt
174
+ * @param {InterestTiming} [config.interestTiming]
175
+ * @param {object} [config.options]
176
+ * @param {string} [config.options.endorsedUi]
177
+ * @param {Amount<'nat'>} minInitialDebt
342
178
  */
343
- export const startVaultFactory = async (
344
- {
345
- consume: {
346
- board,
347
- chainStorage,
348
- chainTimerService,
349
- priceAuthority,
350
- zoe,
351
- feeMintAccess: feeMintAccessP,
352
- economicCommitteeCreatorFacet: electorateCreatorFacet,
353
- reserveCreatorFacet,
354
- },
355
- produce, // { vaultFactoryCreator }
356
- brand: {
357
- consume: { [Stable.symbol]: centralBrandP },
358
- },
359
- instance: {
360
- produce: instanceProduce,
361
- consume: { amm: ammInstance, reserve: reserveInstance },
362
- },
363
- installation: {
364
- consume: {
365
- VaultFactory: vaultFactoryInstallation,
366
- liquidate: liquidateInstallationP,
367
- contractGovernor: contractGovernorInstallation,
368
- },
369
- },
370
- },
179
+ export const setupVaultFactoryArguments = async (
180
+ consume,
371
181
  {
372
- loanParams = {
182
+ interestTiming = {
373
183
  chargingPeriod: SECONDS_PER_HOUR,
374
184
  recordingPeriod: SECONDS_PER_DAY,
375
185
  },
186
+ options: { endorsedUi } = {},
376
187
  } = {},
377
- minInitialDebt = 5_000_000n,
188
+ minInitialDebt,
378
189
  ) => {
379
190
  const STORAGE_PATH = 'vaultFactory';
380
- trace('startVaultFactory');
191
+ trace('setupVaultFactory');
192
+
193
+ const {
194
+ board,
195
+ chainStorage,
196
+ chainTimerService,
197
+ priceAuthority,
198
+ zoe,
199
+ feeMintAccess: feeMintAccessP,
200
+ economicCommitteeCreatorFacet: electorateCreatorFacet,
201
+ reserveKit,
202
+ auctioneerKit,
203
+ } = consume;
381
204
 
382
205
  const poserInvitationP = E(electorateCreatorFacet).getPoserInvitation();
383
- const shortfallInvitationP =
384
- E(reserveCreatorFacet).makeShortfallReportingInvitation();
206
+ const shortfallInvitationP = E(
207
+ E.get(reserveKit).creatorFacet,
208
+ ).makeShortfallReportingInvitation();
209
+
385
210
  const [
386
211
  initialPoserInvitation,
387
212
  poserInvitationAmount,
388
213
  initialShortfallInvitation,
389
214
  shortfallInvitationAmount,
390
- liquidateInstallation,
391
215
  feeMintAccess,
216
+ auctioneerPublicFacet,
392
217
  ] = await Promise.all([
393
218
  poserInvitationP,
394
219
  E(E(zoe).getInvitationIssuer()).getAmountOf(poserInvitationP),
395
220
  shortfallInvitationP,
396
221
  E(E(zoe).getInvitationIssuer()).getAmountOf(shortfallInvitationP),
397
- liquidateInstallationP,
398
222
  feeMintAccessP,
223
+ E.get(auctioneerKit).publicFacet,
399
224
  ]);
400
225
 
401
- const centralBrand = await centralBrandP;
402
-
403
- const ammPublicFacet = await E(zoe).getPublicFacet(ammInstance);
404
- const reservePublicFacet = await E(zoe).getPublicFacet(reserveInstance);
226
+ const reservePublicFacet = await E.get(reserveKit).publicFacet;
405
227
  const storageNode = await makeStorageNodeChild(chainStorage, STORAGE_PATH);
406
228
  const marshaller = await E(board).getReadonlyMarshaller();
407
229
 
408
- const vaultFactoryTerms = makeGovernedTerms(
409
- { storageNode, marshaller },
410
- {
411
- priceAuthority,
412
- reservePublicFacet,
413
- loanTiming: loanParams,
414
- liquidationInstall: liquidateInstallation,
415
- timer: chainTimerService,
416
- electorateInvitationAmount: poserInvitationAmount,
417
- ammPublicFacet,
418
- liquidationTerms: liquidationDetailTerms(centralBrand),
419
- minInitialDebt: AmountMath.make(centralBrand, minInitialDebt),
420
- bootstrapPaymentValue: 0n,
421
- shortfallInvitationAmount,
230
+ const vaultFactoryTerms = makeGovernedVFTerms({
231
+ priceAuthority,
232
+ auctioneerPublicFacet,
233
+ reservePublicFacet,
234
+ interestTiming,
235
+ timer: chainTimerService,
236
+ electorateInvitationAmount: poserInvitationAmount,
237
+ minInitialDebt,
238
+ bootstrapPaymentValue: 0n,
239
+ shortfallInvitationAmount,
240
+ endorsedUi,
241
+ });
242
+
243
+ const vaultFactoryPrivateArgs = {
244
+ feeMintAccess,
245
+ initialPoserInvitation,
246
+ initialShortfallInvitation,
247
+ marshaller,
248
+ storageNode,
249
+ };
250
+
251
+ return { vaultFactoryTerms, vaultFactoryPrivateArgs };
252
+ };
253
+
254
+ /**
255
+ * @param {EconomyBootstrapPowers} powers
256
+ * @param {object} config
257
+ * @param {InterestTiming} [config.interestTiming]
258
+ * @param {object} [config.options]
259
+ * @param {string} [config.options.endorsedUi]
260
+ * @param {bigint} minInitialDebt
261
+ */
262
+ export const startVaultFactory = async (
263
+ {
264
+ consume,
265
+ produce: { vaultFactoryKit },
266
+ brand: {
267
+ consume: { [Stable.symbol]: centralBrandP },
422
268
  },
423
- );
269
+ instance: { produce: instanceProduce },
270
+ installation: {
271
+ consume: {
272
+ VaultFactory: vaultFactoryInstallation,
273
+ contractGovernor: contractGovernorInstallation,
274
+ },
275
+ },
276
+ },
277
+ config,
278
+ minInitialDebt = 5_000_000n,
279
+ ) => {
280
+ trace('startVaultFactory');
281
+
282
+ const centralBrand = await centralBrandP;
283
+
284
+ const { vaultFactoryTerms, vaultFactoryPrivateArgs } =
285
+ await setupVaultFactoryArguments(
286
+ consume,
287
+ config,
288
+ AmountMath.make(centralBrand, minInitialDebt),
289
+ );
424
290
 
425
291
  const governorTerms = await deeplyFulfilledObject(
426
292
  harden({
427
- timer: chainTimerService,
293
+ timer: consume.chainTimerService,
428
294
  governedContractInstallation: vaultFactoryInstallation,
429
295
  governed: {
430
296
  terms: vaultFactoryTerms,
431
297
  issuerKeywordRecord: {},
298
+ label: 'vaultFactory',
432
299
  },
433
300
  }),
434
301
  );
435
302
 
436
- const { creatorFacet: governorCreatorFacet, instance: governorInstance } =
437
- await E(zoe).startInstance(
438
- contractGovernorInstallation,
439
- undefined,
440
- governorTerms,
441
- harden({
442
- electorateCreatorFacet,
443
- governed: {
444
- feeMintAccess,
445
- initialPoserInvitation,
446
- initialShortfallInvitation,
447
- marshaller,
448
- storageNode,
449
- },
450
- }),
451
- );
303
+ /** @type {GovernorStartedInstallationKit<typeof vaultFactoryInstallation>} */
304
+ const g = await E(consume.zoe).startInstance(
305
+ contractGovernorInstallation,
306
+ undefined,
307
+ governorTerms,
308
+ harden({
309
+ electorateCreatorFacet: consume.economicCommitteeCreatorFacet,
310
+ governed: vaultFactoryPrivateArgs,
311
+ }),
312
+ 'vaultFactory.governor',
313
+ );
452
314
 
453
- const [vaultFactoryInstance, vaultFactoryCreator] = await Promise.all([
454
- E(governorCreatorFacet).getInstance(),
455
- E(governorCreatorFacet).getCreatorFacet(),
456
- ]);
315
+ const [vaultFactoryInstance, vaultFactoryCreator, publicFacet, adminFacet] =
316
+ await Promise.all([
317
+ E(g.creatorFacet).getInstance(),
318
+ E(g.creatorFacet).getCreatorFacet(),
319
+ E(g.creatorFacet).getPublicFacet(),
320
+ E(g.creatorFacet).getAdminFacet(),
321
+ ]);
457
322
 
458
- const voteCreator = Far('vaultFactory vote creator', {
459
- /** @type {VoteOnParamChanges} */
460
- voteOnParamChanges: (...args) =>
461
- E(governorCreatorFacet).voteOnParamChanges(...args),
462
- });
323
+ // XXX omitting the governor
324
+ await E(consume.diagnostics).savePrivateArgs(
325
+ vaultFactoryInstance,
326
+ vaultFactoryPrivateArgs,
327
+ );
463
328
 
464
- produce.vaultFactoryCreator.resolve(vaultFactoryCreator);
465
- produce.vaultFactoryGovernorCreator.resolve(governorCreatorFacet);
466
- produce.vaultFactoryVoteCreator.resolve(voteCreator);
329
+ vaultFactoryKit.resolve(
330
+ harden({
331
+ label: 'VaultFactory',
332
+ creatorFacet: vaultFactoryCreator,
333
+ adminFacet,
334
+ publicFacet,
335
+ instance: vaultFactoryInstance,
336
+
337
+ governor: g.instance,
338
+ governorAdminFacet: g.adminFacet,
339
+ governorCreatorFacet: g.creatorFacet,
340
+
341
+ // XXX try refactoring to use savePrivateArgs
342
+ privateArgs: vaultFactoryPrivateArgs,
343
+ }),
344
+ );
467
345
 
468
346
  // Advertise the installations, instances in agoricNames.
469
347
  instanceProduce.VaultFactory.resolve(vaultFactoryInstance);
470
- instanceProduce.Treasury.resolve(vaultFactoryInstance);
471
- instanceProduce.VaultFactoryGovernor.resolve(governorInstance);
348
+ instanceProduce.VaultFactoryGovernor.resolve(g.instance);
472
349
  };
473
350
 
474
351
  /**
@@ -481,7 +358,7 @@ export const startVaultFactory = async (
481
358
  * @param {string} [root0.options.vaultFactoryControllerAddress]
482
359
  */
483
360
  export const grantVaultFactoryControl = async (
484
- { consume: { client, priceAuthorityAdmin, vaultFactoryCreator } },
361
+ { consume: { client, priceAuthorityAdmin, vaultFactoryKit } },
485
362
  { options: { vaultFactoryControllerAddress } = {} } = {},
486
363
  ) => {
487
364
  await E(client).assignBundle([
@@ -489,7 +366,7 @@ export const grantVaultFactoryControl = async (
489
366
  vaultFactoryCreatorFacet:
490
367
  typeof vaultFactoryControllerAddress === 'string' &&
491
368
  addr === vaultFactoryControllerAddress
492
- ? vaultFactoryCreator
369
+ ? E.get(vaultFactoryKit).creatorFacet
493
370
  : undefined,
494
371
  priceAuthorityAdminFacet:
495
372
  typeof vaultFactoryControllerAddress === 'string' &&
@@ -501,92 +378,6 @@ export const grantVaultFactoryControl = async (
501
378
  };
502
379
  harden(grantVaultFactoryControl);
503
380
 
504
- /** @param {BootstrapPowers} powers */
505
- export const configureVaultFactoryUI = async ({
506
- consume: { board, zoe },
507
- issuer: {
508
- consume: { [Stable.symbol]: stableIssuerP },
509
- },
510
- brand: {
511
- consume: { [Stable.symbol]: stableBrandP },
512
- },
513
- installation: {
514
- consume: {
515
- amm: ammInstallation,
516
- VaultFactory: vaultInstallation,
517
- contractGovernor,
518
- binaryVoteCounter,
519
- liquidate,
520
- },
521
- },
522
- instance: {
523
- consume: { amm: ammInstance, VaultFactory: vaultInstance },
524
- },
525
- uiConfig,
526
- }) => {
527
- const installs = await Collect.allValues({
528
- vaultFactory: vaultInstallation,
529
- amm: ammInstallation,
530
- contractGovernor,
531
- binaryVoteCounter,
532
- liquidate,
533
- });
534
- const instances = await Collect.allValues({
535
- amm: ammInstance,
536
- vaultFactory: vaultInstance,
537
- });
538
- const [stableIssuer, stableBrand] = await Promise.all([
539
- stableIssuerP,
540
- stableBrandP,
541
- ]);
542
-
543
- const invitationIssuer = await E(zoe).getInvitationIssuer();
544
-
545
- const vaultFactoryUiDefaults = {
546
- CONTRACT_NAME: 'VaultFactory',
547
- AMM_NAME: 'amm',
548
- BRIDGE_URL: 'http://127.0.0.1:8000',
549
- // Avoid setting API_URL, so that the UI uses the same origin it came from,
550
- // if it has an api server.
551
- // API_URL: 'http://127.0.0.1:8000',
552
- };
553
-
554
- // Look up all the board IDs.
555
- const boardIdValue = [
556
- ['INSTANCE_BOARD_ID', instances.vaultFactory],
557
- ['INSTALLATION_BOARD_ID', installs.vaultFactory],
558
- // @deprecated
559
- ['RUN_ISSUER_BOARD_ID', stableIssuer],
560
- // @deprecated
561
- ['RUN_BRAND_BOARD_ID', stableBrand],
562
- ['STABLE_ISSUER_BOARD_ID', stableIssuer],
563
- ['STABLE_BRAND_BOARD_ID', stableBrand],
564
- ['AMM_INSTALLATION_BOARD_ID', installs.amm],
565
- ['LIQ_INSTALLATION_BOARD_ID', installs.liquidate],
566
- ['BINARY_COUNTER_INSTALLATION_BOARD_ID', installs.binaryVoteCounter],
567
- ['CONTRACT_GOVERNOR_INSTALLATION_BOARD_ID', installs.contractGovernor],
568
- ['AMM_INSTANCE_BOARD_ID', instances.amm],
569
- ['INVITE_BRAND_BOARD_ID', E(invitationIssuer).getBrand()],
570
- ];
571
- await Promise.all(
572
- boardIdValue.map(async ([key, valP]) => {
573
- const val = await valP;
574
- const boardId = await E(board).getId(val);
575
- vaultFactoryUiDefaults[key] = boardId;
576
- }),
577
- );
578
-
579
- // Stash the defaults where the UI can find them.
580
- harden(vaultFactoryUiDefaults);
581
-
582
- // Install the names in agoricNames.
583
- uiConfig.produce[vaultFactoryUiDefaults.CONTRACT_NAME].resolve(
584
- vaultFactoryUiDefaults,
585
- );
586
- uiConfig.produce.Treasury.resolve(vaultFactoryUiDefaults); // compatibility
587
- };
588
- harden(configureVaultFactoryUI);
589
-
590
381
  /**
591
382
  * Start the reward distributor.
592
383
  *
@@ -596,17 +387,12 @@ export const startRewardDistributor = async ({
596
387
  consume: {
597
388
  chainTimerService,
598
389
  bankManager,
599
- vaultFactoryCreator,
390
+ vaultFactoryKit,
600
391
  periodicFeeCollectors,
601
- ammCreatorFacet,
602
- stakeFactoryCreatorFacet,
603
- reservePublicFacet,
392
+ reserveKit,
604
393
  zoe,
605
394
  },
606
- produce: {
607
- feeDistributorCreatorFacet: feeDistributorCreatorFacetP,
608
- periodicFeeCollectors: periodicFeeCollectorsP,
609
- },
395
+ produce: { feeDistributorKit, periodicFeeCollectors: periodicFeeCollectorsP },
610
396
  instance: {
611
397
  produce: { feeDistributor: feeDistributorP },
612
398
  },
@@ -627,7 +413,7 @@ export const startRewardDistributor = async ({
627
413
  timerService,
628
414
  collectionInterval: 60n * 60n, // 1 hour
629
415
  keywordShares: {
630
- RewardDistributor: 1n,
416
+ RewardDistributor: 0n,
631
417
  Reserve: 1n,
632
418
  },
633
419
  }),
@@ -648,216 +434,186 @@ export const startRewardDistributor = async ({
648
434
  return undefined;
649
435
  });
650
436
 
651
- const feeDistributorFacets = await E(zoe).startInstance(
437
+ /**
438
+ * @type {Awaited<
439
+ * ReturnType<typeof import('../feeDistributor.js').makeFeeDistributor>>
440
+ * & { adminFacet: AdminFacet, instance: Instance }
441
+ * }
442
+ */
443
+ const instanceKit = await E(zoe).startInstance(
652
444
  feeDistributor,
653
445
  { Fee: centralIssuer },
654
446
  feeDistributorTerms,
447
+ undefined,
448
+ 'feeDistributor',
655
449
  );
656
- await E(feeDistributorFacets.creatorFacet).setDestinations({
657
- RewardDistributor:
658
- rewardDistributorDepositFacet &&
659
- E(feeDistributorFacets.creatorFacet).makeDepositFacetDestination(
660
- rewardDistributorDepositFacet,
661
- ),
662
- Reserve: E(feeDistributorFacets.creatorFacet).makeOfferDestination(
450
+ /** @type {ERef<import('../feeDistributor.js').FeeDestination>} */
451
+ await E(instanceKit.creatorFacet).setDestinations({
452
+ ...(rewardDistributorDepositFacet && {
453
+ RewardDistributor: E(
454
+ instanceKit.creatorFacet,
455
+ ).makeDepositFacetDestination(rewardDistributorDepositFacet),
456
+ }),
457
+ Reserve: E(instanceKit.creatorFacet).makeOfferDestination(
458
+ zoe,
663
459
  'Collateral',
664
- reservePublicFacet,
460
+ E.get(reserveKit).publicFacet,
665
461
  'makeAddCollateralInvitation',
666
462
  ),
667
463
  });
668
464
 
669
- feeDistributorCreatorFacetP.resolve(feeDistributorFacets.creatorFacet);
670
- feeDistributorP.resolve(feeDistributorFacets.instance);
465
+ feeDistributorKit.resolve(
466
+ harden({ ...instanceKit, label: 'feeDistributor' }),
467
+ );
468
+ feeDistributorP.resolve(instanceKit.instance);
671
469
 
672
470
  // Initialize the periodic collectors list if we don't have one.
673
- periodicFeeCollectorsP.resolve([]);
471
+ periodicFeeCollectorsP.resolve(
472
+ makeScalarBigMapStore('periodicCollectors', { durable: true }),
473
+ );
674
474
  const periodicCollectors = await periodicFeeCollectors;
675
475
 
676
- const collectorFacets = {
677
- vaultFactory: vaultFactoryCreator,
678
- amm: ammCreatorFacet,
679
- runStake: stakeFactoryCreatorFacet,
476
+ const collectorKit = {
477
+ vaultFactory: E.get(vaultFactoryKit).creatorFacet,
680
478
  };
681
479
  await Promise.all(
682
- Object.entries(collectorFacets).map(async ([debugName, collectorFacet]) => {
683
- const collector = E(
684
- feeDistributorFacets.creatorFacet,
685
- ).makeContractFeeCollector(zoe, collectorFacet);
480
+ Object.entries(collectorKit).map(async ([debugName, collectorFacet]) => {
481
+ const collector = E(instanceKit.creatorFacet).makeContractFeeCollector(
482
+ zoe,
483
+ collectorFacet,
484
+ );
686
485
  const periodicCollector = await E(
687
- feeDistributorFacets.creatorFacet,
486
+ instanceKit.creatorFacet,
688
487
  ).startPeriodicCollection(debugName, collector);
689
- periodicCollectors.push(periodicCollector);
488
+ periodicCollectors.init(periodicCollectors.getSize(), periodicCollector);
690
489
  }),
691
490
  );
692
491
  };
693
492
  harden(startRewardDistributor);
694
493
 
695
494
  /**
696
- * @param {BootstrapPowers & PromiseSpaceOf<{
697
- * lienBridge: StakingAuthority,
698
- * }>} powers
699
- */
700
- export const startLienBridge = async ({
701
- consume: { bridgeManager: bridgeOptP },
702
- produce: { lienBridge },
703
- brand: {
704
- consume: { [Stake.symbol]: bldP },
705
- },
706
- }) => {
707
- trace('lienBridge');
708
-
709
- const bridgeManager = await bridgeOptP;
710
- if (!bridgeManager) {
711
- return;
712
- }
713
- const bldBrand = await bldP;
714
- const reporter = makeStakeReporter(bridgeManager, bldBrand);
715
- lienBridge.resolve(reporter);
716
- };
717
-
718
- /**
719
- * @typedef {EconomyBootstrapPowers & PromiseSpaceOf<{
720
- * client: ClientManager,
721
- * lienBridge: StakingAuthority,
722
- * }>} StakeFactoryBootstrapPowers
723
- */
724
-
725
- /**
726
- * @param {StakeFactoryBootstrapPowers } powers
495
+ * @param {EconomyBootstrapPowers} powers
727
496
  * @param {object} config
728
- * @param {bigint} [config.debtLimit] count of Minted
729
- * @param {Rational} [config.mintingRatio] ratio of Minted to BLD
730
- * @param {bigint} [config.interestRateBP]
731
- * @param {bigint} [config.loanFeeBP]
732
- * @param {bigint} [config.chargingPeriod]
733
- * @param {bigint} [config.recordingPeriod]
734
- * @typedef {[bigint, bigint]} Rational
735
- * @typedef {Awaited<ReturnType<typeof import('../stakeFactory/stakeFactory.js').start>>} StartStakeFactory
497
+ * @param {any} [config.auctionParams]
736
498
  */
737
- export const startStakeFactory = async (
499
+ export const startAuctioneer = async (
738
500
  {
739
501
  consume: {
740
- board,
741
502
  zoe,
742
- feeMintAccess: feeMintAccessP,
743
- lienBridge,
744
- client,
503
+ board,
745
504
  chainTimerService,
505
+ priceAuthority,
746
506
  chainStorage,
747
- economicCommitteeCreatorFacet,
507
+ economicCommitteeCreatorFacet: electorateCreatorFacet,
508
+ },
509
+ produce: { auctioneerKit },
510
+ instance: {
511
+ produce: { auctioneer: auctionInstance },
512
+ consume: { reserve: reserveInstance },
748
513
  },
749
- // @ts-expect-error TODO: add to BootstrapPowers
750
- produce: { stakeFactoryCreatorFacet, stakeFactoryGovernorCreatorFacet },
751
514
  installation: {
752
515
  consume: {
516
+ auctioneer: auctionInstallation,
753
517
  contractGovernor: contractGovernorInstallation,
754
- stakeFactory: stakeFactoryInstallation,
755
518
  },
756
519
  },
757
- instance: {
758
- produce: { stakeFactory: stakeFactoryinstanceR },
759
- },
760
- brand: {
761
- consume: { [Stake.symbol]: bldBrandP, [Stable.symbol]: runBrandP },
762
- produce: { Attestation: attestationBrandR },
763
- },
764
520
  issuer: {
765
- consume: { [Stake.symbol]: bldIssuer },
766
- produce: { Attestation: attestationIssuerR },
521
+ consume: { [Stable.symbol]: runIssuerP },
767
522
  },
768
523
  },
769
524
  {
770
- debtLimit = 1_000_000_000_000n,
771
- mintingRatio = [1n, 4n],
772
- interestRateBP = 250n,
773
- loanFeeBP = 200n,
774
- chargingPeriod = SECONDS_PER_HOUR,
775
- recordingPeriod = SECONDS_PER_DAY,
525
+ auctionParams = {
526
+ StartFrequency: 3600n,
527
+ ClockStep: 3n * 60n,
528
+ StartingRate: 10500n,
529
+ LowestRate: 6500n,
530
+ DiscountStep: 500n,
531
+ AuctionStartDelay: 2n,
532
+ PriceLockPeriod: 30n * 60n, // half an hour
533
+ },
776
534
  } = {},
777
535
  ) => {
778
- const STORAGE_PATH = 'stakeFactory';
536
+ trace('startAuctioneer');
537
+ const STORAGE_PATH = 'auction';
779
538
 
780
- const [bldBrand, runBrand] = await Promise.all([bldBrandP, runBrandP]);
539
+ const poserInvitationP = E(electorateCreatorFacet).getPoserInvitation();
781
540
 
782
- const poserInvitationP = E(
783
- economicCommitteeCreatorFacet,
784
- ).getPoserInvitation();
785
- const [initialPoserInvitation, electorateInvitationAmount, feeMintAccess] =
541
+ const [initialPoserInvitation, electorateInvitationAmount, runIssuer] =
786
542
  await Promise.all([
787
543
  poserInvitationP,
788
544
  E(E(zoe).getInvitationIssuer()).getAmountOf(poserInvitationP),
789
- feeMintAccessP,
545
+ runIssuerP,
790
546
  ]);
791
547
 
792
- const stakeFactoryTerms = makeStakeFactoryTerms(
793
- {
794
- timerService: chainTimerService,
795
- chargingPeriod,
796
- recordingPeriod,
797
- },
798
- {
799
- debtLimit: AmountMath.make(runBrand, debtLimit),
800
- mintingRatio: makeRatio(
801
- mintingRatio[0],
802
- runBrand,
803
- mintingRatio[1],
804
- bldBrand,
805
- ),
806
- interestRate: makeRatio(interestRateBP, runBrand, BASIS_POINTS),
807
- loanFee: makeRatio(loanFeeBP, runBrand, BASIS_POINTS),
808
- electorateInvitationAmount,
809
- },
810
- );
548
+ const timerBrand = await E(chainTimerService).getTimerBrand();
811
549
 
812
550
  const storageNode = await makeStorageNodeChild(chainStorage, STORAGE_PATH);
813
551
  const marshaller = await E(board).getReadonlyMarshaller();
814
552
 
815
- const stakeTerms = await deeplyFulfilledObject(
553
+ const reservePublicFacet = await E(zoe).getPublicFacet(reserveInstance);
554
+
555
+ const auctionTerms = makeGovernedATerms(
556
+ { storageNode, marshaller },
557
+ chainTimerService,
558
+ priceAuthority,
559
+ reservePublicFacet,
560
+ {
561
+ ...auctionParams,
562
+ ElectorateInvitationAmount: electorateInvitationAmount,
563
+ TimerBrand: timerBrand,
564
+ },
565
+ );
566
+
567
+ const governorTerms = await deeplyFulfilledObject(
816
568
  harden({
817
569
  timer: chainTimerService,
818
- governedContractInstallation: stakeFactoryInstallation,
570
+ governedContractInstallation: auctionInstallation,
819
571
  governed: {
820
- terms: stakeFactoryTerms,
821
- issuerKeywordRecord: { Stake: bldIssuer },
572
+ terms: auctionTerms,
573
+ issuerKeywordRecord: { Bid: runIssuer },
574
+ storageNode,
575
+ marshaller,
576
+ label: 'auctioneer',
822
577
  },
823
578
  }),
824
579
  );
825
580
 
826
- /** @type {{ publicFacet: GovernorPublic, creatorFacet: GovernedContractFacetAccess<StakeFactoryPublic,StakeFactoryCreator>}} */
827
- const governorFacets = await E(zoe).startInstance(
581
+ /** @type {GovernorStartedInstallationKit<typeof auctionInstallation>} */
582
+ const governorStartResult = await E(zoe).startInstance(
828
583
  contractGovernorInstallation,
829
- {},
830
- stakeTerms,
831
- {
584
+ undefined,
585
+ governorTerms,
586
+ harden({
587
+ electorateCreatorFacet,
832
588
  governed: {
833
- feeMintAccess,
834
589
  initialPoserInvitation,
835
- lienBridge,
836
590
  storageNode,
837
591
  marshaller,
838
592
  },
839
- },
593
+ }),
594
+ 'auctioneer.governor',
840
595
  );
841
- const governedInstance = await E(governorFacets.creatorFacet).getInstance();
842
- const creatorFacet = E(governorFacets.creatorFacet).getCreatorFacet();
843
596
 
844
- const {
845
- issuers: { Attestation: attIssuer },
846
- brands: { Attestation: attBrand },
847
- } = await E(zoe).getTerms(governedInstance);
848
-
849
- stakeFactoryCreatorFacet.resolve(creatorFacet);
850
- stakeFactoryGovernorCreatorFacet.resolve(governorFacets.creatorFacet);
851
- stakeFactoryinstanceR.resolve(governedInstance);
852
- attestationBrandR.resolve(attBrand);
853
- attestationIssuerR.resolve(attIssuer);
854
- return Promise.all([
855
- E(client).assignBundle([
856
- address => ({
857
- // @ts-expect-error ??? creatorFacet is a StakeFactoryCreator; it has the method
858
- attMaker: E(creatorFacet).provideAttestationMaker(address),
859
- }),
860
- ]),
861
- ]);
597
+ const [governedInstance, governedCreatorFacet, governedPublicFacet] =
598
+ await Promise.all([
599
+ E(governorStartResult.creatorFacet).getInstance(),
600
+ E(governorStartResult.creatorFacet).getCreatorFacet(),
601
+ E(governorStartResult.creatorFacet).getPublicFacet(),
602
+ ]);
603
+
604
+ auctioneerKit.resolve(
605
+ harden({
606
+ label: 'auctioneer',
607
+ creatorFacet: governedCreatorFacet,
608
+ adminFacet: governorStartResult.adminFacet,
609
+ publicFacet: governedPublicFacet,
610
+ instance: governedInstance,
611
+
612
+ governor: governorStartResult.instance,
613
+ governorCreatorFacet: governorStartResult.creatorFacet,
614
+ governorAdminFacet: governorStartResult.adminFacet,
615
+ }),
616
+ );
617
+
618
+ auctionInstance.resolve(governedInstance);
862
619
  };
863
- harden(startStakeFactory);