diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-03-06 03:35:03 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2018-04-21 04:56:16 +0800 |
commit | 795a357595b94006a2f1fd6313bdf02103f1b6f5 (patch) | |
tree | 10877e72bcbbbf9b9bb35f8c2d6967ded654e0ab /packages/contracts | |
parent | 5737365b2d50c2aa4fe6e83a54eb1c37787bb8d4 (diff) | |
download | dexon-sol-tools-795a357595b94006a2f1fd6313bdf02103f1b6f5.tar dexon-sol-tools-795a357595b94006a2f1fd6313bdf02103f1b6f5.tar.gz dexon-sol-tools-795a357595b94006a2f1fd6313bdf02103f1b6f5.tar.bz2 dexon-sol-tools-795a357595b94006a2f1fd6313bdf02103f1b6f5.tar.lz dexon-sol-tools-795a357595b94006a2f1fd6313bdf02103f1b6f5.tar.xz dexon-sol-tools-795a357595b94006a2f1fd6313bdf02103f1b6f5.tar.zst dexon-sol-tools-795a357595b94006a2f1fd6313bdf02103f1b6f5.zip |
Fix compile errors
Diffstat (limited to 'packages/contracts')
11 files changed, 54 insertions, 30 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/IExchange.sol b/packages/contracts/src/contracts/current/protocol/Exchange/IExchange.sol index 66c49c84f..5e90f9677 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/IExchange.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/IExchange.sol @@ -1,4 +1,5 @@ pragma solidity ^0.4.19; +pragma experimental ABIEncoderV2; contract IExchange { diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/ISigner.sol b/packages/contracts/src/contracts/current/protocol/Exchange/ISigner.sol index 7f8284c14..75c40f4dc 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/ISigner.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/ISigner.sol @@ -17,6 +17,7 @@ */ pragma solidity ^0.4.19; +pragma experimental ABIEncoderV2; contract ISigner { diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/LibErrors.sol b/packages/contracts/src/contracts/current/protocol/Exchange/LibErrors.sol index 380400b27..fbdc9ee5a 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/LibErrors.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/LibErrors.sol @@ -17,6 +17,7 @@ */ pragma solidity ^0.4.19; +pragma experimental ABIEncoderV2; contract LibErrors { diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/LibPartialAmount.sol b/packages/contracts/src/contracts/current/protocol/Exchange/LibPartialAmount.sol index cf4a65082..dc6e9ed4f 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/LibPartialAmount.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/LibPartialAmount.sol @@ -17,8 +17,9 @@ */ pragma solidity ^0.4.19; +pragma experimental ABIEncoderV2; -import { SafeMath } from "../../utils/SafeMath/SafeMath.sol"; +import "../../utils/SafeMath/SafeMath.sol"; contract LibPartialAmount is SafeMath { diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol index 9700c4c7a..8315634ab 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol @@ -71,14 +71,13 @@ contract MixinExchangeCore is */ /// @dev Fills the input order. - /// @param orderAddresses Array of order's maker, taker, makerToken, takerToken, and feeRecipient. - /// @param orderValues Array of order's makerTokenAmount, takerTokenAmount, makerFee, takerFee, expirationTimestampInSec, and salt. + /// @param order Order struct containing order specifications. /// @param takerTokenFillAmount Desired amount of takerToken to fill. /// @param signature Proof of signing order by maker. /// @return Total amount of takerToken filled in trade. function fillOrder( Order order, - uint takerTokenFillAmount, + uint256 takerTokenFillAmount, bytes signature) public returns (uint256 takerTokenFilledAmount) @@ -144,8 +143,7 @@ contract MixinExchangeCore is } /// @dev Cancels the input order. - /// @param orderAddresses Array of order's maker, taker, makerToken, takerToken, and feeRecipient. - /// @param orderValues Array of order's makerTokenAmount, takerTokenAmount, makerFee, takerFee, expirationTimestampInSec, and salt. + /// @param order Order struct containing order specifications. /// @param takerTokenCancelAmount Desired amount of takerToken to cancel in order. /// @return Amount of takerToken cancelled. function cancelOrder( diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlementProxy.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlementProxy.sol index 83614ec8f..c75d3405a 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlementProxy.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlementProxy.sol @@ -17,6 +17,7 @@ */ pragma solidity ^0.4.19; +pragma experimental ABIEncoderV2; import "./mixins/MSettlement.sol"; import "../TokenTransferProxy/ITokenTransferProxy.sol"; diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol index d9d7be7f2..16714bb3b 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol @@ -17,6 +17,7 @@ */ pragma solidity ^0.4.19; +pragma experimental ABIEncoderV2; import "./mixins/MSignatureValidator.sol"; import "./ISigner.sol"; diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinWrapperFunctions.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinWrapperFunctions.sol index 512f52df6..b8fa4c8bc 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinWrapperFunctions.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinWrapperFunctions.sol @@ -27,7 +27,7 @@ contract MixinWrapperFunctions is MExchangeCore, SafeMath { - /// @param orders Array of orders. + /// @param order Order struct containing order specifications. /// @param takerTokenFillAmount Desired amount of takerToken to fill. /// @param signature Maker's signature of the order. function fillOrKillOrder( @@ -44,7 +44,7 @@ contract MixinWrapperFunctions is } /// @dev Fills an order with specified parameters and ECDSA signature. Returns false if the transaction would otherwise revert. - /// @param orders Array of orders. + /// @param order Order struct containing order specifications. /// @param takerTokenFillAmount Desired amount of takerToken to fill. /// @param signature Maker's signature of the order. /// @return Success if the transaction did not revert. @@ -54,7 +54,7 @@ contract MixinWrapperFunctions is uint256 takerTokenFillAmount, bytes signature) public - returns (bool success, uint256 takerTokenFilledAmount) + returns (uint256 takerTokenFilledAmount) { // We need to call MExchangeCore.fillOrder using a delegatecall in // assembly so that we can intercept a call that throws. For this, we @@ -73,14 +73,14 @@ contract MixinWrapperFunctions is // // (1): len(signature) // (2): 486 + len(signature) - // (3): (32 - len(signature)) mod 32 - // (4): 486 + len(signature) + (32 - len(signature)) mod 32 + // (3): 32 - (len(signature) mod 32) + // (4): 486 + len(signature) + 32 - (len(signature) mod 32) // // [1]: https://solidity.readthedocs.io/en/develop/abi-spec.html // Allocate memory for input uint256 signatureLength = signature.length; - uint256 paddingLength = (32 - signatureLength) % 32 + uint256 paddingLength = 32 - (signatureLength % 32); uint256 inputSize = 486 + signatureLength + paddingLength; bytes memory input = new bytes(inputSize); @@ -98,16 +98,16 @@ contract MixinWrapperFunctions is // We use assembly to write four bytes at a time (actually 32, // but we are only overwriting uninitialized data). A `bytes4` // is stored by value as 256-bit and right-padded with zeros. - bytes4 FILL_ORDER_FUNCTION_SIGNATURE = bytes4(keccak256("fillOrder(address[5],uint256[6],uint256,uint8,bytes32,bytes32)")); + bytes4 FILL_ORDER_FUNCTION_SIGNATURE = this.fillOrder.selector; assembly { mstore(start, FILL_ORDER_FUNCTION_SIGNATURE) } // Use identity function precompile to cheaply copy Order struct over - // We need asssembly to access the precompile + // We need assembly to access the precompile // Note that sizeof(Order) == 12 * 32 == 384 assembly { - delegatecall( + let success := delegatecall( 51, // precompile takes 15 + 3 * numWords 0x4, // precompile for identity function order, // pointer to start of input @@ -115,8 +115,16 @@ contract MixinWrapperFunctions is add(start, 4), // store output at offset 4 384 // output is 384 bytes ) + if iszero(success) { + revert(0, 0) + } } + // Write takerTokenFillAmount + assembly { + mstore(add(start, 388), takerTokenFillAmount) + } + // Write offset to signature and len(signature) // It is done in assembly so we can write 32 bytes at a time. In // solidity we would have to copy one byte at a time. @@ -127,14 +135,17 @@ contract MixinWrapperFunctions is // Copy over signature length contents assembly { let size := add(signatureLength, 32) - delegatecall( + let success := delegatecall( gas, // precompile takes 15 + 3 * numWords 0x4, // precompile for identity function signature, // pointer to start of input - size, // length of input + size, // input is (signatureLength + 32) bytes add(start, 452), // store output at offset 4 - size // output is 384 bytes + size // output is (signatureLength + 32) bytes ) + if iszero(success) { + revert(0, 0) + } } // Write padding @@ -144,7 +155,7 @@ contract MixinWrapperFunctions is // Call the function assembly { - success := delegatecall( + let success := delegatecall( gas, // If fillOrder `revert()`s, we recover unused gas address, // call this contract start, // pointer to start of input @@ -152,11 +163,17 @@ contract MixinWrapperFunctions is start, // store output over input 32 // output is 32 bytes ) - - // Read output value (uint256 takerTokenFilledAmount) - takerTokenFilledAmount := mload(start) + switch success + case 0 { + // No amount filled if delegatecall is unsuccessful + takerTokenFilledAmount := 0 + } + case 1 { + // Read output value (uint256 takerTokenFilledAmount) + takerTokenFilledAmount := mload(start) + } } - return (success, takerTokenFilledAmount); + return takerTokenFilledAmount; } /// @dev Synchronously executes multiple calls of fillOrder in a single transaction. @@ -199,7 +216,7 @@ contract MixinWrapperFunctions is /// @dev Fills an order with specified parameters and ECDSA signature. Returns false if the transaction would otherwise revert. /// @param orders Array of orders. - /// @param takerTokenFillAmount Desired amount of takerToken to fill. + /// @param takerTokenFillAmounts Array of desired amounts of takerToken to fill in orders. /// @param signatures Maker's signatures of the orders. function batchFillOrdersNoThrow( Order[] orders, @@ -218,7 +235,7 @@ contract MixinWrapperFunctions is /// @dev Synchronously executes multiple fill orders in a single transaction until total takerTokenFillAmount filled. /// @param orders Array of orders. - /// @param takerTokenFillAmount Desired total amount of takerToken to fill in orders. + /// @param takerTokenFillAmount Desired amount of takerToken to fill. /// @param signatures Maker's signatures of the orders. /// @return Total amount of takerTokenFillAmount filled in orders. function marketFillOrders( @@ -254,12 +271,11 @@ contract MixinWrapperFunctions is { for (uint256 i = 0; i < orders.length; i++) { require(orders[i].takerToken == orders[0].takerToken); - var (, takerTokenFilledAmount) = fillOrderNoThrow( + totalTakerTokenFilledAmount = safeAdd(totalTakerTokenFilledAmount, fillOrderNoThrow( orders[i], safeSub(takerTokenFillAmount, totalTakerTokenFilledAmount), signatures[i] - ); - totalTakerTokenFilledAmount = safeAdd(totalTakerTokenFilledAmount, takerTokenFilledAmount); + )); if (totalTakerTokenFilledAmount == takerTokenFillAmount) break; } return totalTakerTokenFilledAmount; @@ -271,7 +287,7 @@ contract MixinWrapperFunctions is function batchCancelOrders( Order[] orders, uint256[] takerTokenCancelAmounts) - external + public { for (uint256 i = 0; i < orders.length; i++) { cancelOrder( diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MExchangeCore.sol b/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MExchangeCore.sol index 395fdfa09..668e62301 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MExchangeCore.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MExchangeCore.sol @@ -19,7 +19,9 @@ pragma solidity ^0.4.19; pragma experimental ABIEncoderV2; -contract MExchangeCore { +import "../LibOrder.sol"; + +contract MExchangeCore is LibOrder { function fillOrder( Order order, diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MSettlement.sol b/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MSettlement.sol index 9f9e0996f..2fe8353d7 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MSettlement.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MSettlement.sol @@ -17,6 +17,7 @@ */ pragma solidity ^0.4.19; +pragma experimental ABIEncoderV2; import "../LibOrder.sol"; diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MSignatureValidator.sol b/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MSignatureValidator.sol index 9dfda297d..d9cdd50b0 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MSignatureValidator.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MSignatureValidator.sol @@ -17,6 +17,7 @@ */ pragma solidity ^0.4.19; +pragma experimental ABIEncoderV2; contract MSignatureValidator { |