@agoric/inter-protocol 0.16.1-dev-590740f.0 → 0.16.1-dev-69236fd.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.
@@ -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.
@@ -1036,7 +1036,7 @@ export const prepareVaultManagerKit = (
1036
1036
  if (!storedCollateralQuote)
1037
1037
  throw Fail`lockOraclePrices called before a collateral quote was available`;
1038
1038
  trace(
1039
- `lockPrice`,
1039
+ `lockOraclePrices`,
1040
1040
  getAmountIn(storedCollateralQuote),
1041
1041
  getAmountOut(storedCollateralQuote),
1042
1042
  );
@@ -1046,25 +1046,33 @@ export const prepareVaultManagerKit = (
1046
1046
  return storedCollateralQuote;
1047
1047
  },
1048
1048
  /**
1049
- * @param {AuctioneerPublicFacet} auctionPF
1049
+ * @param {ERef<AuctioneerPublicFacet>} auctionPF
1050
1050
  */
1051
1051
  async liquidateVaults(auctionPF) {
1052
1052
  const { state, facets } = this;
1053
1053
  const { self, helper } = facets;
1054
1054
  const {
1055
1055
  collateralBrand,
1056
- compoundedInterest,
1056
+ compoundedStabilityFee,
1057
1057
  debtBrand,
1058
1058
  liquidatingVaults,
1059
1059
  lockedQuote,
1060
1060
  } = state;
1061
1061
  trace(collateralBrand, 'considering liquidation');
1062
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
+
1063
1074
  const { prioritizedVaults } = collateralEphemera(collateralBrand);
1064
- assert(factoryPowers && prioritizedVaults && zcf);
1065
- lockedQuote ||
1066
- Fail`Must have locked a quote before liquidating vaults.`;
1067
- assert(lockedQuote); // redundant with previous line
1075
+ prioritizedVaults || Fail`prioritizedVaults missing from ephemera`;
1068
1076
 
1069
1077
  const liqMargin = self.getGovernedParams().getLiquidationMargin();
1070
1078
 
@@ -1074,7 +1082,7 @@ export const prepareVaultManagerKit = (
1074
1082
  zcf,
1075
1083
  {
1076
1084
  quote: lockedQuote,
1077
- interest: compoundedInterest,
1085
+ interest: compoundedStabilityFee,
1078
1086
  margin: liqMargin,
1079
1087
  },
1080
1088
  prioritizedVaults,
@@ -1159,11 +1167,11 @@ export const prepareVaultManagerKit = (
1159
1167
  helper.start();
1160
1168
  void state.assetTopicKit.recorder.write(
1161
1169
  harden({
1162
- compoundedInterest: state.compoundedInterest,
1163
- interestRate: factoryPowers
1170
+ compoundedStabilityFee: state.compoundedStabilityFee,
1171
+ stabilityFee: factoryPowers
1164
1172
  .getGovernedParams(state.collateralBrand)
1165
- .getInterestRate(),
1166
- latestInterestUpdate: state.latestInterestUpdate,
1173
+ .getStabilityFee(),
1174
+ latestStabilityFeeUpdate: state.latestStabilityFeeUpdate,
1167
1175
  }),
1168
1176
  );
1169
1177