Remove 0x.js dep from contracts
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { ZeroEx } from '0x.js';
|
||||
import { generatePseudoRandomSalt } from '@0xproject/order-utils';
|
||||
|
||||
import { crypto } from './crypto';
|
||||
|
||||
export const addressUtils = {
|
||||
generatePseudoRandomAddress(): string {
|
||||
const randomBigNum = ZeroEx.generatePseudoRandomSalt();
|
||||
const randomBigNum = generatePseudoRandomSalt();
|
||||
const randomBuff = crypto.solSHA3([randomBigNum]);
|
||||
const randomAddress = `0x${randomBuff.slice(0, 20).toString('hex')}`;
|
||||
return randomAddress;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { ZeroEx } from '0x.js';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import { Web3Wrapper } from '@0xproject/web3_wrapper';
|
||||
import * as ethUtil from 'ethereumjs-util';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
@@ -30,13 +30,14 @@ export const constants = {
|
||||
NUM_DUMMY_ERC20_TO_DEPLOY: 3,
|
||||
NUM_DUMMY_ERC721_TO_DEPLOY: 1,
|
||||
NUM_ERC721_TOKENS_TO_MINT: 2,
|
||||
NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
|
||||
TESTRPC_PRIVATE_KEYS: _.map(TESTRPC_PRIVATE_KEYS_STRINGS, privateKeyString => ethUtil.toBuffer(privateKeyString)),
|
||||
INITIAL_ERC20_BALANCE: ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18),
|
||||
INITIAL_ERC20_ALLOWANCE: ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18),
|
||||
INITIAL_ERC20_BALANCE: Web3Wrapper.toBaseUnitAmount(new BigNumber(10000), 18),
|
||||
INITIAL_ERC20_ALLOWANCE: Web3Wrapper.toBaseUnitAmount(new BigNumber(10000), 18),
|
||||
STATIC_ORDER_PARAMS: {
|
||||
makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
|
||||
takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
|
||||
makerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
|
||||
takerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18),
|
||||
makerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18),
|
||||
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18),
|
||||
},
|
||||
};
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { ZeroEx } from '0x.js';
|
||||
import { generatePseudoRandomSalt } from '@0xproject/order-utils';
|
||||
import { Provider } from '@0xproject/types';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import * as _ from 'lodash';
|
||||
@@ -54,7 +54,7 @@ export class ERC721Wrapper {
|
||||
_.forEach(this._dummyTokenContracts, dummyTokenContract => {
|
||||
_.forEach(this._tokenOwnerAddresses, tokenOwnerAddress => {
|
||||
_.forEach(_.range(constants.NUM_ERC721_TOKENS_TO_MINT), () => {
|
||||
const tokenId = ZeroEx.generatePseudoRandomSalt();
|
||||
const tokenId = generatePseudoRandomSalt();
|
||||
setBalancePromises.push(
|
||||
dummyTokenContract.mint.sendTransactionAsync(tokenOwnerAddress, tokenId, {
|
||||
from: this._contractOwnerAddress,
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import { TransactionReceiptWithDecodedLogs, ZeroEx } from '0x.js';
|
||||
import { TransactionReceiptWithDecodedLogs } from '@0xproject/types';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
import * as _ from 'lodash';
|
||||
import * as Web3 from 'web3';
|
||||
|
||||
@@ -14,10 +15,8 @@ import { AssetProxyId, OrderInfo, SignedOrder, SignedTransaction } from './types
|
||||
export class ExchangeWrapper {
|
||||
private _exchange: ExchangeContract;
|
||||
private _logDecoder: LogDecoder = new LogDecoder(constants.TESTRPC_NETWORK_ID);
|
||||
private _zeroEx: ZeroEx;
|
||||
constructor(exchangeContract: ExchangeContract, zeroEx: ZeroEx) {
|
||||
constructor(exchangeContract: ExchangeContract) {
|
||||
this._exchange = exchangeContract;
|
||||
this._zeroEx = zeroEx;
|
||||
}
|
||||
public async fillOrderAsync(
|
||||
signedOrder: SignedOrder,
|
||||
@@ -196,7 +195,7 @@ export class ExchangeWrapper {
|
||||
opts: { oldAssetProxyAddressIfExists?: string } = {},
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const oldAssetProxyAddress = _.isUndefined(opts.oldAssetProxyAddressIfExists)
|
||||
? ZeroEx.NULL_ADDRESS
|
||||
? constants.NULL_ADDRESS
|
||||
: opts.oldAssetProxyAddressIfExists;
|
||||
const txHash = await this._exchange.registerAssetProxy.sendTransactionAsync(
|
||||
assetProxyId,
|
||||
@@ -246,7 +245,7 @@ export class ExchangeWrapper {
|
||||
return tx;
|
||||
}
|
||||
private async _getTxWithDecodedExchangeLogsAsync(txHash: string) {
|
||||
const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
|
||||
const tx = await Web3Wrapper.awaitTransactionMinedAsync(txHash);
|
||||
tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
|
||||
tx.logs = _.map(tx.logs, log => this._logDecoder.decodeLogOrThrow(log));
|
||||
return tx;
|
||||
|
@@ -1,7 +1,8 @@
|
||||
import { ZeroEx } from '0x.js';
|
||||
import { generatePseudoRandomSalt } from '@0xproject/order-utils';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { constants } from './constants';
|
||||
import { orderUtils } from './order_utils';
|
||||
import { signingUtils } from './signing_utils';
|
||||
import { SignatureType, SignedOrder, UnsignedOrder } from './types';
|
||||
@@ -19,10 +20,10 @@ export class OrderFactory {
|
||||
): SignedOrder {
|
||||
const randomExpiration = new BigNumber(Math.floor((Date.now() + Math.random() * 100000000000) / 1000));
|
||||
const order = ({
|
||||
senderAddress: ZeroEx.NULL_ADDRESS,
|
||||
senderAddress: constants.NULL_ADDRESS,
|
||||
expirationTimeSeconds: randomExpiration,
|
||||
salt: ZeroEx.generatePseudoRandomSalt(),
|
||||
takerAddress: ZeroEx.NULL_ADDRESS,
|
||||
salt: generatePseudoRandomSalt(),
|
||||
takerAddress: constants.NULL_ADDRESS,
|
||||
...this._defaultOrderParams,
|
||||
...customOrderParams,
|
||||
} as any) as UnsignedOrder;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { ZeroEx } from '0x.js';
|
||||
import { generatePseudoRandomSalt } from '@0xproject/order-utils';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import * as ethUtil from 'ethereumjs-util';
|
||||
|
||||
@@ -20,7 +20,7 @@ export class TransactionFactory {
|
||||
data: string,
|
||||
signatureType: SignatureType = SignatureType.Ecrecover,
|
||||
): SignedTransaction {
|
||||
const salt = ZeroEx.generatePseudoRandomSalt();
|
||||
const salt = generatePseudoRandomSalt();
|
||||
const txHash = crypto.solSHA3([this._exchangeAddress, salt, ethUtil.toBuffer(data)]);
|
||||
const signature = signingUtils.signMessage(txHash, this._privateKey, signatureType);
|
||||
const signedTx = {
|
||||
|
Reference in New Issue
Block a user