@agoric/inter-protocol 0.16.2-dev-ecf2d8e.0 → 0.16.2-other-dev-70beeb7.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 (160) hide show
  1. package/CHANGELOG.md +1041 -0
  2. package/package.json +30 -33
  3. package/scripts/add-collateral-core.js +112 -0
  4. package/scripts/build-bundles.js +21 -5
  5. package/scripts/deploy-contracts.js +100 -0
  6. package/scripts/init-core.js +198 -0
  7. package/scripts/invite-committee-core.js +42 -0
  8. package/scripts/manual-price-feed.js +117 -0
  9. package/scripts/price-feed-core.js +104 -0
  10. package/scripts/start-local-chain.sh +84 -0
  11. package/src/auction/auctionBook.js +59 -74
  12. package/src/auction/auctioneer.js +44 -56
  13. package/src/auction/offerBook.js +11 -12
  14. package/src/auction/params.js +5 -3
  15. package/src/auction/scheduleMath.js +13 -13
  16. package/src/auction/scheduler.js +32 -32
  17. package/src/auction/sortedOffers.js +7 -8
  18. package/src/auction/util.js +4 -4
  19. package/src/clientSupport.js +96 -152
  20. package/src/contractSupport.js +5 -5
  21. package/src/econCommitteeCharter.js +17 -18
  22. package/src/feeDistributor.js +33 -34
  23. package/src/interest.js +14 -20
  24. package/src/price/fluxAggregatorContract.js +45 -51
  25. package/src/price/fluxAggregatorKit.js +33 -48
  26. package/src/price/priceOracleKit.js +13 -11
  27. package/src/price/roundsManager.js +64 -52
  28. package/src/proposals/addAssetToVault.js +6 -15
  29. package/src/proposals/committee-proposal.js +27 -21
  30. package/src/proposals/core-proposal.js +7 -7
  31. package/src/proposals/econ-behaviors.js +32 -57
  32. package/src/proposals/price-feed-proposal.js +34 -66
  33. package/src/proposals/startEconCommittee.js +1 -1
  34. package/src/proposals/startPSM.js +22 -32
  35. package/src/proposals/utils.js +7 -26
  36. package/src/psm/psm.js +63 -69
  37. package/src/reserve/assetReserve.js +18 -27
  38. package/src/reserve/assetReserveKit.js +22 -14
  39. package/src/typeGuards.js +13 -0
  40. package/src/vaultFactory/liquidation.js +17 -30
  41. package/src/vaultFactory/math.js +9 -8
  42. package/src/vaultFactory/orderedVaultStore.js +9 -6
  43. package/src/vaultFactory/params.js +18 -24
  44. package/src/vaultFactory/prioritizedVaults.js +2 -2
  45. package/src/vaultFactory/proceeds.js +18 -24
  46. package/src/vaultFactory/storeUtils.js +12 -8
  47. package/src/vaultFactory/types.js +28 -38
  48. package/src/vaultFactory/vault.js +89 -88
  49. package/src/vaultFactory/vaultDirector.js +44 -35
  50. package/src/vaultFactory/vaultFactory.js +26 -33
  51. package/src/vaultFactory/vaultHolder.js +13 -8
  52. package/src/vaultFactory/vaultKit.js +2 -3
  53. package/src/vaultFactory/vaultManager.js +120 -138
  54. package/src/auction/auctionBook.d.ts +0 -83
  55. package/src/auction/auctionBook.d.ts.map +0 -1
  56. package/src/auction/auctioneer.d.ts +0 -75
  57. package/src/auction/auctioneer.d.ts.map +0 -1
  58. package/src/auction/offerBook.d.ts +0 -72
  59. package/src/auction/offerBook.d.ts.map +0 -1
  60. package/src/auction/params.d.ts +0 -142
  61. package/src/auction/params.d.ts.map +0 -1
  62. package/src/auction/scheduleMath.d.ts +0 -4
  63. package/src/auction/scheduleMath.d.ts.map +0 -1
  64. package/src/auction/scheduler.d.ts +0 -49
  65. package/src/auction/scheduler.d.ts.map +0 -1
  66. package/src/auction/sortedOffers.d.ts +0 -8
  67. package/src/auction/sortedOffers.d.ts.map +0 -1
  68. package/src/auction/util.d.ts +0 -30
  69. package/src/auction/util.d.ts.map +0 -1
  70. package/src/clientSupport.d.ts +0 -167
  71. package/src/clientSupport.d.ts.map +0 -1
  72. package/src/collectFees.d.ts +0 -2
  73. package/src/collectFees.d.ts.map +0 -1
  74. package/src/contractSupport.d.ts +0 -33
  75. package/src/contractSupport.d.ts.map +0 -1
  76. package/src/econCommitteeCharter.d.ts +0 -41
  77. package/src/econCommitteeCharter.d.ts.map +0 -1
  78. package/src/feeDistributor.d.ts +0 -212
  79. package/src/feeDistributor.d.ts.map +0 -1
  80. package/src/index.d.ts +0 -2
  81. package/src/index.d.ts.map +0 -1
  82. package/src/interest-math.d.ts +0 -3
  83. package/src/interest-math.d.ts.map +0 -1
  84. package/src/interest.d.ts +0 -29
  85. package/src/interest.d.ts.map +0 -1
  86. package/src/price/fluxAggregatorContract.d.ts +0 -112
  87. package/src/price/fluxAggregatorContract.d.ts.map +0 -1
  88. package/src/price/fluxAggregatorKit.d.ts +0 -155
  89. package/src/price/fluxAggregatorKit.d.ts.map +0 -1
  90. package/src/price/priceOracleKit.d.ts +0 -52
  91. package/src/price/priceOracleKit.d.ts.map +0 -1
  92. package/src/price/roundsManager.d.ts +0 -330
  93. package/src/price/roundsManager.d.ts.map +0 -1
  94. package/src/proposals/addAssetToVault.d.ts +0 -143
  95. package/src/proposals/addAssetToVault.d.ts.map +0 -1
  96. package/src/proposals/committee-proposal.d.ts +0 -113
  97. package/src/proposals/committee-proposal.d.ts.map +0 -1
  98. package/src/proposals/core-proposal.d.ts +0 -149
  99. package/src/proposals/core-proposal.d.ts.map +0 -1
  100. package/src/proposals/econ-behaviors.d.ts +0 -201
  101. package/src/proposals/econ-behaviors.d.ts.map +0 -1
  102. package/src/proposals/price-feed-proposal.d.ts +0 -82
  103. package/src/proposals/price-feed-proposal.d.ts.map +0 -1
  104. package/src/proposals/startEconCommittee.d.ts +0 -34
  105. package/src/proposals/startEconCommittee.d.ts.map +0 -1
  106. package/src/proposals/startPSM.d.ts +0 -61
  107. package/src/proposals/startPSM.d.ts.map +0 -1
  108. package/src/proposals/utils.d.ts +0 -15
  109. package/src/proposals/utils.d.ts.map +0 -1
  110. package/src/provisionPool.d.ts +0 -165
  111. package/src/provisionPool.d.ts.map +0 -1
  112. package/src/provisionPool.js +0 -119
  113. package/src/provisionPoolKit.d.ts +0 -379
  114. package/src/provisionPoolKit.d.ts.map +0 -1
  115. package/src/provisionPoolKit.js +0 -461
  116. package/src/psm/psm.d.ts +0 -178
  117. package/src/psm/psm.d.ts.map +0 -1
  118. package/src/psm/types.d.ts +0 -2
  119. package/src/psm/types.d.ts.map +0 -1
  120. package/src/reserve/assetReserve.d.ts +0 -44
  121. package/src/reserve/assetReserve.d.ts.map +0 -1
  122. package/src/reserve/assetReserveKit.d.ts +0 -114
  123. package/src/reserve/assetReserveKit.d.ts.map +0 -1
  124. package/src/reserve/params.d.ts +0 -10
  125. package/src/reserve/params.d.ts.map +0 -1
  126. package/src/tokens.d.ts +0 -3
  127. package/src/tokens.d.ts.map +0 -1
  128. package/src/tokens.js +0 -5
  129. package/src/vaultFactory/burn.d.ts +0 -2
  130. package/src/vaultFactory/burn.d.ts.map +0 -1
  131. package/src/vaultFactory/liquidation.d.ts +0 -24
  132. package/src/vaultFactory/liquidation.d.ts.map +0 -1
  133. package/src/vaultFactory/math.d.ts +0 -10
  134. package/src/vaultFactory/math.d.ts.map +0 -1
  135. package/src/vaultFactory/orderedVaultStore.d.ts +0 -94
  136. package/src/vaultFactory/orderedVaultStore.d.ts.map +0 -1
  137. package/src/vaultFactory/params.d.ts +0 -159
  138. package/src/vaultFactory/params.d.ts.map +0 -1
  139. package/src/vaultFactory/prioritizedVaults.d.ts +0 -279
  140. package/src/vaultFactory/prioritizedVaults.d.ts.map +0 -1
  141. package/src/vaultFactory/proceeds.d.ts +0 -34
  142. package/src/vaultFactory/proceeds.d.ts.map +0 -1
  143. package/src/vaultFactory/storeUtils.d.ts +0 -25
  144. package/src/vaultFactory/storeUtils.d.ts.map +0 -1
  145. package/src/vaultFactory/type-imports.d.ts +0 -2
  146. package/src/vaultFactory/type-imports.d.ts.map +0 -1
  147. package/src/vaultFactory/types.d.ts +0 -137
  148. package/src/vaultFactory/types.d.ts.map +0 -1
  149. package/src/vaultFactory/vault.d.ts +0 -529
  150. package/src/vaultFactory/vault.d.ts.map +0 -1
  151. package/src/vaultFactory/vaultDirector.d.ts +0 -560
  152. package/src/vaultFactory/vaultDirector.d.ts.map +0 -1
  153. package/src/vaultFactory/vaultFactory.d.ts +0 -162
  154. package/src/vaultFactory/vaultFactory.d.ts.map +0 -1
  155. package/src/vaultFactory/vaultHolder.d.ts +0 -201
  156. package/src/vaultFactory/vaultHolder.d.ts.map +0 -1
  157. package/src/vaultFactory/vaultKit.d.ts +0 -32
  158. package/src/vaultFactory/vaultKit.d.ts.map +0 -1
  159. package/src/vaultFactory/vaultManager.d.ts +0 -554
  160. package/src/vaultFactory/vaultManager.d.ts.map +0 -1
@@ -6,14 +6,14 @@ import { CONTRACT_ELECTORATE, ParamTypes } from '@agoric/governance';
6
6
  import { makeStorageNodeChild } from '@agoric/internal/src/lib-chainStorage.js';
7
7
  import { makeRatio } from '@agoric/zoe/src/contractSupport/index.js';
8
8
  import { E } from '@endo/far';
9
+ import { Stable } from '@agoric/vats/src/tokens.js';
9
10
  import {
10
11
  makeHistoryReviver,
11
12
  makeBoardRemote,
12
13
  slotToBoardRemote,
13
- } from '@agoric/internal/src/marshal.js';
14
+ } from '@agoric/vats/tools/board-utils.js';
14
15
  import { deeplyFulfilledObject } from '@agoric/internal';
15
16
  import { makeScalarBigMapStore } from '@agoric/vat-data';
16
- import { Stable } from '@agoric/internal/src/tokens.js';
17
17
 
18
18
  import { reserveThenGetNamePaths } from './utils.js';
19
19
 
@@ -35,13 +35,10 @@ export { inviteCommitteeMembers, startEconCharter, inviteToEconCharter };
35
35
  const stablePsmKey = `published.psm.${Stable.symbol}`;
36
36
 
37
37
  /**
38
- * @param {[key: string, value: string][]} chainStorageEntries
38
+ * @param {Array<[key: string, value: string]>} chainStorageEntries
39
39
  * @param {string} keyword
40
- * @param {{ minted: Brand<'nat'>; anchor: Brand<'nat'> }} brands
41
- * @returns {{
42
- * metrics?: MetricsNotification;
43
- * governance?: GovernanceSubscriptionState;
44
- * }}
40
+ * @param {{ minted: Brand<'nat'>, anchor: Brand<'nat'> }} brands
41
+ * @returns {{ metrics?: MetricsNotification, governance?: GovernanceSubscriptionState }}
45
42
  */
