{"version":3,"file":"amount.mjs","names":[],"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"],"mappings":";;;AAGA,IAAa,aAAb,MAAa,WAAW;CACtB;;CAGA,IAAI,aAAa;EACf,OAAO,KAAK;CACd;;CAGA,IAAI,YAAY;EACd,OAAO,KAAK;CACd;;CAGA,IAAI,QAAQ;EACV,OAAO,QAAQ,kBAAkB,OAAO,KAAK,iBAAiB,CAAC;CACjE;;CAGA,IAAI,OAAO;EACT,OAAO,QAAQ,kBAAkB,OAAO,KAAK,iBAAiB,CAAC;CACjE;;;;;;;;;;;CAYA,YACE,QACA;EACA,KAAK,oBACH,gBAAgB,SACZ,OAAO,OAAO,UAAU,IACxB,eAAe,SACb,OAAO,OAAO,SAAS,IACvB,WAAW,SACT,OAAO,QAAQ,kBAAkB,OAAO,OAAO,KAAK,CAAC,CAAC,IACtD,OAAO,QAAQ,kBAAkB,OAAO,OAAO,IAAI,CAAC,CAAC;CACjE;CAEA,WAAmB;EACjB,OAAO,GAAG,KAAK,UAAU,eAAe,OAAO,EAAE;CACnD;;;;;CAMA,UAAkB;EAChB,OAAO,OAAO,KAAK,SAAS;CAC9B;;CAGA,OAAO,MAAM,QAAyB;EACpC,OAAO,IAAI,WAAW,EAAE,OAAO,OAAO,CAAC;CACzC;;CAGA,OAAO,KAAK,QAAyB;EACnC,OAAO,IAAI,WAAW,EAAE,OAAO,OAAO,CAAC;CACzC;;CAGA,OAAO,WAAW,QAAyB;EACzC,OAAO,IAAI,WAAW,EAAE,YAAY,OAAO,CAAC;CAC9C;;CAGA,OAAO,UAAU,QAAyB;EACxC,OAAO,IAAI,WAAW,EAAE,YAAY,OAAO,CAAC;CAC9C;AACF"}