Remove artifacts dep from contract-wrappers
This commit is contained in:
parent
dd90aabad6
commit
00e34758c4
@ -1,10 +1,10 @@
|
||||
import { generatePseudoRandomSalt } from '@0x/order-utils';
|
||||
import { crypto } from '@0x/order-utils/lib/src/crypto';
|
||||
import { Order, SignedOrder } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { constants } from './constants';
|
||||
import { hexHash } from './hex_utils';
|
||||
import { BatchMatchOrder, CancelOrder, MatchOrder } from './types';
|
||||
|
||||
export const orderUtils = {
|
||||
@ -59,8 +59,7 @@ export const orderUtils = {
|
||||
},
|
||||
generatePseudoRandomOrderHash(): string {
|
||||
const randomBigNum = generatePseudoRandomSalt();
|
||||
const randomBuff = crypto.solSHA3([randomBigNum]);
|
||||
const randomHash = `0x${randomBuff.toString('hex')}`;
|
||||
const randomHash = hexHash(randomBigNum);
|
||||
return randomHash;
|
||||
},
|
||||
};
|
||||
|
@ -59,7 +59,6 @@ export { DecodedCalldata, BigNumber } from '@0x/utils';
|
||||
export {
|
||||
Order,
|
||||
SignedOrder,
|
||||
DutchAuctionData,
|
||||
ECSignature,
|
||||
AssetProxyId,
|
||||
AssetData,
|
||||
|
@ -65,6 +65,7 @@ export class {{contractName}}Contract extends BaseContract {
|
||||
{{else~}}
|
||||
public static deployedBytecode = '{{this.deployedBytecode}}';
|
||||
{{/ifEquals~}}
|
||||
public static contractName = '{{contractName}}';
|
||||
private readonly _methodABIIndex: { [name: string]: number } = {};
|
||||
{{#if events~}}
|
||||
private readonly _subscriptionManager: SubscriptionManager<{{contractName}}EventArgs, {{contractName}}Events>;
|
||||
|
File diff suppressed because one or more lines are too long
@ -40,6 +40,7 @@ export class LibDummyContract extends BaseContract {
|
||||
* @ignore
|
||||
*/
|
||||
public static deployedBytecode: string | undefined;
|
||||
public static contractName = 'LibDummy';
|
||||
private readonly _methodABIIndex: { [name: string]: number } = {};
|
||||
public static async deployFrom0xArtifactAsync(
|
||||
artifact: ContractArtifact | SimpleContractArtifact,
|
||||
|
@ -41,6 +41,7 @@ export class TestLibDummyContract extends BaseContract {
|
||||
*/
|
||||
public static deployedBytecode =
|
||||
'0x6080604052348015600f57600080fd5b506004361060325760003560e01c806322935e921460375780632b82fdf0146063575b600080fd5b605160048036036020811015604b57600080fd5b5035607d565b60408051918252519081900360200190f35b605160048036036020811015607757600080fd5b5035608c565b60006086826095565b92915050565b6000608682609c565b6104d20190565b6001019056fea265627a7a72315820863e53f0da474a1275d583d88852313fe053941e79bddd5279abd812b31e020c64736f6c634300050c0032';
|
||||
public static contractName = 'TestLibDummy';
|
||||
private readonly _methodABIIndex: { [name: string]: number } = {};
|
||||
public static async deployFrom0xArtifactAsync(
|
||||
artifact: ContractArtifact | SimpleContractArtifact,
|
||||
|
@ -53,7 +53,6 @@
|
||||
"@0x/assert": "^2.2.0-beta.2",
|
||||
"@0x/base-contract": "^5.5.0-beta.3",
|
||||
"@0x/contract-addresses": "^3.3.0-beta.4",
|
||||
"@0x/contract-artifacts": "^2.3.0-beta.3",
|
||||
"@0x/json-schemas": "^4.1.0-beta.2",
|
||||
"@0x/types": "^2.5.0-beta.2",
|
||||
"@0x/utils": "^4.6.0-beta.2",
|
||||
|
@ -1,16 +1,5 @@
|
||||
import { assert } from '@0x/assert';
|
||||
import { ContractAddresses } from '@0x/contract-addresses';
|
||||
import {
|
||||
Coordinator,
|
||||
DevUtils,
|
||||
ERC20Token,
|
||||
ERC721Token,
|
||||
Exchange,
|
||||
Forwarder,
|
||||
Staking,
|
||||
StakingProxy,
|
||||
WETH9,
|
||||
} from '@0x/contract-artifacts';
|
||||
import { AbiDecoder } from '@0x/utils';
|
||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||
import { SupportedProvider } from 'ethereum-types';
|
||||
@ -18,11 +7,12 @@ import { SupportedProvider } from 'ethereum-types';
|
||||
import { ContractWrappersConfigSchema } from './contract_wrappers_config_schema';
|
||||
import { CoordinatorContract } from './generated-wrappers/coordinator';
|
||||
import { DevUtilsContract } from './generated-wrappers/dev_utils';
|
||||
import { ERC20TokenContract } from './generated-wrappers/erc20_token';
|
||||
import { ERC721TokenContract } from './generated-wrappers/erc721_token';
|
||||
import { ExchangeContract } from './generated-wrappers/exchange';
|
||||
import { ForwarderContract } from './generated-wrappers/forwarder';
|
||||
import { StakingContract } from './generated-wrappers/staking';
|
||||
import { WETH9Contract } from './generated-wrappers/weth9';
|
||||
|
||||
import { ContractWrappersConfig } from './types';
|
||||
import { _getDefaultContractAddresses } from './utils/contract_addresses';
|
||||
|
||||
@ -74,19 +64,18 @@ export class ContractWrappers {
|
||||
gasPrice: config.gasPrice,
|
||||
};
|
||||
this._web3Wrapper = new Web3Wrapper(supportedProvider, txDefaults);
|
||||
const artifactsArray = [
|
||||
Coordinator,
|
||||
DevUtils,
|
||||
ERC20Token,
|
||||
ERC721Token,
|
||||
Exchange,
|
||||
Forwarder,
|
||||
Staking,
|
||||
StakingProxy,
|
||||
WETH9,
|
||||
const contractsArray = [
|
||||
CoordinatorContract,
|
||||
DevUtilsContract,
|
||||
ERC20TokenContract,
|
||||
ERC721TokenContract,
|
||||
ExchangeContract,
|
||||
ForwarderContract,
|
||||
StakingContract,
|
||||
WETH9Contract,
|
||||
];
|
||||
artifactsArray.forEach(artifact => {
|
||||
this._web3Wrapper.abiDecoder.addABI(artifact.compilerOutput.abi, artifact.contractName);
|
||||
contractsArray.forEach(contract => {
|
||||
this._web3Wrapper.abiDecoder.addABI(contract.ABI(), contract.contractName);
|
||||
});
|
||||
const contractAddresses =
|
||||
config.contractAddresses === undefined
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -61,6 +61,7 @@ export class ERC20TokenContract extends BaseContract {
|
||||
* @ignore
|
||||
*/
|
||||
public static deployedBytecode: string | undefined;
|
||||
public static contractName = 'ERC20Token';
|
||||
private readonly _methodABIIndex: { [name: string]: number } = {};
|
||||
private readonly _subscriptionManager: SubscriptionManager<ERC20TokenEventArgs, ERC20TokenEvents>;
|
||||
public static async deployFrom0xArtifactAsync(
|
||||
|
@ -71,6 +71,7 @@ export class ERC721TokenContract extends BaseContract {
|
||||
* @ignore
|
||||
*/
|
||||
public static deployedBytecode: string | undefined;
|
||||
public static contractName = 'ERC721Token';
|
||||
private readonly _methodABIIndex: { [name: string]: number } = {};
|
||||
private readonly _subscriptionManager: SubscriptionManager<ERC721TokenEventArgs, ERC721TokenEvents>;
|
||||
public static async deployFrom0xArtifactAsync(
|
||||
|
@ -120,6 +120,7 @@ export class ExchangeContract extends BaseContract {
|
||||
* @ignore
|
||||
*/
|
||||
public static deployedBytecode: string | undefined;
|
||||
public static contractName = 'Exchange';
|
||||
private readonly _methodABIIndex: { [name: string]: number } = {};
|
||||
private readonly _subscriptionManager: SubscriptionManager<ExchangeEventArgs, ExchangeEvents>;
|
||||
public static async deployFrom0xArtifactAsync(
|
||||
|
@ -53,6 +53,7 @@ export class ForwarderContract extends BaseContract {
|
||||
* @ignore
|
||||
*/
|
||||
public static deployedBytecode: string | undefined;
|
||||
public static contractName = 'Forwarder';
|
||||
private readonly _methodABIIndex: { [name: string]: number } = {};
|
||||
private readonly _subscriptionManager: SubscriptionManager<ForwarderEventArgs, ForwarderEvents>;
|
||||
public static async deployFrom0xArtifactAsync(
|
||||
|
@ -172,6 +172,7 @@ export class StakingContract extends BaseContract {
|
||||
* @ignore
|
||||
*/
|
||||
public static deployedBytecode: string | undefined;
|
||||
public static contractName = 'Staking';
|
||||
private readonly _methodABIIndex: { [name: string]: number } = {};
|
||||
private readonly _subscriptionManager: SubscriptionManager<StakingEventArgs, StakingEvents>;
|
||||
public static async deployFrom0xArtifactAsync(
|
||||
|
@ -78,6 +78,7 @@ export class StakingProxyContract extends BaseContract {
|
||||
* @ignore
|
||||
*/
|
||||
public static deployedBytecode: string | undefined;
|
||||
public static contractName = 'StakingProxy';
|
||||
private readonly _methodABIIndex: { [name: string]: number } = {};
|
||||
private readonly _subscriptionManager: SubscriptionManager<StakingProxyEventArgs, StakingProxyEvents>;
|
||||
public static async deployFrom0xArtifactAsync(
|
||||
|
@ -77,6 +77,7 @@ export class WETH9Contract extends BaseContract {
|
||||
* @ignore
|
||||
*/
|
||||
public static deployedBytecode: string | undefined;
|
||||
public static contractName = 'WETH9';
|
||||
private readonly _methodABIIndex: { [name: string]: number } = {};
|
||||
private readonly _subscriptionManager: SubscriptionManager<WETH9EventArgs, WETH9Events>;
|
||||
public static async deployFrom0xArtifactAsync(
|
||||
|
@ -64,14 +64,10 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@0x/assert": "^2.2.0-beta.2",
|
||||
"@0x/contract-addresses": "^3.3.0-beta.4",
|
||||
"@0x/contract-artifacts": "^2.3.0-beta.3",
|
||||
"@0x/contract-wrappers": "^12.2.0-beta.3",
|
||||
"@0x/json-schemas": "^4.1.0-beta.2",
|
||||
"@0x/utils": "^4.6.0-beta.2",
|
||||
"@0x/web3-wrapper": "^6.1.0-beta.2",
|
||||
"bn.js": "^4.11.8",
|
||||
"ethereumjs-abi": "0.6.5",
|
||||
"ethereumjs-util": "^5.1.1",
|
||||
"ethers": "~4.0.4",
|
||||
"lodash": "^4.17.11"
|
||||
|
@ -1,6 +1,5 @@
|
||||
import {
|
||||
AssetProxyId,
|
||||
DutchAuctionData,
|
||||
ERC1155AssetData,
|
||||
ERC1155AssetDataNoProxyId,
|
||||
ERC20AssetData,
|
||||
@ -11,8 +10,6 @@ import {
|
||||
StaticCallAssetData,
|
||||
} from '@0x/types';
|
||||
import { AbiEncoder, BigNumber } from '@0x/utils';
|
||||
import * as ethAbi from 'ethereumjs-abi';
|
||||
import * as ethUtil from 'ethereumjs-util';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { constants } from './constants';
|
||||
@ -233,59 +230,6 @@ export const assetDataUtils = {
|
||||
staticCallData: decodedAssetData.staticCallData,
|
||||
};
|
||||
},
|
||||
/**
|
||||
* Dutch auction details are encoded with the asset data for a 0x order. This function produces a hex
|
||||
* encoded assetData string, containing information both about the asset being traded and the
|
||||
* dutch auction; which is usable in the makerAssetData or takerAssetData fields in a 0x order.
|
||||
* @param assetData Hex encoded assetData string for the asset being auctioned.
|
||||
* @param beginTimeSeconds Begin time of the dutch auction.
|
||||
* @param beginAmount Starting amount being sold in the dutch auction.
|
||||
* @return The hex encoded assetData string.
|
||||
*/
|
||||
encodeDutchAuctionAssetData(assetData: string, beginTimeSeconds: BigNumber, beginAmount: BigNumber): string {
|
||||
const assetDataBuffer = ethUtil.toBuffer(assetData);
|
||||
const abiEncodedAuctionData = (ethAbi as any).rawEncode(
|
||||
['uint256', 'uint256'],
|
||||
[beginTimeSeconds.toString(), beginAmount.toString()],
|
||||
);
|
||||
const abiEncodedAuctionDataBuffer = ethUtil.toBuffer(abiEncodedAuctionData);
|
||||
const dutchAuctionDataBuffer = Buffer.concat([assetDataBuffer, abiEncodedAuctionDataBuffer]);
|
||||
const dutchAuctionData = ethUtil.bufferToHex(dutchAuctionDataBuffer);
|
||||
return dutchAuctionData;
|
||||
},
|
||||
/**
|
||||
* Dutch auction details are encoded with the asset data for a 0x order. This function decodes a hex
|
||||
* encoded assetData string, containing information both about the asset being traded and the
|
||||
* dutch auction.
|
||||
* @param dutchAuctionData Hex encoded assetData string for the asset being auctioned.
|
||||
* @return An object containing the auction asset, auction begin time and auction begin amount.
|
||||
*/
|
||||
decodeDutchAuctionData(dutchAuctionData: string): DutchAuctionData {
|
||||
const dutchAuctionDataBuffer = ethUtil.toBuffer(dutchAuctionData);
|
||||
// Decode asset data
|
||||
const dutchAuctionDataLengthInBytes = 64;
|
||||
const assetDataBuffer = dutchAuctionDataBuffer.slice(
|
||||
0,
|
||||
dutchAuctionDataBuffer.byteLength - dutchAuctionDataLengthInBytes,
|
||||
);
|
||||
const assetDataHex = ethUtil.bufferToHex(assetDataBuffer);
|
||||
const assetData = assetDataUtils.decodeAssetDataOrThrow(assetDataHex);
|
||||
// Decode auction details
|
||||
const dutchAuctionDetailsBuffer = dutchAuctionDataBuffer.slice(
|
||||
dutchAuctionDataBuffer.byteLength - dutchAuctionDataLengthInBytes,
|
||||
);
|
||||
const [beginTimeSecondsAsBN, beginAmountAsBN] = ethAbi.rawDecode(
|
||||
['uint256', 'uint256'],
|
||||
dutchAuctionDetailsBuffer,
|
||||
);
|
||||
const beginTimeSeconds = new BigNumber(beginTimeSecondsAsBN.toString());
|
||||
const beginAmount = new BigNumber(beginAmountAsBN.toString());
|
||||
return {
|
||||
assetData,
|
||||
beginTimeSeconds,
|
||||
beginAmount,
|
||||
};
|
||||
},
|
||||
/**
|
||||
* Decode and return the assetProxyId from the assetData
|
||||
* @param assetData Hex encoded assetData string to decode
|
||||
|
@ -1,47 +0,0 @@
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import BN = require('bn.js');
|
||||
import ABI = require('ethereumjs-abi');
|
||||
import ethUtil = require('ethereumjs-util');
|
||||
import * as _ from 'lodash';
|
||||
|
||||
export const crypto = {
|
||||
/**
|
||||
* We convert types from JS to Solidity as follows:
|
||||
* BigNumber -> uint256
|
||||
* number -> uint8
|
||||
* string -> string
|
||||
* boolean -> bool
|
||||
* valid Ethereum address -> address
|
||||
*/
|
||||
solSHA3(args: any[]): Buffer {
|
||||
return crypto._solHash(args, ABI.soliditySHA3);
|
||||
},
|
||||
solSHA256(args: any[]): Buffer {
|
||||
return crypto._solHash(args, ABI.soliditySHA256);
|
||||
},
|
||||
_solHash(args: any[], hashFunction: (types: string[], values: any[]) => Buffer): Buffer {
|
||||
const argTypes: string[] = [];
|
||||
_.each(args, (arg, i) => {
|
||||
const isNumber = _.isFinite(arg);
|
||||
if (isNumber) {
|
||||
argTypes.push('uint8');
|
||||
} else if (BigNumber.isBigNumber(arg)) {
|
||||
argTypes.push('uint256');
|
||||
const base = 10;
|
||||
args[i] = new BN(arg.toString(base), base);
|
||||
} else if (ethUtil.isValidAddress(arg)) {
|
||||
argTypes.push('address');
|
||||
} else if (_.isString(arg)) {
|
||||
argTypes.push('string');
|
||||
} else if (_.isBuffer(arg) || _.isTypedArray(arg)) {
|
||||
argTypes.push('bytes');
|
||||
} else if (_.isBoolean(arg)) {
|
||||
argTypes.push('bool');
|
||||
} else {
|
||||
throw new Error(`Unable to guess arg type: ${arg}`);
|
||||
}
|
||||
});
|
||||
const hash = hashFunction(argTypes, args);
|
||||
return hash;
|
||||
},
|
||||
};
|
@ -31,7 +31,6 @@ export {
|
||||
ECSignature,
|
||||
AssetData,
|
||||
SingleAssetData,
|
||||
DutchAuctionData,
|
||||
ERC20AssetData,
|
||||
ERC721AssetData,
|
||||
ERC1155AssetData,
|
||||
|
@ -40,15 +40,6 @@ const KNOWN_MULTI_ASSET_ENCODING = {
|
||||
'0x94cfcdd7000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000046000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000024f47261b00000000000000000000000001dc4c1cefef38a777b15aa20260a54e584b16c48000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044025717920000000000000000000000001dc4c1cefef38a777b15aa20260a54e584b16c480000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000204a7cb5fb70000000000000000000000001dc4c1cefef38a777b15aa20260a54e584b16c480000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000003e90000000000000000000000000000000000000000000000000000000000002711000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000c800000000000000000000000000000000000000000000000000000000000007d10000000000000000000000000000000000000000000000000000000000004e210000000000000000000000000000000000000000000000000000000000000044025717920000000000000000000000001dc4c1cefef38a777b15aa20260a54e584b16c4800000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
|
||||
};
|
||||
|
||||
const KNOWN_DUTCH_AUCTION_ENCODING = {
|
||||
tokenAddress: '0x34d402f14d58e001d8efbe6585051bf9706aa064',
|
||||
assetData: '0xf47261b000000000000000000000000034d402f14d58e001d8efbe6585051bf9706aa064', // ERC20
|
||||
beginTimeSeconds: new BigNumber(1562807905),
|
||||
beginAmount: new BigNumber(5),
|
||||
dutchAuctionAssetData:
|
||||
'0xf47261b000000000000000000000000034d402f14d58e001d8efbe6585051bf9706aa064000000000000000000000000000000000000000000000000000000005d268e610000000000000000000000000000000000000000000000000000000000000005',
|
||||
};
|
||||
|
||||
describe('assetDataUtils', () => {
|
||||
it('should encode ERC20', () => {
|
||||
const assetData = assetDataUtils.encodeERC20AssetData(KNOWN_ERC20_ENCODING.address);
|
||||
@ -184,28 +175,4 @@ describe('assetDataUtils', () => {
|
||||
expect(decodedErc1155AssetData2.tokenIds).to.be.deep.equal(KNOWN_ERC1155_ENCODING.tokenIds);
|
||||
expect(decodedErc1155AssetData2.callbackData).to.be.equal(KNOWN_ERC1155_ENCODING.callbackData);
|
||||
});
|
||||
it('should encode Dutch Auction', async () => {
|
||||
const encodedAssetData = assetDataUtils.encodeDutchAuctionAssetData(
|
||||
KNOWN_DUTCH_AUCTION_ENCODING.assetData,
|
||||
KNOWN_DUTCH_AUCTION_ENCODING.beginTimeSeconds,
|
||||
KNOWN_DUTCH_AUCTION_ENCODING.beginAmount,
|
||||
);
|
||||
expect(encodedAssetData).to.be.equal(KNOWN_DUTCH_AUCTION_ENCODING.dutchAuctionAssetData);
|
||||
});
|
||||
it('should decode Dutch Auction', async () => {
|
||||
const { assetData, beginTimeSeconds, beginAmount } = assetDataUtils.decodeDutchAuctionData(
|
||||
KNOWN_DUTCH_AUCTION_ENCODING.dutchAuctionAssetData,
|
||||
);
|
||||
|
||||
const { assetProxyId, tokenAddress } = assetDataUtils.decodeERC20AssetData(
|
||||
KNOWN_DUTCH_AUCTION_ENCODING.assetData,
|
||||
);
|
||||
|
||||
// tslint:disable:no-unnecessary-type-assertion
|
||||
expect((assetData as ERC20AssetData).assetProxyId).to.be.equal(assetProxyId);
|
||||
expect((assetData as ERC20AssetData).tokenAddress).to.be.equal(tokenAddress);
|
||||
// tslint:enable:no-unnecessary-type-assertion
|
||||
expect(beginTimeSeconds).to.deep.equal(KNOWN_DUTCH_AUCTION_ENCODING.beginTimeSeconds);
|
||||
expect(beginAmount).to.deep.equal(KNOWN_DUTCH_AUCTION_ENCODING.beginAmount);
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user