Skip to content

Commit

Permalink
add a sign function for conditional order
Browse files Browse the repository at this point in the history
  • Loading branch information
alex0207s committed Feb 27, 2024
1 parent 68f223e commit 4067352
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/utils/SigHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 4067352

Please sign in to comment.