Skip to content

Commit

Permalink
fix: add maker and taker amounts to OrderFilled and OrdersMatched eve…
Browse files Browse the repository at this point in the history
…nts, formatting
  • Loading branch information
JonathanAmenechi committed Sep 26, 2022
1 parent 1ca6f1b commit af3ba7f
Show file tree
Hide file tree
Showing 25 changed files with 158 additions and 156 deletions.
15 changes: 14 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
profile = { default = { libs = ["node_modules", "lib"] } }
[profile.default]
solc = "0.8.15"
ffi = true
gas_reports = ["*"]
out = "out"
optimizer_runs = 1000000

# fuzz settings
[profile.default.fuzz]
runs = 256
[profile.intense.fuzz]
runs = 10_000

[fmt]
line_length = 120
tab_width = 4
bracket_spacing = true
single_line_statement_blocks = "single"
6 changes: 3 additions & 3 deletions src/exchange/BaseExchange.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import {ERC1155Holder} from "openzeppelin-contracts/token/ERC1155/utils/ERC1155Holder.sol";
import {ReentrancyGuard} from "common/ReentrancyGuard.sol";
import { ERC1155Holder } from "openzeppelin-contracts/token/ERC1155/utils/ERC1155Holder.sol";
import { ReentrancyGuard } from "common/ReentrancyGuard.sol";

abstract contract BaseExchange is ERC1155Holder, ReentrancyGuard {}
abstract contract BaseExchange is ERC1155Holder, ReentrancyGuard { }
26 changes: 13 additions & 13 deletions src/exchange/CTFExchange.sol
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;

import {Auth} from "./mixins/Auth.sol";
import {Fees} from "./mixins/Fees.sol";
import {Assets} from "./mixins/Assets.sol";
import {Hashing} from "./mixins/Hashing.sol";
import {Trading} from "./mixins/Trading.sol";
import {Registry} from "./mixins/Registry.sol";
import {Pausable} from "./mixins/Pausable.sol";
import {Signatures} from "./mixins/Signatures.sol";
import {NonceManager} from "./mixins/NonceManager.sol";
import {AssetOperations} from "./mixins/AssetOperations.sol";
import { Auth } from "./mixins/Auth.sol";
import { Fees } from "./mixins/Fees.sol";
import { Assets } from "./mixins/Assets.sol";
import { Hashing } from "./mixins/Hashing.sol";
import { Trading } from "./mixins/Trading.sol";
import { Registry } from "./mixins/Registry.sol";
import { Pausable } from "./mixins/Pausable.sol";
import { Signatures } from "./mixins/Signatures.sol";
import { NonceManager } from "./mixins/NonceManager.sol";
import { AssetOperations } from "./mixins/AssetOperations.sol";

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

import {Order} from "./libraries/OrderStructs.sol";
import { Order } from "./libraries/OrderStructs.sol";

/// @title CTF Exchange
/// @notice Implements logic for trading CTF assets
Expand All @@ -35,7 +35,7 @@ contract CTFExchange is
constructor(address _collateral, address _ctf, address _proxyFactory, address _safeFactory)
Assets(_collateral, _ctf)
Signatures(_proxyFactory, _safeFactory)
{}
{ }

