@routstr/sdk 0.3.3 → 0.3.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/client/index.d.mts +9 -5
- package/dist/client/index.d.ts +9 -5
- package/dist/client/index.js +70 -131
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +70 -131
- package/dist/client/index.mjs.map +1 -1
- package/dist/discovery/index.d.mts +8 -2
- package/dist/discovery/index.d.ts +8 -2
- package/dist/discovery/index.js +27 -16
- package/dist/discovery/index.js.map +1 -1
- package/dist/discovery/index.mjs +27 -16
- package/dist/discovery/index.mjs.map +1 -1
- package/dist/index.d.mts +10 -8
- package/dist/index.d.ts +10 -8
- package/dist/index.js +141 -185
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +140 -186
- package/dist/index.mjs.map +1 -1
- package/dist/{interfaces-C5fLD3jB.d.mts → interfaces-Bp0Ngmqv.d.mts} +1 -1
- package/dist/{interfaces-BxDEka72.d.ts → interfaces-CIfd_phZ.d.ts} +1 -1
- package/dist/{interfaces-BWJJTCXO.d.mts → interfaces-Cxi8R4TT.d.mts} +1 -1
- package/dist/{interfaces-B62Rw-dd.d.ts → interfaces-D2FDCLyP.d.ts} +1 -1
- package/dist/storage/index.d.mts +9 -7
- package/dist/storage/index.d.ts +9 -7
- package/dist/storage/index.js +51 -34
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/index.mjs +51 -34
- package/dist/storage/index.mjs.map +1 -1
- package/dist/{store-h7m23ffq.d.ts → store-BD5zF9Hp.d.ts} +4 -4
- package/dist/{store-DGeLPv9E.d.mts → store-CBSyK2qg.d.mts} +4 -4
- package/dist/{types-BYj_8c5c.d.mts → types-DPQM6tIG.d.mts} +10 -1
- package/dist/{types-BYj_8c5c.d.ts → types-DPQM6tIG.d.ts} +10 -1
- package/dist/wallet/index.d.mts +8 -6
- package/dist/wallet/index.d.ts +8 -6
- package/dist/wallet/index.js +43 -52
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +43 -52
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { StoreApi } from 'zustand/vanilla';
|
|
2
|
-
import { D as DiscoveryAdapter } from './interfaces-
|
|
3
|
-
import { P as ProviderRegistry, S as StorageAdapter } from './interfaces-
|
|
4
|
-
import { M as Model, P as ProviderInfo } from './types-
|
|
2
|
+
import { D as DiscoveryAdapter } from './interfaces-CIfd_phZ.js';
|
|
3
|
+
import { P as ProviderRegistry, S as StorageAdapter } from './interfaces-D2FDCLyP.js';
|
|
4
|
+
import { M as Model, P as ProviderInfo, S as SdkLogger } from './types-DPQM6tIG.js';
|
|
5
5
|
|
|
6
6
|
interface UsageTrackingEntry {
|
|
7
7
|
id: string;
|
|
@@ -167,6 +167,6 @@ declare const createSdkStore: ({ driver, }: SdkStoreOptions) => {
|
|
|
167
167
|
};
|
|
168
168
|
declare const createDiscoveryAdapterFromStore: (store: SdkStore) => DiscoveryAdapter;
|
|
169
169
|
declare const createStorageAdapterFromStore: (store: SdkStore) => StorageAdapter;
|
|
170
|
-
declare const createProviderRegistryFromStore: (store: SdkStore) => ProviderRegistry;
|
|
170
|
+
declare const createProviderRegistryFromStore: (store: SdkStore, logger?: SdkLogger) => ProviderRegistry;
|
|
171
171
|
|
|
172
172
|
export { type ListUsageTrackingOptions as L, type SdkStore as S, type UsageTrackingDriver as U, type StorageDriver as a, type UsageTrackingEntry as b, createDiscoveryAdapterFromStore as c, createProviderRegistryFromStore as d, createSdkStore as e, createStorageAdapterFromStore as f };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { StoreApi } from 'zustand/vanilla';
|
|
2
|
-
import { D as DiscoveryAdapter } from './interfaces-
|
|
3
|
-
import { P as ProviderRegistry, S as StorageAdapter } from './interfaces-
|
|
4
|
-
import { M as Model, P as ProviderInfo } from './types-
|
|
2
|
+
import { D as DiscoveryAdapter } from './interfaces-Cxi8R4TT.mjs';
|
|
3
|
+
import { P as ProviderRegistry, S as StorageAdapter } from './interfaces-Bp0Ngmqv.mjs';
|
|
4
|
+
import { M as Model, P as ProviderInfo, S as SdkLogger } from './types-DPQM6tIG.mjs';
|
|
5
5
|
|
|
6
6
|
interface UsageTrackingEntry {
|
|
7
7
|
id: string;
|
|
@@ -167,6 +167,6 @@ declare const createSdkStore: ({ driver, }: SdkStoreOptions) => {
|
|
|
167
167
|
};
|
|
168
168
|
declare const createDiscoveryAdapterFromStore: (store: SdkStore) => DiscoveryAdapter;
|
|
169
169
|
declare const createStorageAdapterFromStore: (store: SdkStore) => StorageAdapter;
|
|
170
|
-
declare const createProviderRegistryFromStore: (store: SdkStore) => ProviderRegistry;
|
|
170
|
+
declare const createProviderRegistryFromStore: (store: SdkStore, logger?: SdkLogger) => ProviderRegistry;
|
|
171
171
|
|
|
172
172
|
export { type ListUsageTrackingOptions as L, type SdkStore as S, type UsageTrackingDriver as U, type StorageDriver as a, type UsageTrackingEntry as b, createDiscoveryAdapterFromStore as c, createProviderRegistryFromStore as d, createSdkStore as e, createStorageAdapterFromStore as f };
|
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
* Core types for the Routstr SDK
|
|
3
3
|
* These types are shared across wallet and client modules
|
|
4
4
|
*/
|
|
5
|
+
interface SdkLogger {
|
|
6
|
+
log(...args: unknown[]): void;
|
|
7
|
+
warn(...args: unknown[]): void;
|
|
8
|
+
error(...args: unknown[]): void;
|
|
9
|
+
debug(...args: unknown[]): void;
|
|
10
|
+
child(prefix: string): SdkLogger;
|
|
11
|
+
}
|
|
12
|
+
declare const consoleLogger: SdkLogger;
|
|
13
|
+
declare const noopLogger: SdkLogger;
|
|
5
14
|
interface MessageContentType {
|
|
6
15
|
type: "text" | "image_url" | "file";
|
|
7
16
|
text?: string;
|
|
@@ -222,4 +231,4 @@ interface MintDiscoveryResult {
|
|
|
222
231
|
infoFromProviders: Record<string, ProviderInfo>;
|
|
223
232
|
}
|
|
224
233
|
|
|
225
|
-
export type
|
|
234
|
+
export { type APIErrorVerdict as A, type CandidateProvider as C, type FetchAIResponseParams as F, type ImageData as I, type Model as M, type ProviderInfo as P, type RefundResult as R, type SdkLogger as S, type TransactionHistory as T, type UsageStats as U, type Message as a, type AnnotationData as b, type MessageContentType as c, type MintDiscoveryResult as d, type MintSelection as e, type ModelArchitecture as f, type ModelDiscoveryResult as g, type ModelPricing as h, type ModelSatsPricing as i, type PendingTokenEntry as j, type PerRequestLimits as k, type SpendResult as l, type StreamingResult as m, type TopUpResult as n, consoleLogger as o, noopLogger as p };
|
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
* Core types for the Routstr SDK
|
|
3
3
|
* These types are shared across wallet and client modules
|
|
4
4
|
*/
|
|
5
|
+
interface SdkLogger {
|
|
6
|
+
log(...args: unknown[]): void;
|
|
7
|
+
warn(...args: unknown[]): void;
|
|
8
|
+
error(...args: unknown[]): void;
|
|
9
|
+
debug(...args: unknown[]): void;
|
|
10
|
+
child(prefix: string): SdkLogger;
|
|
11
|
+
}
|
|
12
|
+
declare const consoleLogger: SdkLogger;
|
|
13
|
+
declare const noopLogger: SdkLogger;
|
|
5
14
|
interface MessageContentType {
|
|
6
15
|
type: "text" | "image_url" | "file";
|
|
7
16
|
text?: string;
|
|
@@ -222,4 +231,4 @@ interface MintDiscoveryResult {
|
|
|
222
231
|
infoFromProviders: Record<string, ProviderInfo>;
|
|
223
232
|
}
|
|
224
233
|
|
|
225
|
-
export type
|
|
234
|
+
export { type APIErrorVerdict as A, type CandidateProvider as C, type FetchAIResponseParams as F, type ImageData as I, type Model as M, type ProviderInfo as P, type RefundResult as R, type SdkLogger as S, type TransactionHistory as T, type UsageStats as U, type Message as a, type AnnotationData as b, type MessageContentType as c, type MintDiscoveryResult as d, type MintSelection as e, type ModelArchitecture as f, type ModelDiscoveryResult as g, type ModelPricing as h, type ModelSatsPricing as i, type PendingTokenEntry as j, type PerRequestLimits as k, type SpendResult as l, type StreamingResult as m, type TopUpResult as n, consoleLogger as o, noopLogger as p };
|
package/dist/wallet/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { W as WalletAdapter, S as StorageAdapter, P as ProviderRegistry } from '../interfaces-
|
|
2
|
-
export { A as ApiKeyEntry, C as ChildKeyEntry, R as RoutstrClientOptions, a as StreamingCallbacks, X as XCashuTokenEntry } from '../interfaces-
|
|
3
|
-
import { R as RefundResult,
|
|
4
|
-
export { P as ProviderInfo } from '../types-
|
|
1
|
+
import { W as WalletAdapter, S as StorageAdapter, P as ProviderRegistry } from '../interfaces-Bp0Ngmqv.mjs';
|
|
2
|
+
export { A as ApiKeyEntry, C as ChildKeyEntry, R as RoutstrClientOptions, a as StreamingCallbacks, X as XCashuTokenEntry } from '../interfaces-Bp0Ngmqv.mjs';
|
|
3
|
+
import { S as SdkLogger, R as RefundResult, n as TopUpResult, l as SpendResult } from '../types-DPQM6tIG.mjs';
|
|
4
|
+
export { P as ProviderInfo } from '../types-DPQM6tIG.mjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* BalanceManager - Handles refunding and topping up tokens from providers
|
|
@@ -73,7 +73,8 @@ declare class BalanceManager {
|
|
|
73
73
|
private providerWalletOps;
|
|
74
74
|
/** Cooldown (ms) between opposite operations on the same provider */
|
|
75
75
|
private static readonly PROVIDER_WALLET_COOLDOWN_MS;
|
|
76
|
-
|
|
76
|
+
private readonly logger;
|
|
77
|
+
constructor(walletAdapter: WalletAdapter, storageAdapter: StorageAdapter, providerRegistry?: ProviderRegistry | undefined, cashuSpender?: CashuSpender, logger?: SdkLogger);
|
|
77
78
|
/**
|
|
78
79
|
* Check whether a wallet operation (topup/refund) may run for a provider.
|
|
79
80
|
* Returns the reason when blocked.
|
|
@@ -178,7 +179,8 @@ declare class CashuSpender {
|
|
|
178
179
|
private balanceManager?;
|
|
179
180
|
private _isBusy;
|
|
180
181
|
private debugLevel;
|
|
181
|
-
|
|
182
|
+
private readonly logger;
|
|
183
|
+
constructor(walletAdapter: WalletAdapter, storageAdapter: StorageAdapter, _providerRegistry?: unknown | undefined, balanceManager?: BalanceManager | undefined, logger?: SdkLogger);
|
|
182
184
|
receiveToken(token: string): Promise<{
|
|
183
185
|
success: boolean;
|
|
184
186
|
amount: number;
|
package/dist/wallet/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { W as WalletAdapter, S as StorageAdapter, P as ProviderRegistry } from '../interfaces-
|
|
2
|
-
export { A as ApiKeyEntry, C as ChildKeyEntry, R as RoutstrClientOptions, a as StreamingCallbacks, X as XCashuTokenEntry } from '../interfaces-
|
|
3
|
-
import { R as RefundResult,
|
|
4
|
-
export { P as ProviderInfo } from '../types-
|
|
1
|
+
import { W as WalletAdapter, S as StorageAdapter, P as ProviderRegistry } from '../interfaces-D2FDCLyP.js';
|
|
2
|
+
export { A as ApiKeyEntry, C as ChildKeyEntry, R as RoutstrClientOptions, a as StreamingCallbacks, X as XCashuTokenEntry } from '../interfaces-D2FDCLyP.js';
|
|
3
|
+
import { S as SdkLogger, R as RefundResult, n as TopUpResult, l as SpendResult } from '../types-DPQM6tIG.js';
|
|
4
|
+
export { P as ProviderInfo } from '../types-DPQM6tIG.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* BalanceManager - Handles refunding and topping up tokens from providers
|
|
@@ -73,7 +73,8 @@ declare class BalanceManager {
|
|
|
73
73
|
private providerWalletOps;
|
|
74
74
|
/** Cooldown (ms) between opposite operations on the same provider */
|
|
75
75
|
private static readonly PROVIDER_WALLET_COOLDOWN_MS;
|
|
76
|
-
|
|
76
|
+
private readonly logger;
|
|
77
|
+
constructor(walletAdapter: WalletAdapter, storageAdapter: StorageAdapter, providerRegistry?: ProviderRegistry | undefined, cashuSpender?: CashuSpender, logger?: SdkLogger);
|
|
77
78
|
/**
|
|
78
79
|
* Check whether a wallet operation (topup/refund) may run for a provider.
|
|
79
80
|
* Returns the reason when blocked.
|
|
@@ -178,7 +179,8 @@ declare class CashuSpender {
|
|
|
178
179
|
private balanceManager?;
|
|
179
180
|
private _isBusy;
|
|
180
181
|
private debugLevel;
|
|
181
|
-
|
|
182
|
+
private readonly logger;
|
|
183
|
+
constructor(walletAdapter: WalletAdapter, storageAdapter: StorageAdapter, _providerRegistry?: unknown | undefined, balanceManager?: BalanceManager | undefined, logger?: SdkLogger);
|
|
182
184
|
receiveToken(token: string): Promise<{
|
|
183
185
|
success: boolean;
|
|
184
186
|
amount: number;
|
package/dist/wallet/index.js
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
var cashuTs = require('@cashu/cashu-ts');
|
|
4
4
|
|
|
5
|
+
// core/types.ts
|
|
6
|
+
function makeConsoleLogger(prefix) {
|
|
7
|
+
const fmt = (args) => prefix ? [prefix, ...args] : args;
|
|
8
|
+
return {
|
|
9
|
+
log: (...args) => console.log(...fmt(args)),
|
|
10
|
+
warn: (...args) => console.warn(...fmt(args)),
|
|
11
|
+
error: (...args) => console.error(...fmt(args)),
|
|
12
|
+
debug: (...args) => console.log(...fmt(args)),
|
|
13
|
+
child: (p) => makeConsoleLogger(prefix ? `${prefix}:${p}` : p)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
var consoleLogger = makeConsoleLogger();
|
|
17
|
+
|
|
5
18
|
// core/errors.ts
|
|
6
19
|
var InsufficientBalanceError = class extends Error {
|
|
7
20
|
constructor(required, available, maxMintBalance = 0, maxMintUrl = "", customMessage) {
|
|
@@ -80,14 +93,16 @@ function selectMintWithBalance(balances, units, amount, excludeMints = []) {
|
|
|
80
93
|
return { selectedMintUrl: null, selectedMintBalance: 0 };
|
|
81
94
|
}
|
|
82
95
|
var CashuSpender = class {
|
|
83
|
-
constructor(walletAdapter, storageAdapter, _providerRegistry, balanceManager) {
|
|
96
|
+
constructor(walletAdapter, storageAdapter, _providerRegistry, balanceManager, logger) {
|
|
84
97
|
this.walletAdapter = walletAdapter;
|
|
85
98
|
this.storageAdapter = storageAdapter;
|
|
86
99
|
this._providerRegistry = _providerRegistry;
|
|
87
100
|
this.balanceManager = balanceManager;
|
|
101
|
+
this.logger = (logger ?? consoleLogger).child("CashuSpender");
|
|
88
102
|
}
|
|
89
103
|
_isBusy = false;
|
|
90
104
|
debugLevel = "WARN";
|
|
105
|
+
logger;
|
|
91
106
|
async receiveToken(token) {
|
|
92
107
|
try {
|
|
93
108
|
const result = await this.walletAdapter.receiveToken(token);
|
|
@@ -183,13 +198,13 @@ var CashuSpender = class {
|
|
|
183
198
|
if (levelPriority[level] >= levelPriority[this.debugLevel]) {
|
|
184
199
|
switch (level) {
|
|
185
200
|
case "DEBUG":
|
|
186
|
-
|
|
201
|
+
this.logger.log(...args);
|
|
187
202
|
break;
|
|
188
203
|
case "WARN":
|
|
189
|
-
|
|
204
|
+
this.logger.warn(...args);
|
|
190
205
|
break;
|
|
191
206
|
case "ERROR":
|
|
192
|
-
|
|
207
|
+
this.logger.error(...args);
|
|
193
208
|
break;
|
|
194
209
|
}
|
|
195
210
|
}
|
|
@@ -616,10 +631,11 @@ var CashuSpender = class {
|
|
|
616
631
|
|
|
617
632
|
// wallet/BalanceManager.ts
|
|
618
633
|
var BalanceManager = class _BalanceManager {
|
|
619
|
-
constructor(walletAdapter, storageAdapter, providerRegistry, cashuSpender) {
|
|
634
|
+
constructor(walletAdapter, storageAdapter, providerRegistry, cashuSpender, logger) {
|
|
620
635
|
this.walletAdapter = walletAdapter;
|
|
621
636
|
this.storageAdapter = storageAdapter;
|
|
622
637
|
this.providerRegistry = providerRegistry;
|
|
638
|
+
this.logger = (logger ?? consoleLogger).child("BalanceManager");
|
|
623
639
|
if (cashuSpender) {
|
|
624
640
|
this.cashuSpender = cashuSpender;
|
|
625
641
|
} else {
|
|
@@ -636,6 +652,7 @@ var BalanceManager = class _BalanceManager {
|
|
|
636
652
|
providerWalletOps = /* @__PURE__ */ new Map();
|
|
637
653
|
/** Cooldown (ms) between opposite operations on the same provider */
|
|
638
654
|
static PROVIDER_WALLET_COOLDOWN_MS = 1e4;
|
|
655
|
+
logger;
|
|
639
656
|
/**
|
|
640
657
|
* Check whether a wallet operation (topup/refund) may run for a provider.
|
|
641
658
|
* Returns the reason when blocked.
|
|
@@ -710,7 +727,7 @@ var BalanceManager = class _BalanceManager {
|
|
|
710
727
|
const { mintUrl, baseUrl, apiKey, forceRefund } = options;
|
|
711
728
|
const guard = this._canRunProviderWalletOperation(baseUrl, "refund");
|
|
712
729
|
if (!guard.allowed) {
|
|
713
|
-
|
|
730
|
+
this.logger.log(`Skipping refund for ${baseUrl} - ${guard.reason}`);
|
|
714
731
|
return { success: false, message: guard.reason };
|
|
715
732
|
}
|
|
716
733
|
this._beginProviderWalletOperation(baseUrl, "refund");
|
|
@@ -730,9 +747,7 @@ var BalanceManager = class _BalanceManager {
|
|
|
730
747
|
if (apiKeyEntry?.lastUsed) {
|
|
731
748
|
const fiveMinutesAgo = Date.now() - 5 * 60 * 1e3;
|
|
732
749
|
if (apiKeyEntry.lastUsed > fiveMinutesAgo) {
|
|
733
|
-
|
|
734
|
-
`[BalanceManager] Skipping refund for ${baseUrl} - used ${Math.round((Date.now() - apiKeyEntry.lastUsed) / 1e3)}s ago`
|
|
735
|
-
);
|
|
750
|
+
this.logger.log(`Skipping refund for ${baseUrl} - used ${Math.round((Date.now() - apiKeyEntry.lastUsed) / 1e3)}s ago`);
|
|
736
751
|
return {
|
|
737
752
|
success: false,
|
|
738
753
|
message: "API key was used recently, skipping refund"
|
|
@@ -774,7 +789,7 @@ var BalanceManager = class _BalanceManager {
|
|
|
774
789
|
requestId: fetchResult.requestId
|
|
775
790
|
};
|
|
776
791
|
} catch (error) {
|
|
777
|
-
|
|
792
|
+
this.logger.error("API key refund error", error);
|
|
778
793
|
return this._handleRefundError(error, mintUrl, fetchResult?.requestId);
|
|
779
794
|
}
|
|
780
795
|
}
|
|
@@ -826,7 +841,7 @@ var BalanceManager = class _BalanceManager {
|
|
|
826
841
|
};
|
|
827
842
|
} catch (error) {
|
|
828
843
|
clearTimeout(timeoutId);
|
|
829
|
-
|
|
844
|
+
this.logger.error("fetchRefundToken fetch error", error);
|
|
830
845
|
if (error instanceof Error) {
|
|
831
846
|
if (error.name === "AbortError") {
|
|
832
847
|
return {
|
|
@@ -852,7 +867,7 @@ var BalanceManager = class _BalanceManager {
|
|
|
852
867
|
const { mintUrl, baseUrl, amount, token: providedToken } = options;
|
|
853
868
|
const guard = this._canRunProviderWalletOperation(baseUrl, "topup");
|
|
854
869
|
if (!guard.allowed) {
|
|
855
|
-
|
|
870
|
+
this.logger.log(`Skipping topup for ${baseUrl} - ${guard.reason}`);
|
|
856
871
|
return { success: false, message: guard.reason };
|
|
857
872
|
}
|
|
858
873
|
this._beginProviderWalletOperation(baseUrl, "topup");
|
|
@@ -889,7 +904,7 @@ var BalanceManager = class _BalanceManager {
|
|
|
889
904
|
cashuToken = tokenResult.token;
|
|
890
905
|
const topUpResult = await this._postTopUp(baseUrl, apiKey, cashuToken);
|
|
891
906
|
requestId = topUpResult.requestId;
|
|
892
|
-
|
|
907
|
+
this.logger.log("topUpResult:", topUpResult);
|
|
893
908
|
if (!topUpResult.success) {
|
|
894
909
|
await this._recoverFailedTopUp(cashuToken);
|
|
895
910
|
return {
|
|
@@ -905,10 +920,7 @@ var BalanceManager = class _BalanceManager {
|
|
|
905
920
|
requestId
|
|
906
921
|
};
|
|
907
922
|
} catch (error) {
|
|
908
|
-
|
|
909
|
-
"DEBUG",
|
|
910
|
-
`[TopuPU] topup: Topup result for ${baseUrl}: error=${error}`
|
|
911
|
-
);
|
|
923
|
+
this.logger.log(`topup error for ${baseUrl}: ${error}`);
|
|
912
924
|
if (cashuToken) {
|
|
913
925
|
await this._recoverFailedTopUp(cashuToken);
|
|
914
926
|
}
|
|
@@ -925,13 +937,9 @@ var BalanceManager = class _BalanceManager {
|
|
|
925
937
|
p2pkPubkey
|
|
926
938
|
} = options;
|
|
927
939
|
const adjustedAmount = Math.ceil(amount);
|
|
928
|
-
|
|
929
|
-
`[BalanceManager.createProviderToken] Starting: baseUrl=${baseUrl}, mintUrl=${mintUrl}, amount=${amount}, adjustedAmount=${adjustedAmount}, retryCount=${retryCount}`
|
|
930
|
-
);
|
|
940
|
+
this.logger.log(`createProviderToken: baseUrl=${baseUrl} mintUrl=${mintUrl} amount=${amount} adjustedAmount=${adjustedAmount} retryCount=${retryCount}`);
|
|
931
941
|
if (!adjustedAmount || isNaN(adjustedAmount)) {
|
|
932
|
-
|
|
933
|
-
`[BalanceManager.createProviderToken] FAILURE: Invalid amount - amount=${amount}, adjustedAmount=${adjustedAmount}`
|
|
934
|
-
);
|
|
942
|
+
this.logger.error(`createProviderToken: invalid amount=${amount}`);
|
|
935
943
|
return { success: false, error: "Invalid top up amount" };
|
|
936
944
|
}
|
|
937
945
|
const balanceState = await this.getBalanceState();
|
|
@@ -962,9 +970,7 @@ var BalanceManager = class _BalanceManager {
|
|
|
962
970
|
{ url: "", balance: 0 }
|
|
963
971
|
).url
|
|
964
972
|
);
|
|
965
|
-
|
|
966
|
-
`[BalanceManager.createProviderToken] FAILURE: Insufficient balance - required=${adjustedAmount}, available=${totalMintBalance + targetProviderBalance}, totalMintBalance=${totalMintBalance}, targetProviderBalance=${targetProviderBalance}, refundableProviderBalance=${refundableProviderBalance}`
|
|
967
|
-
);
|
|
973
|
+
this.logger.error(`createProviderToken: insufficient balance required=${adjustedAmount} available=${totalMintBalance + targetProviderBalance} totalMint=${totalMintBalance} targetProvider=${targetProviderBalance}`);
|
|
968
974
|
return { success: false, error: error.message };
|
|
969
975
|
}
|
|
970
976
|
const providerMints = baseUrl && this.providerRegistry ? this.providerRegistry.getProviderMints(baseUrl) : [];
|
|
@@ -1000,9 +1006,7 @@ var BalanceManager = class _BalanceManager {
|
|
|
1000
1006
|
maxMintUrl = mintUrl2;
|
|
1001
1007
|
}
|
|
1002
1008
|
}
|
|
1003
|
-
|
|
1004
|
-
`[BalanceManager.createProviderToken] FAILURE: No candidate mints found - requiredAmount=${requiredAmount}, totalMintBalance=${totalMintBalance}, maxBalance=${maxBalance}, maxMintUrl=${maxMintUrl}, providerMints=${JSON.stringify(providerMints)}`
|
|
1005
|
-
);
|
|
1009
|
+
this.logger.error(`createProviderToken: no candidate mints required=${requiredAmount} totalMint=${totalMintBalance} maxBalance=${maxBalance} maxMint=${maxMintUrl}`);
|
|
1006
1010
|
const error = new InsufficientBalanceError(
|
|
1007
1011
|
adjustedAmount,
|
|
1008
1012
|
totalMintBalance,
|
|
@@ -1014,17 +1018,13 @@ var BalanceManager = class _BalanceManager {
|
|
|
1014
1018
|
let lastError;
|
|
1015
1019
|
for (const candidateMint of candidates) {
|
|
1016
1020
|
try {
|
|
1017
|
-
|
|
1018
|
-
`[BalanceManager.createProviderToken] Attempting mint: ${candidateMint}, amount: ${requiredAmount}`
|
|
1019
|
-
);
|
|
1021
|
+
this.logger.log(`createProviderToken: attempting mint=${candidateMint} amount=${requiredAmount}`);
|
|
1020
1022
|
const token = await this.walletAdapter.sendToken(
|
|
1021
1023
|
candidateMint,
|
|
1022
1024
|
requiredAmount,
|
|
1023
1025
|
p2pkPubkey
|
|
1024
1026
|
);
|
|
1025
|
-
|
|
1026
|
-
`[BalanceManager.createProviderToken] SUCCESS: Token created from mint ${candidateMint}, all mint balances: ${JSON.stringify(Object.fromEntries(Object.entries(balances).map(([mint, balance]) => [mint, getBalanceInSats(balance, units[mint])])))}`
|
|
1027
|
-
);
|
|
1027
|
+
this.logger.log(`createProviderToken: success from mint=${candidateMint}`);
|
|
1028
1028
|
return {
|
|
1029
1029
|
success: true,
|
|
1030
1030
|
token,
|
|
@@ -1033,15 +1033,11 @@ var BalanceManager = class _BalanceManager {
|
|
|
1033
1033
|
};
|
|
1034
1034
|
} catch (error) {
|
|
1035
1035
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
1036
|
-
|
|
1037
|
-
`[BalanceManager.createProviderToken] FAILURE: Mint ${candidateMint} failed with error: ${errorMsg}`
|
|
1038
|
-
);
|
|
1036
|
+
this.logger.error(`createProviderToken: mint=${candidateMint} failed: ${errorMsg}`);
|
|
1039
1037
|
if (error instanceof Error) {
|
|
1040
1038
|
lastError = errorMsg;
|
|
1041
1039
|
if (isNetworkErrorMessage(error.message)) {
|
|
1042
|
-
|
|
1043
|
-
`[BalanceManager.createProviderToken] Network error from ${candidateMint}, trying next mint...`
|
|
1044
|
-
);
|
|
1040
|
+
this.logger.warn(`createProviderToken: network error from ${candidateMint}, trying next mint...`);
|
|
1045
1041
|
continue;
|
|
1046
1042
|
}
|
|
1047
1043
|
}
|
|
@@ -1051,9 +1047,7 @@ var BalanceManager = class _BalanceManager {
|
|
|
1051
1047
|
};
|
|
1052
1048
|
}
|
|
1053
1049
|
}
|
|
1054
|
-
|
|
1055
|
-
`[BalanceManager.createProviderToken] FAILURE: All candidate mints exhausted - lastError=${lastError}, candidates=${JSON.stringify(candidates)}`
|
|
1056
|
-
);
|
|
1050
|
+
this.logger.error(`createProviderToken: all candidate mints exhausted lastError=${lastError}`);
|
|
1057
1051
|
return {
|
|
1058
1052
|
success: false,
|
|
1059
1053
|
error: lastError || "All candidate mints failed while creating top up token"
|
|
@@ -1168,7 +1162,7 @@ var BalanceManager = class _BalanceManager {
|
|
|
1168
1162
|
return { success: true, requestId };
|
|
1169
1163
|
} catch (error) {
|
|
1170
1164
|
clearTimeout(timeoutId);
|
|
1171
|
-
|
|
1165
|
+
this.logger.error("_postTopUp fetch error", error);
|
|
1172
1166
|
if (error instanceof Error) {
|
|
1173
1167
|
if (error.name === "AbortError") {
|
|
1174
1168
|
return {
|
|
@@ -1194,10 +1188,7 @@ var BalanceManager = class _BalanceManager {
|
|
|
1194
1188
|
try {
|
|
1195
1189
|
await this.cashuSpender.receiveToken(cashuToken);
|
|
1196
1190
|
} catch (error) {
|
|
1197
|
-
|
|
1198
|
-
"[BalanceManager._recoverFailedTopUp] Failed to recover token",
|
|
1199
|
-
error
|
|
1200
|
-
);
|
|
1191
|
+
this.logger.error("_recoverFailedTopUp: failed to recover token", error);
|
|
1201
1192
|
}
|
|
1202
1193
|
}
|
|
1203
1194
|
/**
|
|
@@ -1250,9 +1241,9 @@ var BalanceManager = class _BalanceManager {
|
|
|
1250
1241
|
apiKey: data.api_key
|
|
1251
1242
|
};
|
|
1252
1243
|
} else {
|
|
1253
|
-
|
|
1244
|
+
this.logger.warn(`getTokenBalance: status=${response.status}`);
|
|
1254
1245
|
const data = await response.json();
|
|
1255
|
-
|
|
1246
|
+
this.logger.warn("getTokenBalance: FAILED", data);
|
|
1256
1247
|
const isInvalidApiKey = response.status === 401 && data?.detail?.error?.code === "invalid_api_key" && data?.detail?.error?.message?.includes("proofs already spent");
|
|
1257
1248
|
return {
|
|
1258
1249
|
amount: -1,
|
|
@@ -1263,7 +1254,7 @@ var BalanceManager = class _BalanceManager {
|
|
|
1263
1254
|
};
|
|
1264
1255
|
}
|
|
1265
1256
|
} catch (error) {
|
|
1266
|
-
|
|
1257
|
+
this.logger.error("getTokenBalance error", error);
|
|
1267
1258
|
}
|
|
1268
1259
|
return { amount: -1, reserved: 0, unit: "sat", apiKey: "" };
|
|
1269
1260
|
}
|