aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-06-06 21:36:07 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-06-06 21:36:07 +0800
commit8aa673aabe292e7d4684f7cc98ec6ef2ea55ca09 (patch)
tree355dfea06c3e9d1489dbcc91e4792aa506c06762 /src
parent403ec236fffb0ed565e7c933d3608b554c007613 (diff)
downloaddexon-sol-tools-8aa673aabe292e7d4684f7cc98ec6ef2ea55ca09.tar
dexon-sol-tools-8aa673aabe292e7d4684f7cc98ec6ef2ea55ca09.tar.gz
dexon-sol-tools-8aa673aabe292e7d4684f7cc98ec6ef2ea55ca09.tar.bz2
dexon-sol-tools-8aa673aabe292e7d4684f7cc98ec6ef2ea55ca09.tar.lz
dexon-sol-tools-8aa673aabe292e7d4684f7cc98ec6ef2ea55ca09.tar.xz
dexon-sol-tools-8aa673aabe292e7d4684f7cc98ec6ef2ea55ca09.tar.zst
dexon-sol-tools-8aa673aabe292e7d4684f7cc98ec6ef2ea55ca09.zip
Add initial implementation with success test
Diffstat (limited to 'src')
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts53
-rw-r--r--src/types.ts6
2 files changed, 58 insertions, 1 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index d3a53a9f7..b8e34b9e8 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -9,9 +9,9 @@ import {
ExchangeContractErrs,
OrderValues,
OrderAddresses,
+ Order,
SignedOrder,
ContractEvent,
- ZeroExError,
ExchangeEvents,
SubscriptionOpts,
IndexFilterValues,
@@ -169,6 +169,53 @@ export class ExchangeWrapper extends ContractWrapper {
this.throwErrorLogsAsErrors(response.logs);
}
/**
+ * Cancels the order.
+ */
+ public async cancelOrderAsync(order: Order, cancelAmount: BigNumber.BigNumber): Promise<void> {
+ assert.doesConformToSchema('order',
+ SchemaValidator.convertToJSONSchemaCompatibleObject(order as object),
+ signedOrderSchema);
+ assert.isBigNumber('cancelAmount', cancelAmount);
+ await assert.isSenderAddressAvailableAsync(this.web3Wrapper, order.maker);
+
+ const exchangeInstance = await this.getExchangeContractAsync();
+ await this.validateCancelOrderAndThrowIfInvalidAsync(order, cancelAmount);
+
+ const orderAddresses: OrderAddresses = [
+ order.maker,
+ order.taker,
+ order.makerTokenAddress,
+ order.takerTokenAddress,
+ order.feeRecipient,
+ ];
+ const orderValues: OrderValues = [
+ order.makerTokenAmount,
+ order.takerTokenAmount,
+ order.makerFee,
+ order.takerFee,
+ order.expirationUnixTimestampSec,
+ order.salt,
+ ];
+ const gas = await exchangeInstance.cancel.estimateGas(
+ orderAddresses,
+ orderValues,
+ cancelAmount,
+ {
+ from: order.maker,
+ },
+ );
+ const response: ContractResponse = await exchangeInstance.cancel(
+ orderAddresses,
+ orderValues,
+ cancelAmount,
+ {
+ from: order.maker,
+ gas,
+ },
+ );
+ this.throwErrorLogsAsErrors(response.logs);
+ }
+ /**
* Subscribe to an event type emitted by the Exchange smart contract
*/
public async subscribeAsync(eventName: ExchangeEvents, subscriptionOpts: SubscriptionOpts,
@@ -225,6 +272,10 @@ export class ExchangeWrapper extends ContractWrapper {
throw new Error(ExchangeContractErrs.ORDER_FILL_ROUNDING_ERROR);
}
}
+ private async validateCancelOrderAndThrowIfInvalidAsync(order: Order,
+ cancelAmount: BigNumber.BigNumber): Promise<void> {
+ // TODO
+ }
/**
* This method does not currently validate the edge-case where the makerToken or takerToken is also the token used
diff --git a/src/types.ts b/src/types.ts
index a02bd0252..f2214ba6b 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -68,6 +68,12 @@ export interface ExchangeContract {
estimateGas: (orderAddresses: OrderAddresses, orderValues: OrderValues, fillAmount: BigNumber.BigNumber,
shouldCheckTransfer: boolean, v: number, r: string, s: string, txOpts: TxOpts) => number;
};
+ cancel: {
+ (orderAddresses: OrderAddresses, orderValues: OrderValues, cancelAmount: BigNumber.BigNumber,
+ txOpts: TxOpts): ContractResponse;
+ estimateGas: (orderAddresses: OrderAddresses, orderValues: OrderValues, cancelAmount: BigNumber.BigNumber,
+ txOpts: TxOpts) => number;
+ };
filled: {
call: (orderHash: string) => BigNumber.BigNumber;
};