跳至主要内容

池系统

StableFX 运营三个专用流动性池,它们协同工作以确保交易结算、风险缓释和损失保护。本页介绍每个池的角色、涉及的数据类型,以及如何使用 useForexPools hook 获取池数据。

池概览

                  User Deposits
|
+----------+-----------+
| |
Trading Capital Pool Reserves
(50%) (50%)
|
+--------------+--------------+
| | |
Clearing (50%) Hedging (30%) Insurance (20%)
+-----------+ +-----------+ +-----------+
| Settlement| | Risk | | Loss |
| of trades| | mitigation| | protection|
+-----------+ +-----------+ +-----------+

清算池

清算池是最大的储备池,接收 50% 的池储备金(总存款的 25%)。它在交易生命周期内持有稳定币 -- 从报价请求(RFQ)发出到最终结算。

职责:

  • 在 RFQ 到结算窗口期间托管资金。
  • 在交易完成后向对手方释放结算金额。
  • 当交易在匹配前被取消时,将资金返还到清算池。
// Clearing pool transactions follow the trade lifecycle
// RFQ issued -> funds locked in clearing pool
// Trade matched -> funds remain locked
// Trade settled -> funds released to counterparties
// Trade failed -> funds returned to clearing pool

对冲池

对冲池接收 30% 的池储备金(总存款的 15%)。当系统对任何货币对的净敞口超过预定义阈值时,它会吸收方向性风险。

职责:

  • 当某个货币对的净敞口超过阈值时自动重新平衡。
  • 抵消不利货币波动造成的损失。
  • 通过为对冲操作提供流动性来产生收益。

保险池

保险池接收 20% 的池储备金(总存款的 10%)。它作为最后一道防线,承担因结算失败、对手方违约或极端市场事件造成的损失。

职责:

  • 当清算池无法完全结算交易时弥补缺口。
  • 吸收极端市场事件造成的损失(黑天鹅保护)。
  • 额外由所有池中收取的交易手续费的一部分资助。

核心类型

ForexPool

import type { ForexPool, ForexPoolType } from '@one_deploy/sdk';

type ForexPoolType = 'clearing' | 'hedging' | 'insurance';

interface ForexPool {
/** Unique identifier for this pool. */
id: string;

/** The pool category. */
type: ForexPoolType;

/** Total value locked in the pool (in USDC). */
totalValueLocked: number;

/** Current annualized percentage yield. */
apy: number;

/** Pool utilization as a decimal (0.0 to 1.0). */
utilization: number;

/** The stablecoin denomination. */
currency: string;

/** ISO-8601 creation timestamp. */
createdAt: string;

/** ISO-8601 last-update timestamp. */
updatedAt: string;
}

ForexPoolTransaction

import type { ForexPoolTransaction } from '@one_deploy/sdk';

interface ForexPoolTransaction {
/** Unique transaction identifier. */
id: string;

/** The pool this transaction belongs to. */
poolId: string;

/** Transaction type. */
type: 'deposit' | 'withdrawal' | 'fee' | 'rebalance';

/** Amount in the pool's stablecoin currency. */
amount: number;

/** Stablecoin symbol (e.g. "USDC"). */
currency: string;

/** ISO-8601 timestamp of the transaction. */
timestamp: string;

/** On-chain transaction hash, if applicable. */
txHash?: string;
}

useForexPools Hook

useForexPools hook 获取所有三个池及其当前状态。需要先调用 setForexAccessTokensetForexEngineUrl

Hook 签名

import { useForexPools } from '@one_deploy/sdk';

function useForexPools(): UseForexPoolsResult;

UseForexPoolsResult

interface UseForexPoolsResult {
/** Array of all forex pools. */
pools: ForexPool[];

/** Whether the initial fetch is in progress. */
isLoading: boolean;

/** Error object if the fetch failed. */
error: Error | null;

/** Re-fetch pool data. */
refetch: () => Promise<void>;

/** Transactions for a specific pool. */
getPoolTransactions: (
poolId: string,
options?: { limit?: number; offset?: number }
) => Promise<ForexPoolTransaction[]>;
}

获取池数据

基础用法

import React from 'react';
import { View, Text, ActivityIndicator } from 'react-native';
import { useForexPools } from '@one_deploy/sdk';

function ForexPoolList() {
const { pools, isLoading, error, refetch } = useForexPools();

if (isLoading) {
return <ActivityIndicator size="large" />;
}

if (error) {
return <Text style={{ color: 'red' }}>Error: {error.message}</Text>;
}

return (
<View>
{pools.map((pool) => (
<View key={pool.id} style={{ marginBottom: 16, padding: 12 }}>
<Text style={{ fontWeight: '700', textTransform: 'capitalize' }}>
{pool.type} Pool
</Text>
<Text>TVL: ${pool.totalValueLocked.toLocaleString()}</Text>
<Text>APY: {(pool.apy * 100).toFixed(2)}%</Text>
<Text>
Utilization: {(pool.utilization * 100).toFixed(1)}%
</Text>
</View>
))}
</View>
);
}

获取池交易记录

import React, { useEffect, useState } from 'react';
import { View, Text, FlatList } from 'react-native';
import { useForexPools } from '@one_deploy/sdk';
import type { ForexPoolTransaction } from '@one_deploy/sdk';

function PoolTransactions({ poolId }: { poolId: string }) {
const { getPoolTransactions } = useForexPools();
const [transactions, setTransactions] = useState<ForexPoolTransaction[]>([]);

useEffect(() => {
getPoolTransactions(poolId, { limit: 20 }).then(setTransactions);
}, [poolId, getPoolTransactions]);

return (
<FlatList
data={transactions}
keyExtractor={(tx) => tx.id}
renderItem={({ item }) => (
<View style={{ padding: 8, borderBottomWidth: 1, borderColor: '#333' }}>
<Text style={{ color: '#fff' }}>
{item.type.toUpperCase()} -- ${item.amount.toLocaleString()} {item.currency}
</Text>
<Text style={{ color: '#888', fontSize: 12 }}>
{new Date(item.timestamp).toLocaleString()}
</Text>
{item.txHash && (
<Text style={{ color: '#4488ff', fontSize: 12 }}>
Tx: {item.txHash.slice(0, 10)}...{item.txHash.slice(-8)}
</Text>
)}
</View>
)}
/>
);
}

按类型筛选池

import { useForexPools } from '@one_deploy/sdk';
import type { ForexPool, ForexPoolType } from '@one_deploy/sdk';

function usePoolByType(type: ForexPoolType): ForexPool | undefined {
const { pools } = useForexPools();
return pools.find((pool) => pool.type === type);
}

// Usage
function ClearingPoolCard() {
const clearingPool = usePoolByType('clearing');

if (!clearingPool) return null;

return (
<View>
<Text>Clearing Pool</Text>
<Text>TVL: ${clearingPool.totalValueLocked.toLocaleString()}</Text>
</View>
);
}

池生命周期

1. User deposits $10,000 USDC
|
2. computePoolAllocations splits the deposit
|-- Trading capital: $5,000
|-- Clearing pool: $2,500
|-- Hedging pool: $1,500
|-- Insurance pool: $1,000
|
3. Pools receive deposits (ForexPoolTransaction type: 'deposit')
|
4. Trades execute and settle through the clearing pool
|
5. Hedging pool rebalances when exposure thresholds are hit
|
6. Insurance pool covers any settlement shortfalls
|
7. Trading fees are collected and partially routed to insurance

后续步骤