// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.19; /** * @title FormatLib * @notice Shared integer-to-string formatting helpers for backtesting log output. * Extracted to avoid copy-pasting the same logic across PositionTracker * and StrategyExecutor. */ library FormatLib { /// @notice Format an unsigned integer as a decimal string. function str(uint256 v) internal pure returns (string memory) { if (v == 0) return "0"; uint256 tmp = v; uint256 len; while (tmp != 0) { len++; tmp /= 10; } bytes memory buf = new bytes(len); while (v != 0) { buf[--len] = bytes1(uint8(48 + v % 10)); v /= 10; } return string(buf); } /// @notice Format a signed integer as a decimal string (prefixed with '-' if negative). function istr(int256 v) internal pure returns (string memory) { if (v >= 0) return str(uint256(v)); return string.concat("-", str(uint256(-v))); } }