F. Eugene Aumson f11d8a5bd8
@0x/order-utils refactors for v3: orderParsingUtils, signatureUtils, orderHashUtils, RevertErrors, transactionHashUtils (#2321)
* move orderParsingUtils from order-utils to connect

* Remove many functions from signatureUtils

Removed from the exported object, that is.  All of them are used in
other existing code, so they were all moved to be as local to their
usage as possible.

* remove orderHashUtils.isValidOrderHash()

* Move all *RevertErrors from order-utils...

...into their respective @0x/contracts- packages.

* Refactor @0x/order-utils' orderHashUtils away

- Move existing routines into @0x/contracts-test-utils

- Migrate non-contract-test callers to a newly-exposed getOrderHash()
method in DevUtils.

* Move all *RevertErrors from @0x/utils...

...into their respective @0x/contracts- packages.

* rm transactionHashUtils.isValidTransactionHash()

* DevUtils.sol: Fail yarn test if too big to deploy

* Refactor @0x/order-utils transactionHashUtils away

- Move existing routines into @0x/contracts-test-utils

- Migrate non-contract-test callers to a newly-exposed
getTransactionHash() method in DevUtils.

* Consolidate `Removed export...` CHANGELOG entries

* Rm EthBalanceChecker from devutils wrapper exports

* Stop importing from '.' or '.../src'

* fix builds

* fix prettier; dangling promise

* increase max bundle size
2019-11-14 17:14:24 -05:00

62 lines
2.4 KiB
TypeScript

import { BaseContract } from '@0x/base-contract';
import { ApprovalFactory, SignedCoordinatorApproval } from '@0x/contracts-coordinator';
import { SignatureType, SignedZeroExTransaction } from '@0x/types';
import { Actor, ActorConfig, Constructor } from './base';
interface FeeRecipientConfig extends ActorConfig {
verifyingContract?: BaseContract;
}
export interface FeeRecipientInterface {
approvalFactory?: ApprovalFactory;
signCoordinatorApprovalAsync: (
transaction: SignedZeroExTransaction,
txOrigin: string,
signatureType?: SignatureType,
) => Promise<SignedCoordinatorApproval>;
}
/**
* This mixin encapsulates functionaltiy associated with fee recipients within the 0x ecosystem.
* As of writing, the only extra functionality provided is signing Coordinator approvals.
*/
export function FeeRecipientMixin<TBase extends Constructor>(Base: TBase): TBase & Constructor<FeeRecipientInterface> {
return class extends Base {
public readonly actor: Actor;
public readonly approvalFactory?: ApprovalFactory;
/**
* The mixin pattern requires that this constructor uses `...args: any[]`, but this class
* really expects a single `FeeRecipientConfig` parameter (assuming `Actor` is used as the
* base class).
*/
constructor(...args: any[]) {
// tslint:disable-next-line:no-inferred-empty-object-type
super(...args);
this.actor = (this as any) as Actor;
const { verifyingContract } = args[0] as FeeRecipientConfig;
if (verifyingContract !== undefined) {
this.approvalFactory = new ApprovalFactory(this.actor.privateKey, verifyingContract.address);
}
}
/**
* Signs an coordinator transaction.
*/
public async signCoordinatorApprovalAsync(
transaction: SignedZeroExTransaction,
txOrigin: string,
signatureType: SignatureType = SignatureType.EthSign,
): Promise<SignedCoordinatorApproval> {
if (this.approvalFactory === undefined) {
throw new Error('No verifying contract provided in FeeRecipient constructor');
}
return this.approvalFactory.newSignedApprovalAsync(transaction, txOrigin, signatureType);
}
};
}
export class FeeRecipient extends FeeRecipientMixin(Actor) {}