41 lines
1.5 KiB
JavaScript
41 lines
1.5 KiB
JavaScript
"use strict";
|
|
/**
|
|
* USDT unit helpers: platform ledger uses 6 decimals; BEP20 chain uses 18.
|
|
*/
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.BEP20_USDT_DECIMALS = exports.LEDGER_USDT_DECIMALS = void 0;
|
|
exports.scaleChainToLedger = scaleChainToLedger;
|
|
exports.scaleLedgerToChain = scaleLedgerToChain;
|
|
exports.networkForWalletCode = networkForWalletCode;
|
|
exports.LEDGER_USDT_DECIMALS = 6;
|
|
exports.BEP20_USDT_DECIMALS = 18;
|
|
/** Truncate chain (18) amount down to ledger micro-USDT (6). */
|
|
function scaleChainToLedger(amount, fromDecimals, toDecimals = exports.LEDGER_USDT_DECIMALS) {
|
|
if (amount < 0n)
|
|
return 0n;
|
|
if (fromDecimals === toDecimals)
|
|
return amount;
|
|
if (fromDecimals > toDecimals) {
|
|
return amount / 10n ** BigInt(fromDecimals - toDecimals);
|
|
}
|
|
return amount * 10n ** BigInt(toDecimals - fromDecimals);
|
|
}
|
|
/** Scale ledger micro-USDT (6) up to chain units (e.g. BEP20 18). */
|
|
function scaleLedgerToChain(amount, toDecimals, fromDecimals = exports.LEDGER_USDT_DECIMALS) {
|
|
if (amount < 0n)
|
|
return 0n;
|
|
if (fromDecimals === toDecimals)
|
|
return amount;
|
|
if (toDecimals > fromDecimals) {
|
|
return amount * 10n ** BigInt(toDecimals - fromDecimals);
|
|
}
|
|
return amount / 10n ** BigInt(fromDecimals - toDecimals);
|
|
}
|
|
function networkForWalletCode(code) {
|
|
if (code === 'USDT_TRC20')
|
|
return 'TRON';
|
|
if (code === 'USDT_BEP20')
|
|
return 'BSC';
|
|
return null;
|
|
}
|
|
//# sourceMappingURL=usdtUnits.js.map
|