UNPKG

@radixdlt/primitives

Version:
27 lines 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Amount = exports.isAmountOrUnsafeInput = exports.isAmount = exports.isAmountUnsafeInput = void 0; const uint256_extensions_1 = require("./uint256-extensions"); const neverthrow_1 = require("neverthrow"); const uint256_1 = require("@radixdlt/uint256"); const isAmountUnsafeInput = (something) => (0, uint256_extensions_1.isUnsafeInputForUInt256)(something); exports.isAmountUnsafeInput = isAmountUnsafeInput; const isAmount = (something) => (0, uint256_extensions_1.isUInt256)(something); exports.isAmount = isAmount; const isAmountOrUnsafeInput = (something) => (0, exports.isAmount)(something) || (0, exports.isAmountUnsafeInput)(something); exports.isAmountOrUnsafeInput = isAmountOrUnsafeInput; const fromUnsafe = (input) => (0, exports.isAmount)(input) ? (0, neverthrow_1.ok)(input) : (0, exports.isAmountUnsafeInput)(input) ? (0, uint256_extensions_1.uint256FromUnsafe)(input) : (0, neverthrow_1.err)(new Error(`Unable to construct 'AmountT' because of bad input: '${JSON.stringify(input, null, 4)}'`)); const isAmountMultipleOf = (input) => { const { amount, granularity: other } = input; const zero = uint256_1.UInt256.valueOf(0); return amount.mod(other, false).eq(zero); }; exports.Amount = { fromUnsafe, isAmountMultipleOf, }; //# sourceMappingURL=amount.js.map