From 87f6d68e07d56ef33f4fc9ca0d4de1068760bec8 Mon Sep 17 00:00:00 2001 From: Alexander Biryukov Date: Fri, 17 May 2024 13:11:37 +0400 Subject: [PATCH] fix collateral --- scripts/ssv/reads/getExcessTokensToWithdraw.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/ssv/reads/getExcessTokensToWithdraw.ts b/scripts/ssv/reads/getExcessTokensToWithdraw.ts index 1b14d9c..c6085fa 100644 --- a/scripts/ssv/reads/getExcessTokensToWithdraw.ts +++ b/scripts/ssv/reads/getExcessTokensToWithdraw.ts @@ -6,6 +6,7 @@ import { getMinimumLiquidationCollateral } from './getMinimumLiquidationCollater import process from 'process' import { blocksPerDay } from '../../common/helpers/constants' import { getCurrentClusterBalance } from './getCurrentClusterBalance' +import { getLiquidationThresholdPeriod } from './getLiquidationThresholdPeriod' export async function getExcessTokensToWithdraw(clusterState: ClusterStateApi) { logger.info('getExcessTokensToWithdraw started for ' + clusterState.clusterId) @@ -40,9 +41,19 @@ export async function getExcessTokensToWithdraw(clusterState: ClusterStateApi) { const neededBalancePerValidator = totalFeePerBlock * blocksPerDay * allowedDaysToLiquidationForPrivate const minimumLiquidationCollateral = await getMinimumLiquidationCollateral() + + const liquidationThresholdPeriod = await getLiquidationThresholdPeriod() + const collateralForLiquidationThresholdPeriod = liquidationThresholdPeriod * + totalFeePerBlock * + BigInt(validatorCount) + + const collateral = minimumLiquidationCollateral > collateralForLiquidationThresholdPeriod + ? minimumLiquidationCollateral + : collateralForLiquidationThresholdPeriod + const targetBalance = neededBalancePerValidator * BigInt(validatorCount) + - minimumLiquidationCollateral + collateral const balance = await getCurrentClusterBalance(clusterState)