From a318761418b6f72da51b6de345775059865a4f1b Mon Sep 17 00:00:00 2001 From: Agustin Velez Date: Wed, 9 Oct 2024 18:04:10 -0300 Subject: [PATCH] add memory versions --- .../{Permit2Parsing.sol => PermitParsing.sol} | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) rename src/libraries/{Permit2Parsing.sol => PermitParsing.sol} (53%) diff --git a/src/libraries/Permit2Parsing.sol b/src/libraries/PermitParsing.sol similarity index 53% rename from src/libraries/Permit2Parsing.sol rename to src/libraries/PermitParsing.sol index 4a5d3a6..333b0cf 100644 --- a/src/libraries/Permit2Parsing.sol +++ b/src/libraries/PermitParsing.sol @@ -9,6 +9,23 @@ library PermitParsing { uint constant SIGNATURE_SIZE = 65; + function asPermitUnchecked( + bytes memory params, + uint offset + ) internal pure returns (uint256, uint256, bytes32, bytes32, uint8, uint) { + uint256 value; + uint256 deadline; + bytes32 r; + bytes32 s; + uint8 v; + (value, offset) = params.asUint256Unchecked(offset); + (deadline, offset) = params.asUint256Unchecked(offset); + (r, offset) = params.asBytes32Unchecked(offset); + (s, offset) = params.asBytes32Unchecked(offset); + (v, offset) = params.asUint8Unchecked(offset); + return (value, deadline, r, s, v, offset); + } + function asPermitCdUnchecked( bytes calldata params, uint offset @@ -26,6 +43,23 @@ library PermitParsing { return (value, deadline, r, s, v, offset); } + function asPermit2PermitUnchecked( + bytes memory params, + uint offset + ) internal pure returns (uint160, uint48, uint48, uint256, bytes memory, uint) { + uint160 amount; + uint48 expiration; + uint48 nonce; + uint256 sigDeadline; + bytes memory signature; + (amount, offset) = params.asUint160Unchecked(offset); + (expiration, offset) = params.asUint48Unchecked(offset); + (nonce, offset) = params.asUint48Unchecked(offset); + (sigDeadline, offset) = params.asUint256Unchecked(offset); + (signature, offset) = params.sliceUnchecked(offset, SIGNATURE_SIZE); + return (amount, expiration, nonce, sigDeadline, signature, offset); + } + function asPermit2PermitCdUnchecked( bytes calldata params, uint offset @@ -43,6 +77,21 @@ library PermitParsing { return (amount, expiration, nonce, sigDeadline, signature, offset); } + function asPermit2TransferUnchecked( + bytes memory params, + uint offset + ) internal pure returns (uint256, uint256, uint256, bytes memory, uint) { + uint256 amount; + uint256 nonce; + uint256 sigDeadline; + bytes memory signature; + (amount, offset) = params.asUint256Unchecked(offset); + (nonce, offset) = params.asUint256Unchecked(offset); + (sigDeadline, offset) = params.asUint256Unchecked(offset); + (signature, offset) = params.sliceUnchecked(offset, SIGNATURE_SIZE); + return (amount, nonce, sigDeadline, signature, offset); + } + function asPermit2TransferCdUnchecked( bytes calldata params, uint offset