Last active
January 10, 2024 14:34
-
-
Save akerbabber/ff1c523606c85227ae4e53fe3ecb6dc1 to your computer and use it in GitHub Desktop.
Gelato test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(uint8 v, bytes32 r, bytes32 s) = _signERC2771(privateKey, address(contractAddress), data); | |
(bool success, bytes memory nonceBytes) = | |
TRUSTED_FORWARDER.call(abi.encodeWithSignature("userNonce(address)", signer)); | |
//convert nonce to uint | |
uint256 nonce = abi.decode(nonceBytes, (uint256)); | |
require(success, "userNonce failed"); | |
vm.startPrank(relay); | |
(bool success2, bytes memory result) = (0xd8253782c45a12053594b9deB72d8e8aB2Fca54c).call( | |
abi.encodeWithSignature( | |
"sponsoredCallERC2771(CallWithERC2771 calldata _call, address _sponsor, address _feeToken, uint256 _oneBalanceChainId, bytes calldata _userSignature, uint256 _nativeToFeeTokenXRateNumerator, uint256 _nativeToFeeTokenXRateDenominator, bytes32 _correlationId) external", | |
SigUtilsERC2771.CallWithERC2771({ | |
chainId: block.chainid, | |
target: address(contractAddress), | |
data: data, | |
user: signer, | |
userNonce: nonce, | |
userDeadline: block.timestamp + 1 days | |
}), | |
GELATO_SPONSOR, | |
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE, | |
5, | |
abi.encodePacked(v, r, s), | |
6211, | |
10000000, | |
0xCFB8E662173E8437D377FED34B4987B7F9474825624818D9200BCAF01DA2E531 | |
) | |
); | |
function _signERC2771(uint256 signerPrivateKey, address target, bytes memory data) | |
internal | |
view | |
returns (uint8 v, bytes32 r, bytes32 s) | |
{ | |
address signer = vm.addr(signerPrivateKey); | |
(bool success, bytes memory nonceBytes) = | |
TRUSTED_FORWARDER.call(abi.encodeWithSignature("userNonce(address)", signer)); | |
//convert nonce to uint | |
uint256 nonce = abi.decode(nonceBytes, (uint256)); | |
require(success, "userNonce failed"); | |
SigUtilsERC2771.CallWithERC2771 memory callWithERC2771 = SigUtilsERC2771.CallWithERC2771({ | |
chainId: block.chainid, | |
target: target, | |
data: data, | |
user: signer, | |
userNonce: nonce, | |
userDeadline: block.timestamp + 1 days | |
}); | |
bytes32 digest = sigUtilsERC2771.getTypedDataHash(callWithERC2771); | |
(v, r, s) = vm.sign(signerPrivateKey, digest); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment