From 4106a624915181b1d088192ed7482dc6811a04df Mon Sep 17 00:00:00 2001 From: anilhelvaci Date: Wed, 12 Jun 2024 15:38:49 +0300 Subject: [PATCH] fixup(liquidationVisibility): implement `checkWritersPresent` and remove `writeLiqVisibility` Refs: #35 --- .../src/vaultFactory/vaultManager.js | 73 ++++++++----------- 1 file changed, 30 insertions(+), 43 deletions(-) diff --git a/packages/inter-protocol/src/vaultFactory/vaultManager.js b/packages/inter-protocol/src/vaultFactory/vaultManager.js index 6d26633bcf5..0256b4895f5 100644 --- a/packages/inter-protocol/src/vaultFactory/vaultManager.js +++ b/packages/inter-protocol/src/vaultFactory/vaultManager.js @@ -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' + ); }, /** @@ -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, @@ -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(); }, },