@@ -62,6 +62,8 @@ export class ModelClient {
6262 private walletAddress = '' ;
6363 private cachedBaseWallet : { privateKey : string ; address : string } | null = null ;
6464 private cachedSolanaWallet : { privateKey : string ; address : string } | null = null ;
65+ private walletCacheTime = 0 ;
66+ private static WALLET_CACHE_TTL = 30 * 60 * 1000 ; // 30 min TTL
6567
6668 constructor ( opts : LLMClientOptions ) {
6769 this . apiUrl = opts . apiUrl ;
@@ -283,8 +285,10 @@ export class ModelClient {
283285 private async signBasePayment (
284286 response : Response
285287 ) : Promise < Record < string , string > > {
286- if ( ! this . cachedBaseWallet ) {
288+ // Refresh wallet cache after TTL to pick up balance/key changes
289+ if ( ! this . cachedBaseWallet || ( Date . now ( ) - this . walletCacheTime > ModelClient . WALLET_CACHE_TTL ) ) {
287290 const w = getOrCreateWallet ( ) ;
291+ this . walletCacheTime = Date . now ( ) ;
288292 this . cachedBaseWallet = { privateKey : w . privateKey , address : w . address } ;
289293 }
290294 const wallet = this . cachedBaseWallet ;
@@ -317,8 +321,9 @@ export class ModelClient {
317321 private async signSolanaPayment (
318322 response : Response
319323 ) : Promise < Record < string , string > > {
320- if ( ! this . cachedSolanaWallet ) {
324+ if ( ! this . cachedSolanaWallet || ( Date . now ( ) - this . walletCacheTime > ModelClient . WALLET_CACHE_TTL ) ) {
321325 const w = await getOrCreateSolanaWallet ( ) ;
326+ this . walletCacheTime = Date . now ( ) ;
322327 this . cachedSolanaWallet = { privateKey : w . privateKey , address : w . address } ;
323328 }
324329 const wallet = this . cachedSolanaWallet ;
0 commit comments