Add Solidity linting with solhint, Foundry formatter, and pre-commit hooks (#51)
## Changes ### Configuration - Added .solhint.json with recommended rules + custom config - 160 char line length (warn) - Double quotes enforcement (error) - Explicit visibility required (error) - Console statements allowed (scripts/tests need them) - Gas optimization warnings enabled - Ignores test/helpers/, lib/, out/, cache/, broadcast/ - Added foundry.toml [fmt] section - 160 char line length - 4-space tabs - Double quotes - Thousands separators for numbers - Sort imports enabled - Added .lintstagedrc.json for pre-commit auto-fix - Runs solhint --fix on .sol files - Runs forge fmt on .sol files - Added husky pre-commit hook via lint-staged ### NPM Scripts - lint:sol - run solhint - lint:sol:fix - auto-fix solhint issues - format:sol - format with forge fmt - format:sol:check - check formatting - lint / lint:fix - combined commands ### Code Changes - Added explicit visibility modifiers (internal) to constants in scripts and tests - Fixed quote style in DeployLocal.sol - All Solidity files formatted with forge fmt ## Verification - ✅ forge fmt --check passes - ✅ No solhint errors (warnings only) - ✅ forge build succeeds - ✅ forge test passes (107/107) resolves #44 Co-authored-by: johba <johba@harb.eth> Reviewed-on: https://codeberg.org/johba/harb/pulls/51
This commit is contained in:
parent
f8927b426e
commit
d7c2184ccf
45 changed files with 2853 additions and 1225 deletions
|
|
@ -7,7 +7,7 @@ import "@openzeppelin/utils/math/Math.sol";
|
|||
* @title VWAPTracker
|
||||
* @notice Abstract contract for tracking Volume Weighted Average Price (VWAP) data
|
||||
* @dev Provides VWAP calculation and storage functionality that can be inherited by other contracts
|
||||
*
|
||||
*
|
||||
* Key features:
|
||||
* - Volume-weighted average with data compression (max 1000x compression)
|
||||
* - Prevents dormant whale manipulation through historical price memory
|
||||
|
|
@ -31,7 +31,7 @@ abstract contract VWAPTracker {
|
|||
// assuming FEE is 1%
|
||||
uint256 volume = fee * 100;
|
||||
uint256 volumeWeightedPriceX96 = currentPriceX96 * volume;
|
||||
|
||||
|
||||
// ULTRA-RARE EDGE CASE: Check if the new data itself would overflow even before adding
|
||||
// This can only happen with impossibly large transactions (>10,000 ETH + $billion token prices)
|
||||
if (volumeWeightedPriceX96 > type(uint256).max / 2) {
|
||||
|
|
@ -46,18 +46,18 @@ abstract contract VWAPTracker {
|
|||
// Find the MINIMUM compression factor needed to prevent overflow
|
||||
uint256 maxSafeValue = type(uint256).max / 10 ** 6; // Leave substantial room for future data
|
||||
uint256 compressionFactor = (cumulativeVolumeWeightedPriceX96 / maxSafeValue) + 1;
|
||||
|
||||
|
||||
// Cap maximum compression to preserve historical "eternal memory"
|
||||
// Even in extreme cases, historical data should retain significant weight
|
||||
if (compressionFactor > 1000) {
|
||||
compressionFactor = 1000; // Maximum 1000x compression to preserve history
|
||||
}
|
||||
|
||||
|
||||
// Ensure minimum compression effectiveness
|
||||
if (compressionFactor < 2) {
|
||||
compressionFactor = 2; // At least 2x compression when triggered
|
||||
}
|
||||
|
||||
|
||||
// Compress both values by the same minimal factor
|
||||
cumulativeVolumeWeightedPriceX96 = cumulativeVolumeWeightedPriceX96 / compressionFactor;
|
||||
cumulativeVolume = cumulativeVolume / compressionFactor;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue