@agoric/inter-protocol 0.16.2-dev-7cc5def.0 → 0.16.2-u11.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 (176) hide show
  1. package/CHANGELOG.md +1041 -0
  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 +222 -242
  5. package/bundles/bundle-econCommitteeCharter.js +1 -1
  6. package/bundles/bundle-feeDistributor-js-meta.json +458 -0
  7. package/bundles/bundle-feeDistributor.js +1 -0
  8. package/bundles/bundle-fluxAggregatorKit-js-meta.json +327 -343
  9. package/bundles/bundle-fluxAggregatorKit.js +1 -1
  10. package/bundles/bundle-psm-js-meta.json +308 -328
  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 -0
  14. package/bundles/bundle-scaledPriceAuthority-js-meta.json +542 -0
  15. package/bundles/bundle-scaledPriceAuthority.js +1 -0
  16. package/bundles/bundle-vaultFactory-js-meta.json +790 -0
  17. package/bundles/bundle-vaultFactory.js +1 -0
  18. package/package.json +31 -31
  19. package/scripts/add-collateral-core.js +112 -0
  20. package/scripts/build-bundles.js +21 -5
  21. package/scripts/deploy-contracts.js +100 -0
  22. package/scripts/init-core.js +198 -0
  23. package/scripts/invite-committee-core.js +42 -0
  24. package/scripts/manual-price-feed.js +117 -0
  25. package/scripts/price-feed-core.js +104 -0
  26. package/scripts/start-local-chain.sh +84 -0
  27. package/src/auction/auctionBook.js +56 -68
  28. package/src/auction/auctioneer.js +44 -56
  29. package/src/auction/offerBook.js +11 -12
  30. package/src/auction/params.js +5 -3
  31. package/src/auction/scheduleMath.js +13 -13
  32. package/src/auction/scheduler.js +32 -22
  33. package/src/auction/sortedOffers.js +7 -8
  34. package/src/auction/util.js +4 -4
  35. package/src/clientSupport.js +96 -152
  36. package/src/contractSupport.js +5 -5
  37. package/src/econCommitteeCharter.js +15 -16
  38. package/src/feeDistributor.js +33 -34
  39. package/src/interest.js +14 -20
  40. package/src/price/fluxAggregatorContract.js +45 -51
  41. package/src/price/fluxAggregatorKit.js +32 -47
  42. package/src/price/priceOracleKit.js +13 -11
  43. package/src/price/roundsManager.js +64 -52
  44. package/src/proposals/addAssetToVault.js +3 -15
  45. package/src/proposals/committee-proposal.js +9 -5
  46. package/src/proposals/core-proposal.js +7 -7
  47. package/src/proposals/econ-behaviors.js +32 -57
  48. package/src/proposals/price-feed-proposal.js +26 -59
  49. package/src/proposals/startEconCommittee.js +1 -1
  50. package/src/proposals/startPSM.js +22 -32
  51. package/src/proposals/utils.js +7 -26
  52. package/src/psm/psm.js +63 -69
  53. package/src/reserve/assetReserve.js +18 -27
  54. package/src/reserve/assetReserveKit.js +22 -14
  55. package/src/typeGuards.js +13 -0
  56. package/src/vaultFactory/liquidation.js +17 -30
  57. package/src/vaultFactory/math.js +9 -8
  58. package/src/vaultFactory/orderedVaultStore.js +9 -6
  59. package/src/vaultFactory/params.js +18 -24
  60. package/src/vaultFactory/prioritizedVaults.js +2 -2
  61. package/src/vaultFactory/proceeds.js +18 -24
  62. package/src/vaultFactory/storeUtils.js +12 -8
  63. package/src/vaultFactory/types.js +28 -38
  64. package/src/vaultFactory/vault.js +89 -88
  65. package/src/vaultFactory/vaultDirector.js +41 -33
  66. package/src/vaultFactory/vaultFactory.js +26 -33
  67. package/src/vaultFactory/vaultHolder.js +13 -8
  68. package/src/vaultFactory/vaultKit.js +2 -3
  69. package/src/vaultFactory/vaultManager.js +120 -138
  70. package/src/auction/auctionBook.d.ts +0 -83
  71. package/src/auction/auctionBook.d.ts.map +0 -1
  72. package/src/auction/auctioneer.d.ts +0 -75
  73. package/src/auction/auctioneer.d.ts.map +0 -1
  74. package/src/auction/offerBook.d.ts +0 -72
  75. package/src/auction/offerBook.d.ts.map +0 -1
  76. package/src/auction/params.d.ts +0 -142
  77. package/src/auction/params.d.ts.map +0 -1
  78. package/src/auction/scheduleMath.d.ts +0 -4
  79. package/src/auction/scheduleMath.d.ts.map +0 -1
  80. package/src/auction/scheduler.d.ts +0 -49
  81. package/src/auction/scheduler.d.ts.map +0 -1
  82. package/src/auction/sortedOffers.d.ts +0 -8
  83. package/src/auction/sortedOffers.d.ts.map +0 -1
  84. package/src/auction/util.d.ts +0 -30
  85. package/src/auction/util.d.ts.map +0 -1
  86. package/src/clientSupport.d.ts +0 -167
  87. package/src/clientSupport.d.ts.map +0 -1
  88. package/src/collectFees.d.ts +0 -2
  89. package/src/collectFees.d.ts.map +0 -1
  90. package/src/contractSupport.d.ts +0 -33
  91. package/src/contractSupport.d.ts.map +0 -1
  92. package/src/econCommitteeCharter.d.ts +0 -41
  93. package/src/econCommitteeCharter.d.ts.map +0 -1
  94. package/src/feeDistributor.d.ts +0 -212
  95. package/src/feeDistributor.d.ts.map +0 -1
  96. package/src/index.d.ts +0 -2
  97. package/src/index.d.ts.map +0 -1
  98. package/src/interest-math.d.ts +0 -3
  99. package/src/interest-math.d.ts.map +0 -1
  100. package/src/interest.d.ts +0 -29
  101. package/src/interest.d.ts.map +0 -1
  102. package/src/price/fluxAggregatorContract.d.ts +0 -112
  103. package/src/price/fluxAggregatorContract.d.ts.map +0 -1
  104. package/src/price/fluxAggregatorKit.d.ts +0 -155
  105. package/src/price/fluxAggregatorKit.d.ts.map +0 -1
  106. package/src/price/priceOracleKit.d.ts +0 -52
  107. package/src/price/priceOracleKit.d.ts.map +0 -1
  108. package/src/price/roundsManager.d.ts +0 -330
  109. package/src/price/roundsManager.d.ts.map +0 -1
  110. package/src/proposals/addAssetToVault.d.ts +0 -155
  111. package/src/proposals/addAssetToVault.d.ts.map +0 -1
  112. package/src/proposals/committee-proposal.d.ts +0 -121
  113. package/src/proposals/committee-proposal.d.ts.map +0 -1
  114. package/src/proposals/core-proposal.d.ts +0 -149
  115. package/src/proposals/core-proposal.d.ts.map +0 -1
  116. package/src/proposals/econ-behaviors.d.ts +0 -201
  117. package/src/proposals/econ-behaviors.d.ts.map +0 -1
  118. package/src/proposals/price-feed-proposal.d.ts +0 -83
  119. package/src/proposals/price-feed-proposal.d.ts.map +0 -1
  120. package/src/proposals/startEconCommittee.d.ts +0 -34
  121. package/src/proposals/startEconCommittee.d.ts.map +0 -1
  122. package/src/proposals/startPSM.d.ts +0 -61
  123. package/src/proposals/startPSM.d.ts.map +0 -1
  124. package/src/proposals/utils.d.ts +0 -15
  125. package/src/proposals/utils.d.ts.map +0 -1
  126. package/src/provisionPool.d.ts +0 -165
  127. package/src/provisionPool.d.ts.map +0 -1
  128. package/src/provisionPool.js +0 -119
  129. package/src/provisionPoolKit.d.ts +0 -379
  130. package/src/provisionPoolKit.d.ts.map +0 -1
  131. package/src/provisionPoolKit.js +0 -461
  132. package/src/psm/psm.d.ts +0 -178
  133. package/src/psm/psm.d.ts.map +0 -1
  134. package/src/psm/types.d.ts +0 -2
  135. package/src/psm/types.d.ts.map +0 -1
  136. package/src/reserve/assetReserve.d.ts +0 -44
  137. package/src/reserve/assetReserve.d.ts.map +0 -1
  138. package/src/reserve/assetReserveKit.d.ts +0 -114
  139. package/src/reserve/assetReserveKit.d.ts.map +0 -1
  140. package/src/reserve/params.d.ts +0 -10
  141. package/src/reserve/params.d.ts.map +0 -1
  142. package/src/tokens.d.ts +0 -3
  143. package/src/tokens.d.ts.map +0 -1
  144. package/src/tokens.js +0 -5
  145. package/src/vaultFactory/burn.d.ts +0 -2
  146. package/src/vaultFactory/burn.d.ts.map +0 -1
  147. package/src/vaultFactory/liquidation.d.ts +0 -24
  148. package/src/vaultFactory/liquidation.d.ts.map +0 -1
  149. package/src/vaultFactory/math.d.ts +0 -10
  150. package/src/vaultFactory/math.d.ts.map +0 -1
  151. package/src/vaultFactory/orderedVaultStore.d.ts +0 -94
  152. package/src/vaultFactory/orderedVaultStore.d.ts.map +0 -1
  153. package/src/vaultFactory/params.d.ts +0 -159
  154. package/src/vaultFactory/params.d.ts.map +0 -1
  155. package/src/vaultFactory/prioritizedVaults.d.ts +0 -279
  156. package/src/vaultFactory/prioritizedVaults.d.ts.map +0 -1
  157. package/src/vaultFactory/proceeds.d.ts +0 -34
  158. package/src/vaultFactory/proceeds.d.ts.map +0 -1
  159. package/src/vaultFactory/storeUtils.d.ts +0 -25
  160. package/src/vaultFactory/storeUtils.d.ts.map +0 -1
  161. package/src/vaultFactory/type-imports.d.ts +0 -2
  162. package/src/vaultFactory/type-imports.d.ts.map +0 -1
  163. package/src/vaultFactory/types.d.ts +0 -137
  164. package/src/vaultFactory/types.d.ts.map +0 -1
  165. package/src/vaultFactory/vault.d.ts +0 -529
  166. package/src/vaultFactory/vault.d.ts.map +0 -1
  167. package/src/vaultFactory/vaultDirector.d.ts +0 -560
  168. package/src/vaultFactory/vaultDirector.d.ts.map +0 -1
  169. package/src/vaultFactory/vaultFactory.d.ts +0 -162
  170. package/src/vaultFactory/vaultFactory.d.ts.map +0 -1
  171. package/src/vaultFactory/vaultHolder.d.ts +0 -201
  172. package/src/vaultFactory/vaultHolder.d.ts.map +0 -1
  173. package/src/vaultFactory/vaultKit.d.ts +0 -32
  174. package/src/vaultFactory/vaultKit.d.ts.map +0 -1
  175. package/src/vaultFactory/vaultManager.d.ts +0 -554
  176. package/src/vaultFactory/vaultManager.d.ts.map +0 -1
