-
Notifications
You must be signed in to change notification settings - Fork 19
/
OrderVerifier.sol
62 lines (53 loc) · 2.65 KB
/
OrderVerifier.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.24;
import { EIP712 } from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
import { SignatureChecker } from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
import { VerifierBase } from "@equilibria/root/verifier/VerifierBase.sol";
import { IMarketFactory } from "@perennial/core/contracts/interfaces/IMarketFactory.sol";
import { IOrderVerifier } from "./interfaces/IOrderVerifier.sol";
import { Action, ActionLib } from "./types/Action.sol";
import { CancelOrderAction, CancelOrderActionLib } from "./types/CancelOrderAction.sol";
import { PlaceOrderAction, PlaceOrderActionLib } from "./types/PlaceOrderAction.sol";
contract OrderVerifier is VerifierBase, IOrderVerifier {
/// @dev market factory to check authorization
IMarketFactory internal immutable marketFactory;
/// @dev Initializes the domain separator and parameter caches
constructor(IMarketFactory _marketFactory) EIP712("Perennial V2 Trigger Orders", "1.0.0") {
marketFactory = _marketFactory;
}
/// @inheritdoc IOrderVerifier
function verifyAction(Action calldata action, bytes calldata signature)
external
validateAndCancel(action.common, signature)
{
_verifySignature(action, ActionLib.hash(action), signature);
}
/// @inheritdoc IOrderVerifier
function verifyPlaceOrder(PlaceOrderAction calldata action, bytes calldata signature)
external
validateAndCancel(action.action.common, signature)
{
_verifySignature(action.action, PlaceOrderActionLib.hash(action), signature);
}
/// @inheritdoc IOrderVerifier
function verifyCancelOrder(CancelOrderAction calldata action, bytes calldata signature)
external
validateAndCancel(action.action.common, signature)
{
_verifySignature(action.action, CancelOrderActionLib.hash(action), signature);
}
function _verifySignature(Action calldata action, bytes32 hash, bytes calldata signature) internal view {
if (!SignatureChecker.isValidSignatureNow(
action.common.signer,
_hashTypedDataV4(hash),
signature
)) revert VerifierInvalidSignerError();
}
/// @notice Checks whether signer is allowed to sign a message for account
/// @param account user to check authorization for
/// @param signer address which signed a message for the account
/// @return true if signer is authorized, otherwise false
function _authorized(address account, address signer) internal view override returns (bool) {
return super._authorized(account, signer) || marketFactory.signers(account, signer);
}
}