Initial commit: Deal orchestration tool - Freeze-resistant arbitrage loop
- Implemented complete arbitrage loop (Steps 0-4) - Risk control service with hard caps (30% LTV, 25% USDTz exposure) - Progressive redemption testing (0k → 50k → cd /home/intlc/projects/proxmox/dbis_core/src/core/defi/arbitrage && git commit -m "Initial commit: Deal orchestration tool - Freeze-resistant arbitrage loop - Implemented complete arbitrage loop (Steps 0-4) - Risk control service with hard caps (30% LTV, 25% USDTz exposure) - Progressive redemption testing ($50k → $250k → $1M+) - Graceful failure handling and state management - CLI interface and programmatic API - Comprehensive documentation Features: - Capital split into three buckets (Core ETH, Working Liquidity, Opportunistic) - ETH wrapping and collateral supply - USDT borrowing at controlled LTV - Discount arbitrage execution - Partial monetization with redemption testing - Loop closing with profit capture Design Principles: - One-way risk only - Anchor asset (ETH) untouchable - No leverage on discounted assets - Independent leg settlement"M+) - Graceful failure handling and state management - CLI interface and programmatic API - Comprehensive documentation Features: - Capital split into three buckets (Core ETH, Working Liquidity, Opportunistic) - ETH wrapping and collateral supply - USDT borrowing at controlled LTV - Discount arbitrage execution - Partial monetization with redemption testing - Loop closing with profit capture Design Principles: - One-way risk only - Anchor asset (ETH) untouchable - No leverage on discounted assets - Independent leg settlement
This commit is contained in:
141
types.ts
Normal file
141
types.ts
Normal file
@@ -0,0 +1,141 @@
|
||||
// Deal Orchestration Tool - Type Definitions
|
||||
// Freeze-resistant, capital-preserving arbitrage loop
|
||||
|
||||
import { Decimal } from '@prisma/client/runtime/library';
|
||||
|
||||
/**
|
||||
* Capital Buckets (STEP 0)
|
||||
*/
|
||||
export interface CapitalBuckets {
|
||||
coreEth: Decimal; // Never touched
|
||||
workingLiquidity: Decimal; // For wrapping and borrowing
|
||||
opportunisticUsdtz: Decimal; // Reserved for USDTz purchases
|
||||
}
|
||||
|
||||
/**
|
||||
* Deal Execution Request
|
||||
*/
|
||||
export interface DealExecutionRequest {
|
||||
totalEthValue: string; // Total ETH value in USD equivalent
|
||||
participantBankId: string;
|
||||
moduleId: string;
|
||||
poolId?: string;
|
||||
usdtzDiscountRate?: number; // Default 0.40 (40% discount)
|
||||
maxLtv?: number; // Default 0.30 (30%)
|
||||
monetizationSplit?: {
|
||||
redemptionPortion: number; // Default 0.35 (35%)
|
||||
coldStoragePortion: number; // Default 0.65 (65%)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Deal State
|
||||
*/
|
||||
export enum DealStep {
|
||||
INITIALIZED = 'initialized',
|
||||
CAPITAL_SPLIT = 'capital_split',
|
||||
WORKING_LIQUIDITY_GENERATED = 'working_liquidity_generated',
|
||||
ARBITRAGE_EXECUTED = 'arbitrage_executed',
|
||||
MONETIZATION_ATTEMPTED = 'monetization_attempted',
|
||||
LOOP_CLOSED = 'loop_closed',
|
||||
FAILED = 'failed',
|
||||
FROZEN = 'frozen', // Degraded to holding
|
||||
}
|
||||
|
||||
export interface DealState {
|
||||
dealId: string;
|
||||
step: DealStep;
|
||||
buckets: CapitalBuckets;
|
||||
collateralAmount?: Decimal;
|
||||
borrowedAmount?: Decimal;
|
||||
usdtzAcquired?: Decimal;
|
||||
usdtzRedeemed?: Decimal;
|
||||
usdtzColdStorage?: Decimal;
|
||||
onChainTxHashes: Record<string, string>;
|
||||
errors: string[];
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Step Execution Results
|
||||
*/
|
||||
export interface Step0Result {
|
||||
buckets: CapitalBuckets;
|
||||
txHash?: string;
|
||||
}
|
||||
|
||||
export interface Step1Result {
|
||||
wethAmount: Decimal;
|
||||
collateralSupplied: Decimal;
|
||||
borrowedUsdt: Decimal;
|
||||
ltv: Decimal;
|
||||
borrowTxHash?: string;
|
||||
supplyTxHash?: string;
|
||||
}
|
||||
|
||||
export interface Step2Result {
|
||||
usdtSpent: Decimal;
|
||||
usdtzReceived: Decimal;
|
||||
discountRate: Decimal;
|
||||
swapTxHash?: string;
|
||||
}
|
||||
|
||||
export interface Step3Result {
|
||||
usdtzForRedemption: Decimal;
|
||||
usdtzForColdStorage: Decimal;
|
||||
redemptionAttempted: boolean;
|
||||
redemptionSuccessful?: boolean;
|
||||
usdtReceived?: Decimal;
|
||||
redemptionTxHash?: string;
|
||||
}
|
||||
|
||||
export interface Step4Result {
|
||||
borrowRepaid: boolean;
|
||||
ethUnlocked: boolean;
|
||||
remainingUsdtz: Decimal;
|
||||
profitCaptured: Decimal;
|
||||
repayTxHash?: string;
|
||||
unlockTxHash?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Risk Control Checks
|
||||
*/
|
||||
export interface RiskCheckResult {
|
||||
passed: boolean;
|
||||
ltv?: Decimal;
|
||||
maxLtv?: Decimal;
|
||||
usdtzExposure?: Decimal;
|
||||
maxUsdtzExposure?: Decimal;
|
||||
totalNav?: Decimal;
|
||||
errors: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Redemption Test Result
|
||||
*/
|
||||
export interface RedemptionTestResult {
|
||||
amount: Decimal;
|
||||
successful: boolean;
|
||||
txHash?: string;
|
||||
error?: string;
|
||||
durationMs?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deal Execution Result
|
||||
*/
|
||||
export interface DealExecutionResult {
|
||||
dealId: string;
|
||||
state: DealState;
|
||||
step0?: Step0Result;
|
||||
step1?: Step1Result;
|
||||
step2?: Step2Result;
|
||||
step3?: Step3Result;
|
||||
step4?: Step4Result;
|
||||
riskChecks: RiskCheckResult[];
|
||||
redemptionTests: RedemptionTestResult[];
|
||||
finalProfit?: Decimal;
|
||||
status: 'completed' | 'partial' | 'frozen' | 'failed';
|
||||
}
|
||||
Reference in New Issue
Block a user