资金分配
每笔存入 StableFX 的资金都遵循 50/50 资金分配模型。每笔存款的一半分配给活跃交易资金,另一半分配到三个流动性池(清算、对冲、保险)以维持结算保证。
FOREX_CAPITAL_SPLIT 常量
import { FOREX_CAPITAL_SPLIT } from '@one_deploy/sdk';
// FOREX_CAPITAL_SPLIT = 0.5
// This means 50% trading, 50% pool reserves
该常量是一个介于 0 和 1 之间的数字,表示分配给池储备金的比例。剩余部分(1 - FOREX_CAPITAL_SPLIT)用于活跃交易资金。
const deposit = 10_000; // $10,000 USDC
const tradingCapital = deposit * (1 - FOREX_CAPITAL_SPLIT);
// tradingCapital = 5,000
const poolReserves = deposit * FOREX_CAPITAL_SPLIT;
// poolReserves = 5,000
computePoolAllocations 工具函数
computePoolAllocations 函数接收总存款金额,并返回每个池的精确分配以及交易资金部分。
函数签名
import { computePoolAllocations } from '@one_deploy/sdk';
interface PoolAllocations {
/** Amount allocated to active trading. */
tradingCapital: number;
/** Amount allocated to the clearing pool. */
clearingPool: number;
/** Amount allocated to the hedging pool. */
hedgingPool: number;
/** Amount allocated to the insurance pool. */
insurancePool: number;
/** Total pool reserves (clearing + hedging + insurance). */
totalReserves: number;
/** The original deposit amount. */
totalDeposit: number;
}
function computePoolAllocations(deposit: number): PoolAllocations;
池储备金分配
50% 的池储备金部分按照固定权重进一步分配到三个池中:
| 池 | 权重 | 占总存款的比例 |
|---|---|---|
| 清算池 | 50% | 总存款的 25% |
| 对冲池 | 30% | 总存款的 15% |
| 保险池 | 20% | 总存款的 10% |
基础示例
import { computePoolAllocations } from '@one_deploy/sdk';
const allocations = computePoolAllocations(10_000);
console.log(allocations);
// {
// tradingCapital: 5000,
// clearingPool: 2500, // 50% of reserves
// hedgingPool: 1500, // 30% of reserves
// insurancePool: 1000, // 20% of reserves
// totalReserves: 5000,
// totalDeposit: 10000,
// }
React Native -- 显示分配信息
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import { computePoolAllocations, FOREX_CAPITAL_SPLIT } from '@one_deploy/sdk';
interface AllocationDisplayProps {
depositAmount: number;
}
function AllocationDisplay({ depositAmount }: AllocationDisplayProps) {
const alloc = computePoolAllocations(depositAmount);
return (
<View style={styles.container}>
<Text style={styles.header}>Capital Allocation</Text>
<Text style={styles.subtitle}>
Split ratio: {((1 - FOREX_CAPITAL_SPLIT) * 100).toFixed(0)}% trading
/ {(FOREX_CAPITAL_SPLIT * 100).toFixed(0)}% reserves
</Text>
<View style={styles.row}>
<Text style={styles.label}>Total Deposit</Text>
<Text style={styles.value}>${alloc.totalDeposit.toLocaleString()}</Text>
</View>
<View style={styles.divider} />
<View style={styles.row}>
<Text style={styles.label}>Trading Capital</Text>
<Text style={styles.value}>${alloc.tradingCapital.toLocaleString()}</Text>
</View>
<View style={styles.divider} />
<Text style={styles.sectionTitle}>Pool Reserves</Text>
<View style={styles.row}>
<Text style={styles.label}>Clearing Pool (50%)</Text>
<Text style={styles.value}>${alloc.clearingPool.toLocaleString()}</Text>
</View>
<View style={styles.row}>
<Text style={styles.label}>Hedging Pool (30%)</Text>
<Text style={styles.value}>${alloc.hedgingPool.toLocaleString()}</Text>
</View>
<View style={styles.row}>
<Text style={styles.label}>Insurance Pool (20%)</Text>
<Text style={styles.value}>${alloc.insurancePool.toLocaleString()}</Text>
</View>
<View style={styles.divider} />
<View style={styles.row}>
<Text style={[styles.label, styles.bold]}>Total Reserves</Text>
<Text style={[styles.value, styles.bold]}>
${alloc.totalReserves.toLocaleString()}
</Text>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: { padding: 16, backgroundColor: '#1a1a2e', borderRadius: 12 },
header: { fontSize: 18, fontWeight: '700', color: '#ffffff', marginBottom: 4 },
subtitle: { fontSize: 13, color: '#8888aa', marginBottom: 16 },
sectionTitle: { fontSize: 14, fontWeight: '600', color: '#ccccdd', marginBottom: 8 },
row: { flexDirection: 'row', justifyContent: 'space-between', marginBottom: 8 },
label: { fontSize: 14, color: '#aaaacc' },
value: { fontSize: 14, color: '#ffffff', fontFamily: 'monospace' },
bold: { fontWeight: '700' },
divider: { height: 1, backgroundColor: '#2a2a4e', marginVertical: 12 },
});
分配计算 -- 逐步说明
对于 $20,000 USDC 的存款:
Step 1: Apply FOREX_CAPITAL_SPLIT (0.5)
Trading capital = $20,000 * (1 - 0.5) = $10,000
Pool reserves = $20,000 * 0.5 = $10,000
Step 2: Distribute pool reserves
Clearing pool = $10,000 * 0.50 = $5,000
Hedging pool = $10,000 * 0.30 = $3,000
Insurance pool = $10,000 * 0.20 = $2,000
Verification:
$10,000 + $5,000 + $3,000 + $2,000 = $20,000 (matches deposit)
将分配与投资结合使用
创建外汇投资时,分配会自动计算。你可以在用户确认之前预览分配情况:
import React, { useState } from 'react';
import { View, Text, TextInput, TouchableOpacity } from 'react-native';
import {
computePoolAllocations,
useForexInvestments,
} from '@one_deploy/sdk';
function InvestmentPreview() {
const [amount, setAmount] = useState('');
const { createInvestment } = useForexInvestments();
const deposit = parseFloat(amount) || 0;
const alloc = computePoolAllocations(deposit);
const handleConfirm = async () => {
if (deposit <= 0) return;
await createInvestment({
amount: deposit,
currencyPair: 'EUR/USD',
cycle: '7d',
});
};
return (
<View>
<TextInput
value={amount}
onChangeText={setAmount}
placeholder="Enter deposit amount (USDC)"
keyboardType="numeric"
/>
{deposit > 0 && (
<View style={{ marginTop: 16 }}>
<Text>Trading: ${alloc.tradingCapital.toLocaleString()}</Text>
<Text>Clearing: ${alloc.clearingPool.toLocaleString()}</Text>
<Text>Hedging: ${alloc.hedgingPool.toLocaleString()}</Text>
<Text>Insurance: ${alloc.insurancePool.toLocaleString()}</Text>
</View>
)}
<TouchableOpacity onPress={handleConfirm}>
<Text>Confirm Investment</Text>
</TouchableOpacity>
</View>
);
}
边界情况
| 场景 | 行为 |
|---|---|
deposit = 0 | 所有分配返回 0。 |
deposit < 0 | 抛出 Error('Deposit amount must be non-negative')。 |
| 极小额存款(< $1) | 使用完整浮点精度计算分配。 |
| 非数字输入 | TypeScript 编译器会阻止此情况;运行时如果类型转换失败则抛出错误。 |