diff options
Diffstat (limited to 'packages')
-rw-r--r-- | packages/0x.js/package.json | 18 | ||||
-rw-r--r-- | packages/0x.js/src/0x.ts | 82 | ||||
-rw-r--r-- | packages/0x.js/src/artifacts.ts | 7 | ||||
-rw-r--r-- | packages/0x.js/src/index.ts | 52 | ||||
-rw-r--r-- | packages/0x.js/src/schemas/zero_ex_private_network_config_schema.ts | 6 | ||||
-rw-r--r-- | packages/0x.js/src/schemas/zero_ex_public_network_config_schema.ts | 3 | ||||
-rw-r--r-- | packages/0x.js/test/0x.js_test.ts | 68 | ||||
-rw-r--r-- | packages/0x.js/test/global_hooks.ts | 6 | ||||
-rw-r--r-- | packages/0x.js/test/utils/token_utils.ts | 40 | ||||
-rw-r--r-- | packages/0x.js/test/utils/web3_wrapper.ts | 10 | ||||
-rw-r--r-- | packages/contract-wrappers/src/index.ts | 3 | ||||
-rw-r--r-- | packages/contract-wrappers/src/schemas/contract_wrappers_private_network_config_schema.ts | 6 | ||||
-rw-r--r-- | packages/contract-wrappers/src/schemas/contract_wrappers_public_network_config_schema.ts | 2 |
13 files changed, 159 insertions, 144 deletions
diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 3e6e03182..d77f31a69 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -18,9 +18,10 @@ "watch_without_deps": "yarn pre_build && tsc -w", "build": "yarn pre_build && yarn build:all && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", "build:all": "run-p build:umd:prod build:commonjs; exit 0;", - "pre_build": "run-s generate_contract_wrappers copy_artifacts", - "copy_artifacts": "copyfiles -u 2 './src/compact_artifacts/**/*.json' ./lib/src/compact_artifacts", - "generate_contract_wrappers": "abi-gen --abis 'src/compact_artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry|DummyToken).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/generated_contract_wrappers --backend ethers", + "pre_build": "run-s update_artifacts generate_contract_wrappers", + "copy_artifacts": "copyfiles -u 2 './src/artifacts/**/*.json' ./lib/src/artifacts", + "update_artifacts": "for i in ${npm_package_config_contracts}; do copyfiles -u 4 ../migrations/artifacts/2.0.0/$i.json src/artifacts; done;", + "generate_contract_wrappers": "abi-gen --abis 'src/artifacts/@(ZRXToken).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/generated_contract_wrappers --backend ethers", "lint": "tslint --project . --exclude **/src/generated_contract_wrappers/**/*", "test:circleci": "run-s test:coverage", "test": "yarn run_mocha", @@ -29,7 +30,7 @@ "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info", "clean": "shx rm -rf _bundles lib test_temp scripts src/generated_contract_wrappers", "build:umd:prod": "NODE_ENV=production webpack", - "build:commonjs": "tsc && copyfiles -u 2 './src/compact_artifacts/**/*.json' ./lib/src/compact_artifacts && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", + "build:commonjs": "tsc && yarn copy_artifacts && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", "run_mocha": "mocha --require source-map-support/register --require make-promises-safe lib/test/**/*_test.js lib/test/global_hooks.js --timeout 10000 --bail --exit", "manual:postpublish": "yarn build; node ./scripts/postpublish.js", "docs:stage": "node scripts/stage_docs.js", @@ -37,7 +38,7 @@ "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" }, "config": { - "compact_artifacts": "Exchange DummyToken ZRXToken Token EtherToken TokenTransferProxy TokenRegistry", + "contracts": "ZRXToken", "postpublish": { "assets": [ "packages/0x.js/_bundles/index.js", @@ -101,13 +102,14 @@ "dependencies": { "@0xproject/assert": "^0.2.13", "@0xproject/base-contract": "^0.3.5", - "@0xproject/contract-wrappers": "^0.0.5", - "@0xproject/order-utils": "^0.0.8", + "@0xproject/contract-wrappers": "^0.1.0", + "@0xproject/order-utils": "^1.0.0", "@0xproject/sol-compiler": "^0.5.3", - "@0xproject/types": "^0.8.2", + "@0xproject/types": "^1.0.0", "@0xproject/typescript-typings": "^0.4.2", "@0xproject/utils": "^0.7.2", "@0xproject/web3-wrapper": "^0.7.2", + "ethereum-types": "^0.0.2", "ethers": "3.0.22", "lodash": "^4.17.4" }, diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index c6315ac7a..597bc07a5 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -4,19 +4,22 @@ import { ContractWrappersConfig, ERC20ProxyWrapper, ERC20TokenWrapper, + ERC721ProxyWrapper, + ERC721TokenWrapper, EtherTokenWrapper, ExchangeWrapper, } from '@0xproject/contract-wrappers'; import { + ecSignOrderHashAsync, generatePseudoRandomSalt, - getOrderHashHex, - isValidOrderHash, - isValidSignature, - signOrderHashAsync, + isValidSignatureAsync, + MessagePrefixOpts, + orderHashUtils, } from '@0xproject/order-utils'; -import { ECSignature, Order, Provider, SignedOrder, TransactionReceiptWithDecodedLogs } from '@0xproject/types'; +import { ECSignature, Order, SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import { Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; import { constants } from './utils/constants'; @@ -36,21 +39,28 @@ export class ZeroEx { */ public exchange: ExchangeWrapper; /** + * An instance of the ERC20TokenWrapper class containing methods for interacting with any ERC20 token smart contract. */ + public erc20Token: ERC20TokenWrapper; /** - * An instance of the TokenWrapper class containing methods for interacting with any ERC20 token smart contract. + * An instance of the ERC721TokenWrapper class containing methods for interacting with any ERC721 token smart contract. */ - public token: TokenWrapper; + public erc721Token: ERC721TokenWrapper; /** * An instance of the EtherTokenWrapper class containing methods for interacting with the * wrapped ETH ERC20 token smart contract. */ public etherToken: EtherTokenWrapper; /** - * An instance of the TokenTransferProxyWrapper class containing methods for interacting with the - * tokenTransferProxy smart contract. + * An instance of the ERC20ProxyWrapper class containing methods for interacting with the + * ERC20 proxy smart contract. */ - public proxy: TokenTransferProxyWrapper; + public erc20Proxy: ERC20ProxyWrapper; + /** + * An instance of the ERC721ProxyWrapper class containing methods for interacting with the + * ERC721 proxy smart contract. + */ + public erc721Proxy: ERC721ProxyWrapper; private _contractWrappers: ContractWrappers; /** * Generates a pseudo-random 256-bit salt. @@ -62,23 +72,12 @@ export class ZeroEx { return generatePseudoRandomSalt(); } /** - * Verifies that the elliptic curve signature `signature` was generated - * by signing `data` with the private key corresponding to the `signerAddress` address. - * @param data The hex encoded data signed by the supplied signature. - * @param signature An object containing the elliptic curve signature parameters. - * @param signerAddress The hex encoded address that signed the data, producing the supplied signature. - * @return Whether the signature is valid for the supplied signerAddress and data. - */ - public static isValidSignature(data: string, signature: ECSignature, signerAddress: string): boolean { - return isValidSignature(data, signature, signerAddress); - } - /** * Computes the orderHash for a supplied order. * @param order An object that conforms to the Order or SignedOrder interface definitions. * @return The resulting orderHash from hashing the supplied order. */ public static getOrderHashHex(order: Order | SignedOrder): string { - return getOrderHashHex(order); + return orderHashUtils.getOrderHashHex(order); } /** * Checks if the supplied hex encoded order hash is valid. @@ -88,7 +87,7 @@ export class ZeroEx { * @return Whether the supplied orderHash has the expected format. */ public static isValidOrderHash(orderHash: string): boolean { - return isValidOrderHash(orderHash); + return orderHashUtils.isValidOrderHash(orderHash); } /** * A unit amount is defined as the amount of a token above the specified decimal places (integer part). @@ -129,12 +128,31 @@ export class ZeroEx { assert.isWeb3Provider('provider', provider); this._contractWrappers = new ContractWrappers(provider, config); - this.proxy = this._contractWrappers.proxy; - this.token = this._contractWrappers.token; + this.erc20Proxy = this._contractWrappers.erc20Proxy; + this.erc721Proxy = this._contractWrappers.erc721Proxy; + this.erc20Token = this._contractWrappers.erc20Token; + this.erc721Token = this._contractWrappers.erc721Token; this.exchange = this._contractWrappers.exchange; this.etherToken = this._contractWrappers.etherToken; } /** + * Verifies that the provided signature is valid according to the 0x Protocol smart contracts + * @param provider The Web3Provider to use. Some signature types involve checking contract state. + * @param data The hex encoded data signed by the supplied signature. + * @param signature The hex encoded signature. + * @param signerAddress The hex encoded address that signed the data, producing the supplied signature. + * @return Whether the signature is valid for the supplied signerAddress and data. + */ + public async isValidSignatureAsync(data: string, signature: string, signerAddress: string): Promise<boolean> { + const isValid = await isValidSignatureAsync( + this._contractWrappers.getProvider(), + data, + signature, + signerAddress, + ); + return isValid; + } + /** * Sets a new web3 provider for 0x.js. Updating the provider will stop all * subscriptions so you will need to re-subscribe to all events relevant to your app after this call. * @param provider The Web3Provider you would like the 0x.js library to use from now on. @@ -166,23 +184,21 @@ export class ZeroEx { * @param orderHash Hex encoded orderHash to sign. * @param signerAddress The hex encoded Ethereum address you wish to sign it with. This address * must be available via the Provider supplied to 0x.js. - * @param shouldAddPersonalMessagePrefix Some signers add the personal message prefix `\x19Ethereum Signed Message` - * themselves (e.g Parity Signer, Ledger, TestRPC) and others expect it to already be done by the client - * (e.g Metamask). Depending on which signer this request is going to, decide on whether to add the prefix - * before sending the request. + * @param MessagePrefixOpts Options regarding the desired prefix and whether to add it before calling `eth_sign` * @return An object containing the Elliptic curve signature parameters generated by signing the orderHash. */ - public async signOrderHashAsync( + public async ecSignOrderHashAsync( orderHash: string, signerAddress: string, - shouldAddPersonalMessagePrefix: boolean, + messagePrefixOpts: MessagePrefixOpts, ): Promise<ECSignature> { - return signOrderHashAsync( + const signature = await ecSignOrderHashAsync( this._contractWrappers.getProvider(), orderHash, signerAddress, - shouldAddPersonalMessagePrefix, + messagePrefixOpts, ); + return signature; } /** * Waits for a transaction to be mined and returns the transaction receipt. diff --git a/packages/0x.js/src/artifacts.ts b/packages/0x.js/src/artifacts.ts new file mode 100644 index 000000000..f68969d28 --- /dev/null +++ b/packages/0x.js/src/artifacts.ts @@ -0,0 +1,7 @@ +import { ContractArtifact } from '@0xproject/sol-compiler'; + +import * as ZRXToken from './artifacts/ZRXToken.json'; + +export const artifacts = { + ZRXToken: (ZRXToken as any) as ContractArtifact, +}; diff --git a/packages/0x.js/src/index.ts b/packages/0x.js/src/index.ts index c79dbdb77..6dfc0bacc 100644 --- a/packages/0x.js/src/index.ts +++ b/packages/0x.js/src/index.ts @@ -1,30 +1,34 @@ export { ZeroEx } from './0x'; +export { MessagePrefixType, MessagePrefixOpts } from '@0xproject/order-utils'; + export { - BlockParamLiteral, - FilterObject, - BlockParam, - ContractEventArg, ExchangeContractErrs, - LogWithDecodedArgs, Order, - Provider, SignedOrder, ECSignature, OrderStateValid, OrderStateInvalid, OrderState, Token, +} from '@0xproject/types'; + +export { + BlockParamLiteral, + FilterObject, + BlockParam, + LogWithDecodedArgs, + ContractEventArg, + Provider, TransactionReceipt, TransactionReceiptWithDecodedLogs, -} from '@0xproject/types'; +} from 'ethereum-types'; export { EventCallback, ContractEvent, IndexedFilterValues, BlockRange, - OrderCancellationRequest, OrderFillRequest, ContractEventArgs, MethodOpts, @@ -34,18 +38,24 @@ export { DecodedLogEvent, OnOrderStateChangeCallback, ContractWrappersError, - EtherTokenContractEventArgs, - WithdrawalContractEventArgs, - DepositContractEventArgs, - EtherTokenEvents, - TransferContractEventArgs, - ApprovalContractEventArgs, - TokenContractEventArgs, - TokenEvents, - LogErrorContractEventArgs, - LogCancelContractEventArgs, - LogFillContractEventArgs, - ExchangeContractEventArgs, - ExchangeEvents, + WETH9Events, + WETH9WithdrawalEventArgs, + WETH9ApprovalEventArgs, + WETH9EventArgs, + WETH9DepositEventArgs, + WETH9TransferEventArgs, + ERC20TokenTransferEventArgs, + ERC20TokenApprovalEventArgs, + ERC20TokenEvents, + ERC20TokenEventArgs, + ERC721TokenApprovalEventArgs, + ERC721TokenApprovalForAllEventArgs, + ERC721TokenTransferEventArgs, + ERC721TokenEvents, + ExchangeCancelUpToEventArgs, + ExchangeAssetProxyRegisteredEventArgs, + ExchangeFillEventArgs, + ExchangeCancelEventArgs, + ExchangeEventArgs, ContractWrappersConfig, } from '@0xproject/contract-wrappers'; diff --git a/packages/0x.js/src/schemas/zero_ex_private_network_config_schema.ts b/packages/0x.js/src/schemas/zero_ex_private_network_config_schema.ts index 6036b2695..378b86e77 100644 --- a/packages/0x.js/src/schemas/zero_ex_private_network_config_schema.ts +++ b/packages/0x.js/src/schemas/zero_ex_private_network_config_schema.ts @@ -8,7 +8,8 @@ export const zeroExPrivateNetworkConfigSchema = { gasPrice: { $ref: '/Number' }, zrxContractAddress: { $ref: '/Address' }, exchangeContractAddress: { $ref: '/Address' }, - tokenTransferProxyContractAddress: { $ref: '/Address' }, + erc20ProxyContractAddress: { $ref: '/Address' }, + erc721ProxyContractAddress: { $ref: '/Address' }, orderWatcherConfig: { type: 'object', properties: { @@ -28,6 +29,7 @@ export const zeroExPrivateNetworkConfigSchema = { 'networkId', 'zrxContractAddress', 'exchangeContractAddress', - 'tokenTransferProxyContractAddress', + 'erc20ProxyContractAddress', + 'erc721ProxyContractAddress', ], }; diff --git a/packages/0x.js/src/schemas/zero_ex_public_network_config_schema.ts b/packages/0x.js/src/schemas/zero_ex_public_network_config_schema.ts index 7bedb7438..f2a9a4d56 100644 --- a/packages/0x.js/src/schemas/zero_ex_public_network_config_schema.ts +++ b/packages/0x.js/src/schemas/zero_ex_public_network_config_schema.ts @@ -22,7 +22,8 @@ export const zeroExPublicNetworkConfigSchema = { gasPrice: { $ref: '/Number' }, zrxContractAddress: { $ref: '/Address' }, exchangeContractAddress: { $ref: '/Address' }, - tokenTransferProxyContractAddress: { $ref: '/Address' }, + erc20ProxyContractAddress: { $ref: '/Address' }, + erc721ProxyContractAddress: { $ref: '/Address' }, orderWatcherConfig: { type: 'object', properties: { diff --git a/packages/0x.js/test/0x.js_test.ts b/packages/0x.js/test/0x.js_test.ts index 815f94de1..722049955 100644 --- a/packages/0x.js/test/0x.js_test.ts +++ b/packages/0x.js/test/0x.js_test.ts @@ -5,11 +5,11 @@ import * as chai from 'chai'; import * as _ from 'lodash'; import 'mocha'; -import { ApprovalContractEventArgs, LogWithDecodedArgs, TokenEvents, ZeroEx } from '../src'; +import { ERC20TokenApprovalEventArgs, ERC20TokenEvents, LogWithDecodedArgs, ZeroEx } from '../src'; import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; -import { TokenUtils } from './utils/token_utils'; +import { tokenUtils } from './utils/token_utils'; import { provider, web3Wrapper } from './utils/web3_wrapper'; const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); @@ -45,40 +45,34 @@ describe('ZeroEx library', () => { }); }); describe('#isValidSignature', () => { - // The Exchange smart contract `isValidSignature` method only validates orderHashes and assumes - // the length of the data is exactly 32 bytes. Thus for these tests, we use data of this size. const dataHex = '0x6927e990021d23b1eb7b8789f6a6feaf98fe104bb0cf8259421b79f9a34222b0'; - const signature = { - v: 27, - r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', - s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', - }; + const ethSignSignature = + '0x1B61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc3340349190569279751135161d22529dc25add4f6069af05be04cacbda2ace225403'; const address = '0x5409ed021d9299bf6814279a6a1411a7e866a631'; it("should return false if the data doesn't pertain to the signature & address", async () => { - return expect( - (zeroEx.exchange as any)._isValidSignatureUsingContractCallAsync('0x0', signature, address), - ).to.become(false); + return expect((zeroEx.exchange as any).isValidSignatureAsync('0x0', address, ethSignSignature)).to.become( + false, + ); }); it("should return false if the address doesn't pertain to the signature & data", async () => { const validUnrelatedAddress = '0x8b0292b11a196601ed2ce54b665cafeca0347d42'; return expect( - (zeroEx.exchange as any)._isValidSignatureUsingContractCallAsync( - dataHex, - signature, - validUnrelatedAddress, - ), + (zeroEx.exchange as any).isValidSignatureAsync(dataHex, validUnrelatedAddress, ethSignSignature), ).to.become(false); }); it("should return false if the signature doesn't pertain to the dataHex & address", async () => { - const wrongSignature = _.assign({}, signature, { v: 28 }); - return expect( - (zeroEx.exchange as any)._isValidSignatureUsingContractCallAsync(dataHex, wrongSignature, address), - ).to.become(false); + const signatureArray = ethSignSignature.split(''); + // tslint:disable-next-line:custom-no-magic-numbers + signatureArray[5] = 'C'; // V = 28, instead of 27 + const wrongSignature = signatureArray.join(''); + return expect((zeroEx.exchange as any).isValidSignatureAsync(dataHex, address, wrongSignature)).to.become( + false, + ); }); it('should return true if the signature does pertain to the dataHex & address', async () => { - return expect( - (zeroEx.exchange as any)._isValidSignatureUsingContractCallAsync(dataHex, signature, address), - ).to.become(true); + return expect((zeroEx.exchange as any).isValidSignatureAsync(dataHex, address, ethSignSignature)).to.become( + true, + ); }); }); describe('#toUnitAmount', () => { @@ -123,18 +117,16 @@ describe('ZeroEx library', () => { it('returns transaction receipt with decoded logs', async () => { const availableAddresses = await zeroEx.getAvailableAddressesAsync(); const coinbase = availableAddresses[0]; - const tokens = await zeroEx.tokenRegistry.getTokensAsync(); - const tokenUtils = new TokenUtils(tokens); - const zrxTokenAddress = tokenUtils.getProtocolTokenOrThrow().address; - const proxyAddress = zeroEx.proxy.getContractAddress(); - const txHash = await zeroEx.token.setUnlimitedProxyAllowanceAsync(zrxTokenAddress, coinbase); + const zrxTokenAddress = tokenUtils.getProtocolTokenAddress(); + const erc20ProxyAddress = zeroEx.erc20Proxy.getContractAddress(); + const txHash = await zeroEx.erc20Token.setUnlimitedProxyAllowanceAsync(zrxTokenAddress, coinbase); const txReceiptWithDecodedLogs = await zeroEx.awaitTransactionMinedAsync(txHash); // tslint:disable-next-line:no-unnecessary-type-assertion - const log = txReceiptWithDecodedLogs.logs[0] as LogWithDecodedArgs<ApprovalContractEventArgs>; - expect(log.event).to.be.equal(TokenEvents.Approval); + const log = txReceiptWithDecodedLogs.logs[0] as LogWithDecodedArgs<ERC20TokenApprovalEventArgs>; + expect(log.event).to.be.equal(ERC20TokenEvents.Approval); expect(log.args._owner).to.be.equal(coinbase); - expect(log.args._spender).to.be.equal(proxyAddress); - expect(log.args._value).to.be.bignumber.equal(zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS); + expect(log.args._spender).to.be.equal(erc20ProxyAddress); + expect(log.args._value).to.be.bignumber.equal(zeroEx.erc20Token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS); }); }); describe('#config', () => { @@ -146,15 +138,13 @@ describe('ZeroEx library', () => { const zeroExWithWrongExchangeAddress = new ZeroEx(provider, zeroExConfig); expect(zeroExWithWrongExchangeAddress.exchange.getContractAddress()).to.be.equal(ZeroEx.NULL_ADDRESS); }); - it('allows to specify token registry token contract address', async () => { + it('allows to specify erc20Proxy contract address', async () => { const zeroExConfig = { - tokenRegistryContractAddress: ZeroEx.NULL_ADDRESS, + erc20ProxyContractAddress: ZeroEx.NULL_ADDRESS, networkId: constants.TESTRPC_NETWORK_ID, }; - const zeroExWithWrongTokenRegistryAddress = new ZeroEx(provider, zeroExConfig); - expect(zeroExWithWrongTokenRegistryAddress.tokenRegistry.getContractAddress()).to.be.equal( - ZeroEx.NULL_ADDRESS, - ); + const zeroExWithWrongERC20ProxyAddress = new ZeroEx(provider, zeroExConfig); + expect(zeroExWithWrongERC20ProxyAddress.erc20Proxy.getContractAddress()).to.be.equal(ZeroEx.NULL_ADDRESS); }); }); }); diff --git a/packages/0x.js/test/global_hooks.ts b/packages/0x.js/test/global_hooks.ts index 9d6903af5..3d74634fe 100644 --- a/packages/0x.js/test/global_hooks.ts +++ b/packages/0x.js/test/global_hooks.ts @@ -1,5 +1,5 @@ import { devConstants } from '@0xproject/dev-utils'; -import { runV1MigrationsAsync } from '@0xproject/migrations'; +import { runV2MigrationsAsync } from '@0xproject/migrations'; import { provider } from './utils/web3_wrapper'; @@ -12,6 +12,6 @@ before('migrate contracts', async function(): Promise<void> { gas: devConstants.GAS_LIMIT, from: devConstants.TESTRPC_FIRST_ADDRESS, }; - const artifactsDir = `../migrations/artifacts/1.0.0`; - await runV1MigrationsAsync(provider, artifactsDir, txDefaults); + const artifactsDir = `../migrations/artifacts/2.0.0`; + await runV2MigrationsAsync(provider, artifactsDir, txDefaults); }); diff --git a/packages/0x.js/test/utils/token_utils.ts b/packages/0x.js/test/utils/token_utils.ts index fe4886ba4..76ee80b58 100644 --- a/packages/0x.js/test/utils/token_utils.ts +++ b/packages/0x.js/test/utils/token_utils.ts @@ -1,34 +1,12 @@ -import { Token } from '@0xproject/types'; -import * as _ from 'lodash'; +import { generatePseudoRandomSalt } from '@0xproject/order-utils'; +import { BigNumber } from '@0xproject/utils'; -import { InternalZeroExError } from '../../src/types'; +import { artifacts } from '../../src/artifacts'; -const PROTOCOL_TOKEN_SYMBOL = 'ZRX'; -const WETH_TOKEN_SYMBOL = 'WETH'; +import { constants } from './constants'; -export class TokenUtils { - private _tokens: Token[]; - constructor(tokens: Token[]) { - this._tokens = tokens; - } - public getProtocolTokenOrThrow(): Token { - const zrxToken = _.find(this._tokens, { symbol: PROTOCOL_TOKEN_SYMBOL }); - if (_.isUndefined(zrxToken)) { - throw new Error(InternalZeroExError.ZrxNotInTokenRegistry); - } - return zrxToken; - } - public getWethTokenOrThrow(): Token { - const wethToken = _.find(this._tokens, { symbol: WETH_TOKEN_SYMBOL }); - if (_.isUndefined(wethToken)) { - throw new Error(InternalZeroExError.WethNotInTokenRegistry); - } - return wethToken; - } - public getDummyTokens(): Token[] { - const dummyTokens = _.filter(this._tokens, token => { - return !_.includes([PROTOCOL_TOKEN_SYMBOL, WETH_TOKEN_SYMBOL], token.symbol); - }); - return dummyTokens; - } -} +export const tokenUtils = { + getProtocolTokenAddress(): string { + return artifacts.ZRXToken.networks[constants.TESTRPC_NETWORK_ID].address; + }, +}; diff --git a/packages/0x.js/test/utils/web3_wrapper.ts b/packages/0x.js/test/utils/web3_wrapper.ts index f7d11f138..02c8c5918 100644 --- a/packages/0x.js/test/utils/web3_wrapper.ts +++ b/packages/0x.js/test/utils/web3_wrapper.ts @@ -1,8 +1,12 @@ -import { web3Factory } from '@0xproject/dev-utils'; -import { Provider } from '@0xproject/types'; +import { devConstants, web3Factory } from '@0xproject/dev-utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import { Provider } from 'ethereum-types'; +const txDefaults = { + from: devConstants.TESTRPC_FIRST_ADDRESS, + gas: devConstants.GAS_LIMIT, +}; const provider: Provider = web3Factory.getRpcProvider({ shouldUseInProcessGanache: true }); const web3Wrapper = new Web3Wrapper(provider); -export { provider, web3Wrapper }; +export { provider, web3Wrapper, txDefaults }; diff --git a/packages/contract-wrappers/src/index.ts b/packages/contract-wrappers/src/index.ts index b3c4b2c60..d8e597ed1 100644 --- a/packages/contract-wrappers/src/index.ts +++ b/packages/contract-wrappers/src/index.ts @@ -2,6 +2,9 @@ export { ContractWrappers } from './contract_wrappers'; export { ERC20TokenWrapper } from './contract_wrappers/erc20_token_wrapper'; export { EtherTokenWrapper } from './contract_wrappers/ether_token_wrapper'; export { ERC20ProxyWrapper } from './contract_wrappers/erc20_proxy_wrapper'; +export { ExchangeWrapper } from './contract_wrappers/exchange_wrapper'; +export { ERC721TokenWrapper } from './contract_wrappers/erc721_token_wrapper'; +export { ERC721ProxyWrapper } from './contract_wrappers/erc721_proxy_wrapper'; export { ContractWrappersError, diff --git a/packages/contract-wrappers/src/schemas/contract_wrappers_private_network_config_schema.ts b/packages/contract-wrappers/src/schemas/contract_wrappers_private_network_config_schema.ts index d293b4d4f..7e2eca61c 100644 --- a/packages/contract-wrappers/src/schemas/contract_wrappers_private_network_config_schema.ts +++ b/packages/contract-wrappers/src/schemas/contract_wrappers_private_network_config_schema.ts @@ -8,7 +8,8 @@ export const contractWrappersPrivateNetworkConfigSchema = { gasPrice: { $ref: '/Number' }, zrxContractAddress: { $ref: '/Address' }, exchangeContractAddress: { $ref: '/Address' }, - tokenTransferProxyContractAddress: { $ref: '/Address' }, + erc20ProxyContractAddress: { $ref: '/Address' }, + erc721ProxyContractAddress: { $ref: '/Address' }, blockPollingIntervalMs: { type: 'number' }, orderWatcherConfig: { type: 'object', @@ -29,6 +30,7 @@ export const contractWrappersPrivateNetworkConfigSchema = { 'networkId', 'zrxContractAddress', 'exchangeContractAddress', - 'tokenTransferProxyContractAddress', + 'erc20ProxyContractAddress', + 'erc721ProxyContractAddress', ], }; diff --git a/packages/contract-wrappers/src/schemas/contract_wrappers_public_network_config_schema.ts b/packages/contract-wrappers/src/schemas/contract_wrappers_public_network_config_schema.ts index f59b30ad0..363110767 100644 --- a/packages/contract-wrappers/src/schemas/contract_wrappers_public_network_config_schema.ts +++ b/packages/contract-wrappers/src/schemas/contract_wrappers_public_network_config_schema.ts @@ -22,7 +22,7 @@ export const contractWrappersPublicNetworkConfigSchema = { gasPrice: { $ref: '/Number' }, zrxContractAddress: { $ref: '/Address' }, exchangeContractAddress: { $ref: '/Address' }, - tokenTransferProxyContractAddress: { $ref: '/Address' }, + erc20ProxyContractAddress: { $ref: '/Address' }, blockPollingIntervalMs: { type: 'number' }, orderWatcherConfig: { type: 'object', |