Compare commits
149 Commits
0x.js@0.27
...
@0xproject
Author | SHA1 | Date | |
---|---|---|---|
|
a6f9718131 | ||
|
47075edc97 | ||
|
25cee41358 | ||
|
d08d65a3af | ||
|
d14ed71191 | ||
|
f341f62b2b | ||
|
828dffffed | ||
|
af8d24d0eb | ||
|
ca85a97106 | ||
|
5eea829be9 | ||
|
e822e3562d | ||
|
f109d132e4 | ||
|
1fc1eae39a | ||
|
deb6aeae43 | ||
|
f48f126b3a | ||
|
e0d79bd332 | ||
|
5e75aab8ea | ||
|
36125c3539 | ||
|
72ced622d7 | ||
|
b362e2c28e | ||
|
2260a0a4cd | ||
|
3c64b33f5c | ||
|
5301086c68 | ||
|
5687279c8d | ||
|
6c2bf8ed26 | ||
|
f1ecdcf602 | ||
|
1eaefac12b | ||
|
be17b75ad3 | ||
|
0c23f5e07e | ||
|
86e1fa8153 | ||
|
fae0651b0c | ||
|
720641f14c | ||
|
e8495b0c7b | ||
|
e80579a605 | ||
|
5967d39ca9 | ||
|
b82b50e2f0 | ||
|
e893e8c442 | ||
|
3db5efa264 | ||
|
5401c69163 | ||
|
b7030cffd9 | ||
|
73b4b4488e | ||
|
825402b0f9 | ||
|
f23071a214 | ||
|
f1b267cc9f | ||
|
adf1afc6ba | ||
|
0abbdc6b96 | ||
|
598f1dd2d8 | ||
|
594bd2de1c | ||
|
55083316fc | ||
|
8c87394b2b | ||
|
1dba4b85d0 | ||
|
22de68205b | ||
|
f76543ebfa | ||
|
f0c27f98b8 | ||
|
da678ba018 | ||
|
86ed1b4554 | ||
|
06e348f80b | ||
|
f05e0174a0 | ||
|
6bea3ac157 | ||
|
e4d42a079c | ||
|
5bbdb7a8f7 | ||
|
3cf7cb1054 | ||
|
78274440cb | ||
|
e59934ca21 | ||
|
c93bb4ef98 | ||
|
e3763bade2 | ||
|
1ea1c02387 | ||
|
f6321a8e70 | ||
|
08168c6e7d | ||
|
b5030df4e3 | ||
|
8414c18866 | ||
|
038668efdf | ||
|
4441d76725 | ||
|
1f494feec4 | ||
|
1153fa093b | ||
|
c64ec92fb2 | ||
|
20e28d6c70 | ||
|
c0015c2c11 | ||
|
3880f2b3cc | ||
|
293847053a | ||
|
e042f49e27 | ||
|
c036b96848 | ||
|
e95dba2c25 | ||
|
9891d7aaa6 | ||
|
1ce66b4a81 | ||
|
63b1199bd5 | ||
|
47789d770d | ||
|
df58593ff4 | ||
|
e2ef7a74db | ||
|
cde52b10b1 | ||
|
43983f1bb3 | ||
|
eb4adcf797 | ||
|
32568ebf09 | ||
|
c53d195ed0 | ||
|
9b1c9ecb8b | ||
|
8cd204423a | ||
|
2abc5a88c5 | ||
|
4c0bc02c48 | ||
|
16b27c4ae8 | ||
|
dc5f4ab28b | ||
|
f88ecaa035 | ||
|
c0cf47138e | ||
|
e1127dc2e8 | ||
|
5d1b845cad | ||
|
355514ca38 | ||
|
518d0eba84 | ||
|
78fb8d2bdc | ||
|
5673b42ec4 | ||
|
438c8ff807 | ||
|
ee15143dd7 | ||
|
042caa3363 | ||
|
eb667f653c | ||
|
6cbd0d4537 | ||
|
11bf2a0e06 | ||
|
9485e4f4f3 | ||
|
865ee090c8 | ||
|
0fc356740a | ||
|
f285a46d05 | ||
|
1e1c99d8d6 | ||
|
c291419141 | ||
|
290a96d41f | ||
|
ca9518c48c | ||
|
d44d6ccfd8 | ||
|
cec0b2afe3 | ||
|
e85a69655c | ||
|
4b3e038323 | ||
|
c57190dead | ||
|
3d73167f53 | ||
|
2eefec54b4 | ||
|
ab72656fdf | ||
|
b6f2f98db6 | ||
|
c051c48600 | ||
|
04fc16587b | ||
|
f1d5a7d31f | ||
|
7197356928 | ||
|
a75d547af6 | ||
|
bdecb18e3e | ||
|
e2adcaa185 | ||
|
4193893349 | ||
|
53522a98b9 | ||
|
0e856ccfab | ||
|
6093ee7824 | ||
|
46f185bbeb | ||
|
8bfa880371 | ||
|
a7f0d03611 | ||
|
9ce899d3f3 | ||
|
3c3033586d | ||
|
166c741beb | ||
|
629a0fa3a5 |
@@ -19,7 +19,7 @@ jobs:
|
||||
- run: wget https://s3.amazonaws.com/testrpc-shapshots/${CONTRACTS_COMMIT_HASH}.zip
|
||||
- run: unzip ${CONTRACTS_COMMIT_HASH}.zip -d testrpc_snapshot
|
||||
- run: node ./node_modules/lerna/bin/lerna.js bootstrap
|
||||
- run: yarn lerna:run bootstrap
|
||||
- run: yarn lerna:run build
|
||||
- run:
|
||||
name: testrpc
|
||||
command: npm run testrpc -- --db testrpc_snapshot
|
||||
|
@@ -7,7 +7,7 @@
|
||||
"scripts": {
|
||||
"testrpc": "testrpc -p 8545 --networkId 50 -m \"${npm_package_config_mnemonic}\"",
|
||||
"lerna:run": "lerna run",
|
||||
"lerna:publish": "lerna run clean; lerna run build; lerna publish --registry=https://registry.npmjs.org/"
|
||||
"lerna:publish": "yarn install; lerna run clean; lerna run build; lerna publish --registry=https://registry.npmjs.org/"
|
||||
},
|
||||
"config": {
|
||||
"mnemonic": "concert load couple harbor equip island argue ramp clarify fence smart topic"
|
||||
@@ -17,6 +17,6 @@
|
||||
"async-child-process": "^1.1.1",
|
||||
"semver-sort": "^0.0.4",
|
||||
"publish-release": "0xproject/publish-release",
|
||||
"es6-promisify": "^5.0.0"
|
||||
"ethereumjs-testrpc": "6.0.3"
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "0x.js",
|
||||
"version": "0.27.1",
|
||||
"version": "0.27.2",
|
||||
"description": "A javascript library for interacting with the 0x protocol",
|
||||
"keywords": [
|
||||
"0x.js",
|
||||
@@ -16,6 +16,7 @@
|
||||
"build": "run-p build:umd:prod build:commonjs; exit 0;",
|
||||
"docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_DIR",
|
||||
"upload_docs_json": "aws s3 cp generated_docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type application/json",
|
||||
"generate_contract_wrappers": "abi-gen --abiGlob 'src/artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry).json' --templates ../abi-gen-templates/ --output src/contract_wrappers/generated --fileExtension ts",
|
||||
"lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'",
|
||||
"test:circleci": "run-s test:coverage report_test_coverage && if [ $CIRCLE_BRANCH = \"development\" ]; then yarn test:umd; fi",
|
||||
"test": "run-s clean test:commonjs",
|
||||
@@ -44,27 +45,29 @@
|
||||
"node": ">=6.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@0xproject/tslint-config": "^0.2.0",
|
||||
"@0xproject/abi-gen": "^0.0.2",
|
||||
"@0xproject/tslint-config": "^0.2.1",
|
||||
"@0xproject/types": "^0.1.0",
|
||||
"@types/bintrees": "^1.0.2",
|
||||
"@types/jsonschema": "^1.1.1",
|
||||
"@types/lodash": "^4.14.64",
|
||||
"@types/mocha": "^2.2.41",
|
||||
"@types/node": "^8.0.1",
|
||||
"@types/lodash": "^4.14.86",
|
||||
"@types/mocha": "^2.2.42",
|
||||
"@types/node": "^8.0.53",
|
||||
"@types/sinon": "^2.2.2",
|
||||
"@types/uuid": "^3.4.2",
|
||||
"abi-gen-templates": "^0.0.2",
|
||||
"awesome-typescript-loader": "^3.1.3",
|
||||
"chai": "^4.0.1",
|
||||
"chai-as-promised": "^7.1.0",
|
||||
"chai-as-promised-typescript-typings": "0.0.3",
|
||||
"chai-as-promised-typescript-typings": "^0.0.3",
|
||||
"chai-bignumber": "^2.0.1",
|
||||
"chai-typescript-typings": "^0.0.1",
|
||||
"copyfiles": "^1.2.0",
|
||||
"coveralls": "^3.0.0",
|
||||
"dirty-chai": "^2.0.1",
|
||||
"ethereumjs-testrpc": "6.0.3",
|
||||
"json-loader": "^0.5.4",
|
||||
"mocha": "^4.0.0",
|
||||
"npm-run-all": "^4.0.2",
|
||||
"mocha": "^4.0.1",
|
||||
"npm-run-all": "^4.1.2",
|
||||
"nyc": "^11.0.1",
|
||||
"opn-cli": "^3.1.0",
|
||||
"request": "^2.81.0",
|
||||
@@ -79,17 +82,18 @@
|
||||
"types-ethereumjs-util": "0xProject/types-ethereumjs-util",
|
||||
"typescript": "~2.6.1",
|
||||
"web3-provider-engine": "^13.0.1",
|
||||
"web3-typescript-typings": "^0.7.1",
|
||||
"web3-typescript-typings": "^0.7.2",
|
||||
"webpack": "^3.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0xproject/assert": "^0.0.6",
|
||||
"@0xproject/json-schemas": "^0.6.9",
|
||||
"@0xproject/assert": "^0.0.7",
|
||||
"@0xproject/json-schemas": "^0.6.10",
|
||||
"@0xproject/utils": "^0.1.0",
|
||||
"@0xproject/web3-wrapper": "^0.1.0",
|
||||
"bignumber.js": "~4.1.0",
|
||||
"bintrees": "^1.0.2",
|
||||
"bn.js": "4.11.8",
|
||||
"bn.js": "^4.11.8",
|
||||
"compare-versions": "^3.0.1",
|
||||
"es6-promisify": "^5.0.0",
|
||||
"ethereumjs-abi": "^0.6.4",
|
||||
"ethereumjs-blockstream": "^2.0.6",
|
||||
"ethereumjs-util": "^5.1.1",
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import {schemas, SchemaValidator} from '@0xproject/json-schemas';
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as ethUtil from 'ethereumjs-util';
|
||||
import * as _ from 'lodash';
|
||||
@@ -29,7 +30,6 @@ import {intervalUtils} from './utils/interval_utils';
|
||||
import {OrderStateUtils} from './utils/order_state_utils';
|
||||
import {signatureUtils} from './utils/signature_utils';
|
||||
import {utils} from './utils/utils';
|
||||
import {Web3Wrapper} from './web3_wrapper';
|
||||
|
||||
// Customize our BigNumber instances
|
||||
bigNumberConfigs.configure();
|
||||
@@ -179,24 +179,31 @@ export class ZeroEx {
|
||||
const defaults = {
|
||||
gasPrice: config.gasPrice,
|
||||
};
|
||||
this._web3Wrapper = new Web3Wrapper(provider, config.networkId, defaults);
|
||||
this._web3Wrapper = new Web3Wrapper(provider, defaults);
|
||||
this.proxy = new TokenTransferProxyWrapper(
|
||||
this._web3Wrapper,
|
||||
config.networkId,
|
||||
config.tokenTransferProxyContractAddress,
|
||||
);
|
||||
this.token = new TokenWrapper(
|
||||
this._web3Wrapper,
|
||||
config.networkId,
|
||||
this._abiDecoder,
|
||||
this.proxy,
|
||||
);
|
||||
this.exchange = new ExchangeWrapper(
|
||||
this._web3Wrapper,
|
||||
config.networkId,
|
||||
this._abiDecoder,
|
||||
this.token,
|
||||
config.exchangeContractAddress,
|
||||
);
|
||||
this.tokenRegistry = new TokenRegistryWrapper(this._web3Wrapper, config.tokenRegistryContractAddress);
|
||||
this.etherToken = new EtherTokenWrapper(this._web3Wrapper, this.token, config.etherTokenContractAddress);
|
||||
this.tokenRegistry = new TokenRegistryWrapper(
|
||||
this._web3Wrapper, config.networkId, config.tokenRegistryContractAddress,
|
||||
);
|
||||
this.etherToken = new EtherTokenWrapper(
|
||||
this._web3Wrapper, config.networkId, this.token, config.etherTokenContractAddress,
|
||||
);
|
||||
this.orderStateWatcher = new OrderStateWatcher(
|
||||
this._web3Wrapper, this._abiDecoder, this.token, this.exchange, config.orderWatcherConfig,
|
||||
);
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import {Block, BlockAndLogStreamer} from 'ethereumjs-blockstream';
|
||||
import * as _ from 'lodash';
|
||||
import * as Web3 from 'web3';
|
||||
@@ -19,10 +20,19 @@ import {AbiDecoder} from '../utils/abi_decoder';
|
||||
import {constants} from '../utils/constants';
|
||||
import {filterUtils} from '../utils/filter_utils';
|
||||
import {intervalUtils} from '../utils/interval_utils';
|
||||
import {Web3Wrapper} from '../web3_wrapper';
|
||||
|
||||
const CONTRACT_NAME_TO_NOT_FOUND_ERROR: {[contractName: string]: ZeroExError} = {
|
||||
ZRX: ZeroExError.ZRXContractDoesNotExist,
|
||||
EtherToken: ZeroExError.EtherTokenContractDoesNotExist,
|
||||
Token: ZeroExError.TokenContractDoesNotExist,
|
||||
TokenRegistry: ZeroExError.TokenRegistryContractDoesNotExist,
|
||||
TokenTransferProxy: ZeroExError.TokenTransferProxyContractDoesNotExist,
|
||||
Exchange: ZeroExError.ExchangeContractDoesNotExist,
|
||||
};
|
||||
|
||||
export class ContractWrapper {
|
||||
protected _web3Wrapper: Web3Wrapper;
|
||||
private _networkId: number;
|
||||
private _abiDecoder?: AbiDecoder;
|
||||
private _blockAndLogStreamer: BlockAndLogStreamer|undefined;
|
||||
private _blockAndLogStreamInterval: NodeJS.Timer;
|
||||
@@ -30,8 +40,9 @@ export class ContractWrapper {
|
||||
private _filterCallbacks: {[filterToken: string]: EventCallback<ContractEventArgs>};
|
||||
private _onLogAddedSubscriptionToken: string|undefined;
|
||||
private _onLogRemovedSubscriptionToken: string|undefined;
|
||||
constructor(web3Wrapper: Web3Wrapper, abiDecoder?: AbiDecoder) {
|
||||
constructor(web3Wrapper: Web3Wrapper, networkId: number, abiDecoder?: AbiDecoder) {
|
||||
this._web3Wrapper = web3Wrapper;
|
||||
this._networkId = networkId;
|
||||
this._abiDecoder = abiDecoder;
|
||||
this._filters = {};
|
||||
this._filterCallbacks = {};
|
||||
@@ -90,16 +101,30 @@ export class ContractWrapper {
|
||||
const logWithDecodedArgs = this._abiDecoder.tryToDecodeLogOrNoop(log);
|
||||
return logWithDecodedArgs;
|
||||
}
|
||||
protected async _instantiateContractIfExistsAsync<ContractType extends Web3.ContractInstance>(
|
||||
artifact: Artifact, addressIfExists?: string): Promise<ContractType> {
|
||||
const contractInstance =
|
||||
await this._web3Wrapper.getContractInstanceFromArtifactAsync<ContractType>(artifact, addressIfExists);
|
||||
protected async _instantiateContractIfExistsAsync(
|
||||
artifact: Artifact, addressIfExists?: string,
|
||||
): Promise<Web3.ContractInstance> {
|
||||
let contractAddress: string;
|
||||
if (_.isUndefined(addressIfExists)) {
|
||||
if (_.isUndefined(artifact.networks[this._networkId])) {
|
||||
throw new Error(ZeroExError.ContractNotDeployedOnNetwork);
|
||||
}
|
||||
contractAddress = artifact.networks[this._networkId].address.toLowerCase();
|
||||
} else {
|
||||
contractAddress = addressIfExists;
|
||||
}
|
||||
const doesContractExist = await this._web3Wrapper.doesContractExistAtAddressAsync(contractAddress);
|
||||
if (!doesContractExist) {
|
||||
throw new Error(CONTRACT_NAME_TO_NOT_FOUND_ERROR[artifact.contract_name]);
|
||||
}
|
||||
const contractInstance = this._web3Wrapper.getContractInstance(
|
||||
artifact.abi, contractAddress,
|
||||
);
|
||||
return contractInstance;
|
||||
}
|
||||
protected _getContractAddress(artifact: Artifact, addressIfExists?: string): string {
|
||||
if (_.isUndefined(addressIfExists)) {
|
||||
const networkId = this._web3Wrapper.getNetworkId();
|
||||
const contractAddress = artifact.networks[networkId].address;
|
||||
const contractAddress = artifact.networks[this._networkId].address;
|
||||
if (_.isUndefined(contractAddress)) {
|
||||
throw new Error(ZeroExError.ExchangeContractDoesNotExist);
|
||||
}
|
||||
|
@@ -1,12 +1,13 @@
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import {artifacts} from '../artifacts';
|
||||
import {EtherTokenContract, TransactionOpts, ZeroExError} from '../types';
|
||||
import {TransactionOpts, ZeroExError} from '../types';
|
||||
import {assert} from '../utils/assert';
|
||||
import {Web3Wrapper} from '../web3_wrapper';
|
||||
|
||||
import {ContractWrapper} from './contract_wrapper';
|
||||
import {EtherTokenContract} from './generated/ether_token';
|
||||
import {TokenWrapper} from './token_wrapper';
|
||||
|
||||
/**
|
||||
@@ -17,8 +18,9 @@ export class EtherTokenWrapper extends ContractWrapper {
|
||||
private _etherTokenContractIfExists?: EtherTokenContract;
|
||||
private _tokenWrapper: TokenWrapper;
|
||||
private _contractAddressIfExists?: string;
|
||||
constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper, contractAddressIfExists?: string) {
|
||||
super(web3Wrapper);
|
||||
constructor(web3Wrapper: Web3Wrapper, networkId: number, tokenWrapper: TokenWrapper,
|
||||
contractAddressIfExists?: string) {
|
||||
super(web3Wrapper, networkId);
|
||||
this._tokenWrapper = tokenWrapper;
|
||||
this._contractAddressIfExists = contractAddressIfExists;
|
||||
}
|
||||
@@ -92,9 +94,10 @@ export class EtherTokenWrapper extends ContractWrapper {
|
||||
if (!_.isUndefined(this._etherTokenContractIfExists)) {
|
||||
return this._etherTokenContractIfExists;
|
||||
}
|
||||
const contractInstance = await this._instantiateContractIfExistsAsync<EtherTokenContract>(
|
||||
const web3ContractInstance = await this._instantiateContractIfExistsAsync(
|
||||
artifacts.EtherTokenArtifact, this._contractAddressIfExists,
|
||||
);
|
||||
const contractInstance = new EtherTokenContract(web3ContractInstance, this._web3Wrapper.getContractDefaults());
|
||||
this._etherTokenContractIfExists = contractInstance;
|
||||
return this._etherTokenContractIfExists;
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import {schemas} from '@0xproject/json-schemas';
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as _ from 'lodash';
|
||||
import * as Web3 from 'web3';
|
||||
@@ -9,7 +10,6 @@ import {
|
||||
DecodedLogArgs,
|
||||
ECSignature,
|
||||
EventCallback,
|
||||
ExchangeContract,
|
||||
ExchangeContractErrCodes,
|
||||
ExchangeContractErrs,
|
||||
ExchangeContractEventArgs,
|
||||
@@ -37,9 +37,9 @@ import {decorators} from '../utils/decorators';
|
||||
import {ExchangeTransferSimulator} from '../utils/exchange_transfer_simulator';
|
||||
import {OrderValidationUtils} from '../utils/order_validation_utils';
|
||||
import {utils} from '../utils/utils';
|
||||
import {Web3Wrapper} from '../web3_wrapper';
|
||||
|
||||
import {ContractWrapper} from './contract_wrapper';
|
||||
import {ExchangeContract} from './generated/exchange';
|
||||
import {TokenWrapper} from './token_wrapper';
|
||||
|
||||
const SHOULD_VALIDATE_BY_DEFAULT = true;
|
||||
@@ -84,9 +84,9 @@ export class ExchangeWrapper extends ContractWrapper {
|
||||
];
|
||||
return [orderAddresses, orderValues];
|
||||
}
|
||||
constructor(web3Wrapper: Web3Wrapper, abiDecoder: AbiDecoder,
|
||||
constructor(web3Wrapper: Web3Wrapper, networkId: number, abiDecoder: AbiDecoder,
|
||||
tokenWrapper: TokenWrapper, contractAddressIfExists?: string) {
|
||||
super(web3Wrapper, abiDecoder);
|
||||
super(web3Wrapper, networkId, abiDecoder);
|
||||
this._tokenWrapper = tokenWrapper;
|
||||
this._orderValidationUtils = new OrderValidationUtils(tokenWrapper, this);
|
||||
this._contractAddressIfExists = contractAddressIfExists;
|
||||
@@ -789,9 +789,10 @@ export class ExchangeWrapper extends ContractWrapper {
|
||||
if (!_.isUndefined(this._exchangeContractIfExists)) {
|
||||
return this._exchangeContractIfExists;
|
||||
}
|
||||
const contractInstance = await this._instantiateContractIfExistsAsync<ExchangeContract>(
|
||||
const web3ContractInstance = await this._instantiateContractIfExistsAsync(
|
||||
artifacts.ExchangeArtifact, this._contractAddressIfExists,
|
||||
);
|
||||
const contractInstance = new ExchangeContract(web3ContractInstance, this._web3Wrapper.getContractDefaults());
|
||||
this._exchangeContractIfExists = contractInstance;
|
||||
return this._exchangeContractIfExists;
|
||||
}
|
||||
|
@@ -0,0 +1,34 @@
|
||||
import * as _ from 'lodash';
|
||||
import * as Web3 from 'web3';
|
||||
|
||||
import {TxData, TxDataPayable} from '../../types';
|
||||
|
||||
export class BaseContract {
|
||||
protected web3ContractInstance: Web3.ContractInstance;
|
||||
protected defaults: Partial<TxData>;
|
||||
protected async applyDefaultsToTxDataAsync<T extends TxData|TxDataPayable>(
|
||||
txData: T,
|
||||
estimateGasAsync?: (txData: T) => Promise<number>,
|
||||
): Promise<TxData> {
|
||||
// Gas amount sourced with the following priorities:
|
||||
// 1. Optional param passed in to public method call
|
||||
// 2. Global config passed in at library instantiation
|
||||
// 3. Gas estimate calculation + safety margin
|
||||
const removeUndefinedProperties = _.pickBy;
|
||||
const txDataWithDefaults = {
|
||||
...removeUndefinedProperties(this.defaults),
|
||||
...removeUndefinedProperties(txData as any),
|
||||
// HACK: TS can't prove that T is spreadable.
|
||||
// Awaiting https://github.com/Microsoft/TypeScript/pull/13288 to be merged
|
||||
};
|
||||
if (_.isUndefined(txDataWithDefaults.gas) && !_.isUndefined(estimateGasAsync)) {
|
||||
const estimatedGas = await estimateGasAsync(txData);
|
||||
txDataWithDefaults.gas = estimatedGas;
|
||||
}
|
||||
return txDataWithDefaults;
|
||||
}
|
||||
constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>) {
|
||||
this.web3ContractInstance = web3ContractInstance;
|
||||
this.defaults = defaults;
|
||||
}
|
||||
}
|
363
packages/0x.js/src/contract_wrappers/generated/ether_token.ts
Normal file
363
packages/0x.js/src/contract_wrappers/generated/ether_token.ts
Normal file
@@ -0,0 +1,363 @@
|
||||
/**
|
||||
* This file is auto-generated using abi-gen. Don't edit directly.
|
||||
* Templates can be found at https://github.com/0xProject/0x.js/tree/development/packages/abi-gen-templates.
|
||||
*/
|
||||
import {promisify} from '@0xproject/utils';
|
||||
import {BigNumber} from 'bignumber.js';
|
||||
import * as Web3 from 'web3';
|
||||
|
||||
import {TxData, TxDataPayable} from '../../types';
|
||||
import {classUtils} from '../../utils/class_utils';
|
||||
|
||||
import {BaseContract} from './base_contract';
|
||||
|
||||
export class EtherTokenContract extends BaseContract {
|
||||
public name = {
|
||||
async callAsync(
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<string
|
||||
> {
|
||||
const self = this as EtherTokenContract;
|
||||
const result = await promisify<string
|
||||
>(
|
||||
self.web3ContractInstance.name.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public approve = {
|
||||
async sendTransactionAsync(
|
||||
_spender: string,
|
||||
_value: BigNumber,
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as EtherTokenContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.approve.estimateGasAsync.bind(
|
||||
self,
|
||||
_spender,
|
||||
_value,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.approve, self.web3ContractInstance,
|
||||
)(
|
||||
_spender,
|
||||
_value,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
_spender: string,
|
||||
_value: BigNumber,
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as EtherTokenContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.approve.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
_spender,
|
||||
_value,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
_spender: string,
|
||||
_value: BigNumber,
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as EtherTokenContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.approve.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public totalSupply = {
|
||||
async callAsync(
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<BigNumber
|
||||
> {
|
||||
const self = this as EtherTokenContract;
|
||||
const result = await promisify<BigNumber
|
||||
>(
|
||||
self.web3ContractInstance.totalSupply.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public transferFrom = {
|
||||
async sendTransactionAsync(
|
||||
_from: string,
|
||||
_to: string,
|
||||
_value: BigNumber,
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as EtherTokenContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.transferFrom.estimateGasAsync.bind(
|
||||
self,
|
||||
_from,
|
||||
_to,
|
||||
_value,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.transferFrom, self.web3ContractInstance,
|
||||
)(
|
||||
_from,
|
||||
_to,
|
||||
_value,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
_from: string,
|
||||
_to: string,
|
||||
_value: BigNumber,
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as EtherTokenContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.transferFrom.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
_from,
|
||||
_to,
|
||||
_value,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
_from: string,
|
||||
_to: string,
|
||||
_value: BigNumber,
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as EtherTokenContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.transferFrom.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public withdraw = {
|
||||
async sendTransactionAsync(
|
||||
amount: BigNumber,
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as EtherTokenContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.withdraw.estimateGasAsync.bind(
|
||||
self,
|
||||
amount,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.withdraw, self.web3ContractInstance,
|
||||
)(
|
||||
amount,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
amount: BigNumber,
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as EtherTokenContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.withdraw.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
amount,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
amount: BigNumber,
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as EtherTokenContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.withdraw.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public decimals = {
|
||||
async callAsync(
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<BigNumber
|
||||
> {
|
||||
const self = this as EtherTokenContract;
|
||||
const result = await promisify<BigNumber
|
||||
>(
|
||||
self.web3ContractInstance.decimals.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public balanceOf = {
|
||||
async callAsync(
|
||||
_owner: string,
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<BigNumber
|
||||
> {
|
||||
const self = this as EtherTokenContract;
|
||||
const result = await promisify<BigNumber
|
||||
>(
|
||||
self.web3ContractInstance.balanceOf.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
_owner,
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public symbol = {
|
||||
async callAsync(
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<string
|
||||
> {
|
||||
const self = this as EtherTokenContract;
|
||||
const result = await promisify<string
|
||||
>(
|
||||
self.web3ContractInstance.symbol.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public transfer = {
|
||||
async sendTransactionAsync(
|
||||
_to: string,
|
||||
_value: BigNumber,
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as EtherTokenContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.transfer.estimateGasAsync.bind(
|
||||
self,
|
||||
_to,
|
||||
_value,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.transfer, self.web3ContractInstance,
|
||||
)(
|
||||
_to,
|
||||
_value,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
_to: string,
|
||||
_value: BigNumber,
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as EtherTokenContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.transfer.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
_to,
|
||||
_value,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
_to: string,
|
||||
_value: BigNumber,
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as EtherTokenContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.transfer.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public deposit = {
|
||||
async sendTransactionAsync(
|
||||
txData: TxDataPayable = {},
|
||||
): Promise<string> {
|
||||
const self = this as EtherTokenContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.deposit.estimateGasAsync.bind(
|
||||
self,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.deposit, self.web3ContractInstance,
|
||||
)(
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as EtherTokenContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.deposit.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as EtherTokenContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.deposit.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public allowance = {
|
||||
async callAsync(
|
||||
_owner: string,
|
||||
_spender: string,
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<BigNumber
|
||||
> {
|
||||
const self = this as EtherTokenContract;
|
||||
const result = await promisify<BigNumber
|
||||
>(
|
||||
self.web3ContractInstance.allowance.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
_owner,
|
||||
_spender,
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>) {
|
||||
super(web3ContractInstance, defaults);
|
||||
classUtils.bindAll(this, ['web3ContractInstance', 'defaults']);
|
||||
}
|
||||
} // tslint:disable:max-file-line-count
|
730
packages/0x.js/src/contract_wrappers/generated/exchange.ts
Normal file
730
packages/0x.js/src/contract_wrappers/generated/exchange.ts
Normal file
@@ -0,0 +1,730 @@
|
||||
/**
|
||||
* This file is auto-generated using abi-gen. Don't edit directly.
|
||||
* Templates can be found at https://github.com/0xProject/0x.js/tree/development/packages/abi-gen-templates.
|
||||
*/
|
||||
import {promisify} from '@0xproject/utils';
|
||||
import {BigNumber} from 'bignumber.js';
|
||||
import * as Web3 from 'web3';
|
||||
|
||||
import {TxData, TxDataPayable} from '../../types';
|
||||
import {classUtils} from '../../utils/class_utils';
|
||||
|
||||
import {BaseContract} from './base_contract';
|
||||
|
||||
export class ExchangeContract extends BaseContract {
|
||||
public isRoundingError = {
|
||||
async callAsync(
|
||||
numerator: BigNumber,
|
||||
denominator: BigNumber,
|
||||
target: BigNumber,
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<boolean
|
||||
> {
|
||||
const self = this as ExchangeContract;
|
||||
const result = await promisify<boolean
|
||||
>(
|
||||
self.web3ContractInstance.isRoundingError.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
numerator,
|
||||
denominator,
|
||||
target,
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public filled = {
|
||||
async callAsync(
|
||||
index: string,
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<BigNumber
|
||||
> {
|
||||
const self = this as ExchangeContract;
|
||||
const result = await promisify<BigNumber
|
||||
>(
|
||||
self.web3ContractInstance.filled.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
index,
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public cancelled = {
|
||||
async callAsync(
|
||||
index: string,
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<BigNumber
|
||||
> {
|
||||
const self = this as ExchangeContract;
|
||||
const result = await promisify<BigNumber
|
||||
>(
|
||||
self.web3ContractInstance.cancelled.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
index,
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public fillOrdersUpTo = {
|
||||
async sendTransactionAsync(
|
||||
orderAddresses: string[][],
|
||||
orderValues: BigNumber[][],
|
||||
fillTakerTokenAmount: BigNumber,
|
||||
shouldThrowOnInsufficientBalanceOrAllowance: boolean,
|
||||
v: number|BigNumber[],
|
||||
r: string[],
|
||||
s: string[],
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as ExchangeContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.fillOrdersUpTo.estimateGasAsync.bind(
|
||||
self,
|
||||
orderAddresses,
|
||||
orderValues,
|
||||
fillTakerTokenAmount,
|
||||
shouldThrowOnInsufficientBalanceOrAllowance,
|
||||
v,
|
||||
r,
|
||||
s,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.fillOrdersUpTo, self.web3ContractInstance,
|
||||
)(
|
||||
orderAddresses,
|
||||
orderValues,
|
||||
fillTakerTokenAmount,
|
||||
shouldThrowOnInsufficientBalanceOrAllowance,
|
||||
v,
|
||||
r,
|
||||
s,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
orderAddresses: string[][],
|
||||
orderValues: BigNumber[][],
|
||||
fillTakerTokenAmount: BigNumber,
|
||||
shouldThrowOnInsufficientBalanceOrAllowance: boolean,
|
||||
v: number|BigNumber[],
|
||||
r: string[],
|
||||
s: string[],
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as ExchangeContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.fillOrdersUpTo.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
orderAddresses,
|
||||
orderValues,
|
||||
fillTakerTokenAmount,
|
||||
shouldThrowOnInsufficientBalanceOrAllowance,
|
||||
v,
|
||||
r,
|
||||
s,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
orderAddresses: string[][],
|
||||
orderValues: BigNumber[][],
|
||||
fillTakerTokenAmount: BigNumber,
|
||||
shouldThrowOnInsufficientBalanceOrAllowance: boolean,
|
||||
v: number|BigNumber[],
|
||||
r: string[],
|
||||
s: string[],
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as ExchangeContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.fillOrdersUpTo.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public cancelOrder = {
|
||||
async sendTransactionAsync(
|
||||
orderAddresses: string[],
|
||||
orderValues: BigNumber[],
|
||||
cancelTakerTokenAmount: BigNumber,
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as ExchangeContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.cancelOrder.estimateGasAsync.bind(
|
||||
self,
|
||||
orderAddresses,
|
||||
orderValues,
|
||||
cancelTakerTokenAmount,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.cancelOrder, self.web3ContractInstance,
|
||||
)(
|
||||
orderAddresses,
|
||||
orderValues,
|
||||
cancelTakerTokenAmount,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
orderAddresses: string[],
|
||||
orderValues: BigNumber[],
|
||||
cancelTakerTokenAmount: BigNumber,
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as ExchangeContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.cancelOrder.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
orderAddresses,
|
||||
orderValues,
|
||||
cancelTakerTokenAmount,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
orderAddresses: string[],
|
||||
orderValues: BigNumber[],
|
||||
cancelTakerTokenAmount: BigNumber,
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as ExchangeContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.cancelOrder.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public ZRX_TOKEN_CONTRACT = {
|
||||
async callAsync(
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<string
|
||||
> {
|
||||
const self = this as ExchangeContract;
|
||||
const result = await promisify<string
|
||||
>(
|
||||
self.web3ContractInstance.ZRX_TOKEN_CONTRACT.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public batchFillOrKillOrders = {
|
||||
async sendTransactionAsync(
|
||||
orderAddresses: string[][],
|
||||
orderValues: BigNumber[][],
|
||||
fillTakerTokenAmounts: BigNumber[],
|
||||
v: number|BigNumber[],
|
||||
r: string[],
|
||||
s: string[],
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as ExchangeContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.batchFillOrKillOrders.estimateGasAsync.bind(
|
||||
self,
|
||||
orderAddresses,
|
||||
orderValues,
|
||||
fillTakerTokenAmounts,
|
||||
v,
|
||||
r,
|
||||
s,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.batchFillOrKillOrders, self.web3ContractInstance,
|
||||
)(
|
||||
orderAddresses,
|
||||
orderValues,
|
||||
fillTakerTokenAmounts,
|
||||
v,
|
||||
r,
|
||||
s,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
orderAddresses: string[][],
|
||||
orderValues: BigNumber[][],
|
||||
fillTakerTokenAmounts: BigNumber[],
|
||||
v: number|BigNumber[],
|
||||
r: string[],
|
||||
s: string[],
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as ExchangeContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.batchFillOrKillOrders.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
orderAddresses,
|
||||
orderValues,
|
||||
fillTakerTokenAmounts,
|
||||
v,
|
||||
r,
|
||||
s,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
orderAddresses: string[][],
|
||||
orderValues: BigNumber[][],
|
||||
fillTakerTokenAmounts: BigNumber[],
|
||||
v: number|BigNumber[],
|
||||
r: string[],
|
||||
s: string[],
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as ExchangeContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.batchFillOrKillOrders.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public fillOrKillOrder = {
|
||||
async sendTransactionAsync(
|
||||
orderAddresses: string[],
|
||||
orderValues: BigNumber[],
|
||||
fillTakerTokenAmount: BigNumber,
|
||||
v: number|BigNumber,
|
||||
r: string,
|
||||
s: string,
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as ExchangeContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.fillOrKillOrder.estimateGasAsync.bind(
|
||||
self,
|
||||
orderAddresses,
|
||||
orderValues,
|
||||
fillTakerTokenAmount,
|
||||
v,
|
||||
r,
|
||||
s,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.fillOrKillOrder, self.web3ContractInstance,
|
||||
)(
|
||||
orderAddresses,
|
||||
orderValues,
|
||||
fillTakerTokenAmount,
|
||||
v,
|
||||
r,
|
||||
s,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
orderAddresses: string[],
|
||||
orderValues: BigNumber[],
|
||||
fillTakerTokenAmount: BigNumber,
|
||||
v: number|BigNumber,
|
||||
r: string,
|
||||
s: string,
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as ExchangeContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.fillOrKillOrder.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
orderAddresses,
|
||||
orderValues,
|
||||
fillTakerTokenAmount,
|
||||
v,
|
||||
r,
|
||||
s,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
orderAddresses: string[],
|
||||
orderValues: BigNumber[],
|
||||
fillTakerTokenAmount: BigNumber,
|
||||
v: number|BigNumber,
|
||||
r: string,
|
||||
s: string,
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as ExchangeContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.fillOrKillOrder.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public getUnavailableTakerTokenAmount = {
|
||||
async callAsync(
|
||||
orderHash: string,
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<BigNumber
|
||||
> {
|
||||
const self = this as ExchangeContract;
|
||||
const result = await promisify<BigNumber
|
||||
>(
|
||||
self.web3ContractInstance.getUnavailableTakerTokenAmount.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
orderHash,
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public isValidSignature = {
|
||||
async callAsync(
|
||||
signer: string,
|
||||
hash: string,
|
||||
v: number|BigNumber,
|
||||
r: string,
|
||||
s: string,
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<boolean
|
||||
> {
|
||||
const self = this as ExchangeContract;
|
||||
const result = await promisify<boolean
|
||||
>(
|
||||
self.web3ContractInstance.isValidSignature.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
signer,
|
||||
hash,
|
||||
v,
|
||||
r,
|
||||
s,
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public getPartialAmount = {
|
||||
async callAsync(
|
||||
numerator: BigNumber,
|
||||
denominator: BigNumber,
|
||||
target: BigNumber,
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<BigNumber
|
||||
> {
|
||||
const self = this as ExchangeContract;
|
||||
const result = await promisify<BigNumber
|
||||
>(
|
||||
self.web3ContractInstance.getPartialAmount.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
numerator,
|
||||
denominator,
|
||||
target,
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public TOKEN_TRANSFER_PROXY_CONTRACT = {
|
||||
async callAsync(
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<string
|
||||
> {
|
||||
const self = this as ExchangeContract;
|
||||
const result = await promisify<string
|
||||
>(
|
||||
self.web3ContractInstance.TOKEN_TRANSFER_PROXY_CONTRACT.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public batchFillOrders = {
|
||||
async sendTransactionAsync(
|
||||
orderAddresses: string[][],
|
||||
orderValues: BigNumber[][],
|
||||
fillTakerTokenAmounts: BigNumber[],
|
||||
shouldThrowOnInsufficientBalanceOrAllowance: boolean,
|
||||
v: number|BigNumber[],
|
||||
r: string[],
|
||||
s: string[],
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as ExchangeContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.batchFillOrders.estimateGasAsync.bind(
|
||||
self,
|
||||
orderAddresses,
|
||||
orderValues,
|
||||
fillTakerTokenAmounts,
|
||||
shouldThrowOnInsufficientBalanceOrAllowance,
|
||||
v,
|
||||
r,
|
||||
s,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.batchFillOrders, self.web3ContractInstance,
|
||||
)(
|
||||
orderAddresses,
|
||||
orderValues,
|
||||
fillTakerTokenAmounts,
|
||||
shouldThrowOnInsufficientBalanceOrAllowance,
|
||||
v,
|
||||
r,
|
||||
s,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
orderAddresses: string[][],
|
||||
orderValues: BigNumber[][],
|
||||
fillTakerTokenAmounts: BigNumber[],
|
||||
shouldThrowOnInsufficientBalanceOrAllowance: boolean,
|
||||
v: number|BigNumber[],
|
||||
r: string[],
|
||||
s: string[],
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as ExchangeContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.batchFillOrders.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
orderAddresses,
|
||||
orderValues,
|
||||
fillTakerTokenAmounts,
|
||||
shouldThrowOnInsufficientBalanceOrAllowance,
|
||||
v,
|
||||
r,
|
||||
s,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
orderAddresses: string[][],
|
||||
orderValues: BigNumber[][],
|
||||
fillTakerTokenAmounts: BigNumber[],
|
||||
shouldThrowOnInsufficientBalanceOrAllowance: boolean,
|
||||
v: number|BigNumber[],
|
||||
r: string[],
|
||||
s: string[],
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as ExchangeContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.batchFillOrders.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public batchCancelOrders = {
|
||||
async sendTransactionAsync(
|
||||
orderAddresses: string[][],
|
||||
orderValues: BigNumber[][],
|
||||
cancelTakerTokenAmounts: BigNumber[],
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as ExchangeContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.batchCancelOrders.estimateGasAsync.bind(
|
||||
self,
|
||||
orderAddresses,
|
||||
orderValues,
|
||||
cancelTakerTokenAmounts,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.batchCancelOrders, self.web3ContractInstance,
|
||||
)(
|
||||
orderAddresses,
|
||||
orderValues,
|
||||
cancelTakerTokenAmounts,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
orderAddresses: string[][],
|
||||
orderValues: BigNumber[][],
|
||||
cancelTakerTokenAmounts: BigNumber[],
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as ExchangeContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.batchCancelOrders.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
orderAddresses,
|
||||
orderValues,
|
||||
cancelTakerTokenAmounts,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
orderAddresses: string[][],
|
||||
orderValues: BigNumber[][],
|
||||
cancelTakerTokenAmounts: BigNumber[],
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as ExchangeContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.batchCancelOrders.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public fillOrder = {
|
||||
async sendTransactionAsync(
|
||||
orderAddresses: string[],
|
||||
orderValues: BigNumber[],
|
||||
fillTakerTokenAmount: BigNumber,
|
||||
shouldThrowOnInsufficientBalanceOrAllowance: boolean,
|
||||
v: number|BigNumber,
|
||||
r: string,
|
||||
s: string,
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as ExchangeContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.fillOrder.estimateGasAsync.bind(
|
||||
self,
|
||||
orderAddresses,
|
||||
orderValues,
|
||||
fillTakerTokenAmount,
|
||||
shouldThrowOnInsufficientBalanceOrAllowance,
|
||||
v,
|
||||
r,
|
||||
s,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.fillOrder, self.web3ContractInstance,
|
||||
)(
|
||||
orderAddresses,
|
||||
orderValues,
|
||||
fillTakerTokenAmount,
|
||||
shouldThrowOnInsufficientBalanceOrAllowance,
|
||||
v,
|
||||
r,
|
||||
s,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
orderAddresses: string[],
|
||||
orderValues: BigNumber[],
|
||||
fillTakerTokenAmount: BigNumber,
|
||||
shouldThrowOnInsufficientBalanceOrAllowance: boolean,
|
||||
v: number|BigNumber,
|
||||
r: string,
|
||||
s: string,
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as ExchangeContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.fillOrder.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
orderAddresses,
|
||||
orderValues,
|
||||
fillTakerTokenAmount,
|
||||
shouldThrowOnInsufficientBalanceOrAllowance,
|
||||
v,
|
||||
r,
|
||||
s,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
orderAddresses: string[],
|
||||
orderValues: BigNumber[],
|
||||
fillTakerTokenAmount: BigNumber,
|
||||
shouldThrowOnInsufficientBalanceOrAllowance: boolean,
|
||||
v: number|BigNumber,
|
||||
r: string,
|
||||
s: string,
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as ExchangeContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.fillOrder.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public getOrderHash = {
|
||||
async callAsync(
|
||||
orderAddresses: string[],
|
||||
orderValues: BigNumber[],
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<string
|
||||
> {
|
||||
const self = this as ExchangeContract;
|
||||
const result = await promisify<string
|
||||
>(
|
||||
self.web3ContractInstance.getOrderHash.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
orderAddresses,
|
||||
orderValues,
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public EXTERNAL_QUERY_GAS_LIMIT = {
|
||||
async callAsync(
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<BigNumber
|
||||
> {
|
||||
const self = this as ExchangeContract;
|
||||
const result = await promisify<BigNumber
|
||||
>(
|
||||
self.web3ContractInstance.EXTERNAL_QUERY_GAS_LIMIT.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public VERSION = {
|
||||
async callAsync(
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<string
|
||||
> {
|
||||
const self = this as ExchangeContract;
|
||||
const result = await promisify<string
|
||||
>(
|
||||
self.web3ContractInstance.VERSION.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>) {
|
||||
super(web3ContractInstance, defaults);
|
||||
classUtils.bindAll(this, ['web3ContractInstance', 'defaults']);
|
||||
}
|
||||
} // tslint:disable:max-file-line-count
|
232
packages/0x.js/src/contract_wrappers/generated/token.ts
Normal file
232
packages/0x.js/src/contract_wrappers/generated/token.ts
Normal file
@@ -0,0 +1,232 @@
|
||||
/**
|
||||
* This file is auto-generated using abi-gen. Don't edit directly.
|
||||
* Templates can be found at https://github.com/0xProject/0x.js/tree/development/packages/abi-gen-templates.
|
||||
*/
|
||||
import {promisify} from '@0xproject/utils';
|
||||
import {BigNumber} from 'bignumber.js';
|
||||
import * as Web3 from 'web3';
|
||||
|
||||
import {TxData, TxDataPayable} from '../../types';
|
||||
import {classUtils} from '../../utils/class_utils';
|
||||
|
||||
import {BaseContract} from './base_contract';
|
||||
|
||||
export class TokenContract extends BaseContract {
|
||||
public approve = {
|
||||
async sendTransactionAsync(
|
||||
_spender: string,
|
||||
_value: BigNumber,
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as TokenContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.approve.estimateGasAsync.bind(
|
||||
self,
|
||||
_spender,
|
||||
_value,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.approve, self.web3ContractInstance,
|
||||
)(
|
||||
_spender,
|
||||
_value,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
_spender: string,
|
||||
_value: BigNumber,
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as TokenContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.approve.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
_spender,
|
||||
_value,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
_spender: string,
|
||||
_value: BigNumber,
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as TokenContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.approve.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public totalSupply = {
|
||||
async callAsync(
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<BigNumber
|
||||
> {
|
||||
const self = this as TokenContract;
|
||||
const result = await promisify<BigNumber
|
||||
>(
|
||||
self.web3ContractInstance.totalSupply.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public transferFrom = {
|
||||
async sendTransactionAsync(
|
||||
_from: string,
|
||||
_to: string,
|
||||
_value: BigNumber,
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as TokenContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.transferFrom.estimateGasAsync.bind(
|
||||
self,
|
||||
_from,
|
||||
_to,
|
||||
_value,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.transferFrom, self.web3ContractInstance,
|
||||
)(
|
||||
_from,
|
||||
_to,
|
||||
_value,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
_from: string,
|
||||
_to: string,
|
||||
_value: BigNumber,
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as TokenContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.transferFrom.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
_from,
|
||||
_to,
|
||||
_value,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
_from: string,
|
||||
_to: string,
|
||||
_value: BigNumber,
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as TokenContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.transferFrom.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public balanceOf = {
|
||||
async callAsync(
|
||||
_owner: string,
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<BigNumber
|
||||
> {
|
||||
const self = this as TokenContract;
|
||||
const result = await promisify<BigNumber
|
||||
>(
|
||||
self.web3ContractInstance.balanceOf.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
_owner,
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public transfer = {
|
||||
async sendTransactionAsync(
|
||||
_to: string,
|
||||
_value: BigNumber,
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as TokenContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.transfer.estimateGasAsync.bind(
|
||||
self,
|
||||
_to,
|
||||
_value,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.transfer, self.web3ContractInstance,
|
||||
)(
|
||||
_to,
|
||||
_value,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
_to: string,
|
||||
_value: BigNumber,
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as TokenContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.transfer.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
_to,
|
||||
_value,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
_to: string,
|
||||
_value: BigNumber,
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as TokenContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.transfer.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public allowance = {
|
||||
async callAsync(
|
||||
_owner: string,
|
||||
_spender: string,
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<BigNumber
|
||||
> {
|
||||
const self = this as TokenContract;
|
||||
const result = await promisify<BigNumber
|
||||
>(
|
||||
self.web3ContractInstance.allowance.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
_owner,
|
||||
_spender,
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>) {
|
||||
super(web3ContractInstance, defaults);
|
||||
classUtils.bindAll(this, ['web3ContractInstance', 'defaults']);
|
||||
}
|
||||
} // tslint:disable:max-file-line-count
|
550
packages/0x.js/src/contract_wrappers/generated/token_registry.ts
Normal file
550
packages/0x.js/src/contract_wrappers/generated/token_registry.ts
Normal file
@@ -0,0 +1,550 @@
|
||||
/**
|
||||
* This file is auto-generated using abi-gen. Don't edit directly.
|
||||
* Templates can be found at https://github.com/0xProject/0x.js/tree/development/packages/abi-gen-templates.
|
||||
*/
|
||||
import {promisify} from '@0xproject/utils';
|
||||
import {BigNumber} from 'bignumber.js';
|
||||
import * as Web3 from 'web3';
|
||||
|
||||
import {TxData, TxDataPayable} from '../../types';
|
||||
import {classUtils} from '../../utils/class_utils';
|
||||
|
||||
import {BaseContract} from './base_contract';
|
||||
|
||||
export class TokenRegistryContract extends BaseContract {
|
||||
public removeToken = {
|
||||
async sendTransactionAsync(
|
||||
_token: string,
|
||||
_index: BigNumber,
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as TokenRegistryContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.removeToken.estimateGasAsync.bind(
|
||||
self,
|
||||
_token,
|
||||
_index,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.removeToken, self.web3ContractInstance,
|
||||
)(
|
||||
_token,
|
||||
_index,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
_token: string,
|
||||
_index: BigNumber,
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as TokenRegistryContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.removeToken.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
_token,
|
||||
_index,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
_token: string,
|
||||
_index: BigNumber,
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as TokenRegistryContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.removeToken.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public getTokenAddressByName = {
|
||||
async callAsync(
|
||||
_name: string,
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<string
|
||||
> {
|
||||
const self = this as TokenRegistryContract;
|
||||
const result = await promisify<string
|
||||
>(
|
||||
self.web3ContractInstance.getTokenAddressByName.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
_name,
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public getTokenAddressBySymbol = {
|
||||
async callAsync(
|
||||
_symbol: string,
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<string
|
||||
> {
|
||||
const self = this as TokenRegistryContract;
|
||||
const result = await promisify<string
|
||||
>(
|
||||
self.web3ContractInstance.getTokenAddressBySymbol.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
_symbol,
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public setTokenSwarmHash = {
|
||||
async sendTransactionAsync(
|
||||
_token: string,
|
||||
_swarmHash: string,
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as TokenRegistryContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.setTokenSwarmHash.estimateGasAsync.bind(
|
||||
self,
|
||||
_token,
|
||||
_swarmHash,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.setTokenSwarmHash, self.web3ContractInstance,
|
||||
)(
|
||||
_token,
|
||||
_swarmHash,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
_token: string,
|
||||
_swarmHash: string,
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as TokenRegistryContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.setTokenSwarmHash.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
_token,
|
||||
_swarmHash,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
_token: string,
|
||||
_swarmHash: string,
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as TokenRegistryContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.setTokenSwarmHash.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public getTokenMetaData = {
|
||||
async callAsync(
|
||||
_token: string,
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<[string, string, string, BigNumber, string, string]
|
||||
> {
|
||||
const self = this as TokenRegistryContract;
|
||||
const result = await promisify<[string, string, string, BigNumber, string, string]
|
||||
>(
|
||||
self.web3ContractInstance.getTokenMetaData.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
_token,
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public owner = {
|
||||
async callAsync(
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<string
|
||||
> {
|
||||
const self = this as TokenRegistryContract;
|
||||
const result = await promisify<string
|
||||
>(
|
||||
self.web3ContractInstance.owner.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public addToken = {
|
||||
async sendTransactionAsync(
|
||||
_token: string,
|
||||
_name: string,
|
||||
_symbol: string,
|
||||
_decimals: number|BigNumber,
|
||||
_ipfsHash: string,
|
||||
_swarmHash: string,
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as TokenRegistryContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.addToken.estimateGasAsync.bind(
|
||||
self,
|
||||
_token,
|
||||
_name,
|
||||
_symbol,
|
||||
_decimals,
|
||||
_ipfsHash,
|
||||
_swarmHash,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.addToken, self.web3ContractInstance,
|
||||
)(
|
||||
_token,
|
||||
_name,
|
||||
_symbol,
|
||||
_decimals,
|
||||
_ipfsHash,
|
||||
_swarmHash,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
_token: string,
|
||||
_name: string,
|
||||
_symbol: string,
|
||||
_decimals: number|BigNumber,
|
||||
_ipfsHash: string,
|
||||
_swarmHash: string,
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as TokenRegistryContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.addToken.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
_token,
|
||||
_name,
|
||||
_symbol,
|
||||
_decimals,
|
||||
_ipfsHash,
|
||||
_swarmHash,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
_token: string,
|
||||
_name: string,
|
||||
_symbol: string,
|
||||
_decimals: number|BigNumber,
|
||||
_ipfsHash: string,
|
||||
_swarmHash: string,
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as TokenRegistryContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.addToken.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public setTokenName = {
|
||||
async sendTransactionAsync(
|
||||
_token: string,
|
||||
_name: string,
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as TokenRegistryContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.setTokenName.estimateGasAsync.bind(
|
||||
self,
|
||||
_token,
|
||||
_name,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.setTokenName, self.web3ContractInstance,
|
||||
)(
|
||||
_token,
|
||||
_name,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
_token: string,
|
||||
_name: string,
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as TokenRegistryContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.setTokenName.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
_token,
|
||||
_name,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
_token: string,
|
||||
_name: string,
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as TokenRegistryContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.setTokenName.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public tokens = {
|
||||
async callAsync(
|
||||
index: string,
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<[string, string, string, BigNumber, string, string]
|
||||
> {
|
||||
const self = this as TokenRegistryContract;
|
||||
const result = await promisify<[string, string, string, BigNumber, string, string]
|
||||
>(
|
||||
self.web3ContractInstance.tokens.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
index,
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public tokenAddresses = {
|
||||
async callAsync(
|
||||
index: BigNumber,
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<string
|
||||
> {
|
||||
const self = this as TokenRegistryContract;
|
||||
const result = await promisify<string
|
||||
>(
|
||||
self.web3ContractInstance.tokenAddresses.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
index,
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public getTokenByName = {
|
||||
async callAsync(
|
||||
_name: string,
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<[string, string, string, BigNumber, string, string]
|
||||
> {
|
||||
const self = this as TokenRegistryContract;
|
||||
const result = await promisify<[string, string, string, BigNumber, string, string]
|
||||
>(
|
||||
self.web3ContractInstance.getTokenByName.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
_name,
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public getTokenAddresses = {
|
||||
async callAsync(
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<string[]
|
||||
> {
|
||||
const self = this as TokenRegistryContract;
|
||||
const result = await promisify<string[]
|
||||
>(
|
||||
self.web3ContractInstance.getTokenAddresses.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public setTokenIpfsHash = {
|
||||
async sendTransactionAsync(
|
||||
_token: string,
|
||||
_ipfsHash: string,
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as TokenRegistryContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.setTokenIpfsHash.estimateGasAsync.bind(
|
||||
self,
|
||||
_token,
|
||||
_ipfsHash,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.setTokenIpfsHash, self.web3ContractInstance,
|
||||
)(
|
||||
_token,
|
||||
_ipfsHash,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
_token: string,
|
||||
_ipfsHash: string,
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as TokenRegistryContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.setTokenIpfsHash.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
_token,
|
||||
_ipfsHash,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
_token: string,
|
||||
_ipfsHash: string,
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as TokenRegistryContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.setTokenIpfsHash.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public getTokenBySymbol = {
|
||||
async callAsync(
|
||||
_symbol: string,
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<[string, string, string, BigNumber, string, string]
|
||||
> {
|
||||
const self = this as TokenRegistryContract;
|
||||
const result = await promisify<[string, string, string, BigNumber, string, string]
|
||||
>(
|
||||
self.web3ContractInstance.getTokenBySymbol.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
_symbol,
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public setTokenSymbol = {
|
||||
async sendTransactionAsync(
|
||||
_token: string,
|
||||
_symbol: string,
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as TokenRegistryContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.setTokenSymbol.estimateGasAsync.bind(
|
||||
self,
|
||||
_token,
|
||||
_symbol,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.setTokenSymbol, self.web3ContractInstance,
|
||||
)(
|
||||
_token,
|
||||
_symbol,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
_token: string,
|
||||
_symbol: string,
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as TokenRegistryContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.setTokenSymbol.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
_token,
|
||||
_symbol,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
_token: string,
|
||||
_symbol: string,
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as TokenRegistryContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.setTokenSymbol.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public transferOwnership = {
|
||||
async sendTransactionAsync(
|
||||
newOwner: string,
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as TokenRegistryContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.transferOwnership.estimateGasAsync.bind(
|
||||
self,
|
||||
newOwner,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.transferOwnership, self.web3ContractInstance,
|
||||
)(
|
||||
newOwner,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
newOwner: string,
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as TokenRegistryContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.transferOwnership.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
newOwner,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
newOwner: string,
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as TokenRegistryContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.transferOwnership.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>) {
|
||||
super(web3ContractInstance, defaults);
|
||||
classUtils.bindAll(this, ['web3ContractInstance', 'defaults']);
|
||||
}
|
||||
} // tslint:disable:max-file-line-count
|
@@ -0,0 +1,285 @@
|
||||
/**
|
||||
* This file is auto-generated using abi-gen. Don't edit directly.
|
||||
* Templates can be found at https://github.com/0xProject/0x.js/tree/development/packages/abi-gen-templates.
|
||||
*/
|
||||
import {promisify} from '@0xproject/utils';
|
||||
import {BigNumber} from 'bignumber.js';
|
||||
import * as Web3 from 'web3';
|
||||
|
||||
import {TxData, TxDataPayable} from '../../types';
|
||||
import {classUtils} from '../../utils/class_utils';
|
||||
|
||||
import {BaseContract} from './base_contract';
|
||||
|
||||
export class TokenTransferProxyContract extends BaseContract {
|
||||
public transferFrom = {
|
||||
async sendTransactionAsync(
|
||||
token: string,
|
||||
from: string,
|
||||
to: string,
|
||||
value: BigNumber,
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as TokenTransferProxyContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.transferFrom.estimateGasAsync.bind(
|
||||
self,
|
||||
token,
|
||||
from,
|
||||
to,
|
||||
value,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.transferFrom, self.web3ContractInstance,
|
||||
)(
|
||||
token,
|
||||
from,
|
||||
to,
|
||||
value,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
token: string,
|
||||
from: string,
|
||||
to: string,
|
||||
value: BigNumber,
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as TokenTransferProxyContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.transferFrom.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
token,
|
||||
from,
|
||||
to,
|
||||
value,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
token: string,
|
||||
from: string,
|
||||
to: string,
|
||||
value: BigNumber,
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as TokenTransferProxyContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.transferFrom.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public addAuthorizedAddress = {
|
||||
async sendTransactionAsync(
|
||||
target: string,
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as TokenTransferProxyContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.addAuthorizedAddress.estimateGasAsync.bind(
|
||||
self,
|
||||
target,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.addAuthorizedAddress, self.web3ContractInstance,
|
||||
)(
|
||||
target,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
target: string,
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as TokenTransferProxyContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.addAuthorizedAddress.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
target,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
target: string,
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as TokenTransferProxyContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.addAuthorizedAddress.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public authorities = {
|
||||
async callAsync(
|
||||
index: BigNumber,
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<string
|
||||
> {
|
||||
const self = this as TokenTransferProxyContract;
|
||||
const result = await promisify<string
|
||||
>(
|
||||
self.web3ContractInstance.authorities.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
index,
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public removeAuthorizedAddress = {
|
||||
async sendTransactionAsync(
|
||||
target: string,
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as TokenTransferProxyContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.removeAuthorizedAddress.estimateGasAsync.bind(
|
||||
self,
|
||||
target,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.removeAuthorizedAddress, self.web3ContractInstance,
|
||||
)(
|
||||
target,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
target: string,
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as TokenTransferProxyContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.removeAuthorizedAddress.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
target,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
target: string,
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as TokenTransferProxyContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.removeAuthorizedAddress.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
public owner = {
|
||||
async callAsync(
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<string
|
||||
> {
|
||||
const self = this as TokenTransferProxyContract;
|
||||
const result = await promisify<string
|
||||
>(
|
||||
self.web3ContractInstance.owner.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public authorized = {
|
||||
async callAsync(
|
||||
index: string,
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<boolean
|
||||
> {
|
||||
const self = this as TokenTransferProxyContract;
|
||||
const result = await promisify<boolean
|
||||
>(
|
||||
self.web3ContractInstance.authorized.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
index,
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public getAuthorizedAddresses = {
|
||||
async callAsync(
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<string[]
|
||||
> {
|
||||
const self = this as TokenTransferProxyContract;
|
||||
const result = await promisify<string[]
|
||||
>(
|
||||
self.web3ContractInstance.getAuthorizedAddresses.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
public transferOwnership = {
|
||||
async sendTransactionAsync(
|
||||
newOwner: string,
|
||||
txData: TxData = {},
|
||||
): Promise<string> {
|
||||
const self = this as TokenTransferProxyContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.transferOwnership.estimateGasAsync.bind(
|
||||
self,
|
||||
newOwner,
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.transferOwnership, self.web3ContractInstance,
|
||||
)(
|
||||
newOwner,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
newOwner: string,
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as TokenTransferProxyContract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.transferOwnership.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
newOwner,
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
newOwner: string,
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as TokenTransferProxyContract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.transferOwnership.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
||||
constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>) {
|
||||
super(web3ContractInstance, defaults);
|
||||
classUtils.bindAll(this, ['web3ContractInstance', 'defaults']);
|
||||
}
|
||||
} // tslint:disable:max-file-line-count
|
@@ -1,12 +1,13 @@
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import {artifacts} from '../artifacts';
|
||||
import {Token, TokenMetadata, TokenRegistryContract, ZeroExError} from '../types';
|
||||
import {Token, TokenMetadata, ZeroExError} from '../types';
|
||||
import {assert} from '../utils/assert';
|
||||
import {constants} from '../utils/constants';
|
||||
import {Web3Wrapper} from '../web3_wrapper';
|
||||
|
||||
import {ContractWrapper} from './contract_wrapper';
|
||||
import {TokenRegistryContract} from './generated/token_registry';
|
||||
|
||||
/**
|
||||
* This class includes all the functionality related to interacting with the 0x Token Registry smart contract.
|
||||
@@ -26,8 +27,8 @@ export class TokenRegistryWrapper extends ContractWrapper {
|
||||
};
|
||||
return token;
|
||||
}
|
||||
constructor(web3Wrapper: Web3Wrapper, contractAddressIfExists?: string) {
|
||||
super(web3Wrapper);
|
||||
constructor(web3Wrapper: Web3Wrapper, networkId: number, contractAddressIfExists?: string) {
|
||||
super(web3Wrapper, networkId);
|
||||
this._contractAddressIfExists = contractAddressIfExists;
|
||||
}
|
||||
/**
|
||||
@@ -116,9 +117,12 @@ export class TokenRegistryWrapper extends ContractWrapper {
|
||||
if (!_.isUndefined(this._tokenRegistryContractIfExists)) {
|
||||
return this._tokenRegistryContractIfExists;
|
||||
}
|
||||
const contractInstance = await this._instantiateContractIfExistsAsync<TokenRegistryContract>(
|
||||
const web3ContractInstance = await this._instantiateContractIfExistsAsync(
|
||||
artifacts.TokenRegistryArtifact, this._contractAddressIfExists,
|
||||
);
|
||||
const contractInstance = new TokenRegistryContract(
|
||||
web3ContractInstance, this._web3Wrapper.getContractDefaults(),
|
||||
);
|
||||
this._tokenRegistryContractIfExists = contractInstance;
|
||||
return this._tokenRegistryContractIfExists;
|
||||
}
|
||||
|
@@ -1,10 +1,11 @@
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import {artifacts} from '../artifacts';
|
||||
import {TokenTransferProxyContract, ZeroExError} from '../types';
|
||||
import {Web3Wrapper} from '../web3_wrapper';
|
||||
import {ZeroExError} from '../types';
|
||||
|
||||
import {ContractWrapper} from './contract_wrapper';
|
||||
import {TokenTransferProxyContract} from './generated/token_transfer_proxy';
|
||||
|
||||
/**
|
||||
* This class includes the functionality related to interacting with the TokenTransferProxy contract.
|
||||
@@ -12,8 +13,8 @@ import {ContractWrapper} from './contract_wrapper';
|
||||
export class TokenTransferProxyWrapper extends ContractWrapper {
|
||||
private _tokenTransferProxyContractIfExists?: TokenTransferProxyContract;
|
||||
private _contractAddressIfExists?: string;
|
||||
constructor(web3Wrapper: Web3Wrapper, contractAddressIfExists?: string) {
|
||||
super(web3Wrapper);
|
||||
constructor(web3Wrapper: Web3Wrapper, networkId: number, contractAddressIfExists?: string) {
|
||||
super(web3Wrapper, networkId);
|
||||
this._contractAddressIfExists = contractAddressIfExists;
|
||||
}
|
||||
/**
|
||||
@@ -53,9 +54,12 @@ export class TokenTransferProxyWrapper extends ContractWrapper {
|
||||
if (!_.isUndefined(this._tokenTransferProxyContractIfExists)) {
|
||||
return this._tokenTransferProxyContractIfExists;
|
||||
}
|
||||
const contractInstance = await this._instantiateContractIfExistsAsync<TokenTransferProxyContract>(
|
||||
const web3ContractInstance = await this._instantiateContractIfExistsAsync(
|
||||
artifacts.TokenTransferProxyArtifact, this._contractAddressIfExists,
|
||||
);
|
||||
const contractInstance = new TokenTransferProxyContract(
|
||||
web3ContractInstance, this._web3Wrapper.getContractDefaults(),
|
||||
);
|
||||
this._tokenTransferProxyContractIfExists = contractInstance;
|
||||
return this._tokenTransferProxyContractIfExists;
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import {schemas} from '@0xproject/json-schemas';
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
@@ -9,7 +10,6 @@ import {
|
||||
LogWithDecodedArgs,
|
||||
MethodOpts,
|
||||
SubscriptionOpts,
|
||||
TokenContract,
|
||||
TokenContractEventArgs,
|
||||
TokenEvents,
|
||||
TransactionOpts,
|
||||
@@ -18,9 +18,9 @@ import {
|
||||
import {AbiDecoder} from '../utils/abi_decoder';
|
||||
import {assert} from '../utils/assert';
|
||||
import {constants} from '../utils/constants';
|
||||
import {Web3Wrapper} from '../web3_wrapper';
|
||||
|
||||
import {ContractWrapper} from './contract_wrapper';
|
||||
import {TokenContract} from './generated/token';
|
||||
import {TokenTransferProxyWrapper} from './token_transfer_proxy_wrapper';
|
||||
|
||||
const ALLOWANCE_TO_ZERO_GAS_AMOUNT = 47275;
|
||||
@@ -34,9 +34,9 @@ export class TokenWrapper extends ContractWrapper {
|
||||
public UNLIMITED_ALLOWANCE_IN_BASE_UNITS = constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
|
||||
private _tokenContractsByAddress: {[address: string]: TokenContract};
|
||||
private _tokenTransferProxyWrapper: TokenTransferProxyWrapper;
|
||||
constructor(web3Wrapper: Web3Wrapper, abiDecoder: AbiDecoder,
|
||||
constructor(web3Wrapper: Web3Wrapper, networkId: number, abiDecoder: AbiDecoder,
|
||||
tokenTransferProxyWrapper: TokenTransferProxyWrapper) {
|
||||
super(web3Wrapper, abiDecoder);
|
||||
super(web3Wrapper, networkId, abiDecoder);
|
||||
this._tokenContractsByAddress = {};
|
||||
this._tokenTransferProxyWrapper = tokenTransferProxyWrapper;
|
||||
}
|
||||
@@ -313,9 +313,12 @@ export class TokenWrapper extends ContractWrapper {
|
||||
if (!_.isUndefined(tokenContract)) {
|
||||
return tokenContract;
|
||||
}
|
||||
const contractInstance = await this._instantiateContractIfExistsAsync<TokenContract>(
|
||||
const web3ContractInstance = await this._instantiateContractIfExistsAsync(
|
||||
artifacts.TokenArtifact, tokenAddress,
|
||||
);
|
||||
const contractInstance = new TokenContract(
|
||||
web3ContractInstance, this._web3Wrapper.getContractDefaults(),
|
||||
);
|
||||
tokenContract = contractInstance;
|
||||
this._tokenContractsByAddress[tokenAddress] = tokenContract;
|
||||
return tokenContract;
|
||||
|
6
packages/0x.js/src/globals.d.ts
vendored
6
packages/0x.js/src/globals.d.ts
vendored
@@ -39,12 +39,6 @@ declare module 'compare-versions' {
|
||||
export = compareVersions;
|
||||
}
|
||||
|
||||
// es6-promisify declarations
|
||||
declare function promisify(original: any, settings?: any): ((...arg: any[]) => Promise<any>);
|
||||
declare module 'es6-promisify' {
|
||||
export = promisify;
|
||||
}
|
||||
|
||||
declare module 'ethereumjs-abi' {
|
||||
const soliditySHA3: (argTypes: string[], args: any[]) => Buffer;
|
||||
}
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import * as _ from 'lodash';
|
||||
import * as Web3 from 'web3';
|
||||
|
||||
@@ -11,7 +12,6 @@ import {AbiDecoder} from '../utils/abi_decoder';
|
||||
import {assert} from '../utils/assert';
|
||||
import {intervalUtils} from '../utils/interval_utils';
|
||||
import {utils} from '../utils/utils';
|
||||
import {Web3Wrapper} from '../web3_wrapper';
|
||||
|
||||
const DEFAULT_EVENT_POLLING_INTERVAL_MS = 200;
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import {schemas} from '@0xproject/json-schemas';
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import {ZeroEx} from '../0x';
|
||||
@@ -31,7 +32,6 @@ import {assert} from '../utils/assert';
|
||||
import {intervalUtils} from '../utils/interval_utils';
|
||||
import {OrderStateUtils} from '../utils/order_state_utils';
|
||||
import {utils} from '../utils/utils';
|
||||
import {Web3Wrapper} from '../web3_wrapper';
|
||||
|
||||
import {EventWatcher} from './event_watcher';
|
||||
import {ExpirationWatcher} from './expiration_watcher';
|
||||
|
@@ -52,156 +52,6 @@ export interface DecodedLogEvent<ArgsType> {
|
||||
export type EventCallback<ArgsType> = (err: null|Error, log?: DecodedLogEvent<ArgsType>) => void;
|
||||
export type EventWatcherCallback = (log: LogEvent) => void;
|
||||
|
||||
export interface ExchangeContract extends Web3.ContractInstance {
|
||||
isValidSignature: {
|
||||
callAsync: (signerAddressHex: string, dataHex: string, v: number, r: string, s: string,
|
||||
txOpts?: TxOpts) => Promise<boolean>;
|
||||
};
|
||||
ZRX_TOKEN_CONTRACT: {
|
||||
callAsync: () => Promise<string>;
|
||||
};
|
||||
TOKEN_TRANSFER_PROXY_CONTRACT: {
|
||||
callAsync: () => Promise<string>;
|
||||
};
|
||||
getUnavailableTakerTokenAmount: {
|
||||
callAsync: (orderHash: string, defaultBlock?: Web3.BlockParam) => Promise<BigNumber>;
|
||||
};
|
||||
isRoundingError: {
|
||||
callAsync: (takerTokenFillAmount: BigNumber, takerTokenAmount: BigNumber,
|
||||
makerTokenAmount: BigNumber, txOpts?: TxOpts) => Promise<boolean>;
|
||||
};
|
||||
fillOrder: {
|
||||
sendTransactionAsync: (orderAddresses: OrderAddresses, orderValues: OrderValues,
|
||||
fillTakerTokenAmount: BigNumber,
|
||||
shouldThrowOnInsufficientBalanceOrAllowance: boolean,
|
||||
v: number, r: string, s: string, txOpts?: TxOpts) => Promise<string>;
|
||||
estimateGasAsync: (orderAddresses: OrderAddresses, orderValues: OrderValues,
|
||||
fillTakerTokenAmount: BigNumber,
|
||||
shouldThrowOnInsufficientBalanceOrAllowance: boolean,
|
||||
v: number, r: string, s: string, txOpts?: TxOpts) => Promise<number>;
|
||||
};
|
||||
batchFillOrders: {
|
||||
sendTransactionAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[],
|
||||
fillTakerTokenAmounts: BigNumber[],
|
||||
shouldThrowOnInsufficientBalanceOrAllowance: boolean,
|
||||
v: number[], r: string[], s: string[], txOpts?: TxOpts) => Promise<string>;
|
||||
estimateGasAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[],
|
||||
fillTakerTokenAmounts: BigNumber[],
|
||||
shouldThrowOnInsufficientBalanceOrAllowance: boolean,
|
||||
v: number[], r: string[], s: string[], txOpts?: TxOpts) => Promise<number>;
|
||||
};
|
||||
fillOrdersUpTo: {
|
||||
sendTransactionAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[],
|
||||
fillTakerTokenAmount: BigNumber,
|
||||
shouldThrowOnInsufficientBalanceOrAllowance: boolean,
|
||||
v: number[], r: string[], s: string[], txOpts?: TxOpts) => Promise<string>;
|
||||
estimateGasAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[],
|
||||
fillTakerTokenAmount: BigNumber,
|
||||
shouldThrowOnInsufficientBalanceOrAllowance: boolean,
|
||||
v: number[], r: string[], s: string[], txOpts?: TxOpts) => Promise<number>;
|
||||
};
|
||||
cancelOrder: {
|
||||
sendTransactionAsync: (orderAddresses: OrderAddresses, orderValues: OrderValues,
|
||||
cancelTakerTokenAmount: BigNumber, txOpts?: TxOpts) => Promise<string>;
|
||||
estimateGasAsync: (orderAddresses: OrderAddresses, orderValues: OrderValues,
|
||||
cancelTakerTokenAmount: BigNumber,
|
||||
txOpts?: TxOpts) => Promise<number>;
|
||||
};
|
||||
batchCancelOrders: {
|
||||
sendTransactionAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[],
|
||||
cancelTakerTokenAmounts: BigNumber[], txOpts?: TxOpts) => Promise<string>;
|
||||
estimateGasAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[],
|
||||
cancelTakerTokenAmounts: BigNumber[],
|
||||
txOpts?: TxOpts) => Promise<number>;
|
||||
};
|
||||
fillOrKillOrder: {
|
||||
sendTransactionAsync: (orderAddresses: OrderAddresses, orderValues: OrderValues,
|
||||
fillTakerTokenAmount: BigNumber,
|
||||
v: number, r: string, s: string, txOpts?: TxOpts) => Promise<string>;
|
||||
estimateGasAsync: (orderAddresses: OrderAddresses, orderValues: OrderValues,
|
||||
fillTakerTokenAmount: BigNumber,
|
||||
v: number, r: string, s: string, txOpts?: TxOpts) => Promise<number>;
|
||||
};
|
||||
batchFillOrKillOrders: {
|
||||
sendTransactionAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[],
|
||||
fillTakerTokenAmounts: BigNumber[],
|
||||
v: number[], r: string[], s: string[], txOpts: TxOpts) => Promise<string>;
|
||||
estimateGasAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[],
|
||||
fillTakerTokenAmounts: BigNumber[],
|
||||
v: number[], r: string[], s: string[], txOpts?: TxOpts) => Promise<number>;
|
||||
};
|
||||
filled: {
|
||||
callAsync: (orderHash: string, defaultBlock?: Web3.BlockParam) => Promise<BigNumber>;
|
||||
};
|
||||
cancelled: {
|
||||
callAsync: (orderHash: string, defaultBlock?: Web3.BlockParam) => Promise<BigNumber>;
|
||||
};
|
||||
getOrderHash: {
|
||||
callAsync: (orderAddresses: OrderAddresses, orderValues: OrderValues) => Promise<string>;
|
||||
};
|
||||
}
|
||||
|
||||
export interface TokenContract extends Web3.ContractInstance {
|
||||
balanceOf: {
|
||||
callAsync: (address: string, defaultBlock?: Web3.BlockParam) => Promise<BigNumber>;
|
||||
};
|
||||
allowance: {
|
||||
callAsync: (ownerAddress: string, allowedAddress: string,
|
||||
defaultBlock?: Web3.BlockParam) => Promise<BigNumber>;
|
||||
};
|
||||
transfer: {
|
||||
sendTransactionAsync: (toAddress: string, amountInBaseUnits: BigNumber,
|
||||
txOpts?: TxOpts) => Promise<string>;
|
||||
};
|
||||
transferFrom: {
|
||||
sendTransactionAsync: (fromAddress: string, toAddress: string, amountInBaseUnits: BigNumber,
|
||||
txOpts?: TxOpts) => Promise<string>;
|
||||
};
|
||||
approve: {
|
||||
sendTransactionAsync: (proxyAddress: string, amountInBaseUnits: BigNumber,
|
||||
txOpts?: TxOpts) => Promise<string>;
|
||||
};
|
||||
}
|
||||
|
||||
export interface TokenRegistryContract extends Web3.ContractInstance {
|
||||
getTokenMetaData: {
|
||||
callAsync: (address: string) => Promise<TokenMetadata>;
|
||||
};
|
||||
getTokenAddresses: {
|
||||
callAsync: () => Promise<string[]>;
|
||||
};
|
||||
getTokenAddressBySymbol: {
|
||||
callAsync: (symbol: string) => Promise<string>;
|
||||
};
|
||||
getTokenAddressByName: {
|
||||
callAsync: (name: string) => Promise<string>;
|
||||
};
|
||||
getTokenBySymbol: {
|
||||
callAsync: (symbol: string) => Promise<TokenMetadata>;
|
||||
};
|
||||
getTokenByName: {
|
||||
callAsync: (name: string) => Promise<TokenMetadata>;
|
||||
};
|
||||
}
|
||||
|
||||
export interface EtherTokenContract extends Web3.ContractInstance {
|
||||
deposit: {
|
||||
sendTransactionAsync: (txOpts: TxOpts) => Promise<string>;
|
||||
};
|
||||
withdraw: {
|
||||
sendTransactionAsync: (amount: BigNumber, txOpts: TxOpts) => Promise<string>;
|
||||
};
|
||||
}
|
||||
|
||||
export interface TokenTransferProxyContract extends Web3.ContractInstance {
|
||||
getAuthorizedAddresses: {
|
||||
callAsync: () => Promise<string[]>;
|
||||
};
|
||||
authorized: {
|
||||
callAsync: (address: string) => Promise<boolean>;
|
||||
};
|
||||
}
|
||||
|
||||
export enum SolidityTypes {
|
||||
Address = 'address',
|
||||
Uint256 = 'uint256',
|
||||
@@ -393,10 +243,6 @@ export type AsyncMethod = (...args: any[]) => Promise<any>;
|
||||
*/
|
||||
export type Web3Provider = Web3.Provider;
|
||||
|
||||
export interface ExchangeContractByAddress {
|
||||
[address: string]: ExchangeContract;
|
||||
}
|
||||
|
||||
export interface JSONRPCPayload {
|
||||
params: any[];
|
||||
method: string;
|
||||
@@ -540,6 +386,17 @@ export type OrderState = OrderStateValid|OrderStateInvalid;
|
||||
|
||||
export type OnOrderStateChangeCallback = (orderState: OrderState) => void;
|
||||
|
||||
export interface TxData {
|
||||
from?: string;
|
||||
gas?: number;
|
||||
gasPrice?: BigNumber;
|
||||
nonce?: number;
|
||||
}
|
||||
|
||||
export interface TxDataPayable extends TxData {
|
||||
value?: BigNumber;
|
||||
}
|
||||
|
||||
export interface TransactionReceipt {
|
||||
blockHash: string;
|
||||
blockNumber: number;
|
||||
|
@@ -1,12 +1,12 @@
|
||||
import {assert as sharedAssert} from '@0xproject/assert';
|
||||
import {Schema, SchemaValidator} from '@0xproject/json-schemas';
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as _ from 'lodash';
|
||||
import * as Web3 from 'web3';
|
||||
|
||||
import {ECSignature} from '../types';
|
||||
import {signatureUtils} from '../utils/signature_utils';
|
||||
import {Web3Wrapper} from '../web3_wrapper';
|
||||
|
||||
const HEX_REGEX = /^0x[0-9A-F]*$/i;
|
||||
|
||||
|
18
packages/0x.js/src/utils/class_utils.ts
Normal file
18
packages/0x.js/src/utils/class_utils.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import * as _ from 'lodash';
|
||||
|
||||
export const classUtils = {
|
||||
// This is useful for classes that have nested methods. Nested methods don't get bound out of the box.
|
||||
bindAll(self: any, exclude: string[] = ['contructor'], thisArg?: any): void {
|
||||
for (const key of Object.getOwnPropertyNames(self)) {
|
||||
const val = self[key];
|
||||
if (!_.includes(exclude, key)) {
|
||||
if (_.isFunction(val)) {
|
||||
self[key] = val.bind(thisArg || self);
|
||||
} else if (_.isObject(val)) {
|
||||
classUtils.bindAll(val, exclude, self);
|
||||
}
|
||||
}
|
||||
}
|
||||
return self;
|
||||
},
|
||||
};
|
@@ -1,3 +1,4 @@
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
import * as _ from 'lodash';
|
||||
@@ -12,7 +13,6 @@ import {
|
||||
} from '../src';
|
||||
import {EventWatcher} from '../src/order_watcher/event_watcher';
|
||||
import {DoneCallback} from '../src/types';
|
||||
import {Web3Wrapper} from '../src/web3_wrapper';
|
||||
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
import {constants} from './utils/constants';
|
||||
@@ -60,7 +60,7 @@ describe('EventWatcher', () => {
|
||||
before(async () => {
|
||||
web3 = web3Factory.create();
|
||||
const pollingIntervalMs = 10;
|
||||
web3Wrapper = new Web3Wrapper(web3.currentProvider, constants.TESTRPC_NETWORK_ID);
|
||||
web3Wrapper = new Web3Wrapper(web3.currentProvider);
|
||||
eventWatcher = new EventWatcher(web3Wrapper, pollingIntervalMs);
|
||||
});
|
||||
afterEach(() => {
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
import * as _ from 'lodash';
|
||||
@@ -10,7 +11,6 @@ import {ExpirationWatcher} from '../src/order_watcher/expiration_watcher';
|
||||
import {DoneCallback, Token} from '../src/types';
|
||||
import {constants} from '../src/utils/constants';
|
||||
import {utils} from '../src/utils/utils';
|
||||
import {Web3Wrapper} from '../src/web3_wrapper';
|
||||
|
||||
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
import * as _ from 'lodash';
|
||||
@@ -19,7 +20,6 @@ import {
|
||||
} from '../src';
|
||||
import {OrderStateWatcher} from '../src/order_watcher/order_state_watcher';
|
||||
import {DoneCallback} from '../src/types';
|
||||
import {Web3Wrapper} from '../src/web3_wrapper';
|
||||
|
||||
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
|
@@ -1,6 +1,5 @@
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
import promisify = require('es6-promisify');
|
||||
import * as _ from 'lodash';
|
||||
import 'mocha';
|
||||
import * as Sinon from 'sinon';
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import {promisify} from '@0xproject/utils';
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
import promisify = require('es6-promisify');
|
||||
import 'mocha';
|
||||
import * as Web3 from 'web3';
|
||||
|
||||
@@ -38,12 +39,14 @@ describe('TokenWrapper', () => {
|
||||
let tokenUtils: TokenUtils;
|
||||
let coinbase: string;
|
||||
let addressWithoutFunds: string;
|
||||
let web3Wrapper: Web3Wrapper;
|
||||
const config = {
|
||||
networkId: constants.TESTRPC_NETWORK_ID,
|
||||
};
|
||||
before(async () => {
|
||||
web3 = web3Factory.create();
|
||||
zeroEx = new ZeroEx(web3.currentProvider, config);
|
||||
web3Wrapper = new Web3Wrapper(web3.currentProvider);
|
||||
userAddresses = await zeroEx.getAvailableAddressesAsync();
|
||||
tokens = await zeroEx.tokenRegistry.getTokensAsync();
|
||||
tokenUtils = new TokenUtils(tokens);
|
||||
@@ -237,8 +240,10 @@ describe('TokenWrapper', () => {
|
||||
await zeroEx.token.setAllowanceAsync(zrx.address, coinbase, userWithNormalAllowance, transferAmount);
|
||||
await zeroEx.token.setUnlimitedAllowanceAsync(zrx.address, coinbase, userWithUnlimitedAllowance);
|
||||
|
||||
const initBalanceWithNormalAllowance = await promisify(web3.eth.getBalance)(userWithNormalAllowance);
|
||||
const initBalanceWithUnlimitedAllowance = await promisify(web3.eth.getBalance)(userWithUnlimitedAllowance);
|
||||
const initBalanceWithNormalAllowance = await web3Wrapper.getBalanceInWeiAsync(userWithNormalAllowance);
|
||||
const initBalanceWithUnlimitedAllowance = await web3Wrapper.getBalanceInWeiAsync(
|
||||
userWithUnlimitedAllowance,
|
||||
);
|
||||
|
||||
await zeroEx.token.transferFromAsync(
|
||||
zrx.address, coinbase, userWithNormalAllowance, userWithNormalAllowance, transferAmount,
|
||||
@@ -247,8 +252,10 @@ describe('TokenWrapper', () => {
|
||||
zrx.address, coinbase, userWithUnlimitedAllowance, userWithUnlimitedAllowance, transferAmount,
|
||||
);
|
||||
|
||||
const finalBalanceWithNormalAllowance = await promisify(web3.eth.getBalance)(userWithNormalAllowance);
|
||||
const finalBalanceWithUnlimitedAllowance = await promisify(web3.eth.getBalance)(userWithUnlimitedAllowance);
|
||||
const finalBalanceWithNormalAllowance = await web3Wrapper.getBalanceInWeiAsync(userWithNormalAllowance);
|
||||
const finalBalanceWithUnlimitedAllowance = await web3Wrapper.getBalanceInWeiAsync(
|
||||
userWithUnlimitedAllowance,
|
||||
);
|
||||
|
||||
const normalGasCost = initBalanceWithNormalAllowance.minus(finalBalanceWithNormalAllowance);
|
||||
const unlimitedGasCost = initBalanceWithUnlimitedAllowance.minus(finalBalanceWithUnlimitedAllowance);
|
||||
|
27
packages/abi-gen-templates/contract.mustache
Normal file
27
packages/abi-gen-templates/contract.mustache
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* This file is auto-generated using abi-gen. Don't edit directly.
|
||||
* Templates can be found at https://github.com/0xProject/0x.js/tree/development/packages/abi-gen-templates.
|
||||
*/
|
||||
import {promisify} from '@0xproject/utils';
|
||||
import {BigNumber} from 'bignumber.js';
|
||||
import * as Web3 from 'web3';
|
||||
|
||||
import {TxData, TxDataPayable} from '../../types';
|
||||
import {classUtils} from '../../utils/class_utils';
|
||||
|
||||
import {BaseContract} from './base_contract';
|
||||
|
||||
export class {{contractName}}Contract extends BaseContract {
|
||||
{{#each methods}}
|
||||
{{#this.constant}}
|
||||
{{> call contractName=../contractName}}
|
||||
{{/this.constant}}
|
||||
{{^this.constant}}
|
||||
{{> tx contractName=../contractName}}
|
||||
{{/this.constant}}
|
||||
{{/each}}
|
||||
constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>) {
|
||||
super(web3ContractInstance, defaults);
|
||||
classUtils.bindAll(this, ['web3ContractInstance', 'defaults']);
|
||||
}
|
||||
} // tslint:disable:max-file-line-count
|
15
packages/abi-gen-templates/package.json
Normal file
15
packages/abi-gen-templates/package.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "abi-gen-templates",
|
||||
"private": true,
|
||||
"version": "0.0.2",
|
||||
"description": "Handlebars templates to generate TS contract wrappers",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/0xProject/0x.js.git"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/0xProject/0x.js/issues"
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x.js/packages/abi-gen-templates/README.md"
|
||||
}
|
15
packages/abi-gen-templates/partials/call.mustache
Normal file
15
packages/abi-gen-templates/partials/call.mustache
Normal file
@@ -0,0 +1,15 @@
|
||||
public {{this.name}} = {
|
||||
async callAsync(
|
||||
{{> typed_params inputs=inputs}}
|
||||
defaultBlock?: Web3.BlockParam,
|
||||
): Promise<{{> return_type outputs=outputs}}> {
|
||||
const self = this as {{contractName}}Contract;
|
||||
const result = await promisify<{{> return_type outputs=outputs}}>(
|
||||
self.web3ContractInstance.{{this.name}}.call,
|
||||
self.web3ContractInstance,
|
||||
)(
|
||||
{{> params inputs=inputs}}
|
||||
);
|
||||
return result;
|
||||
},
|
||||
};
|
3
packages/abi-gen-templates/partials/params.mustache
Normal file
3
packages/abi-gen-templates/partials/params.mustache
Normal file
@@ -0,0 +1,3 @@
|
||||
{{#each inputs}}
|
||||
{{name}},
|
||||
{{/each}}
|
6
packages/abi-gen-templates/partials/return_type.mustache
Normal file
6
packages/abi-gen-templates/partials/return_type.mustache
Normal file
@@ -0,0 +1,6 @@
|
||||
{{#singleReturnValue}}
|
||||
{{#returnType outputs.0.type}}{{/returnType}}
|
||||
{{/singleReturnValue}}
|
||||
{{^singleReturnValue}}
|
||||
[{{#each outputs}}{{#returnType type}}{{/returnType}}{{#unless @last}}, {{/unless}}{{/each}}]
|
||||
{{/singleReturnValue}}
|
51
packages/abi-gen-templates/partials/tx.mustache
Normal file
51
packages/abi-gen-templates/partials/tx.mustache
Normal file
@@ -0,0 +1,51 @@
|
||||
public {{this.name}} = {
|
||||
async sendTransactionAsync(
|
||||
{{> typed_params inputs=inputs}}
|
||||
{{#this.payable}}
|
||||
txData: TxDataPayable = {},
|
||||
{{/this.payable}}
|
||||
{{^this.payable}}
|
||||
txData: TxData = {},
|
||||
{{/this.payable}}
|
||||
): Promise<string> {
|
||||
const self = this as {{contractName}}Contract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
self.{{this.name}}.estimateGasAsync.bind(
|
||||
self,
|
||||
{{> params inputs=inputs}}
|
||||
),
|
||||
);
|
||||
const txHash = await promisify<string>(
|
||||
self.web3ContractInstance.{{this.name}}, self.web3ContractInstance,
|
||||
)(
|
||||
{{> params inputs=inputs}}
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return txHash;
|
||||
},
|
||||
async estimateGasAsync(
|
||||
{{> typed_params inputs=inputs}}
|
||||
txData: TxData = {},
|
||||
): Promise<number> {
|
||||
const self = this as {{contractName}}Contract;
|
||||
const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
|
||||
txData,
|
||||
);
|
||||
const gas = await promisify<number>(
|
||||
self.web3ContractInstance.{{this.name}}.estimateGas, self.web3ContractInstance,
|
||||
)(
|
||||
{{> params inputs=inputs}}
|
||||
txDataWithDefaults,
|
||||
);
|
||||
return gas;
|
||||
},
|
||||
getABIEncodedTransactionData(
|
||||
{{> typed_params inputs=inputs}}
|
||||
txData: TxData = {},
|
||||
): string {
|
||||
const self = this as {{contractName}}Contract;
|
||||
const abiEncodedTransactionData = self.web3ContractInstance.{{this.name}}.getData();
|
||||
return abiEncodedTransactionData;
|
||||
},
|
||||
};
|
@@ -0,0 +1,3 @@
|
||||
{{#each inputs}}
|
||||
{{name}}: {{#parameterType type}}{{/parameterType}},
|
||||
{{/each}}
|
39
packages/abi-gen/README.md
Normal file
39
packages/abi-gen/README.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# ABI Gen
|
||||
|
||||
This package allows you to generate TypeScript contract wrappers from ABI files.
|
||||
It's heavily inspired by [Geth abigen](https://github.com/ethereum/go-ethereum/wiki/Native-DApps:-Go-bindings-to-Ethereum-contracts) but takes a different approach.
|
||||
You can write your custom handlebars templates which will allow you to seamlessly integrate the generated code into your existing codebase with existing conventions.
|
||||
|
||||
For an example of the generated [wrapper files](https://github.com/0xProject/0x.js/tree/development/packages/0x.js/src/contract_wrappers/generated) check out 0x.js.
|
||||
[Here](https://github.com/0xProject/0x.js/tree/development/packages/abi-gen-templates) are the templates used to generate those files.
|
||||
|
||||
## Instalation
|
||||
`yarn add -g @0xproject/abi-gen`
|
||||
## Usage
|
||||
```
|
||||
abi-gen
|
||||
Options:
|
||||
--help Show help [boolean]
|
||||
--version Show version number [boolean]
|
||||
--abiGlob Glob pattern to search for ABI JSON files [string] [required]
|
||||
--templates Folder where to search for templates [string] [required]
|
||||
--output Folder where to put the output files [string] [required]
|
||||
```
|
||||
## ABI files
|
||||
You're required to pass a [glob](https://en.wikipedia.org/wiki/Glob_(programming)) template where your abi files are located.
|
||||
TL;DR - here is the example from 0x.js.
|
||||
|
||||
`--abiGlob 'src/artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry).json`
|
||||
|
||||
We could've just used `--abiGlob 'src/artifacts/*.json` but we wanted to exclude some of the abi files.
|
||||
|
||||
The abi file should be either a [Truffle](http://truffleframework.com/) contract artifact (a JSON object with an abi key) or a JSON abi array.
|
||||
## How to write custom templates?
|
||||
The best way to get started is to copy [0x.js templates](https://github.com/0xProject/0x.js/tree/development/packages/abi-gen-templates) and start adjusting them for your needs.
|
||||
We use [handlebars](handlebarsjs.com) template engine under the hood.
|
||||
You need to have a master template called `contract.mustache`. it will be used to generate each contract wrapper. Although - you don't need and probably shouldn't write all your logic in a single template file. You can write [partial templates](http://handlebarsjs.com/partials.html) and as long as they are within a partials folder - they will be registered and available.
|
||||
## Which data/context do I get in my templates?
|
||||
For now you don't get much on top of methods abi, some useful helpers and a contract name because it was enough for our use-case, but if you need something else - create a PR.
|
||||
See the [type definition](https://github.com/0xProject/0x.js/tree/development/packages/abi-gen/src/types.ts) of what we pass to the render method.
|
||||
## Output files
|
||||
Output files will be generated within an output folder with names converted to camel case and taken from abi file names. If you already have some files in that folder they will be overwritten.
|
48
packages/abi-gen/package.json
Normal file
48
packages/abi-gen/package.json
Normal file
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "@0xproject/abi-gen",
|
||||
"version": "0.0.2",
|
||||
"description": "Generate contract wrappers from ABI and handlebars templates",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
"scripts": {
|
||||
"lint": "tslint --project . 'src/**/*.ts'",
|
||||
"clean": "shx rm -rf lib",
|
||||
"build": "tsc"
|
||||
},
|
||||
"bin": {
|
||||
"abi-gen": "lib/index.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/0xProject/0x.js.git"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/0xProject/0x.js/issues"
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x.js/packages/abi-gen/README.md",
|
||||
"dependencies": {
|
||||
"bignumber.js": "~4.1.0",
|
||||
"chalk": "^2.3.0",
|
||||
"glob": "^7.1.2",
|
||||
"handlebars": "^4.0.11",
|
||||
"lodash": "^4.17.4",
|
||||
"mkdirp": "^0.5.1",
|
||||
"to-snake-case": "^1.0.0",
|
||||
"web3": "^0.20.0",
|
||||
"yargs": "^10.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@0xproject/tslint-config": "^0.2.1",
|
||||
"@types/glob": "^5.0.33",
|
||||
"@types/handlebars": "^4.0.36",
|
||||
"@types/mkdirp": "^0.5.1",
|
||||
"@types/node": "^8.0.53",
|
||||
"@types/yargs": "^8.0.2",
|
||||
"npm-run-all": "^4.1.2",
|
||||
"shx": "^0.2.2",
|
||||
"tslint": "5.8.0",
|
||||
"typescript": "~2.6.1",
|
||||
"web3-typescript-typings": "^0.7.2"
|
||||
}
|
||||
}
|
4
packages/abi-gen/src/globals.d.ts
vendored
Normal file
4
packages/abi-gen/src/globals.d.ts
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
declare function toSnakeCase(str: string): string;
|
||||
declare module 'to-snake-case' {
|
||||
export = toSnakeCase;
|
||||
}
|
98
packages/abi-gen/src/index.ts
Normal file
98
packages/abi-gen/src/index.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import chalk from 'chalk';
|
||||
import * as fs from 'fs';
|
||||
import {sync as globSync} from 'glob';
|
||||
import * as Handlebars from 'handlebars';
|
||||
import * as _ from 'lodash';
|
||||
import * as mkdirp from 'mkdirp';
|
||||
import * as yargs from 'yargs';
|
||||
|
||||
import toSnakeCase = require('to-snake-case');
|
||||
import * as Web3 from 'web3';
|
||||
|
||||
import {ContextData, ParamKind} from './types';
|
||||
import {utils} from './utils';
|
||||
|
||||
const ABI_TYPE_METHOD = 'function';
|
||||
const MAIN_TEMPLATE_NAME = 'contract.mustache';
|
||||
|
||||
const args = yargs
|
||||
.option('abiGlob', {
|
||||
describe: 'Glob pattern to search for ABI JSON files',
|
||||
type: 'string',
|
||||
demand: true,
|
||||
})
|
||||
.option('templates', {
|
||||
describe: 'Folder where to search for templates',
|
||||
type: 'string',
|
||||
demand: true,
|
||||
})
|
||||
.option('output', {
|
||||
describe: 'Folder where to put the output files',
|
||||
type: 'string',
|
||||
demand: true,
|
||||
})
|
||||
.argv;
|
||||
|
||||
function writeOutputFile(name: string, renderedTsCode: string): void {
|
||||
const fileName = toSnakeCase(name);
|
||||
const filePath = `${args.output}/${fileName}.ts`;
|
||||
fs.writeFileSync(filePath, renderedTsCode);
|
||||
utils.log(`Created: ${chalk.bold(filePath)}`);
|
||||
}
|
||||
|
||||
Handlebars.registerHelper('parameterType', utils.solTypeToTsType.bind(utils, ParamKind.Input));
|
||||
Handlebars.registerHelper('returnType', utils.solTypeToTsType.bind(utils, ParamKind.Output));
|
||||
const partialTemplateFileNames = globSync(`${args.templates}/partials/**/*.mustache`);
|
||||
for (const partialTemplateFileName of partialTemplateFileNames) {
|
||||
const namedContent = utils.getNamedContent(partialTemplateFileName);
|
||||
Handlebars.registerPartial(namedContent.name, namedContent.content);
|
||||
}
|
||||
|
||||
const mainTemplate = utils.getNamedContent(`${args.templates}/${MAIN_TEMPLATE_NAME}`);
|
||||
const template = Handlebars.compile<ContextData>(mainTemplate.content);
|
||||
const abiFileNames = globSync(args.abiGlob);
|
||||
if (_.isEmpty(abiFileNames)) {
|
||||
utils.log(`${chalk.red(`No ABI files found.`)}`);
|
||||
utils.log(`Please make sure you've passed the correct folder name and that the files have
|
||||
${chalk.bold('*.json')} extensions`);
|
||||
process.exit(1);
|
||||
} else {
|
||||
utils.log(`Found ${chalk.green(`${abiFileNames.length}`)} ${chalk.bold('ABI')} files`);
|
||||
mkdirp.sync(args.output);
|
||||
}
|
||||
for (const abiFileName of abiFileNames) {
|
||||
const namedContent = utils.getNamedContent(abiFileName);
|
||||
utils.log(`Processing: ${chalk.bold(namedContent.name)}...`);
|
||||
const parsedContent = JSON.parse(namedContent.content);
|
||||
const ABI = _.isArray(parsedContent) ?
|
||||
parsedContent : // ABI file
|
||||
parsedContent.abi; // Truffle contracts file
|
||||
if (_.isUndefined(ABI)) {
|
||||
utils.log(`${chalk.red(`ABI not found in ${abiFileName}.`)}`);
|
||||
utils.log(`Please make sure your ABI file is either an array with ABI entries or an object with the abi key`);
|
||||
process.exit(1);
|
||||
}
|
||||
const methodAbis = ABI.filter((abi: Web3.AbiDefinition) => abi.type === ABI_TYPE_METHOD) as Web3.MethodAbi[];
|
||||
const methodsData = _.map(methodAbis, methodAbi => {
|
||||
_.map(methodAbi.inputs, input => {
|
||||
if (_.isEmpty(input.name)) {
|
||||
// Auto-generated getters don't have parameter names
|
||||
input.name = 'index';
|
||||
}
|
||||
});
|
||||
// This will make templates simpler
|
||||
const methodData = {
|
||||
...methodAbi,
|
||||
singleReturnValue: methodAbi.outputs.length === 1,
|
||||
};
|
||||
return methodData;
|
||||
});
|
||||
const contextData = {
|
||||
contractName: namedContent.name,
|
||||
methods: methodsData,
|
||||
};
|
||||
const renderedTsCode = template(contextData);
|
||||
writeOutputFile(namedContent.name, renderedTsCode);
|
||||
}
|
15
packages/abi-gen/src/types.ts
Normal file
15
packages/abi-gen/src/types.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import * as Web3 from 'web3';
|
||||
|
||||
export enum ParamKind {
|
||||
Input = 'input',
|
||||
Output = 'output',
|
||||
}
|
||||
|
||||
export interface Method extends Web3.MethodAbi {
|
||||
singleReturnValue: boolean;
|
||||
}
|
||||
|
||||
export interface ContextData {
|
||||
contractName: string;
|
||||
methods: Method[];
|
||||
}
|
56
packages/abi-gen/src/utils.ts
Normal file
56
packages/abi-gen/src/utils.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import * as fs from 'fs';
|
||||
import * as _ from 'lodash';
|
||||
import * as path from 'path';
|
||||
|
||||
import {ParamKind} from './types';
|
||||
|
||||
export const utils = {
|
||||
solTypeToTsType(paramKind: ParamKind, solType: string): string {
|
||||
const trailingArrayRegex = /\[\d*\]$/;
|
||||
if (solType.match(trailingArrayRegex)) {
|
||||
const arrayItemSolType = solType.replace(trailingArrayRegex, '');
|
||||
const arrayItemTsType = utils.solTypeToTsType(paramKind, arrayItemSolType);
|
||||
const arrayTsType = `${arrayItemTsType}[]`;
|
||||
return arrayTsType;
|
||||
} else {
|
||||
const solTypeRegexToTsType = [
|
||||
{regex: '^string$', tsType: 'string'},
|
||||
{regex: '^address$', tsType: 'string'},
|
||||
{regex: '^bool$', tsType: 'boolean'},
|
||||
{regex: '^u?int\\d*$', tsType: 'BigNumber'},
|
||||
{regex: '^bytes\\d*$', tsType: 'string'},
|
||||
];
|
||||
if (paramKind === ParamKind.Input) {
|
||||
// web3 allows to pass those an non-bignumbers and that's nice
|
||||
// but it always returns stuff as BigNumbers
|
||||
solTypeRegexToTsType.unshift({regex: '^u?int(8|16|32)?$', tsType: 'number|BigNumber'});
|
||||
}
|
||||
for (const regexAndTxType of solTypeRegexToTsType) {
|
||||
const {regex, tsType} = regexAndTxType;
|
||||
if (solType.match(regex)) {
|
||||
return tsType;
|
||||
}
|
||||
}
|
||||
throw new Error(`Unknown Solidity type found: ${solType}`);
|
||||
}
|
||||
},
|
||||
log(...args: any[]): void {
|
||||
console.log(...args); // tslint:disable-line:no-console
|
||||
},
|
||||
getPartialNameFromFileName(filename: string): string {
|
||||
const name = path.parse(filename).name;
|
||||
return name;
|
||||
},
|
||||
getNamedContent(filename: string): {name: string; content: string} {
|
||||
const name = utils.getPartialNameFromFileName(filename);
|
||||
try {
|
||||
const content = fs.readFileSync(filename).toString();
|
||||
return {
|
||||
name,
|
||||
content,
|
||||
};
|
||||
} catch (err) {
|
||||
throw new Error(`Failed to read ${filename}: ${err}`);
|
||||
}
|
||||
},
|
||||
};
|
17
packages/abi-gen/tsconfig.json
Normal file
17
packages/abi-gen/tsconfig.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"lib": ["es2015", "dom"],
|
||||
"outDir": "lib",
|
||||
"sourceMap": true,
|
||||
"declaration": true,
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true
|
||||
},
|
||||
"include": [
|
||||
"./src/**/*",
|
||||
"./test/**/*",
|
||||
"../../node_modules/web3-typescript-typings/index.d.ts"
|
||||
]
|
||||
}
|
5
packages/abi-gen/tslint.json
Normal file
5
packages/abi-gen/tslint.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"extends": [
|
||||
"@0xproject/tslint-config"
|
||||
]
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0xproject/assert",
|
||||
"version": "0.0.6",
|
||||
"version": "0.0.7",
|
||||
"description": "Provides a standard way of performing type and schema validation across 0x projects",
|
||||
"main": "lib/src/index.js",
|
||||
"types": "lib/src/index.d.ts",
|
||||
@@ -23,21 +23,21 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x.js/packages/assert/README.md",
|
||||
"devDependencies": {
|
||||
"@0xproject/tslint-config": "^0.2.0",
|
||||
"@types/lodash": "^4.14.78",
|
||||
"@0xproject/tslint-config": "^0.2.1",
|
||||
"@types/lodash": "^4.14.86",
|
||||
"@types/mocha": "^2.2.42",
|
||||
"@types/valid-url": "^1.0.2",
|
||||
"chai": "^4.0.1",
|
||||
"chai-typescript-typings": "^0.0.1",
|
||||
"dirty-chai": "^2.0.1",
|
||||
"mocha": "^4.0.1",
|
||||
"npm-run-all": "^4.1.1",
|
||||
"npm-run-all": "^4.1.2",
|
||||
"shx": "^0.2.2",
|
||||
"tslint": "5.8.0",
|
||||
"typescript": "^2.4.2"
|
||||
"typescript": "~2.6.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0xproject/json-schemas": "^0.6.9",
|
||||
"@0xproject/json-schemas": "^0.6.10",
|
||||
"bignumber.js": "~4.1.0",
|
||||
"ethereum-address": "^0.0.4",
|
||||
"lodash": "^4.17.4",
|
||||
|
@@ -1,5 +1,16 @@
|
||||
# CHANGELOG
|
||||
|
||||
v0.3.0 - _December 8, 2017_
|
||||
------------------------
|
||||
* Expose WebSocketOrderbookChannel and associated types to public interface (#251)
|
||||
* Remove tokenA and tokenB fields from OrdersRequest (#256)
|
||||
|
||||
v0.2.0 - _November 29, 2017_
|
||||
------------------------
|
||||
* Add SignedOrder and TokenTradeInfo to the public interface
|
||||
* Add ECSignature and Order to the public interface
|
||||
* Remove dependency on 0x.js
|
||||
|
||||
v0.1.0 - _November 22, 2017_
|
||||
------------------------
|
||||
* Provide a HttpClient class for interacting with standard relayer api compliant HTTP urls
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0xproject/connect",
|
||||
"version": "0.1.2",
|
||||
"version": "0.3.0",
|
||||
"description": "A javascript library for interacting with the standard relayer api",
|
||||
"keywords": [
|
||||
"connect",
|
||||
@@ -36,9 +36,8 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x.js/packages/connect/README.md",
|
||||
"dependencies": {
|
||||
"0x.js": "^0.27.1",
|
||||
"@0xproject/assert": "^0.0.6",
|
||||
"@0xproject/json-schemas": "^0.6.9",
|
||||
"@0xproject/assert": "^0.0.7",
|
||||
"@0xproject/json-schemas": "^0.6.10",
|
||||
"bignumber.js": "~4.1.0",
|
||||
"isomorphic-fetch": "^2.2.1",
|
||||
"lodash": "^4.17.4",
|
||||
@@ -46,25 +45,25 @@
|
||||
"websocket": "^1.0.25"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@0xproject/tslint-config": "^0.2.0",
|
||||
"@0xproject/tslint-config": "^0.2.1",
|
||||
"@types/fetch-mock": "^5.12.1",
|
||||
"@types/lodash": "^4.14.77",
|
||||
"@types/lodash": "^4.14.86",
|
||||
"@types/mocha": "^2.2.42",
|
||||
"@types/query-string": "^5.0.1",
|
||||
"@types/websocket": "^0.0.34",
|
||||
"chai": "^4.0.1",
|
||||
"chai-as-promised": "^7.1.0",
|
||||
"chai-as-promised-typescript-typings": "0.0.3",
|
||||
"chai-as-promised-typescript-typings": "^0.0.3",
|
||||
"chai-typescript-typings": "^0.0.1",
|
||||
"copyfiles": "^1.2.0",
|
||||
"dirty-chai": "^2.0.1",
|
||||
"fetch-mock": "^5.13.1",
|
||||
"mocha": "^4.0.0",
|
||||
"npm-run-all": "^4.0.2",
|
||||
"mocha": "^4.0.1",
|
||||
"npm-run-all": "^4.1.2",
|
||||
"shx": "^0.2.2",
|
||||
"tslint": "5.8.0",
|
||||
"typedoc": "~0.8.0",
|
||||
"typescript": "~2.6.1",
|
||||
"web3-typescript-typings": "^0.7.1"
|
||||
"web3-typescript-typings": "^0.7.2"
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,3 @@
|
||||
import {SignedOrder} from '0x.js';
|
||||
import {assert} from '@0xproject/assert';
|
||||
import {schemas} from '@0xproject/json-schemas';
|
||||
import {BigNumber} from 'bignumber.js';
|
||||
@@ -16,6 +15,7 @@ import {
|
||||
OrderbookRequest,
|
||||
OrderbookResponse,
|
||||
OrdersRequest,
|
||||
SignedOrder,
|
||||
TokenPairsItem,
|
||||
TokenPairsRequest,
|
||||
} from './types';
|
||||
@@ -34,7 +34,7 @@ export class HttpClient implements Client {
|
||||
private apiEndpointUrl: string;
|
||||
/**
|
||||
* Instantiates a new HttpClient instance
|
||||
* @param url The base url for making API calls
|
||||
* @param url The relayer API base HTTP url you would like to interact with
|
||||
* @return An instance of HttpClient
|
||||
*/
|
||||
constructor(url: string) {
|
||||
|
@@ -1,11 +1,19 @@
|
||||
export {HttpClient} from './http_client';
|
||||
export {WebSocketOrderbookChannel} from './ws_orderbook_channel';
|
||||
export {
|
||||
Client,
|
||||
ECSignature,
|
||||
FeesRequest,
|
||||
FeesResponse,
|
||||
Order,
|
||||
OrderbookChannel,
|
||||
OrderbookChannelHandler,
|
||||
OrderbookChannelSubscriptionOpts,
|
||||
OrderbookRequest,
|
||||
OrderbookResponse,
|
||||
OrdersRequest,
|
||||
SignedOrder,
|
||||
TokenPairsItem,
|
||||
TokenPairsRequest,
|
||||
TokenTradeInfo,
|
||||
} from './types';
|
||||
|
@@ -1,6 +1,34 @@
|
||||
import {SignedOrder} from '0x.js';
|
||||
import {BigNumber} from 'bignumber.js';
|
||||
|
||||
// TODO: Consolidate Order, SignedOrder and ECSignature into a shared package instead of duplicating them from 0x.js
|
||||
export interface Order {
|
||||
maker: string;
|
||||
taker: string;
|
||||
makerFee: BigNumber;
|
||||
takerFee: BigNumber;
|
||||
makerTokenAmount: BigNumber;
|
||||
takerTokenAmount: BigNumber;
|
||||
makerTokenAddress: string;
|
||||
takerTokenAddress: string;
|
||||
salt: BigNumber;
|
||||
exchangeContractAddress: string;
|
||||
feeRecipient: string;
|
||||
expirationUnixTimestampSec: BigNumber;
|
||||
}
|
||||
|
||||
export interface SignedOrder extends Order {
|
||||
ecSignature: ECSignature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Elliptic Curve signature
|
||||
*/
|
||||
export interface ECSignature {
|
||||
v: number;
|
||||
r: string;
|
||||
s: string;
|
||||
}
|
||||
|
||||
export interface Client {
|
||||
getTokenPairsAsync: (request?: TokenPairsRequest) => Promise<TokenPairsItem[]>;
|
||||
getOrdersAsync: (request?: OrdersRequest) => Promise<SignedOrder[]>;
|
||||
@@ -29,10 +57,13 @@ export interface OrderbookChannelSubscriptionOpts {
|
||||
}
|
||||
|
||||
export interface OrderbookChannelHandler {
|
||||
onSnapshot: (channel: OrderbookChannel, snapshot: OrderbookResponse) => void;
|
||||
onUpdate: (channel: OrderbookChannel, order: SignedOrder) => void;
|
||||
onError: (channel: OrderbookChannel, err: Error) => void;
|
||||
onClose: (channel: OrderbookChannel) => void;
|
||||
onSnapshot: (channel: OrderbookChannel, subscriptionOpts: OrderbookChannelSubscriptionOpts,
|
||||
snapshot: OrderbookResponse) => void;
|
||||
onUpdate: (channel: OrderbookChannel, subscriptionOpts: OrderbookChannelSubscriptionOpts,
|
||||
order: SignedOrder) => void;
|
||||
onError: (channel: OrderbookChannel, subscriptionOpts: OrderbookChannelSubscriptionOpts,
|
||||
err: Error) => void;
|
||||
onClose: (channel: OrderbookChannel, subscriptionOpts: OrderbookChannelSubscriptionOpts) => void;
|
||||
}
|
||||
|
||||
export type OrderbookChannelMessage =
|
||||
@@ -48,16 +79,19 @@ export enum OrderbookChannelMessageTypes {
|
||||
|
||||
export interface SnapshotOrderbookChannelMessage {
|
||||
type: OrderbookChannelMessageTypes.Snapshot;
|
||||
requestId: number;
|
||||
payload: OrderbookResponse;
|
||||
}
|
||||
|
||||
export interface UpdateOrderbookChannelMessage {
|
||||
type: OrderbookChannelMessageTypes.Update;
|
||||
requestId: number;
|
||||
payload: SignedOrder;
|
||||
}
|
||||
|
||||
export interface UnknownOrderbookChannelMessage {
|
||||
type: OrderbookChannelMessageTypes.Unknown;
|
||||
requestId: number;
|
||||
payload: undefined;
|
||||
}
|
||||
|
||||
@@ -94,8 +128,6 @@ export interface OrdersRequest {
|
||||
tokenAddress?: string;
|
||||
makerTokenAddress?: string;
|
||||
takerTokenAddress?: string;
|
||||
tokenA?: string;
|
||||
tokenB?: string;
|
||||
maker?: string;
|
||||
taker?: string;
|
||||
trader?: string;
|
||||
|
@@ -1,4 +1,3 @@
|
||||
import {SignedOrder} from '0x.js';
|
||||
import {assert} from '@0xproject/assert';
|
||||
import {schemas} from '@0xproject/json-schemas';
|
||||
import * as _ from 'lodash';
|
||||
@@ -6,6 +5,7 @@ import * as _ from 'lodash';
|
||||
import {
|
||||
OrderbookChannelMessage,
|
||||
OrderbookChannelMessageTypes,
|
||||
SignedOrder,
|
||||
} from '../types';
|
||||
|
||||
import {typeConverters} from './type_converters';
|
||||
@@ -15,28 +15,24 @@ export const orderbookChannelMessageParsers = {
|
||||
const messageObj = JSON.parse(utf8Data);
|
||||
const type: string = _.get(messageObj, 'type');
|
||||
assert.assert(!_.isUndefined(type), `Message is missing a type parameter: ${utf8Data}`);
|
||||
assert.isString('type', type);
|
||||
switch (type) {
|
||||
case (OrderbookChannelMessageTypes.Snapshot): {
|
||||
assert.doesConformToSchema('message', messageObj, schemas.relayerApiOrderbookChannelSnapshotSchema);
|
||||
const orderbook = messageObj.payload;
|
||||
typeConverters.convertOrderbookStringFieldsToBigNumber(orderbook);
|
||||
return {
|
||||
type,
|
||||
payload: orderbook,
|
||||
};
|
||||
return messageObj;
|
||||
}
|
||||
case (OrderbookChannelMessageTypes.Update): {
|
||||
assert.doesConformToSchema('message', messageObj, schemas.relayerApiOrderbookChannelUpdateSchema);
|
||||
const order = messageObj.payload;
|
||||
typeConverters.convertOrderStringFieldsToBigNumber(order);
|
||||
return {
|
||||
type,
|
||||
payload: order,
|
||||
};
|
||||
return messageObj;
|
||||
}
|
||||
default: {
|
||||
return {
|
||||
type: OrderbookChannelMessageTypes.Unknown,
|
||||
requestId: 0,
|
||||
payload: undefined,
|
||||
};
|
||||
}
|
||||
|
@@ -1,4 +1,3 @@
|
||||
import {SignedOrder} from '0x.js';
|
||||
import {assert} from '@0xproject/assert';
|
||||
import {schemas} from '@0xproject/json-schemas';
|
||||
import * as _ from 'lodash';
|
||||
@@ -9,6 +8,7 @@ import {
|
||||
OrderbookChannelHandler,
|
||||
OrderbookChannelMessageTypes,
|
||||
OrderbookChannelSubscriptionOpts,
|
||||
SignedOrder,
|
||||
WebsocketClientEventType,
|
||||
WebsocketConnectionEventType,
|
||||
} from './types';
|
||||
@@ -22,9 +22,10 @@ export class WebSocketOrderbookChannel implements OrderbookChannel {
|
||||
private apiEndpointUrl: string;
|
||||
private client: WebSocket.client;
|
||||
private connectionIfExists?: WebSocket.connection;
|
||||
private subscriptionCounter = 0;
|
||||
/**
|
||||
* Instantiates a new WebSocketOrderbookChannel instance
|
||||
* @param url The base url for making API calls
|
||||
* @param url The relayer API base WS url you would like to interact with
|
||||
* @return An instance of WebSocketOrderbookChannel
|
||||
*/
|
||||
constructor(url: string) {
|
||||
@@ -46,23 +47,25 @@ export class WebSocketOrderbookChannel implements OrderbookChannel {
|
||||
assert.isFunction('handler.onUpdate', _.get(handler, 'onUpdate'));
|
||||
assert.isFunction('handler.onError', _.get(handler, 'onError'));
|
||||
assert.isFunction('handler.onClose', _.get(handler, 'onClose'));
|
||||
this.subscriptionCounter += 1;
|
||||
const subscribeMessage = {
|
||||
type: 'subscribe',
|
||||
channel: 'orderbook',
|
||||
requestId: this.subscriptionCounter,
|
||||
payload: subscriptionOpts,
|
||||
};
|
||||
this._getConnection((error, connection) => {
|
||||
if (!_.isUndefined(error)) {
|
||||
handler.onError(this, error);
|
||||
handler.onError(this, subscriptionOpts, error);
|
||||
} else if (!_.isUndefined(connection) && connection.connected) {
|
||||
connection.on(WebsocketConnectionEventType.Error, wsError => {
|
||||
handler.onError(this, wsError);
|
||||
handler.onError(this, subscriptionOpts, wsError);
|
||||
});
|
||||
connection.on(WebsocketConnectionEventType.Close, () => {
|
||||
handler.onClose(this);
|
||||
handler.onClose(this, subscriptionOpts);
|
||||
});
|
||||
connection.on(WebsocketConnectionEventType.Message, message => {
|
||||
this._handleWebSocketMessage(message, handler);
|
||||
this._handleWebSocketMessage(subscribeMessage.requestId, subscriptionOpts, message, handler);
|
||||
});
|
||||
connection.sendUTF(JSON.stringify(subscribeMessage));
|
||||
}
|
||||
@@ -90,30 +93,34 @@ export class WebSocketOrderbookChannel implements OrderbookChannel {
|
||||
this.client.connect(this.apiEndpointUrl);
|
||||
}
|
||||
}
|
||||
private _handleWebSocketMessage(message: WebSocket.IMessage, handler: OrderbookChannelHandler): void {
|
||||
private _handleWebSocketMessage(requestId: number, subscriptionOpts: OrderbookChannelSubscriptionOpts,
|
||||
message: WebSocket.IMessage, handler: OrderbookChannelHandler): void {
|
||||
if (!_.isUndefined(message.utf8Data)) {
|
||||
try {
|
||||
const utf8Data = message.utf8Data;
|
||||
const parserResult = orderbookChannelMessageParsers.parser(utf8Data);
|
||||
const type = parserResult.type;
|
||||
switch (parserResult.type) {
|
||||
case (OrderbookChannelMessageTypes.Snapshot): {
|
||||
handler.onSnapshot(this, parserResult.payload);
|
||||
break;
|
||||
}
|
||||
case (OrderbookChannelMessageTypes.Update): {
|
||||
handler.onUpdate(this, parserResult.payload);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
handler.onError(this, new Error(`Message has missing a type parameter: ${utf8Data}`));
|
||||
if (parserResult.requestId === requestId) {
|
||||
switch (parserResult.type) {
|
||||
case (OrderbookChannelMessageTypes.Snapshot): {
|
||||
handler.onSnapshot(this, subscriptionOpts, parserResult.payload);
|
||||
break;
|
||||
}
|
||||
case (OrderbookChannelMessageTypes.Update): {
|
||||
handler.onUpdate(this, subscriptionOpts, parserResult.payload);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
handler.onError(
|
||||
this, subscriptionOpts, new Error(`Message has missing a type parameter: ${utf8Data}`));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
handler.onError(this, error);
|
||||
handler.onError(this, subscriptionOpts, error);
|
||||
}
|
||||
} else {
|
||||
handler.onError(this, new Error(`Message does not contain utf8Data`));
|
||||
handler.onError(this, subscriptionOpts, new Error(`Message does not contain utf8Data`));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -5,13 +5,13 @@ const orderbookJsonString = JSON.stringify(orderbookJSON);
|
||||
export const snapshotOrderbookChannelMessage = `{
|
||||
"type": "snapshot",
|
||||
"channel": "orderbook",
|
||||
"channelId": 1,
|
||||
"requestId": 1,
|
||||
"payload": ${orderbookJsonString}
|
||||
}`;
|
||||
|
||||
export const malformedSnapshotOrderbookChannelMessage = `{
|
||||
"type": "snapshot",
|
||||
"channel": "orderbook",
|
||||
"channelId": 1,
|
||||
"requestId": 1,
|
||||
"payload": {}
|
||||
}`;
|
||||
|
@@ -5,6 +5,6 @@ const orderJSONString = JSON.stringify(orderResponseJSON);
|
||||
export const unknownOrderbookChannelMessage = `{
|
||||
"type": "superGoodUpdate",
|
||||
"channel": "orderbook",
|
||||
"channelId": 1,
|
||||
"requestId": 1,
|
||||
"payload": ${orderJSONString}
|
||||
}`;
|
||||
|
@@ -5,13 +5,13 @@ const orderJSONString = JSON.stringify(orderResponseJSON);
|
||||
export const updateOrderbookChannelMessage = `{
|
||||
"type": "update",
|
||||
"channel": "orderbook",
|
||||
"channelId": 1,
|
||||
"requestId": 1,
|
||||
"payload": ${orderJSONString}
|
||||
}`;
|
||||
|
||||
export const malformedUpdateOrderbookChannelMessage = `{
|
||||
"type": "update",
|
||||
"channel": "orderbook",
|
||||
"channelId": 1,
|
||||
"requestId": 1,
|
||||
"payload": {}
|
||||
}`;
|
||||
|
@@ -61,12 +61,12 @@ describe('HttpClient', () => {
|
||||
const orders = await relayerClient.getOrdersAsync();
|
||||
expect(orders).to.be.deep.equal(ordersResponse);
|
||||
});
|
||||
it('gets specfic orders for request', async () => {
|
||||
it('gets specific orders for request', async () => {
|
||||
const tokenAddress = '0x323b5d4c32345ced77393b3530b1eed0f346429d';
|
||||
const ordersRequest = {
|
||||
tokenA: tokenAddress,
|
||||
tokenAddress,
|
||||
};
|
||||
const urlWithQuery = `${url}?tokenA=${tokenAddress}`;
|
||||
const urlWithQuery = `${url}?tokenAddress=${tokenAddress}`;
|
||||
fetchMock.get(urlWithQuery, ordersResponseJSON);
|
||||
const orders = await relayerClient.getOrdersAsync(ordersRequest);
|
||||
expect(orders).to.be.deep.equal(ordersResponse);
|
||||
|
@@ -41,12 +41,22 @@ describe('orderbookChannelMessageParsers', () => {
|
||||
it('throws when message does not include a type', () => {
|
||||
const typelessMessage = `{
|
||||
"channel": "orderbook",
|
||||
"channelId": 1,
|
||||
"requestId": 1,
|
||||
"payload": {}
|
||||
}`;
|
||||
const badCall = () => orderbookChannelMessageParsers.parser(typelessMessage);
|
||||
expect(badCall).throws(`Message is missing a type parameter: ${typelessMessage}`);
|
||||
});
|
||||
it('throws when type is not a string', () => {
|
||||
const messageWithBadType = `{
|
||||
"type": 1,
|
||||
"channel": "orderbook",
|
||||
"requestId": 1,
|
||||
"payload": {}
|
||||
}`;
|
||||
const badCall = () => orderbookChannelMessageParsers.parser(messageWithBadType);
|
||||
expect(badCall).throws('Expected type to be of type string, encountered: 1');
|
||||
});
|
||||
it('throws when snapshot message has malformed payload', () => {
|
||||
const badCall = () =>
|
||||
orderbookChannelMessageParsers.parser(malformedSnapshotOrderbookChannelMessage);
|
||||
|
51
packages/contracts/README.md
Normal file
51
packages/contracts/README.md
Normal file
@@ -0,0 +1,51 @@
|
||||
Contracts
|
||||
-----
|
||||
|
||||
## Useful 0x Wiki Articles
|
||||
|
||||
* [Architecture](https://0xproject.com/wiki#Architecture)
|
||||
* [Contract Interactions](https://0xproject.com/wiki#Contract-Interactions)
|
||||
* [Contract deployed addresses](https://0xproject.com/wiki#Deployed-Addresses)
|
||||
* [0x Protocol Message Format](https://0xproject.com/wiki#Message-Format)
|
||||
* [Bug Bounty Program](https://0xproject.com/wiki#Bug-Bounty)
|
||||
|
||||
## Setup
|
||||
|
||||
### Installing Dependencies
|
||||
|
||||
Install [Node](https://nodejs.org/en/download/releases/)
|
||||
|
||||
Install [yarn](https://yarnpkg.com/lang/en/docs/install/) in order to install the project dependencies more deterministically.
|
||||
|
||||
Install project dependencies:
|
||||
|
||||
```
|
||||
yarn
|
||||
```
|
||||
|
||||
### Running Tests
|
||||
|
||||
Start Testrpc
|
||||
|
||||
```
|
||||
yarn testrpc
|
||||
```
|
||||
|
||||
Run tests
|
||||
|
||||
```
|
||||
yarn test
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
0x protocol is intended to serve as an open technical standard for EVM blockchains and we strongly encourage our community members to help us make improvements and to determine the future direction of the protocol. To report bugs within the 0x smart contracts or unit tests, please create an issue in this repository.
|
||||
|
||||
### ZEIPs
|
||||
Significant changes to 0x protocol's smart contracts, architecture, message format or functionality should be proposed in the [0x Improvement Proposals (ZEIPs)](https://github.com/0xProject/ZEIPs) repository. Follow the contribution guidelines provided therein.
|
||||
|
||||
### Coding conventions
|
||||
|
||||
We use a custom set of [TSLint](https://palantir.github.io/tslint/) rules to enforce our coding conventions.
|
||||
|
||||
In order to see style violation errors, install a tslinter for your text editor. e.g Atom's [atom-typescript](https://atom.io/packages/atom-typescript).
|
344
packages/contracts/build/contracts/DummyToken.json
Normal file
344
packages/contracts/build/contracts/DummyToken.json
Normal file
File diff suppressed because one or more lines are too long
394
packages/contracts/build/contracts/EtherToken.json
Normal file
394
packages/contracts/build/contracts/EtherToken.json
Normal file
@@ -0,0 +1,394 @@
|
||||
{
|
||||
"contract_name": "EtherToken",
|
||||
"abi": [
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "name",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "approve",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "totalSupply",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "transferFrom",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "amount",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "withdraw",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "decimals",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint8"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "balanceOf",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "symbol",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "transfer",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [],
|
||||
"name": "deposit",
|
||||
"outputs": [],
|
||||
"payable": true,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "allowance",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"payable": true,
|
||||
"type": "fallback"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Transfer",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Approval",
|
||||
"type": "event"
|
||||
}
|
||||
],
|
||||
"unlinked_binary": "0x6060604052341561000c57fe5b5b61070f8061001c6000396000f300606060405236156100935763ffffffff60e060020a60003504166306fdde0381146100a4578063095ea7b31461013457806318160ddd1461016757806323b872dd146101895780632e1a7d4d146101c2578063313ce567146101d757806370a08231146101fd57806395d89b411461022b578063a9059cbb146102bb578063d0e30db0146102ee578063dd62ed3e146102f8575b6100a25b61009f61032c565b5b565b005b34156100ac57fe5b6100b461037b565b6040805160208082528351818301528351919283929083019185019080838382156100fa575b8051825260208311156100fa57601f1990920191602091820191016100da565b505050905090810190601f1680156101265780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561013c57fe5b610153600160a060020a03600435166024356103a3565b604080519115158252519081900360200190f35b341561016f57fe5b61017761040e565b60408051918252519081900360200190f35b341561019157fe5b610153600160a060020a0360043581169060243516604435610414565b604080519115158252519081900360200190f35b34156101ca57fe5b6100a26004356104ff565b005b34156101df57fe5b6101e7610580565b6040805160ff9092168252519081900360200190f35b341561020557fe5b610177600160a060020a0360043516610585565b60408051918252519081900360200190f35b341561023357fe5b6100b46105a4565b6040805160208082528351818301528351919283929083019185019080838382156100fa575b8051825260208311156100fa57601f1990920191602091820191016100da565b505050905090810190601f1680156101265780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156102c357fe5b610153600160a060020a03600435166024356105c5565b604080519115158252519081900360200190f35b6100a261032c565b005b341561030057fe5b610177600160a060020a0360043581169060243516610665565b60408051918252519081900360200190f35b600160a060020a03331660009081526020819052604090205461034f9034610692565b600160a060020a0333166000908152602081905260409020556002546103759034610692565b6002555b565b60408051808201909152600b815260a960020a6a22ba3432b9102a37b5b2b702602082015281565b600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b60025481565b600160a060020a03831660009081526020819052604081205461043790836106ac565b600160a060020a03808616600090815260208181526040808320949094556001815283822033909316825291909152205461047290836106ac565b600160a060020a038086166000908152600160209081526040808320338516845282528083209490945591861681529081905220546104b19083610692565b600160a060020a038085166000818152602081815260409182902094909455805186815290519193928816926000805160206106c483398151915292918290030190a35060015b9392505050565b600160a060020a03331660009081526020819052604090205461052290826106ac565b600160a060020a03331660009081526020819052604090205560025461054890826106ac565b600255604051600160a060020a0333169082156108fc029083906000818181858888f19350505050151561057c5760006000fd5b5b50565b601281565b600160a060020a0381166000908152602081905260409020545b919050565b604080518082019091526004815260e360020a630ae8aa8902602082015281565b600160a060020a0333166000908152602081905260408120546105e890836106ac565b600160a060020a0333811660009081526020819052604080822093909355908516815220546106179083610692565b600160a060020a03808516600081815260208181526040918290209490945580518681529051919333909316926000805160206106c483398151915292918290030190a35060015b92915050565b600160a060020a038083166000908152600160209081526040808320938516835292905220545b92915050565b6000828201838110156106a157fe5b8091505b5092915050565b6000828211156106b857fe5b508082035b929150505600ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa165627a7a72305820b0be668913b36ff13a97f9ad56d8eb2e9c169cc9b32bfde9e3b92cec1036f1080029",
|
||||
"networks": {
|
||||
"50": {
|
||||
"links": {},
|
||||
"events": {
|
||||
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef": {
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Transfer",
|
||||
"type": "event"
|
||||
},
|
||||
"0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925": {
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Approval",
|
||||
"type": "event"
|
||||
}
|
||||
},
|
||||
"updated_at": 1502391794392,
|
||||
"address": "0x6eead871b92e216b0368f596e751a25841f65bec"
|
||||
},
|
||||
"42": {
|
||||
"links": {},
|
||||
"events": {
|
||||
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef": {
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Transfer",
|
||||
"type": "event"
|
||||
},
|
||||
"0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925": {
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Approval",
|
||||
"type": "event"
|
||||
}
|
||||
},
|
||||
"updated_at": 1502391794392,
|
||||
"address": "0x05d090b51c40b020eab3bfcb6a2dff130df22e9c"
|
||||
},
|
||||
"1": {
|
||||
"links": {},
|
||||
"events": {
|
||||
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef": {
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Transfer",
|
||||
"type": "event"
|
||||
},
|
||||
"0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925": {
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Approval",
|
||||
"type": "event"
|
||||
}
|
||||
},
|
||||
"updated_at": 1502488087000,
|
||||
"address": "0x2956356cd2a2bf3202f771f50d3d14a367b48070"
|
||||
}
|
||||
},
|
||||
"schema_version": "0.0.5",
|
||||
"updated_at": 1502391794392
|
||||
}
|
997
packages/contracts/build/contracts/Exchange.json
Normal file
997
packages/contracts/build/contracts/Exchange.json
Normal file
File diff suppressed because one or more lines are too long
227
packages/contracts/build/contracts/MaliciousToken.json
Normal file
227
packages/contracts/build/contracts/MaliciousToken.json
Normal file
@@ -0,0 +1,227 @@
|
||||
{
|
||||
"contract_name": "MaliciousToken",
|
||||
"abi": [
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "approve",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "totalSupply",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "transferFrom",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "balanceOf",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "transfer",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "allowance",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Transfer",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Approval",
|
||||
"type": "event"
|
||||
}
|
||||
],
|
||||
"unlinked_binary": "0x60606040526003805460ff19166001179055341561001957fe5b5b610467806100296000396000f3006060604052361561005c5763ffffffff60e060020a600035041663095ea7b3811461005e57806318160ddd1461009157806323b872dd146100b357806370a08231146100ec578063a9059cbb1461011a578063dd62ed3e1461014d575bfe5b341561006657fe5b61007d600160a060020a0360043516602435610181565b604080519115158252519081900360200190f35b341561009957fe5b6100a16101ec565b60408051918252519081900360200190f35b34156100bb57fe5b61007d600160a060020a03600435811690602435166044356101f2565b604080519115158252519081900360200190f35b34156100f457fe5b6100a1600160a060020a03600435166102ee565b60408051918252519081900360200190f35b341561012257fe5b61007d600160a060020a0360043516602435610318565b604080519115158252519081900360200190f35b341561015557fe5b6100a1600160a060020a03600435811690602435166103ca565b60408051918252519081900360200190f35b600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b60025481565b600160a060020a0383166000908152602081905260408120548290108015906102425750600160a060020a0380851660009081526001602090815260408083203390941683529290522054829010155b80156102685750600160a060020a03831660009081526020819052604090205482810110155b156102e257600160a060020a03808416600081815260208181526040808320805488019055888516808452818420805489900390556001835281842033909616845294825291829020805487900390558151868152915192939260008051602061041c8339815191529281900390910190a35060016102e6565b5060005b5b9392505050565b60006102f8610402565b50600160a060020a0381166000908152602081905260409020545b919050565b600160a060020a03331660009081526020819052604081205482901080159061035b5750600160a060020a03831660009081526020819052604090205482810110155b156103bb57600160a060020a03338116600081815260208181526040808320805488900390559387168083529184902080548701905583518681529351919360008051602061041c833981519152929081900390910190a35060016101e6565b5060006101e6565b5b92915050565b60006103d4610402565b50600160a060020a038083166000908152600160209081526040808320938516835292905220545b92915050565b6003805460ff8082166001011660ff199091161790555b5600ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa165627a7a723058201238dbb2f96252f5d35040796309238210d3a5d9ac3261d0effff444e8f0cd0c0029",
|
||||
"networks": {
|
||||
"50": {
|
||||
"links": {},
|
||||
"events": {
|
||||
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef": {
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Transfer",
|
||||
"type": "event"
|
||||
},
|
||||
"0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925": {
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Approval",
|
||||
"type": "event"
|
||||
}
|
||||
},
|
||||
"updated_at": 1502391794396
|
||||
}
|
||||
},
|
||||
"schema_version": "0.0.5",
|
||||
"updated_at": 1502391794396
|
||||
}
|
72
packages/contracts/build/contracts/Migrations.json
Normal file
72
packages/contracts/build/contracts/Migrations.json
Normal file
@@ -0,0 +1,72 @@
|
||||
{
|
||||
"contract_name": "Migrations",
|
||||
"abi": [
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "new_address",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "upgrade",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "last_completed_migration",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "owner",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "completed",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "setCompleted",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"payable": false,
|
||||
"type": "constructor"
|
||||
}
|
||||
],
|
||||
"unlinked_binary": "0x6060604052341561000c57fe5b5b60008054600160a060020a03191633600160a060020a03161790555b5b6101a0806100396000396000f300606060405263ffffffff60e060020a6000350416630900f0108114610042578063445df0ac146100605780638da5cb5b14610082578063fdacd576146100ae575bfe5b341561004a57fe5b61005e600160a060020a03600435166100c3565b005b341561006857fe5b61007061013d565b60408051918252519081900360200190f35b341561008a57fe5b610092610143565b60408051600160a060020a039092168252519081900360200190f35b34156100b657fe5b61005e600435610152565b005b6000805433600160a060020a03908116911614156101375781905080600160a060020a031663fdacd5766001546040518263ffffffff1660e060020a02815260040180828152602001915050600060405180830381600087803b151561012557fe5b6102c65a03f1151561013357fe5b5050505b5b5b5050565b60015481565b600054600160a060020a031681565b60005433600160a060020a039081169116141561016f5760018190555b5b5b505600a165627a7a72305820721709a2522264b5277c3048b17bea0e0f660776a386bacb5f36796ba40dac1c0029",
|
||||
"networks": {
|
||||
"50": {
|
||||
"links": {},
|
||||
"events": {},
|
||||
"updated_at": 1502391794384
|
||||
}
|
||||
},
|
||||
"schema_version": "0.0.5",
|
||||
"updated_at": 1502391794384
|
||||
}
|
189
packages/contracts/build/contracts/Mintable.json
Normal file
189
packages/contracts/build/contracts/Mintable.json
Normal file
@@ -0,0 +1,189 @@
|
||||
{
|
||||
"contract_name": "Mintable",
|
||||
"abi": [
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "approve",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "totalSupply",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "transferFrom",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "balanceOf",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "mint",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "transfer",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "allowance",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Transfer",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Approval",
|
||||
"type": "event"
|
||||
}
|
||||
],
|
||||
"unlinked_binary": "0x6060604052341561000c57fe5b5b6104da8061001c6000396000f300606060405236156100675763ffffffff60e060020a600035041663095ea7b3811461006957806318160ddd1461009c57806323b872dd146100be57806370a08231146100f7578063a0712d6814610125578063a9059cbb1461013a578063dd62ed3e1461016d575bfe5b341561007157fe5b610088600160a060020a03600435166024356101a1565b604080519115158252519081900360200190f35b34156100a457fe5b6100ac61020c565b60408051918252519081900360200190f35b34156100c657fe5b610088600160a060020a0360043581169060243516604435610212565b604080519115158252519081900360200190f35b34156100ff57fe5b6100ac600160a060020a036004351661030e565b60408051918252519081900360200190f35b341561012d57fe5b61013860043561032d565b005b341561014257fe5b610088600160a060020a0360043516602435610395565b604080519115158252519081900360200190f35b341561017557fe5b6100ac600160a060020a0360043581169060243516610447565b60408051918252519081900360200190f35b600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b60025481565b600160a060020a0383166000908152602081905260408120548290108015906102625750600160a060020a0380851660009081526001602090815260408083203390941683529290522054829010155b80156102885750600160a060020a03831660009081526020819052604090205482810110155b1561030257600160a060020a03808416600081815260208181526040808320805488019055888516808452818420805489900390556001835281842033909616845294825291829020805487900390558151868152915192939260008051602061048f8339815191529281900390910190a3506001610306565b5060005b5b9392505050565b600160a060020a0381166000908152602081905260409020545b919050565b68056bc75e2d631000008111156103445760006000fd5b600160a060020a033316600090815260208190526040902054610368908290610474565b600160a060020a03331660009081526020819052604090205560025461038e9082610474565b6002555b50565b600160a060020a0333166000908152602081905260408120548290108015906103d85750600160a060020a03831660009081526020819052604090205482810110155b1561043857600160a060020a03338116600081815260208181526040808320805488900390559387168083529184902080548701905583518681529351919360008051602061048f833981519152929081900390910190a3506001610206565b506000610206565b5b92915050565b600160a060020a038083166000908152600160209081526040808320938516835292905220545b92915050565b60008282018381101561048357fe5b8091505b50929150505600ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa165627a7a72305820fb9e3b0567bae493373766d7c9980e78be7513e22369cbce495956e5849c284d0029",
|
||||
"networks": {},
|
||||
"schema_version": "0.0.5",
|
||||
"updated_at": 1502391449723
|
||||
}
|
517
packages/contracts/build/contracts/MultiSigWallet.json
Normal file
517
packages/contracts/build/contracts/MultiSigWallet.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
40
packages/contracts/build/contracts/Ownable.json
Normal file
40
packages/contracts/build/contracts/Ownable.json
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"contract_name": "Ownable",
|
||||
"abi": [
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "owner",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "newOwner",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "transferOwnership",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"payable": false,
|
||||
"type": "constructor"
|
||||
}
|
||||
],
|
||||
"unlinked_binary": "0x6060604052341561000c57fe5b5b60008054600160a060020a03191633600160a060020a03161790555b5b60f3806100386000396000f300606060405263ffffffff60e060020a6000350416638da5cb5b8114602a578063f2fde38b146053575bfe5b3415603157fe5b6037606e565b60408051600160a060020a039092168252519081900360200190f35b3415605a57fe5b606c600160a060020a0360043516607d565b005b600054600160a060020a031681565b60005433600160a060020a0390811691161460985760006000fd5b600160a060020a0381161560c25760008054600160a060020a031916600160a060020a0383161790555b5b5b505600a165627a7a7230582009515308d7738f55dd8ba99e29943dc01d4a032197af5f4e1adc20b93fb927f20029",
|
||||
"networks": {},
|
||||
"schema_version": "0.0.5",
|
||||
"updated_at": 1502391792217
|
||||
}
|
8
packages/contracts/build/contracts/SafeMath.json
Normal file
8
packages/contracts/build/contracts/SafeMath.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"contract_name": "SafeMath",
|
||||
"abi": [],
|
||||
"unlinked_binary": "0x60606040523415600b57fe5b5b60338060196000396000f30060606040525bfe00a165627a7a723058201f432ae32cd7cc9a0efb0b70b25524cf42d165202875a497f8b0122d77a6a5ba0029",
|
||||
"networks": {},
|
||||
"schema_version": "0.0.5",
|
||||
"updated_at": 1502391792217
|
||||
}
|
176
packages/contracts/build/contracts/StandardToken.json
Normal file
176
packages/contracts/build/contracts/StandardToken.json
Normal file
@@ -0,0 +1,176 @@
|
||||
{
|
||||
"contract_name": "StandardToken",
|
||||
"abi": [
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "approve",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "totalSupply",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "transferFrom",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "balanceOf",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "transfer",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "allowance",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Transfer",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Approval",
|
||||
"type": "event"
|
||||
}
|
||||
],
|
||||
"unlinked_binary": "0x6060604052341561000c57fe5b5b6104388061001c6000396000f3006060604052361561005c5763ffffffff60e060020a600035041663095ea7b3811461005e57806318160ddd1461009157806323b872dd146100b357806370a08231146100ec578063a9059cbb1461011a578063dd62ed3e1461014d575bfe5b341561006657fe5b61007d600160a060020a0360043516602435610181565b604080519115158252519081900360200190f35b341561009957fe5b6100a16101ec565b60408051918252519081900360200190f35b34156100bb57fe5b61007d600160a060020a03600435811690602435166044356101f2565b604080519115158252519081900360200190f35b34156100f457fe5b6100a1600160a060020a03600435166102ee565b60408051918252519081900360200190f35b341561012257fe5b61007d600160a060020a036004351660243561030d565b604080519115158252519081900360200190f35b341561015557fe5b6100a1600160a060020a03600435811690602435166103bf565b60408051918252519081900360200190f35b600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b60025481565b600160a060020a0383166000908152602081905260408120548290108015906102425750600160a060020a0380851660009081526001602090815260408083203390941683529290522054829010155b80156102685750600160a060020a03831660009081526020819052604090205482810110155b156102e257600160a060020a0380841660008181526020818152604080832080548801905588851680845281842080548990039055600183528184203390961684529482529182902080548790039055815186815291519293926000805160206103ed8339815191529281900390910190a35060016102e6565b5060005b5b9392505050565b600160a060020a0381166000908152602081905260409020545b919050565b600160a060020a0333166000908152602081905260408120548290108015906103505750600160a060020a03831660009081526020819052604090205482810110155b156103b057600160a060020a0333811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191936000805160206103ed833981519152929081900390910190a35060016101e6565b5060006101e6565b5b92915050565b600160a060020a038083166000908152600160209081526040808320938516835292905220545b929150505600ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa165627a7a723058208bbb664bbcb187b9a351ec93e9763b53c0157b40e7ee3033bb5b59eddd9e575e0029",
|
||||
"networks": {},
|
||||
"schema_version": "0.0.5",
|
||||
"updated_at": 1502391449723
|
||||
}
|
176
packages/contracts/build/contracts/Token.json
Normal file
176
packages/contracts/build/contracts/Token.json
Normal file
@@ -0,0 +1,176 @@
|
||||
{
|
||||
"contract_name": "Token",
|
||||
"abi": [
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "approve",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "success",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "totalSupply",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "supply",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "transferFrom",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "success",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "balanceOf",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "balance",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "transfer",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "success",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "allowance",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "remaining",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Transfer",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Approval",
|
||||
"type": "event"
|
||||
}
|
||||
],
|
||||
"unlinked_binary": "0x6060604052341561000c57fe5b5b6101e08061001c6000396000f3006060604052361561005c5763ffffffff60e060020a600035041663095ea7b3811461005e57806318160ddd1461009157806323b872dd146100b357806370a08231146100ec578063a9059cbb1461005e578063dd62ed3e1461014d575bfe5b341561006657fe5b61007d600160a060020a0360043516602435610181565b604080519115158252519081900360200190f35b341561009957fe5b6100a161018a565b60408051918252519081900360200190f35b34156100bb57fe5b61007d600160a060020a0360043581169060243516604435610190565b604080519115158252519081900360200190f35b34156100f457fe5b6100a1600160a060020a036004351661019a565b60408051918252519081900360200190f35b341561006657fe5b61007d600160a060020a0360043516602435610181565b604080519115158252519081900360200190f35b341561015557fe5b6100a1600160a060020a0360043581169060243516610181565b60408051918252519081900360200190f35b60005b92915050565b60005b90565b60005b9392505050565b60005b919050565b60005b92915050565b60005b929150505600a165627a7a7230582082d46fcd9caa49348b3932d5c18807e1d10d0105371a8bce147cc647f3762a500029",
|
||||
"networks": {},
|
||||
"schema_version": "0.0.5",
|
||||
"updated_at": 1502391792217
|
||||
}
|
1042
packages/contracts/build/contracts/TokenRegistry.json
Normal file
1042
packages/contracts/build/contracts/TokenRegistry.json
Normal file
File diff suppressed because one or more lines are too long
298
packages/contracts/build/contracts/TokenTransferProxy.json
Normal file
298
packages/contracts/build/contracts/TokenTransferProxy.json
Normal file
@@ -0,0 +1,298 @@
|
||||
{
|
||||
"contract_name": "TokenTransferProxy",
|
||||
"abi": [
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "token",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "transferFrom",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "target",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "addAuthorizedAddress",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "authorities",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "target",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "removeAuthorizedAddress",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "owner",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "authorized",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "getAuthorizedAddresses",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "address[]"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "newOwner",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "transferOwnership",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "target",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "caller",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "LogAuthorizedAddressAdded",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "target",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "caller",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "LogAuthorizedAddressRemoved",
|
||||
"type": "event"
|
||||
}
|
||||
],
|
||||
"unlinked_binary": "0x60606040525b60008054600160a060020a03191633600160a060020a03161790555b5b6106e6806100316000396000f300606060405236156100725763ffffffff60e060020a60003504166315dacbea811461007457806342f1181e146100b3578063494503d4146100d157806370712939146101005780638da5cb5b1461011e578063b91816111461014a578063d39de6e91461017a578063f2fde38b146101e5575bfe5b341561007c57fe5b61009f600160a060020a0360043581169060243581169060443516606435610203565b604080519115158252519081900360200190f35b34156100bb57fe5b6100cf600160a060020a03600435166102ae565b005b34156100d957fe5b6100e4600435610390565b60408051600160a060020a039092168252519081900360200190f35b341561010857fe5b6100cf600160a060020a03600435166103c2565b005b341561012657fe5b6100e461055a565b60408051600160a060020a039092168252519081900360200190f35b341561015257fe5b61009f600160a060020a0360043516610569565b604080519115158252519081900360200190f35b341561018257fe5b61018a61057e565b60408051602080825283518183015283519192839290830191858101910280838382156101d2575b8051825260208311156101d257601f1990920191602091820191016101b2565b5050509050019250505060405180910390f35b34156101ed57fe5b6100cf600160a060020a03600435166105e7565b005b600160a060020a03331660009081526001602052604081205460ff16151561022b5760006000fd5b6040805160006020918201819052825160e060020a6323b872dd028152600160a060020a0388811660048301528781166024830152604482018790529351938916936323b872dd9360648084019491938390030190829087803b151561028d57fe5b6102c65a03f1151561029b57fe5b5050604051519150505b5b949350505050565b60005433600160a060020a039081169116146102ca5760006000fd5b600160a060020a038116600090815260016020526040902054819060ff16156102f35760006000fd5b600160a060020a0382166000908152600160208190526040909120805460ff191682179055600280549091810161032a8382610633565b916000526020600020900160005b81546101009190910a600160a060020a0381810219909216868316918202179092556040513390911692507f94bb87f4c15c4587ff559a7584006fa01ddf9299359be6b512b94527aa961aca90600090a35b5b505b50565b600280548290811061039e57fe5b906000526020600020900160005b915054906101000a9004600160a060020a031681565b6000805433600160a060020a039081169116146103df5760006000fd5b600160a060020a038216600090815260016020526040902054829060ff1615156104095760006000fd5b600160a060020a0383166000908152600160205260408120805460ff1916905591505b6002548210156105195782600160a060020a031660028381548110151561044f57fe5b906000526020600020900160005b9054906101000a9004600160a060020a0316600160a060020a0316141561050d5760028054600019810190811061049057fe5b906000526020600020900160005b9054906101000a9004600160a060020a03166002838154811015156104bf57fe5b906000526020600020900160005b6101000a815481600160a060020a030219169083600160a060020a0316021790555060016002818180549050039150816105079190610633565b50610519565b5b60019091019061042c565b604051600160a060020a0333811691908516907ff5b347a1e40749dd050f5f07fbdbeb7e3efa9756903044dd29401fd1d4bb4a1c90600090a35b5b505b5050565b600054600160a060020a031681565b60016020526000908152604090205460ff1681565b610586610687565b60028054806020026020016040519081016040528092919081815260200182805480156105dc57602002820191906000526020600020905b8154600160a060020a031681526001909101906020018083116105be575b505050505090505b90565b60005433600160a060020a039081169116146106035760006000fd5b600160a060020a0381161561038d5760008054600160a060020a031916600160a060020a0383161790555b5b5b50565b81548183558181151161055357600083815260209020610553918101908301610699565b5b505050565b81548183558181151161055357600083815260209020610553918101908301610699565b5b505050565b60408051602081019091526000815290565b6105e491905b808211156106b3576000815560010161069f565b5090565b905600a165627a7a723058200355c2e534da7274d090b5a2209d5fbe4679ee2760a73c55c16e6d0ff1af016c0029",
|
||||
"networks": {
|
||||
"50": {
|
||||
"links": {},
|
||||
"events": {
|
||||
"0x94bb87f4c15c4587ff559a7584006fa01ddf9299359be6b512b94527aa961aca": {
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "target",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "caller",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "LogAuthorizedAddressAdded",
|
||||
"type": "event"
|
||||
},
|
||||
"0xf5b347a1e40749dd050f5f07fbdbeb7e3efa9756903044dd29401fd1d4bb4a1c": {
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "target",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "caller",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "LogAuthorizedAddressRemoved",
|
||||
"type": "event"
|
||||
}
|
||||
},
|
||||
"updated_at": 1502391794384,
|
||||
"address": "0x168ead2eadb6b3b8f47d6ae0ff418451c1087239"
|
||||
},
|
||||
"42": {
|
||||
"links": {},
|
||||
"events": {
|
||||
"0x94bb87f4c15c4587ff559a7584006fa01ddf9299359be6b512b94527aa961aca": {
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "target",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "caller",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "LogAuthorizedAddressAdded",
|
||||
"type": "event"
|
||||
},
|
||||
"0xf5b347a1e40749dd050f5f07fbdbeb7e3efa9756903044dd29401fd1d4bb4a1c": {
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "target",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "caller",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "LogAuthorizedAddressRemoved",
|
||||
"type": "event"
|
||||
}
|
||||
},
|
||||
"updated_at": 1502391794384,
|
||||
"address": "0x087Eed4Bc1ee3DE49BeFbd66C662B434B15d49d4"
|
||||
},
|
||||
"1": {
|
||||
"links": {},
|
||||
"events": {
|
||||
"0x94bb87f4c15c4587ff559a7584006fa01ddf9299359be6b512b94527aa961aca": {
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "target",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "caller",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "LogAuthorizedAddressAdded",
|
||||
"type": "event"
|
||||
},
|
||||
"0xf5b347a1e40749dd050f5f07fbdbeb7e3efa9756903044dd29401fd1d4bb4a1c": {
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "target",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "caller",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "LogAuthorizedAddressRemoved",
|
||||
"type": "event"
|
||||
}
|
||||
},
|
||||
"updated_at": 1502478966000,
|
||||
"address": "0x8da0d80f5007ef1e431dd2127178d224e32c2ef4"
|
||||
}
|
||||
},
|
||||
"schema_version": "0.0.5",
|
||||
"updated_at": 1502391794384
|
||||
}
|
373
packages/contracts/build/contracts/ZRXToken.json
Normal file
373
packages/contracts/build/contracts/ZRXToken.json
Normal file
@@ -0,0 +1,373 @@
|
||||
{
|
||||
"contract_name": "ZRXToken",
|
||||
"abi": [
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "name",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "approve",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "totalSupply",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "transferFrom",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "decimals",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint8"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "balanceOf",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "symbol",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "transfer",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "allowance",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"payable": false,
|
||||
"type": "constructor"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Transfer",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Approval",
|
||||
"type": "event"
|
||||
}
|
||||
],
|
||||
"unlinked_binary": "0x60606040526b033b2e3c9fd0803ce8000000600355341561001c57fe5b5b600354600160a060020a0333166000908152602081905260409020555b5b6106198061004a6000396000f3006060604052361561007d5763ffffffff60e060020a60003504166306fdde03811461007f578063095ea7b31461010f57806318160ddd1461014257806323b872dd14610164578063313ce5671461019d57806370a08231146101c357806395d89b41146101f1578063a9059cbb14610281578063dd62ed3e146102b4575bfe5b341561008757fe5b61008f6102e8565b6040805160208082528351818301528351919283929083019185019080838382156100d5575b8051825260208311156100d557601f1990920191602091820191016100b5565b505050905090810190601f1680156101015780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561011757fe5b61012e600160a060020a0360043516602435610316565b604080519115158252519081900360200190f35b341561014a57fe5b610152610381565b60408051918252519081900360200190f35b341561016c57fe5b61012e600160a060020a0360043581169060243516604435610387565b604080519115158252519081900360200190f35b34156101a557fe5b6101ad6104aa565b6040805160ff9092168252519081900360200190f35b34156101cb57fe5b610152600160a060020a03600435166104af565b60408051918252519081900360200190f35b34156101f957fe5b61008f6104ce565b6040805160208082528351818301528351919283929083019185019080838382156100d5575b8051825260208311156100d557601f1990920191602091820191016100b5565b505050905090810190601f1680156101015780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561028957fe5b61012e600160a060020a03600435166024356104ee565b604080519115158252519081900360200190f35b34156102bc57fe5b610152600160a060020a03600435811690602435166105a0565b60408051918252519081900360200190f35b6040805180820190915260118152607960020a70183c10283937ba37b1b7b6102a37b5b2b702602082015281565b600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b60035481565b600160a060020a03808416600081815260016020908152604080832033909516835293815283822054928252819052918220548390108015906103ca5750828110155b80156103f05750600160a060020a03841660009081526020819052604090205483810110155b1561049c57600160a060020a038085166000908152602081905260408082208054870190559187168152208054849003905560001981101561045a57600160a060020a03808616600090815260016020908152604080832033909416835292905220805484900390555b83600160a060020a031685600160a060020a03166000805160206105ce833981519152856040518082815260200191505060405180910390a3600191506104a1565b600091505b5b509392505050565b601281565b600160a060020a0381166000908152602081905260409020545b919050565b604080518082019091526003815260eb60020a620b4a4b02602082015281565b600160a060020a0333166000908152602081905260408120548290108015906105315750600160a060020a03831660009081526020819052604090205482810110155b1561059157600160a060020a0333811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191936000805160206105ce833981519152929081900390910190a350600161037b565b50600061037b565b5b92915050565b600160a060020a038083166000908152600160209081526040808320938516835292905220545b929150505600ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa165627a7a72305820c3b32a51a49bb8e7b08cb40d70b018590761113b8e17709dace660ef94b069e30029",
|
||||
"networks": {
|
||||
"50": {
|
||||
"links": {},
|
||||
"events": {
|
||||
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef": {
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Transfer",
|
||||
"type": "event"
|
||||
},
|
||||
"0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925": {
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Approval",
|
||||
"type": "event"
|
||||
}
|
||||
},
|
||||
"updated_at": 1502391794391
|
||||
},
|
||||
"42": {
|
||||
"links": {},
|
||||
"events": {
|
||||
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef": {
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Transfer",
|
||||
"type": "event"
|
||||
},
|
||||
"0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925": {
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Approval",
|
||||
"type": "event"
|
||||
}
|
||||
},
|
||||
"updated_at": 1502391794391,
|
||||
"address": "0x6ff6c0ff1d68b964901f986d4c9fa3ac68346570"
|
||||
},
|
||||
"1": {
|
||||
"links": {},
|
||||
"events": {
|
||||
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef": {
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Transfer",
|
||||
"type": "event"
|
||||
},
|
||||
"0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925": {
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "_spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Approval",
|
||||
"type": "event"
|
||||
}
|
||||
},
|
||||
"updated_at": 1502477311000,
|
||||
"address": "0xe41d2489571d322189246dafa5ebde1f4699f498"
|
||||
}
|
||||
},
|
||||
"schema_version": "0.0.5",
|
||||
"updated_at": 1502391794391
|
||||
}
|
602
packages/contracts/contracts/Exchange.sol
Normal file
602
packages/contracts/contracts/Exchange.sol
Normal file
@@ -0,0 +1,602 @@
|
||||
/*
|
||||
|
||||
Copyright 2017 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.4.11;
|
||||
|
||||
import "./TokenTransferProxy.sol";
|
||||
import "./base/Token.sol";
|
||||
import "./base/SafeMath.sol";
|
||||
|
||||
/// @title Exchange - Facilitates exchange of ERC20 tokens.
|
||||
/// @author Amir Bandeali - <amir@0xProject.com>, Will Warren - <will@0xProject.com>
|
||||
contract Exchange is SafeMath {
|
||||
|
||||
// Error Codes
|
||||
enum Errors {
|
||||
ORDER_EXPIRED, // Order has already expired
|
||||
ORDER_FULLY_FILLED_OR_CANCELLED, // Order has already been fully filled or cancelled
|
||||
ROUNDING_ERROR_TOO_LARGE, // Rounding error too large
|
||||
INSUFFICIENT_BALANCE_OR_ALLOWANCE // Insufficient balance or allowance for token transfer
|
||||
}
|
||||
|
||||
string constant public VERSION = "1.0.0";
|
||||
uint16 constant public EXTERNAL_QUERY_GAS_LIMIT = 4999; // Changes to state require at least 5000 gas
|
||||
|
||||
address public ZRX_TOKEN_CONTRACT;
|
||||
address public TOKEN_TRANSFER_PROXY_CONTRACT;
|
||||
|
||||
// Mappings of orderHash => amounts of takerTokenAmount filled or cancelled.
|
||||
mapping (bytes32 => uint) public filled;
|
||||
mapping (bytes32 => uint) public cancelled;
|
||||
|
||||
event LogFill(
|
||||
address indexed maker,
|
||||
address taker,
|
||||
address indexed feeRecipient,
|
||||
address makerToken,
|
||||
address takerToken,
|
||||
uint filledMakerTokenAmount,
|
||||
uint filledTakerTokenAmount,
|
||||
uint paidMakerFee,
|
||||
uint paidTakerFee,
|
||||
bytes32 indexed tokens, // keccak256(makerToken, takerToken), allows subscribing to a token pair
|
||||
bytes32 orderHash
|
||||
);
|
||||
|
||||
event LogCancel(
|
||||
address indexed maker,
|
||||
address indexed feeRecipient,
|
||||
address makerToken,
|
||||
address takerToken,
|
||||
uint cancelledMakerTokenAmount,
|
||||
uint cancelledTakerTokenAmount,
|
||||
bytes32 indexed tokens,
|
||||
bytes32 orderHash
|
||||
);
|
||||
|
||||
event LogError(uint8 indexed errorId, bytes32 indexed orderHash);
|
||||
|
||||
struct Order {
|
||||
address maker;
|
||||
address taker;
|
||||
address makerToken;
|
||||
address takerToken;
|
||||
address feeRecipient;
|
||||
uint makerTokenAmount;
|
||||
uint takerTokenAmount;
|
||||
uint makerFee;
|
||||
uint takerFee;
|
||||
uint expirationTimestampInSec;
|
||||
bytes32 orderHash;
|
||||
}
|
||||
|
||||
function Exchange(address _zrxToken, address _tokenTransferProxy) {
|
||||
ZRX_TOKEN_CONTRACT = _zrxToken;
|
||||
TOKEN_TRANSFER_PROXY_CONTRACT = _tokenTransferProxy;
|
||||
}
|
||||
|
||||
/*
|
||||
* Core exchange functions
|
||||
*/
|
||||
|
||||
/// @dev Fills the input order.
|
||||
/// @param orderAddresses Array of order's maker, taker, makerToken, takerToken, and feeRecipient.
|
||||
/// @param orderValues Array of order's makerTokenAmount, takerTokenAmount, makerFee, takerFee, expirationTimestampInSec, and salt.
|
||||
/// @param fillTakerTokenAmount Desired amount of takerToken to fill.
|
||||
/// @param shouldThrowOnInsufficientBalanceOrAllowance Test if transfer will fail before attempting.
|
||||
/// @param v ECDSA signature parameter v.
|
||||
/// @param r ECDSA signature parameters r.
|
||||
/// @param s ECDSA signature parameters s.
|
||||
/// @return Total amount of takerToken filled in trade.
|
||||
function fillOrder(
|
||||
address[5] orderAddresses,
|
||||
uint[6] orderValues,
|
||||
uint fillTakerTokenAmount,
|
||||
bool shouldThrowOnInsufficientBalanceOrAllowance,
|
||||
uint8 v,
|
||||
bytes32 r,
|
||||
bytes32 s)
|
||||
public
|
||||
returns (uint filledTakerTokenAmount)
|
||||
{
|
||||
Order memory order = Order({
|
||||
maker: orderAddresses[0],
|
||||
taker: orderAddresses[1],
|
||||
makerToken: orderAddresses[2],
|
||||
takerToken: orderAddresses[3],
|
||||
feeRecipient: orderAddresses[4],
|
||||
makerTokenAmount: orderValues[0],
|
||||
takerTokenAmount: orderValues[1],
|
||||
makerFee: orderValues[2],
|
||||
takerFee: orderValues[3],
|
||||
expirationTimestampInSec: orderValues[4],
|
||||
orderHash: getOrderHash(orderAddresses, orderValues)
|
||||
});
|
||||
|
||||
require(order.taker == address(0) || order.taker == msg.sender);
|
||||
require(order.makerTokenAmount > 0 && order.takerTokenAmount > 0 && fillTakerTokenAmount > 0);
|
||||
require(isValidSignature(
|
||||
order.maker,
|
||||
order.orderHash,
|
||||
v,
|
||||
r,
|
||||
s
|
||||
));
|
||||
|
||||
if (block.timestamp >= order.expirationTimestampInSec) {
|
||||
LogError(uint8(Errors.ORDER_EXPIRED), order.orderHash);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint remainingTakerTokenAmount = safeSub(order.takerTokenAmount, getUnavailableTakerTokenAmount(order.orderHash));
|
||||
filledTakerTokenAmount = min256(fillTakerTokenAmount, remainingTakerTokenAmount);
|
||||
if (filledTakerTokenAmount == 0) {
|
||||
LogError(uint8(Errors.ORDER_FULLY_FILLED_OR_CANCELLED), order.orderHash);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (isRoundingError(filledTakerTokenAmount, order.takerTokenAmount, order.makerTokenAmount)) {
|
||||
LogError(uint8(Errors.ROUNDING_ERROR_TOO_LARGE), order.orderHash);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!shouldThrowOnInsufficientBalanceOrAllowance && !isTransferable(order, filledTakerTokenAmount)) {
|
||||
LogError(uint8(Errors.INSUFFICIENT_BALANCE_OR_ALLOWANCE), order.orderHash);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint filledMakerTokenAmount = getPartialAmount(filledTakerTokenAmount, order.takerTokenAmount, order.makerTokenAmount);
|
||||
uint paidMakerFee;
|
||||
uint paidTakerFee;
|
||||
filled[order.orderHash] = safeAdd(filled[order.orderHash], filledTakerTokenAmount);
|
||||
require(transferViaTokenTransferProxy(
|
||||
order.makerToken,
|
||||
order.maker,
|
||||
msg.sender,
|
||||
filledMakerTokenAmount
|
||||
));
|
||||
require(transferViaTokenTransferProxy(
|
||||
order.takerToken,
|
||||
msg.sender,
|
||||
order.maker,
|
||||
filledTakerTokenAmount
|
||||
));
|
||||
if (order.feeRecipient != address(0)) {
|
||||
if (order.makerFee > 0) {
|
||||
paidMakerFee = getPartialAmount(filledTakerTokenAmount, order.takerTokenAmount, order.makerFee);
|
||||
require(transferViaTokenTransferProxy(
|
||||
ZRX_TOKEN_CONTRACT,
|
||||
order.maker,
|
||||
order.feeRecipient,
|
||||
paidMakerFee
|
||||
));
|
||||
}
|
||||
if (order.takerFee > 0) {
|
||||
paidTakerFee = getPartialAmount(filledTakerTokenAmount, order.takerTokenAmount, order.takerFee);
|
||||
require(transferViaTokenTransferProxy(
|
||||
ZRX_TOKEN_CONTRACT,
|
||||
msg.sender,
|
||||
order.feeRecipient,
|
||||
paidTakerFee
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
LogFill(
|
||||
order.maker,
|
||||
msg.sender,
|
||||
order.feeRecipient,
|
||||
order.makerToken,
|
||||
order.takerToken,
|
||||
filledMakerTokenAmount,
|
||||
filledTakerTokenAmount,
|
||||
paidMakerFee,
|
||||
paidTakerFee,
|
||||
keccak256(order.makerToken, order.takerToken),
|
||||
order.orderHash
|
||||
);
|
||||
return filledTakerTokenAmount;
|
||||
}
|
||||
|
||||
/// @dev Cancels the input order.
|
||||
/// @param orderAddresses Array of order's maker, taker, makerToken, takerToken, and feeRecipient.
|
||||
/// @param orderValues Array of order's makerTokenAmount, takerTokenAmount, makerFee, takerFee, expirationTimestampInSec, and salt.
|
||||
/// @param cancelTakerTokenAmount Desired amount of takerToken to cancel in order.
|
||||
/// @return Amount of takerToken cancelled.
|
||||
function cancelOrder(
|
||||
address[5] orderAddresses,
|
||||
uint[6] orderValues,
|
||||
uint cancelTakerTokenAmount)
|
||||
public
|
||||
returns (uint)
|
||||
{
|
||||
Order memory order = Order({
|
||||
maker: orderAddresses[0],
|
||||
taker: orderAddresses[1],
|
||||
makerToken: orderAddresses[2],
|
||||
takerToken: orderAddresses[3],
|
||||
feeRecipient: orderAddresses[4],
|
||||
makerTokenAmount: orderValues[0],
|
||||
takerTokenAmount: orderValues[1],
|
||||
makerFee: orderValues[2],
|
||||
takerFee: orderValues[3],
|
||||
expirationTimestampInSec: orderValues[4],
|
||||
orderHash: getOrderHash(orderAddresses, orderValues)
|
||||
});
|
||||
|
||||
require(order.maker == msg.sender);
|
||||
require(order.makerTokenAmount > 0 && order.takerTokenAmount > 0 && cancelTakerTokenAmount > 0);
|
||||
|
||||
if (block.timestamp >= order.expirationTimestampInSec) {
|
||||
LogError(uint8(Errors.ORDER_EXPIRED), order.orderHash);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint remainingTakerTokenAmount = safeSub(order.takerTokenAmount, getUnavailableTakerTokenAmount(order.orderHash));
|
||||
uint cancelledTakerTokenAmount = min256(cancelTakerTokenAmount, remainingTakerTokenAmount);
|
||||
if (cancelledTakerTokenAmount == 0) {
|
||||
LogError(uint8(Errors.ORDER_FULLY_FILLED_OR_CANCELLED), order.orderHash);
|
||||
return 0;
|
||||
}
|
||||
|
||||
cancelled[order.orderHash] = safeAdd(cancelled[order.orderHash], cancelledTakerTokenAmount);
|
||||
|
||||
LogCancel(
|
||||
order.maker,
|
||||
order.feeRecipient,
|
||||
order.makerToken,
|
||||
order.takerToken,
|
||||
getPartialAmount(cancelledTakerTokenAmount, order.takerTokenAmount, order.makerTokenAmount),
|
||||
cancelledTakerTokenAmount,
|
||||
keccak256(order.makerToken, order.takerToken),
|
||||
order.orderHash
|
||||
);
|
||||
return cancelledTakerTokenAmount;
|
||||
}
|
||||
|
||||
/*
|
||||
* Wrapper functions
|
||||
*/
|
||||
|
||||
/// @dev Fills an order with specified parameters and ECDSA signature, throws if specified amount not filled entirely.
|
||||
/// @param orderAddresses Array of order's maker, taker, makerToken, takerToken, and feeRecipient.
|
||||
/// @param orderValues Array of order's makerTokenAmount, takerTokenAmount, makerFee, takerFee, expirationTimestampInSec, and salt.
|
||||
/// @param fillTakerTokenAmount Desired amount of takerToken to fill.
|
||||
/// @param v ECDSA signature parameter v.
|
||||
/// @param r ECDSA signature parameters r.
|
||||
/// @param s ECDSA signature parameters s.
|
||||
function fillOrKillOrder(
|
||||
address[5] orderAddresses,
|
||||
uint[6] orderValues,
|
||||
uint fillTakerTokenAmount,
|
||||
uint8 v,
|
||||
bytes32 r,
|
||||
bytes32 s)
|
||||
public
|
||||
{
|
||||
require(fillOrder(
|
||||
orderAddresses,
|
||||
orderValues,
|
||||
fillTakerTokenAmount,
|
||||
false,
|
||||
v,
|
||||
r,
|
||||
s
|
||||
) == fillTakerTokenAmount);
|
||||
}
|
||||
|
||||
/// @dev Synchronously executes multiple fill orders in a single transaction.
|
||||
/// @param orderAddresses Array of address arrays containing individual order addresses.
|
||||
/// @param orderValues Array of uint arrays containing individual order values.
|
||||
/// @param fillTakerTokenAmounts Array of desired amounts of takerToken to fill in orders.
|
||||
/// @param shouldThrowOnInsufficientBalanceOrAllowance Test if transfers will fail before attempting.
|
||||
/// @param v Array ECDSA signature v parameters.
|
||||
/// @param r Array of ECDSA signature r parameters.
|
||||
/// @param s Array of ECDSA signature s parameters.
|
||||
function batchFillOrders(
|
||||
address[5][] orderAddresses,
|
||||
uint[6][] orderValues,
|
||||
uint[] fillTakerTokenAmounts,
|
||||
bool shouldThrowOnInsufficientBalanceOrAllowance,
|
||||
uint8[] v,
|
||||
bytes32[] r,
|
||||
bytes32[] s)
|
||||
public
|
||||
{
|
||||
for (uint i = 0; i < orderAddresses.length; i++) {
|
||||
fillOrder(
|
||||
orderAddresses[i],
|
||||
orderValues[i],
|
||||
fillTakerTokenAmounts[i],
|
||||
shouldThrowOnInsufficientBalanceOrAllowance,
|
||||
v[i],
|
||||
r[i],
|
||||
s[i]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Synchronously executes multiple fillOrKill orders in a single transaction.
|
||||
/// @param orderAddresses Array of address arrays containing individual order addresses.
|
||||
/// @param orderValues Array of uint arrays containing individual order values.
|
||||
/// @param fillTakerTokenAmounts Array of desired amounts of takerToken to fill in orders.
|
||||
/// @param v Array ECDSA signature v parameters.
|
||||
/// @param r Array of ECDSA signature r parameters.
|
||||
/// @param s Array of ECDSA signature s parameters.
|
||||
function batchFillOrKillOrders(
|
||||
address[5][] orderAddresses,
|
||||
uint[6][] orderValues,
|
||||
uint[] fillTakerTokenAmounts,
|
||||
uint8[] v,
|
||||
bytes32[] r,
|
||||
bytes32[] s)
|
||||
public
|
||||
{
|
||||
for (uint i = 0; i < orderAddresses.length; i++) {
|
||||
fillOrKillOrder(
|
||||
orderAddresses[i],
|
||||
orderValues[i],
|
||||
fillTakerTokenAmounts[i],
|
||||
v[i],
|
||||
r[i],
|
||||
s[i]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Synchronously executes multiple fill orders in a single transaction until total fillTakerTokenAmount filled.
|
||||
/// @param orderAddresses Array of address arrays containing individual order addresses.
|
||||
/// @param orderValues Array of uint arrays containing individual order values.
|
||||
/// @param fillTakerTokenAmount Desired total amount of takerToken to fill in orders.
|
||||
/// @param shouldThrowOnInsufficientBalanceOrAllowance Test if transfers will fail before attempting.
|
||||
/// @param v Array ECDSA signature v parameters.
|
||||
/// @param r Array of ECDSA signature r parameters.
|
||||
/// @param s Array of ECDSA signature s parameters.
|
||||
/// @return Total amount of fillTakerTokenAmount filled in orders.
|
||||
function fillOrdersUpTo(
|
||||
address[5][] orderAddresses,
|
||||
uint[6][] orderValues,
|
||||
uint fillTakerTokenAmount,
|
||||
bool shouldThrowOnInsufficientBalanceOrAllowance,
|
||||
uint8[] v,
|
||||
bytes32[] r,
|
||||
bytes32[] s)
|
||||
public
|
||||
returns (uint)
|
||||
{
|
||||
uint filledTakerTokenAmount = 0;
|
||||
for (uint i = 0; i < orderAddresses.length; i++) {
|
||||
require(orderAddresses[i][3] == orderAddresses[0][3]); // takerToken must be the same for each order
|
||||
filledTakerTokenAmount = safeAdd(filledTakerTokenAmount, fillOrder(
|
||||
orderAddresses[i],
|
||||
orderValues[i],
|
||||
safeSub(fillTakerTokenAmount, filledTakerTokenAmount),
|
||||
shouldThrowOnInsufficientBalanceOrAllowance,
|
||||
v[i],
|
||||
r[i],
|
||||
s[i]
|
||||
));
|
||||
if (filledTakerTokenAmount == fillTakerTokenAmount) break;
|
||||
}
|
||||
return filledTakerTokenAmount;
|
||||
}
|
||||
|
||||
/// @dev Synchronously cancels multiple orders in a single transaction.
|
||||
/// @param orderAddresses Array of address arrays containing individual order addresses.
|
||||
/// @param orderValues Array of uint arrays containing individual order values.
|
||||
/// @param cancelTakerTokenAmounts Array of desired amounts of takerToken to cancel in orders.
|
||||
function batchCancelOrders(
|
||||
address[5][] orderAddresses,
|
||||
uint[6][] orderValues,
|
||||
uint[] cancelTakerTokenAmounts)
|
||||
public
|
||||
{
|
||||
for (uint i = 0; i < orderAddresses.length; i++) {
|
||||
cancelOrder(
|
||||
orderAddresses[i],
|
||||
orderValues[i],
|
||||
cancelTakerTokenAmounts[i]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Constant public functions
|
||||
*/
|
||||
|
||||
/// @dev Calculates Keccak-256 hash of order with specified parameters.
|
||||
/// @param orderAddresses Array of order's maker, taker, makerToken, takerToken, and feeRecipient.
|
||||
/// @param orderValues Array of order's makerTokenAmount, takerTokenAmount, makerFee, takerFee, expirationTimestampInSec, and salt.
|
||||
/// @return Keccak-256 hash of order.
|
||||
function getOrderHash(address[5] orderAddresses, uint[6] orderValues)
|
||||
public
|
||||
constant
|
||||
returns (bytes32)
|
||||
{
|
||||
return keccak256(
|
||||
address(this),
|
||||
orderAddresses[0], // maker
|
||||
orderAddresses[1], // taker
|
||||
orderAddresses[2], // makerToken
|
||||
orderAddresses[3], // takerToken
|
||||
orderAddresses[4], // feeRecipient
|
||||
orderValues[0], // makerTokenAmount
|
||||
orderValues[1], // takerTokenAmount
|
||||
orderValues[2], // makerFee
|
||||
orderValues[3], // takerFee
|
||||
orderValues[4], // expirationTimestampInSec
|
||||
orderValues[5] // salt
|
||||
);
|
||||
}
|
||||
|
||||
/// @dev Verifies that an order signature is valid.
|
||||
/// @param signer address of signer.
|
||||
/// @param hash Signed Keccak-256 hash.
|
||||
/// @param v ECDSA signature parameter v.
|
||||
/// @param r ECDSA signature parameters r.
|
||||
/// @param s ECDSA signature parameters s.
|
||||
/// @return Validity of order signature.
|
||||
function isValidSignature(
|
||||
address signer,
|
||||
bytes32 hash,
|
||||
uint8 v,
|
||||
bytes32 r,
|
||||
bytes32 s)
|
||||
public
|
||||
constant
|
||||
returns (bool)
|
||||
{
|
||||
return signer == ecrecover(
|
||||
keccak256("\x19Ethereum Signed Message:\n32", hash),
|
||||
v,
|
||||
r,
|
||||
s
|
||||
);
|
||||
}
|
||||
|
||||
/// @dev Checks if rounding error > 0.1%.
|
||||
/// @param numerator Numerator.
|
||||
/// @param denominator Denominator.
|
||||
/// @param target Value to multiply with numerator/denominator.
|
||||
/// @return Rounding error is present.
|
||||
function isRoundingError(uint numerator, uint denominator, uint target)
|
||||
public
|
||||
constant
|
||||
returns (bool)
|
||||
{
|
||||
uint remainder = mulmod(target, numerator, denominator);
|
||||
if (remainder == 0) return false; // No rounding error.
|
||||
|
||||
uint errPercentageTimes1000000 = safeDiv(
|
||||
safeMul(remainder, 1000000),
|
||||
safeMul(numerator, target)
|
||||
);
|
||||
return errPercentageTimes1000000 > 1000;
|
||||
}
|
||||
|
||||
/// @dev Calculates partial value given a numerator and denominator.
|
||||
/// @param numerator Numerator.
|
||||
/// @param denominator Denominator.
|
||||
/// @param target Value to calculate partial of.
|
||||
/// @return Partial value of target.
|
||||
function getPartialAmount(uint numerator, uint denominator, uint target)
|
||||
public
|
||||
constant
|
||||
returns (uint)
|
||||
{
|
||||
return safeDiv(safeMul(numerator, target), denominator);
|
||||
}
|
||||
|
||||
/// @dev Calculates the sum of values already filled and cancelled for a given order.
|
||||
/// @param orderHash The Keccak-256 hash of the given order.
|
||||
/// @return Sum of values already filled and cancelled.
|
||||
function getUnavailableTakerTokenAmount(bytes32 orderHash)
|
||||
public
|
||||
constant
|
||||
returns (uint)
|
||||
{
|
||||
return safeAdd(filled[orderHash], cancelled[orderHash]);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Internal functions
|
||||
*/
|
||||
|
||||
/// @dev Transfers a token using TokenTransferProxy transferFrom function.
|
||||
/// @param token Address of token to transferFrom.
|
||||
/// @param from Address transfering token.
|
||||
/// @param to Address receiving token.
|
||||
/// @param value Amount of token to transfer.
|
||||
/// @return Success of token transfer.
|
||||
function transferViaTokenTransferProxy(
|
||||
address token,
|
||||
address from,
|
||||
address to,
|
||||
uint value)
|
||||
internal
|
||||
returns (bool)
|
||||
{
|
||||
return TokenTransferProxy(TOKEN_TRANSFER_PROXY_CONTRACT).transferFrom(token, from, to, value);
|
||||
}
|
||||
|
||||
/// @dev Checks if any order transfers will fail.
|
||||
/// @param order Order struct of params that will be checked.
|
||||
/// @param fillTakerTokenAmount Desired amount of takerToken to fill.
|
||||
/// @return Predicted result of transfers.
|
||||
function isTransferable(Order order, uint fillTakerTokenAmount)
|
||||
internal
|
||||
constant // The called token contracts may attempt to change state, but will not be able to due to gas limits on getBalance and getAllowance.
|
||||
returns (bool)
|
||||
{
|
||||
address taker = msg.sender;
|
||||
uint fillMakerTokenAmount = getPartialAmount(fillTakerTokenAmount, order.takerTokenAmount, order.makerTokenAmount);
|
||||
|
||||
if (order.feeRecipient != address(0)) {
|
||||
bool isMakerTokenZRX = order.makerToken == ZRX_TOKEN_CONTRACT;
|
||||
bool isTakerTokenZRX = order.takerToken == ZRX_TOKEN_CONTRACT;
|
||||
uint paidMakerFee = getPartialAmount(fillTakerTokenAmount, order.takerTokenAmount, order.makerFee);
|
||||
uint paidTakerFee = getPartialAmount(fillTakerTokenAmount, order.takerTokenAmount, order.takerFee);
|
||||
uint requiredMakerZRX = isMakerTokenZRX ? safeAdd(fillMakerTokenAmount, paidMakerFee) : paidMakerFee;
|
||||
uint requiredTakerZRX = isTakerTokenZRX ? safeAdd(fillTakerTokenAmount, paidTakerFee) : paidTakerFee;
|
||||
|
||||
if ( getBalance(ZRX_TOKEN_CONTRACT, order.maker) < requiredMakerZRX
|
||||
|| getAllowance(ZRX_TOKEN_CONTRACT, order.maker) < requiredMakerZRX
|
||||
|| getBalance(ZRX_TOKEN_CONTRACT, taker) < requiredTakerZRX
|
||||
|| getAllowance(ZRX_TOKEN_CONTRACT, taker) < requiredTakerZRX
|
||||
) return false;
|
||||
|
||||
if (!isMakerTokenZRX && ( getBalance(order.makerToken, order.maker) < fillMakerTokenAmount // Don't double check makerToken if ZRX
|
||||
|| getAllowance(order.makerToken, order.maker) < fillMakerTokenAmount)
|
||||
) return false;
|
||||
if (!isTakerTokenZRX && ( getBalance(order.takerToken, taker) < fillTakerTokenAmount // Don't double check takerToken if ZRX
|
||||
|| getAllowance(order.takerToken, taker) < fillTakerTokenAmount)
|
||||
) return false;
|
||||
} else if ( getBalance(order.makerToken, order.maker) < fillMakerTokenAmount
|
||||
|| getAllowance(order.makerToken, order.maker) < fillMakerTokenAmount
|
||||
|| getBalance(order.takerToken, taker) < fillTakerTokenAmount
|
||||
|| getAllowance(order.takerToken, taker) < fillTakerTokenAmount
|
||||
) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// @dev Get token balance of an address.
|
||||
/// @param token Address of token.
|
||||
/// @param owner Address of owner.
|
||||
/// @return Token balance of owner.
|
||||
function getBalance(address token, address owner)
|
||||
internal
|
||||
constant // The called token contract may attempt to change state, but will not be able to due to an added gas limit.
|
||||
returns (uint)
|
||||
{
|
||||
return Token(token).balanceOf.gas(EXTERNAL_QUERY_GAS_LIMIT)(owner); // Limit gas to prevent reentrancy
|
||||
}
|
||||
|
||||
/// @dev Get allowance of token given to TokenTransferProxy by an address.
|
||||
/// @param token Address of token.
|
||||
/// @param owner Address of owner.
|
||||
/// @return Allowance of token given to TokenTransferProxy by owner.
|
||||
function getAllowance(address token, address owner)
|
||||
internal
|
||||
constant // The called token contract may attempt to change state, but will not be able to due to an added gas limit.
|
||||
returns (uint)
|
||||
{
|
||||
return Token(token).allowance.gas(EXTERNAL_QUERY_GAS_LIMIT)(owner, TOKEN_TRANSFER_PROXY_CONTRACT); // Limit gas to prevent reentrancy
|
||||
}
|
||||
}
|
132
packages/contracts/contracts/MultiSigWalletWithTimeLock.sol
Normal file
132
packages/contracts/contracts/MultiSigWalletWithTimeLock.sol
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
|
||||
Copyright 2017 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.4.11;
|
||||
|
||||
import "./base/MultiSigWallet.sol";
|
||||
|
||||
/// @title Multisignature wallet with time lock- Allows multiple parties to execute a transaction after a time lock has passed.
|
||||
/// @author Amir Bandeali - <amir@0xProject.com>
|
||||
contract MultiSigWalletWithTimeLock is MultiSigWallet {
|
||||
|
||||
event ConfirmationTimeSet(uint indexed transactionId, uint confirmationTime);
|
||||
event TimeLockChange(uint secondsTimeLocked);
|
||||
|
||||
uint public secondsTimeLocked;
|
||||
|
||||
mapping (uint => uint) public confirmationTimes;
|
||||
|
||||
modifier notFullyConfirmed(uint transactionId) {
|
||||
require(!isConfirmed(transactionId));
|
||||
_;
|
||||
}
|
||||
|
||||
modifier fullyConfirmed(uint transactionId) {
|
||||
require(isConfirmed(transactionId));
|
||||
_;
|
||||
}
|
||||
|
||||
modifier pastTimeLock(uint transactionId) {
|
||||
require(block.timestamp >= confirmationTimes[transactionId] + secondsTimeLocked);
|
||||
_;
|
||||
}
|
||||
|
||||
/*
|
||||
* Public functions
|
||||
*/
|
||||
|
||||
/// @dev Contract constructor sets initial owners, required number of confirmations, and time lock.
|
||||
/// @param _owners List of initial owners.
|
||||
/// @param _required Number of required confirmations.
|
||||
/// @param _secondsTimeLocked Duration needed after a transaction is confirmed and before it becomes executable, in seconds.
|
||||
function MultiSigWalletWithTimeLock(address[] _owners, uint _required, uint _secondsTimeLocked)
|
||||
public
|
||||
MultiSigWallet(_owners, _required)
|
||||
{
|
||||
secondsTimeLocked = _secondsTimeLocked;
|
||||
}
|
||||
|
||||
/// @dev Changes the duration of the time lock for transactions.
|
||||
/// @param _secondsTimeLocked Duration needed after a transaction is confirmed and before it becomes executable, in seconds.
|
||||
function changeTimeLock(uint _secondsTimeLocked)
|
||||
public
|
||||
onlyWallet
|
||||
{
|
||||
secondsTimeLocked = _secondsTimeLocked;
|
||||
TimeLockChange(_secondsTimeLocked);
|
||||
}
|
||||
|
||||
/// @dev Allows an owner to confirm a transaction.
|
||||
/// @param transactionId Transaction ID.
|
||||
function confirmTransaction(uint transactionId)
|
||||
public
|
||||
ownerExists(msg.sender)
|
||||
transactionExists(transactionId)
|
||||
notConfirmed(transactionId, msg.sender)
|
||||
notFullyConfirmed(transactionId)
|
||||
{
|
||||
confirmations[transactionId][msg.sender] = true;
|
||||
Confirmation(msg.sender, transactionId);
|
||||
if (isConfirmed(transactionId)) {
|
||||
setConfirmationTime(transactionId, block.timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Allows an owner to revoke a confirmation for a transaction.
|
||||
/// @param transactionId Transaction ID.
|
||||
function revokeConfirmation(uint transactionId)
|
||||
public
|
||||
ownerExists(msg.sender)
|
||||
confirmed(transactionId, msg.sender)
|
||||
notExecuted(transactionId)
|
||||
notFullyConfirmed(transactionId)
|
||||
{
|
||||
confirmations[transactionId][msg.sender] = false;
|
||||
Revocation(msg.sender, transactionId);
|
||||
}
|
||||
|
||||
/// @dev Allows anyone to execute a confirmed transaction.
|
||||
/// @param transactionId Transaction ID.
|
||||
function executeTransaction(uint transactionId)
|
||||
public
|
||||
notExecuted(transactionId)
|
||||
fullyConfirmed(transactionId)
|
||||
pastTimeLock(transactionId)
|
||||
{
|
||||
Transaction storage tx = transactions[transactionId];
|
||||
tx.executed = true;
|
||||
if (tx.destination.call.value(tx.value)(tx.data))
|
||||
Execution(transactionId);
|
||||
else {
|
||||
ExecutionFailure(transactionId);
|
||||
tx.executed = false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Internal functions
|
||||
*/
|
||||
|
||||
/// @dev Sets the time of when a submission first passed.
|
||||
function setConfirmationTime(uint transactionId, uint confirmationTime)
|
||||
internal
|
||||
{
|
||||
confirmationTimes[transactionId] = confirmationTime;
|
||||
ConfirmationTimeSet(transactionId, confirmationTime);
|
||||
}
|
||||
}
|
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
|
||||
Copyright 2017 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.4.11;
|
||||
|
||||
import "./MultiSigWalletWithTimeLock.sol";
|
||||
|
||||
contract MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress is MultiSigWalletWithTimeLock {
|
||||
|
||||
address public TOKEN_TRANSFER_PROXY_CONTRACT;
|
||||
|
||||
modifier validRemoveAuthorizedAddressTx(uint transactionId) {
|
||||
Transaction storage tx = transactions[transactionId];
|
||||
require(tx.destination == TOKEN_TRANSFER_PROXY_CONTRACT);
|
||||
require(isFunctionRemoveAuthorizedAddress(tx.data));
|
||||
_;
|
||||
}
|
||||
|
||||
/// @dev Contract constructor sets initial owners, required number of confirmations, time lock, and tokenTransferProxy address.
|
||||
/// @param _owners List of initial owners.
|
||||
/// @param _required Number of required confirmations.
|
||||
/// @param _secondsTimeLocked Duration needed after a transaction is confirmed and before it becomes executable, in seconds.
|
||||
/// @param _tokenTransferProxy Address of TokenTransferProxy contract.
|
||||
function MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress(
|
||||
address[] _owners,
|
||||
uint _required,
|
||||
uint _secondsTimeLocked,
|
||||
address _tokenTransferProxy)
|
||||
public
|
||||
MultiSigWalletWithTimeLock(_owners, _required, _secondsTimeLocked)
|
||||
{
|
||||
TOKEN_TRANSFER_PROXY_CONTRACT = _tokenTransferProxy;
|
||||
}
|
||||
|
||||
/// @dev Allows execution of removeAuthorizedAddress without time lock.
|
||||
/// @param transactionId Transaction ID.
|
||||
function executeRemoveAuthorizedAddress(uint transactionId)
|
||||
public
|
||||
notExecuted(transactionId)
|
||||
fullyConfirmed(transactionId)
|
||||
validRemoveAuthorizedAddressTx(transactionId)
|
||||
{
|
||||
Transaction storage tx = transactions[transactionId];
|
||||
tx.executed = true;
|
||||
if (tx.destination.call.value(tx.value)(tx.data))
|
||||
Execution(transactionId);
|
||||
else {
|
||||
ExecutionFailure(transactionId);
|
||||
tx.executed = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Compares first 4 bytes of byte array to removeAuthorizedAddress function signature.
|
||||
/// @param data Transaction data.
|
||||
/// @return Successful if data is a call to removeAuthorizedAddress.
|
||||
function isFunctionRemoveAuthorizedAddress(bytes data)
|
||||
public
|
||||
constant
|
||||
returns (bool)
|
||||
{
|
||||
bytes4 removeAuthorizedAddressSignature = bytes4(sha3("removeAuthorizedAddress(address)"));
|
||||
for (uint i = 0; i < 4; i++) {
|
||||
require(data[i] == removeAuthorizedAddressSignature[i]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
308
packages/contracts/contracts/TokenRegistry.sol
Normal file
308
packages/contracts/contracts/TokenRegistry.sol
Normal file
@@ -0,0 +1,308 @@
|
||||
/*
|
||||
|
||||
Copyright 2017 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.4.11;
|
||||
|
||||
import "./base/Ownable.sol";
|
||||
|
||||
/// @title Token Registry - Stores metadata associated with ERC20 tokens. See ERC22 https://github.com/ethereum/EIPs/issues/22
|
||||
/// @author Amir Bandeali - <amir@0xProject.com>, Will Warren - <will@0xProject.com>
|
||||
contract TokenRegistry is Ownable {
|
||||
|
||||
event LogAddToken(
|
||||
address indexed token,
|
||||
string name,
|
||||
string symbol,
|
||||
uint8 decimals,
|
||||
bytes ipfsHash,
|
||||
bytes swarmHash
|
||||
);
|
||||
|
||||
event LogRemoveToken(
|
||||
address indexed token,
|
||||
string name,
|
||||
string symbol,
|
||||
uint8 decimals,
|
||||
bytes ipfsHash,
|
||||
bytes swarmHash
|
||||
);
|
||||
|
||||
event LogTokenNameChange(address indexed token, string oldName, string newName);
|
||||
event LogTokenSymbolChange(address indexed token, string oldSymbol, string newSymbol);
|
||||
event LogTokenIpfsHashChange(address indexed token, bytes oldIpfsHash, bytes newIpfsHash);
|
||||
event LogTokenSwarmHashChange(address indexed token, bytes oldSwarmHash, bytes newSwarmHash);
|
||||
|
||||
mapping (address => TokenMetadata) public tokens;
|
||||
mapping (string => address) tokenBySymbol;
|
||||
mapping (string => address) tokenByName;
|
||||
|
||||
address[] public tokenAddresses;
|
||||
|
||||
struct TokenMetadata {
|
||||
address token;
|
||||
string name;
|
||||
string symbol;
|
||||
uint8 decimals;
|
||||
bytes ipfsHash;
|
||||
bytes swarmHash;
|
||||
}
|
||||
|
||||
modifier tokenExists(address _token) {
|
||||
require(tokens[_token].token != address(0));
|
||||
_;
|
||||
}
|
||||
|
||||
modifier tokenDoesNotExist(address _token) {
|
||||
require(tokens[_token].token == address(0));
|
||||
_;
|
||||
}
|
||||
|
||||
modifier nameDoesNotExist(string _name) {
|
||||
require(tokenByName[_name] == address(0));
|
||||
_;
|
||||
}
|
||||
|
||||
modifier symbolDoesNotExist(string _symbol) {
|
||||
require(tokenBySymbol[_symbol] == address(0));
|
||||
_;
|
||||
}
|
||||
|
||||
modifier addressNotNull(address _address) {
|
||||
require(_address != address(0));
|
||||
_;
|
||||
}
|
||||
|
||||
|
||||
/// @dev Allows owner to add a new token to the registry.
|
||||
/// @param _token Address of new token.
|
||||
/// @param _name Name of new token.
|
||||
/// @param _symbol Symbol for new token.
|
||||
/// @param _decimals Number of decimals, divisibility of new token.
|
||||
/// @param _ipfsHash IPFS hash of token icon.
|
||||
/// @param _swarmHash Swarm hash of token icon.
|
||||
function addToken(
|
||||
address _token,
|
||||
string _name,
|
||||
string _symbol,
|
||||
uint8 _decimals,
|
||||
bytes _ipfsHash,
|
||||
bytes _swarmHash)
|
||||
public
|
||||
onlyOwner
|
||||
tokenDoesNotExist(_token)
|
||||
addressNotNull(_token)
|
||||
symbolDoesNotExist(_symbol)
|
||||
nameDoesNotExist(_name)
|
||||
{
|
||||
tokens[_token] = TokenMetadata({
|
||||
token: _token,
|
||||
name: _name,
|
||||
symbol: _symbol,
|
||||
decimals: _decimals,
|
||||
ipfsHash: _ipfsHash,
|
||||
swarmHash: _swarmHash
|
||||
});
|
||||
tokenAddresses.push(_token);
|
||||
tokenBySymbol[_symbol] = _token;
|
||||
tokenByName[_name] = _token;
|
||||
LogAddToken(
|
||||
_token,
|
||||
_name,
|
||||
_symbol,
|
||||
_decimals,
|
||||
_ipfsHash,
|
||||
_swarmHash
|
||||
);
|
||||
}
|
||||
|
||||
/// @dev Allows owner to remove an existing token from the registry.
|
||||
/// @param _token Address of existing token.
|
||||
function removeToken(address _token, uint _index)
|
||||
public
|
||||
onlyOwner
|
||||
tokenExists(_token)
|
||||
{
|
||||
require(tokenAddresses[_index] == _token);
|
||||
|
||||
tokenAddresses[_index] = tokenAddresses[tokenAddresses.length - 1];
|
||||
tokenAddresses.length -= 1;
|
||||
|
||||
TokenMetadata storage token = tokens[_token];
|
||||
LogRemoveToken(
|
||||
token.token,
|
||||
token.name,
|
||||
token.symbol,
|
||||
token.decimals,
|
||||
token.ipfsHash,
|
||||
token.swarmHash
|
||||
);
|
||||
delete tokenBySymbol[token.symbol];
|
||||
delete tokenByName[token.name];
|
||||
delete tokens[_token];
|
||||
}
|
||||
|
||||
/// @dev Allows owner to modify an existing token's name.
|
||||
/// @param _token Address of existing token.
|
||||
/// @param _name New name.
|
||||
function setTokenName(address _token, string _name)
|
||||
public
|
||||
onlyOwner
|
||||
tokenExists(_token)
|
||||
nameDoesNotExist(_name)
|
||||
{
|
||||
TokenMetadata storage token = tokens[_token];
|
||||
LogTokenNameChange(_token, token.name, _name);
|
||||
delete tokenByName[token.name];
|
||||
tokenByName[_name] = _token;
|
||||
token.name = _name;
|
||||
}
|
||||
|
||||
/// @dev Allows owner to modify an existing token's symbol.
|
||||
/// @param _token Address of existing token.
|
||||
/// @param _symbol New symbol.
|
||||
function setTokenSymbol(address _token, string _symbol)
|
||||
public
|
||||
onlyOwner
|
||||
tokenExists(_token)
|
||||
symbolDoesNotExist(_symbol)
|
||||
{
|
||||
TokenMetadata storage token = tokens[_token];
|
||||
LogTokenSymbolChange(_token, token.symbol, _symbol);
|
||||
delete tokenBySymbol[token.symbol];
|
||||
tokenBySymbol[_symbol] = _token;
|
||||
token.symbol = _symbol;
|
||||
}
|
||||
|
||||
/// @dev Allows owner to modify an existing token's IPFS hash.
|
||||
/// @param _token Address of existing token.
|
||||
/// @param _ipfsHash New IPFS hash.
|
||||
function setTokenIpfsHash(address _token, bytes _ipfsHash)
|
||||
public
|
||||
onlyOwner
|
||||
tokenExists(_token)
|
||||
{
|
||||
TokenMetadata storage token = tokens[_token];
|
||||
LogTokenIpfsHashChange(_token, token.ipfsHash, _ipfsHash);
|
||||
token.ipfsHash = _ipfsHash;
|
||||
}
|
||||
|
||||
/// @dev Allows owner to modify an existing token's Swarm hash.
|
||||
/// @param _token Address of existing token.
|
||||
/// @param _swarmHash New Swarm hash.
|
||||
function setTokenSwarmHash(address _token, bytes _swarmHash)
|
||||
public
|
||||
onlyOwner
|
||||
tokenExists(_token)
|
||||
{
|
||||
TokenMetadata storage token = tokens[_token];
|
||||
LogTokenSwarmHashChange(_token, token.swarmHash, _swarmHash);
|
||||
token.swarmHash = _swarmHash;
|
||||
}
|
||||
|
||||
/*
|
||||
* Web3 call functions
|
||||
*/
|
||||
|
||||
/// @dev Provides a registered token's address when given the token symbol.
|
||||
/// @param _symbol Symbol of registered token.
|
||||
/// @return Token's address.
|
||||
function getTokenAddressBySymbol(string _symbol) constant returns (address) {
|
||||
return tokenBySymbol[_symbol];
|
||||
}
|
||||
|
||||
/// @dev Provides a registered token's address when given the token name.
|
||||
/// @param _name Name of registered token.
|
||||
/// @return Token's address.
|
||||
function getTokenAddressByName(string _name) constant returns (address) {
|
||||
return tokenByName[_name];
|
||||
}
|
||||
|
||||
/// @dev Provides a registered token's metadata, looked up by address.
|
||||
/// @param _token Address of registered token.
|
||||
/// @return Token metadata.
|
||||
function getTokenMetaData(address _token)
|
||||
public
|
||||
constant
|
||||
returns (
|
||||
address, //tokenAddress
|
||||
string, //name
|
||||
string, //symbol
|
||||
uint8, //decimals
|
||||
bytes, //ipfsHash
|
||||
bytes //swarmHash
|
||||
)
|
||||
{
|
||||
TokenMetadata memory token = tokens[_token];
|
||||
return (
|
||||
token.token,
|
||||
token.name,
|
||||
token.symbol,
|
||||
token.decimals,
|
||||
token.ipfsHash,
|
||||
token.swarmHash
|
||||
);
|
||||
}
|
||||
|
||||
/// @dev Provides a registered token's metadata, looked up by name.
|
||||
/// @param _name Name of registered token.
|
||||
/// @return Token metadata.
|
||||
function getTokenByName(string _name)
|
||||
public
|
||||
constant
|
||||
returns (
|
||||
address, //tokenAddress
|
||||
string, //name
|
||||
string, //symbol
|
||||
uint8, //decimals
|
||||
bytes, //ipfsHash
|
||||
bytes //swarmHash
|
||||
)
|
||||
{
|
||||
address _token = tokenByName[_name];
|
||||
return getTokenMetaData(_token);
|
||||
}
|
||||
|
||||
/// @dev Provides a registered token's metadata, looked up by symbol.
|
||||
/// @param _symbol Symbol of registered token.
|
||||
/// @return Token metadata.
|
||||
function getTokenBySymbol(string _symbol)
|
||||
public
|
||||
constant
|
||||
returns (
|
||||
address, //tokenAddress
|
||||
string, //name
|
||||
string, //symbol
|
||||
uint8, //decimals
|
||||
bytes, //ipfsHash
|
||||
bytes //swarmHash
|
||||
)
|
||||
{
|
||||
address _token = tokenBySymbol[_symbol];
|
||||
return getTokenMetaData(_token);
|
||||
}
|
||||
|
||||
/// @dev Returns an array containing all token addresses.
|
||||
/// @return Array of token addresses.
|
||||
function getTokenAddresses()
|
||||
public
|
||||
constant
|
||||
returns (address[])
|
||||
{
|
||||
return tokenAddresses;
|
||||
}
|
||||
}
|
115
packages/contracts/contracts/TokenTransferProxy.sol
Normal file
115
packages/contracts/contracts/TokenTransferProxy.sol
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
|
||||
Copyright 2017 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.4.11;
|
||||
|
||||
import "./base/Token.sol";
|
||||
import "./base/Ownable.sol";
|
||||
|
||||
/// @title TokenTransferProxy - Transfers tokens on behalf of contracts that have been approved via decentralized governance.
|
||||
/// @author Amir Bandeali - <amir@0xProject.com>, Will Warren - <will@0xProject.com>
|
||||
contract TokenTransferProxy is Ownable {
|
||||
|
||||
/// @dev Only authorized addresses can invoke functions with this modifier.
|
||||
modifier onlyAuthorized {
|
||||
require(authorized[msg.sender]);
|
||||
_;
|
||||
}
|
||||
|
||||
modifier targetAuthorized(address target) {
|
||||
require(authorized[target]);
|
||||
_;
|
||||
}
|
||||
|
||||
modifier targetNotAuthorized(address target) {
|
||||
require(!authorized[target]);
|
||||
_;
|
||||
}
|
||||
|
||||
mapping (address => bool) public authorized;
|
||||
address[] public authorities;
|
||||
|
||||
event LogAuthorizedAddressAdded(address indexed target, address indexed caller);
|
||||
event LogAuthorizedAddressRemoved(address indexed target, address indexed caller);
|
||||
|
||||
/*
|
||||
* Public functions
|
||||
*/
|
||||
|
||||
/// @dev Authorizes an address.
|
||||
/// @param target Address to authorize.
|
||||
function addAuthorizedAddress(address target)
|
||||
public
|
||||
onlyOwner
|
||||
targetNotAuthorized(target)
|
||||
{
|
||||
authorized[target] = true;
|
||||
authorities.push(target);
|
||||
LogAuthorizedAddressAdded(target, msg.sender);
|
||||
}
|
||||
|
||||
/// @dev Removes authorizion of an address.
|
||||
/// @param target Address to remove authorization from.
|
||||
function removeAuthorizedAddress(address target)
|
||||
public
|
||||
onlyOwner
|
||||
targetAuthorized(target)
|
||||
{
|
||||
delete authorized[target];
|
||||
for (uint i = 0; i < authorities.length; i++) {
|
||||
if (authorities[i] == target) {
|
||||
authorities[i] = authorities[authorities.length - 1];
|
||||
authorities.length -= 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
LogAuthorizedAddressRemoved(target, msg.sender);
|
||||
}
|
||||
|
||||
/// @dev Calls into ERC20 Token contract, invoking transferFrom.
|
||||
/// @param token Address of token to transfer.
|
||||
/// @param from Address to transfer token from.
|
||||
/// @param to Address to transfer token to.
|
||||
/// @param value Amount of token to transfer.
|
||||
/// @return Success of transfer.
|
||||
function transferFrom(
|
||||
address token,
|
||||
address from,
|
||||
address to,
|
||||
uint value)
|
||||
public
|
||||
onlyAuthorized
|
||||
returns (bool)
|
||||
{
|
||||
return Token(token).transferFrom(from, to, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Public constant functions
|
||||
*/
|
||||
|
||||
/// @dev Gets all authorized addresses.
|
||||
/// @return Array of authorized addresses.
|
||||
function getAuthorizedAddresses()
|
||||
public
|
||||
constant
|
||||
returns (address[])
|
||||
{
|
||||
return authorities;
|
||||
}
|
||||
}
|
365
packages/contracts/contracts/base/MultiSigWallet.sol
Normal file
365
packages/contracts/contracts/base/MultiSigWallet.sol
Normal file
@@ -0,0 +1,365 @@
|
||||
pragma solidity 0.4.11;
|
||||
|
||||
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
|
||||
/// @author Stefan George - <stefan.george@consensys.net>
|
||||
contract MultiSigWallet {
|
||||
|
||||
uint constant public MAX_OWNER_COUNT = 50;
|
||||
|
||||
event Confirmation(address indexed sender, uint indexed transactionId);
|
||||
event Revocation(address indexed sender, uint indexed transactionId);
|
||||
event Submission(uint indexed transactionId);
|
||||
event Execution(uint indexed transactionId);
|
||||
event ExecutionFailure(uint indexed transactionId);
|
||||
event Deposit(address indexed sender, uint value);
|
||||
event OwnerAddition(address indexed owner);
|
||||
event OwnerRemoval(address indexed owner);
|
||||
event RequirementChange(uint required);
|
||||
|
||||
mapping (uint => Transaction) public transactions;
|
||||
mapping (uint => mapping (address => bool)) public confirmations;
|
||||
mapping (address => bool) public isOwner;
|
||||
address[] public owners;
|
||||
uint public required;
|
||||
uint public transactionCount;
|
||||
|
||||
struct Transaction {
|
||||
address destination;
|
||||
uint value;
|
||||
bytes data;
|
||||
bool executed;
|
||||
}
|
||||
|
||||
modifier onlyWallet() {
|
||||
if (msg.sender != address(this))
|
||||
throw;
|
||||
_;
|
||||
}
|
||||
|
||||
modifier ownerDoesNotExist(address owner) {
|
||||
if (isOwner[owner])
|
||||
throw;
|
||||
_;
|
||||
}
|
||||
|
||||
modifier ownerExists(address owner) {
|
||||
if (!isOwner[owner])
|
||||
throw;
|
||||
_;
|
||||
}
|
||||
|
||||
modifier transactionExists(uint transactionId) {
|
||||
if (transactions[transactionId].destination == 0)
|
||||
throw;
|
||||
_;
|
||||
}
|
||||
|
||||
modifier confirmed(uint transactionId, address owner) {
|
||||
if (!confirmations[transactionId][owner])
|
||||
throw;
|
||||
_;
|
||||
}
|
||||
|
||||
modifier notConfirmed(uint transactionId, address owner) {
|
||||
if (confirmations[transactionId][owner])
|
||||
throw;
|
||||
_;
|
||||
}
|
||||
|
||||
modifier notExecuted(uint transactionId) {
|
||||
if (transactions[transactionId].executed)
|
||||
throw;
|
||||
_;
|
||||
}
|
||||
|
||||
modifier notNull(address _address) {
|
||||
if (_address == 0)
|
||||
throw;
|
||||
_;
|
||||
}
|
||||
|
||||
modifier validRequirement(uint ownerCount, uint _required) {
|
||||
if ( ownerCount > MAX_OWNER_COUNT
|
||||
|| _required > ownerCount
|
||||
|| _required == 0
|
||||
|| ownerCount == 0)
|
||||
throw;
|
||||
_;
|
||||
}
|
||||
|
||||
/// @dev Fallback function allows to deposit ether.
|
||||
function()
|
||||
payable
|
||||
{
|
||||
if (msg.value > 0)
|
||||
Deposit(msg.sender, msg.value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Public functions
|
||||
*/
|
||||
/// @dev Contract constructor sets initial owners and required number of confirmations.
|
||||
/// @param _owners List of initial owners.
|
||||
/// @param _required Number of required confirmations.
|
||||
function MultiSigWallet(address[] _owners, uint _required)
|
||||
public
|
||||
validRequirement(_owners.length, _required)
|
||||
{
|
||||
for (uint i=0; i<_owners.length; i++) {
|
||||
if (isOwner[_owners[i]] || _owners[i] == 0)
|
||||
throw;
|
||||
isOwner[_owners[i]] = true;
|
||||
}
|
||||
owners = _owners;
|
||||
required = _required;
|
||||
}
|
||||
|
||||
/// @dev Allows to add a new owner. Transaction has to be sent by wallet.
|
||||
/// @param owner Address of new owner.
|
||||
function addOwner(address owner)
|
||||
public
|
||||
onlyWallet
|
||||
ownerDoesNotExist(owner)
|
||||
notNull(owner)
|
||||
validRequirement(owners.length + 1, required)
|
||||
{
|
||||
isOwner[owner] = true;
|
||||
owners.push(owner);
|
||||
OwnerAddition(owner);
|
||||
}
|
||||
|
||||
/// @dev Allows to remove an owner. Transaction has to be sent by wallet.
|
||||
/// @param owner Address of owner.
|
||||
function removeOwner(address owner)
|
||||
public
|
||||
onlyWallet
|
||||
ownerExists(owner)
|
||||
{
|
||||
isOwner[owner] = false;
|
||||
for (uint i=0; i<owners.length - 1; i++)
|
||||
if (owners[i] == owner) {
|
||||
owners[i] = owners[owners.length - 1];
|
||||
break;
|
||||
}
|
||||
owners.length -= 1;
|
||||
if (required > owners.length)
|
||||
changeRequirement(owners.length);
|
||||
OwnerRemoval(owner);
|
||||
}
|
||||
|
||||
/// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet.
|
||||
/// @param owner Address of owner to be replaced.
|
||||
/// @param owner Address of new owner.
|
||||
function replaceOwner(address owner, address newOwner)
|
||||
public
|
||||
onlyWallet
|
||||
ownerExists(owner)
|
||||
ownerDoesNotExist(newOwner)
|
||||
{
|
||||
for (uint i=0; i<owners.length; i++)
|
||||
if (owners[i] == owner) {
|
||||
owners[i] = newOwner;
|
||||
break;
|
||||
}
|
||||
isOwner[owner] = false;
|
||||
isOwner[newOwner] = true;
|
||||
OwnerRemoval(owner);
|
||||
OwnerAddition(newOwner);
|
||||
}
|
||||
|
||||
/// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet.
|
||||
/// @param _required Number of required confirmations.
|
||||
function changeRequirement(uint _required)
|
||||
public
|
||||
onlyWallet
|
||||
validRequirement(owners.length, _required)
|
||||
{
|
||||
required = _required;
|
||||
RequirementChange(_required);
|
||||
}
|
||||
|
||||
/// @dev Allows an owner to submit and confirm a transaction.
|
||||
/// @param destination Transaction target address.
|
||||
/// @param value Transaction ether value.
|
||||
/// @param data Transaction data payload.
|
||||
/// @return Returns transaction ID.
|
||||
function submitTransaction(address destination, uint value, bytes data)
|
||||
public
|
||||
returns (uint transactionId)
|
||||
{
|
||||
transactionId = addTransaction(destination, value, data);
|
||||
confirmTransaction(transactionId);
|
||||
}
|
||||
|
||||
/// @dev Allows an owner to confirm a transaction.
|
||||
/// @param transactionId Transaction ID.
|
||||
function confirmTransaction(uint transactionId)
|
||||
public
|
||||
ownerExists(msg.sender)
|
||||
transactionExists(transactionId)
|
||||
notConfirmed(transactionId, msg.sender)
|
||||
{
|
||||
confirmations[transactionId][msg.sender] = true;
|
||||
Confirmation(msg.sender, transactionId);
|
||||
executeTransaction(transactionId);
|
||||
}
|
||||
|
||||
/// @dev Allows an owner to revoke a confirmation for a transaction.
|
||||
/// @param transactionId Transaction ID.
|
||||
function revokeConfirmation(uint transactionId)
|
||||
public
|
||||
ownerExists(msg.sender)
|
||||
confirmed(transactionId, msg.sender)
|
||||
notExecuted(transactionId)
|
||||
{
|
||||
confirmations[transactionId][msg.sender] = false;
|
||||
Revocation(msg.sender, transactionId);
|
||||
}
|
||||
|
||||
/// @dev Allows anyone to execute a confirmed transaction.
|
||||
/// @param transactionId Transaction ID.
|
||||
function executeTransaction(uint transactionId)
|
||||
public
|
||||
notExecuted(transactionId)
|
||||
{
|
||||
if (isConfirmed(transactionId)) {
|
||||
Transaction tx = transactions[transactionId];
|
||||
tx.executed = true;
|
||||
if (tx.destination.call.value(tx.value)(tx.data))
|
||||
Execution(transactionId);
|
||||
else {
|
||||
ExecutionFailure(transactionId);
|
||||
tx.executed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Returns the confirmation status of a transaction.
|
||||
/// @param transactionId Transaction ID.
|
||||
/// @return Confirmation status.
|
||||
function isConfirmed(uint transactionId)
|
||||
public
|
||||
constant
|
||||
returns (bool)
|
||||
{
|
||||
uint count = 0;
|
||||
for (uint i=0; i<owners.length; i++) {
|
||||
if (confirmations[transactionId][owners[i]])
|
||||
count += 1;
|
||||
if (count == required)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Internal functions
|
||||
*/
|
||||
/// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet.
|
||||
/// @param destination Transaction target address.
|
||||
/// @param value Transaction ether value.
|
||||
/// @param data Transaction data payload.
|
||||
/// @return Returns transaction ID.
|
||||
function addTransaction(address destination, uint value, bytes data)
|
||||
internal
|
||||
notNull(destination)
|
||||
returns (uint transactionId)
|
||||
{
|
||||
transactionId = transactionCount;
|
||||
transactions[transactionId] = Transaction({
|
||||
destination: destination,
|
||||
value: value,
|
||||
data: data,
|
||||
executed: false
|
||||
});
|
||||
transactionCount += 1;
|
||||
Submission(transactionId);
|
||||
}
|
||||
|
||||
/*
|
||||
* Web3 call functions
|
||||
*/
|
||||
/// @dev Returns number of confirmations of a transaction.
|
||||
/// @param transactionId Transaction ID.
|
||||
/// @return Number of confirmations.
|
||||
function getConfirmationCount(uint transactionId)
|
||||
public
|
||||
constant
|
||||
returns (uint count)
|
||||
{
|
||||
for (uint i=0; i<owners.length; i++)
|
||||
if (confirmations[transactionId][owners[i]])
|
||||
count += 1;
|
||||
}
|
||||
|
||||
/// @dev Returns total number of transactions after filers are applied.
|
||||
/// @param pending Include pending transactions.
|
||||
/// @param executed Include executed transactions.
|
||||
/// @return Total number of transactions after filters are applied.
|
||||
function getTransactionCount(bool pending, bool executed)
|
||||
public
|
||||
constant
|
||||
returns (uint count)
|
||||
{
|
||||
for (uint i=0; i<transactionCount; i++)
|
||||
if ( pending && !transactions[i].executed
|
||||
|| executed && transactions[i].executed)
|
||||
count += 1;
|
||||
}
|
||||
|
||||
/// @dev Returns list of owners.
|
||||
/// @return List of owner addresses.
|
||||
function getOwners()
|
||||
public
|
||||
constant
|
||||
returns (address[])
|
||||
{
|
||||
return owners;
|
||||
}
|
||||
|
||||
/// @dev Returns array with owner addresses, which confirmed transaction.
|
||||
/// @param transactionId Transaction ID.
|
||||
/// @return Returns array of owner addresses.
|
||||
function getConfirmations(uint transactionId)
|
||||
public
|
||||
constant
|
||||
returns (address[] _confirmations)
|
||||
{
|
||||
address[] memory confirmationsTemp = new address[](owners.length);
|
||||
uint count = 0;
|
||||
uint i;
|
||||
for (i=0; i<owners.length; i++)
|
||||
if (confirmations[transactionId][owners[i]]) {
|
||||
confirmationsTemp[count] = owners[i];
|
||||
count += 1;
|
||||
}
|
||||
_confirmations = new address[](count);
|
||||
for (i=0; i<count; i++)
|
||||
_confirmations[i] = confirmationsTemp[i];
|
||||
}
|
||||
|
||||
/// @dev Returns list of transaction IDs in defined range.
|
||||
/// @param from Index start position of transaction array.
|
||||
/// @param to Index end position of transaction array.
|
||||
/// @param pending Include pending transactions.
|
||||
/// @param executed Include executed transactions.
|
||||
/// @return Returns array of transaction IDs.
|
||||
function getTransactionIds(uint from, uint to, bool pending, bool executed)
|
||||
public
|
||||
constant
|
||||
returns (uint[] _transactionIds)
|
||||
{
|
||||
uint[] memory transactionIdsTemp = new uint[](transactionCount);
|
||||
uint count = 0;
|
||||
uint i;
|
||||
for (i=0; i<transactionCount; i++)
|
||||
if ( pending && !transactions[i].executed
|
||||
|| executed && transactions[i].executed)
|
||||
{
|
||||
transactionIdsTemp[count] = i;
|
||||
count += 1;
|
||||
}
|
||||
_transactionIds = new uint[](to - from);
|
||||
for (i=from; i<to; i++)
|
||||
_transactionIds[i - from] = transactionIdsTemp[i];
|
||||
}
|
||||
}
|
27
packages/contracts/contracts/base/Ownable.sol
Normal file
27
packages/contracts/contracts/base/Ownable.sol
Normal file
@@ -0,0 +1,27 @@
|
||||
pragma solidity 0.4.11;
|
||||
|
||||
/*
|
||||
* Ownable
|
||||
*
|
||||
* Base contract with an owner.
|
||||
* Provides onlyOwner modifier, which prevents function from running if it is called by anyone other than the owner.
|
||||
*/
|
||||
|
||||
contract Ownable {
|
||||
address public owner;
|
||||
|
||||
function Ownable() {
|
||||
owner = msg.sender;
|
||||
}
|
||||
|
||||
modifier onlyOwner() {
|
||||
require(msg.sender == owner);
|
||||
_;
|
||||
}
|
||||
|
||||
function transferOwnership(address newOwner) onlyOwner {
|
||||
if (newOwner != address(0)) {
|
||||
owner = newOwner;
|
||||
}
|
||||
}
|
||||
}
|
41
packages/contracts/contracts/base/SafeMath.sol
Normal file
41
packages/contracts/contracts/base/SafeMath.sol
Normal file
@@ -0,0 +1,41 @@
|
||||
pragma solidity 0.4.11;
|
||||
|
||||
contract SafeMath {
|
||||
function safeMul(uint a, uint b) internal constant returns (uint256) {
|
||||
uint c = a * b;
|
||||
assert(a == 0 || c / a == b);
|
||||
return c;
|
||||
}
|
||||
|
||||
function safeDiv(uint a, uint b) internal constant returns (uint256) {
|
||||
uint c = a / b;
|
||||
return c;
|
||||
}
|
||||
|
||||
function safeSub(uint a, uint b) internal constant returns (uint256) {
|
||||
assert(b <= a);
|
||||
return a - b;
|
||||
}
|
||||
|
||||
function safeAdd(uint a, uint b) internal constant returns (uint256) {
|
||||
uint c = a + b;
|
||||
assert(c >= a);
|
||||
return c;
|
||||
}
|
||||
|
||||
function max64(uint64 a, uint64 b) internal constant returns (uint64) {
|
||||
return a >= b ? a : b;
|
||||
}
|
||||
|
||||
function min64(uint64 a, uint64 b) internal constant returns (uint64) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
function max256(uint256 a, uint256 b) internal constant returns (uint256) {
|
||||
return a >= b ? a : b;
|
||||
}
|
||||
|
||||
function min256(uint256 a, uint256 b) internal constant returns (uint256) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
}
|
44
packages/contracts/contracts/base/StandardToken.sol
Normal file
44
packages/contracts/contracts/base/StandardToken.sol
Normal file
@@ -0,0 +1,44 @@
|
||||
pragma solidity 0.4.11;
|
||||
|
||||
import "./Token.sol";
|
||||
|
||||
contract StandardToken is Token {
|
||||
|
||||
function transfer(address _to, uint _value) returns (bool) {
|
||||
//Default assumes totalSupply can't be over max (2^256 - 1).
|
||||
if (balances[msg.sender] >= _value && balances[_to] + _value >= balances[_to]) {
|
||||
balances[msg.sender] -= _value;
|
||||
balances[_to] += _value;
|
||||
Transfer(msg.sender, _to, _value);
|
||||
return true;
|
||||
} else { return false; }
|
||||
}
|
||||
|
||||
function transferFrom(address _from, address _to, uint _value) returns (bool) {
|
||||
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value >= balances[_to]) {
|
||||
balances[_to] += _value;
|
||||
balances[_from] -= _value;
|
||||
allowed[_from][msg.sender] -= _value;
|
||||
Transfer(_from, _to, _value);
|
||||
return true;
|
||||
} else { return false; }
|
||||
}
|
||||
|
||||
function balanceOf(address _owner) constant returns (uint) {
|
||||
return balances[_owner];
|
||||
}
|
||||
|
||||
function approve(address _spender, uint _value) returns (bool) {
|
||||
allowed[msg.sender][_spender] = _value;
|
||||
Approval(msg.sender, _spender, _value);
|
||||
return true;
|
||||
}
|
||||
|
||||
function allowance(address _owner, address _spender) constant returns (uint) {
|
||||
return allowed[_owner][_spender];
|
||||
}
|
||||
|
||||
mapping (address => uint) balances;
|
||||
mapping (address => mapping (address => uint)) allowed;
|
||||
uint public totalSupply;
|
||||
}
|
38
packages/contracts/contracts/base/Token.sol
Normal file
38
packages/contracts/contracts/base/Token.sol
Normal file
@@ -0,0 +1,38 @@
|
||||
pragma solidity 0.4.11;
|
||||
|
||||
contract Token {
|
||||
|
||||
/// @return total amount of tokens
|
||||
function totalSupply() constant returns (uint supply) {}
|
||||
|
||||
/// @param _owner The address from which the balance will be retrieved
|
||||
/// @return The balance
|
||||
function balanceOf(address _owner) constant returns (uint balance) {}
|
||||
|
||||
/// @notice send `_value` token to `_to` from `msg.sender`
|
||||
/// @param _to The address of the recipient
|
||||
/// @param _value The amount of token to be transferred
|
||||
/// @return Whether the transfer was successful or not
|
||||
function transfer(address _to, uint _value) returns (bool success) {}
|
||||
|
||||
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
|
||||
/// @param _from The address of the sender
|
||||
/// @param _to The address of the recipient
|
||||
/// @param _value The amount of token to be transferred
|
||||
/// @return Whether the transfer was successful or not
|
||||
function transferFrom(address _from, address _to, uint _value) returns (bool success) {}
|
||||
|
||||
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
|
||||
/// @param _spender The address of the account able to transfer the tokens
|
||||
/// @param _value The amount of wei to be approved for transfer
|
||||
/// @return Whether the approval was successful or not
|
||||
function approve(address _spender, uint _value) returns (bool success) {}
|
||||
|
||||
/// @param _owner The address of the account owning tokens
|
||||
/// @param _spender The address of the account able to transfer the tokens
|
||||
/// @return Amount of remaining tokens allowed to spent
|
||||
function allowance(address _owner, address _spender) constant returns (uint remaining) {}
|
||||
|
||||
event Transfer(address indexed _from, address indexed _to, uint _value);
|
||||
event Approval(address indexed _owner, address indexed _spender, uint _value);
|
||||
}
|
33
packages/contracts/contracts/test/DummyToken.sol
Normal file
33
packages/contracts/contracts/test/DummyToken.sol
Normal file
@@ -0,0 +1,33 @@
|
||||
pragma solidity 0.4.11;
|
||||
|
||||
import "./Mintable.sol";
|
||||
import "./../base/Ownable.sol";
|
||||
|
||||
contract DummyToken is Mintable, Ownable {
|
||||
string public name;
|
||||
string public symbol;
|
||||
uint public decimals;
|
||||
|
||||
function DummyToken(
|
||||
string _name,
|
||||
string _symbol,
|
||||
uint _decimals,
|
||||
uint _totalSupply)
|
||||
{
|
||||
name = _name;
|
||||
symbol = _symbol;
|
||||
decimals = _decimals;
|
||||
totalSupply = _totalSupply;
|
||||
balances[msg.sender] = _totalSupply;
|
||||
}
|
||||
|
||||
function setBalance(address _target, uint _value) onlyOwner {
|
||||
uint currBalance = balanceOf(_target);
|
||||
if (_value < currBalance) {
|
||||
totalSupply = safeSub(totalSupply, safeSub(currBalance, _value));
|
||||
} else {
|
||||
totalSupply = safeAdd(totalSupply, safeSub(_value, currBalance));
|
||||
}
|
||||
balances[_target] = _value;
|
||||
}
|
||||
}
|
29
packages/contracts/contracts/test/MaliciousToken.sol
Normal file
29
packages/contracts/contracts/test/MaliciousToken.sol
Normal file
@@ -0,0 +1,29 @@
|
||||
pragma solidity 0.4.11;
|
||||
|
||||
import "./../base/StandardToken.sol";
|
||||
|
||||
contract MaliciousToken is StandardToken {
|
||||
uint8 stateToUpdate = 1; // Not null so that change only requires 5000 gas
|
||||
|
||||
function updateState() internal {
|
||||
stateToUpdate++;
|
||||
}
|
||||
|
||||
function balanceOf(address _owner)
|
||||
public
|
||||
constant
|
||||
returns (uint)
|
||||
{
|
||||
updateState();
|
||||
return balances[_owner];
|
||||
}
|
||||
|
||||
function allowance(address _owner, address _spender)
|
||||
public
|
||||
constant
|
||||
returns (uint)
|
||||
{
|
||||
updateState();
|
||||
return allowed[_owner][_spender];
|
||||
}
|
||||
}
|
16
packages/contracts/contracts/test/Mintable.sol
Normal file
16
packages/contracts/contracts/test/Mintable.sol
Normal file
@@ -0,0 +1,16 @@
|
||||
pragma solidity 0.4.11;
|
||||
|
||||
import "./../tokens/UnlimitedAllowanceToken.sol";
|
||||
import "./../base/SafeMath.sol";
|
||||
|
||||
/*
|
||||
* Mintable
|
||||
* Base contract that creates a mintable UnlimitedAllowanceToken
|
||||
*/
|
||||
contract Mintable is UnlimitedAllowanceToken, SafeMath {
|
||||
function mint(uint _value) {
|
||||
require(_value <= 100000000000000000000);
|
||||
balances[msg.sender] = safeAdd(_value, balances[msg.sender]);
|
||||
totalSupply = safeAdd(totalSupply, _value);
|
||||
}
|
||||
}
|
56
packages/contracts/contracts/tokens/EtherToken.sol
Normal file
56
packages/contracts/contracts/tokens/EtherToken.sol
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
|
||||
Copyright 2017 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.4.11;
|
||||
|
||||
import "./UnlimitedAllowanceToken.sol";
|
||||
import "./../base/SafeMath.sol";
|
||||
|
||||
contract EtherToken is UnlimitedAllowanceToken, SafeMath {
|
||||
|
||||
string constant public name = "Ether Token";
|
||||
string constant public symbol = "WETH";
|
||||
uint8 constant public decimals = 18;
|
||||
|
||||
/// @dev Fallback to calling deposit when ether is sent directly to contract.
|
||||
function()
|
||||
public
|
||||
payable
|
||||
{
|
||||
deposit();
|
||||
}
|
||||
|
||||
/// @dev Buys tokens with Ether, exchanging them 1:1.
|
||||
function deposit()
|
||||
public
|
||||
payable
|
||||
{
|
||||
balances[msg.sender] = safeAdd(balances[msg.sender], msg.value);
|
||||
totalSupply = safeAdd(totalSupply, msg.value);
|
||||
}
|
||||
|
||||
/// @dev Sells tokens in exchange for Ether, exchanging them 1:1.
|
||||
/// @param amount Number of tokens to sell.
|
||||
function withdraw(uint amount)
|
||||
public
|
||||
{
|
||||
balances[msg.sender] = safeSub(balances[msg.sender], amount);
|
||||
totalSupply = safeSub(totalSupply, amount);
|
||||
require(msg.sender.send(amount));
|
||||
}
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
|
||||
Copyright 2017 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.4.11;
|
||||
|
||||
import "./../base/StandardToken.sol";
|
||||
|
||||
contract UnlimitedAllowanceToken is StandardToken {
|
||||
|
||||
uint constant MAX_UINT = 2**256 - 1;
|
||||
|
||||
/// @dev ERC20 transferFrom, modified such that an allowance of MAX_UINT represents an unlimited allowance.
|
||||
/// @param _from Address to transfer from.
|
||||
/// @param _to Address to transfer to.
|
||||
/// @param _value Amount to transfer.
|
||||
/// @return Success of transfer.
|
||||
function transferFrom(address _from, address _to, uint _value)
|
||||
public
|
||||
returns (bool)
|
||||
{
|
||||
uint allowance = allowed[_from][msg.sender];
|
||||
if (balances[_from] >= _value
|
||||
&& allowance >= _value
|
||||
&& balances[_to] + _value >= balances[_to]
|
||||
) {
|
||||
balances[_to] += _value;
|
||||
balances[_from] -= _value;
|
||||
if (allowance < MAX_UINT) {
|
||||
allowed[_from][msg.sender] -= _value;
|
||||
}
|
||||
Transfer(_from, _to, _value);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
33
packages/contracts/contracts/tokens/ZRXToken.sol
Normal file
33
packages/contracts/contracts/tokens/ZRXToken.sol
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
|
||||
Copyright 2017 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.4.11;
|
||||
|
||||
import "./UnlimitedAllowanceToken.sol";
|
||||
|
||||
contract ZRXToken is UnlimitedAllowanceToken {
|
||||
|
||||
uint8 constant public decimals = 18;
|
||||
uint public totalSupply = 10**27; // 1 billion tokens, 18 decimal places
|
||||
string constant public name = "0x Protocol Token";
|
||||
string constant public symbol = "ZRX";
|
||||
|
||||
function ZRXToken() {
|
||||
balances[msg.sender] = totalSupply;
|
||||
}
|
||||
}
|
165
packages/contracts/deploy/cli.ts
Normal file
165
packages/contracts/deploy/cli.ts
Normal file
@@ -0,0 +1,165 @@
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import {BigNumber} from 'bignumber.js';
|
||||
import * as _ from 'lodash';
|
||||
import * as path from 'path';
|
||||
import * as Web3 from 'web3';
|
||||
import * as yargs from 'yargs';
|
||||
|
||||
import {commands} from './src/commands';
|
||||
import {
|
||||
CliOptions,
|
||||
CompilerOptions,
|
||||
DeployerOptions,
|
||||
} from './src/utils/types';
|
||||
|
||||
const DEFAULT_OPTIMIZER_ENABLED = false;
|
||||
const DEFAULT_CONTRACTS_DIR = path.resolve('contracts');
|
||||
const DEFAULT_ARTIFACTS_DIR = `${path.resolve('build')}/artifacts/`;
|
||||
const DEFAULT_NETWORK_ID = 50;
|
||||
const DEFAULT_JSONRPC_PORT = 8545;
|
||||
const DEFAULT_GAS_PRICE = ((10 ** 9) * 2).toString();
|
||||
|
||||
/**
|
||||
* Compiles all contracts with options passed in through CLI.
|
||||
* @param argv Instance of process.argv provided by yargs.
|
||||
*/
|
||||
async function onCompileCommand(args: CliOptions): Promise<void> {
|
||||
const opts: CompilerOptions = {
|
||||
contractsDir: args.contractsDir,
|
||||
networkId: args.networkId,
|
||||
optimizerEnabled: args.shouldOptimize ? 1 : 0,
|
||||
artifactsDir: args.artifactsDir,
|
||||
};
|
||||
await commands.compileAsync(opts);
|
||||
}
|
||||
/**
|
||||
* Compiles all contracts and runs migration script with options passed in through CLI.
|
||||
* Uses network ID of running node.
|
||||
* @param argv Instance of process.argv provided by yargs.
|
||||
*/
|
||||
async function onMigrateCommand(argv: CliOptions): Promise<void> {
|
||||
const url = `http://localhost:${argv.jsonrpcPort}`;
|
||||
const web3Provider = new Web3.providers.HttpProvider(url);
|
||||
const web3Wrapper = new Web3Wrapper(web3Provider);
|
||||
const networkId = await web3Wrapper.getNetworkIdAsync();
|
||||
const compilerOpts: CompilerOptions = {
|
||||
contractsDir: argv.contractsDir,
|
||||
networkId,
|
||||
optimizerEnabled: argv.shouldOptimize ? 1 : 0,
|
||||
artifactsDir: argv.artifactsDir,
|
||||
};
|
||||
await commands.compileAsync(compilerOpts);
|
||||
|
||||
const defaults = {
|
||||
gasPrice: new BigNumber(argv.gasPrice),
|
||||
from: argv.account,
|
||||
};
|
||||
const deployerOpts = {
|
||||
artifactsDir: argv.artifactsDir,
|
||||
jsonrpcPort: argv.jsonrpcPort,
|
||||
networkId,
|
||||
defaults,
|
||||
};
|
||||
await commands.migrateAsync(deployerOpts);
|
||||
}
|
||||
/**
|
||||
* Deploys a single contract with provided name and args.
|
||||
* @param argv Instance of process.argv provided by yargs.
|
||||
*/
|
||||
async function onDeployCommand(argv: CliOptions): Promise<void> {
|
||||
const url = `http://localhost:${argv.jsonrpcPort}`;
|
||||
const web3Provider = new Web3.providers.HttpProvider(url);
|
||||
const web3Wrapper = new Web3Wrapper(web3Provider);
|
||||
const networkId = await web3Wrapper.getNetworkIdAsync();
|
||||
const compilerOpts: CompilerOptions = {
|
||||
contractsDir: argv.contractsDir,
|
||||
networkId,
|
||||
optimizerEnabled: argv.shouldOptimize ? 1 : 0,
|
||||
artifactsDir: argv.artifactsDir,
|
||||
};
|
||||
await commands.compileAsync(compilerOpts);
|
||||
|
||||
const defaults = {
|
||||
gasPrice: new BigNumber(argv.gasPrice),
|
||||
from: argv.account,
|
||||
};
|
||||
const deployerOpts: DeployerOptions = {
|
||||
artifactsDir: argv.artifactsDir,
|
||||
jsonrpcPort: argv.jsonrpcPort,
|
||||
networkId,
|
||||
defaults,
|
||||
};
|
||||
const deployerArgsString = argv.args;
|
||||
const deployerArgs = deployerArgsString.split(',');
|
||||
await commands.deployAsync(argv.contract, deployerArgs, deployerOpts);
|
||||
}
|
||||
/**
|
||||
* Provides extra required options for deploy command.
|
||||
* @param yargsInstance yargs instance provided in builder function callback.
|
||||
*/
|
||||
function deployCommandBuilder(yargsInstance: any) {
|
||||
return yargsInstance
|
||||
.option('contract', {
|
||||
type: 'string',
|
||||
description: 'name of contract to deploy, exluding .sol extension',
|
||||
})
|
||||
.option('args', {
|
||||
type: 'string',
|
||||
description: 'comma separated list of constructor args to deploy contract with',
|
||||
})
|
||||
.demandOption(['contract', 'args'])
|
||||
.help()
|
||||
.argv;
|
||||
}
|
||||
|
||||
(() => {
|
||||
return yargs
|
||||
.option('contracts-dir', {
|
||||
type: 'string',
|
||||
default: DEFAULT_CONTRACTS_DIR,
|
||||
description: 'path of contracts directory to compile',
|
||||
})
|
||||
.option('network-id', {
|
||||
type: 'number',
|
||||
default: DEFAULT_NETWORK_ID,
|
||||
description: 'mainnet=1, kovan=42, testrpc=50',
|
||||
})
|
||||
.option('should-optimize', {
|
||||
type: 'boolean',
|
||||
default: DEFAULT_OPTIMIZER_ENABLED,
|
||||
description: 'enable optimizer',
|
||||
})
|
||||
.option('artifacts-dir', {
|
||||
type: 'string',
|
||||
default: DEFAULT_ARTIFACTS_DIR,
|
||||
description: 'path to write contracts artifacts to',
|
||||
})
|
||||
.option('jsonrpc-port', {
|
||||
type: 'number',
|
||||
default: DEFAULT_JSONRPC_PORT,
|
||||
description: 'port connected to JSON RPC',
|
||||
})
|
||||
.option('gas-price', {
|
||||
type: 'string',
|
||||
default: DEFAULT_GAS_PRICE,
|
||||
description: 'gasPrice to be used for transactions',
|
||||
})
|
||||
.option('account', {
|
||||
type: 'string',
|
||||
description: 'account to use for deploying contracts',
|
||||
})
|
||||
.command('compile',
|
||||
'compile contracts',
|
||||
_.noop,
|
||||
onCompileCommand)
|
||||
.command('migrate',
|
||||
'compile and deploy contracts using migration scripts',
|
||||
_.noop,
|
||||
onMigrateCommand)
|
||||
.command('deploy',
|
||||
'deploy a single contract with provided arguments',
|
||||
deployCommandBuilder,
|
||||
onDeployCommand)
|
||||
.help()
|
||||
.argv;
|
||||
})();
|
40
packages/contracts/deploy/migrations/config/token_info.ts
Normal file
40
packages/contracts/deploy/migrations/config/token_info.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import {constants} from './../../src/utils/constants';
|
||||
import {Token} from './../../src/utils/types';
|
||||
|
||||
export const tokenInfo: Token[] = [
|
||||
{
|
||||
name: 'Augur Reputation Token',
|
||||
symbol: 'REP',
|
||||
decimals: 18,
|
||||
ipfsHash: constants.NULL_BYTES,
|
||||
swarmHash: constants.NULL_BYTES,
|
||||
},
|
||||
{
|
||||
name: 'Digix DAO Token',
|
||||
symbol: 'DGD',
|
||||
decimals: 18,
|
||||
ipfsHash: constants.NULL_BYTES,
|
||||
swarmHash: constants.NULL_BYTES,
|
||||
},
|
||||
{
|
||||
name: 'Golem Network Token',
|
||||
symbol: 'GNT',
|
||||
decimals: 18,
|
||||
ipfsHash: constants.NULL_BYTES,
|
||||
swarmHash: constants.NULL_BYTES,
|
||||
},
|
||||
{
|
||||
name: 'MakerDAO',
|
||||
symbol: 'MKR',
|
||||
decimals: 18,
|
||||
ipfsHash: constants.NULL_BYTES,
|
||||
swarmHash: constants.NULL_BYTES,
|
||||
},
|
||||
{
|
||||
name: 'Melon Token',
|
||||
symbol: 'MLN',
|
||||
decimals: 18,
|
||||
ipfsHash: constants.NULL_BYTES,
|
||||
swarmHash: constants.NULL_BYTES,
|
||||
},
|
||||
];
|
106
packages/contracts/deploy/migrations/migrate.ts
Normal file
106
packages/contracts/deploy/migrations/migrate.ts
Normal file
@@ -0,0 +1,106 @@
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import {BigNumber} from 'bignumber.js';
|
||||
import * as _ from 'lodash';
|
||||
import * as Web3 from 'web3';
|
||||
|
||||
import {Deployer} from './../src/deployer';
|
||||
import {constants} from './../src/utils/constants';
|
||||
import {Token} from './../src/utils/types';
|
||||
import {tokenInfo} from './config/token_info';
|
||||
|
||||
export const migrator = {
|
||||
/**
|
||||
* Custom migrations should be defined in this function. This will be called with the CLI 'migrate' command.
|
||||
* @param deployer Deployer instance.
|
||||
*/
|
||||
async runMigrationsAsync(deployer: Deployer): Promise<void> {
|
||||
const web3Wrapper: Web3Wrapper = deployer.web3Wrapper;
|
||||
const accounts: string[] = await web3Wrapper.getAvailableAddressesAsync();
|
||||
|
||||
const independentContracts: Web3.ContractInstance[] = await Promise.all([
|
||||
deployer.deployAndSaveAsync('TokenTransferProxy'),
|
||||
deployer.deployAndSaveAsync('ZRXToken'),
|
||||
deployer.deployAndSaveAsync('EtherToken'),
|
||||
deployer.deployAndSaveAsync('TokenRegistry'),
|
||||
]);
|
||||
const [tokenTransferProxy, zrxToken, etherToken, tokenReg] = independentContracts;
|
||||
|
||||
const exchangeArgs = [zrxToken.address, tokenTransferProxy.address];
|
||||
const owners = [accounts[0], accounts[1]];
|
||||
const confirmationsRequired = new BigNumber(2);
|
||||
const secondsRequired = new BigNumber(0);
|
||||
const multiSigArgs = [owners, confirmationsRequired, secondsRequired, tokenTransferProxy.address];
|
||||
const dependentContracts: Web3.ContractInstance[] = await Promise.all([
|
||||
deployer.deployAndSaveAsync('Exchange', exchangeArgs),
|
||||
deployer.deployAndSaveAsync('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', multiSigArgs),
|
||||
]);
|
||||
const [exchange, multiSig] = dependentContracts;
|
||||
|
||||
const owner = accounts[0];
|
||||
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, {from: owner});
|
||||
await tokenTransferProxy.transferOwnership.sendTransactionAsync(multiSig.address, {from: owner});
|
||||
|
||||
const tokensToRegister: Web3.ContractInstance[] = await Promise.all(
|
||||
_.map(tokenInfo, async (token: Token): Promise<Web3.ContractInstance> => {
|
||||
const totalSupply = new BigNumber(0);
|
||||
const args = [
|
||||
token.name,
|
||||
token.symbol,
|
||||
token.decimals,
|
||||
totalSupply,
|
||||
];
|
||||
return deployer.deployAsync('DummyToken', args);
|
||||
}),
|
||||
);
|
||||
const addTokenGasEstimate = await tokenReg.addToken.estimateGasAsync(
|
||||
tokensToRegister[0].address,
|
||||
tokenInfo[0].name,
|
||||
tokenInfo[0].symbol,
|
||||
tokenInfo[0].decimals,
|
||||
tokenInfo[0].ipfsHash,
|
||||
tokenInfo[0].swarmHash,
|
||||
{from: owner},
|
||||
);
|
||||
const addTokenPromises = [
|
||||
tokenReg.addToken.sendTransactionAsync(
|
||||
zrxToken.address,
|
||||
'0x Protocol Token',
|
||||
'ZRX',
|
||||
18,
|
||||
constants.NULL_BYTES,
|
||||
constants.NULL_BYTES,
|
||||
{
|
||||
from: owner,
|
||||
gas: addTokenGasEstimate,
|
||||
},
|
||||
),
|
||||
tokenReg.addToken.sendTransactionAsync(
|
||||
etherToken.address,
|
||||
'Ether Token',
|
||||
'WETH',
|
||||
18,
|
||||
constants.NULL_BYTES,
|
||||
constants.NULL_BYTES,
|
||||
{
|
||||
from: owner,
|
||||
gas: addTokenGasEstimate,
|
||||
},
|
||||
),
|
||||
];
|
||||
const addDummyTokenPromises = _.map(tokenInfo, async (token: Token, i: number): Promise<void> => {
|
||||
return tokenReg.addToken.sendTransactionAsync(
|
||||
tokensToRegister[i].address,
|
||||
token.name,
|
||||
token.symbol,
|
||||
token.decimals,
|
||||
token.ipfsHash,
|
||||
token.swarmHash,
|
||||
{
|
||||
from: owner,
|
||||
gas: addTokenGasEstimate,
|
||||
},
|
||||
);
|
||||
});
|
||||
await Promise.all([...addDummyTokenPromises, ...addTokenPromises]);
|
||||
},
|
||||
};
|
15
packages/contracts/deploy/solc/bin_paths.ts
Normal file
15
packages/contracts/deploy/solc/bin_paths.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
interface BinaryPaths {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
export const binPaths: BinaryPaths = {
|
||||
'0.4.10': 'soljson-v0.4.10+commit.f0d539ae.js',
|
||||
'0.4.11': 'soljson-v0.4.11+commit.68ef5810.js',
|
||||
'0.4.12': 'soljson-v0.4.12+commit.194ff033.js',
|
||||
'0.4.13': 'soljson-v0.4.13+commit.fb4cb1a.js',
|
||||
'0.4.14': 'soljson-v0.4.14+commit.c2215d46.js',
|
||||
'0.4.15': 'soljson-v0.4.15+commit.bbb8e64f.js',
|
||||
'0.4.16': 'soljson-v0.4.16+commit.d7661dd9.js',
|
||||
'0.4.17': 'soljson-v0.4.17+commit.bdeb9e52.js',
|
||||
'0.4.18': 'soljson-v0.4.18+commit.9cf6e910.js',
|
||||
};
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user