Skip to content

Commit

Permalink
fixup(liquidationVisibility): Directly invoking methods on `liquidati…
Browse files Browse the repository at this point in the history
…onVisibilityWriters` resulted with below changes;

* Use `Promise.all` instead of `allValuesSettled`
* Remove `liq-rejected-schedule` and `liq-rejected-timestampStorageNode` as we don't need to handle those cases anymore
* Write an error message in postAuction and auctionResults recorder kits in the case of an error in distributing plans

Refs: #35
  • Loading branch information
anilhelvaci committed Jun 13, 2024
1 parent 4106a62 commit 984f55b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 308 deletions.
10 changes: 6 additions & 4 deletions packages/inter-protocol/src/vaultFactory/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
* @typedef {import('@agoric/time/src/types.js').TimestampRecord} TimestampRecord
*
* @typedef {import('@agoric/time').RelativeTime} RelativeTime
*
* @typedef {import('./liquidation.js').VaultData} VaultData
* @typedef {import('./proceeds.js').DistributionPlan} DistributionPlan
*/

/**
Expand Down Expand Up @@ -138,20 +141,19 @@

/**
* @typedef {{
* plan: import('./proceeds.js').DistributionPlan;
* vaultsInPlan: Array;
* plan: DistributionPlan | undefined;
* vaultsInPlan: Array | undefined;
* }} PostAuctionParams
*
* @typedef {{
* plan: import('./proceeds.js').DistributionPlan;
* plan: DistributionPlan | undefined;
* totalCollateral: Amount<'nat'>;
* totalDebt: Amount<'nat'>;
* auctionSchedule: import('../auction/scheduler.js').FullSchedule;
* }} AuctionResultsParams
*/

/**
* @typedef {import('./liquidation.js').VaultData} VaultData
*
* @typedef {object} LiquidationVisibilityWriters
* @property {(vaultData: VaultData) => Promise<void>} writePreAuction
Expand Down
45 changes: 27 additions & 18 deletions packages/inter-protocol/src/vaultFactory/vaultManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
NotifierShape,
RatioShape,
} from '@agoric/ertp';
import { allValuesSettled, makeTracer } from '@agoric/internal';
import { makeTracer } from '@agoric/internal';
import { makeStoredNotifier, observeNotifier } from '@agoric/notifier';
import { appendToStoredArray } from '@agoric/store/src/stores/store-utils.js';
import {
Expand Down Expand Up @@ -165,6 +165,10 @@ const trace = makeTracer('VM');
*/

/**
* @typedef {{
* error: string
* }} DistributionError
*
* @typedef {(
* | string
* | { collateralAmount: Amount<'nat'>; debtAmount: Amount<'nat'> }
Expand All @@ -186,8 +190,8 @@ const trace = makeTracer('VM');
*
* @typedef {{
* preAuctionRecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<PreAuctionState>;
* postAuctionRecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<PostAuctionState>;
* auctionResultRecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<AuctionResultState>;
* postAuctionRecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<PostAuctionState | DistributionError>;
* auctionResultRecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<AuctionResultState | DistributionError>;
* }} LiquidationRecorderKits
*/

Expand Down Expand Up @@ -667,6 +671,11 @@ export const prepareVaultManagerKit = (
* @returns {Promise<void>}
*/
const writePostAuction = ({ plan, vaultsInPlan }) => {
if (!(plan && vaultsInPlan)) {
return E(
liquidationRecorderKits.postAuctionRecorderKit.recorder,
).writeFinal({ error: 'Error distributing proceeds' });
}
/** @type PostAuctionState */
const postAuctionState = plan.transfersToVault.map(
([id, transfer]) => [
Expand All @@ -689,6 +698,12 @@ export const prepareVaultManagerKit = (
totalDebt,
auctionSchedule,
}) => {
if (!plan) {
return E(
liquidationRecorderKits.auctionResultRecorderKit.recorder,
).writeFinal({ error: 'Error distributing proceeds' });
}

/** @type AuctionResultState */
const auctionResultState = {
collateralOffered: totalCollateral,
Expand Down Expand Up @@ -1296,24 +1311,18 @@ export const prepareVaultManagerKit = (
),
);

// helper.makeLiquidationVisibilityWriters and schedulesP depends on others vats,
// so we switched from Promise.all to Promise.allSettled because if one of those vats fail
// we don't want those failures to prevent liquidation process from going forward.
// We don't handle the case where 'makeDeposit' rejects as liquidation depends on
// 'makeDeposit' being fulfilled.
const {
makeDeposit: { userSeatPromise, deposited },
const [
{ userSeatPromise, deposited },
liquidationVisibilityWriters,
auctionSchedule,
} = await allValuesSettled({
] = await Promise.all([
makeDeposit,
liquidationVisibilityWriters:
helper.makeLiquidationVisibilityWriters(timestamp),
auctionSchedule: schedulesP,
});
helper.makeLiquidationVisibilityWriters(timestamp),
schedulesP,
]);

if (helper.checkWritersPresent(liquidationVisibilityWriters)) {
liquidationVisibilityWriters.writePreAuction(vaultData);
void liquidationVisibilityWriters.writePreAuction(vaultData);
}

// This is expected to wait for the duration of the auction, which
Expand Down Expand Up @@ -1357,11 +1366,11 @@ export const prepareVaultManagerKit = (
}

if (helper.checkWritersPresent(liquidationVisibilityWriters)) {
liquidationVisibilityWriters.writePostAuction({
void liquidationVisibilityWriters.writePostAuction({
plan,
vaultsInPlan,
});
liquidationVisibilityWriters.writeAuctionResults({
void liquidationVisibilityWriters.writeAuctionResults({
plan,
totalCollateral,
totalDebt,
Expand Down
Loading

0 comments on commit 984f55b

Please sign in to comment.