Skip to content

Commit 2e75278

Browse files
committed
fix: strip Solana RPC memo prefix [N] before matching deposits
Solana getSignaturesForAddress returns memo as "[byteLen] actualMemo" (e.g. "[15] devsol-abc123"). Strip the prefix with regex before comparing against DB memos. Discovered during live e2e testing.
1 parent 828ff2a commit 2e75278

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

src/services/deposit.test.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ describe('DepositDetector', () => {
114114
const mockRpcWithDeposit = {
115115
getSignaturesForAddress: vi.fn(() => ({
116116
send: vi.fn(async () => [
117-
{ memo: 'devsol-match1', signature: 'deposit_sig_1' },
118-
{ memo: 'unrelated-memo', signature: 'other_sig' },
117+
{ memo: '[15] devsol-match1', signature: 'deposit_sig_1' },
118+
{ memo: '[16] unrelated-memo', signature: 'other_sig' },
119119
]),
120120
})),
121121
};
@@ -185,6 +185,35 @@ describe('DepositDetector', () => {
185185
expect(onDeposit).not.toHaveBeenCalled();
186186
});
187187

188+
it('strips Solana RPC memo prefix [N] before matching', async () => {
189+
const onDeposit = vi.fn();
190+
const tx = db.create({
191+
type: 'sell',
192+
wallet: 'seller1',
193+
sol_amount: 5,
194+
usdc_amount: 4.75,
195+
memo: 'devsol-prefix1',
196+
});
197+
198+
const mockRpcPrefix = {
199+
getSignaturesForAddress: vi.fn(() => ({
200+
send: vi.fn(async () => [
201+
{ memo: '[15] devsol-prefix1', signature: 'prefix_sig' },
202+
]),
203+
})),
204+
};
205+
206+
const detector = new DepositDetector({
207+
db, rpc: mockRpcPrefix as any, treasuryAddress: 'T', onDeposit,
208+
});
209+
210+
await detector.poll();
211+
expect(onDeposit).toHaveBeenCalledWith(
212+
expect.objectContaining({ id: tx.id }),
213+
'prefix_sig',
214+
);
215+
});
216+
188217
it('does not match on memo substring', async () => {
189218
const onDeposit = vi.fn();
190219
db.create({ type: 'sell', wallet: 'seller1', sol_amount: 5, usdc_amount: 4.75, memo: 'devsol-abc' });

src/services/deposit.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ export class DepositDetector {
4747

4848
for (const sig of sigs) {
4949
if (sig.memo && sig.memo.trim()) {
50-
const trimmedMemo = sig.memo.trim();
51-
const matching = pendingSells.find((tx) => tx.memo && trimmedMemo === tx.memo);
50+
// Solana RPC returns memo as "[byteLen] actualMemo" — strip prefix
51+
const rawMemo = sig.memo.trim();
52+
const cleanMemo = rawMemo.replace(/^\[\d+\]\s*/, '');
53+
if (!cleanMemo) continue;
54+
const matching = pendingSells.find((tx) => tx.memo && cleanMemo === tx.memo);
5255
if (matching) {
5356
await this.processDeposit(matching.id, sig.signature);
5457
}

0 commit comments

Comments
 (0)