@@ -11,32 +11,27 @@ import { liquidationResults } from './liquidation.js';
11
11
 
12
12
  /**
13
13
  * @typedef {{
14
- * overage: Amount<'nat'>;
15
- * shortfallToReserve: Amount<'nat'>;
16
- * collateralForReserve: Amount<'nat'>;
17
- * actualCollateralSold: Amount<'nat'>;
18
- * collateralSold: Amount<'nat'>;
19
- * collatRemaining: Amount<'nat'>;
20
- * debtToBurn: Amount<'nat'>;
21
- * mintedForReserve: Amount<'nat'>;
22
- * mintedProceeds: Amount<'nat'>;
23
- * phantomDebt: Amount<'nat'>;
24
- * totalPenalty: Amount<'nat'>;
25
- * transfersToVault: [number, AmountKeywordRecord][];
26
- * vaultsToReinstate: number[];
14
+ * overage: Amount<'nat'>,
15
+ * shortfallToReserve: Amount<'nat'>,
16
+ * collateralForReserve: Amount<'nat'>,
17
+ * actualCollateralSold: Amount<'nat'>,
18
+ * collateralSold: Amount<'nat'>,
19
+ * collatRemaining: Amount<'nat'>,
20
+ * debtToBurn: Amount<'nat'>,
21
+ * mintedForReserve: Amount<'nat'>,
22
+ * mintedProceeds: Amount<'nat'>,
23
+ * phantomDebt: Amount<'nat'>,
24
+ * totalPenalty: Amount<'nat'>,
25
+ * transfersToVault: Array<[number, AmountKeywordRecord]>,
26
+ * vaultsToReinstate: Array<number>
27
27
  * }} DistributionPlan
28
- * The plan to execute for distributing proceeds of a liquidation.
29
28
  *
30
- * Vaults are referenced by index in the list sent to the calculator.
29
+ * The plan to execute for distributing proceeds of a liquidation.
30
+ *
31
+ * Vaults are referenced by index in the list sent to the calculator.
31
32
  */
