aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-03-08 08:07:36 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-04-21 04:56:16 +0800
commit6bfc02d79d189ee6487a74ec095bc7d12314e6a9 (patch)
tree02bb5618a11c229c7bea8bc56b84150a3b63015a /packages/contracts/test
parent7b166837d3ded48874042347d356dc7e4e02f2c1 (diff)
downloaddexon-sol-tools-6bfc02d79d189ee6487a74ec095bc7d12314e6a9.tar
dexon-sol-tools-6bfc02d79d189ee6487a74ec095bc7d12314e6a9.tar.gz
dexon-sol-tools-6bfc02d79d189ee6487a74ec095bc7d12314e6a9.tar.bz2
dexon-sol-tools-6bfc02d79d189ee6487a74ec095bc7d12314e6a9.tar.lz
dexon-sol-tools-6bfc02d79d189ee6487a74ec095bc7d12314e6a9.tar.xz
dexon-sol-tools-6bfc02d79d189ee6487a74ec095bc7d12314e6a9.tar.zst
dexon-sol-tools-6bfc02d79d189ee6487a74ec095bc7d12314e6a9.zip
Modify tests to work with new utils
Diffstat (limited to 'packages/contracts/test')
-rw-r--r--packages/contracts/test/exchange/core.ts485
-rw-r--r--packages/contracts/test/exchange/helpers.ts47
-rw-r--r--packages/contracts/test/exchange/wrapper.ts258
-rw-r--r--packages/contracts/test/tutorials/arbitrage.ts426
4 files changed, 632 insertions, 584 deletions
diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts
index 63a62396a..b68db3edc 100644
--- a/packages/contracts/test/exchange/core.ts
+++ b/packages/contracts/test/exchange/core.ts
@@ -1,4 +1,4 @@
-import { LogWithDecodedArgs, SignedOrder, TransactionReceiptWithDecodedLogs, ZeroEx } from '0x.js';
+import { LogWithDecodedArgs, TransactionReceiptWithDecodedLogs, ZeroEx } from '0x.js';
import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils';
@@ -21,7 +21,8 @@ import { crypto } from '../../src/utils/crypto';
import { ExchangeWrapper } from '../../src/utils/exchange_wrapper';
import { LogDecoder } from '../../src/utils/log_decoder';
import { OrderFactory } from '../../src/utils/order_factory';
-import { BalancesByOwner, ContractName, ExchangeContractErrs } from '../../src/utils/types';
+import { orderUtils } from '../../src/utils/order_utils';
+import { BalancesByOwner, ContractName, ExchangeContractErrs, SignatureType, SignedOrder } from '../../src/utils/types';
import { chaiSetup } from '../utils/chai_setup';
import { deployer } from '../utils/deployer';
import { provider, web3Wrapper } from '../utils/web3_wrapper';
@@ -32,10 +33,10 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
const logDecoder = new LogDecoder(constants.TESTRPC_NETWORK_ID);
describe('Exchange', () => {
- let maker: string;
+ let makerAddress: string;
let tokenOwner: string;
- let taker: string;
- let feeRecipient: string;
+ let takerAddress: string;
+ let feeRecipientAddress: string;
const INITIAL_BALANCE = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18);
const INITIAL_ALLOWANCE = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18);
@@ -55,8 +56,8 @@ describe('Exchange', () => {
before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
- maker = accounts[0];
- [tokenOwner, taker, feeRecipient] = accounts;
+ makerAddress = accounts[0];
+ [tokenOwner, takerAddress, feeRecipientAddress] = accounts;
const [repInstance, dgdInstance, zrxInstance] = await Promise.all([
deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS),
deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS),
@@ -84,43 +85,44 @@ describe('Exchange', () => {
exWrapper = new ExchangeWrapper(exchange, zeroEx);
const defaultOrderParams = {
- exchangeContractAddress: exchange.address,
- maker,
- feeRecipient,
+ exchangeAddress: exchange.address,
+ makerAddress,
+ feeRecipientAddress,
makerTokenAddress: rep.address,
takerTokenAddress: dgd.address,
makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
- makerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
- takerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
+ makerFeeAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
+ takerFeeAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
};
- orderFactory = new OrderFactory(zeroEx, defaultOrderParams);
- dmyBalances = new Balances([rep, dgd, zrx], [maker, taker, feeRecipient]);
+ const secretKey = constants.TESTRPC_ACCOUNTS[0].secretKey;
+ orderFactory = new OrderFactory(secretKey, defaultOrderParams);
+ dmyBalances = new Balances([rep, dgd, zrx], [makerAddress, takerAddress, feeRecipientAddress]);
await Promise.all([
rep.approve.sendTransactionAsync(tokenTransferProxy.address, INITIAL_ALLOWANCE, {
- from: maker,
+ from: makerAddress,
}),
rep.approve.sendTransactionAsync(tokenTransferProxy.address, INITIAL_ALLOWANCE, {
- from: taker,
+ from: takerAddress,
}),
- rep.setBalance.sendTransactionAsync(maker, INITIAL_BALANCE, { from: tokenOwner }),
- rep.setBalance.sendTransactionAsync(taker, INITIAL_BALANCE, { from: tokenOwner }),
+ rep.setBalance.sendTransactionAsync(makerAddress, INITIAL_BALANCE, { from: tokenOwner }),
+ rep.setBalance.sendTransactionAsync(takerAddress, INITIAL_BALANCE, { from: tokenOwner }),
dgd.approve.sendTransactionAsync(tokenTransferProxy.address, INITIAL_ALLOWANCE, {
- from: maker,
+ from: makerAddress,
}),
dgd.approve.sendTransactionAsync(tokenTransferProxy.address, INITIAL_ALLOWANCE, {
- from: taker,
+ from: takerAddress,
}),
- dgd.setBalance.sendTransactionAsync(maker, INITIAL_BALANCE, { from: tokenOwner }),
- dgd.setBalance.sendTransactionAsync(taker, INITIAL_BALANCE, { from: tokenOwner }),
+ dgd.setBalance.sendTransactionAsync(makerAddress, INITIAL_BALANCE, { from: tokenOwner }),
+ dgd.setBalance.sendTransactionAsync(takerAddress, INITIAL_BALANCE, { from: tokenOwner }),
zrx.approve.sendTransactionAsync(tokenTransferProxy.address, INITIAL_ALLOWANCE, {
- from: maker,
+ from: makerAddress,
}),
zrx.approve.sendTransactionAsync(tokenTransferProxy.address, INITIAL_ALLOWANCE, {
- from: taker,
+ from: takerAddress,
}),
- zrx.setBalance.sendTransactionAsync(maker, INITIAL_BALANCE, { from: tokenOwner }),
- zrx.setBalance.sendTransactionAsync(taker, INITIAL_BALANCE, { from: tokenOwner }),
+ zrx.setBalance.sendTransactionAsync(makerAddress, INITIAL_BALANCE, { from: tokenOwner }),
+ zrx.setBalance.sendTransactionAsync(takerAddress, INITIAL_BALANCE, { from: tokenOwner }),
]);
});
beforeEach(async () => {
@@ -138,57 +140,57 @@ describe('Exchange', () => {
describe('fillOrder', () => {
beforeEach(async () => {
balances = await dmyBalances.getAsync();
- signedOrder = await orderFactory.newSignedOrderAsync();
+ signedOrder = orderFactory.newSignedOrder();
});
it('should create an unfillable order', async () => {
- signedOrder = await orderFactory.newSignedOrderAsync({
+ signedOrder = orderFactory.newSignedOrder({
makerTokenAmount: new BigNumber(1001),
takerTokenAmount: new BigNumber(3),
});
- const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(
- ZeroEx.getOrderHashHex(signedOrder),
+ const filledTakerTokenAmountBefore = await exWrapper.getFilledTakerTokenAmountAsync(
+ orderUtils.getOrderHashHex(signedOrder),
);
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const fillTakerTokenAmount1 = new BigNumber(2);
- await exWrapper.fillOrderAsync(signedOrder, taker, {
+ await exWrapper.fillOrderAsync(signedOrder, takerAddress, {
takerTokenFillAmount: fillTakerTokenAmount1,
});
- const filledTakerTokenAmountAfter1 = await zeroEx.exchange.getFilledTakerAmountAsync(
- ZeroEx.getOrderHashHex(signedOrder),
+ const filledTakerTokenAmountAfter1 = await exWrapper.getFilledTakerTokenAmountAsync(
+ orderUtils.getOrderHashHex(signedOrder),
);
expect(filledTakerTokenAmountAfter1).to.be.bignumber.equal(fillTakerTokenAmount1);
const fillTakerTokenAmount2 = new BigNumber(1);
- await exWrapper.fillOrderAsync(signedOrder, taker, {
+ await exWrapper.fillOrderAsync(signedOrder, takerAddress, {
takerTokenFillAmount: fillTakerTokenAmount2,
});
- const filledTakerTokenAmountAfter2 = await zeroEx.exchange.getFilledTakerAmountAsync(
- ZeroEx.getOrderHashHex(signedOrder),
+ const filledTakerTokenAmountAfter2 = await exWrapper.getFilledTakerTokenAmountAsync(
+ orderUtils.getOrderHashHex(signedOrder),
);
expect(filledTakerTokenAmountAfter2).to.be.bignumber.equal(filledTakerTokenAmountAfter1);
});
it('should transfer the correct amounts when makerTokenAmount === takerTokenAmount', async () => {
- signedOrder = await orderFactory.newSignedOrderAsync({
+ signedOrder = orderFactory.newSignedOrder({
makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
});
- const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(
- ZeroEx.getOrderHashHex(signedOrder),
+ const filledTakerTokenAmountBefore = await exWrapper.getFilledTakerTokenAmountAsync(
+ orderUtils.getOrderHashHex(signedOrder),
);
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const takerTokenFillAmount = signedOrder.takerTokenAmount.div(2);
- await exWrapper.fillOrderAsync(signedOrder, taker, { takerTokenFillAmount });
+ await exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerTokenFillAmount });
- const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(
- ZeroEx.getOrderHashHex(signedOrder),
+ const filledTakerTokenAmountAfter = await exWrapper.getFilledTakerTokenAmountAsync(
+ orderUtils.getOrderHashHex(signedOrder),
);
expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(takerTokenFillAmount);
@@ -197,51 +199,51 @@ describe('Exchange', () => {
const makerTokenFillAmount = takerTokenFillAmount
.times(signedOrder.makerTokenAmount)
.dividedToIntegerBy(signedOrder.takerTokenAmount);
- const makerFeePaid = signedOrder.makerFee
+ const makerFeePaid = signedOrder.makerFeeAmount
.times(makerTokenFillAmount)
.dividedToIntegerBy(signedOrder.makerTokenAmount);
- const takerFeePaid = signedOrder.takerFee
+ const takerFeePaid = signedOrder.takerFeeAmount
.times(makerTokenFillAmount)
.dividedToIntegerBy(signedOrder.makerTokenAmount);
- expect(newBalances[maker][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[maker][signedOrder.makerTokenAddress].minus(makerTokenFillAmount),
+ expect(newBalances[makerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrder.makerTokenAddress].minus(makerTokenFillAmount),
);
- expect(newBalances[maker][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[maker][signedOrder.takerTokenAddress].add(takerTokenFillAmount),
+ expect(newBalances[makerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrder.takerTokenAddress].add(takerTokenFillAmount),
);
- expect(newBalances[maker][zrx.address]).to.be.bignumber.equal(
- balances[maker][zrx.address].minus(makerFeePaid),
+ expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[makerAddress][zrx.address].minus(makerFeePaid),
);
- expect(newBalances[taker][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[taker][signedOrder.takerTokenAddress].minus(takerTokenFillAmount),
+ expect(newBalances[takerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrder.takerTokenAddress].minus(takerTokenFillAmount),
);
- expect(newBalances[taker][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[taker][signedOrder.makerTokenAddress].add(makerTokenFillAmount),
+ expect(newBalances[takerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrder.makerTokenAddress].add(makerTokenFillAmount),
);
- expect(newBalances[taker][zrx.address]).to.be.bignumber.equal(
- balances[taker][zrx.address].minus(takerFeePaid),
+ expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[takerAddress][zrx.address].minus(takerFeePaid),
);
- expect(newBalances[feeRecipient][zrx.address]).to.be.bignumber.equal(
- balances[feeRecipient][zrx.address].add(makerFeePaid.add(takerFeePaid)),
+ expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal(
+ balances[feeRecipientAddress][zrx.address].add(makerFeePaid.add(takerFeePaid)),
);
});
it('should transfer the correct amounts when makerTokenAmount > takerTokenAmount', async () => {
- signedOrder = await orderFactory.newSignedOrderAsync({
+ signedOrder = orderFactory.newSignedOrder({
makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
});
- const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(
- ZeroEx.getOrderHashHex(signedOrder),
+ const filledTakerTokenAmountBefore = await exWrapper.getFilledTakerTokenAmountAsync(
+ orderUtils.getOrderHashHex(signedOrder),
);
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const takerTokenFillAmount = signedOrder.takerTokenAmount.div(2);
- await exWrapper.fillOrderAsync(signedOrder, taker, { takerTokenFillAmount });
+ await exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerTokenFillAmount });
- const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(
- ZeroEx.getOrderHashHex(signedOrder),
+ const filledTakerTokenAmountAfter = await exWrapper.getFilledTakerTokenAmountAsync(
+ orderUtils.getOrderHashHex(signedOrder),
);
expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(takerTokenFillAmount);
@@ -250,51 +252,51 @@ describe('Exchange', () => {
const makerTokenFillAmount = takerTokenFillAmount
.times(signedOrder.makerTokenAmount)
.dividedToIntegerBy(signedOrder.takerTokenAmount);
- const makerFeePaid = signedOrder.makerFee
+ const makerFeePaid = signedOrder.makerFeeAmount
.times(makerTokenFillAmount)
.dividedToIntegerBy(signedOrder.makerTokenAmount);
- const takerFeePaid = signedOrder.takerFee
+ const takerFeePaid = signedOrder.takerFeeAmount
.times(makerTokenFillAmount)
.dividedToIntegerBy(signedOrder.makerTokenAmount);
- expect(newBalances[maker][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[maker][signedOrder.makerTokenAddress].minus(makerTokenFillAmount),
+ expect(newBalances[makerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrder.makerTokenAddress].minus(makerTokenFillAmount),
);
- expect(newBalances[maker][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[maker][signedOrder.takerTokenAddress].add(takerTokenFillAmount),
+ expect(newBalances[makerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrder.takerTokenAddress].add(takerTokenFillAmount),
);
- expect(newBalances[maker][zrx.address]).to.be.bignumber.equal(
- balances[maker][zrx.address].minus(makerFeePaid),
+ expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[makerAddress][zrx.address].minus(makerFeePaid),
);
- expect(newBalances[taker][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[taker][signedOrder.takerTokenAddress].minus(takerTokenFillAmount),
+ expect(newBalances[takerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrder.takerTokenAddress].minus(takerTokenFillAmount),
);
- expect(newBalances[taker][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[taker][signedOrder.makerTokenAddress].add(makerTokenFillAmount),
+ expect(newBalances[takerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrder.makerTokenAddress].add(makerTokenFillAmount),
);
- expect(newBalances[taker][zrx.address]).to.be.bignumber.equal(
- balances[taker][zrx.address].minus(takerFeePaid),
+ expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[takerAddress][zrx.address].minus(takerFeePaid),
);
- expect(newBalances[feeRecipient][zrx.address]).to.be.bignumber.equal(
- balances[feeRecipient][zrx.address].add(makerFeePaid.add(takerFeePaid)),
+ expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal(
+ balances[feeRecipientAddress][zrx.address].add(makerFeePaid.add(takerFeePaid)),
);
});
it('should transfer the correct amounts when makerTokenAmount < takerTokenAmount', async () => {
- signedOrder = await orderFactory.newSignedOrderAsync({
+ signedOrder = orderFactory.newSignedOrder({
makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
});
- const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(
- ZeroEx.getOrderHashHex(signedOrder),
+ const filledTakerTokenAmountBefore = await exWrapper.getFilledTakerTokenAmountAsync(
+ orderUtils.getOrderHashHex(signedOrder),
);
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const takerTokenFillAmount = signedOrder.takerTokenAmount.div(2);
- await exWrapper.fillOrderAsync(signedOrder, taker, { takerTokenFillAmount });
+ await exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerTokenFillAmount });
- const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(
- ZeroEx.getOrderHashHex(signedOrder),
+ const filledTakerTokenAmountAfter = await exWrapper.getFilledTakerTokenAmountAsync(
+ orderUtils.getOrderHashHex(signedOrder),
);
expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(takerTokenFillAmount);
@@ -303,52 +305,52 @@ describe('Exchange', () => {
const makerTokenFillAmount = takerTokenFillAmount
.times(signedOrder.makerTokenAmount)
.dividedToIntegerBy(signedOrder.takerTokenAmount);
- const makerFeePaid = signedOrder.makerFee
+ const makerFeePaid = signedOrder.makerFeeAmount
.times(makerTokenFillAmount)
.dividedToIntegerBy(signedOrder.makerTokenAmount);
- const takerFeePaid = signedOrder.takerFee
+ const takerFeePaid = signedOrder.takerFeeAmount
.times(makerTokenFillAmount)
.dividedToIntegerBy(signedOrder.makerTokenAmount);
- expect(newBalances[maker][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[maker][signedOrder.makerTokenAddress].minus(makerTokenFillAmount),
+ expect(newBalances[makerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrder.makerTokenAddress].minus(makerTokenFillAmount),
);
- expect(newBalances[maker][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[maker][signedOrder.takerTokenAddress].add(takerTokenFillAmount),
+ expect(newBalances[makerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrder.takerTokenAddress].add(takerTokenFillAmount),
);
- expect(newBalances[maker][zrx.address]).to.be.bignumber.equal(
- balances[maker][zrx.address].minus(makerFeePaid),
+ expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[makerAddress][zrx.address].minus(makerFeePaid),
);
- expect(newBalances[taker][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[taker][signedOrder.takerTokenAddress].minus(takerTokenFillAmount),
+ expect(newBalances[takerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrder.takerTokenAddress].minus(takerTokenFillAmount),
);
- expect(newBalances[taker][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[taker][signedOrder.makerTokenAddress].add(makerTokenFillAmount),
+ expect(newBalances[takerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrder.makerTokenAddress].add(makerTokenFillAmount),
);
- expect(newBalances[taker][zrx.address]).to.be.bignumber.equal(
- balances[taker][zrx.address].minus(takerFeePaid),
+ expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[takerAddress][zrx.address].minus(takerFeePaid),
);
- expect(newBalances[feeRecipient][zrx.address]).to.be.bignumber.equal(
- balances[feeRecipient][zrx.address].add(makerFeePaid.add(takerFeePaid)),
+ expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal(
+ balances[feeRecipientAddress][zrx.address].add(makerFeePaid.add(takerFeePaid)),
);
});
it('should transfer the correct amounts when taker is specified and order is claimed by taker', async () => {
- signedOrder = await orderFactory.newSignedOrderAsync({
- taker,
+ signedOrder = orderFactory.newSignedOrder({
+ takerAddress,
makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
});
- const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(
- ZeroEx.getOrderHashHex(signedOrder),
+ const filledTakerTokenAmountBefore = await exWrapper.getFilledTakerTokenAmountAsync(
+ orderUtils.getOrderHashHex(signedOrder),
);
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const takerTokenFillAmount = signedOrder.takerTokenAmount.div(2);
- await exWrapper.fillOrderAsync(signedOrder, taker, { takerTokenFillAmount });
+ await exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerTokenFillAmount });
- const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(
- ZeroEx.getOrderHashHex(signedOrder),
+ const filledTakerTokenAmountAfter = await exWrapper.getFilledTakerTokenAmountAsync(
+ orderUtils.getOrderHashHex(signedOrder),
);
const expectedFillAmountTAfter = takerTokenFillAmount.add(filledTakerTokenAmountBefore);
expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(expectedFillAmountTAfter);
@@ -358,40 +360,40 @@ describe('Exchange', () => {
const makerTokenFillAmount = takerTokenFillAmount
.times(signedOrder.makerTokenAmount)
.dividedToIntegerBy(signedOrder.takerTokenAmount);
- const makerFeePaid = signedOrder.makerFee
+ const makerFeePaid = signedOrder.makerFeeAmount
.times(makerTokenFillAmount)
.dividedToIntegerBy(signedOrder.makerTokenAmount);
- const takerFeePaid = signedOrder.takerFee
+ const takerFeePaid = signedOrder.takerFeeAmount
.times(makerTokenFillAmount)
.dividedToIntegerBy(signedOrder.makerTokenAmount);
- expect(newBalances[maker][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[maker][signedOrder.makerTokenAddress].minus(makerTokenFillAmount),
+ expect(newBalances[makerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrder.makerTokenAddress].minus(makerTokenFillAmount),
);
- expect(newBalances[maker][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[maker][signedOrder.takerTokenAddress].add(takerTokenFillAmount),
+ expect(newBalances[makerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrder.takerTokenAddress].add(takerTokenFillAmount),
);
- expect(newBalances[maker][zrx.address]).to.be.bignumber.equal(
- balances[maker][zrx.address].minus(makerFeePaid),
+ expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[makerAddress][zrx.address].minus(makerFeePaid),
);
- expect(newBalances[taker][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[taker][signedOrder.takerTokenAddress].minus(takerTokenFillAmount),
+ expect(newBalances[takerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrder.takerTokenAddress].minus(takerTokenFillAmount),
);
- expect(newBalances[taker][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[taker][signedOrder.makerTokenAddress].add(makerTokenFillAmount),
+ expect(newBalances[takerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrder.makerTokenAddress].add(makerTokenFillAmount),
);
- expect(newBalances[taker][zrx.address]).to.be.bignumber.equal(
- balances[taker][zrx.address].minus(takerFeePaid),
+ expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[takerAddress][zrx.address].minus(takerFeePaid),
);
- expect(newBalances[feeRecipient][zrx.address]).to.be.bignumber.equal(
- balances[feeRecipient][zrx.address].add(makerFeePaid.add(takerFeePaid)),
+ expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal(
+ balances[feeRecipientAddress][zrx.address].add(makerFeePaid.add(takerFeePaid)),
);
});
it('should fill remaining value if takerTokenFillAmount > remaining takerTokenAmount', async () => {
const takerTokenFillAmount = signedOrder.takerTokenAmount.div(2);
- await exWrapper.fillOrderAsync(signedOrder, taker, { takerTokenFillAmount });
+ await exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerTokenFillAmount });
- const res = await exWrapper.fillOrderAsync(signedOrder, taker, {
+ const res = await exWrapper.fillOrderAsync(signedOrder, takerAddress, {
takerTokenFillAmount: signedOrder.takerTokenAmount,
});
const log = logDecoder.decodeLogOrThrow(res.logs[0]) as LogWithDecodedArgs<LogFillContractEventArgs>;
@@ -400,32 +402,34 @@ describe('Exchange', () => {
);
const newBalances = await dmyBalances.getAsync();
- expect(newBalances[maker][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[maker][signedOrder.makerTokenAddress].minus(signedOrder.makerTokenAmount),
+ expect(newBalances[makerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrder.makerTokenAddress].minus(signedOrder.makerTokenAmount),
);
- expect(newBalances[maker][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[maker][signedOrder.takerTokenAddress].add(signedOrder.takerTokenAmount),
+ expect(newBalances[makerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrder.takerTokenAddress].add(signedOrder.takerTokenAmount),
);
- expect(newBalances[maker][zrx.address]).to.be.bignumber.equal(
- balances[maker][zrx.address].minus(signedOrder.makerFee),
+ expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[makerAddress][zrx.address].minus(signedOrder.makerFeeAmount),
);
- expect(newBalances[taker][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[taker][signedOrder.takerTokenAddress].minus(signedOrder.takerTokenAmount),
+ expect(newBalances[takerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrder.takerTokenAddress].minus(signedOrder.takerTokenAmount),
);
- expect(newBalances[taker][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[taker][signedOrder.makerTokenAddress].add(signedOrder.makerTokenAmount),
+ expect(newBalances[takerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrder.makerTokenAddress].add(signedOrder.makerTokenAmount),
);
- expect(newBalances[taker][zrx.address]).to.be.bignumber.equal(
- balances[taker][zrx.address].minus(signedOrder.takerFee),
+ expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[takerAddress][zrx.address].minus(signedOrder.takerFeeAmount),
);
- expect(newBalances[feeRecipient][zrx.address]).to.be.bignumber.equal(
- balances[feeRecipient][zrx.address].add(signedOrder.makerFee.add(signedOrder.takerFee)),
+ expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal(
+ balances[feeRecipientAddress][zrx.address].add(
+ signedOrder.makerFeeAmount.add(signedOrder.takerFeeAmount),
+ ),
);
});
it('should log 1 event with the correct arguments when order has a feeRecipient', async () => {
const divisor = 2;
- const res = await exWrapper.fillOrderAsync(signedOrder, taker, {
+ const res = await exWrapper.fillOrderAsync(signedOrder, takerAddress, {
takerTokenFillAmount: signedOrder.takerTokenAmount.div(divisor),
});
expect(res.logs).to.have.length(1);
@@ -434,29 +438,29 @@ describe('Exchange', () => {
const logArgs = log.args;
const expectedFilledMakerTokenAmount = signedOrder.makerTokenAmount.div(divisor);
const expectedFilledTakerTokenAmount = signedOrder.takerTokenAmount.div(divisor);
- const expectedFeeMPaid = signedOrder.makerFee.div(divisor);
- const expectedFeeTPaid = signedOrder.takerFee.div(divisor);
+ const expectedFeeMPaid = signedOrder.makerFeeAmount.div(divisor);
+ const expectedFeeTPaid = signedOrder.takerFeeAmount.div(divisor);
const tokensHashBuff = crypto.solSHA3([signedOrder.makerTokenAddress, signedOrder.takerTokenAddress]);
const expectedTokens = ethUtil.bufferToHex(tokensHashBuff);
- expect(signedOrder.maker).to.be.equal(logArgs.maker);
- expect(taker).to.be.equal(logArgs.taker);
- expect(signedOrder.feeRecipient).to.be.equal(logArgs.feeRecipient);
- expect(signedOrder.makerTokenAddress).to.be.equal(logArgs.makerToken);
- expect(signedOrder.takerTokenAddress).to.be.equal(logArgs.takerToken);
+ expect(signedOrder.makerAddress).to.be.equal(logArgs.makerAddress);
+ expect(takerAddress).to.be.equal(logArgs.takerAddress);
+ expect(signedOrder.feeRecipientAddress).to.be.equal(logArgs.feeRecipientAddress);
+ expect(signedOrder.makerTokenAddress).to.be.equal(logArgs.makerTokenAddress);
+ expect(signedOrder.takerTokenAddress).to.be.equal(logArgs.takerTokenAddress);
expect(expectedFilledMakerTokenAmount).to.be.bignumber.equal(logArgs.makerTokenFilledAmount);
expect(expectedFilledTakerTokenAmount).to.be.bignumber.equal(logArgs.takerTokenFilledAmount);
- expect(expectedFeeMPaid).to.be.bignumber.equal(logArgs.makerFeePaid);
- expect(expectedFeeTPaid).to.be.bignumber.equal(logArgs.takerFeePaid);
- expect(ZeroEx.getOrderHashHex(signedOrder)).to.be.equal(logArgs.orderHash);
+ expect(expectedFeeMPaid).to.be.bignumber.equal(logArgs.makerFeeAmountPaid);
+ expect(expectedFeeTPaid).to.be.bignumber.equal(logArgs.takerFeeAmountPaid);
+ expect(orderUtils.getOrderHashHex(signedOrder)).to.be.equal(logArgs.orderHash);
});
it('should log 1 event with the correct arguments when order has no feeRecipient', async () => {
- signedOrder = await orderFactory.newSignedOrderAsync({
- feeRecipient: ZeroEx.NULL_ADDRESS,
+ signedOrder = orderFactory.newSignedOrder({
+ feeRecipientAddress: ZeroEx.NULL_ADDRESS,
});
const divisor = 2;
- const res = await exWrapper.fillOrderAsync(signedOrder, taker, {
+ const res = await exWrapper.fillOrderAsync(signedOrder, takerAddress, {
takerTokenFillAmount: signedOrder.takerTokenAmount.div(divisor),
});
expect(res.logs).to.have.length(1);
@@ -470,59 +474,66 @@ describe('Exchange', () => {
const tokensHashBuff = crypto.solSHA3([signedOrder.makerTokenAddress, signedOrder.takerTokenAddress]);
const expectedTokens = ethUtil.bufferToHex(tokensHashBuff);
- expect(signedOrder.maker).to.be.equal(logArgs.maker);
- expect(taker).to.be.equal(logArgs.taker);
- expect(signedOrder.feeRecipient).to.be.equal(logArgs.feeRecipient);
- expect(signedOrder.makerTokenAddress).to.be.equal(logArgs.makerToken);
- expect(signedOrder.takerTokenAddress).to.be.equal(logArgs.takerToken);
+ expect(signedOrder.makerAddress).to.be.equal(logArgs.makerAddress);
+ expect(takerAddress).to.be.equal(logArgs.takerAddress);
+ expect(signedOrder.feeRecipientAddress).to.be.equal(logArgs.feeRecipientAddress);
+ expect(signedOrder.makerTokenAddress).to.be.equal(logArgs.makerTokenAddress);
+ expect(signedOrder.takerTokenAddress).to.be.equal(logArgs.takerTokenAddress);
expect(expectedFilledMakerTokenAmount).to.be.bignumber.equal(logArgs.makerTokenFilledAmount);
expect(expectedFilledTakerTokenAmount).to.be.bignumber.equal(logArgs.takerTokenFilledAmount);
- expect(expectedFeeMPaid).to.be.bignumber.equal(logArgs.makerFeePaid);
- expect(expectedFeeTPaid).to.be.bignumber.equal(logArgs.takerFeePaid);
- expect(ZeroEx.getOrderHashHex(signedOrder)).to.be.equal(logArgs.orderHash);
+ expect(expectedFeeMPaid).to.be.bignumber.equal(logArgs.makerFeeAmountPaid);
+ expect(expectedFeeTPaid).to.be.bignumber.equal(logArgs.takerFeeAmountPaid);
+ expect(orderUtils.getOrderHashHex(signedOrder)).to.be.equal(logArgs.orderHash);
});
it('should throw when taker is specified and order is claimed by other', async () => {
- signedOrder = await orderFactory.newSignedOrderAsync({
- taker: feeRecipient,
+ signedOrder = orderFactory.newSignedOrder({
+ takerAddress: feeRecipientAddress,
makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
});
- return expect(exWrapper.fillOrderAsync(signedOrder, taker)).to.be.rejectedWith(constants.REVERT);
+ return expect(exWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
});
it('should throw if signature is invalid', async () => {
- signedOrder = await orderFactory.newSignedOrderAsync({
+ signedOrder = orderFactory.newSignedOrder({
makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18),
});
- signedOrder.ecSignature.r = ethUtil.bufferToHex(ethUtil.sha3('invalidR'));
- signedOrder.ecSignature.s = ethUtil.bufferToHex(ethUtil.sha3('invalidS'));
- return expect(exWrapper.fillOrderAsync(signedOrder, taker)).to.be.rejectedWith(constants.REVERT);
+ const invalidR = ethUtil.sha3('invalidR');
+ const invalidS = ethUtil.sha3('invalidS');
+ const invalidSigBuff = Buffer.concat([
+ ethUtil.toBuffer(signedOrder.signature.slice(0, 6)),
+ invalidR,
+ invalidS,
+ ]);
+ const invalidSigHex = `0x${invalidSigBuff.toString('hex')}`;
+ signedOrder.signature = invalidSigHex;
+ return expect(exWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
});
it('should throw if makerTokenAmount is 0', async () => {
- signedOrder = await orderFactory.newSignedOrderAsync({
+ signedOrder = orderFactory.newSignedOrder({
makerTokenAmount: new BigNumber(0),
});
- return expect(exWrapper.fillOrderAsync(signedOrder, taker)).to.be.rejectedWith(constants.REVERT);
+ return expect(exWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
});
it('should throw if takerTokenAmount is 0', async () => {
- signedOrder = await orderFactory.newSignedOrderAsync({
+ signedOrder = orderFactory.newSignedOrder({
takerTokenAmount: new BigNumber(0),
});
- return expect(exWrapper.fillOrderAsync(signedOrder, taker)).to.be.rejectedWith(constants.REVERT);
+ return expect(exWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
});
it('should throw if takerTokenFillAmount is 0', async () => {
- signedOrder = await orderFactory.newSignedOrderAsync();
+ signedOrder = orderFactory.newSignedOrder();
return expect(
- exWrapper.fillOrderAsync(signedOrder, taker, {
+ exWrapper.fillOrderAsync(signedOrder, takerAddress, {
takerTokenFillAmount: new BigNumber(0),
}),
).to.be.rejectedWith(constants.REVERT);
@@ -540,11 +551,11 @@ describe('Exchange', () => {
// });
it('should throw if maker balances are too low to fill order', async () => {
- signedOrder = await orderFactory.newSignedOrderAsync({
+ signedOrder = orderFactory.newSignedOrder({
makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18),
});
- return expect(exWrapper.fillOrderAsync(signedOrder, taker)).to.be.rejectedWith(constants.REVERT);
+ return expect(exWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
});
// it('should not change balances if taker balances are too low to fill order and \
@@ -559,11 +570,11 @@ describe('Exchange', () => {
// });
it('should throw if taker balances are too low to fill order', async () => {
- signedOrder = await orderFactory.newSignedOrderAsync({
+ signedOrder = orderFactory.newSignedOrder({
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18),
});
- return expect(exWrapper.fillOrderAsync(signedOrder, taker)).to.be.rejectedWith(constants.REVERT);
+ return expect(exWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
});
// it('should not change balances if maker allowances are too low to fill order and \
@@ -579,10 +590,12 @@ describe('Exchange', () => {
// });
it('should throw if maker allowances are too low to fill order', async () => {
- await rep.approve.sendTransactionAsync(tokenTransferProxy.address, new BigNumber(0), { from: maker });
- expect(exWrapper.fillOrderAsync(signedOrder, taker)).to.be.rejectedWith(constants.REVERT);
+ await rep.approve.sendTransactionAsync(tokenTransferProxy.address, new BigNumber(0), {
+ from: makerAddress,
+ });
+ expect(exWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
await rep.approve.sendTransactionAsync(tokenTransferProxy.address, INITIAL_ALLOWANCE, {
- from: maker,
+ from: makerAddress,
});
});
@@ -599,10 +612,12 @@ describe('Exchange', () => {
// });
it('should throw if taker allowances are too low to fill order', async () => {
- await dgd.approve.sendTransactionAsync(tokenTransferProxy.address, new BigNumber(0), { from: taker });
- expect(exWrapper.fillOrderAsync(signedOrder, taker)).to.be.rejectedWith(constants.REVERT);
+ await dgd.approve.sendTransactionAsync(tokenTransferProxy.address, new BigNumber(0), {
+ from: takerAddress,
+ });
+ expect(exWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
await dgd.approve.sendTransactionAsync(tokenTransferProxy.address, INITIAL_ALLOWANCE, {
- from: taker,
+ from: takerAddress,
});
});
@@ -673,21 +688,21 @@ describe('Exchange', () => {
// });
it('should not change balances if an order is expired', async () => {
- signedOrder = await orderFactory.newSignedOrderAsync({
- expirationUnixTimestampSec: new BigNumber(Math.floor((Date.now() - 10000) / 1000)),
+ signedOrder = orderFactory.newSignedOrder({
+ expirationTimeSeconds: new BigNumber(Math.floor((Date.now() - 10000) / 1000)),
});
- await exWrapper.fillOrderAsync(signedOrder, taker);
+ await exWrapper.fillOrderAsync(signedOrder, takerAddress);
const newBalances = await dmyBalances.getAsync();
expect(newBalances).to.be.deep.equal(balances);
});
it('should log an error event if an order is expired', async () => {
- signedOrder = await orderFactory.newSignedOrderAsync({
- expirationUnixTimestampSec: new BigNumber(Math.floor((Date.now() - 10000) / 1000)),
+ signedOrder = orderFactory.newSignedOrder({
+ expirationTimeSeconds: new BigNumber(Math.floor((Date.now() - 10000) / 1000)),
});
- const res = await exWrapper.fillOrderAsync(signedOrder, taker);
+ const res = await exWrapper.fillOrderAsync(signedOrder, takerAddress);
expect(res.logs).to.have.length(1);
const log = logDecoder.decodeLogOrThrow(res.logs[0]) as LogWithDecodedArgs<LogErrorContractEventArgs>;
const errCode = log.args.errorId;
@@ -695,10 +710,10 @@ describe('Exchange', () => {
});
it('should log an error event if no value is filled', async () => {
- signedOrder = await orderFactory.newSignedOrderAsync({});
- await exWrapper.fillOrderAsync(signedOrder, taker);
+ signedOrder = orderFactory.newSignedOrder({});
+ await exWrapper.fillOrderAsync(signedOrder, takerAddress);
- const res = await exWrapper.fillOrderAsync(signedOrder, taker);
+ const res = await exWrapper.fillOrderAsync(signedOrder, takerAddress);
expect(res.logs).to.have.length(1);
const log = logDecoder.decodeLogOrThrow(res.logs[0]) as LogWithDecodedArgs<LogErrorContractEventArgs>;
const errCode = log.args.errorId;
@@ -709,42 +724,42 @@ describe('Exchange', () => {
describe('cancelOrder', () => {
beforeEach(async () => {
balances = await dmyBalances.getAsync();
- signedOrder = await orderFactory.newSignedOrderAsync();
+ signedOrder = orderFactory.newSignedOrder();
});
it('should throw if not sent by maker', async () => {
- return expect(exWrapper.cancelOrderAsync(signedOrder, taker)).to.be.rejectedWith(constants.REVERT);
+ return expect(exWrapper.cancelOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
});
it('should throw if makerTokenAmount is 0', async () => {
- signedOrder = await orderFactory.newSignedOrderAsync({
+ signedOrder = orderFactory.newSignedOrder({
makerTokenAmount: new BigNumber(0),
});
- return expect(exWrapper.cancelOrderAsync(signedOrder, maker)).to.be.rejectedWith(constants.REVERT);
+ return expect(exWrapper.cancelOrderAsync(signedOrder, makerAddress)).to.be.rejectedWith(constants.REVERT);
});
it('should throw if takerTokenAmount is 0', async () => {
- signedOrder = await orderFactory.newSignedOrderAsync({
+ signedOrder = orderFactory.newSignedOrder({
takerTokenAmount: new BigNumber(0),
});
- return expect(exWrapper.cancelOrderAsync(signedOrder, maker)).to.be.rejectedWith(constants.REVERT);
+ return expect(exWrapper.cancelOrderAsync(signedOrder, makerAddress)).to.be.rejectedWith(constants.REVERT);
});
it('should throw if takerTokenCancelAmount is 0', async () => {
- signedOrder = await orderFactory.newSignedOrderAsync();
+ signedOrder = orderFactory.newSignedOrder();
return expect(
- exWrapper.cancelOrderAsync(signedOrder, maker, {
+ exWrapper.cancelOrderAsync(signedOrder, makerAddress, {
takerTokenCancelAmount: new BigNumber(0),
}),
).to.be.rejectedWith(constants.REVERT);
});
it('should be able to cancel a full order', async () => {
- await exWrapper.cancelOrderAsync(signedOrder, maker);
- await exWrapper.fillOrderAsync(signedOrder, taker, {
+ await exWrapper.cancelOrderAsync(signedOrder, makerAddress);
+ await exWrapper.fillOrderAsync(signedOrder, takerAddress, {
takerTokenFillAmount: signedOrder.takerTokenAmount.div(2),
});
@@ -754,11 +769,11 @@ describe('Exchange', () => {
it('should be able to cancel part of an order', async () => {
const takerTokenCancelAmount = signedOrder.takerTokenAmount.div(2);
- await exWrapper.cancelOrderAsync(signedOrder, maker, {
+ await exWrapper.cancelOrderAsync(signedOrder, makerAddress, {
takerTokenCancelAmount,
});
- const res = await exWrapper.fillOrderAsync(signedOrder, taker, {
+ const res = await exWrapper.fillOrderAsync(signedOrder, takerAddress, {
takerTokenFillAmount: signedOrder.takerTokenAmount,
});
const log = logDecoder.decodeLogOrThrow(res.logs[0]) as LogWithDecodedArgs<LogFillContractEventArgs>;
@@ -770,38 +785,38 @@ describe('Exchange', () => {
const cancelMakerTokenAmount = takerTokenCancelAmount
.times(signedOrder.makerTokenAmount)
.dividedToIntegerBy(signedOrder.takerTokenAmount);
- const makerFeePaid = signedOrder.makerFee
+ const makerFeePaid = signedOrder.makerFeeAmount
.times(cancelMakerTokenAmount)
.dividedToIntegerBy(signedOrder.makerTokenAmount);
- const takerFeePaid = signedOrder.takerFee
+ const takerFeePaid = signedOrder.takerFeeAmount
.times(cancelMakerTokenAmount)
.dividedToIntegerBy(signedOrder.makerTokenAmount);
- expect(newBalances[maker][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[maker][signedOrder.makerTokenAddress].minus(cancelMakerTokenAmount),
+ expect(newBalances[makerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrder.makerTokenAddress].minus(cancelMakerTokenAmount),
);
- expect(newBalances[maker][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[maker][signedOrder.takerTokenAddress].add(takerTokenCancelAmount),
+ expect(newBalances[makerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrder.takerTokenAddress].add(takerTokenCancelAmount),
);
- expect(newBalances[maker][zrx.address]).to.be.bignumber.equal(
- balances[maker][zrx.address].minus(makerFeePaid),
+ expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[makerAddress][zrx.address].minus(makerFeePaid),
);
- expect(newBalances[taker][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[taker][signedOrder.takerTokenAddress].minus(takerTokenCancelAmount),
+ expect(newBalances[takerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrder.takerTokenAddress].minus(takerTokenCancelAmount),
);
- expect(newBalances[taker][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[taker][signedOrder.makerTokenAddress].add(cancelMakerTokenAmount),
+ expect(newBalances[takerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrder.makerTokenAddress].add(cancelMakerTokenAmount),
);
- expect(newBalances[taker][zrx.address]).to.be.bignumber.equal(
- balances[taker][zrx.address].minus(takerFeePaid),
+ expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[takerAddress][zrx.address].minus(takerFeePaid),
);
- expect(newBalances[feeRecipient][zrx.address]).to.be.bignumber.equal(
- balances[feeRecipient][zrx.address].add(makerFeePaid.add(takerFeePaid)),
+ expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal(
+ balances[feeRecipientAddress][zrx.address].add(makerFeePaid.add(takerFeePaid)),
);
});
it('should log 1 event with correct arguments', async () => {
const divisor = 2;
- const res = await exWrapper.cancelOrderAsync(signedOrder, maker, {
+ const res = await exWrapper.cancelOrderAsync(signedOrder, makerAddress, {
takerTokenCancelAmount: signedOrder.takerTokenAmount.div(divisor),
});
expect(res.logs).to.have.length(1);
@@ -810,22 +825,20 @@ describe('Exchange', () => {
const logArgs = log.args;
const expectedCancelledMakerTokenAmount = signedOrder.makerTokenAmount.div(divisor);
const expectedCancelledTakerTokenAmount = signedOrder.takerTokenAmount.div(divisor);
- const tokensHashBuff = crypto.solSHA3([signedOrder.makerTokenAddress, signedOrder.takerTokenAddress]);
- const expectedTokens = ethUtil.bufferToHex(tokensHashBuff);
- expect(signedOrder.maker).to.be.equal(logArgs.maker);
- expect(signedOrder.feeRecipient).to.be.equal(logArgs.feeRecipient);
- expect(signedOrder.makerTokenAddress).to.be.equal(logArgs.makerToken);
- expect(signedOrder.takerTokenAddress).to.be.equal(logArgs.takerToken);
+ expect(signedOrder.makerAddress).to.be.equal(logArgs.makerAddress);
+ expect(signedOrder.feeRecipientAddress).to.be.equal(logArgs.feeRecipientAddress);
+ expect(signedOrder.makerTokenAddress).to.be.equal(logArgs.makerTokenAddress);
+ expect(signedOrder.takerTokenAddress).to.be.equal(logArgs.takerTokenAddress);
expect(expectedCancelledMakerTokenAmount).to.be.bignumber.equal(logArgs.makerTokenCancelledAmount);
expect(expectedCancelledTakerTokenAmount).to.be.bignumber.equal(logArgs.takerTokenCancelledAmount);
- expect(ZeroEx.getOrderHashHex(signedOrder)).to.be.equal(logArgs.orderHash);
+ expect(orderUtils.getOrderHashHex(signedOrder)).to.be.equal(logArgs.orderHash);
});
it('should not log events if no value is cancelled', async () => {
- await exWrapper.cancelOrderAsync(signedOrder, maker);
+ await exWrapper.cancelOrderAsync(signedOrder, makerAddress);
- const res = await exWrapper.cancelOrderAsync(signedOrder, maker);
+ const res = await exWrapper.cancelOrderAsync(signedOrder, makerAddress);
expect(res.logs).to.have.length(1);
const log = logDecoder.decodeLogOrThrow(res.logs[0]) as LogWithDecodedArgs<LogErrorContractEventArgs>;
const errCode = log.args.errorId;
@@ -833,11 +846,11 @@ describe('Exchange', () => {
});
it('should not log events if order is expired', async () => {
- signedOrder = await orderFactory.newSignedOrderAsync({
- expirationUnixTimestampSec: new BigNumber(Math.floor((Date.now() - 10000) / 1000)),
+ signedOrder = orderFactory.newSignedOrder({
+ expirationTimeSeconds: new BigNumber(Math.floor((Date.now() - 10000) / 1000)),
});
- const res = await exWrapper.cancelOrderAsync(signedOrder, maker);
+ const res = await exWrapper.cancelOrderAsync(signedOrder, makerAddress);
expect(res.logs).to.have.length(1);
const log = logDecoder.decodeLogOrThrow(res.logs[0]) as LogWithDecodedArgs<LogErrorContractEventArgs>;
const errCode = log.args.errorId;
diff --git a/packages/contracts/test/exchange/helpers.ts b/packages/contracts/test/exchange/helpers.ts
index d41f37446..c52f66ca5 100644
--- a/packages/contracts/test/exchange/helpers.ts
+++ b/packages/contracts/test/exchange/helpers.ts
@@ -1,4 +1,4 @@
-import { SignedOrder, ZeroEx } from '0x.js';
+import { ZeroEx } from '0x.js';
import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
@@ -9,7 +9,8 @@ import { ExchangeContract } from '../../src/contract_wrappers/generated/exchange
import { constants } from '../../src/utils/constants';
import { ExchangeWrapper } from '../../src/utils/exchange_wrapper';
import { OrderFactory } from '../../src/utils/order_factory';
-import { ContractName } from '../../src/utils/types';
+import { orderUtils } from '../../src/utils/order_utils';
+import { ContractName, SignedOrder } from '../../src/utils/types';
import { chaiSetup } from '../utils/chai_setup';
import { deployer } from '../utils/deployer';
import { provider, web3Wrapper } from '../utils/web3_wrapper';
@@ -20,8 +21,8 @@ const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe('Exchange', () => {
- let maker: string;
- let feeRecipient: string;
+ let makerAddress: string;
+ let feeRecipientAddress: string;
let signedOrder: SignedOrder;
let exchangeWrapper: ExchangeWrapper;
@@ -29,7 +30,7 @@ describe('Exchange', () => {
before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
- [maker, feeRecipient] = accounts;
+ [makerAddress, feeRecipientAddress] = accounts;
const tokenRegistry = await deployer.deployAsync(ContractName.TokenRegistry);
const tokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy);
const [rep, dgd, zrx] = await Promise.all([
@@ -46,18 +47,19 @@ describe('Exchange', () => {
const zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID });
exchangeWrapper = new ExchangeWrapper(exchange, zeroEx);
const defaultOrderParams = {
- exchangeContractAddress: exchange.address,
- maker,
- feeRecipient,
+ exchangeAddress: exchange.address,
+ makerAddress,
+ feeRecipientAddress,
makerTokenAddress: rep.address,
takerTokenAddress: dgd.address,
makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
- makerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
- takerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
+ makerFeeAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
+ takerFeeAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
};
- orderFactory = new OrderFactory(zeroEx, defaultOrderParams);
- signedOrder = await orderFactory.newSignedOrderAsync();
+ const secretKey = constants.TESTRPC_ACCOUNTS[0].secretKey;
+ orderFactory = new OrderFactory(secretKey, defaultOrderParams);
+ signedOrder = orderFactory.newSignedOrder();
});
beforeEach(async () => {
@@ -69,30 +71,31 @@ describe('Exchange', () => {
describe('getOrderHash', () => {
it('should output the correct orderHash', async () => {
const orderHashHex = await exchangeWrapper.getOrderHashAsync(signedOrder);
- expect(ZeroEx.getOrderHashHex(signedOrder)).to.be.equal(orderHashHex);
+ expect(orderUtils.getOrderHashHex(signedOrder)).to.be.equal(orderHashHex);
});
});
describe('isValidSignature', () => {
beforeEach(async () => {
- signedOrder = await orderFactory.newSignedOrderAsync();
+ signedOrder = orderFactory.newSignedOrder();
});
it('should return true with a valid signature', async () => {
const success = await exchangeWrapper.isValidSignatureAsync(signedOrder);
- const orderHashHex = ZeroEx.getOrderHashHex(signedOrder);
- const isValidSignature = ZeroEx.isValidSignature(orderHashHex, signedOrder.ecSignature, signedOrder.maker);
- expect(isValidSignature).to.be.true();
expect(success).to.be.true();
});
it('should return false with an invalid signature', async () => {
- signedOrder.ecSignature.r = ethUtil.bufferToHex(ethUtil.sha3('invalidR'));
- signedOrder.ecSignature.s = ethUtil.bufferToHex(ethUtil.sha3('invalidS'));
+ const invalidR = ethUtil.sha3('invalidR');
+ const invalidS = ethUtil.sha3('invalidS');
+ const invalidSigBuff = Buffer.concat([
+ ethUtil.toBuffer(signedOrder.signature.slice(0, 6)),
+ invalidR,
+ invalidS,
+ ]);
+ const invalidSigHex = `0x${invalidSigBuff.toString('hex')}`;
+ signedOrder.signature = invalidSigHex;
const success = await exchangeWrapper.isValidSignatureAsync(signedOrder);
- const orderHashHex = ZeroEx.getOrderHashHex(signedOrder);
- const isValidSignature = ZeroEx.isValidSignature(orderHashHex, signedOrder.ecSignature, signedOrder.maker);
- expect(isValidSignature).to.be.false();
expect(success).to.be.false();
});
});
diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts
index 2a803e2ac..182578f42 100644
--- a/packages/contracts/test/exchange/wrapper.ts
+++ b/packages/contracts/test/exchange/wrapper.ts
@@ -1,4 +1,4 @@
-import { SignedOrder, ZeroEx } from '0x.js';
+import { ZeroEx } from '0x.js';
import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
@@ -19,7 +19,7 @@ import { Balances } from '../../src/utils/balances';
import { constants } from '../../src/utils/constants';
import { ExchangeWrapper } from '../../src/utils/exchange_wrapper';
import { OrderFactory } from '../../src/utils/order_factory';
-import { BalancesByOwner, ContractName } from '../../src/utils/types';
+import { BalancesByOwner, ContractName, SignedOrder } from '../../src/utils/types';
import { chaiSetup } from '../utils/chai_setup';
import { deployer } from '../utils/deployer';
import { provider, web3Wrapper } from '../utils/web3_wrapper';
@@ -29,10 +29,10 @@ const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe('Exchange', () => {
- let maker: string;
+ let makerAddress: string;
let tokenOwner: string;
- let taker: string;
- let feeRecipient: string;
+ let takerAddress: string;
+ let feeRecipientAddress: string;
const INIT_BAL = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18);
const INIT_ALLOW = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18);
@@ -53,7 +53,7 @@ describe('Exchange', () => {
before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
tokenOwner = accounts[0];
- [maker, taker, feeRecipient] = accounts;
+ [makerAddress, takerAddress, feeRecipientAddress] = accounts;
const [repInstance, dgdInstance, zrxInstance] = await Promise.all([
deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS),
deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS),
@@ -80,32 +80,33 @@ describe('Exchange', () => {
exWrapper = new ExchangeWrapper(exchange, zeroEx);
const defaultOrderParams = {
- exchangeContractAddress: exchange.address,
- maker,
- feeRecipient,
+ exchangeAddress: exchange.address,
+ makerAddress,
+ feeRecipientAddress,
makerTokenAddress: rep.address,
takerTokenAddress: dgd.address,
makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
- makerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
- takerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
+ makerFeeAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
+ takerFeeAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
};
- orderFactory = new OrderFactory(zeroEx, defaultOrderParams);
- dmyBalances = new Balances([rep, dgd, zrx], [maker, taker, feeRecipient]);
+ const secretKey = constants.TESTRPC_ACCOUNTS[0].secretKey;
+ orderFactory = new OrderFactory(secretKey, defaultOrderParams);
+ dmyBalances = new Balances([rep, dgd, zrx], [makerAddress, takerAddress, feeRecipientAddress]);
await Promise.all([
- rep.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, { from: maker }),
- rep.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, { from: taker }),
- rep.setBalance.sendTransactionAsync(maker, INIT_BAL, { from: tokenOwner }),
- rep.setBalance.sendTransactionAsync(taker, INIT_BAL, { from: tokenOwner }),
- dgd.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, { from: maker }),
- dgd.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, { from: taker }),
- dgd.setBalance.sendTransactionAsync(maker, INIT_BAL, { from: tokenOwner }),
- dgd.setBalance.sendTransactionAsync(taker, INIT_BAL, { from: tokenOwner }),
- zrx.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, { from: maker }),
- zrx.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, { from: taker }),
- zrx.setBalance.sendTransactionAsync(maker, INIT_BAL, { from: tokenOwner }),
- zrx.setBalance.sendTransactionAsync(taker, INIT_BAL, { from: tokenOwner }),
+ rep.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, { from: makerAddress }),
+ rep.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, { from: takerAddress }),
+ rep.setBalance.sendTransactionAsync(makerAddress, INIT_BAL, { from: tokenOwner }),
+ rep.setBalance.sendTransactionAsync(takerAddress, INIT_BAL, { from: tokenOwner }),
+ dgd.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, { from: makerAddress }),
+ dgd.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, { from: takerAddress }),
+ dgd.setBalance.sendTransactionAsync(makerAddress, INIT_BAL, { from: tokenOwner }),
+ dgd.setBalance.sendTransactionAsync(takerAddress, INIT_BAL, { from: tokenOwner }),
+ zrx.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, { from: makerAddress }),
+ zrx.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, { from: takerAddress }),
+ zrx.setBalance.sendTransactionAsync(makerAddress, INIT_BAL, { from: tokenOwner }),
+ zrx.setBalance.sendTransactionAsync(takerAddress, INIT_BAL, { from: tokenOwner }),
]);
});
beforeEach(async () => {
@@ -120,12 +121,12 @@ describe('Exchange', () => {
});
it('should transfer the correct amounts', async () => {
- const signedOrder = await orderFactory.newSignedOrderAsync({
+ const signedOrder = orderFactory.newSignedOrder({
makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
});
const takerTokenFillAmount = signedOrder.takerTokenAmount.div(2);
- await exWrapper.fillOrKillOrderAsync(signedOrder, taker, {
+ await exWrapper.fillOrKillOrderAsync(signedOrder, takerAddress, {
takerTokenFillAmount,
});
@@ -134,59 +135,66 @@ describe('Exchange', () => {
const makerTokenFillAmount = takerTokenFillAmount
.times(signedOrder.makerTokenAmount)
.dividedToIntegerBy(signedOrder.takerTokenAmount);
- const makerFee = signedOrder.makerFee
+ const makerFeeAmount = signedOrder.makerFeeAmount
.times(makerTokenFillAmount)
.dividedToIntegerBy(signedOrder.makerTokenAmount);
- const takerFee = signedOrder.takerFee
+ const takerFeeAmount = signedOrder.takerFeeAmount
.times(makerTokenFillAmount)
.dividedToIntegerBy(signedOrder.makerTokenAmount);
- expect(newBalances[maker][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[maker][signedOrder.makerTokenAddress].minus(makerTokenFillAmount),
+ expect(newBalances[makerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrder.makerTokenAddress].minus(makerTokenFillAmount),
);
- expect(newBalances[maker][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[maker][signedOrder.takerTokenAddress].add(takerTokenFillAmount),
+ expect(newBalances[makerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrder.takerTokenAddress].add(takerTokenFillAmount),
);
- expect(newBalances[maker][zrx.address]).to.be.bignumber.equal(balances[maker][zrx.address].minus(makerFee));
- expect(newBalances[taker][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[taker][signedOrder.takerTokenAddress].minus(takerTokenFillAmount),
+ expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[makerAddress][zrx.address].minus(makerFeeAmount),
);
- expect(newBalances[taker][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[taker][signedOrder.makerTokenAddress].add(makerTokenFillAmount),
+ expect(newBalances[takerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrder.takerTokenAddress].minus(takerTokenFillAmount),
);
- expect(newBalances[taker][zrx.address]).to.be.bignumber.equal(balances[taker][zrx.address].minus(takerFee));
- expect(newBalances[feeRecipient][zrx.address]).to.be.bignumber.equal(
- balances[feeRecipient][zrx.address].add(makerFee.add(takerFee)),
+ expect(newBalances[takerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrder.makerTokenAddress].add(makerTokenFillAmount),
+ );
+ expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[takerAddress][zrx.address].minus(takerFeeAmount),
+ );
+ expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal(
+ balances[feeRecipientAddress][zrx.address].add(makerFeeAmount.add(takerFeeAmount)),
);
});
it('should throw if an signedOrder is expired', async () => {
- const signedOrder = await orderFactory.newSignedOrderAsync({
- expirationUnixTimestampSec: new BigNumber(Math.floor((Date.now() - 10000) / 1000)),
+ const signedOrder = orderFactory.newSignedOrder({
+ expirationTimeSeconds: new BigNumber(Math.floor((Date.now() - 10000) / 1000)),
});
- return expect(exWrapper.fillOrKillOrderAsync(signedOrder, taker)).to.be.rejectedWith(constants.REVERT);
+ return expect(exWrapper.fillOrKillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
+ constants.REVERT,
+ );
});
it('should throw if entire takerTokenFillAmount not filled', async () => {
- const signedOrder = await orderFactory.newSignedOrderAsync();
+ const signedOrder = orderFactory.newSignedOrder();
- const from = taker;
- await exWrapper.fillOrderAsync(signedOrder, from, {
+ await exWrapper.fillOrderAsync(signedOrder, takerAddress, {
takerTokenFillAmount: signedOrder.takerTokenAmount.div(2),
});
- return expect(exWrapper.fillOrKillOrderAsync(signedOrder, taker)).to.be.rejectedWith(constants.REVERT);
+ return expect(exWrapper.fillOrKillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
+ constants.REVERT,
+ );
});
});
describe('batch functions', () => {
let signedOrders: SignedOrder[];
beforeEach(async () => {
- signedOrders = await Promise.all([
- orderFactory.newSignedOrderAsync(),
- orderFactory.newSignedOrderAsync(),
- orderFactory.newSignedOrderAsync(),
- ]);
+ signedOrders = [
+ orderFactory.newSignedOrder(),
+ orderFactory.newSignedOrder(),
+ orderFactory.newSignedOrder(),
+ ];
balances = await dmyBalances.getAsync();
});
@@ -200,25 +208,33 @@ describe('Exchange', () => {
const makerTokenFillAmount = takerTokenFillAmount
.times(signedOrder.makerTokenAmount)
.dividedToIntegerBy(signedOrder.takerTokenAmount);
- const makerFee = signedOrder.makerFee
+ const makerFeeAmount = signedOrder.makerFeeAmount
.times(makerTokenFillAmount)
.dividedToIntegerBy(signedOrder.makerTokenAmount);
- const takerFee = signedOrder.takerFee
+ const takerFeeAmount = signedOrder.takerFeeAmount
.times(makerTokenFillAmount)
.dividedToIntegerBy(signedOrder.makerTokenAmount);
takerTokenFillAmounts.push(takerTokenFillAmount);
- balances[maker][makerTokenAddress] = balances[maker][makerTokenAddress].minus(makerTokenFillAmount);
- balances[maker][takerTokenAddress] = balances[maker][takerTokenAddress].add(takerTokenFillAmount);
- balances[maker][zrx.address] = balances[maker][zrx.address].minus(makerFee);
- balances[taker][makerTokenAddress] = balances[taker][makerTokenAddress].add(makerTokenFillAmount);
- balances[taker][takerTokenAddress] = balances[taker][takerTokenAddress].minus(takerTokenFillAmount);
- balances[taker][zrx.address] = balances[taker][zrx.address].minus(takerFee);
- balances[feeRecipient][zrx.address] = balances[feeRecipient][zrx.address].add(
- makerFee.add(takerFee),
+ balances[makerAddress][makerTokenAddress] = balances[makerAddress][makerTokenAddress].minus(
+ makerTokenFillAmount,
+ );
+ balances[makerAddress][takerTokenAddress] = balances[makerAddress][takerTokenAddress].add(
+ takerTokenFillAmount,
+ );
+ balances[makerAddress][zrx.address] = balances[makerAddress][zrx.address].minus(makerFeeAmount);
+ balances[takerAddress][makerTokenAddress] = balances[takerAddress][makerTokenAddress].add(
+ makerTokenFillAmount,
+ );
+ balances[takerAddress][takerTokenAddress] = balances[takerAddress][takerTokenAddress].minus(
+ takerTokenFillAmount,
+ );
+ balances[takerAddress][zrx.address] = balances[takerAddress][zrx.address].minus(takerFeeAmount);
+ balances[feeRecipientAddress][zrx.address] = balances[feeRecipientAddress][zrx.address].add(
+ makerFeeAmount.add(takerFeeAmount),
);
});
- await exWrapper.batchFillOrdersAsync(signedOrders, taker, {
+ await exWrapper.batchFillOrdersAsync(signedOrders, takerAddress, {
takerTokenFillAmounts,
});
@@ -237,25 +253,33 @@ describe('Exchange', () => {
const makerTokenFillAmount = takerTokenFillAmount
.times(signedOrder.makerTokenAmount)
.dividedToIntegerBy(signedOrder.takerTokenAmount);
- const makerFee = signedOrder.makerFee
+ const makerFee = signedOrder.makerFeeAmount
.times(makerTokenFillAmount)
.dividedToIntegerBy(signedOrder.makerTokenAmount);
- const takerFee = signedOrder.takerFee
+ const takerFee = signedOrder.takerFeeAmount
.times(makerTokenFillAmount)
.dividedToIntegerBy(signedOrder.makerTokenAmount);
takerTokenFillAmounts.push(takerTokenFillAmount);
- balances[maker][makerTokenAddress] = balances[maker][makerTokenAddress].minus(makerTokenFillAmount);
- balances[maker][takerTokenAddress] = balances[maker][takerTokenAddress].add(takerTokenFillAmount);
- balances[maker][zrx.address] = balances[maker][zrx.address].minus(makerFee);
- balances[taker][makerTokenAddress] = balances[taker][makerTokenAddress].add(makerTokenFillAmount);
- balances[taker][takerTokenAddress] = balances[taker][takerTokenAddress].minus(takerTokenFillAmount);
- balances[taker][zrx.address] = balances[taker][zrx.address].minus(takerFee);
- balances[feeRecipient][zrx.address] = balances[feeRecipient][zrx.address].add(
+ balances[makerAddress][makerTokenAddress] = balances[makerAddress][makerTokenAddress].minus(
+ makerTokenFillAmount,
+ );
+ balances[makerAddress][takerTokenAddress] = balances[makerAddress][takerTokenAddress].add(
+ takerTokenFillAmount,
+ );
+ balances[makerAddress][zrx.address] = balances[makerAddress][zrx.address].minus(makerFee);
+ balances[takerAddress][makerTokenAddress] = balances[takerAddress][makerTokenAddress].add(
+ makerTokenFillAmount,
+ );
+ balances[takerAddress][takerTokenAddress] = balances[takerAddress][takerTokenAddress].minus(
+ takerTokenFillAmount,
+ );
+ balances[takerAddress][zrx.address] = balances[takerAddress][zrx.address].minus(takerFee);
+ balances[feeRecipientAddress][zrx.address] = balances[feeRecipientAddress][zrx.address].add(
makerFee.add(takerFee),
);
});
- await exWrapper.batchFillOrKillOrdersAsync(signedOrders, taker, {
+ await exWrapper.batchFillOrKillOrdersAsync(signedOrders, takerAddress, {
takerTokenFillAmounts,
});
@@ -270,10 +294,10 @@ describe('Exchange', () => {
takerTokenFillAmounts.push(takerTokenFillAmount);
});
- await exWrapper.fillOrKillOrderAsync(signedOrders[0], taker);
+ await exWrapper.fillOrKillOrderAsync(signedOrders[0], takerAddress);
return expect(
- exWrapper.batchFillOrKillOrdersAsync(signedOrders, taker, {
+ exWrapper.batchFillOrKillOrdersAsync(signedOrders, takerAddress, {
takerTokenFillAmounts,
}),
).to.be.rejectedWith(constants.REVERT);
@@ -285,7 +309,7 @@ describe('Exchange', () => {
const takerTokenFillAmount = signedOrders[0].takerTokenAmount.plus(
signedOrders[1].takerTokenAmount.div(2),
);
- await exWrapper.marketFillOrdersAsync(signedOrders, taker, {
+ await exWrapper.marketFillOrdersAsync(signedOrders, takerAddress, {
takerTokenFillAmount,
});
@@ -294,53 +318,61 @@ describe('Exchange', () => {
const makerTokenFillAmount = signedOrders[0].makerTokenAmount.add(
signedOrders[1].makerTokenAmount.dividedToIntegerBy(2),
);
- const makerFee = signedOrders[0].makerFee.add(signedOrders[1].makerFee.dividedToIntegerBy(2));
- const takerFee = signedOrders[0].takerFee.add(signedOrders[1].takerFee.dividedToIntegerBy(2));
- expect(newBalances[maker][signedOrders[0].makerTokenAddress]).to.be.bignumber.equal(
- balances[maker][signedOrders[0].makerTokenAddress].minus(makerTokenFillAmount),
+ const makerFee = signedOrders[0].makerFeeAmount.add(
+ signedOrders[1].makerFeeAmount.dividedToIntegerBy(2),
+ );
+ const takerFee = signedOrders[0].takerFeeAmount.add(
+ signedOrders[1].takerFeeAmount.dividedToIntegerBy(2),
+ );
+ expect(newBalances[makerAddress][signedOrders[0].makerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrders[0].makerTokenAddress].minus(makerTokenFillAmount),
);
- expect(newBalances[maker][signedOrders[0].takerTokenAddress]).to.be.bignumber.equal(
- balances[maker][signedOrders[0].takerTokenAddress].add(takerTokenFillAmount),
+ expect(newBalances[makerAddress][signedOrders[0].takerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrders[0].takerTokenAddress].add(takerTokenFillAmount),
);
- expect(newBalances[maker][zrx.address]).to.be.bignumber.equal(
- balances[maker][zrx.address].minus(makerFee),
+ expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[makerAddress][zrx.address].minus(makerFee),
);
- expect(newBalances[taker][signedOrders[0].takerTokenAddress]).to.be.bignumber.equal(
- balances[taker][signedOrders[0].takerTokenAddress].minus(takerTokenFillAmount),
+ expect(newBalances[takerAddress][signedOrders[0].takerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrders[0].takerTokenAddress].minus(takerTokenFillAmount),
);
- expect(newBalances[taker][signedOrders[0].makerTokenAddress]).to.be.bignumber.equal(
- balances[taker][signedOrders[0].makerTokenAddress].add(makerTokenFillAmount),
+ expect(newBalances[takerAddress][signedOrders[0].makerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrders[0].makerTokenAddress].add(makerTokenFillAmount),
);
- expect(newBalances[taker][zrx.address]).to.be.bignumber.equal(
- balances[taker][zrx.address].minus(takerFee),
+ expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[takerAddress][zrx.address].minus(takerFee),
);
- expect(newBalances[feeRecipient][zrx.address]).to.be.bignumber.equal(
- balances[feeRecipient][zrx.address].add(makerFee.add(takerFee)),
+ expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal(
+ balances[feeRecipientAddress][zrx.address].add(makerFee.add(takerFee)),
);
});
it('should fill all signedOrders if cannot fill entire takerTokenFillAmount', async () => {
const takerTokenFillAmount = ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18);
signedOrders.forEach(signedOrder => {
- balances[maker][signedOrder.makerTokenAddress] = balances[maker][
+ balances[makerAddress][signedOrder.makerTokenAddress] = balances[makerAddress][
signedOrder.makerTokenAddress
].minus(signedOrder.makerTokenAmount);
- balances[maker][signedOrder.takerTokenAddress] = balances[maker][signedOrder.takerTokenAddress].add(
- signedOrder.takerTokenAmount,
- );
- balances[maker][zrx.address] = balances[maker][zrx.address].minus(signedOrder.makerFee);
- balances[taker][signedOrder.makerTokenAddress] = balances[taker][signedOrder.makerTokenAddress].add(
- signedOrder.makerTokenAmount,
+ balances[makerAddress][signedOrder.takerTokenAddress] = balances[makerAddress][
+ signedOrder.takerTokenAddress
+ ].add(signedOrder.takerTokenAmount);
+ balances[makerAddress][zrx.address] = balances[makerAddress][zrx.address].minus(
+ signedOrder.makerFeeAmount,
);
- balances[taker][signedOrder.takerTokenAddress] = balances[taker][
+ balances[takerAddress][signedOrder.makerTokenAddress] = balances[takerAddress][
+ signedOrder.makerTokenAddress
+ ].add(signedOrder.makerTokenAmount);
+ balances[takerAddress][signedOrder.takerTokenAddress] = balances[takerAddress][
signedOrder.takerTokenAddress
].minus(signedOrder.takerTokenAmount);
- balances[taker][zrx.address] = balances[taker][zrx.address].minus(signedOrder.takerFee);
- balances[feeRecipient][zrx.address] = balances[feeRecipient][zrx.address].add(
- signedOrder.makerFee.add(signedOrder.takerFee),
+ balances[takerAddress][zrx.address] = balances[takerAddress][zrx.address].minus(
+ signedOrder.takerFeeAmount,
+ );
+ balances[feeRecipientAddress][zrx.address] = balances[feeRecipientAddress][zrx.address].add(
+ signedOrder.makerFeeAmount.add(signedOrder.takerFeeAmount),
);
});
- await exWrapper.marketFillOrdersAsync(signedOrders, taker, {
+ await exWrapper.marketFillOrdersAsync(signedOrders, takerAddress, {
takerTokenFillAmount,
});
@@ -349,14 +381,14 @@ describe('Exchange', () => {
});
it('should throw when an signedOrder does not use the same takerTokenAddress', async () => {
- signedOrders = await Promise.all([
- orderFactory.newSignedOrderAsync(),
- orderFactory.newSignedOrderAsync({ takerTokenAddress: zrx.address }),
- orderFactory.newSignedOrderAsync(),
- ]);
+ signedOrders = [
+ orderFactory.newSignedOrder(),
+ orderFactory.newSignedOrder({ takerTokenAddress: zrx.address }),
+ orderFactory.newSignedOrder(),
+ ];
return expect(
- exWrapper.marketFillOrdersAsync(signedOrders, taker, {
+ exWrapper.marketFillOrdersAsync(signedOrders, takerAddress, {
takerTokenFillAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1000), 18),
}),
).to.be.rejectedWith(constants.REVERT);
@@ -366,11 +398,11 @@ describe('Exchange', () => {
describe('batchCancelOrders', () => {
it('should be able to cancel multiple signedOrders', async () => {
const takerTokenCancelAmounts = _.map(signedOrders, signedOrder => signedOrder.takerTokenAmount);
- await exWrapper.batchCancelOrdersAsync(signedOrders, maker, {
+ await exWrapper.batchCancelOrdersAsync(signedOrders, makerAddress, {
takerTokenCancelAmounts,
});
- await exWrapper.batchFillOrdersAsync(signedOrders, taker, {
+ await exWrapper.batchFillOrdersAsync(signedOrders, takerAddress, {
takerTokenFillAmounts: takerTokenCancelAmounts,
});
const newBalances = await dmyBalances.getAsync();
diff --git a/packages/contracts/test/tutorials/arbitrage.ts b/packages/contracts/test/tutorials/arbitrage.ts
index 8a6d02af4..d8f777c8f 100644
--- a/packages/contracts/test/tutorials/arbitrage.ts
+++ b/packages/contracts/test/tutorials/arbitrage.ts
@@ -1,225 +1,225 @@
-import { ECSignature, SignedOrder, ZeroEx } from '0x.js';
-import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
-import { BigNumber } from '@0xproject/utils';
-import { Web3Wrapper } from '@0xproject/web3-wrapper';
-import * as chai from 'chai';
-import ethUtil = require('ethereumjs-util');
-import * as Web3 from 'web3';
+// import { ECSignature, SignedOrder, ZeroEx } from '0x.js';
+// import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
+// import { BigNumber } from '@0xproject/utils';
+// import { Web3Wrapper } from '@0xproject/web3-wrapper';
+// import * as chai from 'chai';
+// import ethUtil = require('ethereumjs-util');
+// import * as Web3 from 'web3';
-import { ArbitrageContract } from '../../src/contract_wrappers/generated/arbitrage';
-import { EtherDeltaContract } from '../../src/contract_wrappers/generated/ether_delta';
-import { ExchangeContract } from '../../src/contract_wrappers/generated/exchange';
-import { Balances } from '../../src/utils/balances';
-import { constants } from '../../src/utils/constants';
-import { crypto } from '../../src/utils/crypto';
-import { ExchangeWrapper } from '../../src/utils/exchange_wrapper';
-import { OrderFactory } from '../../src/utils/order_factory';
-import { BalancesByOwner, ContractName, ExchangeContractErrs } from '../../src/utils/types';
-import { chaiSetup } from '../utils/chai_setup';
-import { deployer } from '../utils/deployer';
-import { provider, web3Wrapper } from '../utils/web3_wrapper';
+// import { ArbitrageContract } from '../../src/contract_wrappers/generated/arbitrage';
+// import { EtherDeltaContract } from '../../src/contract_wrappers/generated/ether_delta';
+// import { ExchangeContract } from '../../src/contract_wrappers/generated/exchange';
+// import { Balances } from '../../src/utils/balances';
+// import { constants } from '../../src/utils/constants';
+// import { crypto } from '../../src/utils/crypto';
+// import { ExchangeWrapper } from '../../src/utils/exchange_wrapper';
+// import { OrderFactory } from '../../src/utils/order_factory';
+// import { BalancesByOwner, ContractName, ExchangeContractErrs } from '../../src/utils/types';
+// import { chaiSetup } from '../utils/chai_setup';
+// import { deployer } from '../utils/deployer';
+// import { provider, web3Wrapper } from '../utils/web3_wrapper';
-chaiSetup.configure();
-const expect = chai.expect;
-const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
+// chaiSetup.configure();
+// const expect = chai.expect;
+// const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
-describe('Arbitrage', () => {
- let coinbase: string;
- let maker: string;
- let edMaker: string;
- let edFrontRunner: string;
- let amountGet: BigNumber;
- let amountGive: BigNumber;
- let makerTokenAmount: BigNumber;
- let takerTokenAmount: BigNumber;
- const feeRecipient = ZeroEx.NULL_ADDRESS;
- const INITIAL_BALANCE = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18);
- const INITIAL_ALLOWANCE = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18);
+// describe('Arbitrage', () => {
+// let coinbase: string;
+// let maker: string;
+// let edMaker: string;
+// let edFrontRunner: string;
+// let amountGet: BigNumber;
+// let amountGive: BigNumber;
+// let makerTokenAmount: BigNumber;
+// let takerTokenAmount: BigNumber;
+// const feeRecipient = ZeroEx.NULL_ADDRESS;
+// const INITIAL_BALANCE = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18);
+// const INITIAL_ALLOWANCE = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18);
- let weth: Web3.ContractInstance;
- let zrx: Web3.ContractInstance;
- let arbitrage: ArbitrageContract;
- let etherDelta: EtherDeltaContract;
+// let weth: Web3.ContractInstance;
+// let zrx: Web3.ContractInstance;
+// let arbitrage: ArbitrageContract;
+// let etherDelta: EtherDeltaContract;
- let signedOrder: SignedOrder;
- let exWrapper: ExchangeWrapper;
- let orderFactory: OrderFactory;
+// let signedOrder: SignedOrder;
+// let exWrapper: ExchangeWrapper;
+// let orderFactory: OrderFactory;
- let zeroEx: ZeroEx;
+// let zeroEx: ZeroEx;
- // From a bird's eye view - we create two orders.
- // 0x order of 1 ZRX (maker) for 1 WETH (taker)
- // ED order of 2 WETH (tokenGive) for 1 ZRX (tokenGet)
- // And then we do an atomic arbitrage between them which gives us 1 WETH.
- before(async () => {
- const accounts = await web3Wrapper.getAvailableAddressesAsync();
- [coinbase, maker, edMaker, edFrontRunner] = accounts;
- weth = await deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS);
- zrx = await deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS);
- const accountLevels = await deployer.deployAsync(ContractName.AccountLevels);
- const edAdminAddress = accounts[0];
- const edMakerFee = 0;
- const edTakerFee = 0;
- const edFeeRebate = 0;
- const etherDeltaInstance = await deployer.deployAsync(ContractName.EtherDelta, [
- edAdminAddress,
- feeRecipient,
- accountLevels.address,
- edMakerFee,
- edTakerFee,
- edFeeRebate,
- ]);
- etherDelta = new EtherDeltaContract(etherDeltaInstance.abi, etherDeltaInstance.address, provider);
- const tokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy);
- const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [
- zrx.address,
- tokenTransferProxy.address,
- ]);
- await tokenTransferProxy.addAuthorizedAddress(exchangeInstance.address, { from: accounts[0] });
- zeroEx = new ZeroEx(provider, {
- exchangeContractAddress: exchangeInstance.address,
- networkId: constants.TESTRPC_NETWORK_ID,
- });
- const exchange = new ExchangeContract(exchangeInstance.abi, exchangeInstance.address, provider);
- exWrapper = new ExchangeWrapper(exchange, zeroEx);
+// From a bird's eye view - we create two orders.
+// 0x order of 1 ZRX (maker) for 1 WETH (taker)
+// ED order of 2 WETH (tokenGive) for 1 ZRX (tokenGet)
+// And then we do an atomic arbitrage between them which gives us 1 WETH.
+// before(async () => {
+// const accounts = await web3Wrapper.getAvailableAddressesAsync();
+// [coinbase, maker, edMaker, edFrontRunner] = accounts;
+// weth = await deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS);
+// zrx = await deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS);
+// const accountLevels = await deployer.deployAsync(ContractName.AccountLevels);
+// const edAdminAddress = accounts[0];
+// const edMakerFee = 0;
+// const edTakerFee = 0;
+// const edFeeRebate = 0;
+// const etherDeltaInstance = await deployer.deployAsync(ContractName.EtherDelta, [
+// edAdminAddress,
+// feeRecipient,
+// accountLevels.address,
+// edMakerFee,
+// edTakerFee,
+// edFeeRebate,
+// ]);
+// etherDelta = new EtherDeltaContract(etherDeltaInstance.abi, etherDeltaInstance.address, provider);
+// const tokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy);
+// const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [
+// zrx.address,
+// tokenTransferProxy.address,
+// ]);
+// await tokenTransferProxy.addAuthorizedAddress(exchangeInstance.address, { from: accounts[0] });
+// zeroEx = new ZeroEx(provider, {
+// exchangeContractAddress: exchangeInstance.address,
+// networkId: constants.TESTRPC_NETWORK_ID,
+// });
+// const exchange = new ExchangeContract(exchangeInstance.abi, exchangeInstance.address, provider);
+// exWrapper = new ExchangeWrapper(exchange, zeroEx);
- makerTokenAmount = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18);
- takerTokenAmount = makerTokenAmount;
- const defaultOrderParams = {
- exchangeContractAddress: exchange.address,
- maker,
- feeRecipient,
- makerTokenAddress: zrx.address,
- takerTokenAddress: weth.address,
- makerTokenAmount,
- takerTokenAmount,
- makerFee: new BigNumber(0),
- takerFee: new BigNumber(0),
- };
- orderFactory = new OrderFactory(zeroEx, defaultOrderParams);
- const arbitrageInstance = await deployer.deployAsync(ContractName.Arbitrage, [
- exchange.address,
- etherDelta.address,
- tokenTransferProxy.address,
- ]);
- arbitrage = new ArbitrageContract(arbitrageInstance.abi, arbitrageInstance.address, provider);
- // Enable arbitrage and withdrawals of tokens
- await arbitrage.setAllowances.sendTransactionAsync(weth.address, { from: coinbase });
- await arbitrage.setAllowances.sendTransactionAsync(zrx.address, { from: coinbase });
+// makerTokenAmount = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18);
+// takerTokenAmount = makerTokenAmount;
+// const defaultOrderParams = {
+// exchangeContractAddress: exchange.address,
+// maker,
+// feeRecipient,
+// makerTokenAddress: zrx.address,
+// takerTokenAddress: weth.address,
+// makerTokenAmount,
+// takerTokenAmount,
+// makerFee: new BigNumber(0),
+// takerFee: new BigNumber(0),
+// };
+// orderFactory = new OrderFactory(zeroEx, defaultOrderParams);
+// const arbitrageInstance = await deployer.deployAsync(ContractName.Arbitrage, [
+// exchange.address,
+// etherDelta.address,
+// tokenTransferProxy.address,
+// ]);
+// arbitrage = new ArbitrageContract(arbitrageInstance.abi, arbitrageInstance.address, provider);
+// // Enable arbitrage and withdrawals of tokens
+// await arbitrage.setAllowances.sendTransactionAsync(weth.address, { from: coinbase });
+// await arbitrage.setAllowances.sendTransactionAsync(zrx.address, { from: coinbase });
- // Give some tokens to arbitrage contract
- await weth.setBalance(arbitrage.address, takerTokenAmount, { from: coinbase });
+// // Give some tokens to arbitrage contract
+// await weth.setBalance(arbitrage.address, takerTokenAmount, { from: coinbase });
- // Fund the maker on exchange side
- await zrx.setBalance(maker, makerTokenAmount, { from: coinbase });
- // Set the allowance for the maker on Exchange side
- await zrx.approve(tokenTransferProxy.address, INITIAL_ALLOWANCE, { from: maker });
+// // Fund the maker on exchange side
+// await zrx.setBalance(maker, makerTokenAmount, { from: coinbase });
+// // Set the allowance for the maker on Exchange side
+// await zrx.approve(tokenTransferProxy.address, INITIAL_ALLOWANCE, { from: maker });
- amountGive = ZeroEx.toBaseUnitAmount(new BigNumber(2), 18);
- // Fund the maker on EtherDelta side
- await weth.setBalance(edMaker, amountGive, { from: coinbase });
- // Set the allowance for the maker on EtherDelta side
- await weth.approve(etherDelta.address, INITIAL_ALLOWANCE, { from: edMaker });
- // Deposit maker funds into EtherDelta
- await etherDelta.depositToken.sendTransactionAsync(weth.address, amountGive, { from: edMaker });
+// amountGive = ZeroEx.toBaseUnitAmount(new BigNumber(2), 18);
+// // Fund the maker on EtherDelta side
+// await weth.setBalance(edMaker, amountGive, { from: coinbase });
+// // Set the allowance for the maker on EtherDelta side
+// await weth.approve(etherDelta.address, INITIAL_ALLOWANCE, { from: edMaker });
+// // Deposit maker funds into EtherDelta
+// await etherDelta.depositToken.sendTransactionAsync(weth.address, amountGive, { from: edMaker });
- amountGet = makerTokenAmount;
- // Fund the front runner on EtherDelta side
- await zrx.setBalance(edFrontRunner, amountGet, { from: coinbase });
- // Set the allowance for the front-runner on EtherDelta side
- await zrx.approve(etherDelta.address, INITIAL_ALLOWANCE, { from: edFrontRunner });
- // Deposit front runner funds into EtherDelta
- await etherDelta.depositToken.sendTransactionAsync(zrx.address, amountGet, { from: edFrontRunner });
- });
- beforeEach(async () => {
- await blockchainLifecycle.startAsync();
- });
- afterEach(async () => {
- await blockchainLifecycle.revertAsync();
- });
- describe('makeAtomicTrade', () => {
- let addresses: string[];
- let values: BigNumber[];
- let v: number[];
- let r: string[];
- let s: string[];
- let tokenGet: string;
- let tokenGive: string;
- let expires: BigNumber;
- let nonce: BigNumber;
- let edSignature: ECSignature;
- before(async () => {
- signedOrder = await orderFactory.newSignedOrderAsync();
- tokenGet = zrx.address;
- tokenGive = weth.address;
- const blockNumber = await web3Wrapper.getBlockNumberAsync();
- const ED_ORDER_EXPIRATION_IN_BLOCKS = 10;
- expires = new BigNumber(blockNumber + ED_ORDER_EXPIRATION_IN_BLOCKS);
- nonce = new BigNumber(42);
- const edOrderHash = `0x${crypto
- .solSHA256([etherDelta.address, tokenGet, amountGet, tokenGive, amountGive, expires, nonce])
- .toString('hex')}`;
- const shouldAddPersonalMessagePrefix = false;
- edSignature = await zeroEx.signOrderHashAsync(edOrderHash, edMaker, shouldAddPersonalMessagePrefix);
- addresses = [
- signedOrder.maker,
- signedOrder.taker,
- signedOrder.makerTokenAddress,
- signedOrder.takerTokenAddress,
- signedOrder.feeRecipient,
- edMaker,
- ];
- const fillTakerTokenAmount = takerTokenAmount;
- const edFillAmount = makerTokenAmount;
- values = [
- signedOrder.makerTokenAmount,
- signedOrder.takerTokenAmount,
- signedOrder.makerFee,
- signedOrder.takerFee,
- signedOrder.expirationUnixTimestampSec,
- signedOrder.salt,
- fillTakerTokenAmount,
- amountGet,
- amountGive,
- expires,
- nonce,
- edFillAmount,
- ];
- v = [signedOrder.ecSignature.v, edSignature.v];
- r = [signedOrder.ecSignature.r, edSignature.r];
- s = [signedOrder.ecSignature.s, edSignature.s];
- });
- it('should successfully execute the arbitrage if not front-runned', async () => {
- const txHash = await arbitrage.makeAtomicTrade.sendTransactionAsync(addresses, values, v, r, s, {
- from: coinbase,
- });
- const res = await zeroEx.awaitTransactionMinedAsync(txHash);
- const postBalance = await weth.balanceOf(arbitrage.address);
- expect(postBalance).to.be.bignumber.equal(amountGive);
- });
- it('should fail and revert if front-runned', async () => {
- const preBalance = await weth.balanceOf(arbitrage.address);
- // Front-running transaction
- await etherDelta.trade.sendTransactionAsync(
- tokenGet,
- amountGet,
- tokenGive,
- amountGive,
- expires,
- nonce,
- edMaker,
- edSignature.v,
- edSignature.r,
- edSignature.s,
- amountGet,
- { from: edFrontRunner },
- );
- // tslint:disable-next-line:await-promise
- await expect(
- arbitrage.makeAtomicTrade.sendTransactionAsync(addresses, values, v, r, s, { from: coinbase }),
- ).to.be.rejectedWith(constants.REVERT);
- const postBalance = await weth.balanceOf(arbitrage.address);
- expect(preBalance).to.be.bignumber.equal(postBalance);
- });
- });
-});
+// amountGet = makerTokenAmount;
+// // Fund the front runner on EtherDelta side
+// await zrx.setBalance(edFrontRunner, amountGet, { from: coinbase });
+// // Set the allowance for the front-runner on EtherDelta side
+// await zrx.approve(etherDelta.address, INITIAL_ALLOWANCE, { from: edFrontRunner });
+// // Deposit front runner funds into EtherDelta
+// await etherDelta.depositToken.sendTransactionAsync(zrx.address, amountGet, { from: edFrontRunner });
+// });
+// beforeEach(async () => {
+// await blockchainLifecycle.startAsync();
+// });
+// afterEach(async () => {
+// await blockchainLifecycle.revertAsync();
+// });
+// describe('makeAtomicTrade', () => {
+// let addresses: string[];
+// let values: BigNumber[];
+// let v: number[];
+// let r: string[];
+// let s: string[];
+// let tokenGet: string;
+// let tokenGive: string;
+// let expires: BigNumber;
+// let nonce: BigNumber;
+// let edSignature: ECSignature;
+// before(async () => {
+// signedOrder = await orderFactory.newSignedOrderAsync();
+// tokenGet = zrx.address;
+// tokenGive = weth.address;
+// const blockNumber = await web3Wrapper.getBlockNumberAsync();
+// const ED_ORDER_EXPIRATION_IN_BLOCKS = 10;
+// expires = new BigNumber(blockNumber + ED_ORDER_EXPIRATION_IN_BLOCKS);
+// nonce = new BigNumber(42);
+// const edOrderHash = `0x${crypto
+// .solSHA256([etherDelta.address, tokenGet, amountGet, tokenGive, amountGive, expires, nonce])
+// .toString('hex')}`;
+// const shouldAddPersonalMessagePrefix = false;
+// edSignature = await zeroEx.signOrderHashAsync(edOrderHash, edMaker, shouldAddPersonalMessagePrefix);
+// addresses = [
+// signedOrder.maker,
+// signedOrder.taker,
+// signedOrder.makerTokenAddress,
+// signedOrder.takerTokenAddress,
+// signedOrder.feeRecipient,
+// edMaker,
+// ];
+// const fillTakerTokenAmount = takerTokenAmount;
+// const edFillAmount = makerTokenAmount;
+// values = [
+// signedOrder.makerTokenAmount,
+// signedOrder.takerTokenAmount,
+// signedOrder.makerFee,
+// signedOrder.takerFee,
+// signedOrder.expirationUnixTimestampSec,
+// signedOrder.salt,
+// fillTakerTokenAmount,
+// amountGet,
+// amountGive,
+// expires,
+// nonce,
+// edFillAmount,
+// ];
+// v = [signedOrder.ecSignature.v, edSignature.v];
+// r = [signedOrder.ecSignature.r, edSignature.r];
+// s = [signedOrder.ecSignature.s, edSignature.s];
+// });
+// it('should successfully execute the arbitrage if not front-runned', async () => {
+// const txHash = await arbitrage.makeAtomicTrade.sendTransactionAsync(addresses, values, v, r, s, {
+// from: coinbase,
+// });
+// const res = await zeroEx.awaitTransactionMinedAsync(txHash);
+// const postBalance = await weth.balanceOf(arbitrage.address);
+// expect(postBalance).to.be.bignumber.equal(amountGive);
+// });
+// it('should fail and revert if front-runned', async () => {
+// const preBalance = await weth.balanceOf(arbitrage.address);
+// // Front-running transaction
+// await etherDelta.trade.sendTransactionAsync(
+// tokenGet,
+// amountGet,
+// tokenGive,
+// amountGive,
+// expires,
+// nonce,
+// edMaker,
+// edSignature.v,
+// edSignature.r,
+// edSignature.s,
+// amountGet,
+// { from: edFrontRunner },
+// );
+// // tslint:disable-next-line:await-promise
+// await expect(
+// arbitrage.makeAtomicTrade.sendTransactionAsync(addresses, values, v, r, s, { from: coinbase }),
+// ).to.be.rejectedWith(constants.REVERT);
+// const postBalance = await weth.balanceOf(arbitrage.address);
+// expect(preBalance).to.be.bignumber.equal(postBalance);
+// });
+// });
+// });