Generate (complete) solidity docs (#2391)
* `@0x/sol-doc`: New doc generator. * `@0x/sol-compiler`: Be more tolerant of AST-only compilation targets. * `@0x/contracts-exchange`: Add more devdoc comments. `@0x/contracts-exchange-libs`: Add more devdoc comments. * `@0x/sol-doc`: Update package script. * `@0x/sol-doc`: Remove unused files and update package scripts to be easier to configure. * Add more devdocs to contracts. * `@0x/sol-doc`: Remove doc artifacts. * `@0x/sol-doc`: Add `.gitignore` and `.npmignore`. * `@0x/contracts-exchange`: Fix compilation errors. * Fix more broken contracts. * `@0x/contracts-erc20-bridge-sampler`: Fix failing tests. * `@0x/contracts-asset-proxy`: Remove accidentally introduced hackathion file (lol). * `@0x/sol-doc`: Prevent some inherited contracts from being included in docs unintentionally. * `@0x/sol-doc`: Rename test file. * `@0x/contracts-exchange`: Update `orderEpoch` devdoc. * `@0x/sol-doc`: Tweak event and function docs. * Update CODEOWNERS. * `@0x/sol-doc` Tweak function md generation. * `@0x/sol-doc`: add `transformDocs()` tests. * `@0x/sol-doc`: add `extract_docs` tests. * `@0x/sol-doc` Fix linter errors. * `@0x/contracts-erc20-bridge-sampler`: Fix broken `ERC20BridgeSampler.sol` compile. * `@0x/sol-doc` Fix mismatched `dev-utils` dep version. * `@0x/sol-doc`: Add `gen_md` tests. * `@0x/sol-doc`: Remove `fs.promises` calls. * `@0x/sol-doc`: Fix linter errors. * `@0x/sol-doc`: Export all relevant types and functions. Co-authored-by: Lawrence Forman <me@merklejerk.com>
This commit is contained in:
@@ -29,6 +29,7 @@ import "./MixinTransferSimulator.sol";
|
||||
// MixinAssetProxyDispatcher, MixinExchangeCore, MixinSignatureValidator,
|
||||
// and MixinTransactions are all inherited via the other Mixins that are
|
||||
// used.
|
||||
/// @dev The 0x Exchange contract.
|
||||
contract Exchange is
|
||||
LibEIP712ExchangeDomain,
|
||||
MixinMatchOrders,
|
||||
|
||||
@@ -62,11 +62,11 @@ contract MixinAssetProxyDispatcher is
|
||||
|
||||
/// @dev Gets an asset proxy.
|
||||
/// @param assetProxyId Id of the asset proxy.
|
||||
/// @return The asset proxy registered to assetProxyId. Returns 0x0 if no proxy is registered.
|
||||
/// @return assetProxy The asset proxy address registered to assetProxyId. Returns 0x0 if no proxy is registered.
|
||||
function getAssetProxy(bytes4 assetProxyId)
|
||||
external
|
||||
view
|
||||
returns (address)
|
||||
returns (address assetProxy)
|
||||
{
|
||||
return _assetProxies[assetProxyId];
|
||||
}
|
||||
|
||||
@@ -45,14 +45,21 @@ contract MixinExchangeCore is
|
||||
using LibSafeMath for uint256;
|
||||
using LibBytes for bytes;
|
||||
|
||||
// Mapping of orderHash => amount of takerAsset already bought by maker
|
||||
/// @dev Mapping of orderHash => amount of takerAsset already bought by maker
|
||||
/// @param 0 Order hash.
|
||||
/// @return 0 The amount of taker asset filled.
|
||||
mapping (bytes32 => uint256) public filled;
|
||||
|
||||
// Mapping of orderHash => cancelled
|
||||
/// @dev Mapping of orderHash => cancelled
|
||||
/// @param 0 Order hash.
|
||||
/// @return 0 Whether the order was cancelled.
|
||||
mapping (bytes32 => bool) public cancelled;
|
||||
|
||||
// Mapping of makerAddress => senderAddress => lowest salt an order can have in order to be fillable
|
||||
// Orders with specified senderAddress and with a salt less than their epoch are considered cancelled
|
||||
/// @dev Mapping of makerAddress => senderAddress => lowest salt an order can have in order to be fillable
|
||||
/// Orders with specified senderAddress and with a salt less than their epoch are considered cancelled
|
||||
/// @param 0 Address of the order's maker.
|
||||
/// @param 1 Address of the order's sender.
|
||||
/// @return 0 Minimum valid order epoch.
|
||||
mapping (address => mapping (address => uint256)) public orderEpoch;
|
||||
|
||||
/// @dev Cancels all orders created by makerAddress with a salt less than or equal to the targetOrderEpoch
|
||||
@@ -94,7 +101,7 @@ contract MixinExchangeCore is
|
||||
/// @param order Order struct containing order specifications.
|
||||
/// @param takerAssetFillAmount Desired amount of takerAsset to sell.
|
||||
/// @param signature Proof that order has been created by maker.
|
||||
/// @return Amounts filled and fees paid by maker and taker.
|
||||
/// @return fillResults Amounts filled and fees paid by maker and taker.
|
||||
function fillOrder(
|
||||
LibOrder.Order memory order,
|
||||
uint256 takerAssetFillAmount,
|
||||
@@ -125,7 +132,7 @@ contract MixinExchangeCore is
|
||||
|
||||
/// @dev Gets information about an order: status, hash, and amount filled.
|
||||
/// @param order Order to gather information on.
|
||||
/// @return OrderInfo Information about the order and its state.
|
||||
/// @return orderInfo Information about the order and its state.
|
||||
/// See LibOrder.OrderInfo for a complete description.
|
||||
function getOrderInfo(LibOrder.Order memory order)
|
||||
public
|
||||
@@ -140,7 +147,7 @@ contract MixinExchangeCore is
|
||||
// edge cases in the supporting infrastructure because they have
|
||||
// an 'infinite' price when computed by a simple division.
|
||||
if (order.makerAssetAmount == 0) {
|
||||
orderInfo.orderStatus = uint8(LibOrder.OrderStatus.INVALID_MAKER_ASSET_AMOUNT);
|
||||
orderInfo.orderStatus = LibOrder.OrderStatus.INVALID_MAKER_ASSET_AMOUNT;
|
||||
return orderInfo;
|
||||
}
|
||||
|
||||
@@ -149,35 +156,35 @@ contract MixinExchangeCore is
|
||||
// Instead of distinguishing between unfilled and filled zero taker
|
||||
// amount orders, we choose not to support them.
|
||||
if (order.takerAssetAmount == 0) {
|
||||
orderInfo.orderStatus = uint8(LibOrder.OrderStatus.INVALID_TAKER_ASSET_AMOUNT);
|
||||
orderInfo.orderStatus = LibOrder.OrderStatus.INVALID_TAKER_ASSET_AMOUNT;
|
||||
return orderInfo;
|
||||
}
|
||||
|
||||
// Validate order availability
|
||||
if (orderInfo.orderTakerAssetFilledAmount >= order.takerAssetAmount) {
|
||||
orderInfo.orderStatus = uint8(LibOrder.OrderStatus.FULLY_FILLED);
|
||||
orderInfo.orderStatus = LibOrder.OrderStatus.FULLY_FILLED;
|
||||
return orderInfo;
|
||||
}
|
||||
|
||||
// Validate order expiration
|
||||
// solhint-disable-next-line not-rely-on-time
|
||||
if (block.timestamp >= order.expirationTimeSeconds) {
|
||||
orderInfo.orderStatus = uint8(LibOrder.OrderStatus.EXPIRED);
|
||||
orderInfo.orderStatus = LibOrder.OrderStatus.EXPIRED;
|
||||
return orderInfo;
|
||||
}
|
||||
|
||||
// Check if order has been cancelled
|
||||
if (cancelled[orderInfo.orderHash]) {
|
||||
orderInfo.orderStatus = uint8(LibOrder.OrderStatus.CANCELLED);
|
||||
orderInfo.orderStatus = LibOrder.OrderStatus.CANCELLED;
|
||||
return orderInfo;
|
||||
}
|
||||
if (orderEpoch[order.makerAddress][order.senderAddress] > order.salt) {
|
||||
orderInfo.orderStatus = uint8(LibOrder.OrderStatus.CANCELLED);
|
||||
orderInfo.orderStatus = LibOrder.OrderStatus.CANCELLED;
|
||||
return orderInfo;
|
||||
}
|
||||
|
||||
// All other statuses are ruled out: order is Fillable
|
||||
orderInfo.orderStatus = uint8(LibOrder.OrderStatus.FILLABLE);
|
||||
orderInfo.orderStatus = LibOrder.OrderStatus.FILLABLE;
|
||||
return orderInfo;
|
||||
}
|
||||
|
||||
@@ -185,7 +192,7 @@ contract MixinExchangeCore is
|
||||
/// @param order Order struct containing order specifications.
|
||||
/// @param takerAssetFillAmount Desired amount of takerAsset to sell.
|
||||
/// @param signature Proof that order has been created by maker.
|
||||
/// @return Amounts filled and fees paid by maker and taker.
|
||||
/// @return fillResults Amounts filled and fees paid by maker and taker.
|
||||
function _fillOrder(
|
||||
LibOrder.Order memory order,
|
||||
uint256 takerAssetFillAmount,
|
||||
@@ -255,7 +262,7 @@ contract MixinExchangeCore is
|
||||
_assertValidCancel(order, orderInfo);
|
||||
|
||||
// Noop if order is already unfillable
|
||||
if (orderInfo.orderStatus != uint8(LibOrder.OrderStatus.FILLABLE)) {
|
||||
if (orderInfo.orderStatus != LibOrder.OrderStatus.FILLABLE) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -337,7 +344,7 @@ contract MixinExchangeCore is
|
||||
view
|
||||
{
|
||||
// An order can only be filled if its status is FILLABLE.
|
||||
if (orderInfo.orderStatus != uint8(LibOrder.OrderStatus.FILLABLE)) {
|
||||
if (orderInfo.orderStatus != LibOrder.OrderStatus.FILLABLE) {
|
||||
LibRichErrors.rrevert(LibExchangeRichErrors.OrderStatusError(
|
||||
orderInfo.orderHash,
|
||||
LibOrder.OrderStatus(orderInfo.orderStatus)
|
||||
|
||||
@@ -29,10 +29,12 @@ contract MixinProtocolFees is
|
||||
IProtocolFees,
|
||||
Ownable
|
||||
{
|
||||
// The protocol fee multiplier -- the owner can update this field.
|
||||
/// @dev The protocol fee multiplier -- the owner can update this field.
|
||||
/// @return 0 Gas multplier.
|
||||
uint256 public protocolFeeMultiplier;
|
||||
|
||||
// The address of the registered protocolFeeCollector contract -- the owner can update this field.
|
||||
/// @dev The address of the registered protocolFeeCollector contract -- the owner can update this field.
|
||||
/// @return 0 Contract to forward protocol fees to.
|
||||
address public protocolFeeCollector;
|
||||
|
||||
/// @dev Allows the owner to update the protocol fee multiplier.
|
||||
|
||||
@@ -47,10 +47,16 @@ contract MixinSignatureValidator is
|
||||
// bytes4(keccak256("isValidWalletSignature(bytes32,address,bytes)"))
|
||||
bytes4 private constant LEGACY_WALLET_MAGIC_VALUE = 0xb0671381;
|
||||
|
||||
// Mapping of hash => signer => signed
|
||||
/// @dev Mapping of hash => signer => signed
|
||||
/// @param 0 Order hash.
|
||||
/// @param 1 Signer address.
|
||||
/// @return 0 Whether the hash is presigned.
|
||||
mapping (bytes32 => mapping (address => bool)) public preSigned;
|
||||
|
||||
// Mapping of signer => validator => approved
|
||||
/// @dev Mapping of signer => validator => approved
|
||||
/// @param 0 Signer address.
|
||||
/// @param 1 Signature validator address.
|
||||
/// @return 0 Whether the validator is allowed to validate on behalf of the signer.
|
||||
mapping (address => mapping (address => bool)) public allowedValidators;
|
||||
|
||||
/// @dev Approves a hash on-chain.
|
||||
|
||||
@@ -36,11 +36,14 @@ contract MixinTransactions is
|
||||
{
|
||||
using LibZeroExTransaction for LibZeroExTransaction.ZeroExTransaction;
|
||||
|
||||
// Mapping of transaction hash => executed
|
||||
// This prevents transactions from being executed more than once.
|
||||
/// @dev Mapping of transaction hash => executed
|
||||
/// This prevents transactions from being executed more than once.
|
||||
/// @param 0 The transaction hash.
|
||||
/// @return 0 Whether the transation was executed.
|
||||
mapping (bytes32 => bool) public transactionsExecuted;
|
||||
|
||||
// Address of current transaction signer
|
||||
/// @dev Address of current transaction signer.
|
||||
/// @return 0 The address associated with the the current transaction.
|
||||
address public currentContextAddress;
|
||||
|
||||
/// @dev Executes an Exchange method call in the context of signer.
|
||||
@@ -62,7 +65,7 @@ contract MixinTransactions is
|
||||
/// @dev Executes a batch of Exchange method calls in the context of signer(s).
|
||||
/// @param transactions Array of 0x transaction structures.
|
||||
/// @param signatures Array of proofs that transactions have been signed by signer(s).
|
||||
/// @return Array containing ABI encoded return data for each of the underlying Exchange function calls.
|
||||
/// @return returnData Array containing ABI encoded return data for each of the underlying Exchange function calls.
|
||||
function batchExecuteTransactions(
|
||||
LibZeroExTransaction.ZeroExTransaction[] memory transactions,
|
||||
bytes[] memory signatures
|
||||
@@ -70,10 +73,10 @@ contract MixinTransactions is
|
||||
public
|
||||
payable
|
||||
disableRefundUntilEnd
|
||||
returns (bytes[] memory)
|
||||
returns (bytes[] memory returnData)
|
||||
{
|
||||
uint256 length = transactions.length;
|
||||
bytes[] memory returnData = new bytes[](length);
|
||||
returnData = new bytes[](length);
|
||||
for (uint256 i = 0; i != length; i++) {
|
||||
returnData[i] = _executeTransaction(transactions[i], signatures[i]);
|
||||
}
|
||||
@@ -117,7 +120,7 @@ contract MixinTransactions is
|
||||
_setCurrentContextAddressIfRequired(signerAddress, address(0));
|
||||
|
||||
emit TransactionExecution(transactionHash);
|
||||
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,10 +36,11 @@ contract MixinWrapperFunctions is
|
||||
{
|
||||
using LibSafeMath for uint256;
|
||||
|
||||
/// @dev Fills the input order. Reverts if exact takerAssetFillAmount not filled.
|
||||
/// @dev Fills the input order. Reverts if exact `takerAssetFillAmount` not filled.
|
||||
/// @param order Order struct containing order specifications.
|
||||
/// @param takerAssetFillAmount Desired amount of takerAsset to sell.
|
||||
/// @param signature Proof that order has been created by maker.
|
||||
/// @return fillResults Amounts filled and fees paid.
|
||||
function fillOrKillOrder(
|
||||
LibOrder.Order memory order,
|
||||
uint256 takerAssetFillAmount,
|
||||
@@ -62,7 +63,7 @@ contract MixinWrapperFunctions is
|
||||
/// @param orders Array of order specifications.
|
||||
/// @param takerAssetFillAmounts Array of desired amounts of takerAsset to sell in orders.
|
||||
/// @param signatures Proofs that orders have been created by makers.
|
||||
/// @return Array of amounts filled and fees paid by makers and taker.
|
||||
/// @return fillResults Array of amounts filled and fees paid by makers and taker.
|
||||
function batchFillOrders(
|
||||
LibOrder.Order[] memory orders,
|
||||
uint256[] memory takerAssetFillAmounts,
|
||||
@@ -89,7 +90,7 @@ contract MixinWrapperFunctions is
|
||||
/// @param orders Array of order specifications.
|
||||
/// @param takerAssetFillAmounts Array of desired amounts of takerAsset to sell in orders.
|
||||
/// @param signatures Proofs that orders have been created by makers.
|
||||
/// @return Array of amounts filled and fees paid by makers and taker.
|
||||
/// @return fillResults Array of amounts filled and fees paid by makers and taker.
|
||||
function batchFillOrKillOrders(
|
||||
LibOrder.Order[] memory orders,
|
||||
uint256[] memory takerAssetFillAmounts,
|
||||
@@ -116,7 +117,7 @@ contract MixinWrapperFunctions is
|
||||
/// @param orders Array of order specifications.
|
||||
/// @param takerAssetFillAmounts Array of desired amounts of takerAsset to sell in orders.
|
||||
/// @param signatures Proofs that orders have been created by makers.
|
||||
/// @return Array of amounts filled and fees paid by makers and taker.
|
||||
/// @return fillResults Array of amounts filled and fees paid by makers and taker.
|
||||
function batchFillOrdersNoThrow(
|
||||
LibOrder.Order[] memory orders,
|
||||
uint256[] memory takerAssetFillAmounts,
|
||||
@@ -145,7 +146,7 @@ contract MixinWrapperFunctions is
|
||||
/// @param orders Array of order specifications.
|
||||
/// @param takerAssetFillAmount Desired amount of takerAsset to sell.
|
||||
/// @param signatures Proofs that orders have been signed by makers.
|
||||
/// @return Amounts filled and fees paid by makers and taker.
|
||||
/// @return fillResults Amounts filled and fees paid by makers and taker.
|
||||
function marketSellOrdersNoThrow(
|
||||
LibOrder.Order[] memory orders,
|
||||
uint256 takerAssetFillAmount,
|
||||
@@ -186,7 +187,7 @@ contract MixinWrapperFunctions is
|
||||
/// @param orders Array of order specifications.
|
||||
/// @param makerAssetFillAmount Desired amount of makerAsset to buy.
|
||||
/// @param signatures Proofs that orders have been signed by makers.
|
||||
/// @return Amounts filled and fees paid by makers and taker.
|
||||
/// @return fillResults Amounts filled and fees paid by makers and taker.
|
||||
function marketBuyOrdersNoThrow(
|
||||
LibOrder.Order[] memory orders,
|
||||
uint256 makerAssetFillAmount,
|
||||
@@ -234,7 +235,7 @@ contract MixinWrapperFunctions is
|
||||
/// @param orders Array of order specifications.
|
||||
/// @param takerAssetFillAmount Minimum amount of takerAsset to sell.
|
||||
/// @param signatures Proofs that orders have been signed by makers.
|
||||
/// @return Amounts filled and fees paid by makers and taker.
|
||||
/// @return fillResults Amounts filled and fees paid by makers and taker.
|
||||
function marketSellOrdersFillOrKill(
|
||||
LibOrder.Order[] memory orders,
|
||||
uint256 takerAssetFillAmount,
|
||||
@@ -259,7 +260,7 @@ contract MixinWrapperFunctions is
|
||||
/// @param orders Array of order specifications.
|
||||
/// @param makerAssetFillAmount Minimum amount of makerAsset to buy.
|
||||
/// @param signatures Proofs that orders have been signed by makers.
|
||||
/// @return Amounts filled and fees paid by makers and taker.
|
||||
/// @return fillResults Amounts filled and fees paid by makers and taker.
|
||||
function marketBuyOrdersFillOrKill(
|
||||
LibOrder.Order[] memory orders,
|
||||
uint256 makerAssetFillAmount,
|
||||
@@ -295,7 +296,7 @@ contract MixinWrapperFunctions is
|
||||
/// @dev Fills the input order. Reverts if exact takerAssetFillAmount not filled.
|
||||
/// @param order Order struct containing order specifications.
|
||||
/// @param takerAssetFillAmount Desired amount of takerAsset to sell.
|
||||
/// @param signature Proof that order has been created by maker.
|
||||
/// @param fillResults ignature Proof that order has been created by maker.
|
||||
function _fillOrKillOrder(
|
||||
LibOrder.Order memory order,
|
||||
uint256 takerAssetFillAmount,
|
||||
@@ -324,7 +325,7 @@ contract MixinWrapperFunctions is
|
||||
/// @param order Order struct containing order specifications.
|
||||
/// @param takerAssetFillAmount Desired amount of takerAsset to sell.
|
||||
/// @param signature Proof that order has been created by maker.
|
||||
/// @return Amounts filled and fees paid by maker and taker.
|
||||
/// @return fillResults Amounts filled and fees paid by maker and taker.
|
||||
function _fillOrderNoThrow(
|
||||
LibOrder.Order memory order,
|
||||
uint256 takerAssetFillAmount,
|
||||
|
||||
@@ -30,7 +30,7 @@ import "../src/Exchange.sol";
|
||||
contract TestWrapperFunctions is
|
||||
Exchange
|
||||
{
|
||||
uint8 internal constant MAX_ORDER_STATUS = uint8(LibOrder.OrderStatus.CANCELLED);
|
||||
LibOrder.OrderStatus internal constant MAX_ORDER_STATUS = LibOrder.OrderStatus.CANCELLED;
|
||||
uint256 internal constant ALWAYS_FAILING_SALT = uint256(-1);
|
||||
string internal constant ALWAYS_FAILING_SALT_REVERT_REASON = "ALWAYS_FAILING_SALT";
|
||||
|
||||
@@ -61,7 +61,7 @@ contract TestWrapperFunctions is
|
||||
// Lower uint128 of `order.salt` is the `orderTakerAssetFilledAmount`.
|
||||
orderInfo.orderTakerAssetFilledAmount = uint128(order.salt);
|
||||
// High byte of `order.salt` is the `orderStatus`.
|
||||
orderInfo.orderStatus = uint8(order.salt >> 248) % (MAX_ORDER_STATUS + 1);
|
||||
orderInfo.orderStatus = LibOrder.OrderStatus(uint8(order.salt >> 248) % (uint8(MAX_ORDER_STATUS) + 1));
|
||||
orderInfo.orderHash = order.getTypedDataHash(EIP712_EXCHANGE_DOMAIN_HASH);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user