134 lines
3.8 KiB
TypeScript
134 lines
3.8 KiB
TypeScript
import {
|
|
WatchedWallet,
|
|
RawWalletTransaction,
|
|
CopySignal,
|
|
Trade,
|
|
SimulatedExecution,
|
|
EventJournalEntry,
|
|
} from './models.js';
|
|
|
|
// Clock types and interfaces
|
|
export interface IClock {
|
|
now(): Date;
|
|
}
|
|
|
|
export class SystemClock implements IClock {
|
|
now(): Date {
|
|
return new Date();
|
|
}
|
|
}
|
|
|
|
// Wallet Watcher types and interfaces
|
|
export interface WalletTransactionObservation {
|
|
signature: string;
|
|
slot: number;
|
|
walletAddress: string;
|
|
tokenMint?: string | null;
|
|
side?: 'buy' | 'sell' | null;
|
|
amountSol?: number | null;
|
|
tokenAmount?: number | null;
|
|
timestamp: Date;
|
|
correlationId?: string;
|
|
}
|
|
|
|
export interface IWalletWatcher {
|
|
startWatching(): Promise<void>;
|
|
stopWatching(): Promise<void>;
|
|
onObservation(callback: (obs: WalletTransactionObservation) => Promise<void>): void;
|
|
}
|
|
|
|
// Market Data types and interfaces
|
|
export interface MarketQuote {
|
|
tokenMint: string;
|
|
priceSol: number;
|
|
timestamp: Date;
|
|
}
|
|
|
|
export interface IMarketDataProvider {
|
|
getQuote(tokenMint: string, timestamp: Date): Promise<MarketQuote>;
|
|
}
|
|
|
|
// Strategy Engine interface
|
|
export interface StrategyEvaluationResult {
|
|
shouldCopy: boolean;
|
|
reason: string;
|
|
}
|
|
|
|
export interface IStrategyEngine {
|
|
name: string;
|
|
version: string;
|
|
evaluate(signal: CopySignal): Promise<StrategyEvaluationResult>;
|
|
}
|
|
|
|
// Trade Executor types and interfaces
|
|
export interface ExecutionResult {
|
|
priceSol: number;
|
|
tokenAmount: number;
|
|
amountSol: number;
|
|
timestamp: Date;
|
|
}
|
|
|
|
export interface ITradeExecutor {
|
|
executeEntry(
|
|
signal: CopySignal,
|
|
latencyScenario: number,
|
|
positionSizeSol: number,
|
|
): Promise<ExecutionResult>;
|
|
executeExit(trade: Trade): Promise<ExecutionResult>;
|
|
}
|
|
|
|
// Repository Interfaces
|
|
export interface IWalletRepository {
|
|
getWatchedWallets(): Promise<WatchedWallet[]>;
|
|
isWalletWatched(address: string): Promise<boolean>;
|
|
addWatchedWallet(
|
|
wallet: Omit<WatchedWallet, 'id' | 'createdAt' | 'updatedAt'>,
|
|
): Promise<WatchedWallet>;
|
|
}
|
|
|
|
export interface ICopySignalRepository {
|
|
saveSignal(signal: CopySignal): Promise<void>;
|
|
getSignalByCorrelationId(correlationId: string): Promise<CopySignal | null>;
|
|
}
|
|
|
|
export interface IRawWalletTransactionRepository {
|
|
saveTransaction(tx: RawWalletTransaction): Promise<void>;
|
|
getTransactionBySignature(signature: string): Promise<RawWalletTransaction | null>;
|
|
}
|
|
|
|
export interface ITradeRepository {
|
|
saveTrade(trade: Trade): Promise<void>;
|
|
updateTrade(trade: Trade): Promise<void>;
|
|
getTradeByCorrelationIdAndScenario(
|
|
correlationId: string,
|
|
latencyScenario: number,
|
|
): Promise<Trade | null>;
|
|
getActiveTradesForScenario(latencyScenario: number): Promise<Trade[]>;
|
|
getTradeById(id: string): Promise<Trade | null>;
|
|
getTradesForScenario(latencyScenario: number): Promise<Trade[]>;
|
|
}
|
|
|
|
export interface ISimulationExecutionRepository {
|
|
saveExecution(execution: SimulatedExecution): Promise<void>;
|
|
getExecutionsByTradeId(tradeId: string): Promise<SimulatedExecution[]>;
|
|
getPendingExecutionsBefore(timestamp: Date): Promise<SimulatedExecution[]>;
|
|
updateExecution(execution: SimulatedExecution): Promise<void>;
|
|
}
|
|
|
|
export interface IEventJournalRepository {
|
|
logEvent(entry: EventJournalEntry): Promise<void>;
|
|
getEventsByCorrelationId(correlationId: string): Promise<EventJournalEntry[]>;
|
|
}
|
|
|
|
// Metrics interface
|
|
export interface IMetricsProvider {
|
|
recordWalletDetectionLatency(latencyMs: number, wallet: string): void;
|
|
recordSignalProcessingLatency(latencyMs: number): void;
|
|
recordQuoteLatency(latencyMs: number, provider: string): void;
|
|
recordExecutionLatency(latencyMs: number, scenario: number): void;
|
|
recordPrice(tokenMint: string, priceSol: number): void;
|
|
recordPortfolioBalance(balanceSol: number, scenario: number): void;
|
|
recordTradePnl(pnlSol: number, scenario: number, tokenMint: string): void;
|
|
recordExcursion(mfeSol: number, maeSol: number, scenario: number, tokenMint: string): void;
|
|
}
|