feat: On-Chain-Scanner für Watchlist-Transfers (eth_getLogs, RPC-Fallback, Chunking)
This commit is contained in:
45
src/server/signals/onchain.test.ts
Normal file
45
src/server/signals/onchain.test.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
import { buildLogFilter, decodeTransferLogs, TRANSFER_TOPIC } from './onchain';
|
||||
|
||||
const WALLET = '0x5be9a4959308a0d0c7bc0870e319314d8d957dbb';
|
||||
|
||||
describe('buildLogFilter', () => {
|
||||
test('filtert auf Token-Whitelist + Transfer-Topic + Wallet als Empfänger', () => {
|
||||
const f = buildLogFilter(100, 200);
|
||||
expect(f.fromBlock).toBe('0x64');
|
||||
expect(f.toBlock).toBe('0xc8');
|
||||
expect(f.address).toContain('0x514910771af9ca656af840dff83e8264ecf986ca'); // LINK
|
||||
expect(f.topics[0]).toBe(TRANSFER_TOPIC);
|
||||
expect(f.topics[1]).toBeNull(); // from: beliebig
|
||||
expect(f.topics[2]).toContain('0x000000000000000000000000' + WALLET.slice(2));
|
||||
});
|
||||
});
|
||||
|
||||
describe('decodeTransferLogs', () => {
|
||||
test('dekodiert Token, Menge (decimals-skaliert), Tx-Hash, Block', () => {
|
||||
const log = {
|
||||
address: '0x514910771af9ca656af840dff83e8264ecf986ca', // LINK, 18 decimals
|
||||
topics: [
|
||||
TRANSFER_TOPIC,
|
||||
'0x000000000000000000000000aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
|
||||
'0x000000000000000000000000' + WALLET.slice(2),
|
||||
],
|
||||
data: '0x' + (5n * 10n ** 18n).toString(16).padStart(64, '0'), // 5 LINK
|
||||
transactionHash: '0xabc',
|
||||
blockNumber: '0x64',
|
||||
};
|
||||
const out = decodeTransferLogs([log]);
|
||||
expect(out).toHaveLength(1);
|
||||
expect(out[0]).toEqual({ symbol: 'LINK', instrument: 'LINK_USDT', amount: 5, txHash: '0xabc', blockNumber: 100 });
|
||||
});
|
||||
test('ignoriert Logs unbekannter Token-Contracts', () => {
|
||||
const log = {
|
||||
address: '0x000000000000000000000000000000000000dead',
|
||||
topics: [TRANSFER_TOPIC, '0x0', '0x0'],
|
||||
data: '0x1',
|
||||
transactionHash: '0xdef',
|
||||
blockNumber: '0x65',
|
||||
};
|
||||
expect(decodeTransferLogs([log])).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user