Skip to content

Commit

Permalink
add NatSpec comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ZumZoom committed Jun 28, 2024
1 parent b1a0179 commit 7d5f824
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
6 changes: 6 additions & 0 deletions contracts/helpers/OrderRegistrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { IOrderMixin } from "../interfaces/IOrderMixin.sol";
import { IOrderRegistrator } from "../interfaces/IOrderRegistrator.sol";
import { OrderLib } from "../OrderLib.sol";

/**
* @title OrderRegistrator
*/
contract OrderRegistrator is IOrderRegistrator {
using AddressLib for Address;
using OrderLib for IOrderMixin.Order;
Expand All @@ -18,6 +21,9 @@ contract OrderRegistrator is IOrderRegistrator {
_LIMIT_ORDER_PROTOCOL = limitOrderProtocol;
}

/**
* @notice See {IOrderRegistrator-registerOrder}.
*/
function registerOrder(IOrderMixin.Order calldata order, bytes calldata extension, bytes calldata signature) external {
// Validate order
{
Expand Down
23 changes: 20 additions & 3 deletions contracts/helpers/SafeOrderBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import { IOrderMixin } from "../interfaces/IOrderMixin.sol";
import { IOrderRegistrator } from "../interfaces/IOrderRegistrator.sol";

/**
* @title SafeOrderBuilder
* @dev The contract is responsible for building and signing limit orders for the GnosisSafe.
* The contract uses oracles to adjust the order taking amount based on the volatility of the maker and taker assets.
*/
contract SafeOrderBuilder is GnosisSafeStorage {
error StaleOraclePrice();

Expand All @@ -28,6 +33,15 @@ contract SafeOrderBuilder is GnosisSafeStorage {
uint256 ttl;
}

/**
* @notice Builds and signs a limit order for the GnosisSafe.
* The order is signed by the GnosisSafe and registered in the order registrator.
* The order taking amount is adjusted based on the volatility of the maker and taker assets.
* @param order The order to be built and signed.
* @param extension The extension data associated with the order.
* @param makerAssetOracleParams The oracle query parameters for the maker asset.
* @param takerAssetOracleParams The oracle query parameters for the taker asset.
*/
function buildAndSignOrder(
IOrderMixin.Order memory order,
bytes calldata extension,
Expand Down Expand Up @@ -56,9 +70,12 @@ contract SafeOrderBuilder is GnosisSafeStorage {
_ORDER_REGISTRATOR.registerOrder(order, extension, "");
}

/// @dev Returns hash of a message that can be signed by owners.
/// @param message Message that should be hashed
/// @return Message hash.

/**
* @dev Returns hash of a message that can be signed by owners.
* @param message Message that should be hashed.
* @return bytes32 hash of the message.
*/
function _getMessageHash(bytes memory message) private view returns (bytes32) {
bytes32 safeMessageHash = keccak256(abi.encode(_SAFE_MSG_TYPEHASH, keccak256(message)));
return keccak256(abi.encodePacked(bytes1(0x19), bytes1(0x01), GnosisSafe(payable(address(this))).domainSeparator(), safeMessageHash));
Expand Down
17 changes: 17 additions & 0 deletions contracts/interfaces/IOrderRegistrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,25 @@ pragma solidity 0.8.23;

import { IOrderMixin } from "./IOrderMixin.sol";

/**
* @title IOrderRegistrator
* @dev The interface defines the structure of the order registrator contract.
* The registrator is responsible for registering orders and emitting an event when an order is registered.
*/
interface IOrderRegistrator {
/**
* @notice Emitted when an order is registered.
* @param order The order that was registered.
* @param extension The extension data associated with the order.
* @param signature The signature of the order.
*/
event OrderRegistered(IOrderMixin.Order order, bytes extension, bytes signature);

/**
* @notice Registers an order.
* @param order The order to be registered.
* @param extension The extension data associated with the order.
* @param signature The signature of the order.
*/
function registerOrder(IOrderMixin.Order calldata order, bytes calldata extension, bytes calldata signature) external;
}

0 comments on commit 7d5f824

Please sign in to comment.