46
43
  const findOldPSMState = (chainStorageEntries, keyword, brands) => {
47
44
  // In this reviver, object references are revived as boardIDs
@@ -83,7 +80,7 @@ const findOldPSMState = (chainStorageEntries, keyword, brands) => {
83
80
  * @param {bigint} [config.WantMintedFeeBP]
84
81
  * @param {bigint} [config.GiveMintedFeeBP]
85
82
  * @param {bigint} [config.MINT_LIMIT]
86
- * @param {{ anchorOptions?: AnchorOptions }} [config.options]
83
+ * @param {{ anchorOptions?: AnchorOptions } } [config.options]
87
84
  */
88
85
  export const startPSM = async (
89
86
  {
@@ -294,16 +291,16 @@ harden(startPSM);
294
291
  */
295
292
 
296
293
  /**
297
- * Make anchor issuer out of a Cosmos asset; presumably USDC over IBC. Add it to
298
- * BankManager.
294
+ * Make anchor issuer out of a Cosmos asset; presumably
295
+ * USDC over IBC. Add it to BankManager.
299
296
  *
300
- * Also, if vatParameters shows an anchorPoolBalance for this asset, mint a
301
- * payment for that balance.
297
+ * Also, if vatParameters shows an anchorPoolBalance for this asset,
298
+ * mint a payment for that balance.
302
299
  *
303
300
  * TODO: address redundancy with publishInterchainAssetFromBank
304
301
  *
305
302
  * @param {EconomyBootstrapPowers & WellKnownSpaces & ChainStorageVatParams} powers
306
- * @param {{ options: { anchorOptions?: AnchorOptions } }} config
303
+ * @param {{options?: { anchorOptions?: AnchorOptions } }} [config]
307
304
  */
308
305
  export const makeAnchorAsset = async (
309
306
  {
@@ -348,18 +345,13 @@ export const makeAnchorAsset = async (
348
345
  }),
349
346
  );
350
347
 
351
- const { creatorFacet: mint, publicFacet: issuer } = /**
352
- * @type {{
353
- * creatorFacet: ERef<Mint<'nat'>>;
354
- * publicFacet: ERef<Issuer<'nat'>>;
355
- * }}
356
- */ (
357
- await E(startUpgradable)({
358
- installation: mintHolder,
359
- label: keyword,
360
- terms,
361
- })
362
- );
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
+ });
363
355
 
364
356
  const brand = await E(issuer).getBrand();
365
357
  const kit = harden({ mint, issuer, brand });
@@ -371,25 +363,23 @@ export const makeAnchorAsset = async (
371
363
  slotToBoardRemote,
372
364
  );
373
365
  const metricsKey = `${stablePsmKey}.${keyword}.metrics`;
374
- const maybeReviveMetrics = async () => {
375
- if (!toSlotReviver.has(metricsKey)) {
376
- return;
377
- }
366
+ if (toSlotReviver.has(metricsKey)) {
378
367
  const metrics = toSlotReviver.getItem(metricsKey);
379
368
  produceAnchorBalancePayments.resolve(
380
369
  makeScalarBigMapStore('Anchor balance payments', { durable: true }),
381
370
  );
382
371
  // XXX this rule should only apply to the 1st await
372
+ // eslint-disable-next-line @jessie.js/no-nested-await
383
373
  const anchorPaymentMap = await anchorBalancePayments;
384
374
 
385
375
  // TODO: validate that `metrics.anchorPoolBalance.value` is
386
376
  // pass-by-copy PureData (e.g., contains no remotables).
377
+ // eslint-disable-next-line @jessie.js/no-nested-await
387
378
  const pmt = await E(mint).mintPayment(
388
379
  AmountMath.make(brand, metrics.anchorPoolBalance.value),
389
380
  );
390
381
  anchorPaymentMap.init(brand, pmt);
391
- };
392
- await maybeReviveMetrics();
382
+ }
393
383
 
394
384
  await Promise.all([
395
385
  E(E(agoricNamesAdmin).lookupAdmin('issuer')).update(keyword, kit.issuer),
@@ -10,6 +10,7 @@ const { Fail } = assert;
10
10
  */
11
11
  export const reserveThenGetNamePaths = async (nameAdmin, paths) => {
12
12
  /**
13
+ *
13
14
  * @param {ERef<import('@agoric/vats').NameAdmin>} nextAdmin
14
15
  * @param {string[]} path
15
16
  */
@@ -53,7 +54,7 @@ export const reserveThenGetNames = async (nameAdmin, names) =>
53
54
  * @param {string} debugName
54
55
  * @param {ERef<import('@agoric/vats').NameAdmin>} namesByAddressAdmin
55
56
  * @param {string} addr
56
- * @param {ERef<Payment>[]} payments
57
+ * @param {Array<ERef<Payment>>} payments
57
58
  */
58
59
  export const reserveThenDeposit = async (
59
60
  debugName,
@@ -78,15 +79,7 @@ export const reserveThenDeposit = async (
78
79
  );
79
80
  };
80
81
 
81
- /**
82
- * @type {<T>(
83
- * store: ERef<
84
- * Map<string, T> | import('@agoric/internal/src/scratch.js').ScratchPad
85
- * >,
86
- * key: string,
87
- * make: () => T,
88
- * ) => Promise<T>}
89
- */
82
+ /** @type {<T>(store: ERef<Map<string, T> | import('@agoric/internal/src/scratch.js').ScratchPad>, key: string, make: () => T) => Promise<T>} */
90
83
  const provideWhen = async (store, key, make) => {
91
84
  const found = await E(store).get(key);
92
85
  if (found) {
@@ -98,33 +91,21 @@ const provideWhen = async (store, key, make) => {
98
91
  };
99
92
 
100
93
  /**
101
- * @param {{
102
- * scratch: ERef<import('@agoric/internal/src/scratch.js').ScratchPad>;
103
- * }} homeP
94
+ * @param {{ scratch: ERef<import('@agoric/internal/src/scratch.js').ScratchPad> }} homeP
104
95
  * @param {object} opts
105
- * @param {(specifier: string) => Promise<{ default: Bundle }>} opts.loadBundle
96
+ * @param {(specifier: string) => Promise<{default: Bundle}>} opts.loadBundle
106
97
  * @param {string} [opts.installCacheKey]
107
98
  */
108
99
  export const makeInstallCache = async (
109
100
  homeP,
110
101
  { installCacheKey = 'installCache', loadBundle },
111
102
  ) => {
112
- /**
113
- * @type {CopyMap<
114
- * string,
115
- * { installation: Installation; boardId: string; path?: string }
116
- * >}
117
- */
103
+ /** @type {CopyMap<string, {installation: Installation, boardId: string, path?: string}>} */
118
104
  const initial = await provideWhen(E.get(homeP).scratch, installCacheKey, () =>
119
105
  makeCopyMap([]),
120
106
  );
121
107
  // ISSUE: getCopyMapEntries of CopyMap<K, V> loses K, V.
122
- /**
123
- * @type {Map<
124
- * string,
125
- * { installation: Installation; boardId: string; path?: string }
126
- * >}
127
- */
108
+ /** @type {Map<string, {installation: Installation, boardId: string, path?: string}>} */
128
109
  const working = new Map(getCopyMapEntries(initial));
129
110
 
130
111
  const saveCache = async () => {
package/src/psm/psm.js CHANGED
@@ -41,86 +41,80 @@ const { Fail } = assert;
41
41
 
42
42
  /**
43
43
  * @file The Parity Stability Module supports efficiently minting/burning a
44
- * stable token at a specified fixed ratio to a reference stable token, which
45
- * thereby acts as an anchor to provide additional stability. For flexible
46
- * economic policies, the fee percentage for trading into and out of the
47
- * stable token are specified separately.
44
+ * stable token at a specified fixed ratio to a reference stable token, which
45
+ * thereby acts as an anchor to provide additional stability. For flexible
46
+ * economic policies, the fee percentage for trading into and out of the stable
47
+ * token are specified separately.
48
48
  */
49
49
 
50
50
  /**
51
- * @typedef {object} MetricsNotification Metrics naming scheme is that nouns are
52
- * present values and past-participles are accumulative.
53
- * @property {Amount<'nat'>} anchorPoolBalance amount of Anchor token available
54
- * to be swapped
55
- * @property {Amount<'nat'>} mintedPoolBalance amount of Minted token
56
- * outstanding (the amount minted minus the amount burned).
57
- * @property {Amount<'nat'>} feePoolBalance amount of Minted token fees
58
- * available to be collected
59
- * @property {Amount<'nat'>} totalAnchorProvided running sum of Anchor ever
60
- * given by this contract
61
- * @property {Amount<'nat'>} totalMintedProvided running sum of Minted ever
62
- * given by this contract
51
+ * @typedef {object} MetricsNotification
52
+ * Metrics naming scheme is that nouns are present values and past-participles
53
+ * are accumulative.
54
+ *
55
+ * @property {Amount<'nat'>} anchorPoolBalance amount of Anchor token
56
+ * available to be swapped
57
+ * @property {Amount<'nat'>} mintedPoolBalance amount of Minted token
58
+ * outstanding (the amount minted minus the amount burned).
59
+ * @property {Amount<'nat'>} feePoolBalance amount of Minted token
60
+ * fees available to be collected
61
+ *
62
+ * @property {Amount<'nat'>} totalAnchorProvided running sum of Anchor
63
+ * ever given by this contract
64
+ * @property {Amount<'nat'>} totalMintedProvided running sum of Minted
65
+ * ever given by this contract
63
66
  */
64
67
 
65
68
  /** @typedef {import('@agoric/vat-data').Baggage} Baggage */
66
69
 
67
- /** @type {ContractMeta} */
68
- export const meta = {
69
- upgradability: 'canUpgrade',
70
- customTermsShape: {
71
- anchorBrand: BrandShape,
72
- anchorPerMinted: RatioShape,
73
- electionManager: InstanceHandleShape,
74
- governedParams: {
75
- [CONTRACT_ELECTORATE]: {
76
- type: ParamTypes.INVITATION,
77
- value: AmountShape,
78
- },
79
- WantMintedFee: {
80
- type: ParamTypes.RATIO,
81
- value: RatioShape,
82
- },
83
- GiveMintedFee: {
84
- type: ParamTypes.RATIO,
85
- value: RatioShape,
86
- },
87
- MintLimit: { type: ParamTypes.AMOUNT, value: AmountShape },
70
+ export const customTermsShape = {
71
+ anchorBrand: BrandShape,
72
+ anchorPerMinted: RatioShape,
73
+ electionManager: InstanceHandleShape,
74
+ governedParams: {
75
+ [CONTRACT_ELECTORATE]: {
76
+ type: ParamTypes.INVITATION,
77
+ value: AmountShape,
88
78
  },
89
- },
90
- privateArgsShape: M.splitRecord(
91
- {
92
- marshaller: M.remotable('Marshaller'),
93
- storageNode: StorageNodeShape,
79
+ WantMintedFee: {
80
+ type: ParamTypes.RATIO,
81
+ value: RatioShape,
94
82
  },
95
- {
96
- // only necessary on first invocation, not subsequent
97
- feeMintAccess: FeeMintAccessShape,
98
- initialPoserInvitation: InvitationShape,
83
+ GiveMintedFee: {
84
+ type: ParamTypes.RATIO,
85
+ value: RatioShape,
99
86
  },
100
- ),
87
+ MintLimit: { type: ParamTypes.AMOUNT, value: AmountShape },
88
+ },
101
89
  };
102
- harden(meta);
90
+ harden(customTermsShape);
91
+
92
+ export const privateArgsShape = M.splitRecord(
93
+ harden({
94
+ marshaller: M.remotable('Marshaller'),
95
+ storageNode: StorageNodeShape,
96
+ }),
97
+ harden({
98
+ // only necessary on first invocation, not subsequent
99
+ feeMintAccess: FeeMintAccessShape,
100
+ initialPoserInvitation: InvitationShape,
101
+ }),
102
+ );
103
+ harden(privateArgsShape);
103
104
 
104
105
  /**
105
- * @param {ZCF<
106
- * GovernanceTerms<{
107
- * GiveMintedFee: 'ratio';
108
- * WantMintedFee: 'ratio';
109
- * MintLimit: 'amount';
106
+ * @param {ZCF<GovernanceTerms<{
107
+ * GiveMintedFee: 'ratio',
108
+ * WantMintedFee: 'ratio',
109
+ * MintLimit: 'amount',
110
110
  * }> & {
111
- * anchorBrand: Brand<'nat'>;
112
- * anchorPerMinted: Ratio;
113
- * }
114
- * >} zcf
115
- * @param {{
116
- * feeMintAccess: FeeMintAccess;
117
- * initialPoserInvitation: Invitation;
118
- * storageNode: StorageNode;
119
- * marshaller: Marshaller;
120
- * }} privateArgs
111
+ * anchorBrand: Brand<'nat'>,
112
+ * anchorPerMinted: Ratio,
113
+ * }>} zcf
114
+ * @param {{feeMintAccess: FeeMintAccess, initialPoserInvitation: Invitation, storageNode: StorageNode, marshaller: Marshaller}} privateArgs
121
115
  * @param {Baggage} baggage
122
116
  */
123
- export const start = async (zcf, privateArgs, baggage) => {
117
+ export const prepare = async (zcf, privateArgs, baggage) => {
124
118
  const { anchorBrand, anchorPerMinted } = zcf.getTerms();
125
119
  console.log('PSM Starting', anchorBrand, anchorPerMinted);
126
120
 
@@ -237,7 +231,9 @@ export const start = async (zcf, privateArgs, baggage) => {
237
231
  updateMetrics();
238
232
  };
239
233
 
240
- /** @param {Amount<'nat'>} toMint */
234
+ /**
235
+ * @param {Amount<'nat'>} toMint
236
+ */
241
237
  const assertUnderLimit = toMint => {
242
238
  const mintedAfter = AmountMath.add(
243
239
  baggage.get('mintedPoolBalance'),
@@ -266,8 +262,7 @@ export const start = async (zcf, privateArgs, baggage) => {
266
262
  /**
267
263
  * @param {ZCFSeat} seat
268
264
  * @param {Amount<'nat'>} given
269
- * @param {Amount<'nat'>} [wanted] defaults to maximum anchor (given exchange
270
- * rate minus fees)
265
+ * @param {Amount<'nat'>} [wanted] defaults to maximum anchor (given exchange rate minus fees)
271
266
  */
272
267
  const giveMinted = (seat, given, wanted = emptyAnchor) => {
273
268
  const fee = ceilMultiplyBy(given, params.getGiveMintedFee());
@@ -445,6 +440,5 @@ export const start = async (zcf, privateArgs, baggage) => {
445
440
  publicFacet,
446
441
  });
447
442
  };
448
- harden(start);
449
443
 
450
- /** @typedef {Awaited<ReturnType<typeof start>>['publicFacet']} PsmPublicFacet */
444
+ /** @typedef {Awaited<ReturnType<typeof prepare>>['publicFacet']} PsmPublicFacet */
@@ -10,42 +10,36 @@ import { prepareAssetReserveKit } from './assetReserveKit.js';
10
10
 
11
11
  const trace = makeTracer('AR', true);
12
12
 
13
- /** @type {ContractMeta} */
14
- export const meta = {
15
- upgradability: 'canUpgrade',
16
- };
17
- harden(meta);
18
-
19
13
  /**
20
14
  * @typedef {{
21
- * increaseLiquidationShortfall: (increase: Amount) => void;
22
- * reduceLiquidationShortfall: (reduction: Amount) => void;
15
+ * increaseLiquidationShortfall: (increase: Amount) => void
16
+ * reduceLiquidationShortfall: (reduction: Amount) => void
23
17
  * }} ShortfallReportingFacet
24
18
  */
25
19
 
26
20
  /** @typedef {import('@agoric/vat-data').Baggage} Baggage */
27
21
 
28
22
  /**
29
- * Asset Reserve holds onto assets for the Inter Protocol, and can dispense it
30
- * for various purposes under governance control.
23
+ * Asset Reserve holds onto assets for the Inter Protocol, and can
24
+ * dispense it for various purposes under governance control.
31
25
  *
32
26
  * This contract has the ability to mint Fee tokens, granted through its private
33
27
  * arguments.
34
28
  *
35
- * @param {ZCF<
36
- * GovernanceTerms<{}> & {
37
- * governedApis: ['burnFeesToReduceShortfall'];
38
- * }
29
+ * @param {ZCF<GovernanceTerms<{}> &
30
+ * {
31
+ * governedApis: ['burnFeesToReduceShortfall'],
32
+ * }
39
33
  * >} zcf
40
34
  * @param {{
41
- * feeMintAccess: FeeMintAccess;
42
- * initialPoserInvitation: Invitation;
43
- * marshaller: ERef<Marshaller>;
44
- * storageNode: ERef<StorageNode>;
35
+ * feeMintAccess: FeeMintAccess,
36
+ * initialPoserInvitation: Invitation,
37
+ * marshaller: ERef<Marshaller>,
38
+ * storageNode: ERef<StorageNode>,
45
39
  * }} privateArgs
46
40
  * @param {Baggage} baggage
47
41
  */
48
- export const start = async (zcf, privateArgs, baggage) => {
42
+ export const prepare = async (zcf, privateArgs, baggage) => {
49
43
  trace('prepare', Object.keys(privateArgs), [...baggage.keys()]);
50
44
  // This contract mixes two styles of access to durable state. durableStores
51
45
  // are declared at the top level and referenced lexically. local state is
@@ -72,11 +66,11 @@ export const start = async (zcf, privateArgs, baggage) => {
72
66
  };
73
67
  trace('awaiting takeFeeMint');
74
68
  const feeMint = await takeFeeMint();
75
- const storageNode = await privateArgs.storageNode;
76
69
  const makeAssetReserveKit = await prepareAssetReserveKit(baggage, {
77
70
  feeMint,
78
71
  makeRecorderKit,
79
- storageNode,
72
+ // eslint-disable-next-line @jessie.js/no-nested-await -- spurious
73
+ storageNode: await privateArgs.storageNode,
80
74
  zcf,
81
75
  });
82
76
 
@@ -112,7 +106,7 @@ export const start = async (zcf, privateArgs, baggage) => {
112
106
  publicFacet: /** @type {any} */ (assetReserveKit.public),
113
107
  };
114
108
  };
115
- harden(start);
109
+ harden(prepare);
116
110
 
117
111
  /**
118
112
  * @typedef {object} ShortfallReporter
@@ -127,8 +121,5 @@ harden(start);
127
121
  * @property {() => Promise<Invitation<ShortfallReporter>>} makeShortfallReportingInvitation
128
122
  */
129
123
 
130
- /** @typedef {Awaited<ReturnType<typeof start>>['publicFacet']} AssetReservePublicFacet */
131
- /**
132
- * @typedef {Awaited<ReturnType<typeof start>>['creatorFacet']} AssetReserveCreatorFacet
133
- * the creator facet for the governor
134
- */
124
+ /** @typedef {Awaited<ReturnType<typeof prepare>>['publicFacet']} AssetReservePublicFacet */
125
+ /** @typedef {Awaited<ReturnType<typeof prepare>>['creatorFacet']} AssetReserveCreatorFacet the creator facet for the governor */
@@ -9,7 +9,7 @@ import {
9
9
  } from '@agoric/zoe/src/contractSupport/topics.js';
10
10
  import { AmountKeywordRecordShape } from '@agoric/zoe/src/typeGuards.js';
11
11
  import { E } from '@endo/eventual-send';
12
- import { UnguardedHelperI } from '@agoric/internal/src/typeGuards.js';
12
+ import { UnguardedHelperI } from '../typeGuards.js';
13
13
 
14
14
  const { quote: q } = assert;
15
15
 
@@ -17,6 +17,7 @@ const trace = makeTracer('ReserveKit', true);
17
17
 
18
18
  /**
19
19
  * @typedef {object} MetricsNotification
20
+ *
20
21
  * @property {AmountKeywordRecord} allocations
21
22
  * @property {Amount<'nat'>} shortfallBalance shortfall from liquidation that
22
23
  * has not yet been compensated.
@@ -27,11 +28,10 @@ const trace = makeTracer('ReserveKit', true);
27
28
  /**
28
29
  * @param {import('@agoric/vat-data').Baggage} baggage
29
30
  * @param {{
30
- * feeMint: ZCFMint<'nat'>;
31
- * makeRecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').MakeRecorderKit;
32
- * storageNode: StorageNode;
33
- * zcf: ZCF;
34
- * }} powers
31
+ * feeMint: ZCFMint<'nat'>,
32
+ * makeRecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').MakeRecorderKit,
33
+ * storageNode: StorageNode,
34
+ * zcf: ZCF}} powers
35
35
  */
36
36
  export const prepareAssetReserveKit = async (
37
37
  baggage,
@@ -63,7 +63,10 @@ export const prepareAssetReserveKit = async (
63
63
  reduceLiquidationShortfall: M.call(AmountShape).returns(),
64
64
  }),
65
65
  },
66
- /** @param {StorageNode} metricsNode */
66
+ /**
67
+ *
68
+ * @param {StorageNode} metricsNode
69
+ */
67
70
  metricsNode => {
68
71
  /**
69
72
  * Used to look up the unique keyword for each brand, including Fee brand.
@@ -74,8 +77,7 @@ export const prepareAssetReserveKit = async (
74
77
  durable: true,
75
78
  });
76
79
  /**
77
- * Used to look up the brands for keywords, excluding Fee because it's a
78
- * special case.
80
+ * Used to look up the brands for keywords, excluding Fee because it's a special case.
79
81
  *
80
82
  * @type {MapStore<Keyword, Brand>}
81
83
  */
@@ -135,6 +137,7 @@ export const prepareAssetReserveKit = async (
135
137
  },
136
138
  governedApis: {
137
139
  /**
140
+ *
138
141
  * @param {Amount<'nat'>} reduction
139
142
  * @returns {void}
140
143
  */
@@ -202,11 +205,12 @@ export const prepareAssetReserveKit = async (
202
205
  },
203
206
  },
204
207
  /**
205
- * XXX missing governance public methods
206
- * https://github.com/Agoric/agoric-sdk/issues/5200
208
+ * XXX missing governance public methods https://github.com/Agoric/agoric-sdk/issues/5200
207
209
  */
208
210
  public: {
209
- /** Anyone can deposit any assets to the reserve */
211
+ /**
212
+ * Anyone can deposit any assets to the reserve
213
+ */
210
214
  makeAddCollateralInvitation() {
211
215
  /** @type {OfferHandler<Promise<string>>} */
212
216
  const handler = async seat => {
@@ -243,7 +247,9 @@ export const prepareAssetReserveKit = async (
243
247
  },
244
248
  },
245
249
  shortfallReportingFacet: {
246
- /** @param {Amount<'nat'>} shortfall */
250
+ /**
251
+ * @param {Amount<"nat">} shortfall
252
+ */
247
253
  increaseLiquidationShortfall(shortfall) {
248
254
  const { facets, state } = this;
249
255
  state.shortfallBalance = AmountMath.add(
@@ -254,7 +260,9 @@ export const prepareAssetReserveKit = async (
254
260
  },
255
261
 
256
262
  // currently exposed for testing. Maybe it only gets called internally?
257
- /** @param {Amount<'nat'>} reduction */
263
+ /**
264
+ * @param {Amount<"nat">} reduction
265
+ */
258
266
  reduceLiquidationShortfall(reduction) {
259
267
  const { state } = this;
260
268
  if (AmountMath.isGTE(reduction, state.shortfallBalance)) {
@@ -0,0 +1,13 @@
1
+ // @jessie-check
2
+
3
+ import { M } from '@agoric/store';
4
+
5
+ /**
6
+ * To be used only for 'helper' facets where the calls are from trusted code.
7
+ */
8
+ export const UnguardedHelperI = M.interface(
9
+ 'helper',
10
+ {},
11
+ // not exposed so sloppy okay
12
+ { sloppy: true },
13
+ );
@@ -22,8 +22,7 @@ const makeCancelToken = makeCancelTokenMaker('liq');
22
22
 
23
23
  /**
24
24
  * This will normally be set. If the schedule goes sideways, we'll unschedule
25
- * all events and unset it. When auction params are changed, we'll restart the
26
- * schedule
25
+ * all events and unset it. When auction params are changed, we'll restart the schedule
27
26
  *
28
27
  * @type {object | undefined}
29
28
  */
@@ -48,16 +47,15 @@ const cancelWakeups = timer => {
48
47
  };
49
48
 
50
49
  /**
51
- * Schedule wakeups for the _next_ auction round.
50
+ * Schedule wakeups for the *next* auction round.
52
51
  *
53
- * In practice, there are these cases to handle (with N as "live" and N+1 is
54
- * "next"):
52
+ * In practice, there are these cases to handle (with N as "live" and N+1 is "next"):
55
53
  *
56
- * | when (now within the range) | what |
57
- * | ------------------------------- | ---------------------------------------- |
58
- * | [start N, nominalStart N+1] | good: schedule normally the three wakers |
59
- * | (nominalStart N+1, endTime N+1] | recover: skip round N+1 and schedule N+2 |
60
- * | (endTime N+1, ∞) | give up: wait for repair by governance |
54
+ * | when (now within the range) | what |
55
+ * | -------------------------------- | --------------------------------------- |
56
+ * | [start N, nominalStart N+1] | good: schedule normally the three wakers|
57
+ * | (nominalStart N+1, endTime N+1] | recover: skip round N+1 and schedule N+2|
58
+ * | (endTime N+1, ∞) | give up: wait for repair by governance |
61
59
  *
62
60
  * @param {object} opts
63
61
  * @param {ERef<TimerService>} opts.timer
@@ -134,7 +132,7 @@ const setWakeups = ({
134
132
  };
135
133
 
136
134
  /**
137
- * Schedule wakeups for the _next_ auction round.
135
+ * Schedule wakeups for the *next* auction round.
138
136
  *
139
137
  * Called by vaultDirector's resetWakeupsForNextAuction at start() and every
140
138
  * time there's a "reschedule" wakeup.
@@ -187,7 +185,7 @@ harden(setWakeupsForNextAuction);
187
185
  /**
188
186
  * @param {Amount<'nat'>} debt
189
187
  * @param {Amount<'nat'>} minted
190
- * @returns {{ overage: Amount<'nat'>; shortfall: Amount<'nat'> }}
188
+ * @returns {{ overage: Amount<'nat'>, shortfall: Amount<'nat'>}}
191
189
  */
192
190
  export const liquidationResults = (debt, minted) => {
193
191
  if (AmountMath.isEmpty(minted)) {
@@ -242,21 +240,15 @@ export const watchForGovernanceChange = (
242
240
  * @param {PriceQuote} collateralizationDetails.quote
243
241
  * @param {Ratio} collateralizationDetails.interest
244
242
  * @param {Ratio} collateralizationDetails.margin
245
- * @param {ReturnType<
246
- * typeof import('./prioritizedVaults.js').makePrioritizedVaults
247
- * >} prioritizedVaults
243
+ * @param {ReturnType<typeof import('./prioritizedVaults.js').makePrioritizedVaults>} prioritizedVaults
248
244
  * @param {SetStore<Vault>} liquidatingVaults
249
245
  * @param {Brand<'nat'>} debtBrand
250
246
  * @param {Brand<'nat'>} collateralBrand
251
247
  * @returns {{
252
- * vaultData: MapStore<
253
- * Vault,
254
- * { collateralAmount: Amount<'nat'>; debtAmount: Amount<'nat'> }
255
- * >;
256
- * totalDebt: Amount<'nat'>;
257
- * totalCollateral: Amount<'nat'>;
258
- * liqSeat: ZCFSeat;
259
- * }}
248
+ * vaultData: MapStore<Vault, { collateralAmount: Amount<'nat'>, debtAmount: Amount<'nat'>}>,
249
+ * totalDebt: Amount<'nat'>,
250
+ * totalCollateral: Amount<'nat'>,
251
+ * liqSeat: ZCFSeat}}
260
252
  */
261
253
  export const getLiquidatableVaults = (
262
254
  zcf,
@@ -269,18 +261,13 @@ export const getLiquidatableVaults = (
269
261
  const vaultsToLiquidate = prioritizedVaults.removeVaultsBelow(
270
262
  collateralizationDetails,
271
263
  );
272
- /**
273
- * @type {MapStore<
274
- * Vault,
275
- * { collateralAmount: Amount<'nat'>; debtAmount: Amount<'nat'> }
276
- * >}
277
- */
264
+ /** @type {MapStore<Vault, { collateralAmount: Amount<'nat'>, debtAmount: Amount<'nat'>}>} */
278
265
  const vaultData = makeScalarMapStore();
279
266
 
280
267
  const { zcfSeat: liqSeat } = zcf.makeEmptySeatKit();
281
268
  let totalDebt = AmountMath.makeEmpty(debtBrand);
282
269
  let totalCollateral = AmountMath.makeEmpty(collateralBrand);
283
- /** @type {TransferPart[]} */
270
+ /** @type {import('@agoric/zoe/src/contractSupport/atomicTransfer.js').TransferPart[]} */
284
271
  const transfers = [];
285
272
 
286
273
  for (const vault of vaultsToLiquidate.values()) {