aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/util/exchange_wrapper.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/contracts/util/exchange_wrapper.ts')
-rw-r--r--packages/contracts/util/exchange_wrapper.ts60
1 files changed, 34 insertions, 26 deletions
diff --git a/packages/contracts/util/exchange_wrapper.ts b/packages/contracts/util/exchange_wrapper.ts
index b749cd72e..03d04629d 100644
--- a/packages/contracts/util/exchange_wrapper.ts
+++ b/packages/contracts/util/exchange_wrapper.ts
@@ -1,4 +1,4 @@
-import { TransactionReceiptWithDecodedLogs, ZeroEx } from '0x.js';
+import { SignedOrder, TransactionReceiptWithDecodedLogs, ZeroEx } from '0x.js';
import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
import * as Web3 from 'web3';
@@ -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 { signedOrderUtils } from './signed_order_utils';
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,19 @@ export class ExchangeWrapper {
} = {},
): Promise<TransactionReceiptWithDecodedLogs> {
const shouldThrowOnInsufficientBalanceOrAllowance = !!opts.shouldThrowOnInsufficientBalanceOrAllowance;
- const params = order.createFill(shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmount);
+ const params = signedOrderUtils.createFill(
+ signedOrder,
+ 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 +45,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 = signedOrderUtils.createCancel(signedOrder, opts.cancelTakerTokenAmount);
const txHash = await this._exchange.cancelOrder.sendTransactionAsync(
params.orderAddresses,
params.orderValues,
@@ -58,19 +62,23 @@ 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 = signedOrderUtils.createFill(
+ signedOrder,
+ 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 +87,7 @@ export class ExchangeWrapper {
return tx;
}
public async batchFillOrdersAsync(
- orders: Order[],
+ orders: SignedOrder[],
from: string,
opts: {
fillTakerTokenAmounts?: BigNumber[];
@@ -108,7 +116,7 @@ export class ExchangeWrapper {
return tx;
}
public async batchFillOrKillOrdersAsync(
- orders: Order[],
+ orders: SignedOrder[],
from: string,
opts: { fillTakerTokenAmounts?: BigNumber[]; shouldThrowOnInsufficientBalanceOrAllowance?: boolean } = {},
): Promise<TransactionReceiptWithDecodedLogs> {
@@ -133,7 +141,7 @@ export class ExchangeWrapper {
return tx;
}
public async fillOrdersUpToAsync(
- orders: Order[],
+ orders: SignedOrder[],
from: string,
opts: { fillTakerTokenAmount: BigNumber; shouldThrowOnInsufficientBalanceOrAllowance?: boolean },
): Promise<TransactionReceiptWithDecodedLogs> {
@@ -159,7 +167,7 @@ export class ExchangeWrapper {
return tx;
}
public async batchCancelOrdersAsync(
- orders: Order[],
+ orders: SignedOrder[],
from: string,
opts: { cancelTakerTokenAmounts?: BigNumber[] } = {},
): Promise<TransactionReceiptWithDecodedLogs> {
@@ -175,19 +183,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 = signedOrderUtils.getOrderAddressesAndValues(signedOrder);
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.params.orderHashHex as string,
- order.params.v as number,
- order.params.r as string,
- order.params.s as string,
+ signedOrder.maker,
+ ZeroEx.getOrderHashHex(signedOrder),
+ signedOrder.ecSignature.v,
+ signedOrder.ecSignature.r,
+ signedOrder.ecSignature.s,
);
return isValidSignature;
}