After trying to recuparate money from cold wallet10
This commit is contained in:
parent
bedda74d89
commit
88cf30c428
@ -65,12 +65,31 @@ export async function listPositiveSnapshots(): Promise<HdSnapshotRow[]> {
|
||||
wt.decimals,
|
||||
u.first_name,
|
||||
u.last_name,
|
||||
EXISTS (
|
||||
SELECT 1 FROM transactions t
|
||||
WHERE t.type = 'deposit'
|
||||
AND t.status = 'completed'
|
||||
AND lower(t.to_address) = lower(s.address)
|
||||
) AS credited,
|
||||
(
|
||||
COALESCE((
|
||||
SELECT SUM(
|
||||
COALESCE(
|
||||
NULLIF(t.metadata->>'chain_amount', '')::numeric,
|
||||
CASE
|
||||
WHEN wt.decimals = 18 THEN t.amount::numeric * 1000000000000
|
||||
ELSE t.amount::numeric
|
||||
END
|
||||
)
|
||||
)
|
||||
FROM transactions t
|
||||
WHERE t.type = 'deposit'
|
||||
AND t.status = 'completed'
|
||||
AND lower(t.to_address) = lower(s.address)
|
||||
), 0)
|
||||
-
|
||||
COALESCE((
|
||||
SELECT SUM(ds.amount::numeric)
|
||||
FROM deposit_sweeps ds
|
||||
WHERE ds.status = 'completed'
|
||||
AND lower(ds.from_address) = lower(s.address)
|
||||
), 0)
|
||||
) >= s.on_chain_amount
|
||||
AS credited,
|
||||
EXISTS (
|
||||
SELECT 1 FROM deposit_sweeps ds
|
||||
WHERE ds.status IN ('pending', 'gas_funding', 'broadcasting')
|
||||
|
||||
@ -326,21 +326,29 @@ export async function creditBscDepositByTxHash(txHash: string): Promise<{
|
||||
if (receipt.status !== 1) return { credited: false, reason: 'transaction failed on-chain' };
|
||||
|
||||
const contract = bscService.resolveUsdtContract(custodyType.contract_address).toLowerCase();
|
||||
const transfer = receipt.transfers.find((t) => t.contract.toLowerCase() === contract);
|
||||
if (!transfer) {
|
||||
const usdtTransfers = receipt.transfers.filter((t) => t.contract.toLowerCase() === contract);
|
||||
if (usdtTransfers.length === 0) {
|
||||
return { credited: false, reason: 'no USDT Transfer log for configured BEP20 contract' };
|
||||
}
|
||||
|
||||
const rows = await query<Array<{ address: string; user_id: string }>>(
|
||||
`SELECT address, user_id FROM user_wallets
|
||||
WHERE wallet_type_id = $1 AND lower(address) = lower($2)`,
|
||||
[custodyType.id, transfer.to]
|
||||
);
|
||||
const wallet = rows[0];
|
||||
let wallet: { address: string; user_id: string } | undefined;
|
||||
let transfer = usdtTransfers[0];
|
||||
for (const t of usdtTransfers) {
|
||||
const rows = await query<Array<{ address: string; user_id: string }>>(
|
||||
`SELECT address, user_id FROM user_wallets
|
||||
WHERE wallet_type_id = $1 AND lower(address) = lower($2)`,
|
||||
[custodyType.id, t.to]
|
||||
);
|
||||
if (rows[0]) {
|
||||
wallet = rows[0];
|
||||
transfer = t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!wallet) {
|
||||
return {
|
||||
credited: false,
|
||||
reason: `no USDT_BEP20 user_wallet for to=${transfer.to}`,
|
||||
reason: `no USDT_BEP20 user_wallet for to=${usdtTransfers.map((t) => t.to).join(',')}`,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user