{"version":3,"file":"amount.mjs","sources":["../../src/types/amount.ts"],"sourcesContent":["import algosdk from 'algosdk'\n\n/** Wrapper class to ensure safe, explicit conversion between µAlgo, Algo and numbers */\nexport class AlgoAmount {\n  private amountInMicroAlgo: bigint\n\n  /** Return the amount as a number in µAlgo */\n  get microAlgos() {\n    return this.amountInMicroAlgo\n  }\n\n  /** Return the amount as a number in µAlgo */\n  get microAlgo() {\n    return this.amountInMicroAlgo\n  }\n\n  /** Return the amount as a number in Algo */\n  get algos() {\n    return algosdk.microalgosToAlgos(Number(this.amountInMicroAlgo))\n  }\n\n  /** Return the amount as a number in Algo */\n  get algo() {\n    return algosdk.microalgosToAlgos(Number(this.amountInMicroAlgo))\n  }\n\n  /**\n   * Create a new `AlgoAmount` instance.\n   *\n   * @param amount - An object specifying the amount in Algo or µALGO. Use the key 'algo' for Algo amounts and 'microAlgo' for µALGO.\n   * @returns A new instance of `AlgoAmount` representing the specified amount.\n   * @example\n   * ```typescript\n   * const amount = new AlgoAmount({ algo: 5 });\n   * ```\n   */\n  constructor(\n    amount: { algos: number | bigint } | { algo: number | bigint } | { microAlgos: number | bigint } | { microAlgo: number | bigint },\n  ) {\n    this.amountInMicroAlgo =\n      'microAlgos' in amount\n        ? BigInt(amount.microAlgos)\n        : 'microAlgo' in amount\n          ? BigInt(amount.microAlgo)\n          : 'algos' in amount\n            ? BigInt(algosdk.algosToMicroalgos(Number(amount.algos)))\n            : BigInt(algosdk.algosToMicroalgos(Number(amount.algo)))\n  }\n\n  toString(): string {\n    return `${this.microAlgo.toLocaleString('en-US')} µALGO`\n  }\n\n  /** valueOf allows you to use `AlgoAmount` in comparison operations such as `<` and `>=` etc.,\n   * but it's not recommended to use this to convert to a number, it's much safer to explicitly call\n   * the algos or microAlgos properties\n   */\n  valueOf(): number {\n    return Number(this.microAlgo)\n  }\n\n  /** Create a `AlgoAmount` object representing the given number of Algo */\n  static Algos(amount: number | bigint) {\n    return new AlgoAmount({ algos: amount })\n  }\n\n  /** Create a `AlgoAmount` object representing the given number of Algo */\n  static Algo(amount: number | bigint) {\n    return new AlgoAmount({ algos: amount })\n  }\n\n  /** Create a `AlgoAmount` object representing the given number of µAlgo */\n  static MicroAlgos(amount: number | bigint) {\n    return new AlgoAmount({ microAlgos: amount })\n  }\n\n  /** Create a `AlgoAmount` object representing the given number of µAlgo */\n  static MicroAlgo(amount: number | bigint) {\n    return new AlgoAmount({ microAlgos: amount })\n  }\n}\n"],"names":[],"mappings":";;AAEA;MACa,UAAU,CAAA;;AAIrB,IAAA,IAAI,UAAU,GAAA;QACZ,OAAO,IAAI,CAAC,iBAAiB;;;AAI/B,IAAA,IAAI,SAAS,GAAA;QACX,OAAO,IAAI,CAAC,iBAAiB;;;AAI/B,IAAA,IAAI,KAAK,GAAA;QACP,OAAO,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;;;AAIlE,IAAA,IAAI,IAAI,GAAA;QACN,OAAO,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;;AAGlE;;;;;;;;;AASG;AACH,IAAA,WAAA,CACE,MAAiI,EAAA;AAEjI,QAAA,IAAI,CAAC,iBAAiB;AACpB,YAAA,YAAY,IAAI;AACd,kBAAE,MAAM,CAAC,MAAM,CAAC,UAAU;kBACxB,WAAW,IAAI;AACf,sBAAE,MAAM,CAAC,MAAM,CAAC,SAAS;sBACvB,OAAO,IAAI;AACX,0BAAE,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACxD,0BAAE,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;;IAGlE,QAAQ,GAAA;QACN,OAAO,CAAA,EAAG,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA,MAAA,CAAQ;;AAG1D;;;AA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