fix(trading-service): 区块链充值 balanceBefore 从 trading_accounts 读取
修复 MarketMakerDepositConsumerService 读取 market_maker_configs.cash_balance 作为 balanceBefore 的 bug。该字段由中心化充值路径不维护,导致区块链充值 流水中 balanceBefore 始终为 0 或脱轨值。 改为与 deposit()/withdraw() 一致: - balanceBefore 从 trading_accounts 读取(权威数据源) - 删除对 market_maker_configs.cash_balance 的写操作 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
7aa7a54d9c
commit
e306f346d3
|
|
@ -204,25 +204,23 @@ export class MarketMakerDepositConsumerService implements OnModuleInit, OnModule
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 根据资产类型更新余额
|
// 2. 根据资产类型更新余额
|
||||||
|
// 与中心化充值保持一致:只操作 trading_accounts,balanceBefore 从 trading_accounts 读取
|
||||||
const assetField = payload.assetType === 'EUSDT' ? 'shareBalance' : 'cashBalance';
|
const assetField = payload.assetType === 'EUSDT' ? 'shareBalance' : 'cashBalance';
|
||||||
const currentBalance = payload.assetType === 'EUSDT'
|
const depositAmount = new Prisma.Decimal(payload.amountFormatted);
|
||||||
? marketMaker.shareBalance
|
|
||||||
: marketMaker.cashBalance;
|
|
||||||
const newBalance = currentBalance.add(new Prisma.Decimal(payload.amountFormatted));
|
|
||||||
|
|
||||||
// 更新做市商配置余额
|
const tradingAccountBefore = await tx.tradingAccount.findUnique({
|
||||||
await tx.marketMakerConfig.update({
|
where: { accountSequence: marketMaker.accountSequence },
|
||||||
where: { id: marketMaker.id },
|
|
||||||
data: {
|
|
||||||
[assetField]: newBalance,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
const currentBalance = tradingAccountBefore
|
||||||
|
? (payload.assetType === 'EUSDT' ? tradingAccountBefore.shareBalance : tradingAccountBefore.cashBalance)
|
||||||
|
: new Prisma.Decimal(0);
|
||||||
|
const newBalance = currentBalance.add(depositAmount);
|
||||||
|
|
||||||
// 同步更新交易账户余额(getConfig 从 trading_accounts 读取余额)
|
// 更新交易账户余额(权威数据源,与中心化充值路径一致)
|
||||||
await tx.tradingAccount.update({
|
await tx.tradingAccount.update({
|
||||||
where: { accountSequence: marketMaker.accountSequence },
|
where: { accountSequence: marketMaker.accountSequence },
|
||||||
data: {
|
data: {
|
||||||
[assetField]: { increment: new Prisma.Decimal(payload.amountFormatted) },
|
[assetField]: { increment: depositAmount },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -232,7 +230,7 @@ export class MarketMakerDepositConsumerService implements OnModuleInit, OnModule
|
||||||
marketMakerId: marketMaker.id,
|
marketMakerId: marketMaker.id,
|
||||||
type: 'DEPOSIT',
|
type: 'DEPOSIT',
|
||||||
assetType: payload.assetType === 'EUSDT' ? 'SHARE' : 'CASH',
|
assetType: payload.assetType === 'EUSDT' ? 'SHARE' : 'CASH',
|
||||||
amount: new Prisma.Decimal(payload.amountFormatted),
|
amount: depositAmount,
|
||||||
balanceBefore: currentBalance,
|
balanceBefore: currentBalance,
|
||||||
balanceAfter: newBalance,
|
balanceAfter: newBalance,
|
||||||
memo: `区块链充值: ${payload.txHash.slice(0, 10)}... (${payload.fromAddress.slice(0, 10)}...)`,
|
memo: `区块链充值: ${payload.txHash.slice(0, 10)}... (${payload.fromAddress.slice(0, 10)}...)`,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue