142 lines
3.1 KiB
TypeScript
142 lines
3.1 KiB
TypeScript
|
|
// 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';
|
||
|
|
}
|