56 lines
2.5 KiB
JavaScript
56 lines
2.5 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.scaleUsdtMicroToWalletRaw = scaleUsdtMicroToWalletRaw;
|
|
exports.getWithdrawalNetworkFeeRaw = getWithdrawalNetworkFeeRaw;
|
|
exports.getTransferMinRemainingRaw = getTransferMinRemainingRaw;
|
|
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;
|
|
/**
|
|
* Scales a 6-decimal micro-USDT admin setting to wallet raw units.
|
|
* Used for withdrawal fees and transfer minimum-remaining balance.
|
|
*/
|
|
function scaleUsdtMicroToWalletRaw(micro, walletDecimals = 6) {
|
|
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);
|
|
}
|
|
/**
|
|
* 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) {
|
|
return scaleUsdtMicroToWalletRaw(settings.withdrawal_network_fee_usdt_micro, walletDecimals);
|
|
}
|
|
/**
|
|
* Minimum remaining main-wallet balance after a peer transfer (0 = disabled).
|
|
* Stored as 6-decimal micro-USDT; scaled to wallet decimals when needed.
|
|
*/
|
|
function getTransferMinRemainingRaw(settings, walletDecimals = 6) {
|
|
return scaleUsdtMicroToWalletRaw(settings.transfer_min_remaining_usdt_micro, 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
|