Skip to content

Commit

Permalink
fixup(liquidationVisibility): implement checkWritersPresent and rem…
Browse files Browse the repository at this point in the history
…ove `writeLiqVisibility`

Refs: #35
  • Loading branch information
anilhelvaci committed Jun 17, 2024
1 parent d3e14f2 commit 7f4a8e8
Showing 1 changed file with 30 additions and 43 deletions.
73 changes: 30 additions & 43 deletions packages/inter-protocol/src/vaultFactory/vaultManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,28 +716,23 @@ export const prepareVaultManagerKit = (
},

/**
* This method checks if liquidationVisibilityWriters is undefined or
* not in case of a rejected promise when creating the writers. If
* liquidationVisibilityWriters is undefined it silently notifies the
* console. Otherwise, it goes on with the writing.
*
* @param {LiquidationVisibilityWriters} liquidationVisibilityWriters
* @param {[string, object][]} writes
* @returns {boolean}
*/
async writeLiqVisibility(liquidationVisibilityWriters, writes) {
console.log('WRITES', writes);
if (!liquidationVisibilityWriters) {
trace(
'writeLiqVisibility',
`Error: liquidationVisibilityWriters is ${liquidationVisibilityWriters}`,
);
return;
}

for (const [methodName, params] of writes) {
trace('DEBUG', methodName, params);
void liquidationVisibilityWriters[methodName](params);
}
checkWritersPresent(liquidationVisibilityWriters) {
console.log(
'[DEBUG] liquidationVisibilityWriters:',
liquidationVisibilityWriters,
);
return !(
typeof liquidationVisibilityWriters?.writePreAuction !==
'function' ||
typeof liquidationVisibilityWriters?.writePostAuction !==
'function' ||
typeof liquidationVisibilityWriters?.writeAuctionResults !==
'function'
);
},

/**
Expand Down Expand Up @@ -1317,9 +1312,9 @@ export const prepareVaultManagerKit = (
auctionSchedule: schedulesP,
});

void helper.writeLiqVisibility(liquidationVisibilityWriters, [
['writePreAuction', vaultData],
]);
if (helper.checkWritersPresent(liquidationVisibilityWriters)) {
liquidationVisibilityWriters.writePreAuction(vaultData);
}

// This is expected to wait for the duration of the auction, which
// is controlled by the auction parameters startFrequency, clockStep,
Expand Down Expand Up @@ -1360,27 +1355,19 @@ export const prepareVaultManagerKit = (
vault.liquidated();
liquidatingVaults.delete(vault);
}
void helper.writeLiqVisibility(
liquidationVisibilityWriters,
harden([
[
'writeAuctionResults',
{
plan,
totalCollateral,
totalDebt,
auctionSchedule,
},
],
[
'writePostAuction',
{
plan,
vaultsInPlan,
},
],
]),
);

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

0 comments on commit 7f4a8e8

Please sign in to comment.