diff --git a/.gitmodules b/.gitmodules index c54835d..5e007a6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,6 +7,3 @@ [submodule "lib/v4-core"] path = lib/v4-core url = https://github.com/Uniswap/v4-core -[submodule "lib/solmate"] - path = lib/solmate - url = https://github.com/Transmissions11/solmate diff --git a/lib/solmate b/lib/solmate deleted file mode 160000 index 97bdb20..0000000 --- a/lib/solmate +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 97bdb2003b70382996a79a406813f76417b1cf90 diff --git a/src/Governance.sol b/src/Governance.sol index 5edac1b..0e5a4af 100644 --- a/src/Governance.sol +++ b/src/Governance.sol @@ -17,8 +17,6 @@ import {Multicall} from "./utils/Multicall.sol"; import {WAD, PermitParams} from "./utils/Types.sol"; import {safeCallWithMinGas} from "./utils/SafeCallMinGas.sol"; -import {SafeCastLib} from "lib/solmate/src/utils/SafeCastLib.sol"; - /// @title Governance: Modular Initiative based Governance contract Governance is Multicall, UserProxyFactory, ReentrancyGuard, IGovernance { using SafeERC20 for IERC20; diff --git a/test/EncodingDecoding.t.sol b/test/EncodingDecoding.t.sol new file mode 100644 index 0000000..4598c1f --- /dev/null +++ b/test/EncodingDecoding.t.sol @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.24; + +import {Test, console2} from "forge-std/Test.sol"; + +library EncodingDecoding { + function encodeLQTYAllocation(uint88 _lqty, uint32 _averageTimestamp) public pure returns (uint224) { + uint224 _value = (uint224(_lqty) << 32) | _averageTimestamp; + return _value; + } + + function decodeLQTYAllocation(uint224 _value) public pure returns (uint88, uint32) { + return (uint88(_value >> 32), uint32(_value)); + } +} + +contract EncodingDecodingTest is Test { + // value -> encoding -> decoding -> value + function test_encoding_and_decoding_symmetrical(uint88 lqty, uint32 averageTimestamp) public { + uint224 encodedValue = EncodingDecoding.encodeLQTYAllocation(lqty, averageTimestamp); + (uint88 decodedLqty, uint32 decodedAverageTimestamp) = EncodingDecoding.decodeLQTYAllocation(encodedValue); + + assertEq(lqty, decodedLqty); + assertEq(averageTimestamp, decodedAverageTimestamp); + + // Redo + uint224 reEncoded = EncodingDecoding.encodeLQTYAllocation(decodedLqty, decodedAverageTimestamp); + (uint88 reDecodedLqty, uint32 reDecodedAverageTimestamp) = EncodingDecoding.decodeLQTYAllocation(encodedValue); + + assertEq(reEncoded, encodedValue); + assertEq(reDecodedLqty, decodedLqty); + assertEq(reDecodedAverageTimestamp, decodedAverageTimestamp); + } + + + /// We expect this test to fail as the encoding is ambigous past u120 + function testFail_encoding_not_equal_reproducer() public { + _receive_undo_compare(18371677541005923091065047412368542483005086202); + } + + // receive -> undo -> check -> redo -> compare + function test_receive_undo_compare(uint120 encodedValue) public { + _receive_undo_compare(encodedValue); + } + + // receive -> undo -> check -> redo -> compare + function _receive_undo_compare(uint224 encodedValue) public { + /// These values fail because we could pass a value that is bigger than intended + (uint88 decodedLqty, uint32 decodedAverageTimestamp) = EncodingDecoding.decodeLQTYAllocation(encodedValue); + + uint224 encodedValue2 = EncodingDecoding.encodeLQTYAllocation(decodedLqty, decodedAverageTimestamp); + (uint88 decodedLqty2, uint32 decodedAverageTimestamp2) = EncodingDecoding.decodeLQTYAllocation(encodedValue2); + + assertEq(encodedValue, encodedValue2, "encoded values not equal"); + assertEq(decodedLqty, decodedLqty2, "decoded lqty not equal"); + assertEq(decodedAverageTimestamp, decodedAverageTimestamp2, "decoded timestamps not equal"); + } + + +} \ No newline at end of file