Skip to content

Commit 9ce8fe8

Browse files
committed
Merge dev: fix account key comparison in deposit detector
2 parents 3b6c3a6 + b0f386d commit 9ce8fe8

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

src/services/deposit.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,25 @@ export class DepositDetector {
5050
const txDetail = await this.cfg.rpc.getTransaction(sig, {
5151
maxSupportedTransactionVersion: 0,
5252
}).send();
53-
if (!txDetail?.meta) return false;
53+
if (!txDetail?.meta) {
54+
log.warn({ sig }, 'verifyDeposit: no meta');
55+
return false;
56+
}
5457
const { preBalances, postBalances } = txDetail.meta;
5558
const accountKeys = txDetail.transaction.message.staticAccountKeys;
56-
const treasuryIdx = accountKeys.findIndex(k => k === this.cfg.treasuryAddress);
57-
if (treasuryIdx === -1) return false;
59+
const treasuryIdx = accountKeys.findIndex(k => String(k) === String(this.cfg.treasuryAddress));
60+
if (treasuryIdx === -1) {
61+
log.warn({ sig, accountKeys: accountKeys.map(String), treasury: this.cfg.treasuryAddress }, 'verifyDeposit: treasury not in accountKeys');
62+
return false;
63+
}
5864
const received = (postBalances[treasuryIdx] - preBalances[treasuryIdx]) / 1_000_000_000;
59-
return received >= expectedSol * 0.999;
60-
} catch {
65+
const ok = received >= expectedSol * 0.999;
66+
if (!ok) {
67+
log.warn({ sig, received, expectedSol, threshold: expectedSol * 0.999 }, 'verifyDeposit: amount below threshold');
68+
}
69+
return ok;
70+
} catch (err) {
71+
log.warn({ sig, err }, 'verifyDeposit: exception');
6172
return false;
6273
}
6374
}
@@ -107,12 +118,12 @@ export class DepositDetector {
107118
if (!txDetail?.meta) return;
108119

109120
const accountKeys = txDetail.transaction.message.staticAccountKeys;
110-
const treasuryIdx = accountKeys.findIndex(k => k === this.cfg.treasuryAddress);
121+
const treasuryIdx = accountKeys.findIndex(k => String(k) === String(this.cfg.treasuryAddress));
111122
if (treasuryIdx === -1) return;
112123

113124
const received = (txDetail.meta.postBalances[treasuryIdx] - txDetail.meta.preBalances[treasuryIdx]) / 1_000_000_000;
114125
// Sender is the first account (fee payer)
115-
const sender = accountKeys[0];
126+
const sender = String(accountKeys[0]);
116127

117128
const matching = pendingSells.find(
118129
(tx) => tx.wallet === sender && received >= tx.sol_amount * 0.999,

0 commit comments

Comments
 (0)