Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/operator restrictions #4

Open
wants to merge 47 commits into
base: feat/generic-sanity-checks
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
6a9cd63
implemented order specific sanity checks
Oct 11, 2023
305fe99
fix: order schema
Oct 15, 2023
74b3fe4
feat: Import EIP712 and EIP1271 contracts for signature verification …
Oct 15, 2023
f7620c6
feat: implement order_type_hash for signature verification
Oct 15, 2023
f514692
feat: implement and use order hash fns for signature verification
Oct 15, 2023
9650e28
fix: add signatures param in fillOrder fn
Oct 15, 2023
c77178c
feat: implement signature verification core logic
Oct 15, 2023
e2bf7f6
fix: stack too deep by setting via_ir to true
Oct 15, 2023
de85df4
feat: implement fn to decode calldata
Oct 15, 2023
8009baa
define pre-interaction hook interface
Oct 15, 2023
a396f4c
feat: import and attach decoder lib for hooks
Oct 15, 2023
9aaac8a
feat: implement core logic of pre-interaction hook
Oct 15, 2023
f762069
fix: modify stubs as comments
Oct 15, 2023
410a120
fix: add another stub as a comment
Oct 15, 2023
2f7baa3
feat: implement vault contract
Oct 16, 2023
a419357
feat: integrate vault contract for maker-to-vault asset transfer
Oct 16, 2023
99211c4
feat: implement logic for vault-to-maker asset transfer
Oct 16, 2023
aa21e29
feat: define post-interaction hook interface
Oct 16, 2023
1646350
feat: implement core logic of post-interaction hook
Oct 16, 2023
c8ede00
feat: add validation for maker requested amount
Oct 16, 2023
a9af474
fix: corrected transfer from offered amount instead of requested amou…
Oct 16, 2023
8821760
refacator: renamed 'clearingPrices' fillOrder fn param to 'offeredAmo…
Oct 16, 2023
44d6b9f
fix: passing 'orderMessageHash' instead of 'orderHash' in pre-interac…
Oct 16, 2023
edee642
feat: log OrderFill event
Oct 16, 2023
5479a53
define facilitator interaction hook interface
Oct 16, 2023
7ea9136
refactor: modify 'fillOrders' fn param
Oct 16, 2023
583ae79
refactor: renamed 'facilitatorInteractionCalldata' var of fillOrders …
Oct 16, 2023
3010816
refactor: modified facilitator interaction hook interface
Oct 16, 2023
9ed479a
feat: implement core logic of facilitator interaction hook
Oct 16, 2023
52a9bea
docs: modified natspec comments of facilitator interaction hook inter…
Oct 16, 2023
5d1d7e3
refactor: removed unnecessary comment
Oct 16, 2023
a09b9b1
feat: implement only operator modifier
Oct 16, 2023
dd87423
feat: implement manage operator role fn
Oct 16, 2023
5c9f6b5
fix: transfer funds to recipient from vault instead of maker
Oct 16, 2023
d2a300a
docs: added some TBD comments
Oct 16, 2023
efe5a3b
Create slither.yml
gul-hameed Oct 19, 2023
48d19f2
Update slither.yml
gul-hameed Oct 19, 2023
caa07f0
Update slither.yml
gul-hameed Oct 19, 2023
564a5e4
Update slither.yml
gul-hameed Oct 19, 2023
20e8888
Update slither.yml
gul-hameed Oct 19, 2023
6a6b68f
Update slither.yml
gul-hameed Oct 19, 2023
caf8f71
Update slither.yml
gul-hameed Oct 19, 2023
6af3d10
Update slither.yml
gul-hameed Oct 19, 2023
31880f4
Update slither.yml
gul-hameed Oct 25, 2023
ccaaaf0
Update slither.yml
gul-hameed Oct 25, 2023
4508197
Create slither-output.txt
gul-hameed Oct 25, 2023
c4921e1
Update slither.yml
gul-hameed Oct 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/AdvancedOrderEngine.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;

import {EIP712} from "openzeppelin/utils/cryptography/EIP712.sol";
import {IERC1271} from "openzeppelin/interfaces/IERC1271.sol";
import {OrderEngine} from "./libraries/OrderEngine.sol";
import "./AdvancedOrderEngineErrors.sol";

contract AdvancedOrderEngine {
contract AdvancedOrderEngine is EIP712 {
using OrderEngine for OrderEngine.Order;

constructor(
string memory name,
string memory version
) EIP712(name, version) {}

/**
* @notice Fills multiple orders by processing the specified orders and clearing prices.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@0xhammadghazi
The natspec for signatures seems missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

acknowledged

*
Expand Down Expand Up @@ -46,6 +53,32 @@ contract AdvancedOrderEngine {
revert ZeroFacilitatorTargetAddress(); // TBD: use generic error message i.e. ZeroAddress()
}

for (uint256 i; i < orders.length; ) {
OrderEngine.Order calldata order = orders[i];

bytes32 orderHash;

if (block.timestamp > order.validTill) {
revert OrderExpired(orderHash);
}

if (order.buyTokenAmount == 0 || order.sellTokenAmount == 0) {
revert ZeroTokenAmounts();
}

if (
order.maker == address(0) ||
order.buyToken == address(0) ||
order.sellToken == address(0)
) {
revert ZeroAddress();
}

unchecked {
++i;
}
}

// Loop start
// Perform order specific sanity checks
// Verify signatjures
Expand Down
3 changes: 3 additions & 0 deletions src/AdvancedOrderEngineErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ pragma solidity 0.8.21;
error ArraysLengthMismatch(uint256 ordersArrLen, uint256 clearingPricesArrLen);
error ZeroFacilitatorTargetAddress();
error EmptyOrdersArray();
error OrderExpired(bytes32 orderHash);
error ZeroTokenAmounts();
error ZeroAddress();
22 changes: 21 additions & 1 deletion src/libraries/OrderEngine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ library OrderEngine {
bytes predicates;
bytes preInteraction;
bytes postInteraction;
bytes signature;
}

bytes32 public constant ORDER_TYPE_HASH =
keccak256(
"Order("
"uint256 nonce,"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use smaller datatype for nonce ?
@0xhammadghazi

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm considering this. Actually, we can consider using smaller types for the following variables: nonce, validTill, sellTokenAmount, buyTokenAmount, and feeAmounts

"uint256 validTill,"
"uint256 sellTokenAmount,"
"uint256 buyTokenAmount,"
"uint256 feeAmounts,"
"address maker,"
"address taker,"
"address recipient,"
"address sellToken,"
"address buyToken,"
"bool isPartiallyFillable,"
"bytes32 extraData,"
"bytes predicates,"
"bytes preInteraction,"
"bytes postInteraction"
")"
);
}