diff options
Diffstat (limited to 'packages/contracts/src')
7 files changed, 78 insertions, 63 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/IExchange.sol b/packages/contracts/src/contracts/current/protocol/Exchange/IExchange.sol index 3315e270f..083966425 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/IExchange.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/IExchange.sol @@ -35,8 +35,8 @@ contract IExchange { address indexed maker, address taker, address indexed feeRecipient, - address makerToken, - address takerToken, + bytes makerAssetData, + bytes takerAssetData, uint256 makerTokenFilledAmount, uint256 takerTokenFilledAmount, uint256 makerFeePaid, @@ -47,8 +47,8 @@ contract IExchange { event LogCancel( address indexed maker, address indexed feeRecipient, - address makerToken, - address takerToken, + bytes makerAssetData, + bytes takerAssetData, uint256 makerTokenCancelledAmount, uint256 takerTokenCancelledAmount, bytes32 indexed orderHash diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/LibOrder.sol b/packages/contracts/src/contracts/current/protocol/Exchange/LibOrder.sol index 862a8cfb5..d47a0fbbe 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/LibOrder.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/LibOrder.sol @@ -25,8 +25,6 @@ contract LibOrder { "address exchangeAddress", "address makerAddress", "address takerAddress", - "address makerTokenAddress", - "address takerTokenAddress", "address feeRecipientAddress", "uint256 makerTokenAmount", "uint256 takerTokenAmount", @@ -41,8 +39,6 @@ contract LibOrder { struct Order { address makerAddress; address takerAddress; - address makerTokenAddress; - address takerTokenAddress; address feeRecipientAddress; uint256 makerTokenAmount; uint256 takerTokenAmount; @@ -69,8 +65,6 @@ contract LibOrder { address(this), order.makerAddress, order.takerAddress, - order.makerTokenAddress, - order.takerTokenAddress, order.feeRecipientAddress, order.makerTokenAmount, order.takerTokenAmount, diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol index 000977cf6..ec1bd57ce 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol @@ -53,8 +53,8 @@ contract MixinExchangeCore is address indexed makerAddress, address takerAddress, address indexed feeRecipientAddress, - address makerTokenAddress, - address takerTokenAddress, + bytes makerAssetData, + bytes takerAssetData, uint256 makerTokenFilledAmount, uint256 takerTokenFilledAmount, uint256 makerFeePaid, @@ -65,8 +65,8 @@ contract MixinExchangeCore is event Cancel( address indexed makerAddress, address indexed feeRecipientAddress, - address makerTokenAddress, - address takerTokenAddress, + bytes makerAssetData, + bytes takerAssetData, bytes32 indexed orderHash ); @@ -153,8 +153,8 @@ contract MixinExchangeCore is order.makerAddress, msg.sender, order.feeRecipientAddress, - order.makerTokenAddress, - order.takerTokenAddress, + order.makerAssetData, + order.takerAssetData, fillResults.makerTokenFilledAmount, fillResults.takerTokenFilledAmount, fillResults.makerFeePaid, @@ -195,8 +195,8 @@ contract MixinExchangeCore is emit Cancel( order.makerAddress, order.feeRecipientAddress, - order.makerTokenAddress, - order.takerTokenAddress, + order.makerAssetData, + order.takerAssetData, orderHash ); return true; diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinWrapperFunctions.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinWrapperFunctions.sol index 8ac9977bd..027fcd87f 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinWrapperFunctions.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinWrapperFunctions.sol @@ -22,11 +22,13 @@ pragma experimental ABIEncoderV2; import "./mixins/MExchangeCore.sol"; import "./LibPartialAmount.sol"; import "../../utils/SafeMath/SafeMath.sol"; +import "../../utils/LibBytes/LibBytes.sol"; /// @dev Consumes MExchangeCore contract MixinWrapperFunctions is MExchangeCore, SafeMath, + LibBytes, LibPartialAmount { /// @dev Fills the input order. Reverts if exact takerTokenFillAmount not filled. @@ -73,26 +75,24 @@ contract MixinWrapperFunctions is // | | 0x00 | | 1. offset to order (*) | // | | 0x20 | | 2. takerTokenFillAmount | // | | 0x40 | | 3. offset to signature (*) | - // | Data | | 13 * 32 | order: | + // | Data | | 11 * 32 | order: | // | | 0x000 | | 1. makerAddress | // | | 0x020 | | 2. takerAddress | - // | | 0x040 | | 3. makerTokenAddress | - // | | 0x060 | | 4. takerTokenAddress | - // | | 0x080 | | 5. feeRecipientAddress | - // | | 0x0A0 | | 6. makerTokenAmount | - // | | 0x0C0 | | 7. takerTokenAmount | - // | | 0x0E0 | | 8. makerFeeAmount | - // | | 0x100 | | 9. takerFeeAmount | - // | | 0x120 | | 10. expirationTimeSeconds | - // | | 0x140 | | 11. salt | - // | | 0x160 | | 12. Offset to makerAssetProxyMetadata (*) | - // | | 0x180 | | 13. Offset to takerAssetProxyMetadata (*) | - // | | 0x1A0 | 32 | makerAssetProxyMetadata Length | - // | | 0x1C0 | ** | makerAssetProxyMetadata Contents | - // | | 0x1E0 | 32 | takerAssetProxyMetadata Length | - // | | 0x200 | ** | takerAssetProxyMetadata Contents | - // | | 0x220 | 32 | signature Length | - // | | 0x240 | ** | signature Contents | + // | | 0x040 | | 3. feeRecipientAddress | + // | | 0x060 | | 4. makerTokenAmount | + // | | 0x080 | | 5. takerTokenAmount | + // | | 0x0A0 | | 6. makerFeeAmount | + // | | 0x0C0 | | 7. takerFeeAmount | + // | | 0x0E0 | | 8. expirationTimeSeconds | + // | | 0x100 | | 9. salt | + // | | 0x120 | | 10. Offset to makerAssetProxyMetadata (*) | + // | | 0x140 | | 11. Offset to takerAssetProxyMetadata (*) | + // | | 0x160 | 32 | makerAssetProxyMetadata Length | + // | | 0x180 | ** | makerAssetProxyMetadata Contents | + // | | 0x1A0 | 32 | takerAssetProxyMetadata Length | + // | | 0x1C0 | ** | takerAssetProxyMetadata Contents | + // | | 0x1E0 | 32 | signature Length | + // | | 0x200 | ** | signature Contents | // * Offsets are calculated from the beginning of the current area: Header, Params, Data: // An offset stored in the Params area is calculated from the beginning of the Params section. @@ -149,22 +149,20 @@ contract MixinWrapperFunctions is // the stores sequentially. mstore(dataAreaEnd, mload(sourceOffset)) // makerAddress mstore(add(dataAreaEnd, 0x20), mload(add(sourceOffset, 0x20))) // takerAddress - mstore(add(dataAreaEnd, 0x40), mload(add(sourceOffset, 0x40))) // makerTokenAddress - mstore(add(dataAreaEnd, 0x60), mload(add(sourceOffset, 0x60))) // takerTokenAddress - mstore(add(dataAreaEnd, 0x80), mload(add(sourceOffset, 0x80))) // feeRecipientAddress - mstore(add(dataAreaEnd, 0xA0), mload(add(sourceOffset, 0xA0))) // makerTokenAmount - mstore(add(dataAreaEnd, 0xC0), mload(add(sourceOffset, 0xC0))) // takerTokenAmount - mstore(add(dataAreaEnd, 0xE0), mload(add(sourceOffset, 0xE0))) // makerFeeAmount - mstore(add(dataAreaEnd, 0x100), mload(add(sourceOffset, 0x100))) // takerFeeAmount - mstore(add(dataAreaEnd, 0x120), mload(add(sourceOffset, 0x120))) // expirationTimeSeconds - mstore(add(dataAreaEnd, 0x140), mload(add(sourceOffset, 0x140))) // salt - mstore(add(dataAreaEnd, 0x160), mload(add(sourceOffset, 0x160))) // Offset to makerAssetProxyMetadata - mstore(add(dataAreaEnd, 0x180), mload(add(sourceOffset, 0x180))) // Offset to takerAssetProxyMetadata - dataAreaEnd := add(dataAreaEnd, 0x1A0) - sourceOffset := add(sourceOffset, 0x1A0) + mstore(add(dataAreaEnd, 0x40), mload(add(sourceOffset, 0x40))) // feeRecipientAddress + mstore(add(dataAreaEnd, 0x60), mload(add(sourceOffset, 0x60))) // makerTokenAmount + mstore(add(dataAreaEnd, 0x80), mload(add(sourceOffset, 0x80))) // takerTokenAmount + mstore(add(dataAreaEnd, 0xA0), mload(add(sourceOffset, 0xA0))) // makerFeeAmount + mstore(add(dataAreaEnd, 0xC0), mload(add(sourceOffset, 0xC0))) // takerFeeAmount + mstore(add(dataAreaEnd, 0xE0), mload(add(sourceOffset, 0xE0))) // expirationTimeSeconds + mstore(add(dataAreaEnd, 0x100), mload(add(sourceOffset, 0x100))) // salt + mstore(add(dataAreaEnd, 0x120), mload(add(sourceOffset, 0x120))) // Offset to makerAssetProxyMetadata + mstore(add(dataAreaEnd, 0x140), mload(add(sourceOffset, 0x140))) // Offset to takerAssetProxyMetadata + dataAreaEnd := add(dataAreaEnd, 0x160) + sourceOffset := add(sourceOffset, 0x160) // Write offset to <order.makerAssetProxyMetadata> - mstore(add(dataAreaStart, mul(11, 0x20)), sub(dataAreaEnd, dataAreaStart)) + mstore(add(dataAreaStart, mul(9, 0x20)), sub(dataAreaEnd, dataAreaStart)) // Calculate length of <order.makerAssetProxyMetadata> arrayLenBytes := mload(sourceOffset) @@ -183,7 +181,7 @@ contract MixinWrapperFunctions is } // Write offset to <order.takerAssetProxyMetadata> - mstore(add(dataAreaStart, mul(12, 0x20)), sub(dataAreaEnd, dataAreaStart)) + mstore(add(dataAreaStart, mul(10, 0x20)), sub(dataAreaEnd, dataAreaStart)) // Calculate length of <order.takerAssetProxyMetadata> arrayLenBytes := mload(sourceOffset) @@ -325,7 +323,7 @@ contract MixinWrapperFunctions is for (uint256 i = 0; i < orders.length; i++) { // Token being sold by taker must be the same for each order - require(orders[i].takerTokenAddress == orders[0].takerTokenAddress); + require(areBytesEqual(orders[i].takerAssetData, orders[0].takerAssetData)); // Calculate the remaining amount of takerToken to sell uint256 remainingTakerTokenFillAmount = safeSub(takerTokenFillAmount, totalFillResults.takerTokenFilledAmount); @@ -364,7 +362,7 @@ contract MixinWrapperFunctions is for (uint256 i = 0; i < orders.length; i++) { // Token being sold by taker must be the same for each order - require(orders[i].takerTokenAddress == orders[0].takerTokenAddress); + require(areBytesEqual(orders[i].takerAssetData, orders[0].takerAssetData)); // Calculate the remaining amount of takerToken to sell uint256 remainingTakerTokenFillAmount = safeSub(takerTokenFillAmount, totalFillResults.takerTokenFilledAmount); @@ -402,7 +400,7 @@ contract MixinWrapperFunctions is for (uint256 i = 0; i < orders.length; i++) { // Token being bought by taker must be the same for each order - require(orders[i].makerTokenAddress == orders[0].makerTokenAddress); + require(areBytesEqual(orders[i].makerAssetData, orders[0].makerAssetData)); // Calculate the remaining amount of makerToken to buy uint256 remainingMakerTokenFillAmount = safeSub(makerTokenFillAmount, totalFillResults.makerTokenFilledAmount); @@ -449,7 +447,7 @@ contract MixinWrapperFunctions is for (uint256 i = 0; i < orders.length; i++) { // Token being bought by taker must be the same for each order - require(orders[i].makerTokenAddress == orders[0].makerTokenAddress); + require(areBytesEqual(orders[i].makerAssetData, orders[0].makerAssetData)); // Calculate the remaining amount of makerToken to buy uint256 remainingMakerTokenFillAmount = safeSub(makerTokenFillAmount, totalFillResults.makerTokenFilledAmount); diff --git a/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol b/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol index ed65463db..106536572 100644 --- a/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol +++ b/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol @@ -20,6 +20,37 @@ pragma solidity ^0.4.21; contract LibBytes { + /// @dev Compares two byte arrays. + /// @param lhs First byte array to compare. + /// @param rhs Second byte array. + /// @return True if arrays are the same. + function areBytesEqual(bytes memory lhs, bytes memory rhs) + public + returns (bool equal) + { + assembly { + // Get the number of words occupied by <lhs> + let lenFullWords := div(add(mload(lhs), 0x1F), 0x20) + + // Add 1 to the number of words, to account for the length field + lenFullWords := add(lenFullWords, 0x1) + + // Verify equality word-by-word. + // Terminates early if there is a mismatch. + for {let i := 0} lt(i, lenFullWords) {i := add(i, 1)} { + let lhsWord := mload(add(lhs, mul(i, 0x20))) + let rhsWord := mload(add(rhs, mul(i, 0x20))) + equal := eq(lhsWord, rhsWord) + if eq(equal, 0) { + // Break + i := lenFullWords + } + } + } + + return equal; + } + /// @dev Reads an address from a position in a byte array. /// @param b Byte array containing an address. /// @param index Index in byte array of address. diff --git a/packages/contracts/src/utils/order_utils.ts b/packages/contracts/src/utils/order_utils.ts index 052ae89d6..18892b4d4 100644 --- a/packages/contracts/src/utils/order_utils.ts +++ b/packages/contracts/src/utils/order_utils.ts @@ -26,8 +26,6 @@ export const orderUtils = { const orderStruct = { makerAddress: signedOrder.makerAddress, takerAddress: signedOrder.takerAddress, - makerTokenAddress: signedOrder.makerTokenAddress, - takerTokenAddress: signedOrder.takerTokenAddress, feeRecipientAddress: signedOrder.feeRecipientAddress, makerTokenAmount: signedOrder.makerTokenAmount, takerTokenAmount: signedOrder.takerTokenAmount, @@ -45,8 +43,6 @@ export const orderUtils = { 'address exchangeAddress', 'address makerAddress', 'address takerAddress', - 'address makerTokenAddress', - 'address takerTokenAddress', 'address feeRecipientAddress', 'uint256 makerTokenAmount', 'uint256 takerTokenAmount', @@ -61,8 +57,6 @@ export const orderUtils = { order.exchangeAddress, order.makerAddress, order.takerAddress, - order.makerTokenAddress, - order.takerTokenAddress, order.feeRecipientAddress, order.makerTokenAmount, order.takerTokenAmount, diff --git a/packages/contracts/src/utils/types.ts b/packages/contracts/src/utils/types.ts index f51dd5a1d..d692bed61 100644 --- a/packages/contracts/src/utils/types.ts +++ b/packages/contracts/src/utils/types.ts @@ -139,8 +139,6 @@ export interface SignedOrder extends UnsignedOrder { export interface OrderStruct { makerAddress: string; takerAddress: string; - makerTokenAddress: string; - takerTokenAddress: string; feeRecipientAddress: string; makerTokenAmount: BigNumber; takerTokenAmount: BigNumber; |