Skip to content

Commit

Permalink
chore(vaults): handle missing lockedQuote as valid
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jun 7, 2023
1 parent daf56fc commit c711453
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 2 additions & 0 deletions packages/inter-protocol/src/vaultFactory/vaultDirector.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ const prepareVaultDirector = (
metrics: makeRecorderTopic('Vault Factory metrics', metricsKit),
});

/** @param {(vm: VaultManager) => void} fn */
const allManagersDo = fn => {
for (const managerIndex of collateralManagers.values()) {
const vm = vaultManagers.get(managerIndex).self;
Expand Down Expand Up @@ -424,6 +425,7 @@ const prepareVaultDirector = (

makeLiquidationWaker() {
return makeWaker('liquidationWaker', _timestamp => {
// XXX floating promise
allManagersDo(vm => vm.liquidateVaults(auctioneer));
});
},
Expand Down
22 changes: 15 additions & 7 deletions packages/inter-protocol/src/vaultFactory/vaultManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export const prepareVaultManagerKit = (
// throw. See https://github.com/Agoric/agoric-sdk/issues/4317
void observeNotifier(quoteNotifier, {
updateState(value) {
trace('vaultManager got new collateral quote', value);
trace('storing new quote', value.quoteAmount.value);
ephemera.storedCollateralQuote = value;
},
fail(reason) {
Expand Down Expand Up @@ -1036,7 +1036,7 @@ export const prepareVaultManagerKit = (
if (!storedCollateralQuote)
throw Fail`lockOraclePrices called before a collateral quote was available`;
trace(
`lockPrice`,
`lockOraclePrices`,
getAmountIn(storedCollateralQuote),
getAmountOut(storedCollateralQuote),
);
Expand All @@ -1046,7 +1046,7 @@ export const prepareVaultManagerKit = (
return storedCollateralQuote;
},
/**
* @param {AuctioneerPublicFacet} auctionPF
* @param {ERef<AuctioneerPublicFacet>} auctionPF
*/
async liquidateVaults(auctionPF) {
const { state, facets } = this;
Expand All @@ -1060,11 +1060,19 @@ export const prepareVaultManagerKit = (
} = state;
trace(collateralBrand, 'considering liquidation');

if (!lockedQuote) {
// By design, the first cycle of auction may call this before a quote is locked
// because the schedule is global at the vaultDirector level, and if a manager
// starts after the price lock time there's nothing to be done.
// NB: this message should not log repeatedly.
console.error(
'Skipping liquidation because no quote is locked yet (may happen with new manager)',
);
return;
}

const { prioritizedVaults } = collateralEphemera(collateralBrand);
assert(factoryPowers && prioritizedVaults && zcf);
lockedQuote ||
Fail`Must have locked a quote before liquidating vaults.`;
assert(lockedQuote); // redundant with previous line
prioritizedVaults || Fail`prioritizedVaults missing from ephemera`;

const liqMargin = self.getGovernedParams().getLiquidationMargin();

Expand Down

0 comments on commit c711453

Please sign in to comment.