Files
protocol/contracts/integrations/test/actors/taker.ts
2019-10-31 15:28:02 -07:00

54 lines
1.8 KiB
TypeScript

import { SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { TransactionReceiptWithDecodedLogs, TxData } from 'ethereum-types';
import { Actor, Constructor } from './base';
import { DeploymentManager } from '../utils/deployment_manager';
export interface TakerInterface {
fillOrderAsync: (
order: SignedOrder,
fillAmount: BigNumber,
txData?: Partial<TxData>,
) => Promise<TransactionReceiptWithDecodedLogs>;
}
export function TakerMixin<TBase extends Constructor>(Base: TBase): TBase & Constructor<TakerInterface> {
return class extends Base {
public readonly actor: Actor;
/**
* The mixin pattern requires that this constructor uses `...args: any[]`, but this class
* really expects a single `ActorConfig` parameter (assuming `Actor` is used as the base
* class).
*/
constructor(...args: any[]) {
super(...args);
this.actor = (this as any) as Actor;
}
/**
* Fills an order by the given `fillAmount`. Defaults to paying the protocol fee in ETH.
*/
public async fillOrderAsync(
order: SignedOrder,
fillAmount: BigNumber,
txData: Partial<TxData> = {},
): Promise<TransactionReceiptWithDecodedLogs> {
return this.actor.deployment.exchange.fillOrder.awaitTransactionSuccessAsync(
order,
fillAmount,
order.signature,
{
from: this.actor.address,
gasPrice: DeploymentManager.gasPrice,
value: DeploymentManager.protocolFee,
...txData,
},
);
}
};
}
export class Taker extends TakerMixin(Actor) {}