UNPKG

fsl-js-sdk

Version:
28 lines (27 loc) 1.15 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DecimalUtil = void 0; var spl_token_v0_1 = require("@solana/spl-token-v0"); var decimal_js_1 = __importDefault(require("decimal.js")); var DecimalUtil = /** @class */ (function () { function DecimalUtil() { } DecimalUtil.fromU64 = function (input, shift) { if (shift === void 0) { shift = 0; } return new decimal_js_1.default(input.toString()).div(new decimal_js_1.default(10).pow(shift)); }; DecimalUtil.toU64 = function (input, shift) { if (shift === void 0) { shift = 0; } if (input.isNeg()) { throw new Error('Negative decimal value ${input} cannot be converted to u64.'); } var shiftedValue = input.mul(new decimal_js_1.default(10).pow(shift)); var zeroDecimalValue = shiftedValue.trunc(); return new spl_token_v0_1.u64(zeroDecimalValue.toString()); }; return DecimalUtil; }()); exports.DecimalUtil = DecimalUtil;