After correcting the issue for bonus fund credit for BEP20
This commit is contained in:
parent
a407d49f02
commit
ad17999faf
@ -128,6 +128,9 @@ export async function updateAdminReferralSettings(req: AuthRequest, res: Respons
|
||||
minFirstDepositRaw: body.minFirstDepositRaw,
|
||||
commissionWalletTypeId: body.commissionWalletTypeId,
|
||||
});
|
||||
if (body.commissionWalletTypeId != null) {
|
||||
await bonusPoolRepository.ensurePool(body.commissionWalletTypeId);
|
||||
}
|
||||
const config = await referralService.getProgramSettingsForAdmin();
|
||||
res.json(config);
|
||||
} catch (e) {
|
||||
@ -202,6 +205,20 @@ export async function fundBonusPool(req: AuthRequest, res: Response): Promise<vo
|
||||
res.status(400).json({ error: 'Amount must be positive' });
|
||||
return;
|
||||
}
|
||||
|
||||
// Commissions debit the commission wallet pool only (unified USDT ledger = USDT_TRC20).
|
||||
// Custody rails (e.g. USDT_BEP20) must not be fundable here — there is no pool row for them.
|
||||
const settings = await referralRepository.getSettings();
|
||||
if (walletTypeId !== settings.commission_wallet_type_id) {
|
||||
res.status(400).json({
|
||||
error:
|
||||
'Bonus pool can only be funded for the referral commission wallet type (USDT ledger). ' +
|
||||
'BEP20/TRC20 deposit rails are not separate bonus pools.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
await bonusPoolRepository.ensurePool(walletTypeId);
|
||||
|
||||
const { createFundRequest } = await import('../services/fundApprovalService');
|
||||
const result = await createFundRequest({
|
||||
operationType: 'bonus_pool_fund',
|
||||
|
||||
@ -14,6 +14,24 @@ export async function listPools(): Promise<Array<{ wallet_type_id: number; avail
|
||||
);
|
||||
}
|
||||
|
||||
export async function hasPool(walletTypeId: number): Promise<boolean> {
|
||||
const rows = await query<{ wallet_type_id: number }[]>(
|
||||
'SELECT wallet_type_id FROM platform_bonus_pools WHERE wallet_type_id = $1',
|
||||
[walletTypeId]
|
||||
);
|
||||
return Boolean(rows[0]);
|
||||
}
|
||||
|
||||
/** Ensure a pool row exists (e.g. after changing commission wallet type). */
|
||||
export async function ensurePool(walletTypeId: number): Promise<void> {
|
||||
await query(
|
||||
`INSERT INTO platform_bonus_pools (wallet_type_id, available_balance)
|
||||
VALUES ($1, 0)
|
||||
ON CONFLICT (wallet_type_id) DO NOTHING`,
|
||||
[walletTypeId]
|
||||
);
|
||||
}
|
||||
|
||||
/** Admin funds the platform bonus pool (off-chain treasury allocation). */
|
||||
export async function fundPool(walletTypeId: number, amount: bigint): Promise<void> {
|
||||
const client = await getClient();
|
||||
@ -23,7 +41,11 @@ export async function fundPool(walletTypeId: number, amount: bigint): Promise<vo
|
||||
'SELECT available_balance FROM platform_bonus_pools WHERE wallet_type_id = $1 FOR UPDATE',
|
||||
[walletTypeId]
|
||||
);
|
||||
if (!row.rows[0]) throw new Error('Bonus pool not found for wallet type');
|
||||
if (!row.rows[0]) {
|
||||
throw new Error(
|
||||
'Bonus pool not found for wallet type. Fund only the commission wallet type (USDT_TRC20 ledger), not a custody rail like USDT_BEP20.'
|
||||
);
|
||||
}
|
||||
const newBalance = BigInt(row.rows[0].available_balance) + amount;
|
||||
await client.query(
|
||||
'UPDATE platform_bonus_pools SET available_balance = $1, updated_at = NOW() WHERE wallet_type_id = $2',
|
||||
|
||||
@ -213,6 +213,16 @@ export async function executeApprovedRequest(
|
||||
amountRaw: string;
|
||||
};
|
||||
const amount = BigInt(amountRaw);
|
||||
const settings = await (
|
||||
await import('../repositories/referralRepository')
|
||||
).getSettings();
|
||||
if (walletTypeId !== settings.commission_wallet_type_id) {
|
||||
throw new Error(
|
||||
'Bonus pool fund must target the referral commission wallet type (USDT ledger). ' +
|
||||
'Reject this request and re-fund using USDT_TRC20 — custody rails like USDT_BEP20 have no bonus pool.'
|
||||
);
|
||||
}
|
||||
await bonusPoolRepository.ensurePool(walletTypeId);
|
||||
await bonusPoolRepository.fundPool(walletTypeId, amount);
|
||||
const pools = await bonusPoolRepository.listPools();
|
||||
return { message: 'Pool funded', pools };
|
||||
|
||||
@ -148,12 +148,18 @@ export function ReferralAdminPage() {
|
||||
useEffect(() => {
|
||||
if (!configQ.data) return;
|
||||
setFundForm((f) => {
|
||||
if (f.walletTypeId) return f;
|
||||
const cfg = configQ.data;
|
||||
const allowedIds = new Set(
|
||||
(cfg.pools.length ? cfg.pools.map((p) => p.walletTypeId) : [cfg.settings.commissionWalletTypeId]).filter(
|
||||
Boolean
|
||||
)
|
||||
);
|
||||
const currentOk = f.walletTypeId && allowedIds.has(Number(f.walletTypeId));
|
||||
if (currentOk) return f;
|
||||
const preferred =
|
||||
cfg.settings.commissionWalletTypeId ||
|
||||
cfg.pools[0]?.walletTypeId ||
|
||||
cfg.walletTypes[0]?.id;
|
||||
[...allowedIds][0];
|
||||
return preferred ? { ...f, walletTypeId: String(preferred) } : f;
|
||||
});
|
||||
}, [configQ.data]);
|
||||
@ -930,7 +936,16 @@ export function ReferralAdminPage() {
|
||||
value={fundForm.walletTypeId}
|
||||
onChange={(e) => setFundForm((f) => ({ ...f, walletTypeId: String(e.target.value) }))}
|
||||
>
|
||||
{walletTypeOptions.map((wt) => (
|
||||
{/* Only pool rows (commission ledger) — not custody rails like BEP20 */}
|
||||
{(config?.pools?.length
|
||||
? config.pools.map((p) => ({
|
||||
id: p.walletTypeId,
|
||||
label: p.label,
|
||||
}))
|
||||
: walletTypeOptions
|
||||
.filter((wt) => wt.id === config?.settings.commissionWalletTypeId)
|
||||
.map((wt) => ({ id: wt.id, label: wt.label }))
|
||||
).map((wt) => (
|
||||
<MenuItem key={wt.id} value={String(wt.id)}>
|
||||
{wt.label}
|
||||
</MenuItem>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user