Return filledAmount from fillOrderAsync
This commit is contained in:
parent
656d74518d
commit
42c61ecda5
@ -27,6 +27,7 @@ import {
|
||||
OrderCancellationRequest,
|
||||
OrderFillRequest,
|
||||
LogErrorContractEventArgs,
|
||||
LogFillContractEventArgs,
|
||||
} from '../types';
|
||||
import {assert} from '../utils/assert';
|
||||
import {utils} from '../utils/utils';
|
||||
@ -144,10 +145,11 @@ export class ExchangeWrapper extends ContractWrapper {
|
||||
* execution the tokens cannot be transferred.
|
||||
* @param takerAddress The user Ethereum address who would like to fill this order.
|
||||
* Must be available via the supplied Web3.Provider passed to 0x.js.
|
||||
* @return The amount of the order (in taker tokens baseUnits) that was filled.
|
||||
*/
|
||||
@decorators.contractCallErrorHandler
|
||||
public async fillOrderAsync(signedOrder: SignedOrder, takerTokenFillAmount: BigNumber.BigNumber,
|
||||
shouldCheckTransfer: boolean, takerAddress: string): Promise<void> {
|
||||
shouldCheckTransfer: boolean, takerAddress: string): Promise<BigNumber.BigNumber> {
|
||||
assert.doesConformToSchema('signedOrder', signedOrder, signedOrderSchema);
|
||||
assert.isBigNumber('takerTokenFillAmount', takerTokenFillAmount);
|
||||
assert.isBoolean('shouldCheckTransfer', shouldCheckTransfer);
|
||||
@ -184,6 +186,9 @@ export class ExchangeWrapper extends ContractWrapper {
|
||||
},
|
||||
);
|
||||
this._throwErrorLogsAsErrors(response.logs);
|
||||
const logFillArgs = response.logs[0].args as LogFillContractEventArgs;
|
||||
const filledAmount = new BigNumber(logFillArgs.filledValueT);
|
||||
return filledAmount;
|
||||
}
|
||||
/**
|
||||
* Sequentially and atomically fills signedOrders up to the specified takerTokenFillAmount.
|
||||
|
@ -339,6 +339,24 @@ describe('ExchangeWrapper', () => {
|
||||
expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, takerAddress))
|
||||
.to.be.bignumber.equal(fillableAmount.minus(partialFillAmount));
|
||||
});
|
||||
it('should return filled amount', async () => {
|
||||
const signedOrder = await fillScenarios.createFillableSignedOrderAsync(
|
||||
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
|
||||
);
|
||||
const partialFillAmount = new BigNumber(3);
|
||||
await zeroEx.exchange.fillOrderAsync(
|
||||
signedOrder, partialFillAmount, shouldCheckTransfer, takerAddress);
|
||||
const missingBalance = new BigNumber(1);
|
||||
const totalBalance = partialFillAmount.plus(missingBalance);
|
||||
await zeroEx.token.transferAsync(takerTokenAddress, coinbase, takerAddress, missingBalance);
|
||||
await zeroEx.token.setProxyAllowanceAsync(takerTokenAddress, takerAddress, totalBalance);
|
||||
await zeroEx.token.transferAsync(makerTokenAddress, coinbase, makerAddress, missingBalance);
|
||||
await zeroEx.token.setProxyAllowanceAsync(makerTokenAddress, makerAddress, totalBalance);
|
||||
const remainingFillAmount = fillableAmount.minus(partialFillAmount);
|
||||
const filledAmount = await zeroEx.exchange.fillOrderAsync(
|
||||
signedOrder, partialFillAmount, shouldCheckTransfer, takerAddress);
|
||||
expect(filledAmount).to.be.bignumber.equal(remainingFillAmount);
|
||||
});
|
||||
it('should fill the valid orders with fees', async () => {
|
||||
const makerFee = new BigNumber(1);
|
||||
const takerFee = new BigNumber(2);
|
||||
|
Loading…
x
Reference in New Issue
Block a user