Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions scripts/monitor-deposits.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Template deposit monitor for HighloadWalletV3
* - Computes contract address from config
* - Polls the RPC (or subscribes) for transactions to that address
* - Detects incoming native TON transfers and calls a placeholder `onDeposit` handler
*
* Replace the placeholder code with your TonClient RPC calls and DB/business logic.
*/

import 'dotenv/config';
import { contractAddress } from '@ton/core';
import { HighloadWalletV3Code } from '../wrappers/compiled';
import { beginCell } from '@ton/core';


Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RPC_URL default 'https://net.ton.dev' may not be a valid or current TON RPC endpoint. This should be verified and updated to a known, working endpoint (such as from the TON documentation), or the script should require this environment variable to be set explicitly to avoid confusion.

Copilot uses AI. Check for mistakes.
const RPC_URL = process.env.RPC_URL || 'https://net.ton.dev';
const WORKCHAIN = Number(process.env.WORKCHAIN || 0);
const SUBWALLET_ID = Number(process.env.SUBWALLET_ID || 0x10ad);
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SUBWALLET_ID default value 0x10ad (4269) appears to be an arbitrary constant. For better clarity in a template script, consider adding a comment explaining what this value represents and whether users should customize it, or use a more conventional default like 0.

Suggested change
const SUBWALLET_ID = Number(process.env.SUBWALLET_ID || 0x10ad);
// Default subwallet id for this template; override via SUBWALLET_ID env var for your deployment.
const SUBWALLET_ID = Number(process.env.SUBWALLET_ID || 0);

Copilot uses AI. Check for mistakes.
const TIMEOUT = Number(process.env.TIMEOUT || 3600);

const code = beginCell().endCell();
const data = beginCell().endCell();
const init = { code, data };
const address = contractAddress(WORKCHAIN, init);

console.log('Monitoring deposits for address:', address.toString({ urlSafe: true, bounceable: true }));

async function onDeposit(tx: any) {
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected any. Specify a different type.

Suggested change
async function onDeposit(tx: any) {
async function onDeposit(tx: unknown) {

Copilot uses AI. Check for mistakes.
// TODO: implement mapping from tx -> user (memo, query_id, off-chain mapping)
console.log('Deposit detected:', tx);
// Example: credit internal DB, notify user, etc.
}

Comment on lines +28 to +33
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'onDeposit' is defined but never used.

Suggested change
async function onDeposit(tx: any) {
// TODO: implement mapping from tx -> user (memo, query_id, off-chain mapping)
console.log('Deposit detected:', tx);
// Example: credit internal DB, notify user, etc.
}

Copilot uses AI. Check for mistakes.
async function pollOnce() {
try {
// TODO: Replace with TonClient or provider calls to fetch transactions for `address`
// Example pseudocode:
// import { TonClient } from '@ton/ton';
// const client = new TonClient({ endpoint: RPC_URL });
// const txs = await client.getTransactions(address);
// for (const tx of txs) { if (tx.incoming && tx.value > 0) await onDeposit(tx); }

console.log('Polling (template) — implement RPC polling/subscription here.');
} catch (e) {
console.error('Polling error:', e);
}
}

setInterval(() => {
pollOnce().catch(console.error);
}, 15_000);
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The polling starts only after the first 15-second interval. Consider calling pollOnce() immediately after the setInterval to begin monitoring right away when the script starts, rather than waiting for the first interval to elapse.

Suggested change
}, 15_000);
}, 15_000);
// Perform an initial poll immediately so monitoring starts without waiting for the first interval.
pollOnce().catch(console.error);

Copilot uses AI. Check for mistakes.