diff options
Diffstat (limited to 'packages/contracts/test/exchange/wrapper.ts')
-rw-r--r-- | packages/contracts/test/exchange/wrapper.ts | 400 |
1 files changed, 194 insertions, 206 deletions
diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts index b87f45387..00e703b2f 100644 --- a/packages/contracts/test/exchange/wrapper.ts +++ b/packages/contracts/test/exchange/wrapper.ts @@ -85,10 +85,10 @@ describe('Exchange', () => { feeRecipientAddress, makerTokenAddress: rep.address, takerTokenAddress: dgd.address, - makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), - takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18), - makerFeeAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18), - takerFeeAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18), + makerSellAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), + makerBuyAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18), + makerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18), + takerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18), }; const privateKey = constants.TESTRPC_PRIVATE_KEYS[0]; @@ -119,45 +119,45 @@ describe('Exchange', () => { describe('fillOrKillOrder', () => { it('should transfer the correct amounts', async () => { const signedOrder = orderFactory.newSignedOrder({ - makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), - takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18), + makerSellAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), + makerBuyAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18), }); - const takerTokenFillAmount = signedOrder.takerTokenAmount.div(2); + const takerSellAmount = signedOrder.makerBuyAmount.div(2); await exWrapper.fillOrKillOrderAsync(signedOrder, takerAddress, { - takerTokenFillAmount, + takerSellAmount, }); const newBalances = await dmyBalances.getAsync(); - const makerTokenFillAmount = takerTokenFillAmount - .times(signedOrder.makerTokenAmount) - .dividedToIntegerBy(signedOrder.takerTokenAmount); - const makerFeeAmount = signedOrder.makerFeeAmount - .times(makerTokenFillAmount) - .dividedToIntegerBy(signedOrder.makerTokenAmount); - const takerFeeAmount = signedOrder.takerFeeAmount - .times(makerTokenFillAmount) - .dividedToIntegerBy(signedOrder.makerTokenAmount); + const makerAmountSold = takerSellAmount + .times(signedOrder.makerSellAmount) + .dividedToIntegerBy(signedOrder.makerBuyAmount); + const makerFee = signedOrder.makerFee + .times(makerAmountSold) + .dividedToIntegerBy(signedOrder.makerSellAmount); + const takerFee = signedOrder.takerFee + .times(makerAmountSold) + .dividedToIntegerBy(signedOrder.makerSellAmount); expect(newBalances[makerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal( - balances[makerAddress][signedOrder.makerTokenAddress].minus(makerTokenFillAmount), + balances[makerAddress][signedOrder.makerTokenAddress].minus(makerAmountSold), ); expect(newBalances[makerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal( - balances[makerAddress][signedOrder.takerTokenAddress].add(takerTokenFillAmount), + balances[makerAddress][signedOrder.takerTokenAddress].add(takerSellAmount), ); expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal( - balances[makerAddress][zrx.address].minus(makerFeeAmount), + balances[makerAddress][zrx.address].minus(makerFee), ); expect(newBalances[takerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal( - balances[takerAddress][signedOrder.takerTokenAddress].minus(takerTokenFillAmount), + balances[takerAddress][signedOrder.takerTokenAddress].minus(takerSellAmount), ); expect(newBalances[takerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal( - balances[takerAddress][signedOrder.makerTokenAddress].add(makerTokenFillAmount), + balances[takerAddress][signedOrder.makerTokenAddress].add(makerAmountSold), ); expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal( - balances[takerAddress][zrx.address].minus(takerFeeAmount), + balances[takerAddress][zrx.address].minus(takerFee), ); expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal( - balances[feeRecipientAddress][zrx.address].add(makerFeeAmount.add(takerFeeAmount)), + balances[feeRecipientAddress][zrx.address].add(makerFee.add(takerFee)), ); }); @@ -171,11 +171,11 @@ describe('Exchange', () => { ); }); - it('should throw if entire takerTokenFillAmount not filled', async () => { + it('should throw if entire takerSellAmount not filled', async () => { const signedOrder = orderFactory.newSignedOrder(); await exWrapper.fillOrderAsync(signedOrder, takerAddress, { - takerTokenFillAmount: signedOrder.takerTokenAmount.div(2), + takerSellAmount: signedOrder.makerBuyAmount.div(2), }); return expect(exWrapper.fillOrKillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith( @@ -187,51 +187,51 @@ describe('Exchange', () => { describe('fillOrderNoThrow', () => { it('should transfer the correct amounts', async () => { const signedOrder = orderFactory.newSignedOrder({ - makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), - takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18), + makerSellAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), + makerBuyAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18), }); - const takerTokenFillAmount = signedOrder.takerTokenAmount.div(2); + const takerSellAmount = signedOrder.makerBuyAmount.div(2); await exWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress, { - takerTokenFillAmount, + takerSellAmount, }); const newBalances = await dmyBalances.getAsync(); - const makerTokenFillAmount = takerTokenFillAmount - .times(signedOrder.makerTokenAmount) - .dividedToIntegerBy(signedOrder.takerTokenAmount); - const makerFeeAmount = signedOrder.makerFeeAmount - .times(makerTokenFillAmount) - .dividedToIntegerBy(signedOrder.makerTokenAmount); - const takerFeeAmount = signedOrder.takerFeeAmount - .times(makerTokenFillAmount) - .dividedToIntegerBy(signedOrder.makerTokenAmount); + const makerAmountSold = takerSellAmount + .times(signedOrder.makerSellAmount) + .dividedToIntegerBy(signedOrder.makerBuyAmount); + const makerFee = signedOrder.makerFee + .times(makerAmountSold) + .dividedToIntegerBy(signedOrder.makerSellAmount); + const takerFee = signedOrder.takerFee + .times(makerAmountSold) + .dividedToIntegerBy(signedOrder.makerSellAmount); expect(newBalances[makerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal( - balances[makerAddress][signedOrder.makerTokenAddress].minus(makerTokenFillAmount), + balances[makerAddress][signedOrder.makerTokenAddress].minus(makerAmountSold), ); expect(newBalances[makerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal( - balances[makerAddress][signedOrder.takerTokenAddress].add(takerTokenFillAmount), + balances[makerAddress][signedOrder.takerTokenAddress].add(takerSellAmount), ); expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal( - balances[makerAddress][zrx.address].minus(makerFeeAmount), + balances[makerAddress][zrx.address].minus(makerFee), ); expect(newBalances[takerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal( - balances[takerAddress][signedOrder.takerTokenAddress].minus(takerTokenFillAmount), + balances[takerAddress][signedOrder.takerTokenAddress].minus(takerSellAmount), ); expect(newBalances[takerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal( - balances[takerAddress][signedOrder.makerTokenAddress].add(makerTokenFillAmount), + balances[takerAddress][signedOrder.makerTokenAddress].add(makerAmountSold), ); expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal( - balances[takerAddress][zrx.address].minus(takerFeeAmount), + balances[takerAddress][zrx.address].minus(takerFee), ); expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal( - balances[feeRecipientAddress][zrx.address].add(makerFeeAmount.add(takerFeeAmount)), + balances[feeRecipientAddress][zrx.address].add(makerFee.add(takerFee)), ); }); it('should not change balances if maker balances are too low to fill order', async () => { const signedOrder = orderFactory.newSignedOrder({ - makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18), + makerSellAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18), }); await exWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress); @@ -241,7 +241,7 @@ describe('Exchange', () => { it('should not change balances if taker balances are too low to fill order', async () => { const signedOrder = orderFactory.newSignedOrder({ - takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18), + makerBuyAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18), }); await exWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress); @@ -277,48 +277,48 @@ describe('Exchange', () => { expect(newBalances).to.be.deep.equal(balances); }); - it('should not change balances if makerTokenAddress is ZRX, makerTokenAmount + makerFee > maker balance', async () => { + it('should not change balances if makerTokenAddress is ZRX, makerSellAmount + makerFee > maker balance', async () => { const makerZRXBalance = new BigNumber(balances[makerAddress][zrx.address]); const signedOrder = orderFactory.newSignedOrder({ makerTokenAddress: zrx.address, - makerTokenAmount: makerZRXBalance, - makerFeeAmount: new BigNumber(1), + makerSellAmount: makerZRXBalance, + makerFee: new BigNumber(1), }); await exWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress); const newBalances = await dmyBalances.getAsync(); expect(newBalances).to.be.deep.equal(balances); }); - it('should not change balances if makerTokenAddress is ZRX, makerTokenAmount + makerFee > maker allowance', async () => { + it('should not change balances if makerTokenAddress is ZRX, makerSellAmount + makerFee > maker allowance', async () => { const makerZRXAllowance = await zrx.allowance.callAsync(makerAddress, tokenTransferProxy.address); const signedOrder = orderFactory.newSignedOrder({ makerTokenAddress: zrx.address, - makerTokenAmount: new BigNumber(makerZRXAllowance), - makerFeeAmount: new BigNumber(1), + makerSellAmount: new BigNumber(makerZRXAllowance), + makerFee: new BigNumber(1), }); await exWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress); const newBalances = await dmyBalances.getAsync(); expect(newBalances).to.be.deep.equal(balances); }); - it('should not change balances if takerTokenAddress is ZRX, takerTokenAmount + takerFee > taker balance', async () => { + it('should not change balances if takerTokenAddress is ZRX, makerBuyAmount + takerFee > taker balance', async () => { const takerZRXBalance = new BigNumber(balances[takerAddress][zrx.address]); const signedOrder = orderFactory.newSignedOrder({ takerTokenAddress: zrx.address, - takerTokenAmount: takerZRXBalance, - takerFeeAmount: new BigNumber(1), + makerBuyAmount: takerZRXBalance, + takerFee: new BigNumber(1), }); await exWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress); const newBalances = await dmyBalances.getAsync(); expect(newBalances).to.be.deep.equal(balances); }); - it('should not change balances if takerTokenAddress is ZRX, takerTokenAmount + takerFee > taker allowance', async () => { + it('should not change balances if takerTokenAddress is ZRX, makerBuyAmount + takerFee > taker allowance', async () => { const takerZRXAllowance = await zrx.allowance.callAsync(takerAddress, tokenTransferProxy.address); const signedOrder = orderFactory.newSignedOrder({ takerTokenAddress: zrx.address, - takerTokenAmount: new BigNumber(takerZRXAllowance), - takerFeeAmount: new BigNumber(1), + makerBuyAmount: new BigNumber(takerZRXAllowance), + takerFee: new BigNumber(1), }); await exWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress); const newBalances = await dmyBalances.getAsync(); @@ -338,42 +338,42 @@ describe('Exchange', () => { describe('batchFillOrders', () => { it('should transfer the correct amounts', async () => { - const takerTokenFillAmounts: BigNumber[] = []; + const takerSellAmounts: BigNumber[] = []; const makerTokenAddress = rep.address; const takerTokenAddress = dgd.address; _.forEach(signedOrders, signedOrder => { - const takerTokenFillAmount = signedOrder.takerTokenAmount.div(2); - const makerTokenFillAmount = takerTokenFillAmount - .times(signedOrder.makerTokenAmount) - .dividedToIntegerBy(signedOrder.takerTokenAmount); - const makerFeeAmount = signedOrder.makerFeeAmount - .times(makerTokenFillAmount) - .dividedToIntegerBy(signedOrder.makerTokenAmount); - const takerFeeAmount = signedOrder.takerFeeAmount - .times(makerTokenFillAmount) - .dividedToIntegerBy(signedOrder.makerTokenAmount); - takerTokenFillAmounts.push(takerTokenFillAmount); + const takerSellAmount = signedOrder.makerBuyAmount.div(2); + const makerAmountSold = takerSellAmount + .times(signedOrder.makerSellAmount) + .dividedToIntegerBy(signedOrder.makerBuyAmount); + const makerFee = signedOrder.makerFee + .times(makerAmountSold) + .dividedToIntegerBy(signedOrder.makerSellAmount); + const takerFee = signedOrder.takerFee + .times(makerAmountSold) + .dividedToIntegerBy(signedOrder.makerSellAmount); + takerSellAmounts.push(takerSellAmount); balances[makerAddress][makerTokenAddress] = balances[makerAddress][makerTokenAddress].minus( - makerTokenFillAmount, + makerAmountSold, ); balances[makerAddress][takerTokenAddress] = balances[makerAddress][takerTokenAddress].add( - takerTokenFillAmount, + takerSellAmount, ); - balances[makerAddress][zrx.address] = balances[makerAddress][zrx.address].minus(makerFeeAmount); + balances[makerAddress][zrx.address] = balances[makerAddress][zrx.address].minus(makerFee); balances[takerAddress][makerTokenAddress] = balances[takerAddress][makerTokenAddress].add( - makerTokenFillAmount, + makerAmountSold, ); balances[takerAddress][takerTokenAddress] = balances[takerAddress][takerTokenAddress].minus( - takerTokenFillAmount, + takerSellAmount, ); - balances[takerAddress][zrx.address] = balances[takerAddress][zrx.address].minus(takerFeeAmount); + balances[takerAddress][zrx.address] = balances[takerAddress][zrx.address].minus(takerFee); balances[feeRecipientAddress][zrx.address] = balances[feeRecipientAddress][zrx.address].add( - makerFeeAmount.add(takerFeeAmount), + makerFee.add(takerFee), ); }); await exWrapper.batchFillOrdersAsync(signedOrders, takerAddress, { - takerTokenFillAmounts, + takerSellAmounts, }); const newBalances = await dmyBalances.getAsync(); @@ -383,33 +383,33 @@ describe('Exchange', () => { describe('batchFillOrKillOrders', () => { it('should transfer the correct amounts', async () => { - const takerTokenFillAmounts: BigNumber[] = []; + const takerSellAmounts: BigNumber[] = []; const makerTokenAddress = rep.address; const takerTokenAddress = dgd.address; _.forEach(signedOrders, signedOrder => { - const takerTokenFillAmount = signedOrder.takerTokenAmount.div(2); - const makerTokenFillAmount = takerTokenFillAmount - .times(signedOrder.makerTokenAmount) - .dividedToIntegerBy(signedOrder.takerTokenAmount); - const makerFee = signedOrder.makerFeeAmount - .times(makerTokenFillAmount) - .dividedToIntegerBy(signedOrder.makerTokenAmount); - const takerFee = signedOrder.takerFeeAmount - .times(makerTokenFillAmount) - .dividedToIntegerBy(signedOrder.makerTokenAmount); - takerTokenFillAmounts.push(takerTokenFillAmount); + const takerSellAmount = signedOrder.makerBuyAmount.div(2); + const makerAmountSold = takerSellAmount + .times(signedOrder.makerSellAmount) + .dividedToIntegerBy(signedOrder.makerBuyAmount); + const makerFee = signedOrder.makerFee + .times(makerAmountSold) + .dividedToIntegerBy(signedOrder.makerSellAmount); + const takerFee = signedOrder.takerFee + .times(makerAmountSold) + .dividedToIntegerBy(signedOrder.makerSellAmount); + takerSellAmounts.push(takerSellAmount); balances[makerAddress][makerTokenAddress] = balances[makerAddress][makerTokenAddress].minus( - makerTokenFillAmount, + makerAmountSold, ); balances[makerAddress][takerTokenAddress] = balances[makerAddress][takerTokenAddress].add( - takerTokenFillAmount, + takerSellAmount, ); balances[makerAddress][zrx.address] = balances[makerAddress][zrx.address].minus(makerFee); balances[takerAddress][makerTokenAddress] = balances[takerAddress][makerTokenAddress].add( - makerTokenFillAmount, + makerAmountSold, ); balances[takerAddress][takerTokenAddress] = balances[takerAddress][takerTokenAddress].minus( - takerTokenFillAmount, + takerSellAmount, ); balances[takerAddress][zrx.address] = balances[takerAddress][zrx.address].minus(takerFee); balances[feeRecipientAddress][zrx.address] = balances[feeRecipientAddress][zrx.address].add( @@ -418,7 +418,7 @@ describe('Exchange', () => { }); await exWrapper.batchFillOrKillOrdersAsync(signedOrders, takerAddress, { - takerTokenFillAmounts, + takerSellAmounts, }); const newBalances = await dmyBalances.getAsync(); @@ -426,17 +426,17 @@ describe('Exchange', () => { }); it('should throw if a single signedOrder does not fill the expected amount', async () => { - const takerTokenFillAmounts: BigNumber[] = []; + const takerSellAmounts: BigNumber[] = []; _.forEach(signedOrders, signedOrder => { - const takerTokenFillAmount = signedOrder.takerTokenAmount.div(2); - takerTokenFillAmounts.push(takerTokenFillAmount); + const takerSellAmount = signedOrder.makerBuyAmount.div(2); + takerSellAmounts.push(takerSellAmount); }); await exWrapper.fillOrKillOrderAsync(signedOrders[0], takerAddress); return expect( exWrapper.batchFillOrKillOrdersAsync(signedOrders, takerAddress, { - takerTokenFillAmounts, + takerSellAmounts, }), ).to.be.rejectedWith(constants.REVERT); }); @@ -444,42 +444,42 @@ describe('Exchange', () => { describe('batchFillOrdersNoThrow', async () => { it('should transfer the correct amounts', async () => { - const takerTokenFillAmounts: BigNumber[] = []; + const takerSellAmounts: BigNumber[] = []; const makerTokenAddress = rep.address; const takerTokenAddress = dgd.address; _.forEach(signedOrders, signedOrder => { - const takerTokenFillAmount = signedOrder.takerTokenAmount.div(2); - const makerTokenFillAmount = takerTokenFillAmount - .times(signedOrder.makerTokenAmount) - .dividedToIntegerBy(signedOrder.takerTokenAmount); - const makerFeeAmount = signedOrder.makerFeeAmount - .times(makerTokenFillAmount) - .dividedToIntegerBy(signedOrder.makerTokenAmount); - const takerFeeAmount = signedOrder.takerFeeAmount - .times(makerTokenFillAmount) - .dividedToIntegerBy(signedOrder.makerTokenAmount); - takerTokenFillAmounts.push(takerTokenFillAmount); + const takerSellAmount = signedOrder.makerBuyAmount.div(2); + const makerAmountSold = takerSellAmount + .times(signedOrder.makerSellAmount) + .dividedToIntegerBy(signedOrder.makerBuyAmount); + const makerFee = signedOrder.makerFee + .times(makerAmountSold) + .dividedToIntegerBy(signedOrder.makerSellAmount); + const takerFee = signedOrder.takerFee + .times(makerAmountSold) + .dividedToIntegerBy(signedOrder.makerSellAmount); + takerSellAmounts.push(takerSellAmount); balances[makerAddress][makerTokenAddress] = balances[makerAddress][makerTokenAddress].minus( - makerTokenFillAmount, + makerAmountSold, ); balances[makerAddress][takerTokenAddress] = balances[makerAddress][takerTokenAddress].add( - takerTokenFillAmount, + takerSellAmount, ); - balances[makerAddress][zrx.address] = balances[makerAddress][zrx.address].minus(makerFeeAmount); + balances[makerAddress][zrx.address] = balances[makerAddress][zrx.address].minus(makerFee); balances[takerAddress][makerTokenAddress] = balances[takerAddress][makerTokenAddress].add( - makerTokenFillAmount, + makerAmountSold, ); balances[takerAddress][takerTokenAddress] = balances[takerAddress][takerTokenAddress].minus( - takerTokenFillAmount, + takerSellAmount, ); - balances[takerAddress][zrx.address] = balances[takerAddress][zrx.address].minus(takerFeeAmount); + balances[takerAddress][zrx.address] = balances[takerAddress][zrx.address].minus(takerFee); balances[feeRecipientAddress][zrx.address] = balances[feeRecipientAddress][zrx.address].add( - makerFeeAmount.add(takerFeeAmount), + makerFee.add(takerFee), ); }); await exWrapper.batchFillOrdersNoThrowAsync(signedOrders, takerAddress, { - takerTokenFillAmounts, + takerSellAmounts, }); const newBalances = await dmyBalances.getAsync(); @@ -487,7 +487,7 @@ describe('Exchange', () => { }); it('should not throw if an order is invalid and fill the remaining orders', async () => { - const takerTokenFillAmounts: BigNumber[] = []; + const takerSellAmounts: BigNumber[] = []; const makerTokenAddress = rep.address; const takerTokenAddress = dgd.address; @@ -497,41 +497,41 @@ describe('Exchange', () => { }; const validOrders = signedOrders.slice(1); - takerTokenFillAmounts.push(invalidOrder.takerTokenAmount.div(2)); + takerSellAmounts.push(invalidOrder.makerBuyAmount.div(2)); _.forEach(validOrders, signedOrder => { - const takerTokenFillAmount = signedOrder.takerTokenAmount.div(2); - const makerTokenFillAmount = takerTokenFillAmount - .times(signedOrder.makerTokenAmount) - .dividedToIntegerBy(signedOrder.takerTokenAmount); - const makerFeeAmount = signedOrder.makerFeeAmount - .times(makerTokenFillAmount) - .dividedToIntegerBy(signedOrder.makerTokenAmount); - const takerFeeAmount = signedOrder.takerFeeAmount - .times(makerTokenFillAmount) - .dividedToIntegerBy(signedOrder.makerTokenAmount); - takerTokenFillAmounts.push(takerTokenFillAmount); + const takerSellAmount = signedOrder.makerBuyAmount.div(2); + const makerAmountSold = takerSellAmount + .times(signedOrder.makerSellAmount) + .dividedToIntegerBy(signedOrder.makerBuyAmount); + const makerFee = signedOrder.makerFee + .times(makerAmountSold) + .dividedToIntegerBy(signedOrder.makerSellAmount); + const takerFee = signedOrder.takerFee + .times(makerAmountSold) + .dividedToIntegerBy(signedOrder.makerSellAmount); + takerSellAmounts.push(takerSellAmount); balances[makerAddress][makerTokenAddress] = balances[makerAddress][makerTokenAddress].minus( - makerTokenFillAmount, + makerAmountSold, ); balances[makerAddress][takerTokenAddress] = balances[makerAddress][takerTokenAddress].add( - takerTokenFillAmount, + takerSellAmount, ); - balances[makerAddress][zrx.address] = balances[makerAddress][zrx.address].minus(makerFeeAmount); + balances[makerAddress][zrx.address] = balances[makerAddress][zrx.address].minus(makerFee); balances[takerAddress][makerTokenAddress] = balances[takerAddress][makerTokenAddress].add( - makerTokenFillAmount, + makerAmountSold, ); balances[takerAddress][takerTokenAddress] = balances[takerAddress][takerTokenAddress].minus( - takerTokenFillAmount, + takerSellAmount, ); - balances[takerAddress][zrx.address] = balances[takerAddress][zrx.address].minus(takerFeeAmount); + balances[takerAddress][zrx.address] = balances[takerAddress][zrx.address].minus(takerFee); balances[feeRecipientAddress][zrx.address] = balances[feeRecipientAddress][zrx.address].add( - makerFeeAmount.add(takerFeeAmount), + makerFee.add(takerFee), ); }); const newOrders = [invalidOrder, ...validOrders]; await exWrapper.batchFillOrdersNoThrowAsync(newOrders, takerAddress, { - takerTokenFillAmounts, + takerSellAmounts, }); const newBalances = await dmyBalances.getAsync(); @@ -540,39 +540,33 @@ describe('Exchange', () => { }); describe('marketFillOrders', () => { - it('should stop when the entire takerTokenFillAmount is filled', async () => { - const takerTokenFillAmount = signedOrders[0].takerTokenAmount.plus( - signedOrders[1].takerTokenAmount.div(2), - ); - await exWrapper.marketFillOrdersAsync(signedOrders, takerAddress, { - takerTokenFillAmount, + it('should stop when the entire takerSellAmount is filled', async () => { + const takerSellAmount = signedOrders[0].makerBuyAmount.plus(signedOrders[1].makerBuyAmount.div(2)); + await exWrapper.marketSellOrdersAsync(signedOrders, takerAddress, { + takerSellAmount, }); const newBalances = await dmyBalances.getAsync(); - const makerTokenFillAmount = signedOrders[0].makerTokenAmount.add( - signedOrders[1].makerTokenAmount.dividedToIntegerBy(2), - ); - const makerFee = signedOrders[0].makerFeeAmount.add( - signedOrders[1].makerFeeAmount.dividedToIntegerBy(2), - ); - const takerFee = signedOrders[0].takerFeeAmount.add( - signedOrders[1].takerFeeAmount.dividedToIntegerBy(2), + const makerAmountSold = signedOrders[0].makerSellAmount.add( + signedOrders[1].makerSellAmount.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[makerAddress][signedOrders[0].makerTokenAddress]).to.be.bignumber.equal( - balances[makerAddress][signedOrders[0].makerTokenAddress].minus(makerTokenFillAmount), + balances[makerAddress][signedOrders[0].makerTokenAddress].minus(makerAmountSold), ); expect(newBalances[makerAddress][signedOrders[0].takerTokenAddress]).to.be.bignumber.equal( - balances[makerAddress][signedOrders[0].takerTokenAddress].add(takerTokenFillAmount), + balances[makerAddress][signedOrders[0].takerTokenAddress].add(takerSellAmount), ); expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal( balances[makerAddress][zrx.address].minus(makerFee), ); expect(newBalances[takerAddress][signedOrders[0].takerTokenAddress]).to.be.bignumber.equal( - balances[takerAddress][signedOrders[0].takerTokenAddress].minus(takerTokenFillAmount), + balances[takerAddress][signedOrders[0].takerTokenAddress].minus(takerSellAmount), ); expect(newBalances[takerAddress][signedOrders[0].makerTokenAddress]).to.be.bignumber.equal( - balances[takerAddress][signedOrders[0].makerTokenAddress].add(makerTokenFillAmount), + balances[takerAddress][signedOrders[0].makerTokenAddress].add(makerAmountSold), ); expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal( balances[takerAddress][zrx.address].minus(takerFee), @@ -582,33 +576,33 @@ describe('Exchange', () => { ); }); - it('should fill all signedOrders if cannot fill entire takerTokenFillAmount', async () => { - const takerTokenFillAmount = ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18); + it('should fill all signedOrders if cannot fill entire takerSellAmount', async () => { + const takerSellAmount = ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18); _.forEach(signedOrders, signedOrder => { balances[makerAddress][signedOrder.makerTokenAddress] = balances[makerAddress][ signedOrder.makerTokenAddress - ].minus(signedOrder.makerTokenAmount); + ].minus(signedOrder.makerSellAmount); balances[makerAddress][signedOrder.takerTokenAddress] = balances[makerAddress][ signedOrder.takerTokenAddress - ].add(signedOrder.takerTokenAmount); + ].add(signedOrder.makerBuyAmount); balances[makerAddress][zrx.address] = balances[makerAddress][zrx.address].minus( - signedOrder.makerFeeAmount, + signedOrder.makerFee, ); balances[takerAddress][signedOrder.makerTokenAddress] = balances[takerAddress][ signedOrder.makerTokenAddress - ].add(signedOrder.makerTokenAmount); + ].add(signedOrder.makerSellAmount); balances[takerAddress][signedOrder.takerTokenAddress] = balances[takerAddress][ signedOrder.takerTokenAddress - ].minus(signedOrder.takerTokenAmount); + ].minus(signedOrder.makerBuyAmount); balances[takerAddress][zrx.address] = balances[takerAddress][zrx.address].minus( - signedOrder.takerFeeAmount, + signedOrder.takerFee, ); balances[feeRecipientAddress][zrx.address] = balances[feeRecipientAddress][zrx.address].add( - signedOrder.makerFeeAmount.add(signedOrder.takerFeeAmount), + signedOrder.makerFee.add(signedOrder.takerFee), ); }); - await exWrapper.marketFillOrdersAsync(signedOrders, takerAddress, { - takerTokenFillAmount, + await exWrapper.marketSellOrdersAsync(signedOrders, takerAddress, { + takerSellAmount, }); const newBalances = await dmyBalances.getAsync(); @@ -623,47 +617,41 @@ describe('Exchange', () => { ]; return expect( - exWrapper.marketFillOrdersAsync(signedOrders, takerAddress, { - takerTokenFillAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1000), 18), + exWrapper.marketSellOrdersAsync(signedOrders, takerAddress, { + takerSellAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1000), 18), }), ).to.be.rejectedWith(constants.REVERT); }); }); describe('marketFillOrdersNoThrow', () => { - it('should stop when the entire takerTokenFillAmount is filled', async () => { - const takerTokenFillAmount = signedOrders[0].takerTokenAmount.plus( - signedOrders[1].takerTokenAmount.div(2), - ); - await exWrapper.marketFillOrdersNoThrowAsync(signedOrders, takerAddress, { - takerTokenFillAmount, + it('should stop when the entire takerSellAmount is filled', async () => { + const takerSellAmount = signedOrders[0].makerBuyAmount.plus(signedOrders[1].makerBuyAmount.div(2)); + await exWrapper.marketSellOrdersNoThrowAsync(signedOrders, takerAddress, { + takerSellAmount, }); const newBalances = await dmyBalances.getAsync(); - const makerTokenFillAmount = signedOrders[0].makerTokenAmount.add( - signedOrders[1].makerTokenAmount.dividedToIntegerBy(2), - ); - const makerFee = signedOrders[0].makerFeeAmount.add( - signedOrders[1].makerFeeAmount.dividedToIntegerBy(2), - ); - const takerFee = signedOrders[0].takerFeeAmount.add( - signedOrders[1].takerFeeAmount.dividedToIntegerBy(2), + const makerAmountSold = signedOrders[0].makerSellAmount.add( + signedOrders[1].makerSellAmount.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[makerAddress][signedOrders[0].makerTokenAddress]).to.be.bignumber.equal( - balances[makerAddress][signedOrders[0].makerTokenAddress].minus(makerTokenFillAmount), + balances[makerAddress][signedOrders[0].makerTokenAddress].minus(makerAmountSold), ); expect(newBalances[makerAddress][signedOrders[0].takerTokenAddress]).to.be.bignumber.equal( - balances[makerAddress][signedOrders[0].takerTokenAddress].add(takerTokenFillAmount), + balances[makerAddress][signedOrders[0].takerTokenAddress].add(takerSellAmount), ); expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal( balances[makerAddress][zrx.address].minus(makerFee), ); expect(newBalances[takerAddress][signedOrders[0].takerTokenAddress]).to.be.bignumber.equal( - balances[takerAddress][signedOrders[0].takerTokenAddress].minus(takerTokenFillAmount), + balances[takerAddress][signedOrders[0].takerTokenAddress].minus(takerSellAmount), ); expect(newBalances[takerAddress][signedOrders[0].makerTokenAddress]).to.be.bignumber.equal( - balances[takerAddress][signedOrders[0].makerTokenAddress].add(makerTokenFillAmount), + balances[takerAddress][signedOrders[0].makerTokenAddress].add(makerAmountSold), ); expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal( balances[takerAddress][zrx.address].minus(takerFee), @@ -673,33 +661,33 @@ describe('Exchange', () => { ); }); - it('should fill all signedOrders if cannot fill entire takerTokenFillAmount', async () => { - const takerTokenFillAmount = ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18); + it('should fill all signedOrders if cannot fill entire takerSellAmount', async () => { + const takerSellAmount = ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18); _.forEach(signedOrders, signedOrder => { balances[makerAddress][signedOrder.makerTokenAddress] = balances[makerAddress][ signedOrder.makerTokenAddress - ].minus(signedOrder.makerTokenAmount); + ].minus(signedOrder.makerSellAmount); balances[makerAddress][signedOrder.takerTokenAddress] = balances[makerAddress][ signedOrder.takerTokenAddress - ].add(signedOrder.takerTokenAmount); + ].add(signedOrder.makerBuyAmount); balances[makerAddress][zrx.address] = balances[makerAddress][zrx.address].minus( - signedOrder.makerFeeAmount, + signedOrder.makerFee, ); balances[takerAddress][signedOrder.makerTokenAddress] = balances[takerAddress][ signedOrder.makerTokenAddress - ].add(signedOrder.makerTokenAmount); + ].add(signedOrder.makerSellAmount); balances[takerAddress][signedOrder.takerTokenAddress] = balances[takerAddress][ signedOrder.takerTokenAddress - ].minus(signedOrder.takerTokenAmount); + ].minus(signedOrder.makerBuyAmount); balances[takerAddress][zrx.address] = balances[takerAddress][zrx.address].minus( - signedOrder.takerFeeAmount, + signedOrder.takerFee, ); balances[feeRecipientAddress][zrx.address] = balances[feeRecipientAddress][zrx.address].add( - signedOrder.makerFeeAmount.add(signedOrder.takerFeeAmount), + signedOrder.makerFee.add(signedOrder.takerFee), ); }); - await exWrapper.marketFillOrdersNoThrowAsync(signedOrders, takerAddress, { - takerTokenFillAmount, + await exWrapper.marketSellOrdersNoThrowAsync(signedOrders, takerAddress, { + takerSellAmount, }); const newBalances = await dmyBalances.getAsync(); @@ -714,8 +702,8 @@ describe('Exchange', () => { ]; return expect( - exWrapper.marketFillOrdersNoThrowAsync(signedOrders, takerAddress, { - takerTokenFillAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1000), 18), + exWrapper.marketSellOrdersNoThrowAsync(signedOrders, takerAddress, { + takerSellAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1000), 18), }), ).to.be.rejectedWith(constants.REVERT); }); @@ -723,11 +711,11 @@ describe('Exchange', () => { describe('batchCancelOrders', () => { it('should be able to cancel multiple signedOrders', async () => { - const takerTokenCancelAmounts = _.map(signedOrders, signedOrder => signedOrder.takerTokenAmount); + const takerTokenCancelAmounts = _.map(signedOrders, signedOrder => signedOrder.makerBuyAmount); await exWrapper.batchCancelOrdersAsync(signedOrders, makerAddress); await exWrapper.batchFillOrdersAsync(signedOrders, takerAddress, { - takerTokenFillAmounts: takerTokenCancelAmounts, + takerSellAmounts: takerTokenCancelAmounts, }); const newBalances = await dmyBalances.getAsync(); expect(balances).to.be.deep.equal(newBalances); |