-
Notifications
You must be signed in to change notification settings - Fork 6
/
FloodPlainOnChainOrders.sol
57 lines (46 loc) · 1.91 KB
/
FloodPlainOnChainOrders.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
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
// Inheritances
import {FloodPlain} from "../FloodPlain.sol";
import {IFloodPlainOnChainOrders} from "./IFloodPlainOnChainOrders.sol";
// Libraries
import {OrderHash} from "../libraries/OrderHash.sol";
// Interfaces
import {IFloodPlain} from "../IFloodPlain.sol";
abstract contract FloodPlainOnChainOrders is FloodPlain, IFloodPlainOnChainOrders {
using OrderHash for Order;
OrderWithSignature[] internal _etchedOrders;
function getEtchedOrder(uint256 etchedOrderId)
external
view
returns (OrderWithSignature memory /* etchedOrder */ )
{
return _etchedOrders[etchedOrderId];
}
function fulfillEtchedOrder(uint256 orderId, address fulfiller, bytes calldata extraData) external {
OrderWithSignature memory orderWithSignature = _etchedOrders[orderId];
// Fulfill the etched order using the standard fulfillment function.
bytes memory data = abi.encodeWithSelector(
this.fulfillOrder.selector, orderWithSignature.order, orderWithSignature.signature, fulfiller, extraData
);
assembly {
let result := delegatecall(gas(), address(), add(data, 0x20), mload(data), 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// delegatecall returns 0 on error.
case 0 { revert(0, returndatasize()) }
default { return(0, returndatasize()) }
}
}
function etchOrder(OrderWithSignature calldata orderWithSignature) external returns (uint256 orderId) {
orderId = _etchedOrders.length;
_etchedOrders.push(orderWithSignature);
emit OrderEtched({
orderId: orderId,
orderHash: orderWithSignature.order.hash(),
order: orderWithSignature.order,
signature: orderWithSignature.signature
});
}
}