Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
Add coordinator wrapper (#1792)
Browse files Browse the repository at this point in the history
* wip first pass at coordinator wrapper

* implement cancels, helper methods, and more unit tests

* pin typeorm version in pipeline

* prettier

* add export to 0x.js

* generate ZeroEx transaction using EIP712

* update Coordinator artifact

* change OrderError -> TypedDataError
  • Loading branch information
xianny authored May 9, 2019
1 parent c2d3e5f commit 41cc523
Show file tree
Hide file tree
Showing 22 changed files with 2,391 additions and 197 deletions.
3 changes: 3 additions & 0 deletions packages/0x.js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export {

export {
ContractWrappers,
CoordinatorWrapper,
CoordinatorServerCancellationResponse,
CoordinatorServerError,
DutchAuctionWrapper,
ERC20TokenWrapper,
ERC721TokenWrapper,
Expand Down
140 changes: 101 additions & 39 deletions packages/contract-artifacts/artifacts/Coordinator.json

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions packages/contract-wrappers/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
[
{
"version": "9.1.0",
"changes": [
{
"note": "Added CoordinatorWrapper to support orders with the Coordinator extension contract",
"pr": 1792
}
]
},
{
"version": "9.0.0",
"changes": [
Expand Down
4 changes: 4 additions & 0 deletions packages/contract-wrappers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@
},
"devDependencies": {
"@0x/contracts-test-utils": "^3.1.2",
"@0x/coordinator-server": "0.1.1",
"@0x/dev-utils": "^2.2.1",
"@0x/fill-scenarios": "^3.0.5",
"@0x/migrations": "^4.1.1",
"@0x/subproviders": "^4.0.5",
"@0x/tslint-config": "^3.0.1",
"@types/lodash": "4.14.104",
"@types/mocha": "^2.2.42",
"@types/nock": "^10.0.1",
"@types/node": "*",
"@types/sinon": "^2.2.2",
"@types/uuid": "^3.4.3",
Expand All @@ -56,6 +58,7 @@
"dirty-chai": "^2.0.1",
"make-promises-safe": "^1.1.0",
"mocha": "^4.1.0",
"nock": "^10.0.6",
"npm-run-all": "^4.1.2",
"nyc": "^11.0.1",
"opn-cli": "^3.1.0",
Expand Down Expand Up @@ -83,6 +86,7 @@
"ethereumjs-blockstream": "6.0.0",
"ethereumjs-util": "^5.1.1",
"ethers": "~4.0.4",
"http-status-codes": "^1.3.2",
"js-sha3": "^0.7.0",
"lodash": "^4.17.11",
"uuid": "^3.3.2"
Expand Down
15 changes: 15 additions & 0 deletions packages/contract-wrappers/src/contract_wrappers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
Coordinator,
DutchAuction,
ERC20Proxy,
ERC20Token,
Expand All @@ -14,6 +15,7 @@ import { Web3Wrapper } from '@0x/web3-wrapper';
import { SupportedProvider } from 'ethereum-types';
import * as _ from 'lodash';

import { CoordinatorWrapper } from './contract_wrappers/coordinator_wrapper';
import { DutchAuctionWrapper } from './contract_wrappers/dutch_auction_wrapper';
import { ERC20ProxyWrapper } from './contract_wrappers/erc20_proxy_wrapper';
import { ERC20TokenWrapper } from './contract_wrappers/erc20_token_wrapper';
Expand Down Expand Up @@ -73,6 +75,11 @@ export class ContractWrappers {
*/
public dutchAuction: DutchAuctionWrapper;

/**
* An instance of the CoordinatorWrapper class containing methods for interacting with the Coordinator extension contract.
*/
public coordinator: CoordinatorWrapper;

private readonly _web3Wrapper: Web3Wrapper;
/**
* Instantiates a new ContractWrappers instance.
Expand All @@ -88,6 +95,7 @@ export class ContractWrappers {
};
this._web3Wrapper = new Web3Wrapper(supportedProvider, txDefaults);
const artifactsArray = [
Coordinator,
DutchAuction,
ERC20Proxy,
ERC20Token,
Expand Down Expand Up @@ -155,6 +163,13 @@ export class ContractWrappers {
config.networkId,
contractAddresses.dutchAuction,
);
this.coordinator = new CoordinatorWrapper(
this._web3Wrapper,
config.networkId,
contractAddresses.coordinator,
contractAddresses.exchange,
contractAddresses.coordinatorRegistry,
);
}
/**
* Unsubscribes from all subscriptions for all contracts.
Expand Down

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions packages/contract-wrappers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export {
} from '@0x/abi-gen-wrappers';

export { ContractWrappers } from './contract_wrappers';
export { CoordinatorWrapper } from './contract_wrappers/coordinator_wrapper';
export { ERC20TokenWrapper } from './contract_wrappers/erc20_token_wrapper';
export { ERC721TokenWrapper } from './contract_wrappers/erc721_token_wrapper';
export { EtherTokenWrapper } from './contract_wrappers/ether_token_wrapper';
Expand Down Expand Up @@ -58,6 +59,8 @@ export {
TraderInfo,
ValidateOrderFillableOpts,
DutchAuctionData,
CoordinatorServerCancellationResponse,
CoordinatorServerError,
} from './types';

export {
Expand All @@ -72,6 +75,8 @@ export {
Order,
SignedOrder,
AssetProxyId,
SignedZeroExTransaction,
ZeroExTransaction,
} from '@0x/types';

export {
Expand Down
8 changes: 8 additions & 0 deletions packages/contract-wrappers/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,11 @@ export interface DutchAuctionData {
beginTimeSeconds: BigNumber;
beginAmount: BigNumber;
}

export { CoordinatorServerCancellationResponse, CoordinatorServerError } from './utils/coordinator_server_types';

export interface CoordinatorTransaction {
salt: BigNumber;
signerAddress: string;
data: string;
}
61 changes: 61 additions & 0 deletions packages/contract-wrappers/src/utils/coordinator_server_types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Order, SignedOrder, SignedZeroExTransaction } from '@0x/types';
import { BigNumber } from '@0x/utils';

export interface CoordinatorServerApprovalResponse {
signatures: string[];
expirationTimeSeconds: BigNumber[];
}
export interface CoordinatorServerApprovalRawResponse {
signatures: string[];
expirationTimeSeconds: BigNumber;
}

export interface CoordinatorServerCancellationResponse {
outstandingFillSignatures: CoordinatorOutstandingFillSignatures[];
cancellationSignatures: string[];
}
export interface CoordinatorOutstandingFillSignatures {
orderHash: string;
approvalSignatures: string[];
expirationTimeSeconds: BigNumber;
takerAssetFillAmount: BigNumber;
}

export interface CoordinatorServerResponse {
isError: boolean;
status: number;
body?: CoordinatorServerCancellationResponse | CoordinatorServerApprovalRawResponse;
error?: any;
request: CoordinatorServerRequest;
coordinatorOperator: string;
orders?: Array<SignedOrder | Order>;
}

export interface CoordinatorServerRequest {
signedTransaction: SignedZeroExTransaction;
txOrigin: string;
}

export class CoordinatorServerError extends Error {
public message: CoordinatorServerErrorMsg;
public approvedOrders?: SignedOrder[] = [];
public cancellations?: CoordinatorServerCancellationResponse[] = [];
public errors: CoordinatorServerResponse[];
constructor(
message: CoordinatorServerErrorMsg,
approvedOrders: SignedOrder[],
cancellations: CoordinatorServerCancellationResponse[],
errors: CoordinatorServerResponse[],
) {
super();
this.message = message;
this.approvedOrders = approvedOrders;
this.cancellations = cancellations;
this.errors = errors;
}
}

export enum CoordinatorServerErrorMsg {
CancellationFailed = 'Failed to cancel with some coordinator server(s). See errors for more info. See cancellations for successful cancellations.',
FillFailed = 'Failed to obtain approval signatures from some coordinator server(s). See errors for more info. Current transaction has been abandoned but you may resubmit with only approvedOrders (a new ZeroEx transaction will have to be signed).',
}
Loading

0 comments on commit 41cc523

Please sign in to comment.