aboutsummaryrefslogtreecommitdiffstats
path: root/contracts
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-12-14 07:58:58 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-12-19 05:36:05 +0800
commitb524ac7af2ebf0f00c50ae3c1ad7cd85ab8b6462 (patch)
tree5ba666bd7c9de94e32dae9f0ce0f83ccf527a11a /contracts
parentdea6f35b0471913551d58a08f547974701fc0057 (diff)
downloaddexon-sol-tools-b524ac7af2ebf0f00c50ae3c1ad7cd85ab8b6462.tar
dexon-sol-tools-b524ac7af2ebf0f00c50ae3c1ad7cd85ab8b6462.tar.gz
dexon-sol-tools-b524ac7af2ebf0f00c50ae3c1ad7cd85ab8b6462.tar.bz2
dexon-sol-tools-b524ac7af2ebf0f00c50ae3c1ad7cd85ab8b6462.tar.lz
dexon-sol-tools-b524ac7af2ebf0f00c50ae3c1ad7cd85ab8b6462.tar.xz
dexon-sol-tools-b524ac7af2ebf0f00c50ae3c1ad7cd85ab8b6462.tar.zst
dexon-sol-tools-b524ac7af2ebf0f00c50ae3c1ad7cd85ab8b6462.zip
Prettier / Linter on contracts + TS
Diffstat (limited to 'contracts')
-rw-r--r--contracts/extensions/contracts/BalanceThresholdFilter/MixinBalanceThresholdFilterCore.sol14
-rw-r--r--contracts/extensions/contracts/BalanceThresholdFilter/MixinExchangeCalldata.sol5
-rw-r--r--contracts/extensions/contracts/BalanceThresholdFilter/interfaces/IBalanceThresholdFilterCore.sol3
-rw-r--r--contracts/extensions/contracts/BalanceThresholdFilter/mixins/MExchangeCalldata.sol3
-rw-r--r--contracts/extensions/test/extensions/balance_threshold_filter.ts109
5 files changed, 44 insertions, 90 deletions
diff --git a/contracts/extensions/contracts/BalanceThresholdFilter/MixinBalanceThresholdFilterCore.sol b/contracts/extensions/contracts/BalanceThresholdFilter/MixinBalanceThresholdFilterCore.sol
index a8947751a..27767ad98 100644
--- a/contracts/extensions/contracts/BalanceThresholdFilter/MixinBalanceThresholdFilterCore.sol
+++ b/contracts/extensions/contracts/BalanceThresholdFilter/MixinBalanceThresholdFilterCore.sol
@@ -68,7 +68,7 @@ contract MixinBalanceThresholdFilterCore is
// Validate account balances
uint256 balanceThreshold = BALANCE_THRESHOLD;
IThresholdAsset thresholdAsset = THRESHOLD_ASSET;
- for(uint256 i = 0; i < addressesToValidate.length; ++i) {
+ for (uint256 i = 0; i < addressesToValidate.length; ++i) {
uint256 addressBalance = thresholdAsset.balanceOf(addressesToValidate[i]);
if (addressBalance < balanceThreshold) {
revert("AT_LEAST_ONE_ADDRESS_DOES_NOT_MEET_BALANCE_THRESHOLD");
@@ -95,8 +95,9 @@ contract MixinBalanceThresholdFilterCore is
returns (address[] memory addressesToValidate)
{
bytes4 exchangeFunctionSelector = bytes4(exchangeCalldataload(0));
- if(
- exchangeFunctionSelector == batchFillOrdersSelector ||
+ // solhint-disable expression-indent
+ if (
+ exchangeFunctionSelector == batchFillOrdersSelector ||
exchangeFunctionSelector == batchFillOrdersNoThrowSelector ||
exchangeFunctionSelector == batchFillOrKillOrdersSelector ||
exchangeFunctionSelector == marketBuyOrdersSelector ||
@@ -106,7 +107,7 @@ contract MixinBalanceThresholdFilterCore is
) {
addressesToValidate = loadMakerAddressesFromOrderArray(0);
addressesToValidate = addressesToValidate.append(signerAddress);
- } else if(
+ } else if (
exchangeFunctionSelector == fillOrderSelector ||
exchangeFunctionSelector == fillOrderNoThrowSelector ||
exchangeFunctionSelector == fillOrKillOrderSelector
@@ -114,18 +115,19 @@ contract MixinBalanceThresholdFilterCore is
address makerAddress = loadMakerAddressFromOrder(0);
addressesToValidate = addressesToValidate.append(makerAddress);
addressesToValidate = addressesToValidate.append(signerAddress);
- } else if(exchangeFunctionSelector == matchOrdersSelector) {
+ } else if (exchangeFunctionSelector == matchOrdersSelector) {
address leftMakerAddress = loadMakerAddressFromOrder(0);
addressesToValidate = addressesToValidate.append(leftMakerAddress);
address rightMakerAddress = loadMakerAddressFromOrder(1);
addressesToValidate = addressesToValidate.append(rightMakerAddress);
addressesToValidate = addressesToValidate.append(signerAddress);
- } else if(
+ } else if (
exchangeFunctionSelector != cancelOrderSelector &&
exchangeFunctionSelector != batchCancelOrdersSelector &&
exchangeFunctionSelector != cancelOrdersUpToSelector
) {
revert("INVALID_OR_BLOCKED_EXCHANGE_SELECTOR");
}
+ // solhint-enable expression-indent
}
}
diff --git a/contracts/extensions/contracts/BalanceThresholdFilter/MixinExchangeCalldata.sol b/contracts/extensions/contracts/BalanceThresholdFilter/MixinExchangeCalldata.sol
index 12f601dea..d49b7123f 100644
--- a/contracts/extensions/contracts/BalanceThresholdFilter/MixinExchangeCalldata.sol
+++ b/contracts/extensions/contracts/BalanceThresholdFilter/MixinExchangeCalldata.sol
@@ -78,8 +78,7 @@ contract MixinExchangeCalldata is
}
/// @dev Extracts the maker addresses from an array of orders stored in the Exchange calldata
- /// (which is embedded in `signedExchangeTransaction`), and records them in
- /// the running list of addresses to validate.
+ /// (which is embedded in `signedExchangeTransaction`).
/// @param orderArrayParamIndex Index of the order array in the Exchange function's signature
/// @return makerAddresses The extracted maker addresses.
function loadMakerAddressesFromOrderArray(uint256 orderArrayParamIndex)
@@ -92,7 +91,7 @@ contract MixinExchangeCalldata is
uint256 orderArrayLengthInBytes = orderArrayLength * 32;
uint256 orderArrayElementPtr = orderArrayPtr + 32;
uint256 orderArrayElementEndPtr = orderArrayElementPtr + orderArrayLengthInBytes;
- for(uint orderPtrOffset = orderArrayElementPtr; orderPtrOffset < orderArrayElementEndPtr; orderPtrOffset += 32) {
+ for (uint orderPtrOffset = orderArrayElementPtr; orderPtrOffset < orderArrayElementEndPtr; orderPtrOffset += 32) {
uint256 orderPtr = uint256(loadExchangeData(orderPtrOffset));
address makerAddress = address(loadExchangeData(orderPtr + orderArrayElementPtr));
makerAddresses = makerAddresses.append(makerAddress);
diff --git a/contracts/extensions/contracts/BalanceThresholdFilter/interfaces/IBalanceThresholdFilterCore.sol b/contracts/extensions/contracts/BalanceThresholdFilter/interfaces/IBalanceThresholdFilterCore.sol
index 37e607be1..3d8e2bbd1 100644
--- a/contracts/extensions/contracts/BalanceThresholdFilter/interfaces/IBalanceThresholdFilterCore.sol
+++ b/contracts/extensions/contracts/BalanceThresholdFilter/interfaces/IBalanceThresholdFilterCore.sol
@@ -20,7 +20,6 @@
pragma solidity 0.4.24;
-
contract IBalanceThresholdFilterCore {
/// @dev Executes an Exchange transaction iff the maker and taker meet
@@ -53,4 +52,4 @@ contract IBalanceThresholdFilterCore {
bytes signature
)
external;
-} \ No newline at end of file
+}
diff --git a/contracts/extensions/contracts/BalanceThresholdFilter/mixins/MExchangeCalldata.sol b/contracts/extensions/contracts/BalanceThresholdFilter/mixins/MExchangeCalldata.sol
index 8e0414c17..bf2940fe1 100644
--- a/contracts/extensions/contracts/BalanceThresholdFilter/mixins/MExchangeCalldata.sol
+++ b/contracts/extensions/contracts/BalanceThresholdFilter/mixins/MExchangeCalldata.sol
@@ -47,8 +47,7 @@ contract MExchangeCalldata {
returns (address makerAddress);
/// @dev Extracts the maker addresses from an array of orders stored in the Exchange calldata
- /// (which is embedded in `signedExchangeTransaction`), and records them in
- /// the running list of addresses to validate.
+ /// (which is embedded in `signedExchangeTransaction`).
/// @param orderArrayParamIndex Index of the order array in the Exchange function's signature
/// @return makerAddresses The extracted maker addresses.
function loadMakerAddressesFromOrderArray(uint256 orderArrayParamIndex)
diff --git a/contracts/extensions/test/extensions/balance_threshold_filter.ts b/contracts/extensions/test/extensions/balance_threshold_filter.ts
index 6350c019f..20397b14f 100644
--- a/contracts/extensions/test/extensions/balance_threshold_filter.ts
+++ b/contracts/extensions/test/extensions/balance_threshold_filter.ts
@@ -5,7 +5,6 @@ import { BigNumber } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import * as chai from 'chai';
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
-import * as ethUtil from 'ethereumjs-util';
import * as _ from 'lodash';
import {
@@ -21,12 +20,9 @@ import {
ContractName,
ERC20BalancesByOwner,
expectTransactionFailedAsync,
- expectTransactionFailedWithoutReasonAsync,
OrderFactory,
OrderStatus,
- orderUtils,
provider,
- SignedTransaction,
TransactionFactory,
txDefaults,
web3Wrapper,
@@ -77,7 +73,6 @@ describe(ContractName.BalanceThresholdFilter, () => {
let defaultOrderParams: Partial<Order>;
let validSignedOrder: SignedOrder;
let validSignedOrder2: SignedOrder;
- let validSignedFillOrderTx: SignedTransaction;
let erc721BalanceThresholdFilterInstance: BalanceThresholdFilterContract;
let erc20BalanceThresholdFilterInstance: BalanceThresholdFilterContract;
@@ -257,10 +252,7 @@ describe(ContractName.BalanceThresholdFilter, () => {
{ takerAssetFillAmount },
);
// Assert validated addresses
- const expectedValidatedAddresseses = [
- validSignedOrder.makerAddress,
- validTakerAddress,
- ];
+ const expectedValidatedAddresseses = [validSignedOrder.makerAddress, validTakerAddress];
await assertValidatedAddressesLog(txReceipt, expectedValidatedAddresseses);
// Check balances
const newBalances = await erc20Wrapper.getBalancesAsync();
@@ -308,7 +300,7 @@ describe(ContractName.BalanceThresholdFilter, () => {
badSelectorHex,
signatureHex,
),
- RevertReason.InvalidOrBlockedExchangeSelector
+ RevertReason.InvalidOrBlockedExchangeSelector,
);
});
it('should revert if senderAddress is not set to the valid forwarding contract', async () => {
@@ -319,12 +311,10 @@ describe(ContractName.BalanceThresholdFilter, () => {
});
// Call valid forwarder
return expectTransactionFailedAsync(
- erc721TakerBalanceThresholdWrapper.fillOrderAsync(
- signedOrderWithBadSenderAddress,
- validTakerAddress,
- { takerAssetFillAmount },
- ),
- RevertReason.FailedExecution
+ erc721TakerBalanceThresholdWrapper.fillOrderAsync(signedOrderWithBadSenderAddress, validTakerAddress, {
+ takerAssetFillAmount,
+ }),
+ RevertReason.FailedExecution,
);
});
});
@@ -339,11 +329,9 @@ describe(ContractName.BalanceThresholdFilter, () => {
// Execute a valid fill
const orders = [validSignedOrder, validSignedOrder2];
const takerAssetFillAmounts = [takerAssetFillAmount, takerAssetFillAmount];
- const txReceipt = await erc721TakerBalanceThresholdWrapper.batchFillOrdersAsync(
- orders,
- validTakerAddress,
- { takerAssetFillAmounts },
- );
+ const txReceipt = await erc721TakerBalanceThresholdWrapper.batchFillOrdersAsync(orders, validTakerAddress, {
+ takerAssetFillAmounts,
+ });
// Assert validated addresses
const expectedValidatedAddresseses = [
validSignedOrder.makerAddress,
@@ -647,10 +635,7 @@ describe(ContractName.BalanceThresholdFilter, () => {
{ takerAssetFillAmount },
);
// Assert validated addresses
- const expectedValidatedAddresseses = [
- validSignedOrder.makerAddress,
- validTakerAddress,
- ];
+ const expectedValidatedAddresseses = [validSignedOrder.makerAddress, validTakerAddress];
await assertValidatedAddressesLog(txReceipt, expectedValidatedAddresseses);
// Check balances
const newBalances = await erc20Wrapper.getBalancesAsync();
@@ -693,11 +678,9 @@ describe(ContractName.BalanceThresholdFilter, () => {
});
// Execute transaction
return expectTransactionFailedAsync(
- erc721TakerBalanceThresholdWrapper.fillOrderAsync(
- signedOrderWithBadMakerAddress,
- validTakerAddress,
- { takerAssetFillAmount },
- ),
+ erc721TakerBalanceThresholdWrapper.fillOrderAsync(signedOrderWithBadMakerAddress, validTakerAddress, {
+ takerAssetFillAmount,
+ }),
RevertReason.AtLeastOneAddressDoesNotMeetBalanceThreshold,
);
});
@@ -724,10 +707,7 @@ describe(ContractName.BalanceThresholdFilter, () => {
{ takerAssetFillAmount },
);
// Assert validated addresses
- const expectedValidatedAddresseses = [
- validSignedOrder.makerAddress,
- validTakerAddress,
- ];
+ const expectedValidatedAddresseses = [validSignedOrder.makerAddress, validTakerAddress];
await assertValidatedAddressesLog(txReceipt, expectedValidatedAddresseses);
// Check balances
const newBalances = await erc20Wrapper.getBalancesAsync();
@@ -780,11 +760,9 @@ describe(ContractName.BalanceThresholdFilter, () => {
});
it('should revert if taker does not meet the balance threshold', async () => {
return expectTransactionFailedAsync(
- erc721NonValidBalanceThresholdWrapper.fillOrderNoThrowAsync(
- validSignedOrder,
- invalidAddress,
- { takerAssetFillAmount },
- ),
+ erc721NonValidBalanceThresholdWrapper.fillOrderNoThrowAsync(validSignedOrder, invalidAddress, {
+ takerAssetFillAmount,
+ }),
RevertReason.AtLeastOneAddressDoesNotMeetBalanceThreshold,
);
});
@@ -804,10 +782,7 @@ describe(ContractName.BalanceThresholdFilter, () => {
{ takerAssetFillAmount: takerAssetFillAmount_ },
);
// Assert validated addresses
- const expectedValidatedAddresseses = [
- validSignedOrder.makerAddress,
- validTakerAddress,
- ];
+ const expectedValidatedAddresseses = [validSignedOrder.makerAddress, validTakerAddress];
await assertValidatedAddressesLog(txReceipt, expectedValidatedAddresseses);
// Check balances
const newBalances = await erc20Wrapper.getBalancesAsync();
@@ -860,11 +835,9 @@ describe(ContractName.BalanceThresholdFilter, () => {
});
it('should revert if taker does not meet the balance threshold', async () => {
return expectTransactionFailedAsync(
- erc721NonValidBalanceThresholdWrapper.fillOrKillOrderAsync(
- validSignedOrder,
- invalidAddress,
- { takerAssetFillAmount },
- ),
+ erc721NonValidBalanceThresholdWrapper.fillOrKillOrderAsync(validSignedOrder, invalidAddress, {
+ takerAssetFillAmount,
+ }),
RevertReason.AtLeastOneAddressDoesNotMeetBalanceThreshold,
);
});
@@ -916,14 +889,10 @@ describe(ContractName.BalanceThresholdFilter, () => {
const cumulativeMakerAssetFillAmount = validSignedOrder.makerAssetAmount.plus(makerAssetFillAmount2);
// Maker #1
expect(newBalances[validMakerAddress][defaultMakerAssetAddress]).to.be.bignumber.equal(
- erc20Balances[validMakerAddress][defaultMakerAssetAddress].minus(
- validSignedOrder.makerAssetAmount,
- ),
+ erc20Balances[validMakerAddress][defaultMakerAssetAddress].minus(validSignedOrder.makerAssetAmount),
);
expect(newBalances[validMakerAddress][defaultTakerAssetAddress]).to.be.bignumber.equal(
- erc20Balances[validMakerAddress][defaultTakerAssetAddress].add(
- validSignedOrder.takerAssetAmount,
- ),
+ erc20Balances[validMakerAddress][defaultTakerAssetAddress].add(validSignedOrder.takerAssetAmount),
);
expect(newBalances[validMakerAddress][zrxToken.address]).to.be.bignumber.equal(
erc20Balances[validMakerAddress][zrxToken.address].minus(validSignedOrder.makerFee),
@@ -1018,14 +987,10 @@ describe(ContractName.BalanceThresholdFilter, () => {
const cumulativeMakerAssetFillAmount = validSignedOrder.makerAssetAmount.plus(makerAssetFillAmount2);
// Maker #1
expect(newBalances[validMakerAddress][defaultMakerAssetAddress]).to.be.bignumber.equal(
- erc20Balances[validMakerAddress][defaultMakerAssetAddress].minus(
- validSignedOrder.makerAssetAmount,
- ),
+ erc20Balances[validMakerAddress][defaultMakerAssetAddress].minus(validSignedOrder.makerAssetAmount),
);
expect(newBalances[validMakerAddress][defaultTakerAssetAddress]).to.be.bignumber.equal(
- erc20Balances[validMakerAddress][defaultTakerAssetAddress].add(
- validSignedOrder.takerAssetAmount,
- ),
+ erc20Balances[validMakerAddress][defaultTakerAssetAddress].add(validSignedOrder.takerAssetAmount),
);
expect(newBalances[validMakerAddress][zrxToken.address]).to.be.bignumber.equal(
erc20Balances[validMakerAddress][zrxToken.address].minus(validSignedOrder.makerFee),
@@ -1097,11 +1062,9 @@ describe(ContractName.BalanceThresholdFilter, () => {
.times(validSignedOrder.makerAssetAmount)
.dividedToIntegerBy(validSignedOrder.takerAssetAmount);
const cumulativeMakerAssetFillAmount = validSignedOrder.makerAssetAmount.plus(makerAssetFillAmount2);
- const txReceipt = await erc721TakerBalanceThresholdWrapper.marketBuyOrdersAsync(
- orders,
- validTakerAddress,
- { makerAssetFillAmount: cumulativeMakerAssetFillAmount },
- );
+ const txReceipt = await erc721TakerBalanceThresholdWrapper.marketBuyOrdersAsync(orders, validTakerAddress, {
+ makerAssetFillAmount: cumulativeMakerAssetFillAmount,
+ });
// Assert validated addresses
const expectedValidatedAddresseses = [
validSignedOrder.makerAddress,
@@ -1120,14 +1083,10 @@ describe(ContractName.BalanceThresholdFilter, () => {
const takerFeePaid = validSignedOrder.takerFee.plus(takerFeePaid2);
// Maker #1
expect(newBalances[validMakerAddress][defaultMakerAssetAddress]).to.be.bignumber.equal(
- erc20Balances[validMakerAddress][defaultMakerAssetAddress].minus(
- validSignedOrder.makerAssetAmount,
- ),
+ erc20Balances[validMakerAddress][defaultMakerAssetAddress].minus(validSignedOrder.makerAssetAmount),
);
expect(newBalances[validMakerAddress][defaultTakerAssetAddress]).to.be.bignumber.equal(
- erc20Balances[validMakerAddress][defaultTakerAssetAddress].add(
- validSignedOrder.takerAssetAmount,
- ),
+ erc20Balances[validMakerAddress][defaultTakerAssetAddress].add(validSignedOrder.takerAssetAmount),
);
expect(newBalances[validMakerAddress][zrxToken.address]).to.be.bignumber.equal(
erc20Balances[validMakerAddress][zrxToken.address].minus(validSignedOrder.makerFee),
@@ -1224,14 +1183,10 @@ describe(ContractName.BalanceThresholdFilter, () => {
const takerFeePaid = validSignedOrder.takerFee.plus(takerFeePaid2);
// Maker #1
expect(newBalances[validMakerAddress][defaultMakerAssetAddress]).to.be.bignumber.equal(
- erc20Balances[validMakerAddress][defaultMakerAssetAddress].minus(
- validSignedOrder.makerAssetAmount,
- ),
+ erc20Balances[validMakerAddress][defaultMakerAssetAddress].minus(validSignedOrder.makerAssetAmount),
);
expect(newBalances[validMakerAddress][defaultTakerAssetAddress]).to.be.bignumber.equal(
- erc20Balances[validMakerAddress][defaultTakerAssetAddress].add(
- validSignedOrder.takerAssetAmount,
- ),
+ erc20Balances[validMakerAddress][defaultTakerAssetAddress].add(validSignedOrder.takerAssetAmount),
);
expect(newBalances[validMakerAddress][zrxToken.address]).to.be.bignumber.equal(
erc20Balances[validMakerAddress][zrxToken.address].minus(validSignedOrder.makerFee),