/** * MCP Investment Server Configuration * Agent allocations and profit distribution */ import { Pool, PoolConfig } from 'pg'; // Database configuration const dbConfig: PoolConfig = { host: process.env.DB_HOST || 'localhost', port: parseInt(process.env.DB_PORT || '5432', 10), database: process.env.DB_NAME || 'trading_platform', user: process.env.DB_USER || 'trading_app', password: process.env.DB_PASSWORD || '', ssl: process.env.DB_SSL === 'true' ? { rejectUnauthorized: false } : false, max: parseInt(process.env.DB_POOL_MAX || '20', 10), idleTimeoutMillis: 30000, connectionTimeoutMillis: 5000, }; // Database pool singleton let pool: Pool | null = null; export function getPool(): Pool { if (!pool) { pool = new Pool(dbConfig); pool.on('error', (err) => { console.error('Unexpected database pool error:', err); }); } return pool; } export async function closePool(): Promise { if (pool) { await pool.end(); pool = null; } } // Server configuration export const serverConfig = { port: parseInt(process.env.PORT || '3093', 10), env: process.env.NODE_ENV || 'development', logLevel: process.env.LOG_LEVEL || 'info', }; // Wallet service configuration export const walletServiceConfig = { baseUrl: process.env.WALLET_SERVICE_URL || 'http://localhost:3090', timeout: parseInt(process.env.WALLET_SERVICE_TIMEOUT || '10000', 10), }; // Investment configuration export const investmentConfig = { // Minimum allocation amount per agent minAllocationAmount: parseFloat(process.env.MIN_ALLOCATION_AMOUNT || '100'), // Maximum allocation amount per agent maxAllocationAmount: parseFloat(process.env.MAX_ALLOCATION_AMOUNT || '100000'), // Minimum withdrawal amount minWithdrawalAmount: parseFloat(process.env.MIN_WITHDRAWAL_AMOUNT || '10'), // Profit distribution frequency (days) profitDistributionFrequencyDays: parseInt(process.env.PROFIT_DISTRIBUTION_FREQUENCY_DAYS || '30', 10), // Lock period for new allocations (days) allocationLockPeriodDays: parseInt(process.env.ALLOCATION_LOCK_PERIOD_DAYS || '7', 10), // Early withdrawal penalty percentage earlyWithdrawalPenaltyPercent: parseFloat(process.env.EARLY_WITHDRAWAL_PENALTY_PERCENT || '5'), // Agent types agentTypes: ['ATLAS', 'ORION', 'NOVA'] as const, }; // Agent default configurations export const agentDefaults = { ATLAS: { name: 'Atlas', riskLevel: 'conservative', targetReturnPercent: 8, maxDrawdownPercent: 5, managementFeePercent: 1.5, performanceFeePercent: 15, }, ORION: { name: 'Orion', riskLevel: 'moderate', targetReturnPercent: 15, maxDrawdownPercent: 12, managementFeePercent: 2.0, performanceFeePercent: 20, }, NOVA: { name: 'Nova', riskLevel: 'aggressive', targetReturnPercent: 25, maxDrawdownPercent: 25, managementFeePercent: 2.5, performanceFeePercent: 25, }, }; // Helper to set tenant context for RLS export async function setTenantContext(client: any, tenantId: string): Promise { await client.query(`SET LOCAL app.current_tenant_id = '${tenantId}'`); }