Skip to content

Commit

Permalink
test morpho approve2
Browse files Browse the repository at this point in the history
  • Loading branch information
sanbir committed Dec 10, 2024
1 parent ae51395 commit 5a7b5c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/p2pLendingProxyFactory/P2pLendingProxyFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ contract P2pLendingProxyFactory is P2pLendingProxyFactoryStructs, ERC165, IP2pLe
));
}

/// @notice Creates an EIP-712 typed data hash for Permit2
function getPermit2HashTypedData(bytes32 _dataHash) external view returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", Permit2Lib.PERMIT2.DOMAIN_SEPARATOR(), _dataHash));
}

/// @notice Calculates the salt required for deterministic clone creation
/// depending on client address and client basis points
/// @param _clientAddress address
Expand Down
6 changes: 3 additions & 3 deletions test/MainnetIntegration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ contract MainnetIntegration is Test {
IAllowanceTransfer.PermitDetails memory permitDetails = IAllowanceTransfer.PermitDetails({
token: USDT,
amount: 10000000,
expiration: 281474976710655,
expiration: type(uint48).max,
nonce: 0
});
IAllowanceTransfer.PermitSingle memory permitSingle = IAllowanceTransfer.PermitSingle({
details: permitDetails,
spender: MorphoEthereumBundlerV2,
sigDeadline: SigDeadline
});
bytes32 permitSingleHash = PermitHash.hash(permitSingle);
bytes32 permitSingleHash = factory.getPermit2HashTypedData(PermitHash.hash(permitSingle));
(uint8 v0, bytes32 r0, bytes32 s0) = vm.sign(clientPrivateKey, permitSingleHash);
bytes memory signatureForApprove2 = abi.encodePacked(r0, s0, v0);
bytes memory approve2CallData = abi.encodeCall(IMorphoEthereumBundlerV2.approve2, (
Expand All @@ -104,7 +104,7 @@ contract MainnetIntegration is Test {
spender: proxyAddress,
sigDeadline: SigDeadline
});
bytes32 permitSingleForP2pLendingProxyHash = PermitHash.hash(permitSingleForP2pLendingProxy);
bytes32 permitSingleForP2pLendingProxyHash = factory.getPermit2HashTypedData(PermitHash.hash(permitSingleForP2pLendingProxy));
(uint8 v1, bytes32 r1, bytes32 s1) = vm.sign(clientPrivateKey, permitSingleForP2pLendingProxyHash);
bytes memory permit2SignatureForP2pLendingProxy = abi.encodePacked(r1, s1, v1);

Expand Down

0 comments on commit 5a7b5c1

Please sign in to comment.