11import { isDbConfigured } from '../db/client.js'
22import * as portfolioDb from '../db/portfolioDb.js'
33import { randomUUID } from 'node:crypto'
4+ import type { Portfolio } from '../types/index.js'
45
56const SLIPPAGE_MIN = 0.5
67const SLIPPAGE_MAX = 5
@@ -9,17 +10,7 @@ function clampSlippageTolerance(p: number): number {
910 return Math . max ( SLIPPAGE_MIN , Math . min ( SLIPPAGE_MAX , p ) )
1011}
1112
12- interface Portfolio {
13- id : string
14- userAddress : string
15- allocations : Record < string , number >
16- threshold : number
17- slippageTolerance ?: number
18- balances : Record < string , number >
19- totalValue : number
20- createdAt : string
21- lastRebalance : string
22- }
13+
2314
2415const useCache = process . env . USE_MEMORY_CACHE === 'true'
2516
@@ -56,7 +47,8 @@ class PortfolioStorage {
5647 balances : { } ,
5748 totalValue : 0 ,
5849 createdAt : new Date ( ) . toISOString ( ) ,
59- lastRebalance : new Date ( ) . toISOString ( )
50+ lastRebalance : new Date ( ) . toISOString ( ) ,
51+ version : 1
6052 }
6153 if ( isDbConfigured ( ) ) {
6254 await portfolioDb . dbCreatePortfolio ( id , userAddress , allocations , threshold , { } , 0 )
@@ -83,7 +75,8 @@ class PortfolioStorage {
8375 balances : currentBalances ,
8476 totalValue,
8577 createdAt : new Date ( ) . toISOString ( ) ,
86- lastRebalance : new Date ( ) . toISOString ( )
78+ lastRebalance : new Date ( ) . toISOString ( ) ,
79+ version : 1
8780 }
8881 if ( isDbConfigured ( ) ) {
8982 await portfolioDb . dbCreatePortfolio (
@@ -159,10 +152,5 @@ class PortfolioStorage {
159152 this . portfolios . clear ( )
160153 }
161154}
162- /**
163- * portfolioStorage.ts
164- *
165- * Backward-compatible re-export: all callers that import `portfolioStorage`
166- * now transparently use the SQLite-backed DatabaseService singleton.
167- */
168- export { databaseService as portfolioStorage , type Portfolio } from './databaseService.js'
155+ export { databaseService as portfolioStorage } from './databaseService.js'
156+ export type { Portfolio } from '../types/index.js'
0 commit comments