Shared helper
src/test/tokenhelper.sol
Small library the base contract uses to read token balance, decimals and symbol, and to call approve and transfer. Generic ERC-20 plumbing with no target-specific logic.
Code
Shown in full with its original header, as part of the open dataset (repository licence Apache-2.0, see NOTICE). This file's own SPDX header reads UNLICENSED. It declares interfaces and helpers only. ThreatWire has not executed this code. It is shown for defensive research, as published in the public reference dataset. Check licences, verify the blob against the pinned commit, and do not run it against live contracts without your own review.
1// SPDX-License-Identifier: UNLICENSED3pragma solidity ^0.8.0;5library TokenHelper {6 function callTokenFunction(7 address tokenAddress,8 bytes memory data,9 bool staticCall10 ) private returns (bytes memory) {11 (bool success, bytes memory result) = staticCall ? tokenAddress.staticcall(data) : tokenAddress.call(data);12 require(success, "Failed to call token function");13 return result;14 }16 function getTokenBalance(address tokenAddress, address targetAddress) internal returns (uint256) {17 bytes memory result =18 callTokenFunction(tokenAddress, abi.encodeWithSignature("balanceOf(address)", targetAddress), true);19 return abi.decode(result, (uint256));20 }22 function getTokenDecimals(23 address tokenAddress24 ) internal returns (uint8) {25 bytes memory result = callTokenFunction(tokenAddress, abi.encodeWithSignature("decimals()"), true);26 return abi.decode(result, (uint8));27 }29 function getTokenSymbol(30 address tokenAddress31 ) internal returns (string memory) {32 bytes memory result = callTokenFunction(tokenAddress, abi.encodeWithSignature("symbol()"), true);33 return abi.decode(result, (string));34 }36 function approveToken(address token, address spender, uint256 spendAmount) internal returns (bool) {37 bytes memory result =38 callTokenFunction(token, abi.encodeWithSignature("approve(address,uint256)", spender, spendAmount), false);39 return abi.decode(result, (bool));40 }42 function transferToken(address token, address receiver, uint256 amount) internal returns (bool) {43 bytes memory result =44 callTokenFunction(token, abi.encodeWithSignature("transfer(address,uint256)", receiver, amount), false);45 return abi.decode(result, (bool));46 }47}Components and what they do
- TokenHelper.getTokenBalance, getTokenDecimals, getTokenSymbol
- TokenHelper.approveToken, transferToken
Related files
1 linkedImports used by this file, other reproduction files from the same month or protocol in the dataset, and patterns for the same incident. Each opens in our reader with verbatim source.
- src/test/basetest.solImports this file · 142 lines
File record
- Name
- tokenhelper.sol
- Path
- src/test/tokenhelper.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- 743f98a4697b48d7a09fb3f937f9d512233d6f2d
- Language
- Solidity
- Size
- 47 lines
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/tokenhelper.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 743f98a4697b48d7a09fb3f937f9d512233d6f2d, retrieved 2026-10-19. Verbatim copy of the file including its SPDX header, read with git show. No edits. ThreatWire has never executed this file. Reference: source file at the pinned commit.