aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/util/exchange_wrapper.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-02-07 19:22:22 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-02-07 19:22:22 +0800
commitfd004032cb23998184a78ac4a0a486ef1bd04c25 (patch)
tree90f7e64996ccc0fee1e5428b2ced9b2c2b1c3d4a /packages/contracts/util/exchange_wrapper.ts
parent4b6324050da4862f4d8bdb7d6dbd66107929a2b5 (diff)
downloaddexon-0x-contracts-fd004032cb23998184a78ac4a0a486ef1bd04c25.tar.gz
dexon-0x-contracts-fd004032cb23998184a78ac4a0a486ef1bd04c25.tar.zst
dexon-0x-contracts-fd004032cb23998184a78ac4a0a486ef1bd04c25.zip
Introduce SignedOrder class and remove type assertions
Diffstat (limited to 'packages/contracts/util/exchange_wrapper.ts')
-rw-r--r--packages/contracts/util/exchange_wrapper.ts50
1 files changed, 25 insertions, 25 deletions
diff --git a/packages/contracts/util/exchange_wrapper.ts b/packages/contracts/util/exchange_wrapper.ts
index e44a0eab6..ff263246f 100644
--- a/packages/contracts/util/exchange_wrapper.ts
+++ b/packages/contracts/util/exchange_wrapper.ts
@@ -6,7 +6,7 @@ import * as Web3 from 'web3';
import { ExchangeContract } from '../src/contract_wrappers/generated/exchange';
import { formatters } from './formatters';
-import { Order } from './order';
+import { SignedOrder } from './signed_order';
export class ExchangeWrapper {
private _exchange: ExchangeContract;
@@ -16,7 +16,7 @@ export class ExchangeWrapper {
this._zeroEx = zeroEx;
}
public async fillOrderAsync(
- order: Order,
+ signedOrder: SignedOrder,
from: string,
opts: {
fillTakerTokenAmount?: BigNumber;
@@ -24,15 +24,15 @@ export class ExchangeWrapper {
} = {},
): Promise<TransactionReceiptWithDecodedLogs> {
const shouldThrowOnInsufficientBalanceOrAllowance = !!opts.shouldThrowOnInsufficientBalanceOrAllowance;
- const params = order.createFill(shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmount);
+ const params = signedOrder.createFill(shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmount);
const txHash = await this._exchange.fillOrder.sendTransactionAsync(
params.orderAddresses,
params.orderValues,
params.fillTakerTokenAmount,
params.shouldThrowOnInsufficientBalanceOrAllowance,
- params.v as number,
- params.r as string,
- params.s as string,
+ params.v,
+ params.r,
+ params.s,
{ from },
);
const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
@@ -41,11 +41,11 @@ export class ExchangeWrapper {
return tx;
}
public async cancelOrderAsync(
- order: Order,
+ signedOrder: SignedOrder,
from: string,
opts: { cancelTakerTokenAmount?: BigNumber } = {},
): Promise<TransactionReceiptWithDecodedLogs> {
- const params = order.createCancel(opts.cancelTakerTokenAmount);
+ const params = signedOrder.createCancel(opts.cancelTakerTokenAmount);
const txHash = await this._exchange.cancelOrder.sendTransactionAsync(
params.orderAddresses,
params.orderValues,
@@ -58,19 +58,19 @@ export class ExchangeWrapper {
return tx;
}
public async fillOrKillOrderAsync(
- order: Order,
+ signedOrder: SignedOrder,
from: string,
opts: { fillTakerTokenAmount?: BigNumber } = {},
): Promise<TransactionReceiptWithDecodedLogs> {
const shouldThrowOnInsufficientBalanceOrAllowance = true;
- const params = order.createFill(shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmount);
+ const params = signedOrder.createFill(shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmount);
const txHash = await this._exchange.fillOrKillOrder.sendTransactionAsync(
params.orderAddresses,
params.orderValues,
params.fillTakerTokenAmount,
- params.v as number,
- params.r as string,
- params.s as string,
+ params.v,
+ params.r,
+ params.s,
{ from },
);
const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
@@ -79,7 +79,7 @@ export class ExchangeWrapper {
return tx;
}
public async batchFillOrdersAsync(
- orders: Order[],
+ orders: SignedOrder[],
from: string,
opts: {
fillTakerTokenAmounts?: BigNumber[];
@@ -108,7 +108,7 @@ export class ExchangeWrapper {
return tx;
}
public async batchFillOrKillOrdersAsync(
- orders: Order[],
+ orders: SignedOrder[],
from: string,
opts: { fillTakerTokenAmounts?: BigNumber[]; shouldThrowOnInsufficientBalanceOrAllowance?: boolean } = {},
): Promise<TransactionReceiptWithDecodedLogs> {
@@ -133,7 +133,7 @@ export class ExchangeWrapper {
return tx;
}
public async fillOrdersUpToAsync(
- orders: Order[],
+ orders: SignedOrder[],
from: string,
opts: { fillTakerTokenAmount: BigNumber; shouldThrowOnInsufficientBalanceOrAllowance?: boolean },
): Promise<TransactionReceiptWithDecodedLogs> {
@@ -159,7 +159,7 @@ export class ExchangeWrapper {
return tx;
}
public async batchCancelOrdersAsync(
- orders: Order[],
+ orders: SignedOrder[],
from: string,
opts: { cancelTakerTokenAmounts?: BigNumber[] } = {},
): Promise<TransactionReceiptWithDecodedLogs> {
@@ -175,19 +175,19 @@ export class ExchangeWrapper {
_.each(tx.logs, log => wrapLogBigNumbers(log));
return tx;
}
- public async getOrderHashAsync(order: Order): Promise<string> {
+ public async getOrderHashAsync(signedOrder: SignedOrder): Promise<string> {
const shouldThrowOnInsufficientBalanceOrAllowance = false;
- const params = order.createFill(shouldThrowOnInsufficientBalanceOrAllowance);
+ const params = signedOrder.createFill(shouldThrowOnInsufficientBalanceOrAllowance);
const orderHash = await this._exchange.getOrderHash(params.orderAddresses, params.orderValues);
return orderHash;
}
- public async isValidSignatureAsync(order: Order): Promise<boolean> {
+ public async isValidSignatureAsync(signedOrder: SignedOrder): Promise<boolean> {
const isValidSignature = await this._exchange.isValidSignature(
- order.params.maker,
- order.getOrderHashHex(),
- order.params.v as number,
- order.params.r as string,
- order.params.s as string,
+ signedOrder.params.maker,
+ signedOrder.getOrderHashHex(),
+ signedOrder.params.v,
+ signedOrder.params.r,
+ signedOrder.params.s,
);
return isValidSignature;
}