Skip to content

Commit

Permalink
forge fmt contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
mouseless-eth committed Jul 16, 2023
1 parent 8433709 commit ec86920
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
19 changes: 8 additions & 11 deletions contract/test/misc/SandoCommon.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "./GeneralHelper.sol";
/// @dev Encoding schema: fits any uint256 (32 byte value) into 5 bytes. 4 bytes reserved for a value, 1 byte reserved for storage slot to store the 4 byte value in.
library FiveBytesEncodingUtils {
struct EncodingMetaData {
/// @notice AmountIn squashed down to four bytes
/// @notice TargetValue squashed down to four bytes
uint32 fourBytes;
/// @notice How many byte shifts to apply on our four bytes
uint8 byteShift;
Expand All @@ -22,11 +22,7 @@ library FiveBytesEncodingUtils {
* @param amount The amount to be encoded
* @return encodingParams Parameters used for encoding the given input
*/
function encode(uint256 amount)
public
pure
returns (EncodingMetaData memory encodingParams)
{
function encode(uint256 amount) public pure returns (EncodingMetaData memory encodingParams) {
uint8 byteShift = 0; // how many byte shifts are needed to store value into four bytes?
uint32 fourByteValue = 0;

Expand All @@ -42,10 +38,7 @@ library FiveBytesEncodingUtils {
byteShift++;
}

encodingParams = EncodingMetaData({
fourBytes: fourByteValue,
byteShift: byteShift
});
encodingParams = EncodingMetaData({fourBytes: fourByteValue, byteShift: byteShift});
}

/**
Expand All @@ -65,7 +58,11 @@ library FiveBytesEncodingUtils {
* @param paramIndex Which param index should we encode to
* @return fiveBytes The final five bytes used in calldata
*/
function finalzeForParamIndex(EncodingMetaData calldata encodingParams, uint8 paramIndex) public pure returns (uint40 fiveBytes) {
function finalzeForParamIndex(EncodingMetaData calldata encodingParams, uint8 paramIndex)
public
pure
returns (uint40 fiveBytes)
{
// 4 for function selector
uint8 memLocation = 4 + 32 + (paramIndex * 32) - 4 - encodingParams.byteShift;

Expand Down
5 changes: 2 additions & 3 deletions contract/test/misc/V2SandoUtility.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ library V2SandoUtility {
uint256 amountInActual = WethEncodingUtils.decode(WethEncodingUtils.encode(amountIn));

// Get amounts out and encode it
FiveBytesEncodingUtils.EncodingMetaData memory fiveByteParams = FiveBytesEncodingUtils.encode(
GeneralHelper.getAmountOut(weth, outputToken, amountInActual)
);
FiveBytesEncodingUtils.EncodingMetaData memory fiveByteParams =
FiveBytesEncodingUtils.encode(GeneralHelper.getAmountOut(weth, outputToken, amountInActual));

string memory functionSignature = weth < outputToken ? "v2_frontrun0" : "v2_frontrun1";
uint8 jumpDest = SandoCommon.getJumpDestFromSig(functionSignature);
Expand Down
9 changes: 7 additions & 2 deletions contract/test/misc/V3SandoUtility.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ library V3SandoUtility {

FiveBytesEncodingUtils.EncodingMetaData memory fiveByteParams = FiveBytesEncodingUtils.encode(uint256(amountIn));

payload =
abi.encodePacked(jumpDest, address(pool), address(inputToken), poolKeyHash, FiveBytesEncodingUtils.finalzeForParamIndex(fiveByteParams, 2));
payload = abi.encodePacked(
jumpDest,
address(pool),
address(inputToken),
poolKeyHash,
FiveBytesEncodingUtils.finalzeForParamIndex(fiveByteParams, 2)
);
}
}

0 comments on commit ec86920

Please sign in to comment.