/*//////////////////////////////////////////////////////////////
PAUSE
Expand Down
2 changes: 1 addition & 1 deletion src/exchange/interfaces/IConditionalTokens.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import {IERC20} from "openzeppelin-contracts/token/ERC20/IERC20.sol";
import { IERC20 } from "openzeppelin-contracts/token/ERC20/IERC20.sol";

/// @title IConditionalTokens
/// @notice Interface for the Gnosis ConditionalTokensFramework: https://github.com/gnosis/conditional-tokens-contracts/blob/master/contracts/ConditionalTokens.sol
Expand Down
2 changes: 1 addition & 1 deletion src/exchange/interfaces/IHashing.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import {Order} from "../libraries/OrderStructs.sol";
import { Order } from "../libraries/OrderStructs.sol";

abstract contract IHashing {
function hashOrder(Order memory order) public view virtual returns (bytes32);
Expand Down
2 changes: 1 addition & 1 deletion src/exchange/interfaces/ISignatures.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import {Order} from "../libraries/OrderStructs.sol";
import { Order } from "../libraries/OrderStructs.sol";

interface ISignaturesEE {
error InvalidSignature();
Expand Down
8 changes: 4 additions & 4 deletions src/exchange/interfaces/ITrading.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import {OrderStatus, Order} from "../libraries/OrderStructs.sol";
import { OrderStatus, Order } from "../libraries/OrderStructs.sol";

interface ITradingEE {
error NotOwner();
Expand All @@ -24,8 +24,8 @@ interface ITradingEE {
address indexed taker,
uint256 makerAssetId,
uint256 takerAssetId,
uint256 filled,
uint256 remaining,
uint256 makerAmountFilled,
uint256 takerAmountFilled,
uint256 fee
);

Expand All @@ -40,4 +40,4 @@ interface ITradingEE {
);
}

interface ITrading is ITradingEE {}
interface ITrading is ITradingEE { }
10 changes: 3 additions & 7 deletions src/exchange/libraries/CalculatorHelper.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import {Order, Side} from "../libraries/OrderStructs.sol";
import { Order, Side } from "../libraries/OrderStructs.sol";

library CalculatorHelper {
uint256 internal constant ONE = 10 ** 18;
Expand Down Expand Up @@ -56,16 +56,12 @@ library CalculatorHelper {
}

function _calculatePrice(uint256 makerAmount, uint256 takerAmount, Side side) internal pure returns (uint256) {
if (side == Side.BUY) {
return takerAmount != 0 ? makerAmount * ONE / takerAmount : 0;
}
if (side == Side.BUY) return takerAmount != 0 ? makerAmount * ONE / takerAmount : 0;
return makerAmount != 0 ? takerAmount * ONE / makerAmount : 0;
}

function isCrossing(Order memory a, Order memory b) internal pure returns (bool) {
if (a.takerAmount == 0 || b.takerAmount == 0) {
return true;
}
if (a.takerAmount == 0 || b.takerAmount == 0) return true;

return _isCrossing(calculatePrice(a), calculatePrice(b), a.side, b.side);
}
Expand Down
4 changes: 2 additions & 2 deletions src/exchange/libraries/TransferHelper.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import {IERC1155} from "openzeppelin-contracts/token/ERC1155/IERC1155.sol";
import { IERC1155 } from "openzeppelin-contracts/token/ERC1155/IERC1155.sol";

import {SafeTransferLib, ERC20} from "common/libraries/SafeTransferLib.sol";
import { SafeTransferLib, ERC20 } from "common/libraries/SafeTransferLib.sol";

/// @title TransferHelper
/// @notice Helper method to transfer tokens
Expand Down
27 changes: 10 additions & 17 deletions src/exchange/mixins/AssetOperations.sol
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import {IERC20} from "openzeppelin-contracts/token/ERC20/IERC20.sol";
import {IERC1155} from "openzeppelin-contracts/token/ERC1155/IERC1155.sol";
import { IERC20 } from "openzeppelin-contracts/token/ERC20/IERC20.sol";
import { IERC1155 } from "openzeppelin-contracts/token/ERC1155/IERC1155.sol";

import {IAssets} from "../interfaces/IAssets.sol";
import {IAssetOperations} from "../interfaces/IAssetOperations.sol";
import {IConditionalTokens} from "../interfaces/IConditionalTokens.sol";
import { IAssets } from "../interfaces/IAssets.sol";
import { IAssetOperations } from "../interfaces/IAssetOperations.sol";
import { IConditionalTokens } from "../interfaces/IConditionalTokens.sol";

import {TransferHelper} from "../libraries/TransferHelper.sol";
import { TransferHelper } from "../libraries/TransferHelper.sol";

/// @title Asset Operations
/// @notice Operations on the CTF and Collateral assets
abstract contract AssetOperations is IAssetOperations, IAssets {
bytes32 public constant parentCollectionId = bytes32(0);

function _getBalance(uint256 tokenId) internal override returns (uint256) {
if (tokenId == 0) {
return IERC20(getCollateral()).balanceOf(address(this));
}
if (tokenId == 0) return IERC20(getCollateral()).balanceOf(address(this));
return IERC1155(getCtf()).balanceOf(address(this), tokenId);
}

function _transfer(address from, address to, uint256 id, uint256 value) internal override {
if (id == 0) {
return _transferCollateral(from, to, value);
}
if (id == 0) return _transferCollateral(from, to, value);
return _transferCTF(from, to, id, value);
}

function _transferCollateral(address from, address to, uint256 value) internal {
address token = getCollateral();
if (from == address(this)) {
TransferHelper._transferERC20(token, to, value);
} else {
TransferHelper._transferFromERC20(token, from, to, value);
}
if (from == address(this)) TransferHelper._transferERC20(token, to, value);
else TransferHelper._transferFromERC20(token, from, to, value);
}

function _transferCTF(address from, address to, uint256 id, uint256 value) internal {
Expand Down
4 changes: 2 additions & 2 deletions src/exchange/mixins/Assets.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import {IERC20} from "openzeppelin-contracts/token/ERC20/IERC20.sol";
import { IERC20 } from "openzeppelin-contracts/token/ERC20/IERC20.sol";

import {IAssets} from "../interfaces/IAssets.sol";
import { IAssets } from "../interfaces/IAssets.sol";

abstract contract Assets is IAssets {
address internal immutable collateral;
Expand Down
2 changes: 1 addition & 1 deletion src/exchange/mixins/Auth.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import {IAuth} from "../interfaces/IAuth.sol";
import { IAuth } from "../interfaces/IAuth.sol";

/// @title Auth
/// @notice Provides admin and operator roles and access control modifiers
Expand Down
2 changes: 1 addition & 1 deletion src/exchange/mixins/Fees.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import {IFees} from "../interfaces/IFees.sol";
import { IFees } from "../interfaces/IFees.sol";

abstract contract Fees is IFees {
/// @notice Maximum fee rate that can be signed into an Order
Expand Down
6 changes: 3 additions & 3 deletions src/exchange/mixins/Hashing.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import {EIP712} from "openzeppelin-contracts/utils/cryptography/draft-EIP712.sol";
import { EIP712 } from "openzeppelin-contracts/utils/cryptography/draft-EIP712.sol";

import {IHashing} from "../interfaces/IHashing.sol";
import { IHashing } from "../interfaces/IHashing.sol";

import {Order, ORDER_TYPEHASH} from "../libraries/OrderStructs.sol";
import { Order, ORDER_TYPEHASH } from "../libraries/OrderStructs.sol";

abstract contract Hashing is EIP712, IHashing {
bytes32 public immutable domainSeparator;
Expand Down
6 changes: 3 additions & 3 deletions src/exchange/mixins/NonceManager.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import {INonceManager} from "../interfaces/INonceManager.sol";
import { INonceManager } from "../interfaces/INonceManager.sol";

abstract contract NonceManager is INonceManager {
mapping(address => uint256) public nonces;
Expand All @@ -11,10 +11,10 @@ abstract contract NonceManager is INonceManager {
}

function updateNonce(uint256 val) internal {
nonces[msg.sender] = nonces[msg.sender] + val;
nonces[ msg.sender] = nonces[ msg.sender] + val;
}

function isValidNonce(address usr, uint256 nonce) public view override returns (bool) {
return nonces[usr] == nonce;
return nonces[ usr] == nonce;
}
}
2 changes: 1 addition & 1 deletion src/exchange/mixins/Pausable.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import {IPausable} from "../interfaces/IPausable.sol";
import { IPausable } from "../interfaces/IPausable.sol";

abstract contract Pausable is IPausable {
bool public paused = false;
Expand Down
4 changes: 2 additions & 2 deletions src/exchange/mixins/PolyFactoryHelper.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import {PolySafeLib} from "../libraries/PolySafeLib.sol";
import {PolyProxyLib} from "../libraries/PolyProxyLib.sol";
import { PolySafeLib } from "../libraries/PolySafeLib.sol";
import { PolyProxyLib } from "../libraries/PolyProxyLib.sol";

interface IPolyProxyFactory {
function getImplementation() external view returns (address);
Expand Down
14 changes: 7 additions & 7 deletions src/exchange/mixins/Registry.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import {IRegistry} from "../interfaces/IRegistry.sol";
import { IRegistry } from "../interfaces/IRegistry.sol";

struct OutcomeToken {
uint256 complement;
Expand All @@ -15,14 +15,14 @@ abstract contract Registry is IRegistry {
/// @notice Gets the conditionId from a tokenId
/// @param token - The token
function getConditionId(uint256 token) public view override returns (bytes32) {
return registry[token].conditionId;
return registry[ token].conditionId;
}

/// @notice Gets the complement of a tokenId
/// @param token - The token
function getComplement(uint256 token) public view override returns (uint256) {
validateTokenId(token);
return registry[token].complement;
return registry[ token].complement;
}

/// @notice Validates the complement of a tokenId
Expand All @@ -35,16 +35,16 @@ abstract contract Registry is IRegistry {
/// @param tokenId - The tokenId

function validateTokenId(uint256 tokenId) public view override {
if (registry[tokenId].complement == 0) revert InvalidTokenId();
if (registry[ tokenId].complement == 0) revert InvalidTokenId();
}

function _registerToken(uint256 token0, uint256 token1, bytes32 conditionId) internal {
if (token0 == token1 || (token0 == 0 || token1 == 0)) revert InvalidTokenId();
if (registry[token0].complement != 0 || registry[token1].complement != 0) revert AlreadyRegistered();
if (registry[ token0].complement != 0 || registry[ token1].complement != 0) revert AlreadyRegistered();

registry[token0] = OutcomeToken({complement: token1, conditionId: conditionId});
registry[ token0] = OutcomeToken({complement: token1, conditionId: conditionId});

registry[token1] = OutcomeToken({complement: token0, conditionId: conditionId});
registry[ token1] = OutcomeToken({complement: token0, conditionId: conditionId});

emit TokenRegistered(token0, token1, conditionId);
emit TokenRegistered(token1, token0, conditionId);
Expand Down
12 changes: 6 additions & 6 deletions src/exchange/mixins/Signatures.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

import {IERC1271} from "openzeppelin-contracts/interfaces/IERC1271.sol";
import {ECDSA} from "openzeppelin-contracts/utils/cryptography/ECDSA.sol";
import { IERC1271 } from "openzeppelin-contracts/interfaces/IERC1271.sol";
import { ECDSA } from "openzeppelin-contracts/utils/cryptography/ECDSA.sol";

import {SignatureType, Order} from "../libraries/OrderStructs.sol";
import { SignatureType, Order } from "../libraries/OrderStructs.sol";

import {ISignatures} from "../interfaces/ISignatures.sol";
import { ISignatures } from "../interfaces/ISignatures.sol";

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

/// @title Signatures
/// @notice Maintains logic that defines the various signature types and validates them
abstract contract Signatures is ISignatures, PolyFactoryHelper {
constructor(address _proxyFactory, address _safeFactory) PolyFactoryHelper(_proxyFactory, _safeFactory) {}
constructor(address _proxyFactory, address _safeFactory) PolyFactoryHelper(_proxyFactory, _safeFactory) { }

/// @notice Validates the signature of an order
/// @param orderHash - The hash of the order
Expand Down
Loading

0 comments on commit af3ba7f

Please sign in to comment.