41 lines
1.8 KiB
JavaScript
41 lines
1.8 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Withdrawal network fee helpers (USDT deducted from user ledger).
|
|
*/
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.USDT_DECIMALS = exports.USDT_FEE_SETTING_DECIMALS = void 0;
|
|
exports.getWithdrawalNetworkFeeRaw = getWithdrawalNetworkFeeRaw;
|
|
exports.formatUsdtRawHuman = formatUsdtRawHuman;
|
|
/** Canonical micro units for the admin setting (6 decimal places). */
|
|
exports.USDT_FEE_SETTING_DECIMALS = 6;
|
|
/** @deprecated Use USDT_FEE_SETTING_DECIMALS */
|
|
exports.USDT_DECIMALS = exports.USDT_FEE_SETTING_DECIMALS;
|
|
/**
|
|
* Returns the configured network fee in smallest units for the given wallet decimals.
|
|
* Setting is stored as 6-decimal micro-USDT; scaled when wallet decimals differ (e.g. BEP20 18).
|
|
*/
|
|
function getWithdrawalNetworkFeeRaw(settings, walletDecimals = 6) {
|
|
const micro = settings.withdrawal_network_fee_usdt_micro;
|
|
if (!Number.isFinite(micro) || micro < 0)
|
|
return 0n;
|
|
const base = BigInt(Math.floor(micro));
|
|
if (walletDecimals === exports.USDT_FEE_SETTING_DECIMALS)
|
|
return base;
|
|
if (walletDecimals > exports.USDT_FEE_SETTING_DECIMALS) {
|
|
return base * 10n ** BigInt(walletDecimals - exports.USDT_FEE_SETTING_DECIMALS);
|
|
}
|
|
return base / 10n ** BigInt(exports.USDT_FEE_SETTING_DECIMALS - walletDecimals);
|
|
}
|
|
/**
|
|
* Formats a raw USDT amount for display (trims trailing zeros).
|
|
*/
|
|
function formatUsdtRawHuman(raw, decimals = exports.USDT_FEE_SETTING_DECIMALS) {
|
|
if (decimals <= 0)
|
|
return raw.toString();
|
|
const divisor = 10n ** BigInt(decimals);
|
|
const intPart = raw / divisor;
|
|
const frac = raw % divisor;
|
|
const fracStr = frac.toString().padStart(decimals, '0').replace(/0+$/, '');
|
|
return fracStr ? `${intPart}.${fracStr}` : intPart.toString();
|
|
}
|
|
//# sourceMappingURL=withdrawalFee.js.map
|