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