aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/contracts')
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol33
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IExchangeCore.sol7
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/libs/LibExchangeErrors.sol4
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/mixins/MExchangeCore.sol2
-rw-r--r--packages/contracts/src/contracts/current/test/ExchangeWrapper/ExchangeWrapper.sol9
-rw-r--r--packages/contracts/test/exchange/core.ts30
-rw-r--r--packages/contracts/test/exchange/transactions.ts10
7 files changed, 49 insertions, 46 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol
index 2ebbfdabf..c406354a7 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol
@@ -45,34 +45,35 @@ contract MixinExchangeCore is
mapping (bytes32 => bool) public cancelled;
// Mapping of makerAddress => senderAddress => lowest salt an order can have in order to be fillable
- // Orders with a salt less than their maker's epoch are considered cancelled
- mapping (address => mapping (address => uint256)) public makerEpoch;
+ // Orders with specified senderAddress and with a salt less than their epoch to are considered cancelled
+ mapping (address => mapping (address => uint256)) public orderEpoch;
////// Core exchange functions //////
- /// @dev Cancels all orders created by sender with a salt less than or equal to the specified salt value.
- /// @param salt Orders created with a salt less or equal to this value will be cancelled.
- function cancelOrdersUpTo(uint256 salt)
+ /// @dev Cancels all orders created by makerAddress with a salt less than or equal to the targetOrderEpoch
+ /// and senderAddress equal to msg.sender (or null address if msg.sender == makerAddress).
+ /// @param targetOrderEpoch Orders created with a salt less or equal to this value will be cancelled.
+ function cancelOrdersUpTo(uint256 targetOrderEpoch)
external
{
address makerAddress = getCurrentContextAddress();
- // If this function is called via `executeTransaction`, we only update the makerEpoch for the makerAddress/msg.sender combination.
+ // If this function is called via `executeTransaction`, we only update the orderEpoch for the makerAddress/msg.sender combination.
// This allows external filter contracts to add rules to how orders are cancelled via this function.
address senderAddress = makerAddress == msg.sender ? address(0) : msg.sender;
- // makerEpoch is initialized to 0, so to cancelUpTo we need salt + 1
- uint256 newMakerEpoch = salt + 1;
- uint256 oldMakerEpoch = makerEpoch[makerAddress][senderAddress];
+ // orderEpoch is initialized to 0, so to cancelUpTo we need salt + 1
+ uint256 newOrderEpoch = targetOrderEpoch + 1;
+ uint256 oldOrderEpoch = orderEpoch[makerAddress][senderAddress];
- // Ensure makerEpoch is monotonically increasing
+ // Ensure orderEpoch is monotonically increasing
require(
- newMakerEpoch > oldMakerEpoch,
- INVALID_NEW_MAKER_EPOCH
+ newOrderEpoch > oldOrderEpoch,
+ INVALID_NEW_ORDER_EPOCH
);
- // Update makerEpoch
- makerEpoch[makerAddress][senderAddress] = newMakerEpoch;
- emit CancelUpTo(makerAddress, senderAddress, newMakerEpoch);
+ // Update orderEpoch
+ orderEpoch[makerAddress][senderAddress] = newOrderEpoch;
+ emit CancelUpTo(makerAddress, senderAddress, newOrderEpoch);
}
/// @dev Fills the input order.
@@ -183,7 +184,7 @@ contract MixinExchangeCore is
orderInfo.orderStatus = uint8(OrderStatus.CANCELLED);
return orderInfo;
}
- if (makerEpoch[order.makerAddress][order.senderAddress] > order.salt) {
+ if (orderEpoch[order.makerAddress][order.senderAddress] > order.salt) {
orderInfo.orderStatus = uint8(OrderStatus.CANCELLED);
return orderInfo;
}
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IExchangeCore.sol b/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IExchangeCore.sol
index 7ca2dd052..98222f33f 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IExchangeCore.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IExchangeCore.sol
@@ -24,9 +24,10 @@ import "../libs/LibFillResults.sol";
contract IExchangeCore {
- /// @dev Cancels all orders reated by sender with a salt less than or equal to the specified salt value.
- /// @param salt Orders created with a salt less or equal to this value will be cancelled.
- function cancelOrdersUpTo(uint256 salt)
+ /// @dev Cancels all orders created by makerAddress with a salt less than or equal to the targetOrderEpoch
+ /// and senderAddress equal to msg.sender (or null address if msg.sender == makerAddress).
+ /// @param targetOrderEpoch Orders created with a salt less or equal to this value will be cancelled.
+ function cancelOrdersUpTo(uint256 targetOrderEpoch)
external;
/// @dev Fills the input order.
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibExchangeErrors.sol b/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibExchangeErrors.sol
index 48dd0f8be..adf27bec3 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibExchangeErrors.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibExchangeErrors.sol
@@ -36,7 +36,7 @@ contract LibExchangeErrors {
string constant SIGNATURE_UNSUPPORTED = "SIGNATURE_UNSUPPORTED"; // Signature type unsupported.
/// cancelOrdersUptTo errors ///
- string constant INVALID_NEW_MAKER_EPOCH = "INVALID_NEW_MAKER_EPOCH"; // Specified salt must be greater than or equal to existing makerEpoch.
+ string constant INVALID_NEW_ORDER_EPOCH = "INVALID_NEW_ORDER_EPOCH"; // Specified salt must be greater than or equal to existing orderEpoch.
/// fillOrKillOrder errors ///
string constant COMPLETE_FILL_FAILED = "COMPLETE_FILL_FAILED"; // Desired takerAssetFillAmount could not be completely filled.
@@ -55,7 +55,7 @@ contract LibExchangeErrors {
string constant ASSET_PROXY_ID_MISMATCH = "ASSET_PROXY_ID_MISMATCH"; // newAssetProxyId does not match given assetProxyId.
/// Length validation errors ///
- string constant LENGTH_GREATER_THAN_0_REQUIRED = "LENGTH_GREATER_THAN_0_REQUIRED"; // Byte array must have a length greater than 0.
+ string constant LENGTH_GREATER_THAN_0_REQUIRED = "LENGTH_GREATER_THAN_0_REQUIRED"; // Byte array must have a length greater than 0.
string constant LENGTH_0_REQUIRED = "LENGTH_1_REQUIRED"; // Byte array must have a length of 1.
string constant LENGTH_65_REQUIRED = "LENGTH_66_REQUIRED"; // Byte array must have a length of 66.
}
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 b4552b7bf..fb345294c 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MExchangeCore.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MExchangeCore.sol
@@ -53,7 +53,7 @@ contract MExchangeCore is
event CancelUpTo(
address indexed makerAddress,
address indexed senderAddress,
- uint256 makerEpoch
+ uint256 orderEpoch
);
/// @dev Updates state with results of a fill order.
diff --git a/packages/contracts/src/contracts/current/test/ExchangeWrapper/ExchangeWrapper.sol b/packages/contracts/src/contracts/current/test/ExchangeWrapper/ExchangeWrapper.sol
index 629a846d9..5baaf6e5a 100644
--- a/packages/contracts/src/contracts/current/test/ExchangeWrapper/ExchangeWrapper.sol
+++ b/packages/contracts/src/contracts/current/test/ExchangeWrapper/ExchangeWrapper.sol
@@ -67,12 +67,13 @@ contract ExchangeWrapper {
);
}
- /// @dev Cancels all orders created by sender with a salt less than or equal to the specified salt value.
- /// @param cancelSalt Orders created with a salt less or equal to this value will be cancelled.
+ /// @dev Cancels all orders created by sender with a salt less than or equal to the targetOrderEpoch
+ /// and senderAddress equal to this contract.
+ /// @param targetOrderEpoch Orders created with a salt less or equal to this value will be cancelled.
/// @param salt Arbitrary value to gaurantee uniqueness of 0x transaction hash.
/// @param makerSignature Proof that maker wishes to call this function with given params.
function cancelOrdersUpTo(
- uint256 cancelSalt,
+ uint256 targetOrderEpoch,
uint256 salt,
bytes makerSignature
)
@@ -83,7 +84,7 @@ contract ExchangeWrapper {
// Encode arguments into byte array.
bytes memory data = abi.encodeWithSelector(
EXCHANGE.cancelOrdersUpTo.selector,
- cancelSalt
+ targetOrderEpoch
);
// Call `cancelOrdersUpTo` via `executeTransaction`.
diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts
index 63c2fa6c0..ea37a1e99 100644
--- a/packages/contracts/test/exchange/core.ts
+++ b/packages/contracts/test/exchange/core.ts
@@ -620,30 +620,30 @@ describe('Exchange core', () => {
});
describe('cancelOrdersUpTo', () => {
- it('should fail to set makerEpoch less than current makerEpoch', async () => {
- const makerEpoch = new BigNumber(1);
- await exchangeWrapper.cancelOrdersUpToAsync(makerEpoch, makerAddress);
- const lesserMakerEpoch = new BigNumber(0);
+ it('should fail to set orderEpoch less than current orderEpoch', async () => {
+ const orderEpoch = new BigNumber(1);
+ await exchangeWrapper.cancelOrdersUpToAsync(orderEpoch, makerAddress);
+ const lesserOrderEpoch = new BigNumber(0);
return expectRevertOrAlwaysFailingTransactionAsync(
- exchangeWrapper.cancelOrdersUpToAsync(lesserMakerEpoch, makerAddress),
+ exchangeWrapper.cancelOrdersUpToAsync(lesserOrderEpoch, makerAddress),
);
});
- it('should fail to set makerEpoch equal to existing makerEpoch', async () => {
- const makerEpoch = new BigNumber(1);
- await exchangeWrapper.cancelOrdersUpToAsync(makerEpoch, makerAddress);
+ it('should fail to set orderEpoch equal to existing orderEpoch', async () => {
+ const orderEpoch = new BigNumber(1);
+ await exchangeWrapper.cancelOrdersUpToAsync(orderEpoch, makerAddress);
return expectRevertOrAlwaysFailingTransactionAsync(
- exchangeWrapper.cancelOrdersUpToAsync(makerEpoch, makerAddress),
+ exchangeWrapper.cancelOrdersUpToAsync(orderEpoch, makerAddress),
);
});
- it('should cancel only orders with a makerEpoch less than existing makerEpoch', async () => {
- // Cancel all transactions with a makerEpoch less than 1
- const makerEpoch = new BigNumber(1);
- await exchangeWrapper.cancelOrdersUpToAsync(makerEpoch, makerAddress);
+ it('should cancel only orders with a orderEpoch less than existing orderEpoch', async () => {
+ // Cancel all transactions with a orderEpoch less than 1
+ const orderEpoch = new BigNumber(1);
+ await exchangeWrapper.cancelOrdersUpToAsync(orderEpoch, makerAddress);
- // Create 3 orders with makerEpoch values: 0,1,2,3
- // Since we cancelled with makerEpoch=1, orders with makerEpoch<=1 will not be processed
+ // Create 3 orders with orderEpoch values: 0,1,2,3
+ // Since we cancelled with orderEpoch=1, orders with orderEpoch<=1 will not be processed
erc20Balances = await erc20Wrapper.getBalancesAsync();
const signedOrders = [
orderFactory.newSignedOrder({
diff --git a/packages/contracts/test/exchange/transactions.ts b/packages/contracts/test/exchange/transactions.ts
index 088b537cc..9a625880c 100644
--- a/packages/contracts/test/exchange/transactions.ts
+++ b/packages/contracts/test/exchange/transactions.ts
@@ -218,11 +218,11 @@ describe('Exchange transactions', () => {
senderAddress: exchangeWrapperContract.address,
salt: orderSalt,
});
- const cancelSalt = orderSalt.add(1);
- const cancelData = exchange.cancelOrdersUpTo.getABIEncodedTransactionData(cancelSalt);
+ const targetOrderEpoch = orderSalt.add(1);
+ const cancelData = exchange.cancelOrdersUpTo.getABIEncodedTransactionData(targetOrderEpoch);
const signedCancelTx = makerTransactionFactory.newSignedTransaction(cancelData);
await exchangeWrapperContract.cancelOrdersUpTo.sendTransactionAsync(
- cancelSalt,
+ targetOrderEpoch,
signedCancelTx.salt,
signedCancelTx.signature,
{
@@ -256,8 +256,8 @@ describe('Exchange transactions', () => {
senderAddress: exchangeWrapperContract.address,
salt: orderSalt,
});
- const cancelSalt = orderSalt.add(1);
- await exchangeWrapper.cancelOrdersUpToAsync(cancelSalt, makerAddress);
+ const targetOrderEpoch = orderSalt.add(1);
+ await exchangeWrapper.cancelOrdersUpToAsync(targetOrderEpoch, makerAddress);
erc20Balances = await erc20Wrapper.getBalancesAsync();
const takerAssetFillAmount = signedOrder.takerAssetAmount;