简单赚币系统设计
类 Binance Simple Earn 的完整赚币产品体系:活期/定期理财、资金费率套利、PoS 质押、流动性质押、借贷池,以及双币投资等结构化产品的系统设计与实现。
1. 赚币产品总览
各大交易所(Binance / OKX / Bybit)都提供「简单赚币」产品,本质是将用户闲置资产投入到不同收益来源中。了解底层原理后,可以自建系统获取更高收益或为平台用户提供赚币服务。
各平台产品对比
┌──────────────┬────────────────┬────────────────┬────────────────┐ │ 产品 │ Binance │ OKX │ Bybit │ ├──────────────┼────────────────┼────────────────┼────────────────┤ │ 活期 (USDT) │ 2.5% APY │ 2.0% APY │ 3.0% APY │ │ 定期 30天 │ 4.5% APY │ 4.0% APY │ 4.2% APY │ │ 定期 90天 │ 5.5% APY │ 5.8% APY │ 5.0% APY │ │ ETH 质押 │ 3.2% (BETH) │ 3.0% │ 3.5% │ │ SOL 质押 │ 6.5% │ 6.0% │ 7.0% │ │ 双币投资 │ 5-200%+ │ 5-150%+ │ 5-100%+ │ │ 资金费率套利 │ 手动/第三方 │ 手动 │ ─ │ │ 借贷 (供给) │ Binance Loan │ OKX Earn │ Bybit Lending │ ├──────────────┼────────────────┼────────────────┼────────────────┤ │ 收益来源 │ 借贷+平台补贴 │ 借贷+平台补贴 │ 借贷+平台补贴 │ │ 风险等级 │ 低-高 │ 低-高 │ 低-高 │ │ 最低门槛 │ $1 │ $1 │ $1 │ └──────────────┴────────────────┴────────────────┴────────────────┘ // 重要: APY 会根据市场供需实时变化 // 牛市期间: 借贷需求高 → 活期/定期收益上升 // 熊市期间: 需求低 → 收益下降,但资金费率套利可能更好
收益计算器
输入资金和期限,横向对比各平台各类产品的收益:
| 产品 | 平台 | 类型 | 资产 | APY | 锁定 | 风险 | 365 天收益 | 最终金额 |
|---|---|---|---|---|---|---|---|---|
| 资金费率套利 | Self-Managed | 套利 | USDT | 15.0% | 灵活 | 中 | +1617.98 | 11,617.98 |
| SOL 质押 | Binance | 质押 | SOL | 6.5% | 灵活 | 中 | +671.53 | 10,671.53 |
| 定期 90 天 | OKX | 定期 | USDT | 5.8% | 90天 | 低 | +597.10 | 10,597.1 |
| 定期 60 天 | Binance | 定期 | USDT | 5.2% | 60天 | 低 | +533.72 | 10,533.72 |
| Aave USDC | Aave | DeFi | USDC | 4.8% | 灵活 | 中 | +491.67 | 10,491.67 |
| 定期 30 天 | Binance | 定期 | USDT | 4.5% | 30天 | 低 | +460.25 | 10,460.25 |
| Compound USDT | Compound | DeFi | USDT | 4.2% | 灵活 | 中 | +428.92 | 10,428.92 |
| ETH Lido | Lido | DeFi | ETH | 3.5% | 灵活 | 中 | +356.18 | 10,356.18 |
| ETH 质押 | Binance | 质押 | ETH | 3.2% | 灵活 | 中 | +325.16 | 10,325.16 |
| 活期赚币 | Bybit | 活期 | USDT | 3.0% | 灵活 | 低 | +304.53 | 10,304.53 |
| 活期赚币 | Binance | 活期 | USDT | 2.5% | 灵活 | 低 | +253.14 | 10,253.14 |
| 活期赚币 | OKX | 活期 | USDT | 2.0% | 灵活 | 低 | +202.01 | 10,202.01 |
2. 活期赚币 (Flexible Savings)
活期赚币是最基础的理财产品。用户存入资产后按日计息,随时可以赎回。底层资金被借给杠杆交易用户和做市商,利息的大部分返还给存款用户。
活期赚币实现
// === 活期赚币核心数据结构 ===
// 份额模型 (类似基金净值)
// 用户持有"份额"而非直接持有资产
// 好处: 利息自动复利,无需逐笔计算
table flexible_savings_pool:
pool_id BIGINT PRIMARY KEY
asset VARCHAR(10) // USDT, BTC, ETH
total_shares DECIMAL(36,18) // 总份额
total_assets DECIMAL(36,18) // 总资产 (含已产生利息)
share_price DECIMAL(36,18) // 每份价值 = total_assets / total_shares
base_rate DECIMAL(10,8) // 基础年化利率
utilization DECIMAL(10,8) // 资金利用率
reserve_ratio DECIMAL(10,8) // 储备率 (预留可赎回)
last_update TIMESTAMP
table user_flexible_position:
user_id BIGINT
pool_id BIGINT
shares DECIMAL(36,18) // 持有份额
deposit_time TIMESTAMP
PRIMARY KEY (user_id, pool_id)
// === 存入 (Subscribe) ===
function deposit(userId, asset, amount):
pool = getPool(asset)
// 1. 计算可获得的份额
shares = amount / pool.share_price
// 例: 存入 10,000 USDT, share_price = 1.002
// shares = 10,000 / 1.002 = 9,980.04 份
// 2. 更新池子
pool.total_shares += shares
pool.total_assets += amount
// 3. 更新用户持仓
userPosition.shares += shares
// 4. 资金划转: 用户现货账户 → 理财池
transfer(userId, "SPOT" → "EARN", amount)
return { shares, sharePrice: pool.share_price }
// === 赎回 (Redeem) ===
function redeem(userId, asset, shares):
pool = getPool(asset)
// 1. 计算可取回金额 (含利息)
amount = shares * pool.share_price
// 例: 赎回 9,980.04 份, share_price 已涨到 1.005
// amount = 9,980.04 * 1.005 = 10,029.94 USDT (赚了 29.94)
// 2. 流动性检查
available = pool.total_assets * (1 - pool.utilization)
if amount > available:
// 排队赎回 or 拒绝
return ERROR("流动性不足,请稍后再试")
// 3. 更新池子
pool.total_shares -= shares
pool.total_assets -= amount
// 4. 资金划转
transfer(userId, "EARN" → "SPOT", amount)
return { amount, profit: amount - originalDeposit }
// === 每日利息结算 (Accrue Interest) ===
function dailyAccrue(pool):
// 1. 计算当日利息收入
lentAmount = pool.total_assets * pool.utilization
dailyRate = pool.base_rate / 365
grossInterest = lentAmount * dailyRate
// 2. 平台抽成
platformFee = grossInterest * 0.15 // 15% 归平台
netInterest = grossInterest - platformFee
// 3. 更新池子总资产 (份额不变,单价上升 → 利息自动复利)
pool.total_assets += netInterest
pool.share_price = pool.total_assets / pool.total_shares
// share_price 每天微涨,用户赎回时自然获得利息
// 4. 更新利率 (根据利用率)
pool.base_rate = calcRate(pool.utilization)
return { grossInterest, netInterest, newSharePrice: pool.share_price }用户持有份额而非直接持有资产。池子 share_price 每天上涨,赎回时按最新价兑换。利息自动复利。
利率 = f(利用率)。存款多、借款少 → 利率下降。借款需求旺盛 → 利率上升。供需自平衡。
预留 20% 资金池不出借,保证日常赎回。大额赎回可能需要排队。极端情况启用赎回限制。
小额赎回即时到账 (从储备金中支付)。大额赎回 T+1 (等待借款回收)。紧急赎回收取 0.1% 费用。
3. 定期赚币 (Fixed Savings)
定期产品锁定用户资金一段时间,换取更高利率。锁定期间资金不可赎回。因为资金确定性更强,平台可以更充分地利用这些资金,提供更高回报。
// === 定期产品数据结构 ===
table fixed_savings_product:
product_id BIGINT PRIMARY KEY
asset VARCHAR(10)
duration_days INT // 30, 60, 90, 120
apy DECIMAL(10,6) // 年化利率
total_quota DECIMAL(36,18) // 总额度
subscribed DECIMAL(36,18) // 已申购
min_amount DECIMAL(36,18) // 最小申购
max_per_user DECIMAL(36,18) // 单用户限额
status ENUM('upcoming','open','closed','settled')
open_time TIMESTAMP // 开放申购时间
lock_start TIMESTAMP // 锁定开始时间
table fixed_savings_order:
order_id BIGINT PRIMARY KEY
user_id BIGINT
product_id BIGINT
principal DECIMAL(36,18) // 本金
interest DECIMAL(36,18) // 应付利息 (预计算)
status ENUM('locked','settled','redeemed')
lock_time TIMESTAMP
mature_time TIMESTAMP
auto_renew BOOLEAN
// === 申购 ===
function subscribe(userId, productId, amount):
product = getProduct(productId)
// 1. 校验
if product.status != 'open': return ERROR("产品未开放")
if amount < product.min_amount: return ERROR("低于最低限额")
if amount > product.max_per_user: return ERROR("超过个人限额")
remaining = product.total_quota - product.subscribed
if amount > remaining: return ERROR("额度不足")
// 2. 预计算利息
interest = amount * product.apy * product.duration_days / 365
// 3. 创建订单
order = {
userId, productId,
principal: amount,
interest,
status: 'locked',
lockTime: now(),
matureTime: now() + product.duration_days * DAY,
autoRenew: false,
}
// 4. 冻结资金
product.subscribed += amount
transfer(userId, "SPOT" → "EARN_FIXED", amount)
return order
// === 到期结算 (定时任务) ===
function settleMaturedOrders():
orders = query("SELECT * FROM fixed_savings_order
WHERE status = 'locked' AND mature_time <= NOW()")
for order in orders:
total = order.principal + order.interest
if order.auto_renew:
// 利息发放到现货,本金自动续期
transfer(order.userId, "EARN_FIXED" → "SPOT", order.interest)
renewOrder(order)
else:
// 本金 + 利息全部返还
transfer(order.userId, "EARN_FIXED" → "SPOT", total)
order.status = 'settled'
// === 提前赎回 (部分平台支持) ===
function earlyRedeem(orderId):
order = getOrder(orderId)
// 罚息: 已产生利息全部扣除
elapsed = (now() - order.lockTime) / DAY
earnedInterest = order.principal * product.apy * elapsed / 365
penalty = earnedInterest // 全部利息作为罚金
refund = order.principal // 只退本金,无利息
transfer(userId, "EARN_FIXED" → "SPOT", refund)
order.status = 'redeemed'额度抢购
热门定期产品限额发售。高利率产品在开放后数秒售罄。使用秒杀架构(预扣库存+异步确认)。
利息预计算
申购时即确定到期利息。利息来源 = 平台出借资金的利息收入 + 平台补贴。
自动续期
到期后本金自动转入新一期同产品。利息发放到现货账户。适合长期持有用户。
提前赎回
部分平台允许提前赎回但扣除全部已产生利息。相当于免费锁仓。不建议提前赎回。
4. 资金费率套利赚币
资金费率套利是收益最高且相对安全的赚币方式。同时持有现货多头和永续合约空头,价格涨跌互相对冲,净赚每 8 小时的正资金费率。牛市期间年化可达 15-30%。
自建资金费率套利系统
// === 资金费率套利 Bot ===
class FundingRateArbBot:
def __init__(self, config):
self.exchange = config.exchange
self.symbol = config.symbol // "BTCUSDT"
self.capitalUsdt = config.capital // 100,000 USDT
self.minRate = config.minRate // 0.005% 最低正费率
self.maxPositionPct = 0.9 // 90% 资金使用率
// === 开仓逻辑 ===
def openPosition(self):
price = self.exchange.getMarkPrice(self.symbol)
// 资金分配: 50% 买现货, 50% 做保证金 (1x 杠杆空)
spotAmount = self.capitalUsdt * 0.5
quantity = spotAmount / price
// 1. 买入现货
spotOrder = self.exchange.createOrder(
symbol=self.symbol,
side="BUY",
type="MARKET",
quantity=quantity,
market="SPOT"
)
// 2. 做空永续合约 (1x 杠杆,保证金 = 另外 50%)
perpOrder = self.exchange.createOrder(
symbol=self.symbol,
side="SELL",
type="MARKET",
quantity=quantity,
leverage=1,
market="PERP"
)
log(f"开仓完成: 现货 {quantity} BTC, 合约空 {quantity} BTC")
// === 监控循环 ===
def monitor(self):
while True:
rate = self.exchange.getFundingRate(self.symbol)
nextSettlement = self.exchange.getNextFundingTime()
position = self.getPosition()
// 检查是否需要平仓
if self.shouldClose(rate, position):
self.closePosition()
log("费率转负/触发止损,平仓")
break
// 再平衡: 价格大幅变动后现货/合约仓位不对等
if self.needRebalance(position):
self.rebalance(position)
// 收益复投 (可选)
if position.unrealizedProfit > self.capitalUsdt * 0.01:
self.compound(position.unrealizedProfit)
sleep(60) // 每分钟检查
// === 平仓条件 ===
def shouldClose(self, currentRate, position):
// 1. 资金费率连续 3 次为负
recentRates = self.exchange.getRecentFundingRates(self.symbol, 3)
if all(r < 0 for r in recentRates):
return True
// 2. 预测费率持续为负 (合约折价)
premiumIndex = self.exchange.getPremiumIndex(self.symbol)
if premiumIndex < -0.005: // 合约折价 > 0.5%
return True
// 3. 累计亏损超限 (极端情况)
if position.unrealizedPnl < -self.capitalUsdt * 0.02:
return True
return False
// === 再平衡 ===
def rebalance(self, position):
spotQty = position.spotQuantity
perpQty = position.perpQuantity
diff = abs(spotQty - perpQty)
if diff / spotQty > 0.01: // 偏差 > 1%
if spotQty > perpQty:
// 合约端加空
self.exchange.createOrder("SELL", diff, market="PERP")
else:
// 现货端加仓
self.exchange.createOrder("BUY", diff, market="SPOT")
// === 收益计算 ===
// 假设:
// 资金: 100,000 USDT
// BTC 价格: 42,000
// 仓位: ~1.19 BTC (50,000 USDT 现货)
// 名义价值: ~50,000 USDT
// 平均费率: 0.01% (每 8 小时)
//
// 每次收益 = 50,000 * 0.0001 = 5 USDT
// 日收益 = 5 * 3 = 15 USDT
// 月收益 = 15 * 30 = 450 USDT
// 年收益 = 15 * 365 = 5,475 USDT
// 年化 APY = 5,475 / 100,000 = 5.475%
//
// 牛市 (费率 0.03-0.05%):
// 年化可达 15-25%
//
// 注意成本:
// 开仓手续费: ~50 USDT (一次性)
// 资金占用: 合约需要保证金现货多+合约空完全对冲。BTC 涨 1000,现货赚 1000 合约亏 1000,净值不变。只赚费率。
永续合约资金费率。正费率时空头从多头处收取。牛市正费率频率高(> 90%),年化可达 15-30%。
负费率时反向支付、合约强平风险(需维持保证金)、现货/合约价差变化、交易所风险。
平台产品收益被抽成。自建 Bot 可获取全部费率收益,还可跨所比较选择最高费率。
资金费率套利模拟器
设置仓位和费率参数,模拟资金费率结算过程,观察长期收益:
5. 质押赚币 (Staking)
// === 质押类型对比 ===
┌──────────────┬──────────────┬──────────────┬──────────────┬──────────────┐
│ 方式 │ ETH 原生质押 │ Lido (stETH)│ 交易所质押 │ SOL 委托质押 │
├──────────────┼──────────────┼──────────────┼──────────────┼──────────────┤
│ 最低门槛 │ 32 ETH │ 0.01 ETH │ 0.01 ETH │ 0.01 SOL │
│ APY │ ~3.5% │ ~3.5% │ ~3.0% │ ~6.5% │
│ 流动性 │ 需要退出队列 │ stETH 可交易│ 灵活赎回 │ 2天解质押 │
│ 抽成 │ 无 │ 10% │ 10-20% │ 验证者5-10% │
│ 安全性 │ 最高 │ 智能合约风险 │ 平台信用 │ 验证者风险 │
│ 额外用途 │ 无 │ DeFi 可组合 │ 无 │ DeFi 可组合 │
│ 去中心化 │ 最高 │ 中等 │ 最低 │ 高 │
└──────────────┴──────────────┴──────────────┴──────────────┴──────────────┘
// === 自建质押服务实现 ===
class StakingService:
// 用户质押入口
def stake(self, userId, asset, amount):
if asset == "ETH":
// 聚合到 32 ETH 后创建验证节点
pool = self.getOrCreatePool(asset)
pool.pending += amount
if pool.pending >= 32:
validatorPubKey = self.createValidator(pool.pending)
pool.pending = pool.pending - 32
pool.activeValidators.append(validatorPubKey)
// 给用户发放质押凭证 (类似 BETH)
mintStakingToken(userId, amount)
elif asset == "SOL":
// 委托给验证者节点
validator = self.selectBestValidator()
delegateTx = createDelegation(amount, validator)
submitTransaction(delegateTx)
mintStakingToken(userId, amount)
// 收益分配 (每日)
def distributeRewards(self):
// 1. 获取链上奖励
rewards = self.getEpochRewards()
// 2. 扣除运营费
platformFee = rewards * 0.10 // 10% 平台抽成
netRewards = rewards - platformFee
// 3. 按份额分配
for user in self.getStakers():
userShare = user.stakedAmount / totalStaked
userReward = netRewards * userShare
// 增加用户质押凭证余额 (自动复利)
user.stakingTokenBalance += userReward / stakingTokenPrice
// 选择验证者 (委托质押)
def selectBestValidator(self):
validators = self.getValidators()
// 评分: APY 权重 40%, 正常运行时间 30%, 佣金率 20%, 去中心化 10%
scored = []
for v in validators:
score = (v.apy * 0.4
+ v.uptime * 0.3
+ (1 - v.commission) * 0.2
+ v.decentralizationScore * 0.1)
scored.append((v, score))
return max(scored, key=lambda x: x[1])[0]直接参与 PoS 共识,最安全。ETH 需 32 个起,SOL 无门槛。收益来自区块奖励+交易费。
Lido / Rocket Pool 将质押资产代币化 (stETH/rETH)。用户可在 DeFi 中继续使用,叠加收益。
交易所聚合小额用户质押。优点是门槛低、操作简单。缺点是平台抽成、中心化风险。
EigenLayer 等协议允许已质押 ETH 再次质押到其他协议。额外收益但增加 Slashing 风险。
6. 借贷赚币 (Lending)
借贷是赚币产品的核心底层。用户存入资产到借贷池,借款人抵押资产后借出。存款人赚取利息,利率由资金利用率动态决定。Aave / Compound 是典型的去中心化借贷协议。
借贷池利率模型
// === 分段线性利率模型 (Aave V3 风格) ===
// 参数:
// U_optimal = 80% // 最优利用率 (拐点)
// R_base = 2% // 基础利率
// R_slope1 = 8% // 低利用率段斜率
// R_slope2 = 90% // 高利用率段斜率 (陡峭)
function borrowRate(utilization):
if utilization <= U_optimal:
// 低利用率段: 利率缓慢上升
return R_base + (utilization / U_optimal) * R_slope1
// U=0%: 2%, U=40%: 6%, U=80%: 10%
else:
// 高利用率段: 利率急剧上升 (激励还款 & 新存款)
excess = (utilization - U_optimal) / (1 - U_optimal)
return R_base + R_slope1 + excess * R_slope2
// U=85%: 32.5%, U=90%: 55%, U=95%: 77.5%, U=100%: 100%
function supplyRate(utilization, reserveFactor=0.10):
// 存款利率 = 借款利率 × 利用率 × (1 - 储备金率)
return borrowRate(utilization) * utilization * (1 - reserveFactor)
// 储备金率: 10% 利息归协议/平台, 90% 归存款人
// === 为什么利率曲线要在 80% 处急剧上升? ===
// 1. 利用率 < 80%: 正常运营, 利率温和, 鼓励借贷
// 2. 利用率 > 80%: 流动性紧张!
// - 存款人可能无法赎回 → 高利率吸引新存款
// - 借款人成本飙升 → 激励还款减少借款
// - 自动平衡供需, 保证池子流动性
// === 清算机制 ===
function checkLiquidation(borrower):
collateralValue = sum(asset.amount * oracle.getPrice(asset) * asset.ltv
for asset in borrower.collaterals)
debtValue = sum(debt.amount * oracle.getPrice(debt.asset)
for debt in borrower.debts)
healthFactor = collateralValue / debtValue
if healthFactor < 1.0:
// 触发清算: 清算人最多偿还 50% 债务
maxLiquidation = debtValue * 0.5
// 清算人获得等值抵押品 + 5% 折扣 (清算奖励)
liquidationBonus = 1.05
collateralSeized = maxLiquidation * liquidationBonus
return { canLiquidate: true, maxAmount: maxLiquidation, bonus: "5%" }
// === 闪电贷 (Flash Loan) ===
// 在同一交易内借出并归还, 无需抵押品
// 用途: 套利, 清算, 抵押品互换
function flashLoan(amount, asset, callback):
pool.transfer(amount, borrower) // 1. 借出
callback() // 2. 用户执行操作
assert pool.balance >= originalBalance + fee // 3. 检查还款
// 如果未还款, 整个交易回滚 (原子性)借款必须提供超过借款价值的抵押品 (LTV 50-80%)。ETH 抵押率 80% = 1 ETH 可借 0.8 ETH 等值 USDT。
分段线性模型。80% 拐点前平缓,拐点后陡峭。高利用率时利率飙升,自动调节供需平衡。
健康因子 < 1.0 时任何人可清算。清算人偿还债务获得抵押品 5% 折扣。保障池子不会坏账。
无抵押单交易借贷。必须在同一交易中归还。失败则整个交易回滚。用于套利和清算。
借贷池模拟器
调整池子参数,模拟存借操作。观察利用率如何影响利率,以及健康因子如何决定清算风险:
7. 结构化产品
结构化产品通过组合基础金融工具(主要是期权),为用户提供增强收益。典型产品:双币投资(Dual Investment)、鲨鱼鳍(Shark Fin)、雪球(Snowball)。
// === 双币投资 (Dual Investment) ===
// 本质: 用户卖出一个期权, 收取权利金作为收益
// "低买": 卖出 Put 期权 → 目标价以下则买入 BTC
// "高卖": 卖出 Call 期权 → 目标价以上则卖出 BTC
// 例: USDT 低买双币投资
// 存入: 10,000 USDT
// 目标价: 40,000 (当前 42,000)
// 期限: 7 天
// APY: 58%
function dualInvestSettle(deposit, targetPrice, currentPrice, apy, days):
premium = deposit * apy * days / 365
if currentPrice <= targetPrice:
// 到期价 <= 目标价: 用户以目标价买入 BTC
btcAmount = (deposit + premium) / targetPrice
return { asset: "BTC", amount: btcAmount, note: "按目标价买入 BTC" }
else:
// 到期价 > 目标价: 用户获得 USDT + 收益
return { asset: "USDT", amount: deposit + premium, note: "获得本金+收益" }
// === 鲨鱼鳍 (Shark Fin) ===
// 看涨鲨鱼鳍: 看好小涨, 设定价格区间
// 到期价在区间内 → 高收益 (线性增长)
// 到期价在区间外 → 保本 + 基础收益
function sharkFinSettle(deposit, lowerBarrier, upperBarrier,
currentPrice, maxAPY, baseAPY, days):
if currentPrice >= lowerBarrier and currentPrice <= upperBarrier:
// 区间内: 收益随价格线性增长
position = (currentPrice - lowerBarrier) / (upperBarrier - lowerBarrier)
effectiveAPY = baseAPY + position * (maxAPY - baseAPY)
else:
// 区间外: 基础收益 (保本)
effectiveAPY = baseAPY
earnings = deposit * effectiveAPY * days / 365
return { amount: deposit + earnings, apy: effectiveAPY }
// === 平台如何赚钱 ===
// 1. 双币投资: 平台将用户卖出的期权在 Deribit 等期权市场对冲
// 权利金 (用户获得) < 实际期权价格 → 差额归平台
// 2. 鲨鱼鳍: 平台构建障碍期权组合, 成本 < 用户获得的收益
// 用户获得固定收益, 平台通过期权对冲获得利润
// 3. 雪球: 类似自动可赎回结构票据 (Autocallable Note)
// 平台本质是期权做市商, 通过 Delta 对冲管理风险双币投资
本质是卖期权收权利金。低买 = 卖 Put(愿意低价接盘),高卖 = 卖 Call(愿意高价卖出)。收益高但有转换风险。
鲨鱼鳍
保本型结构化产品。价格在区间内获得最高收益,区间外仍保本。适合认为市场小幅波动的用户。
雪球
高收益但有敲入亏损风险。价格温和波动时持续获得票息。暴跌敲入时承受全部跌幅。高风险高收益。
对冲原理
平台在专业期权市场 (Deribit) 买入对应期权对冲。用户收益 = 期权权利金 - 平台利润。
8. 系统架构实现
// === 数据库核心表 ===
// 产品表 (活期/定期/质押/借贷)
table earn_product:
id BIGSERIAL PRIMARY KEY
type ENUM('flexible','fixed','staking','lending','structured')
asset VARCHAR(10)
name VARCHAR(100)
apy_base DECIMAL(10,6)
apy_current DECIMAL(10,6) // 实时利率
total_quota DECIMAL(36,18)
subscribed DECIMAL(36,18)
min_amount DECIMAL(36,18)
max_per_user DECIMAL(36,18)
lock_days INT DEFAULT 0
status ENUM('active','paused','closed')
created_at TIMESTAMP
// 用户持仓表
table earn_position:
id BIGSERIAL PRIMARY KEY
user_id BIGINT NOT NULL
product_id BIGINT REFERENCES earn_product(id)
principal DECIMAL(36,18) // 本金
shares DECIMAL(36,18) // 份额 (活期)
accrued_interest DECIMAL(36,18) // 已计利息
subscribe_time TIMESTAMP
mature_time TIMESTAMP // 定期到期时间
auto_renew BOOLEAN DEFAULT false
status ENUM('active','matured','redeemed')
// 利息流水表
table earn_interest_log:
id BIGSERIAL PRIMARY KEY
position_id BIGINT
user_id BIGINT
interest_date DATE
daily_rate DECIMAL(16,12)
interest_amount DECIMAL(36,18)
share_price DECIMAL(36,18) // 当日净值
created_at TIMESTAMP
// 资金池表
table earn_pool:
id BIGSERIAL PRIMARY KEY
asset VARCHAR(10)
total_deposits DECIMAL(36,18)
total_borrowed DECIMAL(36,18)
utilization DECIMAL(10,8)
supply_rate DECIMAL(10,8)
borrow_rate DECIMAL(10,8)
reserve_balance DECIMAL(36,18) // 储备金
share_price DECIMAL(36,18)
updated_at TIMESTAMP
// === 定时任务 ===
// 每日 00:00 UTC: 利息结算 (活期)
// 每日 00:00 UTC: 到期检查 (定期)
// 每分钟: 利率更新 (借贷池)
// 每 8 小时: 资金费率结算 (套利产品)
// 每日: 对账校验 (资金一致性)每类产品独立资金池。活期池、定期池、借贷池、质押池互相隔离。单个池子出问题不影响其他产品。
活期产品使用份额模型。share_price 每日上涨体现利息。避免逐用户逐笔计算利息,性能优异。
利息结算通过 Kafka 异步处理。结算任务幂等(同一天不重复结算)。失败可重试不会重复发息。
用户持仓总和 = 池子总资产 + 储备金。任何偏差立即报警。防止利息计算 bug 导致资金损失。
9. 风控与清算
// === 清算流程 (借贷池) ===
// 1. 清算检测 (每个区块/每秒)
function checkLiquidations():
borrowers = getAllActiveBorrowers()
for borrower in borrowers:
healthFactor = calcHealthFactor(borrower)
if healthFactor < 1.0:
// 触发清算
liquidationOpportunity = {
borrower: borrower.address,
debtAsset: borrower.debtAsset,
debtAmount: borrower.debt * 0.5, // 最多清算 50%
collateralAsset: borrower.collateralAsset,
collateralAmount: borrower.debt * 0.5 * 1.05, // 5% 奖励
healthFactor,
}
emitLiquidationEvent(liquidationOpportunity)
// 2. 清算执行 (清算机器人 / MEV)
function executeLiquidation(borrower, debtAmount, collateralAsset):
// a. 清算人支付债务代币
transferFrom(liquidator, pool, debtAmount, debtAsset)
// b. 清算人获得抵押品 (含 5% 折扣)
collateralToSeize = debtAmount * getPrice(debtAsset) / getPrice(collateralAsset) * 1.05
transfer(pool, liquidator, collateralToSeize, collateralAsset)
// c. 更新借款人仓位
borrower.debt -= debtAmount
borrower.collateral -= collateralToSeize
// 3. 坏账处理
function handleBadDebt(borrower):
if borrower.collateral <= 0 and borrower.debt > 0:
// 抵押品不足以覆盖债务 → 坏账
badDebt = borrower.debt
// 从保险基金中扣除
if insuranceFund.balance >= badDebt:
insuranceFund.balance -= badDebt
else:
// 保险基金不足 → 社会化分摊 (所有存款人均摊损失)
lossPerShare = badDebt / pool.totalShares
pool.sharePrice -= lossPerShare
// === 风险参数建议 ===
┌──────────────┬──────────────┬──────────────┬──────────────┐
│ 资产 │ LTV (借贷率) │ 清算阈值 │ 清算奖励 │
├──────────────┼──────────────┼──────────────┼──────────────┤
│ ETH │ 80% │ 82.5% │ 5% │
│ BTC │ 75% │ 78% │ 5% │
│ USDC/USDT │ 85% │ 87% │ 3% │
│ SOL │ 65% │ 70% │ 8% │
│ 其他 Altcoin │ 50-60% │ 55-65% │ 10% │
└──────────────┴──────────────┴──────────────┴──────────────┘健康因子
= 抵押品价值 * LTV / 借款价值。< 1.0 触发清算。< 1.2 发出预警通知用户追加抵押品。
价格预言机
使用 Chainlink 等多源聚合预言机。防止单一价格源被操纵导致错误清算。
保险基金
清算罚金的一部分注入保险基金。用于覆盖极端行情下的坏账。不足时存款人共担损失。
赎回熔断
单日赎回超过池子 30% 时启动排队机制。防止银行挤兑式赎回导致流动性危机。