32
33
 
33
- /**
34
- * @typedef {{
35
- * collateral: Amount<'nat'>;
36
- * presaleDebt: Amount<'nat'>;
37
- * currentDebt: Amount<'nat'>;
38
- * }} VaultBalances
39
- */
34
+ /** @typedef {{ collateral: Amount<'nat'>, presaleDebt: Amount<'nat'>, currentDebt: Amount<'nat'> }} VaultBalances */
40
35
 
41
36
  /**
42
37
  * Liquidation.md describes how to process liquidation proceeds.
@@ -51,8 +46,7 @@ import { liquidationResults } from './liquidation.js';
51
46
  * @param {Amount<'nat'>} inputs.totalDebt
52
47
  * @param {Amount<'nat'>} inputs.totalCollateral
53
48
  * @param {PriceDescription} inputs.oraclePriceAtStart
54
- * @param {VaultBalances[]} inputs.vaultsBalances ordered best to worst
55
- * collateralized
49
+ * @param {Array<VaultBalances>} inputs.vaultsBalances ordered best to worst collateralized
56
50
  * @param {Ratio} inputs.penaltyRate
57
51
  * @returns {DistributionPlan}
58
52
  */
@@ -19,9 +19,13 @@ const { multiply } = natSafeMath;
19
19
 
20
20
  const trace = makeTracer('Store', true);
21
21
 
22
- /** @typedef {import('@endo/marshal').PureData} PureData */
22
+ /**
23
+ * @typedef {import('@endo/marshal').PureData} PureData
24
+ */
23
25
 
24
- /** @typedef {[normalizedCollateralization: number, vaultId: VaultId]} CompositeKey */
26
+ /**
27
+ * @typedef {[normalizedCollateralization: number, vaultId: VaultId]} CompositeKey
28
+ */
25
29
 
26
30
  // `makeEncodePassable` has three named options:
27
31
  // `encodeRemotable`, `encodeError`, and `encodePromise`.
@@ -65,12 +69,12 @@ const decodeNumber = encoded => {
65
69
  };
66
70
 
67
71
  // Type annotations to support static testing of amount values
