@agoric/inter-protocol 0.16.1 → 0.16.2-dev-8c14632.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 (34) hide show
  1. package/README.md +1 -1
  2. package/bundles/bundle-auctioneer-js-meta.json +285 -285
  3. package/bundles/bundle-auctioneer.js +1 -1
  4. package/bundles/bundle-econCommitteeCharter-js-meta.json +201 -201
  5. package/bundles/bundle-econCommitteeCharter.js +1 -1
  6. package/bundles/bundle-feeDistributor-js-meta.json +201 -201
  7. package/bundles/bundle-feeDistributor.js +1 -1
  8. package/bundles/bundle-fluxAggregatorKit-js-meta.json +307 -307
  9. package/bundles/bundle-fluxAggregatorKit.js +1 -1
  10. package/bundles/bundle-psm-js-meta.json +264 -264
  11. package/bundles/bundle-psm.js +1 -1
  12. package/bundles/bundle-reserve-js-meta.json +295 -295
  13. package/bundles/bundle-reserve.js +1 -1
  14. package/bundles/bundle-scaledPriceAuthority-js-meta.json +225 -225
  15. package/bundles/bundle-scaledPriceAuthority.js +1 -1
  16. package/bundles/bundle-vaultFactory-js-meta.json +346 -346
  17. package/bundles/bundle-vaultFactory.js +1 -1
  18. package/package.json +20 -19
  19. package/scripts/add-STARS.js +43 -0
  20. package/scripts/add-collateral-core.js +2 -2
  21. package/src/auction/scheduler.js +2 -12
  22. package/src/interest-math.js +13 -13
  23. package/src/interest.js +24 -24
  24. package/src/price/fluxAggregatorContract.js +4 -8
  25. package/src/proposals/addAssetToVault.js +19 -7
  26. package/src/proposals/price-feed-proposal.js +29 -15
  27. package/src/proposals/startPSM.js +6 -4
  28. package/src/reserve/assetReserve.js +2 -2
  29. package/src/vaultFactory/params.js +4 -4
  30. package/src/vaultFactory/storeUtils.js +11 -7
  31. package/src/vaultFactory/types.js +4 -4
  32. package/src/vaultFactory/vault.js +18 -13
  33. package/src/vaultFactory/vaultDirector.js +2 -0
  34. package/src/vaultFactory/vaultManager.js +47 -40
@@ -131,15 +131,15 @@ harden(fromVaultKey);
131
131
  * For use by `normalizedCollRatioKey` and tests.
132
132
  *
133
133
  * @param {PriceQuote} quote
134
- * @param {Ratio} compoundedInterest
134
+ * @param {Ratio} compoundedStabilityFee
135
135
  * @param {Ratio} margin
136
136
  * @returns {number}
137
137
  */
