harb/onchain/test/helpers/CSVHelper.sol

63 lines
2.6 KiB
Solidity
Raw Normal View History

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import "forge-std/Test.sol";
import "forge-std/Vm.sol";
/**
* @title CSVHelper
* @dev Library for managing CSV data in Solidity, including converting values to strings and writing CSV data.
*/
library CSVHelper {
/**
* @notice Creates a standard CSV header for liquidity position data.
* @return The CSV header as a string.
*/
function createPositionsHeader() internal pure returns (string memory) {
2025-07-08 10:33:10 +02:00
return
2025-07-17 21:35:18 +02:00
"precedingAction, currentTick, floorTickLower, floorTickUpper, floorEth, floorHarb, anchorTickLower, anchorTickUpper, anchorEth, anchorHarb, discoveryTickLower, discoveryTickUpper, discoveryEth, discoveryHarb, token0isWeth";
}
function createTimeSeriesHeader() internal pure returns (string memory) {
return "time, price, harbTotalSupply, supplyChange, stakeOutstandingShares, avgTaxRate, sentiment, taxCollected";
}
/**
* @notice Appends new CSV data to the existing CSV string.
* @param csv The current CSV string.
* @param newRow The new row to append.
* @return The updated CSV string.
*/
function appendRow(string memory csv, string memory newRow) internal pure returns (string memory) {
return string(abi.encodePacked(csv, "\n", newRow));
}
/**
* @notice Converts a `uint256` to a string using Forge's built-in vm.toString()
* @param vm The Forge VM instance
* @param _i The integer to convert.
* @return The string representation of the integer.
* @dev This function is a wrapper around vm.toString() for consistency with the library interface.
* In practice, use vm.toString() directly in test files.
*/
function uintToStr(Vm vm, uint256 _i) internal pure returns (string memory) {
// Note: This function is kept for API compatibility but should not be used in new code.
// Use vm.toString() directly instead.
return vm.toString(_i);
}
/**
* @notice Converts an `int256` to a string using Forge's built-in vm.toString()
* @param vm The Forge VM instance
* @param _i The integer to convert.
* @return The string representation of the integer.
* @dev This function is a wrapper around vm.toString() for consistency with the library interface.
* In practice, use vm.toString() directly in test files.
*/
function intToStr(Vm vm, int256 _i) internal pure returns (string memory) {
// Note: This function is kept for API compatibility but should not be used in new code.
// Use vm.toString() directly instead.
return vm.toString(_i);
}
}