@routstr/sdk 0.2.3 → 0.2.4

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.mjs CHANGED
@@ -1513,9 +1513,13 @@ var BalanceManager = class {
1513
1513
  p2pkPubkey
1514
1514
  } = options;
1515
1515
  const adjustedAmount = Math.ceil(amount);
1516
- console.log(`[BalanceManager.createProviderToken] Starting: baseUrl=${baseUrl}, mintUrl=${mintUrl}, amount=${amount}, adjustedAmount=${adjustedAmount}, retryCount=${retryCount}`);
1516
+ console.log(
1517
+ `[BalanceManager.createProviderToken] Starting: baseUrl=${baseUrl}, mintUrl=${mintUrl}, amount=${amount}, adjustedAmount=${adjustedAmount}, retryCount=${retryCount}`
1518
+ );
1517
1519
  if (!adjustedAmount || isNaN(adjustedAmount)) {
1518
- console.error(`[BalanceManager.createProviderToken] FAILURE: Invalid amount - amount=${amount}, adjustedAmount=${adjustedAmount}`);
1520
+ console.error(
1521
+ `[BalanceManager.createProviderToken] FAILURE: Invalid amount - amount=${amount}, adjustedAmount=${adjustedAmount}`
1522
+ );
1519
1523
  return { success: false, error: "Invalid top up amount" };
1520
1524
  }
1521
1525
  const balanceState = await this.getBalanceState();
@@ -1546,15 +1550,11 @@ var BalanceManager = class {
1546
1550
  { url: "", balance: 0 }
1547
1551
  ).url
1548
1552
  );
1549
- console.error(`[BalanceManager.createProviderToken] FAILURE: Insufficient balance - required=${adjustedAmount}, available=${totalMintBalance + targetProviderBalance}, totalMintBalance=${totalMintBalance}, targetProviderBalance=${targetProviderBalance}, refundableProviderBalance=${refundableProviderBalance}`);
1553
+ console.error(
1554
+ `[BalanceManager.createProviderToken] FAILURE: Insufficient balance - required=${adjustedAmount}, available=${totalMintBalance + targetProviderBalance}, totalMintBalance=${totalMintBalance}, targetProviderBalance=${targetProviderBalance}, refundableProviderBalance=${refundableProviderBalance}`
1555
+ );
1550
1556
  return { success: false, error: error.message };
1551
1557
  }
1552
- if (targetProviderBalance >= adjustedAmount) {
1553
- return {
1554
- success: true,
1555
- amountSpent: 0
1556
- };
1557
- }
1558
1558
  const providerMints = baseUrl && this.providerRegistry ? this.providerRegistry.getProviderMints(baseUrl) : [];
1559
1559
  let requiredAmount = adjustedAmount;
1560
1560
  const supportedMintsOnly = providerMints.length > 0;
@@ -1588,7 +1588,9 @@ var BalanceManager = class {
1588
1588
  maxMintUrl = mintUrl2;
1589
1589
  }
1590
1590
  }
1591
- console.error(`[BalanceManager.createProviderToken] FAILURE: No candidate mints found - requiredAmount=${requiredAmount}, totalMintBalance=${totalMintBalance}, maxBalance=${maxBalance}, maxMintUrl=${maxMintUrl}, providerMints=${JSON.stringify(providerMints)}`);
1591
+ console.error(
1592
+ `[BalanceManager.createProviderToken] FAILURE: No candidate mints found - requiredAmount=${requiredAmount}, totalMintBalance=${totalMintBalance}, maxBalance=${maxBalance}, maxMintUrl=${maxMintUrl}, providerMints=${JSON.stringify(providerMints)}`
1593
+ );
1592
1594
  const error = new InsufficientBalanceError(
1593
1595
  adjustedAmount,
1594
1596
  totalMintBalance,
@@ -1600,13 +1602,17 @@ var BalanceManager = class {
1600
1602
  let lastError;
1601
1603
  for (const candidateMint of candidates) {
1602
1604
  try {
1603
- console.log(`[BalanceManager.createProviderToken] Attempting mint: ${candidateMint}, amount: ${requiredAmount}`);
1605
+ console.log(
1606
+ `[BalanceManager.createProviderToken] Attempting mint: ${candidateMint}, amount: ${requiredAmount}`
1607
+ );
1604
1608
  const token = await this.walletAdapter.sendToken(
1605
1609
  candidateMint,
1606
1610
  requiredAmount,
1607
1611
  p2pkPubkey
1608
1612
  );
1609
- console.log(`[BalanceManager.createProviderToken] SUCCESS: Token created from mint ${candidateMint}`);
1613
+ console.log(
1614
+ `[BalanceManager.createProviderToken] SUCCESS: Token created from mint ${candidateMint}`
1615
+ );
1610
1616
  return {
1611
1617
  success: true,
1612
1618
  token,
@@ -1615,11 +1621,15 @@ var BalanceManager = class {
1615
1621
  };
1616
1622
  } catch (error) {
1617
1623
  const errorMsg = error instanceof Error ? error.message : String(error);
1618
- console.error(`[BalanceManager.createProviderToken] FAILURE: Mint ${candidateMint} failed with error: ${errorMsg}`);
1624
+ console.error(
1625
+ `[BalanceManager.createProviderToken] FAILURE: Mint ${candidateMint} failed with error: ${errorMsg}`
1626
+ );
1619
1627
  if (error instanceof Error) {
1620
1628
  lastError = errorMsg;
1621
1629
  if (isNetworkErrorMessage(error.message)) {
1622
- console.warn(`[BalanceManager.createProviderToken] Network error from ${candidateMint}, trying next mint...`);
1630
+ console.warn(
1631
+ `[BalanceManager.createProviderToken] Network error from ${candidateMint}, trying next mint...`
1632
+ );
1623
1633
  continue;
1624
1634
  }
1625
1635
  }
@@ -1629,7 +1639,9 @@ var BalanceManager = class {
1629
1639
  };
1630
1640
  }
1631
1641
  }
1632
- console.error(`[BalanceManager.createProviderToken] FAILURE: All candidate mints exhausted - lastError=${lastError}, candidates=${JSON.stringify(candidates)}`);
1642
+ console.error(
1643
+ `[BalanceManager.createProviderToken] FAILURE: All candidate mints exhausted - lastError=${lastError}, candidates=${JSON.stringify(candidates)}`
1644
+ );
1633
1645
  return {
1634
1646
  success: false,
1635
1647
  error: lastError || "All candidate mints failed while creating top up token"