138
- export const normalizedCollRatio = (quote, compoundedInterest, margin) => {
138
+ export const normalizedCollRatio = (quote, compoundedStabilityFee, margin) => {
139
139
  const amountIn = getAmountIn(quote).value;
140
140
  const amountOut = getAmountOut(quote).value;
141
- const interestNumerator = compoundedInterest.numerator.value;
142
- const interestBase = compoundedInterest.denominator.value;
141
+ const interestNumerator = compoundedStabilityFee.numerator.value;
142
+ const interestBase = compoundedStabilityFee.denominator.value;
143
143
  const numerator = multiply(
144
144
  margin.numerator.value,
145
145
  multiply(amountIn, interestNumerator),
@@ -159,13 +159,17 @@ harden(normalizedCollRatio);
159
159
  * out the numerator and the denominator, and divide only once.
160
160
  *
161
161
  * @param {PriceQuote} quote
162
- * @param {Ratio} compoundedInterest
162
+ * @param {Ratio} compoundedStabilityFee
163
163
  * @param {Ratio} margin
164
164
  * @returns {string} lexically sortable string in which highest
165
165
  * debt-to-collateral is earliest
166
166
  */
167
- export const normalizedCollRatioKey = (quote, compoundedInterest, margin) => {
168
- const collRatio = normalizedCollRatio(quote, compoundedInterest, margin);
167
+ export const normalizedCollRatioKey = (
168
+ quote,
169
+ compoundedStabilityFee,
170
+ margin,
171
+ ) => {
172
+ const collRatio = normalizedCollRatio(quote, compoundedStabilityFee, margin);
169
173
  return `${encodeNumber(collRatio)}:`;
170
174
  };
171
175
  harden(normalizedCollRatioKey);
@@ -26,7 +26,7 @@
26
26
  * @property {Ratio} liquidationMargin - margin below which collateral will be
27
27
  * liquidated to satisfy the debt.
28
28
  * @property {Ratio} liquidationPenalty - penalty charged upon liquidation as proportion of debt
29
- * @property {Ratio} interestRate - annual interest rate charged on debt positions
29
+ * @property {Ratio} stabilityFee - annual interest rate charged on debt positions
30
30
  * @property {Ratio} mintFee - The fee (in BasisPoints) charged when creating
31
31
  * or increasing a debt position.
32
32
  * @property {Amount<'nat'>} debtLimit
@@ -78,7 +78,7 @@
78
78
  * @property {() => Ratio} getLiquidationMargin
79
79
  * @property {() => Ratio} getMintFee
80
80
  * @property {() => Promise<PriceQuote>} getCollateralQuote
81
- * @property {() => Ratio} getInterestRate - The annual interest rate on a debt position
81
+ * @property {() => Ratio} getStabilityFee - The annual interest rate on a debt position
82
82
  * @property {() => RelativeTime} getChargingPeriod - The period (in seconds) at
83
83
  * which interest is charged to the debt position.
84
84
  * @property {() => RelativeTime} getRecordingPeriod - The period (in seconds)
@@ -109,8 +109,8 @@
109
109
 
110
110
  /**
111
111
  * @typedef {object} DebtStatus
112
- * @property {Timestamp} latestInterestUpdate
113
- * @property {NatValue} interest interest accrued since latestInterestUpdate
112
+ * @property {Timestamp} latestStabilityFeeUpdate
113
+ * @property {NatValue} interest interest accrued since latestStabilityFeeUpdate
114
114
  * @property {NatValue} newDebt total including principal and interest
115
115
  */
116
116
 
@@ -72,7 +72,7 @@ const validTransitions = {
72
72
  *
73
73
  * @typedef {object} VaultNotification
74
74
  * @property {Amount<'nat'>} locked Amount of Collateral locked
75
- * @property {{debt: Amount<'nat'>, interest: Ratio}} debtSnapshot 'debt' at the point the compounded interest was 'interest'
75
+ * @property {{debt: Amount<'nat'>, stabilityFee: Ratio}} debtSnapshot 'debt' at the point the compounded stabilityFee was 'stabilityFee'
76
76
  * @property {HolderPhase} vaultState
77
77
  */
78
78
 
@@ -86,7 +86,7 @@ const validTransitions = {
86
86
  * @property {() => Brand<'nat'>} getDebtBrand
87
87
  * @property {MintAndTransfer} mintAndTransfer
88
88
  * @property {(amount: Amount, seat: ZCFSeat) => void} burn
89
- * @property {() => Ratio} getCompoundedInterest
89
+ * @property {() => Ratio} getCompoundedStabilityFee
90
90
  * @property {(oldDebt: import('./storeUtils.js').NormalizedDebt, oldCollateral: Amount<'nat'>, vaultId: VaultId, vaultPhase: VaultPhase, vault: Vault) => void} handleBalanceChange
91
91
  * @property {() => import('./vaultManager.js').GovernedParamGetters} getGovernedParams
92
92
  */
@@ -104,7 +104,7 @@ const validTransitions = {
104
104
  * Snapshot is of the debt and compounded interest when the principal was last changed.
105
105
  *
106
106
  * @typedef {{
107
- * interestSnapshot: Ratio,
107
+ * stabilityFeeSnapshot: Ratio,
108
108
  * phase: VaultPhase,
109
109
  * debtSnapshot: Amount<'nat'>,
110
110
  * outerUpdater: import('@agoric/zoe/src/contractSupport/recorder.js').Recorder<VaultNotification> | null,
@@ -132,7 +132,7 @@ const VaultStateShape = harden({
132
132
  phase: M.any(),
133
133
  storageNode: M.any(),
134
134
  vaultSeat: M.any(),
135
- interestSnapshot: M.any(),
135
+ stabilityFeeSnapshot: M.any(),
136
136
  debtSnapshot: M.any(),
137
137
  });
138
138
 
@@ -174,7 +174,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
174
174
  vaultSeat: zcf.makeEmptySeatKit().zcfSeat,
175
175
 
176
176
  // Two values from the same moment
177
- interestSnapshot: manager.getCompoundedInterest(),
177
+ stabilityFeeSnapshot: manager.getCompoundedStabilityFee(),
178
178
  debtSnapshot: AmountMath.makeEmpty(manager.getDebtBrand()),
179
179
  });
180
180
  },
@@ -257,7 +257,8 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
257
257
 
258
258
  // update local state
259
259
  state.debtSnapshot = newDebt;
260
- state.interestSnapshot = state.manager.getCompoundedInterest();
260
+ state.stabilityFeeSnapshot =
261
+ state.manager.getCompoundedStabilityFee();
261
262
  },
262
263
 
263
264
  /**
@@ -327,10 +328,11 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
327
328
  getStateSnapshot(newPhase) {
328
329
  const { state, facets } = this;
329
330
 
330
- const { debtSnapshot: debt, interestSnapshot: interest } = state;
331
+ const { debtSnapshot: debt, stabilityFeeSnapshot: stabilityFee } =
332
+ state;
331
333
  /** @type {VaultNotification} */
332
334
  return harden({
333
- debtSnapshot: { debt, interest },
335
+ debtSnapshot: { debt, stabilityFee },
334
336
  locked: facets.self.getCollateralAmount(),
335
337
  // newPhase param is so that makeTransferInvitation can finish without setting the vault's phase
336
338
  // TODO refactor https://github.com/Agoric/agoric-sdk/issues/4415
@@ -785,7 +787,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
785
787
  helper.updateDebtSnapshot(self.getCurrentDebt());
786
788
  const {
787
789
  debtSnapshot: debt,
788
- interestSnapshot: interest,
790
+ stabilityFeeSnapshot: stabilityFee,
789
791
  phase,
790
792
  } = state;
791
793
  if (outerUpdater) {
@@ -795,7 +797,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
795
797
  state.outerUpdater = null;
796
798
  }
797
799
  const transferState = {
798
- debtSnapshot: { debt, interest },
800
+ debtSnapshot: { debt, stabilityFee },
799
801
  locked: self.getCollateralAmount(),
800
802
  vaultState: phase,
801
803
  };
@@ -839,8 +841,8 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
839
841
  const { state } = this;
840
842
  return calculateCurrentDebt(
841
843
  state.debtSnapshot,
842
- state.interestSnapshot,
843
- state.manager.getCompoundedInterest(),
844
+ state.stabilityFeeSnapshot,
845
+ state.manager.getCompoundedStabilityFee(),
844
846
  );
845
847
  },
846
848
 
@@ -857,7 +859,10 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
857
859
  getNormalizedDebt() {
858
860
  const { state } = this;
859
861
  // @ts-expect-error cast
860
- return reverseInterest(state.debtSnapshot, state.interestSnapshot);
862
+ return reverseInterest(
863
+ state.debtSnapshot,
864
+ state.stabilityFeeSnapshot,
865
+ );
861
866
  },
862
867
  },
863
868
  },
@@ -250,6 +250,7 @@ const prepareVaultDirector = (
250
250
  metrics: makeRecorderTopic('Vault Factory metrics', metricsKit),
251
251
  });
252
252
 
253
+ /** @param {(vm: VaultManager) => void} fn */
253
254
  const allManagersDo = fn => {
254
255
  for (const managerIndex of collateralManagers.values()) {
255
256
  const vm = vaultManagers.get(managerIndex).self;
@@ -424,6 +425,7 @@ const prepareVaultDirector = (
424
425
 
425
426
  makeLiquidationWaker() {
426
427
  return makeWaker('liquidationWaker', _timestamp => {
428
+ // XXX floating promise
427
429
  allManagersDo(vm => vm.liquidateVaults(auctioneer));
428
430
  });
429
431
  },
@@ -95,16 +95,16 @@ const trace = makeTracer('VM');
95
95
 
96
96
  /**
97
97
  * @typedef {{
98
- * compoundedInterest: Ratio,
99
- * interestRate: Ratio,
100
- * latestInterestUpdate: Timestamp,
98
+ * compoundedStabilityFee: Ratio,
99
+ * stabilityFee: Ratio,
100
+ * latestStabilityFeeUpdate: Timestamp,
101
101
  * }} AssetState
102
102
  *
103
103
  * @typedef {{
104
104
  * getChargingPeriod: () => RelativeTime,
105
105
  * getRecordingPeriod: () => RelativeTime,
106
106
  * getDebtLimit: () => Amount<'nat'>,
107
- * getInterestRate: () => Ratio,
107
+ * getStabilityFee: () => Ratio,
108
108
  * getLiquidationPadding: () => Ratio,
109
109
  * getLiquidationMargin: () => Ratio,
110
110
  * getLiquidationPenalty: () => Ratio,
@@ -138,8 +138,8 @@ const trace = makeTracer('VM');
138
138
 
139
139
  /**
140
140
  * @typedef {{
141
- * compoundedInterest: Ratio,
142
- * latestInterestUpdate: Timestamp,
141
+ * compoundedStabilityFee: Ratio,
142
+ * latestStabilityFeeUpdate: Timestamp,
143
143
  * numLiquidationsCompleted: number,
144
144
  * numLiquidationsAborted: number,
145
145
  * totalCollateral: Amount<'nat'>,
@@ -230,8 +230,8 @@ export const prepareVaultManagerKit = (
230
230
  return harden({
231
231
  ...params,
232
232
  ...immutable,
233
- compoundedInterest: makeRatio(100n, debtBrand), // starts at 1.0, no interest
234
- latestInterestUpdate: startTimeStamp,
233
+ compoundedStabilityFee: makeRatio(100n, debtBrand), // starts at 1.0, no interest
234
+ latestStabilityFeeUpdate: startTimeStamp,
235
235
  numLiquidationsCompleted: 0,
236
236
  numLiquidationsAborted: 0,
237
237
  totalCollateral: zeroCollateral,
@@ -255,7 +255,7 @@ export const prepareVaultManagerKit = (
255
255
  makeVaultInvitation: M.call().returns(M.promise()),
256
256
  getPublicTopics: M.call().returns(TopicsRecordShape),
257
257
  getQuotes: M.call().returns(NotifierShape),
258
- getCompoundedInterest: M.call().returns(RatioShape),
258
+ getCompoundedStabilityFee: M.call().returns(RatioShape),
259
259
  }),
260
260
  helper: M.interface(
261
261
  'helper',
@@ -276,7 +276,7 @@ export const prepareVaultManagerKit = (
276
276
  getAssetSubscriber: M.call().returns(SubscriberShape),
277
277
  getCollateralBrand: M.call().returns(BrandShape),
278
278
  getDebtBrand: M.call().returns(BrandShape),
279
- getCompoundedInterest: M.call().returns(RatioShape),
279
+ getCompoundedStabilityFee: M.call().returns(RatioShape),
280
280
  scopeDescription: M.call(M.string()).returns(M.string()),
281
281
  handleBalanceChange: M.call(
282
282
  AmountShape,
@@ -319,8 +319,8 @@ export const prepareVaultManagerKit = (
319
319
  const ephemera = collateralEphemera(this.state.collateralBrand);
320
320
  return ephemera.storedQuotesNotifier;
321
321
  },
322
- getCompoundedInterest() {
323
- return this.state.compoundedInterest;
322
+ getCompoundedStabilityFee() {
323
+ return this.state.compoundedStabilityFee;
324
324
  },
325
325
  getPublicTopics() {
326
326
  const { assetTopicKit, metricsTopicKit } = this.state;
@@ -400,7 +400,7 @@ export const prepareVaultManagerKit = (
400
400
  // throw. See https://github.com/Agoric/agoric-sdk/issues/4317
401
401
  void observeNotifier(quoteNotifier, {
402
402
  updateState(value) {
403
- trace('vaultManager got new collateral quote', value);
403
+ trace('storing new quote', value.quoteAmount.value);
404
404
  ephemera.storedCollateralQuote = value;
405
405
  },
406
406
  fail(reason) {
@@ -419,9 +419,9 @@ export const prepareVaultManagerKit = (
419
419
  updateTime,
420
420
  });
421
421
 
422
- const interestRate = factoryPowers
422
+ const stabilityFee = factoryPowers
423
423
  .getGovernedParams(collateralBrand)
424
- .getInterestRate();
424
+ .getStabilityFee();
425
425
 
426
426
  // Update state with the results of charging interest
427
427
 
@@ -433,7 +433,7 @@ export const prepareVaultManagerKit = (
433
433
  seatAllocationKeyword: 'Minted',
434
434
  },
435
435
  {
436
- interestRate,
436
+ stabilityFee,
437
437
  chargingPeriod: factoryPowers
438
438
  .getGovernedParams(collateralBrand)
439
439
  .getChargingPeriod(),
@@ -442,15 +442,15 @@ export const prepareVaultManagerKit = (
442
442
  .getRecordingPeriod(),
443
443
  },
444
444
  {
445
- latestInterestUpdate: state.latestInterestUpdate,
446
- compoundedInterest: state.compoundedInterest,
445
+ latestStabilityFeeUpdate: state.latestStabilityFeeUpdate,
446
+ compoundedStabilityFee: state.compoundedStabilityFee,
447
447
  totalDebt: state.totalDebt,
448
448
  },
449
449
  updateTime,
450
450
  );
451
451
 
452
- state.compoundedInterest = changes.compoundedInterest;
453
- state.latestInterestUpdate = changes.latestInterestUpdate;
452
+ state.compoundedStabilityFee = changes.compoundedStabilityFee;
453
+ state.latestStabilityFeeUpdate = changes.latestStabilityFeeUpdate;
454
454
  state.totalDebt = changes.totalDebt;
455
455
 
456
456
  return facets.helper.assetNotify();
@@ -458,14 +458,14 @@ export const prepareVaultManagerKit = (
458
458
  assetNotify() {
459
459
  const { state } = this;
460
460
  const { collateralBrand, assetTopicKit } = state;
461
- const interestRate = factoryPowers
461
+ const stabilityFee = factoryPowers
462
462
  .getGovernedParams(collateralBrand)
463
- .getInterestRate();
463
+ .getStabilityFee();
464
464
  /** @type {AssetState} */
465
465
  const payload = harden({
466
- compoundedInterest: state.compoundedInterest,
467
- interestRate,
468
- latestInterestUpdate: state.latestInterestUpdate,
466
+ compoundedStabilityFee: state.compoundedStabilityFee,
467
+ stabilityFee,
468
+ latestStabilityFeeUpdate: state.latestStabilityFeeUpdate,
469
469
  });
470
470
  return assetTopicKit.recorder.write(payload);
471
471
  },
@@ -843,8 +843,8 @@ export const prepareVaultManagerKit = (
843
843
  /**
844
844
  * coefficient on existing debt to calculate new debt
845
845
  */
846
- getCompoundedInterest() {
847
- return this.state.compoundedInterest;
846
+ getCompoundedStabilityFee() {
847
+ return this.state.compoundedStabilityFee;
848
848
  },
849
849
  /**
850
850
  * Called by a vault when its balances change.
@@ -963,7 +963,6 @@ export const prepareVaultManagerKit = (
963
963
 
964
964
  try {
965
965
  // TODO `await` is allowed until the above ordering is fixed
966
- // eslint-disable-next-line @jessie.js/no-nested-await
967
966
  const vaultKit = await vault.initVaultKit(seat, vaultStorageNode);
968
967
  // initVaultKit calls back to handleBalanceChange() which will add the
969
968
  // vault to prioritizedVaults
@@ -1037,7 +1036,7 @@ export const prepareVaultManagerKit = (
1037
1036
  if (!storedCollateralQuote)
1038
1037
  throw Fail`lockOraclePrices called before a collateral quote was available`;
1039
1038
  trace(
1040
- `lockPrice`,
1039
+ `lockOraclePrices`,
1041
1040
  getAmountIn(storedCollateralQuote),
1042
1041
  getAmountOut(storedCollateralQuote),
1043
1042
  );
@@ -1047,25 +1046,33 @@ export const prepareVaultManagerKit = (
1047
1046
  return storedCollateralQuote;
1048
1047
  },
1049
1048
  /**
1050
- * @param {AuctioneerPublicFacet} auctionPF
1049
+ * @param {ERef<AuctioneerPublicFacet>} auctionPF
1051
1050
  */
1052
1051
  async liquidateVaults(auctionPF) {
1053
1052
  const { state, facets } = this;
1054
1053
  const { self, helper } = facets;
1055
1054
  const {
1056
1055
  collateralBrand,
1057
- compoundedInterest,
1056
+ compoundedStabilityFee,
1058
1057
  debtBrand,
1059
1058
  liquidatingVaults,
1060
1059
  lockedQuote,
1061
1060
  } = state;
1062
1061
  trace(collateralBrand, 'considering liquidation');
1063
1062
 
1063
+ if (!lockedQuote) {
1064
+ // By design, the first cycle of auction may call this before a quote is locked
1065
+ // because the schedule is global at the vaultDirector level, and if a manager
1066
+ // starts after the price lock time there's nothing to be done.
1067
+ // NB: this message should not log repeatedly.
1068
+ console.error(
1069
+ 'Skipping liquidation because no quote is locked yet (may happen with new manager)',
1070
+ );
1071
+ return;
1072
+ }
1073
+
1064
1074
  const { prioritizedVaults } = collateralEphemera(collateralBrand);
1065
- assert(factoryPowers && prioritizedVaults && zcf);
1066
- lockedQuote ||
1067
- Fail`Must have locked a quote before liquidating vaults.`;
1068
- assert(lockedQuote); // redundant with previous line
1075
+ prioritizedVaults || Fail`prioritizedVaults missing from ephemera`;
1069
1076
 
1070
1077
  const liqMargin = self.getGovernedParams().getLiquidationMargin();
1071
1078
 
@@ -1075,7 +1082,7 @@ export const prepareVaultManagerKit = (
1075
1082
  zcf,
1076
1083
  {
1077
1084
  quote: lockedQuote,
1078
- interest: compoundedInterest,
1085
+ interest: compoundedStabilityFee,
1079
1086
  margin: liqMargin,
1080
1087
  },
1081
1088
  prioritizedVaults,
@@ -1160,11 +1167,11 @@ export const prepareVaultManagerKit = (
1160
1167
  helper.start();
1161
1168
  void state.assetTopicKit.recorder.write(
1162
1169
  harden({
1163
- compoundedInterest: state.compoundedInterest,
1164
- interestRate: factoryPowers
1170
+ compoundedStabilityFee: state.compoundedStabilityFee,
1171
+ stabilityFee: factoryPowers
1165
1172
  .getGovernedParams(state.collateralBrand)
1166
- .getInterestRate(),
1167
- latestInterestUpdate: state.latestInterestUpdate,
1173
+ .getStabilityFee(),
1174
+ latestStabilityFeeUpdate: state.latestStabilityFeeUpdate,
1168
1175
  }),
1169
1176
  );
1170
1177