Merge pull request #258 from 0xProject/feature/contracts-refactor
A bunch of refactorings
This commit is contained in:
@@ -5,7 +5,7 @@ jobs:
|
||||
docker:
|
||||
- image: circleci/node:6.12
|
||||
environment:
|
||||
CONTRACTS_COMMIT_HASH: '78fe8dd'
|
||||
CONTRACTS_COMMIT_HASH: '6bda6a2'
|
||||
steps:
|
||||
- checkout
|
||||
- run: echo 'export PATH=$HOME/CIRCLE_PROJECT_REPONAME/node_modules/.bin:$PATH' >> $BASH_ENV
|
||||
|
||||
@@ -2,13 +2,11 @@
|
||||
* 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 {TxData, TxDataPayable} from '@0xproject/types';
|
||||
import {classUtils, 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 {
|
||||
@@ -12,11 +12,11 @@
|
||||
"main": "lib/src/index.js",
|
||||
"types": "lib/src/index.d.ts",
|
||||
"scripts": {
|
||||
"prebuild": "npm run clean",
|
||||
"prebuild": "run-s clean generate_contract_wrappers",
|
||||
"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",
|
||||
"generate_contract_wrappers": "node ../abi-gen/lib/index.js --abiGlob 'src/artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry|DummyToken).json' --templates contract_templates --output src/contract_wrappers/generated",
|
||||
"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",
|
||||
@@ -31,7 +31,7 @@
|
||||
"test:commonjs": "run-s build:commonjs run_mocha",
|
||||
"pretest:umd": "run-s clean build:umd:dev build:commonjs",
|
||||
"substitute_umd_bundle": "shx mv _bundles/* lib/src",
|
||||
"run_mocha": "mocha lib/test/**/*_test.js --timeout 5000 --bail --exit"
|
||||
"run_mocha": "mocha lib/test/**/*_test.js --timeout 10000 --bail --exit"
|
||||
},
|
||||
"config": {
|
||||
"artifacts": "TokenTransferProxy Exchange TokenRegistry Token EtherToken"
|
||||
@@ -48,6 +48,7 @@
|
||||
"@0xproject/abi-gen": "^0.0.2",
|
||||
"@0xproject/tslint-config": "^0.2.1",
|
||||
"@0xproject/types": "^0.1.0",
|
||||
"@0xproject/dev-utils": "^0.0.1",
|
||||
"@types/bintrees": "^1.0.2",
|
||||
"@types/jsonschema": "^1.1.1",
|
||||
"@types/lodash": "^4.14.86",
|
||||
@@ -55,7 +56,6 @@
|
||||
"@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",
|
||||
@@ -78,8 +78,6 @@
|
||||
"truffle-hdwallet-provider": "^0.0.3",
|
||||
"tslint": "5.8.0",
|
||||
"typedoc": "~0.8.0",
|
||||
"types-bn": "^0.0.1",
|
||||
"types-ethereumjs-util": "0xProject/types-ethereumjs-util",
|
||||
"typescript": "~2.6.1",
|
||||
"web3-provider-engine": "^13.0.1",
|
||||
"web3-typescript-typings": "^0.7.2",
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import {schemas, SchemaValidator} from '@0xproject/json-schemas';
|
||||
import {bigNumberConfigs, intervalUtils} from '@0xproject/utils';
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as ethUtil from 'ethereumjs-util';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import {artifacts} from './artifacts';
|
||||
import {bigNumberConfigs} from './bignumber_config';
|
||||
import {EtherTokenWrapper} from './contract_wrappers/ether_token_wrapper';
|
||||
import {ExchangeWrapper} from './contract_wrappers/exchange_wrapper';
|
||||
import {TokenRegistryWrapper} from './contract_wrappers/token_registry_wrapper';
|
||||
@@ -26,7 +26,6 @@ import {
|
||||
import {AbiDecoder} from './utils/abi_decoder';
|
||||
import {assert} from './utils/assert';
|
||||
import {constants} from './utils/constants';
|
||||
import {intervalUtils} from './utils/interval_utils';
|
||||
import {OrderStateUtils} from './utils/order_state_utils';
|
||||
import {signatureUtils} from './utils/signature_utils';
|
||||
import {utils} from './utils/utils';
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import * as DummyTokenArtifact from './artifacts/DummyToken.json';
|
||||
import * as EtherTokenArtifact from './artifacts/EtherToken.json';
|
||||
import * as ExchangeArtifact from './artifacts/Exchange.json';
|
||||
import * as TokenArtifact from './artifacts/Token.json';
|
||||
@@ -8,6 +9,7 @@ import {Artifact} from './types';
|
||||
|
||||
export const artifacts = {
|
||||
ZRXArtifact: ZRXArtifact as any as Artifact,
|
||||
DummyTokenArtifact: DummyTokenArtifact as any as Artifact,
|
||||
TokenArtifact: TokenArtifact as any as Artifact,
|
||||
ExchangeArtifact: ExchangeArtifact as any as Artifact,
|
||||
EtherTokenArtifact: EtherTokenArtifact as any as Artifact,
|
||||
|
||||
23
packages/0x.js/src/artifacts/DummyToken.json
Normal file
23
packages/0x.js/src/artifacts/DummyToken.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"contract_name": "DummyToken",
|
||||
"abi":
|
||||
[
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_target",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "_value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "setBalance",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"type": "function"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -244,7 +244,7 @@
|
||||
"address": "0x05d090b51c40b020eab3bfcb6a2dff130df22e9c"
|
||||
},
|
||||
"50": {
|
||||
"address": "0x48bacb9266a570d521063ef5dd96e61686dbe788"
|
||||
"address": "0x871dd7c2b4b25e1aa18728e9d5f2af4c4e431f5c"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -601,7 +601,7 @@
|
||||
"address": "0x90fe2af704b34e0224bf2299c838e04d4dcf1364"
|
||||
},
|
||||
"50": {
|
||||
"address": "0xb69e673309512a9d726f87304c6984054f87a93b"
|
||||
"address": "0x48bacb9266a570d521063ef5dd96e61686dbe788"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@
|
||||
"address": "0x087eed4bc1ee3de49befbd66c662b434b15d49d4"
|
||||
},
|
||||
"50": {
|
||||
"address": "0x871dd7c2b4b25e1aa18728e9d5f2af4c4e431f5c"
|
||||
"address": "0x1dc4c1cefef38a777b15aa20260a54e584b16c48"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"address": "0x6ff6c0ff1d68b964901f986d4c9fa3ac68346570"
|
||||
},
|
||||
"50": {
|
||||
"address": "0x25b8fe1de9daf8ba351890744ff28cf7dfa8f5e3"
|
||||
"address": "0x1d7022f5b17d2f8b695918fb48fa1089c9f85401"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {intervalUtils} from '@0xproject/utils';
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import {Block, BlockAndLogStreamer} from 'ethereumjs-blockstream';
|
||||
import * as _ from 'lodash';
|
||||
@@ -19,7 +20,6 @@ import {
|
||||
import {AbiDecoder} from '../utils/abi_decoder';
|
||||
import {constants} from '../utils/constants';
|
||||
import {filterUtils} from '../utils/filter_utils';
|
||||
import {intervalUtils} from '../utils/interval_utils';
|
||||
|
||||
const CONTRACT_NAME_TO_NOT_FOUND_ERROR: {[contractName: string]: ZeroExError} = {
|
||||
ZRX: ZeroExError.ZRXContractDoesNotExist,
|
||||
|
||||
6
packages/0x.js/src/contract_wrappers/generated/.gitignore
vendored
Normal file
6
packages/0x.js/src/contract_wrappers/generated/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
dummy_token.ts
|
||||
ether_token.ts
|
||||
exchange.ts
|
||||
token_registry.ts
|
||||
token_transfer_proxy.ts
|
||||
token.ts
|
||||
@@ -1,8 +1,7 @@
|
||||
import {TxData, TxDataPayable} from '@0xproject/types';
|
||||
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>;
|
||||
|
||||
@@ -1,363 +0,0 @@
|
||||
/**
|
||||
* 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
|
||||
@@ -1,730 +0,0 @@
|
||||
/**
|
||||
* 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
|
||||
@@ -1,232 +0,0 @@
|
||||
/**
|
||||
* 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
|
||||
@@ -1,550 +0,0 @@
|
||||
/**
|
||||
* 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
|
||||
@@ -1,285 +0,0 @@
|
||||
/**
|
||||
* 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
|
||||
@@ -27,7 +27,6 @@ export {
|
||||
ContractEventArg,
|
||||
Web3Provider,
|
||||
ZeroExConfig,
|
||||
TransactionReceipt,
|
||||
TransactionReceiptWithDecodedLogs,
|
||||
LogWithDecodedArgs,
|
||||
MethodOpts,
|
||||
@@ -42,3 +41,7 @@ export {
|
||||
OrderStateInvalid,
|
||||
OrderState,
|
||||
} from './types';
|
||||
|
||||
export {
|
||||
TransactionReceipt,
|
||||
} from '@0xproject/types';
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {intervalUtils} from '@0xproject/utils';
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import * as _ from 'lodash';
|
||||
import * as Web3 from 'web3';
|
||||
@@ -10,7 +11,6 @@ import {
|
||||
} from '../types';
|
||||
import {AbiDecoder} from '../utils/abi_decoder';
|
||||
import {assert} from '../utils/assert';
|
||||
import {intervalUtils} from '../utils/interval_utils';
|
||||
import {utils} from '../utils/utils';
|
||||
|
||||
const DEFAULT_EVENT_POLLING_INTERVAL_MS = 200;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import {intervalUtils} from '@0xproject/utils';
|
||||
import {BigNumber} from 'bignumber.js';
|
||||
import {RBTree} from 'bintrees';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import {ZeroEx} from '../0x';
|
||||
import {SignedOrder, ZeroExError} from '../types';
|
||||
import {intervalUtils} from '../utils/interval_utils';
|
||||
import {utils} from '../utils/utils';
|
||||
|
||||
const DEFAULT_EXPIRATION_MARGIN_MS = 0;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {schemas} from '@0xproject/json-schemas';
|
||||
import {intervalUtils} from '@0xproject/utils';
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
@@ -29,7 +30,6 @@ import {
|
||||
} from '../types';
|
||||
import {AbiDecoder} from '../utils/abi_decoder';
|
||||
import {assert} from '../utils/assert';
|
||||
import {intervalUtils} from '../utils/interval_utils';
|
||||
import {OrderStateUtils} from '../utils/order_state_utils';
|
||||
import {utils} from '../utils/utils';
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {TransactionReceipt} from '@0xproject/types';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as Web3 from 'web3';
|
||||
|
||||
@@ -385,28 +386,4 @@ export interface OrderStateInvalid {
|
||||
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;
|
||||
transactionHash: string;
|
||||
transactionIndex: number;
|
||||
from: string;
|
||||
to: string;
|
||||
status: null|0|1;
|
||||
cumulativeGasUsed: number;
|
||||
gasUsed: number;
|
||||
contractAddress: string|null;
|
||||
logs: Web3.LogEntry[];
|
||||
} // tslint:disable:max-file-line-count
|
||||
// tslint:disable:max-file-line-count
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {BlockchainLifecycle} from '@0xproject/dev-utils';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
import * as _ from 'lodash';
|
||||
@@ -6,13 +7,12 @@ import * as Sinon from 'sinon';
|
||||
|
||||
import {ApprovalContractEventArgs, LogWithDecodedArgs, Order, TokenEvents, ZeroEx, ZeroExError} from '../src';
|
||||
|
||||
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
import {constants} from './utils/constants';
|
||||
import {TokenUtils} from './utils/token_utils';
|
||||
import {web3Factory} from './utils/web3_factory';
|
||||
|
||||
const blockchainLifecycle = new BlockchainLifecycle();
|
||||
const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL);
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {BlockchainLifecycle} from '@0xproject/dev-utils';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
import 'mocha';
|
||||
@@ -5,14 +6,13 @@ import * as Web3 from 'web3';
|
||||
|
||||
import {ZeroEx, ZeroExError} from '../src';
|
||||
|
||||
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
import {constants} from './utils/constants';
|
||||
import {web3Factory} from './utils/web3_factory';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle();
|
||||
const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL);
|
||||
|
||||
// Since the address depositing/withdrawing ETH/WETH also needs to pay gas costs for the transaction,
|
||||
// a small amount of ETH will be used to pay this gas cost. We therefore check that the difference between
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {BlockchainLifecycle} from '@0xproject/dev-utils';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
|
||||
@@ -5,14 +6,13 @@ import {ExchangeContractErrs, Token, ZeroEx} from '../src';
|
||||
import {BlockParamLiteral, TradeSide, TransferType} from '../src/types';
|
||||
import {ExchangeTransferSimulator} from '../src/utils/exchange_transfer_simulator';
|
||||
|
||||
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
import {constants} from './utils/constants';
|
||||
import {web3Factory} from './utils/web3_factory';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle();
|
||||
const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL);
|
||||
|
||||
describe('ExchangeTransferSimulator', () => {
|
||||
const web3 = web3Factory.create();
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {BlockchainLifecycle} from '@0xproject/dev-utils';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
import 'mocha';
|
||||
@@ -19,7 +20,6 @@ import {
|
||||
} from '../src';
|
||||
import {BlockParamLiteral, DoneCallback} from '../src/types';
|
||||
|
||||
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
import {constants} from './utils/constants';
|
||||
import {FillScenarios} from './utils/fill_scenarios';
|
||||
@@ -28,7 +28,7 @@ import {web3Factory} from './utils/web3_factory';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle();
|
||||
const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL);
|
||||
|
||||
const NON_EXISTENT_ORDER_HASH = '0x79370342234e7acd6bbeac335bd3bb1d368383294b64b8160a00f4060e4d3777';
|
||||
|
||||
@@ -53,6 +53,7 @@ describe('ExchangeWrapper', () => {
|
||||
tokenUtils = new TokenUtils(tokens);
|
||||
zrxTokenAddress = tokenUtils.getProtocolTokenOrThrow().address;
|
||||
fillScenarios = new FillScenarios(zeroEx, userAddresses, tokens, zrxTokenAddress, exchangeContractAddress);
|
||||
await fillScenarios.initTokenBalancesAsync();
|
||||
});
|
||||
beforeEach(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
@@ -71,7 +72,7 @@ describe('ExchangeWrapper', () => {
|
||||
before(async () => {
|
||||
[coinbase, makerAddress, takerAddress, feeRecipient] = userAddresses;
|
||||
tokens = await zeroEx.tokenRegistry.getTokensAsync();
|
||||
const [makerToken, takerToken] = tokenUtils.getNonProtocolTokens();
|
||||
const [makerToken, takerToken] = tokenUtils.getDummyTokens();
|
||||
makerTokenAddress = makerToken.address;
|
||||
takerTokenAddress = takerToken.address;
|
||||
});
|
||||
@@ -201,7 +202,7 @@ describe('ExchangeWrapper', () => {
|
||||
before(async () => {
|
||||
[coinbase, makerAddress, takerAddress, feeRecipient] = userAddresses;
|
||||
tokens = await zeroEx.tokenRegistry.getTokensAsync();
|
||||
const [makerToken, takerToken] = tokenUtils.getNonProtocolTokens();
|
||||
const [makerToken, takerToken] = tokenUtils.getDummyTokens();
|
||||
makerTokenAddress = makerToken.address;
|
||||
takerTokenAddress = takerToken.address;
|
||||
});
|
||||
@@ -436,7 +437,7 @@ describe('ExchangeWrapper', () => {
|
||||
const cancelAmount = new BigNumber(3);
|
||||
beforeEach(async () => {
|
||||
[coinbase, makerAddress, takerAddress] = userAddresses;
|
||||
const [makerToken, takerToken] = tokenUtils.getNonProtocolTokens();
|
||||
const [makerToken, takerToken] = tokenUtils.getDummyTokens();
|
||||
makerTokenAddress = makerToken.address;
|
||||
takerTokenAddress = takerToken.address;
|
||||
signedOrder = await fillScenarios.createFillableSignedOrderAsync(
|
||||
@@ -557,7 +558,8 @@ describe('ExchangeWrapper', () => {
|
||||
let orderHash: string;
|
||||
before(() => {
|
||||
takerAddress = userAddresses[1];
|
||||
const [makerToken, takerToken] = tokens;
|
||||
tokenUtils = new TokenUtils(tokens);
|
||||
const [makerToken, takerToken] = tokenUtils.getDummyTokens();
|
||||
makerTokenAddress = makerToken.address;
|
||||
takerTokenAddress = takerToken.address;
|
||||
});
|
||||
@@ -633,7 +635,7 @@ describe('ExchangeWrapper', () => {
|
||||
const cancelTakerAmountInBaseUnits = new BigNumber(1);
|
||||
before(() => {
|
||||
[coinbase, makerAddress, takerAddress] = userAddresses;
|
||||
const [makerToken, takerToken] = tokens;
|
||||
const [makerToken, takerToken] = tokenUtils.getDummyTokens();
|
||||
makerTokenAddress = makerToken.address;
|
||||
takerTokenAddress = takerToken.address;
|
||||
});
|
||||
@@ -731,7 +733,7 @@ describe('ExchangeWrapper', () => {
|
||||
const fillableAmount = new BigNumber(5);
|
||||
before(async () => {
|
||||
[, makerAddress, takerAddress] = userAddresses;
|
||||
const [makerToken, takerToken] = tokenUtils.getNonProtocolTokens();
|
||||
const [makerToken, takerToken] = tokenUtils.getDummyTokens();
|
||||
makerTokenAddress = makerToken.address;
|
||||
takerTokenAddress = takerToken.address;
|
||||
});
|
||||
@@ -766,7 +768,7 @@ describe('ExchangeWrapper', () => {
|
||||
let txHash: string;
|
||||
before(async () => {
|
||||
[, makerAddress, takerAddress] = userAddresses;
|
||||
const [makerToken, takerToken] = tokenUtils.getNonProtocolTokens();
|
||||
const [makerToken, takerToken] = tokenUtils.getDummyTokens();
|
||||
makerTokenAddress = makerToken.address;
|
||||
takerTokenAddress = takerToken.address;
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {BlockchainLifecycle} from '@0xproject/dev-utils';
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
@@ -12,8 +13,8 @@ import {DoneCallback, Token} from '../src/types';
|
||||
import {constants} from '../src/utils/constants';
|
||||
import {utils} from '../src/utils/utils';
|
||||
|
||||
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
import {constants as testConstants} from './utils/constants';
|
||||
import {FillScenarios} from './utils/fill_scenarios';
|
||||
import {reportCallbackErrors} from './utils/report_callback_errors';
|
||||
import {TokenUtils} from './utils/token_utils';
|
||||
@@ -21,7 +22,7 @@ import {web3Factory} from './utils/web3_factory';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle();
|
||||
const blockchainLifecycle = new BlockchainLifecycle(testConstants.RPC_URL);
|
||||
|
||||
describe('ExpirationWatcher', () => {
|
||||
let web3: Web3;
|
||||
@@ -56,7 +57,7 @@ describe('ExpirationWatcher', () => {
|
||||
fillScenarios = new FillScenarios(zeroEx, userAddresses, tokens, zrxTokenAddress, exchangeContractAddress);
|
||||
[coinbase, makerAddress, takerAddress, feeRecipient] = userAddresses;
|
||||
tokens = await zeroEx.tokenRegistry.getTokensAsync();
|
||||
const [makerToken, takerToken] = tokenUtils.getNonProtocolTokens();
|
||||
const [makerToken, takerToken] = tokenUtils.getDummyTokens();
|
||||
makerTokenAddress = makerToken.address;
|
||||
takerTokenAddress = takerToken.address;
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {BlockchainLifecycle} from '@0xproject/dev-utils';
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
@@ -21,7 +22,6 @@ import {
|
||||
import {OrderStateWatcher} from '../src/order_watcher/order_state_watcher';
|
||||
import {DoneCallback} from '../src/types';
|
||||
|
||||
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
import {constants} from './utils/constants';
|
||||
import {FillScenarios} from './utils/fill_scenarios';
|
||||
@@ -33,7 +33,7 @@ const TIMEOUT_MS = 150;
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle();
|
||||
const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL);
|
||||
|
||||
describe('OrderStateWatcher', () => {
|
||||
let web3: Web3;
|
||||
@@ -65,7 +65,8 @@ describe('OrderStateWatcher', () => {
|
||||
tokenUtils = new TokenUtils(tokens);
|
||||
zrxTokenAddress = tokenUtils.getProtocolTokenOrThrow().address;
|
||||
fillScenarios = new FillScenarios(zeroEx, userAddresses, tokens, zrxTokenAddress, exchangeContractAddress);
|
||||
[makerToken, takerToken] = tokenUtils.getNonProtocolTokens();
|
||||
await fillScenarios.initTokenBalancesAsync();
|
||||
[makerToken, takerToken] = tokenUtils.getDummyTokens();
|
||||
web3Wrapper = (zeroEx as any)._web3Wrapper;
|
||||
});
|
||||
beforeEach(async () => {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {BlockchainLifecycle} from '@0xproject/dev-utils';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
import * as Sinon from 'sinon';
|
||||
@@ -8,7 +9,6 @@ import {BlockParamLiteral, TradeSide, TransferType} from '../src/types';
|
||||
import {ExchangeTransferSimulator} from '../src/utils/exchange_transfer_simulator';
|
||||
import {OrderValidationUtils} from '../src/utils/order_validation_utils';
|
||||
|
||||
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
import {constants} from './utils/constants';
|
||||
import {FillScenarios} from './utils/fill_scenarios';
|
||||
@@ -17,7 +17,7 @@ import {web3Factory} from './utils/web3_factory';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle();
|
||||
const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL);
|
||||
|
||||
describe('OrderValidation', () => {
|
||||
let web3: Web3;
|
||||
@@ -50,7 +50,7 @@ describe('OrderValidation', () => {
|
||||
tokenUtils = new TokenUtils(tokens);
|
||||
zrxTokenAddress = tokenUtils.getProtocolTokenOrThrow().address;
|
||||
fillScenarios = new FillScenarios(zeroEx, userAddresses, tokens, zrxTokenAddress, exchangeContractAddress);
|
||||
const [makerToken, takerToken] = tokenUtils.getNonProtocolTokens();
|
||||
const [makerToken, takerToken] = tokenUtils.getDummyTokens();
|
||||
makerTokenAddress = makerToken.address;
|
||||
takerTokenAddress = takerToken.address;
|
||||
orderValidationUtils = new OrderValidationUtils(zeroEx.token, zeroEx.exchange);
|
||||
@@ -185,7 +185,7 @@ describe('OrderValidation', () => {
|
||||
const cancelAmount = new BigNumber(3);
|
||||
beforeEach(async () => {
|
||||
[coinbase, makerAddress, takerAddress] = userAddresses;
|
||||
const [makerToken, takerToken] = tokenUtils.getNonProtocolTokens();
|
||||
const [makerToken, takerToken] = tokenUtils.getDummyTokens();
|
||||
makerTokenAddress = makerToken.address;
|
||||
takerTokenAddress = takerToken.address;
|
||||
signedOrder = await fillScenarios.createFillableSignedOrderAsync(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {BlockchainLifecycle} from '@0xproject/dev-utils';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
import * as _ from 'lodash';
|
||||
@@ -15,7 +16,6 @@ import {
|
||||
} from '../src';
|
||||
import {BlockParamLiteral, DoneCallback} from '../src/types';
|
||||
|
||||
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
import {constants} from './utils/constants';
|
||||
import {reportCallbackErrors} from './utils/report_callback_errors';
|
||||
@@ -24,7 +24,7 @@ import {web3Factory} from './utils/web3_factory';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle();
|
||||
const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL);
|
||||
|
||||
describe('SubscriptionTest', () => {
|
||||
let web3: Web3;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {BlockchainLifecycle} from '@0xproject/dev-utils';
|
||||
import {schemas, SchemaValidator} from '@0xproject/json-schemas';
|
||||
import * as chai from 'chai';
|
||||
import * as _ from 'lodash';
|
||||
@@ -5,14 +6,13 @@ import 'mocha';
|
||||
|
||||
import {Token, ZeroEx} from '../src';
|
||||
|
||||
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
import {constants} from './utils/constants';
|
||||
import {web3Factory} from './utils/web3_factory';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle();
|
||||
const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL);
|
||||
|
||||
const TOKEN_REGISTRY_SIZE_AFTER_MIGRATION = 7;
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {BlockchainLifecycle} from '@0xproject/dev-utils';
|
||||
import {promisify} from '@0xproject/utils';
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import BigNumber from 'bignumber.js';
|
||||
@@ -21,7 +22,6 @@ import {
|
||||
} from '../src';
|
||||
import {BlockParamLiteral, DoneCallback} from '../src/types';
|
||||
|
||||
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
import {constants} from './utils/constants';
|
||||
import {TokenUtils} from './utils/token_utils';
|
||||
@@ -29,7 +29,7 @@ import {web3Factory} from './utils/web3_factory';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle();
|
||||
const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL);
|
||||
|
||||
describe('TokenWrapper', () => {
|
||||
let web3: Web3;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
export const constants = {
|
||||
NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
|
||||
RPC_HOST: 'localhost',
|
||||
RPC_PORT: 8545,
|
||||
RPC_URL: 'http://localhost:8545',
|
||||
ROPSTEN_NETWORK_ID: 3,
|
||||
KOVAN_NETWORK_ID: 42,
|
||||
TESTRPC_NETWORK_ID: 50,
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import BigNumber from 'bignumber.js';
|
||||
|
||||
import {SignedOrder, Token, ZeroEx} from '../../src';
|
||||
import {artifacts} from '../../src/artifacts';
|
||||
import {DummyTokenContract} from '../../src/contract_wrappers/generated/dummy_token';
|
||||
import {orderFactory} from '../utils/order_factory';
|
||||
|
||||
import {constants} from './constants';
|
||||
|
||||
const INITIAL_COINBASE_TOKEN_SUPPLY_IN_UNITS = new BigNumber(100);
|
||||
|
||||
export class FillScenarios {
|
||||
private zeroEx: ZeroEx;
|
||||
private userAddresses: string[];
|
||||
@@ -21,6 +26,23 @@ export class FillScenarios {
|
||||
this.zrxTokenAddress = zrxTokenAddress;
|
||||
this.exchangeContractAddress = exchangeContractAddress;
|
||||
}
|
||||
public async initTokenBalancesAsync() {
|
||||
const web3Wrapper = (this.zeroEx as any)._web3Wrapper as Web3Wrapper;
|
||||
for (const token of this.tokens) {
|
||||
if (token.symbol !== 'ZRX' && token.symbol !== 'WETH') {
|
||||
const contractInstance = web3Wrapper.getContractInstance(
|
||||
artifacts.DummyTokenArtifact.abi, token.address,
|
||||
);
|
||||
const defaults = {};
|
||||
const dummyToken = new DummyTokenContract(contractInstance, defaults);
|
||||
const tokenSupply = ZeroEx.toBaseUnitAmount(INITIAL_COINBASE_TOKEN_SUPPLY_IN_UNITS, token.decimals);
|
||||
const txHash = await dummyToken.setBalance.sendTransactionAsync(this.coinbase, tokenSupply, {
|
||||
from: this.coinbase,
|
||||
});
|
||||
await this.zeroEx.awaitTransactionMinedAsync(txHash);
|
||||
}
|
||||
}
|
||||
}
|
||||
public async createFillableSignedOrderAsync(makerTokenAddress: string, takerTokenAddress: string,
|
||||
makerAddress: string, takerAddress: string,
|
||||
fillableAmount: BigNumber,
|
||||
|
||||
@@ -3,6 +3,7 @@ import * as _ from 'lodash';
|
||||
import {InternalZeroExError, Token} from '../../src/types';
|
||||
|
||||
const PROTOCOL_TOKEN_SYMBOL = 'ZRX';
|
||||
const WETH_TOKEN_SYMBOL = 'WETH';
|
||||
|
||||
export class TokenUtils {
|
||||
private tokens: Token[];
|
||||
@@ -16,10 +17,10 @@ export class TokenUtils {
|
||||
}
|
||||
return zrxToken;
|
||||
}
|
||||
public getNonProtocolTokens(): Token[] {
|
||||
const nonProtocolTokens = _.filter(this.tokens, token => {
|
||||
return token.symbol !== PROTOCOL_TOKEN_SYMBOL;
|
||||
public getDummyTokens(): Token[] {
|
||||
const dummyTokens = _.filter(this.tokens, token => {
|
||||
return !_.includes([PROTOCOL_TOKEN_SYMBOL, WETH_TOKEN_SYMBOL], token.symbol);
|
||||
});
|
||||
return nonProtocolTokens;
|
||||
return dummyTokens;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,13 +21,12 @@ export const web3Factory = {
|
||||
},
|
||||
getRpcProvider(hasAddresses: boolean = true): Web3.Provider {
|
||||
const provider = new ProviderEngine();
|
||||
const rpcUrl = `http://${constants.RPC_HOST}:${constants.RPC_PORT}`;
|
||||
if (!hasAddresses) {
|
||||
provider.addProvider(new EmptyWalletSubprovider());
|
||||
}
|
||||
provider.addProvider(new FakeGasEstimateSubprovider(constants.GAS_ESTIMATE));
|
||||
provider.addProvider(new RpcSubprovider({
|
||||
rpcUrl,
|
||||
rpcUrl: constants.RPC_URL,
|
||||
}));
|
||||
provider.start();
|
||||
return provider;
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
@@ -5,7 +5,7 @@ It's heavily inspired by [Geth abigen](https://github.com/ethereum/go-ethereum/w
|
||||
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.
|
||||
[Here](https://github.com/0xProject/0x.js/tree/development/packages/0x.js/src/contract_templates) are the templates used to generate those files.
|
||||
|
||||
## Instalation
|
||||
`yarn add -g @0xproject/abi-gen`
|
||||
@@ -29,7 +29,7 @@ We could've just used `--abiGlob 'src/artifacts/*.json` but we wanted to exclude
|
||||
|
||||
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.
|
||||
The best way to get started is to copy [0x.js templates](https://github.com/0xProject/0x.js/tree/development/packages/0x.js/src/contract_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?
|
||||
|
||||
@@ -11,49 +11,34 @@ 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.
|
||||
* Some operations might be completed in parallel, but we don't do that on purpose.
|
||||
* That way the addresses are deterministic.
|
||||
* @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 tokenTransferProxy = await deployer.deployAndSaveAsync('TokenTransferProxy');
|
||||
const zrxToken = await deployer.deployAndSaveAsync('ZRXToken');
|
||||
const etherToken = await deployer.deployAndSaveAsync('EtherToken');
|
||||
const tokenReg = await deployer.deployAndSaveAsync('TokenRegistry');
|
||||
|
||||
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 exchange = await deployer.deployAndSaveAsync('Exchange', exchangeArgs);
|
||||
const multiSig = await deployer.deployAndSaveAsync(
|
||||
'MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', multiSigArgs,
|
||||
);
|
||||
|
||||
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,
|
||||
zrxToken.address,
|
||||
tokenInfo[0].name,
|
||||
tokenInfo[0].symbol,
|
||||
tokenInfo[0].decimals,
|
||||
@@ -61,35 +46,41 @@ export const migrator = {
|
||||
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,
|
||||
await tokenReg.addToken.sendTransactionAsync(
|
||||
zrxToken.address,
|
||||
'0x Protocol Token',
|
||||
'ZRX',
|
||||
18,
|
||||
constants.NULL_BYTES,
|
||||
constants.NULL_BYTES,
|
||||
{
|
||||
from: owner,
|
||||
gas: addTokenGasEstimate,
|
||||
},
|
||||
);
|
||||
await tokenReg.addToken.sendTransactionAsync(
|
||||
etherToken.address,
|
||||
'Ether Token',
|
||||
'WETH',
|
||||
18,
|
||||
constants.NULL_BYTES,
|
||||
constants.NULL_BYTES,
|
||||
{
|
||||
from: owner,
|
||||
gas: addTokenGasEstimate,
|
||||
},
|
||||
);
|
||||
for (const token of tokenInfo) {
|
||||
const totalSupply = new BigNumber(0);
|
||||
const args = [
|
||||
token.name,
|
||||
token.symbol,
|
||||
token.decimals,
|
||||
totalSupply,
|
||||
];
|
||||
const dummyToken = await deployer.deployAsync('DummyToken', args);
|
||||
await tokenReg.addToken.sendTransactionAsync(
|
||||
dummyToken.address,
|
||||
token.name,
|
||||
token.symbol,
|
||||
token.decimals,
|
||||
@@ -100,7 +91,6 @@ export const migrator = {
|
||||
gas: addTokenGasEstimate,
|
||||
},
|
||||
);
|
||||
});
|
||||
await Promise.all([...addDummyTokenPromises, ...addTokenPromises]);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x.js/packages/contracts/README.md",
|
||||
"devDependencies": {
|
||||
"@0xproject/dev-utils": "^0.0.1",
|
||||
"@0xproject/tslint-config": "^0.2.1",
|
||||
"@0xproject/types": "^0.1.0",
|
||||
"@types/bluebird": "^3.5.3",
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import {RPC} from '@0xproject/dev-utils';
|
||||
import {promisify} from '@0xproject/utils';
|
||||
import {BigNumber} from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
import Web3 = require('web3');
|
||||
|
||||
import * as multiSigWalletJSON from '../../build/contracts/MultiSigWalletWithTimeLock.json';
|
||||
import * as truffleConf from '../../truffle.js';
|
||||
import {Artifacts} from '../../util/artifacts';
|
||||
import {constants} from '../../util/constants';
|
||||
import {MultiSigWrapper} from '../../util/multi_sig_wrapper';
|
||||
import {RPC} from '../../util/rpc';
|
||||
import {ContractInstance} from '../../util/types';
|
||||
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
@@ -38,7 +39,8 @@ contract('MultiSigWalletWithTimeLock', (accounts: string[]) => {
|
||||
|
||||
const secondsTimeLocked = await multiSig.secondsTimeLocked.call();
|
||||
initialSecondsTimeLocked = secondsTimeLocked.toNumber();
|
||||
rpc = new RPC();
|
||||
const rpcUrl = `http://${truffleConf.networks.development.host}:${truffleConf.networks.development.port}`;
|
||||
rpc = new RPC(rpcUrl);
|
||||
});
|
||||
|
||||
describe('changeTimeLock', () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {bigNumberConfigs} from '@0xproject/utils';
|
||||
import {BigNumber} from 'bignumber.js';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import {bigNumberConfigs} from './bignumber_config';
|
||||
import {BalancesByOwner, ContractInstance} from './types';
|
||||
|
||||
bigNumberConfigs.configure();
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import {BigNumber} from 'bignumber.js';
|
||||
|
||||
export const bigNumberConfigs = {
|
||||
configure() {
|
||||
// By default BigNumber's `toString` method converts to exponential notation if the value has
|
||||
// more then 20 digits. We want to avoid this behavior, so we set EXPONENTIAL_AT to a high number
|
||||
BigNumber.config({
|
||||
EXPONENTIAL_AT: 1000,
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -1,43 +0,0 @@
|
||||
import 'isomorphic-fetch';
|
||||
|
||||
import * as truffleConf from '../truffle.js';
|
||||
|
||||
export class RPC {
|
||||
private host: string;
|
||||
private port: number;
|
||||
private id: number;
|
||||
constructor() {
|
||||
this.host = truffleConf.networks.development.host;
|
||||
this.port = truffleConf.networks.development.port;
|
||||
this.id = 0;
|
||||
}
|
||||
public async increaseTimeAsync(time: number) {
|
||||
const method = 'evm_increaseTime';
|
||||
const params = [time];
|
||||
const payload = this.toPayload(method, params);
|
||||
return this.sendAsync(payload);
|
||||
}
|
||||
public async mineBlockAsync() {
|
||||
const method = 'evm_mine';
|
||||
const payload = this.toPayload(method);
|
||||
return this.sendAsync(payload);
|
||||
}
|
||||
private toPayload(method: string, params: any[] = []) {
|
||||
const payload = JSON.stringify({
|
||||
id: this.id,
|
||||
method,
|
||||
params,
|
||||
});
|
||||
this.id++;
|
||||
return payload;
|
||||
}
|
||||
private async sendAsync(payload: string): Promise<any> {
|
||||
const opts = {
|
||||
method: 'POST',
|
||||
body: payload,
|
||||
};
|
||||
const response = await fetch(`http://${this.host}:${this.port}`, opts);
|
||||
const responsePayload = await response.json();
|
||||
return responsePayload;
|
||||
}
|
||||
}
|
||||
10
packages/dev-utils/README.md
Normal file
10
packages/dev-utils/README.md
Normal file
@@ -0,0 +1,10 @@
|
||||
Dev utils
|
||||
------
|
||||
|
||||
Dev utils to be shared across 0x projects and packages
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
yarn add @0xproject/dev-utils
|
||||
```
|
||||
37
packages/dev-utils/package.json
Normal file
37
packages/dev-utils/package.json
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "@0xproject/dev-utils",
|
||||
"version": "0.0.1",
|
||||
"description": "0x dev TS utils",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"clean": "shx rm -rf lib",
|
||||
"lint": "tslint --project . 'src/**/*.ts'"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/0xProject/0x.js.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/0xProject/0x.js/issues"
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x.js/packages/dev-utils/README.md",
|
||||
"devDependencies": {
|
||||
"@0xproject/tslint-config": "^0.2.0",
|
||||
"@types/lodash": "^4.14.86",
|
||||
"npm-run-all": "^4.1.2",
|
||||
"shx": "^0.2.2",
|
||||
"tslint": "5.8.0",
|
||||
"typescript": "~2.6.1",
|
||||
"types-bn": "^0.0.1",
|
||||
"types-ethereumjs-util": "0xProject/types-ethereumjs-util"
|
||||
},
|
||||
"dependencies": {
|
||||
"bignumber.js": "~4.1.0",
|
||||
"ethereumjs-util": "^5.1.2",
|
||||
"lodash": "^4.17.4",
|
||||
"request-promise-native": "^1.0.5"
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,8 @@ import {RPC} from './rpc';
|
||||
export class BlockchainLifecycle {
|
||||
private rpc: RPC;
|
||||
private snapshotIdsStack: number[];
|
||||
constructor() {
|
||||
this.rpc = new RPC();
|
||||
constructor(url: string) {
|
||||
this.rpc = new RPC(url);
|
||||
this.snapshotIdsStack = [];
|
||||
}
|
||||
// TODO: In order to run these tests on an actual node, we should check if we are running against
|
||||
2
packages/dev-utils/src/index.ts
Normal file
2
packages/dev-utils/src/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export {RPC} from './rpc';
|
||||
export {BlockchainLifecycle} from './blockchain_lifecycle';
|
||||
@@ -1,15 +1,12 @@
|
||||
import * as ethUtil from 'ethereumjs-util';
|
||||
import * as request from 'request-promise-native';
|
||||
|
||||
import {constants} from './constants';
|
||||
|
||||
export class RPC {
|
||||
private host: string;
|
||||
private url: string;
|
||||
private port: number;
|
||||
private id: number;
|
||||
constructor() {
|
||||
this.host = constants.RPC_HOST;
|
||||
this.port = constants.RPC_PORT;
|
||||
constructor(url: string) {
|
||||
this.url = url;
|
||||
this.id = 0;
|
||||
}
|
||||
public async takeSnapshotAsync(): Promise<number> {
|
||||
@@ -27,6 +24,12 @@ export class RPC {
|
||||
const didRevert = await this.sendAsync(payload);
|
||||
return didRevert;
|
||||
}
|
||||
public async increaseTimeAsync(time: number) {
|
||||
const method = 'evm_increaseTime';
|
||||
const params = [time];
|
||||
const payload = this.toPayload(method, params);
|
||||
return this.sendAsync(payload);
|
||||
}
|
||||
public async mineBlockAsync(): Promise<void> {
|
||||
const method = 'evm_mine';
|
||||
const params: any[] = [];
|
||||
@@ -45,7 +48,7 @@ export class RPC {
|
||||
private async sendAsync(payload: string): Promise<any> {
|
||||
const opts = {
|
||||
method: 'POST',
|
||||
uri: `http://${this.host}:${this.port}`,
|
||||
uri: this.url,
|
||||
body: payload,
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
17
packages/dev-utils/tsconfig.json
Normal file
17
packages/dev-utils/tsconfig.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"lib": [ "es2017", "dom"],
|
||||
"outDir": "lib",
|
||||
"sourceMap": true,
|
||||
"declaration": true,
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true
|
||||
},
|
||||
"include": [
|
||||
"./src/**/*",
|
||||
"../../node_modules/types-bn/index.d.ts",
|
||||
"../../node_modules/types-ethereumjs-util/index.d.ts"
|
||||
]
|
||||
}
|
||||
5
packages/dev-utils/tslint.json
Normal file
5
packages/dev-utils/tslint.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"extends": [
|
||||
"@0xproject/tslint-config"
|
||||
]
|
||||
}
|
||||
2
packages/kovan-faucets/src/ts/global.d.ts
vendored
2
packages/kovan-faucets/src/ts/global.d.ts
vendored
@@ -19,7 +19,7 @@ declare module 'ethereumjs-tx' {
|
||||
public s: Buffer;
|
||||
public v: Buffer;
|
||||
public serialize(): Buffer;
|
||||
public sign(buffer: Buffer): void;
|
||||
public sign(buffer: Buffer): void;
|
||||
constructor(txParams: any);
|
||||
}
|
||||
export = EthereumTx;
|
||||
|
||||
@@ -8,6 +8,10 @@ export interface TxData {
|
||||
nonce?: number;
|
||||
}
|
||||
|
||||
export interface TxDataPayable extends TxData {
|
||||
value?: BigNumber;
|
||||
}
|
||||
|
||||
export interface TransactionReceipt {
|
||||
blockHash: string;
|
||||
blockNumber: number;
|
||||
|
||||
@@ -1,2 +1,5 @@
|
||||
export {promisify} from './promisify';
|
||||
export {addressUtils} from './address_utils';
|
||||
export {classUtils} from './class_utils';
|
||||
export {intervalUtils} from './interval_utils';
|
||||
export {bigNumberConfigs} from './bignumber_config';
|
||||
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
LedgerWalletSubprovider,
|
||||
RedundantRPCSubprovider,
|
||||
} from '@0xproject/subproviders';
|
||||
import {promisify} from '@0xproject/utils';
|
||||
import {intervalUtils, promisify} from '@0xproject/utils';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import compareVersions = require('compare-versions');
|
||||
import ethUtil = require('ethereumjs-util');
|
||||
@@ -75,7 +75,7 @@ export class Blockchain {
|
||||
private userAddress: string;
|
||||
private cachedProvider: Web3.Provider;
|
||||
private ledgerSubprovider: LedgerWalletSubprovider;
|
||||
private zrxPollIntervalId: number;
|
||||
private zrxPollIntervalId: NodeJS.Timer;
|
||||
private static async onPageLoadAsync() {
|
||||
if (document.readyState === 'complete') {
|
||||
return; // Already loaded
|
||||
@@ -359,7 +359,7 @@ export class Blockchain {
|
||||
|
||||
const [currBalance] = await this.getTokenBalanceAndAllowanceAsync(this.userAddress, token.address);
|
||||
|
||||
this.zrxPollIntervalId = window.setInterval(async () => {
|
||||
this.zrxPollIntervalId = intervalUtils.setAsyncExcludingInterval(async () => {
|
||||
const [balance] = await this.getTokenBalanceAndAllowanceAsync(this.userAddress, token.address);
|
||||
if (!balance.eq(currBalance)) {
|
||||
this.dispatcher.replaceTokenBalanceByAddress(token.address, balance);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {promisify} from '@0xproject/utils';
|
||||
import {intervalUtils, promisify} from '@0xproject/utils';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as _ from 'lodash';
|
||||
import {Dispatcher} from 'ts/redux/dispatcher';
|
||||
@@ -9,7 +9,7 @@ export class Web3Wrapper {
|
||||
private web3: Web3;
|
||||
private prevNetworkId: number;
|
||||
private shouldPollUserAddress: boolean;
|
||||
private watchNetworkAndBalanceIntervalId: number;
|
||||
private watchNetworkAndBalanceIntervalId: NodeJS.Timer;
|
||||
private prevUserEtherBalanceInEth: BigNumber;
|
||||
private prevUserAddress: string;
|
||||
constructor(dispatcher: Dispatcher, provider: Web3.Provider, networkIdIfExists: number,
|
||||
@@ -98,7 +98,7 @@ export class Web3Wrapper {
|
||||
let prevNodeVersion: string;
|
||||
this.prevUserEtherBalanceInEth = new BigNumber(0);
|
||||
this.dispatcher.updateNetworkId(this.prevNetworkId);
|
||||
this.watchNetworkAndBalanceIntervalId = window.setInterval(async () => {
|
||||
this.watchNetworkAndBalanceIntervalId = intervalUtils.setAsyncExcludingInterval(async () => {
|
||||
// Check for network state changes
|
||||
const currentNetworkId = await this.getNetworkIdIfExists();
|
||||
if (currentNetworkId !== this.prevNetworkId) {
|
||||
|
||||
@@ -3132,7 +3132,7 @@ ethereumjs-util@4.5.0, ethereumjs-util@^4.0.0, ethereumjs-util@^4.0.1, ethereumj
|
||||
rlp "^2.0.0"
|
||||
secp256k1 "^3.0.1"
|
||||
|
||||
ethereumjs-util@^5.0.0, ethereumjs-util@^5.0.1, ethereumjs-util@^5.1.1:
|
||||
ethereumjs-util@^5.0.0, ethereumjs-util@^5.0.1, ethereumjs-util@^5.1.1, ethereumjs-util@^5.1.2:
|
||||
version "5.1.2"
|
||||
resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-5.1.2.tgz#25ba0215cbb4c2f0b108a6f96af2a2e62e45921f"
|
||||
dependencies:
|
||||
@@ -7608,7 +7608,7 @@ request-promise-core@1.1.1:
|
||||
dependencies:
|
||||
lodash "^4.13.1"
|
||||
|
||||
request-promise-native@^1.0.4:
|
||||
request-promise-native@^1.0.4, request-promise-native@^1.0.5:
|
||||
version "1.0.5"
|
||||
resolved "https://registry.yarnpkg.com/request-promise-native/-/request-promise-native-1.0.5.tgz#5281770f68e0c9719e5163fd3fab482215f4fda5"
|
||||
dependencies:
|
||||
|
||||
Reference in New Issue
Block a user