@routstr/sdk 0.3.0 → 0.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.
@@ -1764,8 +1764,8 @@ var ProviderManager = class _ProviderManager {
1764
1764
  lastFailed = /* @__PURE__ */ new Map();
1765
1765
  /** Providers on cooldown: [provider_url, cooldown_started_timestamp][] */
1766
1766
  providersOnCoolDown = [];
1767
- /** Cooldown duration in milliseconds (5 minutes) */
1768
- static COOLDOWN_DURATION_MS = 5 * 60 * 1e3;
1767
+ /** Cooldown duration in milliseconds (42 seconds) */
1768
+ static COOLDOWN_DURATION_MS = 42 * 1e3;
1769
1769
  /** Optional persistent store for failure tracking */
1770
1770
  store = null;
1771
1771
  /** Instance ID for debugging */
@@ -4203,11 +4203,12 @@ var RoutstrClient = class {
4203
4203
  baseUrl
4204
4204
  );
4205
4205
  const currentBalance = currentBalanceInfo.unit === "msat" ? currentBalanceInfo.amount / 1e3 : currentBalanceInfo.amount;
4206
- const shortfall = Math.max(0, params.requiredSats - currentBalance);
4206
+ const reservedBalance = currentBalanceInfo.unit === "msat" ? (currentBalanceInfo.reserved ?? 0) / 1e3 : currentBalanceInfo.reserved ?? 0;
4207
+ const shortfall = Math.max(0, params.requiredSats - currentBalance + reservedBalance);
4207
4208
  topupAmount = shortfall > 0.21 * params.requiredSats ? shortfall : 0.21 * params.requiredSats;
4208
4209
  this._log(
4209
4210
  "DEBUG",
4210
- `The shortfall is: ${shortfall}. requiredSats: ${params.requiredSats}. Current Balance: ${currentBalance} `
4211
+ `The shortfall is: ${shortfall}. requiredSats: ${params.requiredSats}. Current Balance: ${currentBalance}. Reserved Balance: ${reservedBalance}. Available Balance: ${currentBalance - reservedBalance}`
4211
4212
  );
4212
4213
  } catch (e) {
4213
4214
  this._log(
@@ -4352,10 +4353,10 @@ var RoutstrClient = class {
4352
4353
  tryNextProvider = true;
4353
4354
  }
4354
4355
  }
4355
- if ((status === 401 || status === 403 || status === 413 || status === 400 || status === 500 || status === 502 || status === 503 || status === 504 || status === 521) && !tryNextProvider) {
4356
+ if ((status === 401 || status === 403 || status === 413 || status === 400 || status === 429 || status === 500 || status === 502 || status === 503 || status === 504 || status === 521) && !tryNextProvider) {
4356
4357
  this._log(
4357
4358
  "DEBUG",
4358
- `[RoutstrClient] _handleErrorResponse: Status ${status} (auth/server error), attempting refund for ${baseUrl}, mode=${this.mode}`
4359
+ `[RoutstrClient] _handleErrorResponse: Status ${status} (${status === 429 ? "rate limited" : "auth/server error"}), attempting refund for ${baseUrl}, mode=${this.mode}`
4359
4360
  );
4360
4361
  if (this.mode === "apikeys") {
4361
4362
  this._log(