After deposing the correct money from binance but failed1

This commit is contained in:
Your Name 2026-08-26 11:19:02 +02:00
parent 7b3abf59a3
commit f4c3fbd35c
4 changed files with 166 additions and 25 deletions

View File

@ -11,6 +11,42 @@ import * as depositSweepRepository from '../repositories/depositSweepRepository'
import * as exchangeFundingRepository from '../repositories/exchangeFundingRepository';
import * as settingsRepository from '../repositories/settingsRepository';
import * as tronService from './blockchain/tronService';
import * as bscService from './blockchain/bscService';
import { USDT_BEP20_CODE, USDT_TRC20_CODE } from './walletCapabilities';
import { MIN_BNB_WEI_FOR_WITHDRAWAL, MIN_TRX_SUN_FOR_WITHDRAWAL } from './hotLiquidityService';
async function readTronTokenBalance(address: string, contract: string): Promise<string | null> {
try {
return (await tronService.getTrc20BalanceRaw(address, contract)).toString();
} catch {
return null;
}
}
async function readTronNativeSun(address: string): Promise<string | null> {
try {
return (await tronService.getTrxBalanceSun(address)).toString();
} catch {
return null;
}
}
async function readBscUsdtBalance(address: string, dbContract: string | null): Promise<string | null> {
try {
const contract = bscService.resolveUsdtContract(dbContract);
return (await bscService.getUsdtBalanceRaw(address, contract)).toString();
} catch {
return null;
}
}
async function readBscNativeWei(address: string): Promise<string | null> {
try {
return (await bscService.getNativeBalanceWei(address)).toString();
} catch {
return null;
}
}
export async function getTreasuryOverview() {
const types = await walletRepository.getWalletTypes();
@ -28,30 +64,45 @@ export async function getTreasuryOverview() {
let hotOnChainBalance: string | null = null;
let coldOnChainBalance: string | null = null;
let hotNativeBalance: string | null = null;
let coldNativeBalance: string | null = null;
let nativeSymbol: string | null = null;
let nativeDecimals: number | null = null;
let minNativeForWithdraw: string | null = null;
try {
if (hot?.address && wt.network === 'TRON') {
const contract =
config.blockchain.tron.usdtTrc20Contract || wt.contract_address || '';
if (contract) {
hotOnChainBalance = (
await tronService.getTrc20BalanceRaw(hot.address, contract)
).toString();
}
if (wt.code === USDT_TRC20_CODE || wt.network === 'TRON') {
nativeSymbol = 'TRX';
nativeDecimals = 6;
minNativeForWithdraw = MIN_TRX_SUN_FOR_WITHDRAWAL.toString();
const contract =
config.blockchain.tron.usdtTrc20Contract || wt.contract_address || '';
if (hot?.address) {
if (contract) hotOnChainBalance = await readTronTokenBalance(hot.address, contract);
hotNativeBalance = await readTronNativeSun(hot.address);
}
if (cold?.address && wt.network === 'TRON') {
const contract =
config.blockchain.tron.usdtTrc20Contract || wt.contract_address || '';
if (contract) {
coldOnChainBalance = (
await tronService.getTrc20BalanceRaw(cold.address, contract)
).toString();
}
if (cold?.address) {
if (contract) coldOnChainBalance = await readTronTokenBalance(cold.address, contract);
coldNativeBalance = await readTronNativeSun(cold.address);
}
} else if (wt.code === USDT_BEP20_CODE || wt.network === 'BSC') {
nativeSymbol = 'BNB';
nativeDecimals = 18;
minNativeForWithdraw = MIN_BNB_WEI_FOR_WITHDRAWAL.toString();
if (hot?.address) {
hotOnChainBalance = await readBscUsdtBalance(hot.address, wt.contract_address);
hotNativeBalance = await readBscNativeWei(hot.address);
}
if (cold?.address) {
coldOnChainBalance = await readBscUsdtBalance(cold.address, wt.contract_address);
coldNativeBalance = await readBscNativeWei(cold.address);
}
} catch {
// RPC errors — balances stay null
}
const hotNativeOk =
hotNativeBalance != null && minNativeForWithdraw != null
? BigInt(hotNativeBalance) >= BigInt(minNativeForWithdraw)
: null;
return {
walletType: wt,
coldWallet: cold
@ -60,6 +111,12 @@ export async function getTreasuryOverview() {
hotWallet: hot ? { id: hot.id, address: hot.address, isActive: hot.is_active } : null,
hotOnChainBalance,
coldOnChainBalance,
hotNativeBalance,
coldNativeBalance,
nativeSymbol,
nativeDecimals,
minNativeForWithdraw,
hotNativeOk,
};
})
);

View File

@ -47,6 +47,12 @@ type TreasuryOverview = {
hotWallet: { id: string; address: string } | null;
hotOnChainBalance: string | null;
coldOnChainBalance: string | null;
hotNativeBalance: string | null;
coldNativeBalance: string | null;
nativeSymbol: string | null;
nativeDecimals: number | null;
minNativeForWithdraw: string | null;
hotNativeOk: boolean | null;
}>;
recentPendingSweeps: number;
recentFailedSweeps: number;
@ -78,8 +84,24 @@ type SweepRow = {
function formatRaw(amount: string | null, decimals: number): string {
if (amount == null) return '—';
const n = Number(amount) / 10 ** decimals;
return Number.isFinite(n) ? n.toLocaleString(undefined, { maximumFractionDigits: 6 }) : amount;
try {
const raw = BigInt(amount);
const base = 10n ** BigInt(decimals);
const whole = raw / base;
const frac = raw % base;
if (frac === 0n) return whole.toString();
const fracStr = frac.toString().padStart(decimals, '0').replace(/0+$/, '');
return `${whole.toString()}.${fracStr}`;
} catch {
return amount;
}
}
function explorerUrl(network: string, address: string): string | null {
if (!address || address === '—') return null;
if (network === 'BSC') return `https://bscscan.com/address/${address}`;
if (network === 'TRON') return `https://tronscan.org/#/address/${address}`;
return null;
}
export function TreasuryAdminPage() {
@ -197,12 +219,18 @@ export function TreasuryAdminPage() {
<Alert severity="info">{t('admin.treasury.sweepDisabledHint')}</Alert>
)}
<Alert severity="info">{t('admin.treasury.gasHint')}</Alert>
{overview.assets.map((asset) => {
const wt = asset.walletType;
const form = coldForms[wt.id] ?? {
address: asset.coldWallet?.address ?? '',
label: asset.coldWallet?.label ?? '',
};
const nativeDec = asset.nativeDecimals ?? 18;
const hotExplorer = asset.hotWallet?.address
? explorerUrl(wt.network, asset.hotWallet.address)
: null;
return (
<Card key={wt.id} sx={{ borderRadius: 2 }}>
<CardContent>
@ -216,12 +244,54 @@ export function TreasuryAdminPage() {
balance: formatRaw(asset.coldOnChainBalance, wt.decimals),
})}
</Typography>
{asset.nativeSymbol && asset.coldWallet?.address && (
<Typography>
{t('admin.treasury.coldGasOnChain', {
symbol: asset.nativeSymbol,
balance: formatRaw(asset.coldNativeBalance, nativeDec),
})}
</Typography>
)}
<Typography>
{t('admin.treasury.hotOnChain', {
address: asset.hotWallet?.address ?? '—',
balance: formatRaw(asset.hotOnChainBalance, wt.decimals),
})}
</Typography>
{asset.nativeSymbol && asset.hotWallet?.address && (
<Stack direction="row" spacing={1} alignItems="center" useFlexGap sx={{ flexWrap: 'wrap' }}>
<Typography>
{t('admin.treasury.hotGasOnChain', {
symbol: asset.nativeSymbol,
balance: formatRaw(asset.hotNativeBalance, nativeDec),
})}
</Typography>
{asset.hotNativeOk === true && (
<Chip size="small" color="success" label={t('admin.treasury.gasOk')} />
)}
{asset.hotNativeOk === false && (
<Chip
size="small"
color="warning"
label={t('admin.treasury.gasLow', {
min: formatRaw(asset.minNativeForWithdraw, nativeDec),
symbol: asset.nativeSymbol,
})}
/>
)}
{hotExplorer && (
<Button
size="small"
href={hotExplorer}
target="_blank"
rel="noopener noreferrer"
sx={{ textTransform: 'none' }}
>
{t('admin.treasury.viewOnExplorer')}
</Button>
)}
</Stack>
)}
</Stack>
<Stack direction={{ xs: 'column', sm: 'row' }} spacing={1}>
<TextField

View File

@ -1524,8 +1524,15 @@ export const en = {
failedSweeps: '{{count}} failed sweeps',
sweepDisabledHint:
'Set SWEEP_ENABLED=true in backend .env to auto-move deposits to cold storage.',
coldOnChain: 'Cold: {{address}} · on-chain {{balance}}',
hotOnChain: 'Hot: {{address}} · on-chain {{balance}}',
coldOnChain: 'Cold: {{address}} · USDT {{balance}}',
hotOnChain: 'Hot: {{address}} · USDT {{balance}}',
coldGasOnChain: 'Cold gas ({{symbol}}): {{balance}}',
hotGasOnChain: 'Hot gas ({{symbol}}): {{balance}}',
gasOk: 'enough for withdrawals',
gasLow: 'below min {{min}} {{symbol}} — top up before withdrawals',
gasHint:
'Native gas (BNB / TRX) is not a platform ledger balance. It stays on the hot wallet on-chain and is checked live before each withdrawal. History: use the explorer link.',
viewOnExplorer: 'View on explorer',
coldAddress: 'Cold wallet address',
label: 'Label',
saveCold: 'Save cold',

View File

@ -1540,8 +1540,15 @@ export const fr = {
failedSweeps: '{{count}} sweep(s) échoué(s)',
sweepDisabledHint:
'Définissez SWEEP_ENABLED=true dans le .env backend pour déplacer automatiquement les dépôts vers le cold storage.',
coldOnChain: 'Cold : {{address}} · on-chain {{balance}}',
hotOnChain: 'Hot : {{address}} · on-chain {{balance}}',
coldOnChain: 'Cold : {{address}} · USDT {{balance}}',
hotOnChain: 'Hot : {{address}} · USDT {{balance}}',
coldGasOnChain: 'Gas cold ({{symbol}}) : {{balance}}',
hotGasOnChain: 'Gas hot ({{symbol}}) : {{balance}}',
gasOk: 'suffisant pour les retraits',
gasLow: 'sous le minimum {{min}} {{symbol}} — rechargez avant les retraits',
gasHint:
'Le gas natif (BNB / TRX) n’est pas un solde ledger Prediqo. Il reste on-chain sur le hot wallet et est vérifié en direct avant chaque retrait. Historique : lien explorateur.',
viewOnExplorer: 'Voir sur l’explorateur',
coldAddress: 'Adresse cold wallet',
label: 'Libellé',
saveCold: 'Enregistrer cold',