{"version":3,"file":"Amount.mjs","sources":["../../src/Amount.ts"],"sourcesContent":["import {\n  NumberSerializer,\n  Serializer,\n  mapSerializer,\n} from '@metaplex-foundation/umi-serializers';\nimport { BigIntInput, createBigInt } from './BigInt';\nimport { AmountMismatchError, UnexpectedAmountError } from './errors';\n\n/**\n * The identifier of an amount.\n * @category Utils — Amounts\n */\nexport type AmountIdentifier = 'SOL' | 'USD' | '%' | 'splToken' | string;\n\n/**\n * The number of decimals in an amount represented using the lowest possible unit.\n * @category Utils — Amounts\n */\nexport type AmountDecimals = number;\n\n/**\n * Describes an amount of any type or currency using the lowest possible unit.\n * It uses a BigInt to represent the basis points of the amount, a decimal number\n * to know how to interpret the basis points, and an identifier to know what\n * type of amount we are dealing with.\n *\n * Custom type parameters can be used to represent specific types of amounts.\n * For example:\n * - Amount<'SOL', 9> represents an amount of SOL in lamports.\n * - Amount<'USD', 2> represents an amount of USD in cents.\n * - Amount<'%', 2> represents a percentage with 2 decimals.\n *\n * @category Utils — Amounts\n */\nexport type Amount<\n  I extends AmountIdentifier = AmountIdentifier,\n  D extends AmountDecimals = AmountDecimals\n> = {\n  /** The amount in its lower possible unit such that it does not contain decimals. */\n  basisPoints: bigint;\n  /** The identifier of the amount. */\n  identifier: I;\n  /** The number of decimals in the amount. */\n  decimals: D;\n};\n\n/**\n * An amount of SOL represented using the lowest possible unit — i.e. lamports.\n * @category Utils — Amounts\n */\nexport type SolAmount = Amount<'SOL', 9>;\n\n/**\n * An amount of US dollars represented using the lowest possible unit — i.e. cents.\n * @category Utils — Amounts\n */\nexport type UsdAmount = Amount<'USD', 2>;\n\n/**\n * An amount of SOL represented using the micro units — i.e. microlamports.\n * @category Utils — Amounts\n */\nexport type MicroSolAmount = Amount<'uSOL', 15>;\n\n/**\n * An percentage represented in basis points using a given number of decimals.\n * @category Utils — Amounts\n */\nexport type PercentAmount<D extends AmountDecimals> = Amount<'%', D>;\n\n/**\n * Creates an amount from the provided basis points, identifier, and decimals.\n * @category Utils — Amounts\n */\nexport const createAmount = <\n  I extends AmountIdentifier,\n  D extends AmountDecimals\n>(\n  basisPoints: BigIntInput,\n  identifier: I,\n  decimals: D\n): Amount<I, D> => ({\n  basisPoints: createBigInt(basisPoints),\n  identifier,\n  decimals,\n});\n\n/**\n * Creates an amount from a decimal value which will be converted to the lowest\n * possible unit using the provided decimals.\n * @category Utils — Amounts\n */\nexport const createAmountFromDecimals = <\n  I extends AmountIdentifier,\n  D extends AmountDecimals\n>(\n  decimalAmount: number,\n  identifier: I,\n  decimals: D\n): Amount<I, D> => {\n  const exponentAmount = createAmount(\n    BigInt(10) ** BigInt(decimals ?? 0),\n    identifier,\n    decimals\n  );\n\n  return multiplyAmount(exponentAmount, decimalAmount);\n};\n\n/**\n * Creates a percentage amount from the provided decimal value.\n * @category Utils — Amounts\n */\nexport const percentAmount = <D extends AmountDecimals>(\n  percent: number,\n  decimals: D = 2 as D\n): Amount<'%', D> => createAmountFromDecimals(percent, '%', decimals);\n\n/**\n * Creates an amount of SPL tokens from the provided decimal value.\n * @category Utils — Amounts\n */\nexport const tokenAmount = <\n  I extends AmountIdentifier,\n  D extends AmountDecimals\n>(\n  tokens: number,\n  identifier?: I,\n  decimals?: D\n): Amount<I, D> =>\n  createAmountFromDecimals(\n    tokens,\n    (identifier ?? 'splToken') as I,\n    (decimals ?? 0) as D\n  );\n\n/**\n * Creates a {@link SolAmount} from the provided lamports.\n * @category Utils — Amounts\n */\nexport const lamports = (lamports: BigIntInput): SolAmount =>\n  createAmount(lamports, 'SOL', 9);\n\n/**\n * Creates a {@link SolAmount} from the provided decimal value in SOL.\n * @category Utils — Amounts\n */\nexport const sol = (sol: number): SolAmount =>\n  createAmountFromDecimals(sol, 'SOL', 9);\n\n/**\n * Creates a {@link UsdAmount} from the provided decimal value in USD.\n * @category Utils — Amounts\n */\nexport const usd = (usd: number): UsdAmount =>\n  createAmountFromDecimals(usd, 'USD', 2);\n\n/**\n * Creates a {@link MicroSolAmount} from the provided micro lamports.\n * @category Utils — Amounts\n */\nexport const microLamports = (microLamports: BigIntInput): MicroSolAmount =>\n  createAmount(microLamports, 'uSOL', 15);\n\n/**\n * Creates a {@link MicroSolAmount} from the provided decimal value in SOL.\n * @category Utils — Amounts\n */\nexport const microSol = (sol: number): MicroSolAmount =>\n  createAmountFromDecimals(sol, 'uSOL', 15);\n\n/**\n * Determines whether a given amount has the provided identifier and decimals.\n * @category Utils — Amounts\n */\nexport const isAmount = <I extends AmountIdentifier, D extends AmountDecimals>(\n  amount: Amount,\n  identifier: I,\n  decimals: D\n): amount is Amount<I, D> =>\n  amount.identifier === identifier && amount.decimals === decimals;\n\n/**\n * Determines whether a given amount is a {@link SolAmount}.\n * @category Utils — Amounts\n */\nexport const isSolAmount = (amount: Amount): amount is SolAmount =>\n  isAmount(amount, 'SOL', 9);\n\n/**\n * Determines whether two amounts are of the same type.\n * @category Utils — Amounts\n */\nexport const sameAmounts = (left: Amount, right: Amount): boolean =>\n  isAmount(left, right.identifier, right.decimals);\n\n/**\n * Ensures that a given amount has the provided identifier and decimals.\n * @category Utils — Amounts\n */\nexport function assertAmount<\n  I extends AmountIdentifier,\n  D extends AmountDecimals\n>(amount: Amount, identifier: I, decimals: D): asserts amount is Amount<I, D> {\n  if (!isAmount(amount, identifier, decimals)) {\n    throw new UnexpectedAmountError(amount, identifier, decimals);\n  }\n}\n\n/**\n * Ensures that a given amount is a {@link SolAmount}.\n * @category Utils — Amounts\n */\nexport function assertSolAmount(actual: Amount): asserts actual is SolAmount {\n  assertAmount(actual, 'SOL', 9);\n}\n\n/**\n * Ensures that two amounts are of the same type.\n * @category Utils — Amounts\n */\nexport function assertSameAmounts(\n  left: Amount,\n  right: Amount,\n  operation?: string\n) {\n  if (!sameAmounts(left, right)) {\n    throw new AmountMismatchError(left, right, operation);\n  }\n}\n\n/**\n * Adds two amounts of the same type.\n * @category Utils — Amounts\n */\nexport const addAmounts = <\n  I extends AmountIdentifier,\n  D extends AmountDecimals\n>(\n  left: Amount<I, D>,\n  right: Amount<I, D>\n): Amount<I, D> => {\n  assertSameAmounts(left, right, 'add');\n\n  return {\n    ...left,\n    basisPoints: left.basisPoints + right.basisPoints,\n  };\n};\n\n/**\n * Subtracts two amounts of the same type.\n * @category Utils — Amounts\n */\nexport const subtractAmounts = <\n  I extends AmountIdentifier,\n  D extends AmountDecimals\n>(\n  left: Amount<I, D>,\n  right: Amount<I, D>\n): Amount<I, D> => {\n  assertSameAmounts(left, right, 'subtract');\n\n  return {\n    ...left,\n    basisPoints: left.basisPoints - right.basisPoints,\n  };\n};\n\n/**\n * Multiplies an amount by a given multiplier.\n * @category Utils — Amounts\n */\nexport const multiplyAmount = <\n  I extends AmountIdentifier,\n  D extends AmountDecimals\n>(\n  left: Amount<I, D>,\n  multiplier: number | bigint\n): Amount<I, D> => {\n  if (typeof multiplier === 'bigint') {\n    return { ...left, basisPoints: left.basisPoints * multiplier };\n  }\n\n  const [units, decimals] = multiplier.toString().split('.');\n  const multiplierBasisPoints = BigInt(units + (decimals ?? ''));\n  const multiplierExponents = BigInt(10) ** BigInt(decimals?.length ?? 0);\n\n  return {\n    ...left,\n    basisPoints:\n      (left.basisPoints * multiplierBasisPoints) / multiplierExponents,\n  };\n};\n\n/**\n * Divides an amount by a given divisor.\n * @category Utils — Amounts\n */\nexport const divideAmount = <\n  I extends AmountIdentifier,\n  D extends AmountDecimals\n>(\n  left: Amount<I, D>,\n  divisor: number | bigint\n): Amount<I, D> => {\n  if (typeof divisor === 'bigint') {\n    return { ...left, basisPoints: left.basisPoints / divisor };\n  }\n\n  const [units, decimals] = divisor.toString().split('.');\n  const divisorBasisPoints = BigInt(units + (decimals ?? ''));\n  const divisorExponents = BigInt(10) ** BigInt(decimals?.length ?? 0);\n\n  return {\n    ...left,\n    basisPoints: (left.basisPoints * divisorExponents) / divisorBasisPoints,\n  };\n};\n\n/**\n * Returns the absolute value of an amount.\n * @category Utils — Amounts\n */\nexport const absoluteAmount = <\n  I extends AmountIdentifier,\n  D extends AmountDecimals\n>(\n  value: Amount<I, D>\n): Amount<I, D> => {\n  const x = value.basisPoints;\n  return { ...value, basisPoints: x < 0 ? -x : x };\n};\n\n/**\n * Compares two amounts of the same type.\n * @category Utils — Amounts\n */\nexport const compareAmounts = <\n  I extends AmountIdentifier,\n  D extends AmountDecimals\n>(\n  left: Amount<I, D>,\n  right: Amount<I, D>\n): -1 | 0 | 1 => {\n  assertSameAmounts(left, right, 'compare');\n  if (left.basisPoints > right.basisPoints) return 1;\n  if (left.basisPoints < right.basisPoints) return -1;\n  return 0;\n};\n\n/**\n * Determines whether two amounts are equal.\n * An optional tolerance can be provided to allow for small differences.\n * When using {@link SolAmount}, this is usually due to transaction or small storage fees.\n * @category Utils — Amounts\n */\nexport const isEqualToAmount = <\n  I extends AmountIdentifier,\n  D extends AmountDecimals\n>(\n  left: Amount<I, D>,\n  right: Amount<I, D>,\n  tolerance?: Amount<I, D>\n): boolean => {\n  tolerance = tolerance ?? createAmount(0, left.identifier, left.decimals);\n  assertSameAmounts(left, right, 'isEqualToAmount');\n  assertSameAmounts(left, tolerance, 'isEqualToAmount');\n\n  const delta = absoluteAmount(subtractAmounts(left, right));\n\n  return isLessThanOrEqualToAmount(delta, tolerance);\n};\n\n/**\n * Whether the left amount is less than the right amount.\n * @category Utils — Amounts\n */\nexport const isLessThanAmount = <\n  I extends AmountIdentifier,\n  D extends AmountDecimals\n>(\n  left: Amount<I, D>,\n  right: Amount<I, D>\n): boolean => compareAmounts(left, right) < 0;\n\n/**\n * Whether the left amount is less than or equal to the right amount.\n * @category Utils — Amounts\n */\nexport const isLessThanOrEqualToAmount = <\n  I extends AmountIdentifier,\n  D extends AmountDecimals\n>(\n  left: Amount<I, D>,\n  right: Amount<I, D>\n): boolean => compareAmounts(left, right) <= 0;\n\n/**\n * Whether the left amount is greater than the right amount.\n * @category Utils — Amounts\n */\nexport const isGreaterThanAmount = <\n  I extends AmountIdentifier,\n  D extends AmountDecimals\n>(\n  left: Amount<I, D>,\n  right: Amount<I, D>\n): boolean => compareAmounts(left, right) > 0;\n\n/**\n * Whether the left amount is greater than or equal to the right amount.\n * @category Utils — Amounts\n */\nexport const isGreaterThanOrEqualToAmount = <\n  I extends AmountIdentifier,\n  D extends AmountDecimals\n>(\n  left: Amount<I, D>,\n  right: Amount<I, D>\n): boolean => compareAmounts(left, right) >= 0;\n\n/**\n * Whether the amount is zero.\n * @category Utils — Amounts\n */\nexport const isZeroAmount = (value: Amount): boolean =>\n  value.basisPoints === BigInt(0);\n\n/**\n * Whether the amount is positive.\n * @category Utils — Amounts\n */\nexport const isPositiveAmount = (value: Amount): boolean =>\n  value.basisPoints >= BigInt(0);\n\n/**\n * Whether the amount is negative.\n * @category Utils — Amounts\n */\nexport const isNegativeAmount = (value: Amount): boolean =>\n  value.basisPoints < BigInt(0);\n\n/**\n * Converts an amount to a string by using the amount's decimals.\n * @category Utils — Amounts\n */\nexport const amountToString = (value: Amount, maxDecimals?: number): string => {\n  let text = value.basisPoints.toString();\n  if (value.decimals === 0) {\n    return text;\n  }\n\n  const sign = text.startsWith('-') ? '-' : '';\n  text = text.replace('-', '');\n  text = text.padStart(value.decimals + 1, '0');\n  const units = text.slice(0, -value.decimals);\n  let decimals = text.slice(-value.decimals);\n\n  if (maxDecimals !== undefined) {\n    decimals = decimals.slice(0, maxDecimals);\n  }\n\n  return `${sign + units}.${decimals}`;\n};\n\n/**\n * Converts an amount to a number by using the amount's decimals.\n * Note that this may throw an error if the amount is too large to fit in a JavaScript number.\n * @category Utils — Amounts\n */\nexport const amountToNumber = (value: Amount): number =>\n  parseFloat(amountToString(value));\n\n/**\n * Displays an amount as a string by using the amount's decimals and identifier.\n * @category Utils — Amounts\n */\nexport const displayAmount = (value: Amount, maxDecimals?: number): string => {\n  const amountAsString = amountToString(value, maxDecimals);\n\n  switch (value.identifier) {\n    case '%':\n      return `${amountAsString}%`;\n    case 'splToken':\n      return /^1(\\.0+)?$/.test(amountAsString)\n        ? `${amountAsString} Token`\n        : `${amountAsString} Tokens`;\n    default:\n      if (value.identifier.startsWith('splToken.')) {\n        const [, identifier] = value.identifier.split('.');\n        return `${identifier} ${amountAsString}`;\n      }\n      return `${value.identifier} ${amountAsString}`;\n  }\n};\n\n/**\n * Converts a number serializer into an amount serializer\n * by providing an amount identifier and decimals.\n * @category Utils — Amounts\n */\nexport const mapAmountSerializer = <\n  I extends AmountIdentifier = AmountIdentifier,\n  D extends AmountDecimals = AmountDecimals\n>(\n  serializer: NumberSerializer,\n  identifier: I,\n  decimals: D\n): Serializer<Amount<I, D>> =>\n  mapSerializer(\n    serializer as Serializer<number | bigint>,\n    (value: Amount<I, D>): number | bigint =>\n      value.basisPoints > Number.MAX_SAFE_INTEGER\n        ? value.basisPoints\n        : Number(value.basisPoints),\n    (value: number | bigint): Amount<I, D> =>\n      createAmount(value, identifier, decimals)\n  );\n"],"names":["createAmount","basisPoints","identifier","decimals","createBigInt","createAmountFromDecimals","decimalAmount","exponentAmount","BigInt","multiplyAmount","percentAmount","percent","tokenAmount","tokens","lamports","sol","usd","microLamports","microSol","isAmount","amount","isSolAmount","sameAmounts","left","right","assertAmount","UnexpectedAmountError","assertSolAmount","actual","assertSameAmounts","operation","AmountMismatchError","addAmounts","subtractAmounts","multiplier","units","toString","split","multiplierBasisPoints","multiplierExponents","length","divideAmount","divisor","divisorBasisPoints","divisorExponents","absoluteAmount","value","x","compareAmounts","isEqualToAmount","tolerance","delta","isLessThanOrEqualToAmount","isLessThanAmount","isGreaterThanAmount","isGreaterThanOrEqualToAmount","isZeroAmount","isPositiveAmount","isNegativeAmount","amountToString","maxDecimals","text","sign","startsWith","replace","padStart","slice","undefined","amountToNumber","parseFloat","displayAmount","amountAsString","test","mapAmountSerializer","serializer","mapSerializer","Number","MAX_SAFE_INTEGER"],"mappings":";;;;;AAQA;AACA;AACA;AACA;;AA2DA;AACA;AACA;AACA;AACO,MAAMA,YAAY,GAAG,CAI1BC,WAAwB,EACxBC,UAAa,EACbC,QAAW,MACO;AAClBF,EAAAA,WAAW,EAAEG,YAAY,C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