aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-06-02 18:57:21 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-06-02 18:57:21 +0800
commite1ee6b84945e729d894f6535be02f3541e43dbf0 (patch)
treeab58800b09c204ab05fb9c2a1161ded792d7e244 /src
parent2a0c6abbe7f9abeacc4fea05bc468413ec1f4732 (diff)
downloaddexon-sol-tools-e1ee6b84945e729d894f6535be02f3541e43dbf0.tar
dexon-sol-tools-e1ee6b84945e729d894f6535be02f3541e43dbf0.tar.gz
dexon-sol-tools-e1ee6b84945e729d894f6535be02f3541e43dbf0.tar.bz2
dexon-sol-tools-e1ee6b84945e729d894f6535be02f3541e43dbf0.tar.lz
dexon-sol-tools-e1ee6b84945e729d894f6535be02f3541e43dbf0.tar.xz
dexon-sol-tools-e1ee6b84945e729d894f6535be02f3541e43dbf0.tar.zst
dexon-sol-tools-e1ee6b84945e729d894f6535be02f3541e43dbf0.zip
Add check for ROUNDING_ERROR and test for it
Diffstat (limited to 'src')
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts16
-rw-r--r--src/types.ts5
2 files changed, 21 insertions, 0 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index 3fb187de2..fe5fc3d78 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -154,6 +154,10 @@ export class ExchangeWrapper extends ContractWrapper {
if (fillMakerAmountInBaseUnits.greaterThan(makerAllowance)) {
throw new Error(FillOrderValidationErrs.NOT_ENOUGH_MAKER_ALLOWANCE);
}
+ if (await this.isRoundingErrorAsync(signedOrder.takerTokenAmount, fillTakerAmountInBaseUnits,
+ signedOrder.makerTokenAmount)) {
+ throw new Error(FillOrderValidationErrs.ROUNDING_ERROR);
+ }
}
private throwErrorLogsAsErrors(logs: ContractEvent[]): void {
const errEvent = _.find(logs, {event: 'LogError'});
@@ -163,6 +167,18 @@ export class ExchangeWrapper extends ContractWrapper {
throw new Error(errMessage);
}
}
+ private async isRoundingErrorAsync(takerTokenAmount: BigNumber.BigNumber,
+ fillTakerAmountInBaseUnits: BigNumber.BigNumber,
+ makerTokenAmount: BigNumber.BigNumber): Promise<boolean> {
+ const exchangeInstance = await this.getExchangeContractAsync();
+ const senderAddress = await this.web3Wrapper.getSenderAddressOrThrowAsync();
+ const isRoundingError = await exchangeInstance.isRoundingError.call(
+ takerTokenAmount, fillTakerAmountInBaseUnits, makerTokenAmount, {
+ from: senderAddress,
+ },
+ );
+ return isRoundingError;
+ }
private async getExchangeContractAsync(): Promise<ExchangeContract> {
if (!_.isUndefined(this.exchangeContractIfExists)) {
return this.exchangeContractIfExists;
diff --git a/src/types.ts b/src/types.ts
index f80f98dc4..73c448b85 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -34,6 +34,10 @@ export type OrderValues = [BigNumber.BigNumber, BigNumber.BigNumber, BigNumber.B
export interface ExchangeContract {
isValidSignature: any;
+ isRoundingError: {
+ call: (takerTokenAmount: BigNumber.BigNumber, fillTakerAmountInBaseUnits: BigNumber.BigNumber,
+ makerTokenAmount: BigNumber.BigNumber, txOpts: TxOpts) => Promise<boolean>;
+ };
fill: {
(orderAddresses: OrderAddresses, orderValues: OrderValues, fillAmount: BigNumber.BigNumber,
shouldCheckTransfer: boolean, v: number, r: string, s: string, txOpts: TxOpts): ContractResponse;
@@ -93,6 +97,7 @@ export const FillOrderValidationErrs = strEnum([
'NOT_ENOUGH_TAKER_ALLOWANCE',
'NOT_ENOUGH_MAKER_BALANCE',
'NOT_ENOUGH_MAKER_ALLOWANCE',
+ 'ROUNDING_ERROR',
]);
export type FillOrderValidationErrs = keyof typeof FillOrderValidationErrs;