This repository contains a small set of reusable Solidity utilities and patterns used in the Sun Protocol ecosystem, with a focus on TRON / TRC‑20 token handling and secure vault operations. It is set up as a dual Hardhat + Foundry project so you can both develop and test contracts conveniently.
-
SafeTransferLib: Helper library for interacting with TRC‑20 / ERC‑20 tokens that may not strictly follow the standard and might not return a boolean value.- Wraps
approve,transfer, andtransferFromwith safe low‑level calls. - Contains special handling for TRON USDT contracts on:
- Nile testnet (
NILE_CHAIN_ID,USDTNileAddr) - Mainnet (
MAIN_CHAIN_ID,USDTMainAddr)
- Nile testnet (
- Provides a
safeTransferETHfunction for safely sending native TRX/ETH‑style value.
- Wraps
-
SSPSafeVault: A simple owner‑controlled vault contract.- Holds a single
assetToken(IERC20) and uses OpenZeppelinSafeERC20. - Supports a configurable set of
mintersthat can request token transfers from the vault to recipients. - Allows the owner to recover:
- Native TRX via
recoverTRX. - Any TRC‑20 / ERC‑20 token via
recoverTRC20.
- Native TRX via
- Holds a single
-
Extensive Tests:
- Foundry tests in
test/cover:- Standard ERC‑20 behavior.
- Tokens that do not return a value.
- Tokens that revert or return
false. - Special cases for TRON USDT on Nile and Mainnet.
- Foundry tests in
contracts/libraries/SafeTransferLib.sol– Safe token transfer helpers with TRON USDT special cases.utils/SSPSafeVault.sol– Owner‑controlled vault using OpenZeppelinOwnableandSafeERC20.
test/SafeTransferLib.t.sol– Foundry tests forSafeTransferLib.TokenSender.sol– Simple helper contract used by tests to exercise the library.mocks/– Mock ERC‑20 implementations simulating different token behaviors.
foundry.toml– Foundry configuration pointing tocontracts/andtest/.hardhat.config.ts– Hardhat configuration (via@sun-protocol/sunhat) with support for TRON networks (tron,nile,shasta) and a local Ethereum‑style network (localhost).deploy/anddeployTron/– Example deployment scripts for Hardhat.
- Node.js (v18+ recommended)
- npm or yarn
- Foundry (for
forgecommands) – see the Foundry book for installation instructions.
git clone <this-repo-url>
cd sun-contract-std
npm installThis will install all Node dependencies, including Hardhat, @sun-protocol/sunhat, and OpenZeppelin contracts.
Install this package (or copy the contracts into your own project, depending on how you consume it), then:
pragma solidity >=0.4.22 <0.9.0;
import "./contracts/libraries/SafeTransferLib.sol";
contract TokenSender {
using SafeTransferLib for address;
function send(address token, address to, uint256 amount) external returns (bool) {
return token.safeTransfer(to, amount);
}
}For the vault:
pragma solidity >=0.6.0 <0.9.0;
import "./contracts/utils/SSPSafeVault.sol";
contract MyVault is SSPSafeVault {
constructor(address asset) SSPSafeVault(asset) {}
}Adjust import paths to match how you integrate this repository (e.g. via node_modules or direct relative paths).
- Compile with Hardhat
npm run compile- Run Hardhat tests
npm test- Run Foundry tests
npm run test-foundryMake sure you have Foundry installed and forge available in your PATH.
Hardhat is configured via hardhat.config.ts to support:
- localhost – Local Hardhat network (for development and testing).
- tron – TRON mainnet.
- nile – TRON Nile testnet.
- shasta – TRON Shasta testnet.
You can use the provided scripts as a starting point:
- Deploy to localhost
npm run deploy- Deploy to TRON networks
npm run deploy-tron # mainnet
npm run deploy-nile # Nile testnet
npm run deploy-shasta # Shasta testnetSet the PRIVATE_KEY environment variable in a .env file or your shell before deploying to live networks.
These contracts are provided as‑is and without any warranty. They are intended as reusable primitives but may not have undergone a full professional audit. Use at your own risk, and always perform your own security review and testing before deploying to mainnet.
This project is licensed under the MIT License. See the SPDX identifiers in the Solidity files for more details.