aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-03-09 07:58:21 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-04-21 04:56:16 +0800
commit2c44c7ea8333dd26e96acd7869ee60cc1d177da4 (patch)
tree4a35f1fd448ab10461bf6f25607d4224cc97b6fc
parent9cc1956b4b25081810680d79b12f80727c96c1ef (diff)
downloaddexon-sol-tools-2c44c7ea8333dd26e96acd7869ee60cc1d177da4.tar
dexon-sol-tools-2c44c7ea8333dd26e96acd7869ee60cc1d177da4.tar.gz
dexon-sol-tools-2c44c7ea8333dd26e96acd7869ee60cc1d177da4.tar.bz2
dexon-sol-tools-2c44c7ea8333dd26e96acd7869ee60cc1d177da4.tar.lz
dexon-sol-tools-2c44c7ea8333dd26e96acd7869ee60cc1d177da4.tar.xz
dexon-sol-tools-2c44c7ea8333dd26e96acd7869ee60cc1d177da4.tar.zst
dexon-sol-tools-2c44c7ea8333dd26e96acd7869ee60cc1d177da4.zip
Add fillOrderNoThrow to exchange wrapper and add test
-rw-r--r--packages/contracts/src/utils/exchange_wrapper.ts21
-rw-r--r--packages/contracts/test/exchange/wrapper.ts54
2 files changed, 69 insertions, 6 deletions
diff --git a/packages/contracts/src/utils/exchange_wrapper.ts b/packages/contracts/src/utils/exchange_wrapper.ts
index 04e6c2feb..9dd414be2 100644
--- a/packages/contracts/src/utils/exchange_wrapper.ts
+++ b/packages/contracts/src/utils/exchange_wrapper.ts
@@ -81,6 +81,27 @@ export class ExchangeWrapper {
});
return tx;
}
+ public async fillOrderNoThrowAsync(
+ signedOrder: SignedOrder,
+ from: string,
+ opts: { takerTokenFillAmount?: BigNumber } = {},
+ ): Promise<TransactionReceiptWithDecodedLogs> {
+ const params = orderUtils.createFill(signedOrder, opts.takerTokenFillAmount);
+ const txHash = await this._exchange.fillOrderNoThrow.sendTransactionAsync(
+ params.order,
+ params.takerTokenFillAmount,
+ params.signature,
+ { from },
+ );
+ const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
+ tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
+ tx.logs = _.map(tx.logs, log => {
+ const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log);
+ wrapLogBigNumbers(logWithDecodedArgs);
+ return logWithDecodedArgs;
+ });
+ return tx;
+ }
public async batchFillOrdersAsync(
orders: SignedOrder[],
from: string,
diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts
index 182578f42..e5933a7e7 100644
--- a/packages/contracts/test/exchange/wrapper.ts
+++ b/packages/contracts/test/exchange/wrapper.ts
@@ -111,15 +111,12 @@ describe('Exchange', () => {
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
+ balances = await dmyBalances.getAsync();
});
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('fillOrKillOrder', () => {
- beforeEach(async () => {
- balances = await dmyBalances.getAsync();
- });
-
it('should transfer the correct amounts', async () => {
const signedOrder = orderFactory.newSignedOrder({
makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
@@ -187,6 +184,52 @@ 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),
+ });
+ const takerTokenFillAmount = signedOrder.takerTokenAmount.div(2);
+ await exWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress, {
+ takerTokenFillAmount,
+ });
+
+ 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);
+ expect(newBalances[makerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrder.makerTokenAddress].minus(makerTokenFillAmount),
+ );
+ expect(newBalances[makerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrder.takerTokenAddress].add(takerTokenFillAmount),
+ );
+ expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[makerAddress][zrx.address].minus(makerFeeAmount),
+ );
+ expect(newBalances[takerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrder.takerTokenAddress].minus(takerTokenFillAmount),
+ );
+ 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)),
+ );
+ });
+ });
+
describe('batch functions', () => {
let signedOrders: SignedOrder[];
beforeEach(async () => {
@@ -195,7 +238,6 @@ describe('Exchange', () => {
orderFactory.newSignedOrder(),
orderFactory.newSignedOrder(),
];
- balances = await dmyBalances.getAsync();
});
describe('batchFillOrders', () => {
@@ -304,7 +346,7 @@ describe('Exchange', () => {
});
});
- describe('fillOrdersUpTo', () => {
+ describe('marketFillOrders', () => {
it('should stop when the entire takerTokenFillAmount is filled', async () => {
const takerTokenFillAmount = signedOrders[0].takerTokenAmount.plus(
signedOrders[1].takerTokenAmount.div(2),