From 4067352718652ddff4726d8deaa3410860255f04 Mon Sep 17 00:00:00 2001 From: alex0207s Date: Tue, 27 Feb 2024 13:18:32 +0800 Subject: [PATCH] add a sign function for conditional order --- test/utils/SigHelper.sol | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/utils/SigHelper.sol b/test/utils/SigHelper.sol index d606f6e5..5fba1d1d 100644 --- a/test/utils/SigHelper.sol +++ b/test/utils/SigHelper.sol @@ -4,6 +4,7 @@ pragma solidity 0.8.17; import { AllowFill, getAllowFillHash } from "contracts/libraries/AllowFill.sol"; import { GenericSwapData, getGSDataHash } from "contracts/libraries/GenericSwapData.sol"; import { LimitOrder, getLimitOrderHash } from "contracts/libraries/LimitOrder.sol"; +import { ConOrder, getConOrderHash } from "contracts/libraries/ConditionalOrder.sol"; import { RFQOffer, getRFQOfferHash } from "contracts/libraries/RFQOffer.sol"; import { RFQTx, getRFQTxHash } from "contracts/libraries/RFQTx.sol"; import { Test } from "forge-std/Test.sol"; @@ -159,4 +160,25 @@ contract SigHelper is Test { (uint8 v, bytes32 r, bytes32 s) = vm.sign(_privateKey, EIP712SignDigest); return abi.encodePacked(r, s, v); } + + function signConOrder(uint256 _privateKey, ConOrder memory _order, bytes32 domainSeperator) internal pure returns (bytes memory sig) { + bytes32 orderHash = getConOrderHash(_order); + bytes32 EIP712SignDigest = getEIP712Hash(domainSeperator, orderHash); + (uint8 v, bytes32 r, bytes32 s) = vm.sign(_privateKey, EIP712SignDigest); + return abi.encodePacked(r, s, v); + } + + function signConOrder(uint256 _privateKey, ConOrder memory _order, address verifyingContract) internal view returns (bytes memory sig) { + bytes32 orderHash = getConOrderHash(_order); + bytes32 EIP712SignDigest = getEIP712Hash(computeEIP712DomainSeparator(block.chainid, verifyingContract), orderHash); + (uint8 v, bytes32 r, bytes32 s) = vm.sign(_privateKey, EIP712SignDigest); + return abi.encodePacked(r, s, v); + } + + function signConOrder(uint256 _privateKey, ConOrder memory _order, uint256 chainId, address verifyingContract) internal pure returns (bytes memory sig) { + bytes32 orderHash = getConOrderHash(_order); + bytes32 EIP712SignDigest = getEIP712Hash(computeEIP712DomainSeparator(chainId, verifyingContract), orderHash); + (uint8 v, bytes32 r, bytes32 s) = vm.sign(_privateKey, EIP712SignDigest); + return abi.encodePacked(r, s, v); + } }