TransferHelper
Handles token and native transfers with automatic dev fee calculation and optional timing randomization.
Import
import { TransferHelper } from '@knight-shield/core';
Constructor
const helper = new TransferHelper(wallet, tokenRegistry);
wallet—KnightShieldWalletinstancetokenRegistry—TokenRegistryinstance (for token transfers)
Dev Fee
All transfers include a 0.15% dev fee (15 basis points). This fee is calculated automatically and deducted from the transfer amount.
const fee = helper.calculateDevFee(1_000_000n);
// fee = 1_500n (0.15% of 1,000,000)
Methods
sendNative(to, amount): Promise<TxResult>
Sends native tokens (tDUST) to a recipient. Dev fee is deducted automatically.
const result = await helper.sendNative(recipientAddress, 1_000_000n);
// Sends 998,500 to recipient + 1,500 dev fee
sendToken(symbol, to, amount): Promise<TxResult>
Sends a registered token to a recipient.
const result = await helper.sendToken('CLOAK', recipientAddress, 500n);
calculateDevFee(amount): bigint
Calculates the dev fee for a given amount.
const fee = helper.calculateDevFee(10_000n);
// fee = 15n
Timing Randomizer
The TransferHelper includes an optional timing randomizer for basic GhostTracking protection:
enableTimingRandomizer(minMs, maxMs): void
Enables random delay before each transfer.
helper.enableTimingRandomizer(500, 8000);
// All subsequent transfers wait 0.5–8 seconds before executing
disableTimingRandomizer(): void
Disables the timing randomizer.
helper.disableTimingRandomizer();
applyTimingDelay(): Promise<number>
Manually applies a timing delay. Returns the actual delay in milliseconds.
const ms = await helper.applyTimingDelay();
console.log(`Waited ${ms}ms`);
Transaction Flow
sendNative(to, amount)
│
├── calculateDevFee(amount) → fee = amount * 15 / 10000
├── applyTimingDelay() → random wait (if enabled)
├── WalletFacade.balance() → prepare transaction
└── WalletFacade.submit() → broadcast to network