68
- /** @typedef {Amount<'nat'> & { normalized: true }} NormalizedDebt */
69
- /** @typedef {Amount<'nat'> & { normalized: false }} ActualDebt */
72
+ /** @typedef {Amount<'nat'> & {normalized: true}} NormalizedDebt */
73
+ /** @typedef {Amount<'nat'> & {normalized: false}} ActualDebt */
70
74
 
71
75
  /**
72
- * Overcollateralized are greater than one. The more undercollaterized the
73
- * smaller in [0-1].
76
+ * Overcollateralized are greater than one.
77
+ * The more undercollaterized the smaller in [0-1].
74
78
  *
75
79
  * @param {NormalizedDebt} normalizedDebt normalized (not actual) total debt
76
80
  * @param {Amount<'nat'>} collateral
@@ -91,7 +95,7 @@ const collateralizationRatio = (normalizedDebt, collateral) => {
91
95
  * @param {Amount<'nat'>} collateral
92
96
  * @param {VaultId} vaultId
93
97
  * @returns {string} lexically sortable string in which highest
94
- * debt-to-collateral is earliest
98
+ * debt-to-collateral is earliest
95
99
  */
96
100
  export const toVaultKey = (normalizedDebt, collateral, vaultId) => {
97
101
  assert(normalizedDebt);
@@ -158,7 +162,7 @@ harden(normalizedCollRatio);
158
162
  * @param {Ratio} compoundedInterest
159
163
  * @param {Ratio} margin
160
164
  * @returns {string} lexically sortable string in which highest
161
- * debt-to-collateral is earliest
165
+ * debt-to-collateral is earliest
162
166
  */
163
167
  export const normalizedCollRatioKey = (quote, compoundedInterest, margin) => {
164
168
  const collRatio = normalizedCollRatio(quote, compoundedInterest, margin);
@@ -2,30 +2,21 @@
2
2
 
3
3
  /**
4
4
  * @typedef {import('./vault').VaultNotification} VaultNotification
5
- *
6
5
  * @typedef {import('./vault').Vault} Vault
7
- *
8
6
  * @typedef {import('./vaultKit').VaultKit} VaultKit
9
- *
10
7
  * @typedef {import('./vaultManager').VaultManager} VaultManager
11
- *
12
8
  * @typedef {import('./vaultManager').CollateralManager} CollateralManager
13
- *
14
9
  * @typedef {import('../reserve/assetReserve.js').AssetReserveLimitedCreatorFacet} AssetReserveCreatorFacet
15
- *
16
10
  * @typedef {import('../reserve/assetReserve.js').AssetReservePublicFacet} AssetReservePublicFacet
17
- *
18
11
  * @typedef {import('../auction/auctioneer.js').AuctioneerPublicFacet} AuctioneerPublicFacet
19
- *
20
12
  * @typedef {import('./vaultFactory.js').VaultFactoryContract['publicFacet']} VaultFactoryPublicFacet
21
13
  *
22
14
  * @typedef {import('@agoric/time/src/types').Timestamp} Timestamp
23
- *
24
15
  * @typedef {import('@agoric/time/src/types').RelativeTime} RelativeTime
25
16
  */
26
17
 
27
18
  /**
28
- * @typedef {object} AutoswapLocal
19
+ * @typedef {object} AutoswapLocal
29
20
  * @property {(amount: Amount, brand: Brand) => Amount} getInputPrice
30
21
  * @property {() => Invitation} makeSwapInvitation
31
22
  */
@@ -33,16 +24,13 @@
33
24
  /**
34
25
  * @typedef {object} VaultManagerParamValues
35
26
  * @property {Ratio} liquidationMargin - margin below which collateral will be
36
- * liquidated to satisfy the debt.
37
- * @property {Ratio} liquidationPenalty - penalty charged upon liquidation as
38
- * proportion of debt
39
- * @property {Ratio} interestRate - annual interest rate charged on debt
40
- * positions
41
- * @property {Ratio} mintFee - The fee (in BasisPoints) charged when creating or
42
- * increasing a debt position.
27
+ * liquidated to satisfy the debt.
28
+ * @property {Ratio} liquidationPenalty - penalty charged upon liquidation as proportion of debt
29
+ * @property {Ratio} interestRate - annual interest rate charged on debt positions
30
+ * @property {Ratio} mintFee - The fee (in BasisPoints) charged when creating
31
+ * or increasing a debt position.
43
32
  * @property {Amount<'nat'>} debtLimit
44
- * @property {Ratio} [liquidationPadding] - vault must maintain this in order to
45
- * remove collateral or add debt
33
+ * @property {Ratio} [liquidationPadding] - vault must maintain this in order to remove collateral or add debt
46
34
  */
47
35
 
48
36
  /**
@@ -54,7 +42,7 @@
54
42
  */
55
43
 
56
44
  /**
57
- * @typedef {object} VaultFactoryCreatorFacet
45
+ * @typedef {object} VaultFactoryCreatorFacet
58
46
  * @property {AddVaultType} addVaultType
59
47
  * @property {() => Allocation} getRewardAllocation
60
48
  * @property {() => Promise<Invitation<string, never>>} makeCollectFeesInvitation
@@ -63,20 +51,23 @@
63
51
  */
64
52
 
65
53
  /**
66
- * @callback MintAndTransfer Mint new debt `toMint` and transfer the `fee`
67
- * portion to the vaultFactory's reward pool. Then reallocate over all the
68
- * seat arguments and the rewardPoolSeat. Update the `totalDebt` if the
69
- * reallocate succeeds.
54
+ * @callback MintAndTransfer
55
+ * Mint new debt `toMint` and transfer the `fee` portion to the vaultFactory's reward
56
+ * pool. Then reallocate over all the seat arguments and the rewardPoolSeat. Update
57
+ * the `totalDebt` if the reallocate succeeds.
70
58
  * @param {ZCFSeat} mintReceiver
71
59
  * @param {Amount<'nat'>} toMint
72
60
  * @param {Amount<'nat'>} fee
73
- * @param {TransferPart[]} transfers
61
+ * @param {import('@agoric/zoe/src/contractSupport/atomicTransfer.js').TransferPart[]} transfers
74
62
  * @returns {void}
75
63
  */
76
64
 
77
65
  /**
78
- * @callback BurnDebt Burn debt tokens off a seat and update the `totalDebt` if
79
- * the reallocate succeeds.
66
+ * @callback BurnDebt
67
+ *
68
+ * Burn debt tokens off a seat and update
69
+ * the `totalDebt` if the reallocate succeeds.
70
+ *
80
71
  * @param {Amount} toBurn
81
72
  * @param {ZCFSeat} fromSeat
82
73
  * @returns {void}
@@ -87,15 +78,16 @@
87
78
  * @property {() => Ratio} getLiquidationMargin
88
79
  * @property {() => Ratio} getMintFee
89
80
  * @property {() => Promise<PriceQuote>} getCollateralQuote
90
- * @property {() => Ratio} getInterestRate - The annual interest rate on a debt
91
- * position
81
+ * @property {() => Ratio} getInterestRate - The annual interest rate on a debt position
92
82
  * @property {() => RelativeTime} getChargingPeriod - The period (in seconds) at
93
83
  * which interest is charged to the debt position.
94
84
  * @property {() => RelativeTime} getRecordingPeriod - The period (in seconds)
95
85
  * at which interest is recorded to the debt position.
96
86
  */
97
87
 
98
- /** @typedef {string} VaultId */
88
+ /**
89
+ * @typedef {string} VaultId
90
+ */
99
91
 
100
92
  /**
101
93
  * @typedef {object} InterestTiming
@@ -112,9 +104,7 @@
112
104
 
113
105
  /**
114
106
  * @typedef {object} Liquidator
115
- * @property {() => Promise<
116
- * Invitation<void, { debt: Amount<'nat'>; penaltyRate: Ratio }>
117
- * >} makeLiquidateInvitation
107
+ * @property {() => Promise<Invitation<void, { debt: Amount<'nat'>; penaltyRate: Ratio; }>>} makeLiquidateInvitation
118
108
  */
119
109
 
120
110
  /**
@@ -134,11 +124,11 @@
134
124
  /**
135
125
  * @typedef {object} CalculatorKit
136
126
  * @property {Calculate} calculate calculate new debt for charging periods up to
137
- * the present.
127
+ * the present.
138
128
  * @property {Calculate} calculateReportingPeriod calculate new debt for
139
- * reporting periods up to the present. If some charging periods have elapsed
140
- * that don't constitute whole reporting periods, the time is not updated past
141
- * them and interest is not accumulated for them.
129
+ * reporting periods up to the present. If some charging periods have elapsed
130
+ * that don't constitute whole reporting periods, the time is not updated past
131
+ * them and interest is not accumulated for them.
142
132
  */
143
133
 
144
- /** @typedef {{ key: 'governedParams' | { collateralBrand: Brand } }} VaultFactoryParamPath */
134
+ /** @typedef {{key: 'governedParams' | {collateralBrand: Brand}}} VaultFactoryParamPath */
@@ -1,6 +1,5 @@
1
1
  import { AmountMath, AmountShape } from '@agoric/ertp';
2
- import { StorageNodeShape, makeTracer } from '@agoric/internal';
3
- import { UnguardedHelperI } from '@agoric/internal/src/typeGuards.js';
2
+ import { makeTracer, StorageNodeShape } from '@agoric/internal';
4
3
  import { M, prepareExoClassKit } from '@agoric/vat-data';
5
4
  import { atomicTransfer } from '@agoric/zoe/src/contractSupport/index.js';
6
5
  import { SeatShape } from '@agoric/zoe/src/typeGuards.js';
@@ -10,10 +9,11 @@ import {
10
9
  makeNatAmountShape,
11
10
  } from '../contractSupport.js';
12
11
  import { calculateCurrentDebt, reverseInterest } from '../interest-math.js';
13
- import { calculateDebtCosts } from './math.js';
12
+ import { UnguardedHelperI } from '../typeGuards.js';
14
13
  import { prepareVaultKit } from './vaultKit.js';
15
14
 
16
15
  import '@agoric/zoe/exported.js';
16
+ import { calculateDebtCosts } from './math.js';
17
17
 
18
18
  const { quote: q, Fail } = assert;
19
19
 
@@ -22,36 +22,31 @@ const trace = makeTracer('Vault', true);
22
22
  /** @typedef {import('./storeUtils.js').NormalizedDebt} NormalizedDebt */
23
23
 
24
24
  /**
25
- * @file This has most of the logic for a Vault, to borrow Minted against
26
- * collateral.
25
+ * @file This has most of the logic for a Vault, to borrow Minted against collateral.
27
26
  *
28
- * The logic here is for Vault which is the majority of logic of vaults but the
29
- * user view is the `vault` value contained in VaultKit.
27
+ * The logic here is for Vault which is the majority of logic of vaults but
28
+ * the user view is the `vault` value contained in VaultKit.
30
29
  *
31
- * A note on naming convention:
32
- *
33
- * - `Pre` is used as a postfix for any mutable value retrieved _before_ an
34
- * `await`, to flag values that must used very carefully after the
35
- * `await`
36
- * - `new` is a prefix for values that describe the result of executing a
37
- * transaction; e.g., `debt` is the value before the txn, and `newDebt`
38
- * will be value if the txn completes.
39
- * - the absence of one of these implies the opposite, so `newDebt` is the future
40
- * value fo `debt`, as computed based on values after any `await`
30
+ * A note on naming convention:
31
+ * - `Pre` is used as a postfix for any mutable value retrieved *before* an
32
+ * `await`, to flag values that must used very carefully after the `await`
33
+ * - `new` is a prefix for values that describe the result of executing a
34
+ * transaction; e.g., `debt` is the value before the txn, and `newDebt`
35
+ * will be value if the txn completes.
36
+ * - the absence of one of these implies the opposite, so `newDebt` is the
37
+ * future value fo `debt`, as computed based on values after any `await`
41
38
  */
42
39
 
43
40
  /**
44
41
  * Constants for vault phase.
45
42
  *
46
- * - ACTIVE - vault is in use and can be changed
47
- * - LIQUIDATING - vault is being liquidated by the vault manager, and cannot be
48
- * changed by the user. If liquidation fails, vaults may remain in this state.
49
- * An upgrade to the contract might be able to recover them.
50
- * - TRANSFER - vault is able to be transferred (payments and debits frozen until
51
- * it has a new owner)
52
- * - CLOSED - vault was closed by the user and all assets have been paid out
53
- * - LIQUIDATED - vault was closed by the manager, with remaining assets paid to
54
- * owner
43
+ * ACTIVE - vault is in use and can be changed
44
+ * LIQUIDATING - vault is being liquidated by the vault manager, and cannot be changed by the user.
45
+ * If liquidation fails, vaults may remain in this state. An upgrade to the contract
46
+ * might be able to recover them.
47
+ * TRANSFER - vault is able to be transferred (payments and debits frozen until it has a new owner)
48
+ * CLOSED - vault was closed by the user and all assets have been paid out
49
+ * LIQUIDATED - vault was closed by the manager, with remaining assets paid to owner
55
50
  */
56
51
  export const Phase = /** @type {const} */ ({
57
52
  ACTIVE: 'active',
@@ -63,7 +58,7 @@ export const Phase = /** @type {const} */ ({
63
58
 
64
59
  /**
65
60
  * @typedef {Phase[keyof Omit<typeof Phase, 'TRANSFER'>]} VaultPhase
66
- * @type {{ [K in VaultPhase]: VaultPhase[] }}
61
+ * @type {{[K in VaultPhase]: Array<VaultPhase>}}
67
62
  */
68
63
  const validTransitions = {
69
64
  [Phase.ACTIVE]: [Phase.LIQUIDATING, Phase.CLOSED],
@@ -77,8 +72,7 @@ const validTransitions = {
77
72
  *
78
73
  * @typedef {object} VaultNotification
79
74
  * @property {Amount<'nat'>} locked Amount of Collateral locked
80
- * @property {{ debt: Amount<'nat'>; interest: Ratio }} debtSnapshot 'debt' at
81
- * the point the compounded interest was 'interest'
75
+ * @property {{debt: Amount<'nat'>, interest: Ratio}} debtSnapshot 'debt' at the point the compounded interest was 'interest'
82
76
  * @property {HolderPhase} vaultState
83
77
  */
84
78
 
@@ -93,36 +87,27 @@ const validTransitions = {
93
87
  * @property {MintAndTransfer} mintAndTransfer
94
88
  * @property {(amount: Amount, seat: ZCFSeat) => void} burn
95
89
  * @property {() => Ratio} getCompoundedInterest
96
- * @property {(
97
- * oldDebt: import('./storeUtils.js').NormalizedDebt,
98
- * oldCollateral: Amount<'nat'>,
99
- * vaultId: VaultId,
100
- * vaultPhase: VaultPhase,
101
- * vault: Vault,
102
- * ) => void} handleBalanceChange
90
+ * @property {(oldDebt: import('./storeUtils.js').NormalizedDebt, oldCollateral: Amount<'nat'>, vaultId: VaultId, vaultPhase: VaultPhase, vault: Vault) => void} handleBalanceChange
103
91
  * @property {() => import('./vaultManager.js').GovernedParamGetters} getGovernedParams
104
92
  */
105
93
 
106
94
  /**
107
95
  * @typedef {Readonly<{
108
- * idInManager: VaultId;
109
- * manager: VaultManager;
110
- * storageNode: StorageNode;
111
- * vaultSeat: ZCFSeat;
96
+ * idInManager: VaultId,
97
+ * manager: VaultManager,
98
+ * storageNode: StorageNode,
99
+ * vaultSeat: ZCFSeat,
112
100
  * }>} ImmutableState
113
101
  */
114
102
 
115
103
  /**
116
- * Snapshot is of the debt and compounded interest when the principal was last
117
- * changed.
104
+ * Snapshot is of the debt and compounded interest when the principal was last changed.
118
105
  *
119
106
  * @typedef {{
120
- * interestSnapshot: Ratio;
121
- * phase: VaultPhase;
122
- * debtSnapshot: Amount<'nat'>;
123
- * outerUpdater:
124
- * | import('@agoric/zoe/src/contractSupport/recorder.js').Recorder<VaultNotification>
125
- * | null;
107
+ * interestSnapshot: Ratio,
108
+ * phase: VaultPhase,
109
+ * debtSnapshot: Amount<'nat'>,
110
+ * outerUpdater: import('@agoric/zoe/src/contractSupport/recorder.js').Recorder<VaultNotification> | null,
126
111
  * }} MutableState
127
112
  */
128
113
 
@@ -210,10 +195,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
210
195
  return AmountMath.makeEmpty(this.facets.helper.debtBrand());
211
196
  },
212
197
  /**
213
- * @typedef {{
214
- * give: { Collateral: Amount<'nat'>; Minted: Amount<'nat'> };
215
- * want: { Collateral: Amount<'nat'>; Minted: Amount<'nat'> };
216
- * }} FullProposal
198
+ * @typedef {{ give: { Collateral: Amount<'nat'>, Minted: Amount<'nat'> }, want: { Collateral: Amount<'nat'>, Minted: Amount<'nat'> } }} FullProposal
217
199
  */
218
200
  /**
219
201
  * @param {ProposalRecord} partial
@@ -238,7 +220,9 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
238
220
  //#endregion
239
221
 
240
222
  //#region Phase logic
241
- /** @param {VaultPhase} newPhase */
223
+ /**
224
+ * @param {VaultPhase} newPhase
225
+ */
242
226
  assignPhase(newPhase) {
243
227
  const { state } = this;
244
228
 
@@ -277,14 +261,12 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
277
261
  },
278
262
 
279
263
  /**
280
- * Update the debt balance and propagate upwards to maintain aggregate
281
- * debt and liquidation order.
264
+ * Update the debt balance and propagate upwards to
265
+ * maintain aggregate debt and liquidation order.
282
266
  *
283
- * @param {NormalizedDebt} oldDebtNormalized - prior principal and all
284
- * accrued interest, normalized to the launch of the vaultManager
267
+ * @param {NormalizedDebt} oldDebtNormalized - prior principal and all accrued interest, normalized to the launch of the vaultManager
285
268
  * @param {Amount<'nat'>} oldCollateral - actual collateral
286
- * @param {Amount<'nat'>} newDebtActual - actual principal and all
287
- * accrued interest
269
+ * @param {Amount<'nat'>} newDebtActual - actual principal and all accrued interest
288
270
  */
289
271
  updateDebtAccounting(oldDebtNormalized, oldCollateral, newDebtActual) {
290
272
  const { state, facets } = this;
@@ -300,7 +282,10 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
300
282
  );
301
283
  },
302
284
 
303
- /** @param {ZCFSeat} seat */
285
+ /**
286
+ *
287
+ * @param {ZCFSeat} seat
288
+ */
304
289
  getCollateralAllocated(seat) {
305
290
  return seat.getAmountAllocated(
306
291
  'Collateral',
@@ -322,6 +307,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
322
307
  },
323
308
 
324
309
  /**
310
+ *
325
311
  * @param {Amount<'nat'>} collateralAmount
326
312
  * @param {Amount<'nat'>} proposedDebt
327
313
  */
@@ -334,7 +320,10 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
334
320
  )} for ${q(collateralAmount)} collateral`;
335
321
  },
336
322
 
337
- /** @param {HolderPhase} newPhase */
323
+ /**
324
+ *
325
+ * @param {HolderPhase} newPhase
326
+ */
338
327
  getStateSnapshot(newPhase) {
339
328
  const { state, facets } = this;
340
329
 
@@ -349,7 +338,9 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
349
338
  });
350
339
  },
351
340
 
352
- /** call this whenever anything changes! */
341
+ /**
342
+ * call this whenever anything changes!
343
+ */
353
344
  updateUiState() {
354
345
  const { state, facets } = this;
355
346
  const { outerUpdater } = state;
@@ -377,7 +368,9 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
377
368
  }
378
369
  },
379
370
 
380
- /** @param {ZCFSeat} seat */
371
+ /**
372
+ * @param {ZCFSeat} seat
373
+ */
381
374
  async closeHook(seat) {
382
375
  const { state, facets } = this;
383
376
 
@@ -447,11 +440,11 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
447
440
  },
448
441
 
449
442
  /**
450
- * Calculate the fee, the amount to mint and the resulting debt. The
451
- * give and the want together reflect a delta, where typically one is
452
- * zero because they come from the gave/want of an offer proposal. If
453
- * the `want` is zero, the `fee` will also be zero, so the simple math
454
- * works.
443
+ * Calculate the fee, the amount to mint and the resulting debt.
444
+ * The give and the want together reflect a delta, where typically
445
+ * one is zero because they come from the gave/want of an offer
446
+ * proposal. If the `want` is zero, the `fee` will also be zero,
447
+ * so the simple math works.
455
448
  *
456
449
  * @param {Amount<'nat'>} currentDebt
457
450
  * @param {Amount<'nat'>} giveAmount
@@ -529,6 +522,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
529
522
  },
530
523
 
531
524
  /**
525
+ *
532
526
  * @param {ZCFSeat} clientSeat
533
527
  * @param {FullProposal} fp
534
528
  * @param {ReturnType<typeof calculateDebtCosts>} costs
@@ -549,7 +543,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
549
543
 
550
544
  const giveMintedTaken = AmountMath.subtract(fp.give.Minted, surplus);
551
545
 
552
- /** @type {TransferPart[]} */
546
+ /** @type {import('@agoric/zoe/src/contractSupport/atomicTransfer.js').TransferPart[]} */
553
547
  const transfers = harden([
554
548
  [clientSeat, vaultSeat, { Collateral: fp.give.Collateral }],
555
549
  [vaultSeat, clientSeat, { Collateral: fp.want.Collateral }],
@@ -574,6 +568,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
574
568
  },
575
569
 
576
570
  /**
571
+ *
577
572
  * @param {ZCFSeat} seat
578
573
  * @returns {VaultKit}
579
574
  */
@@ -674,7 +669,9 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
674
669
  return vaultKit;
675
670
  },
676
671
 
677
- /** Called by manager at start of liquidation. */
672
+ /**
673
+ * Called by manager at start of liquidation.
674
+ */
678
675
  liquidating() {
679
676
  const { facets } = this;
680
677
 
@@ -684,8 +681,8 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
684
681
  },
685
682
 
686
683
  /**
687
- * Called by manager at end of liquidation, at which point all debts
688
- * have been covered.
684
+ * Called by manager at end of liquidation, at which point all debts have been
685
+ * covered.
689
686
  */
690
687
  liquidated() {
691
688
  const { facets } = this;
@@ -777,7 +774,9 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
777
774
  );
778
775
  },
779
776
 
780
- /** @returns {Promise<Invitation>} */
777
+ /**
778
+ * @returns {Promise<Invitation>}
779
+ */
781
780
  makeTransferInvitation() {
782
781
  const { state, facets } = this;
783
782
  const { outerUpdater } = state;
@@ -809,7 +808,10 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
809
808
 
810
809
  // for status/debugging
811
810
 
812
- /** @returns {Amount<'nat'>} */
811
+ /**
812
+ *
813
+ * @returns {Amount<'nat'>}
814
+ */
813
815
  getCollateralAmount() {
814
816
  const { state, facets } = this;
815
817
  const { vaultSeat } = state;
@@ -823,15 +825,15 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
823
825
  /**
824
826
  * The actual current debt, including accrued interest.
825
827
  *
826
- * This looks like a simple getter but it does a lot of the heavy
827
- * lifting for interest accrual. Rather than updating all records when
828
- * interest accrues, the vault manager updates just its rolling
829
- * compounded interest. Here we calculate what the current debt is given
830
- * what's recorded in this vault and what interest has compounded since
831
- * this vault record was written.
828
+ * This looks like a simple getter but it does a lot of the heavy lifting for
829
+ * interest accrual. Rather than updating all records when interest accrues,
830
+ * the vault manager updates just its rolling compounded interest. Here we
831
+ * calculate what the current debt is given what's recorded in this vault and
832
+ * what interest has compounded since this vault record was written.
832
833
  *
833
- * @returns {Amount<'nat'>}
834
834
  * @see getNormalizedDebt
835
+ *
836
+ * @returns {Amount<'nat'>}
835
837
  */
836
838
  getCurrentDebt() {
837
839
  const { state } = this;
@@ -843,15 +845,14 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
843
845
  },
844
846
 
845
847
  /**
846
- * The normalization puts all debts on a common time-independent scale
847
- * since the launch of this vault manager. This allows the manager to
848
- * order vaults by their debt-to-collateral ratios without having to
849
- * mutate the debts as the interest accrues.
848
+ * The normalization puts all debts on a common time-independent scale since
849
+ * the launch of this vault manager. This allows the manager to order vaults
850
+ * by their debt-to-collateral ratios without having to mutate the debts as
851
+ * the interest accrues.
850
852
  *
851
- * @returns {import('./storeUtils.js').NormalizedDebt} as if the vault
852
- * was open at the launch of this manager, before any interest
853
- * accrued
854
853
  * @see getActualDebAmount
854
+ *
855
+ * @returns {import('./storeUtils.js').NormalizedDebt} as if the vault was open at the launch of this manager, before any interest accrued
855
856
  */
856
857
  getNormalizedDebt() {
857
858
  const { state } = this;