@neuraiproject/neurai-assets 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -4419,6 +4419,11 @@ function requireBaseAssetTransactionBuilder () {
4419
4419
  this.ownerTokenManager = new OwnerTokenManager(rpc);
4420
4420
  this.utxoSelector = new UTXOSelector(rpc);
4421
4421
  this.outputOrderer = new OutputOrderer();
4422
+
4423
+ // `estimatesmartfee` is called twice per build (pre-selection guess and
4424
+ // post-selection recompute). The fee rate is stable for the duration of
4425
+ // a single build, so cache the first lookup and reuse it.
4426
+ this._feeRatePromise = null;
4422
4427
  }
4423
4428
 
4424
4429
  /**
@@ -4465,7 +4470,10 @@ function requireBaseAssetTransactionBuilder () {
4465
4470
  * @returns {Promise<number>} Estimated fee in XNA
4466
4471
  */
4467
4472
  async estimateFee(inputs, outputs) {
4468
- const feeRate = await this.utxoSelector.getFeeRate();
4473
+ if (!this._feeRatePromise) {
4474
+ this._feeRatePromise = this.utxoSelector.getFeeRate();
4475
+ }
4476
+ const feeRate = await this._feeRatePromise;
4469
4477
  return this.utxoSelector.estimateFee(inputs, outputs, feeRate);
4470
4478
  }
4471
4479
 
@@ -4599,24 +4607,47 @@ function requireBaseAssetTransactionBuilder () {
4599
4607
  }
4600
4608
 
4601
4609
  /**
4602
- * Convert asset amount to protocol raw units.
4603
- * Asset raw quantities in transaction payloads are always encoded with
4604
- * 8 decimal places, regardless of the asset's displayed `units`.
4610
+ * Build the JSON `asset_quantity` value for a `createrawtransaction`
4611
+ * output (issue / reissue / tag change_quantity / etc.).
4612
+ *
4613
+ * The chain parses this field with `AmountFromValue()` (Bitcoin-style
4614
+ * decimal-XNA → 10^8 sats), then validates that the resulting CAmount
4615
+ * is a multiple of `10^(8 - units)` via `CheckAmountWithUnits`
4616
+ * (assets.cpp). So:
4617
+ *
4618
+ * - The JSON value MUST be the user-facing display amount
4619
+ * (e.g. "1" for one token, "1.5" for one and a half tokens).
4620
+ * - The lib must NOT pre-multiply by 10^8 or 10^units; the daemon
4621
+ * does the 10^8 scaling itself, and any extra factor here lands
4622
+ * duplicated and inflates the minted supply (or trips the
4623
+ * ParseFixedPoint `exponent >= 18` cap → "Invalid amount (3)").
4624
+ *
4625
+ * History: pre-1.2.2 multiplied by 10^units (correct only for units=0
4626
+ * assets, inflated everything else by 10^units). v1.2.2 changed to
4627
+ * always 10^8 (correct only for units=8, inflated everything else by
4628
+ * 10^8 — e.g. reissuing 1 token of a units=0 asset minted 100,000,000).
4629
+ * The right answer is to send the value untouched.
4630
+ *
4631
+ * The `units` parameter is kept for API compatibility but is unused.
4605
4632
  *
4606
4633
  * @param {number} amount - User-facing asset amount
4607
- * @param {number} units - Asset decimal places (kept for API compatibility)
4608
- * @returns {number} Amount in protocol raw units
4634
+ * @param {number} units - Asset decimal places (unused; kept for API)
4635
+ * @returns {number} The user-facing amount, ready for the JSON output
4609
4636
  */
4610
4637
  toSatoshis(amount, units) {
4611
- return Math.round(amount * 100000000);
4638
+ return amount;
4612
4639
  }
4613
4640
 
4614
4641
  /**
4615
- * Convert protocol raw units back to a user-facing asset amount.
4642
+ * Convert a chain-side asset balance / UTXO satoshis value back to a
4643
+ * user-facing amount. The chain consistently encodes asset balances
4644
+ * in 10^8 sats (because everything goes through AmountFromValue on
4645
+ * the way in), so the divisor is always 10^8 — independent of the
4646
+ * asset's `units`.
4616
4647
  *
4617
- * @param {number} satoshis - Amount in protocol raw units
4618
- * @param {number} units - Asset decimal places (kept for API compatibility)
4619
- * @returns {number} Amount in asset units
4648
+ * @param {number} satoshis - Chain value in 10^8 sats
4649
+ * @param {number} units - Asset decimal places (unused; kept for API)
4650
+ * @returns {number} User-facing asset amount
4620
4651
  */
4621
4652
  fromSatoshis(satoshis, units) {
4622
4653
  return satoshis / 100000000;