From c53a36687b01890c4bb5fa290a3816461e1be89b Mon Sep 17 00:00:00 2001 From: naturexie <786281870@qq.com> Date: Wed, 29 Jan 2025 19:25:00 +0800 Subject: [PATCH] feat: The maximum amount of debt that can be borrowed is logically adjusted --- screens/Trading/components/TradingOperate.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/screens/Trading/components/TradingOperate.tsx b/screens/Trading/components/TradingOperate.tsx index 35190cc5..c38033d0 100644 --- a/screens/Trading/components/TradingOperate.tsx +++ b/screens/Trading/components/TradingOperate.tsx @@ -27,6 +27,7 @@ import { useRegisterTokenType } from "../../../hooks/useRegisterTokenType"; import { MARGIN_MIN_COLLATERAL_USD } from "../../../utils/config"; import type { Asset } from "../../../redux/assetState"; import { expandToken, shrinkToken } from "../../../store"; +import type { IMarginConfigState } from "../../../redux/marginConfigState"; interface TradingOperateProps { onMobileClose?: () => void; @@ -272,7 +273,7 @@ const TradingOperate: React.FC = ({ onMobileClose, id }) => } else if (new Decimal(longInput || 0).gt(ReduxcategoryCurrentBalance2 || 0)) { setWarnTip(insufficient_balance); } else { - const borrowLimit = getBorrowLimit(ReduxcategoryAssets2, tokenInAmount); + const borrowLimit = getBorrowLimit(ReduxcategoryAssets2, tokenInAmount, config); const price_1 = getAssetPrice(ReduxcategoryAssets1); const price_2 = getAssetPrice(ReduxcategoryAssets2); if (borrowLimit?.isExceed) { @@ -311,7 +312,7 @@ const TradingOperate: React.FC = ({ onMobileClose, id }) => } else if (new Decimal(shortInput || 0).gt(ReduxcategoryCurrentBalance2 || 0)) { setWarnTip(insufficient_balance); } else { - const borrowLimit = getBorrowLimit(ReduxcategoryAssets1, tokenInAmount); + const borrowLimit = getBorrowLimit(ReduxcategoryAssets1, tokenInAmount, config); if (borrowLimit?.isExceed) { setWarnTip( <> @@ -351,6 +352,7 @@ const TradingOperate: React.FC = ({ onMobileClose, id }) => ReduxcategoryCurrentBalance2, longInput, shortInput, + config, ], ); const setMaxInputBanlance = (key: string) => { @@ -530,7 +532,7 @@ const TradingOperate: React.FC = ({ onMobileClose, id }) => if (!value) return "0"; return value.toFixed(6).replace(/\.?0+$/, ""); }; - function getBorrowLimit(assetDebt: Asset, debt_amount: number) { + function getBorrowLimit(assetDebt: Asset, debt_amount: number, marginConfig: IMarginConfigState) { const assetsMap = isMainStream ? assets.data : assetsMEME.data; const asset = assetsMap[assetDebt.token_id]; const temp1 = new Decimal(asset.supplied.balance) @@ -543,8 +545,10 @@ const TradingOperate: React.FC = ({ onMobileClose, id }) => const availableLiquidity = Number( shrinkToken(temp2, asset.metadata.decimals + asset.config.extra_decimals), ); + const scale = marginConfig.pending_debt_scale / 10000; + const availableLiquidityForMargin = availableLiquidity * scale; // asset.config.min_borrowed_amount; - if (new Decimal(debt_amount || 0).gte(availableLiquidity || 0)) { + if (new Decimal(debt_amount || 0).gte(availableLiquidityForMargin || 0)) { return { isExceed: true, availableLiquidity,