1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
import * as _ from 'lodash';
// Utility function to create a K:V from a list of strings
// Adapted from: https://basarat.gitbooks.io/typescript/content/docs/types/literal-types.html
function strEnum(values: string[]): {[key: string]: string} {
return _.reduce(values, (result, key) => {
result[key] = key;
return result;
}, Object.create(null));
}
export const ZeroExError = strEnum([
'CONTRACT_DOES_NOT_EXIST',
'UNHANDLED_ERROR',
'USER_HAS_NO_ASSOCIATED_ADDRESSES',
'INVALID_SIGNATURE',
'CONTRACT_NOT_DEPLOYED_ON_NETWORK',
]);
export type ZeroExError = keyof typeof ZeroExError;
/**
* Elliptic Curve signature
*/
export interface ECSignature {
v: number;
r: string;
s: string;
}
export type OrderAddresses = [string, string, string, string, string];
export type OrderValues = [
BigNumber.BigNumber, BigNumber.BigNumber, BigNumber.BigNumber,
BigNumber.BigNumber, BigNumber.BigNumber, BigNumber.BigNumber
];
export interface TxData {
from: string;
}
export interface ExchangeContract {
isValidSignature: any;
fill: (
orderAddresses: OrderAddresses, orderValues: OrderValues, fillAmount: BigNumber.BigNumber,
shouldCheckTransfer: boolean, v: number, r: string, s: string, txData: TxData,
) => ContractResponse;
}
export interface TokenContract {
balanceOf: {
call: (address: string) => Promise<BigNumber.BigNumber>;
};
allowance: {
call: (ownerAddress: string, allowedAddress: string) => Promise<BigNumber.BigNumber>;
};
transfer: (to: string, amountInBaseUnits: BigNumber.BigNumber, txOpts: TxOpts) => Promise<boolean>;
approve: (proxyAddress: string, amountInBaseUnits: BigNumber.BigNumber, txOpts: TxOpts) => void;
}
export interface TokenRegistryContract {
getTokenMetaData: {
call: (address: string) => Promise<TokenMetadata>;
};
getTokenAddresses: {
call: () => Promise<string[]>;
};
}
export const SolidityTypes = strEnum([
'address',
'uint256',
]);
export type SolidityTypes = keyof typeof SolidityTypes;
export enum ExchangeContractErrs {
ERROR_FILL_EXPIRED, // Order has already expired
ERROR_FILL_NO_VALUE, // Order has already been fully filled or cancelled
ERROR_FILL_TRUNCATION, // Rounding error too large
ERROR_FILL_BALANCE_ALLOWANCE, // Insufficient balance or allowance for token transfer
ERROR_CANCEL_EXPIRED, // Order has already expired
ERROR_CANCEL_NO_VALUE, // Order has already been fully filled or cancelled
}
export interface ContractResponse {
logs: ContractEvent[];
}
export interface ContractEvent {
event: string;
args: any;
}
export interface Order {
maker: string;
taker?: string;
makerFee: BigNumber.BigNumber;
takerFee: BigNumber.BigNumber;
makerTokenAmount: BigNumber.BigNumber;
takerTokenAmount: BigNumber.BigNumber;
makerTokenAddress: string;
takerTokenAddress: string;
salt: BigNumber.BigNumber;
feeRecipient: string;
expirationUnixTimestampSec: BigNumber.BigNumber;
}
export interface SignedOrder extends Order {
ecSignature: ECSignature;
}
// [address, name, symbol, projectUrl, decimals, ipfsHash, swarmHash]
export type TokenMetadata = [string, string, string, string, BigNumber.BigNumber, string, string];
export interface Token {
name: string;
address: string;
symbol: string;
decimals: number;
url: string;
}
export interface TxOpts {
from: string;
gas?: number;
}
|