Merge pull request #884 from 0xProject/export-more-0x.js
Export missing V2 pieces from 0x.js
This commit is contained in:
commit
e2fb49a8f8
@ -36,6 +36,10 @@
|
|||||||
{
|
{
|
||||||
"note": "Remove stateLayer config from OrderWatcher. It now always operates on the latest block",
|
"note": "Remove stateLayer config from OrderWatcher. It now always operates on the latest block",
|
||||||
"pr": 875
|
"pr": 875
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"note": "Export ZeroEx.assetData with methods to decode/encode assetData fields found in 0x orders",
|
||||||
|
"pr": 884
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -10,6 +10,7 @@ import {
|
|||||||
ExchangeWrapper,
|
ExchangeWrapper,
|
||||||
} from '@0xproject/contract-wrappers';
|
} from '@0xproject/contract-wrappers';
|
||||||
import {
|
import {
|
||||||
|
assetDataUtils,
|
||||||
ecSignOrderHashAsync,
|
ecSignOrderHashAsync,
|
||||||
generatePseudoRandomSalt,
|
generatePseudoRandomSalt,
|
||||||
isValidSignatureAsync,
|
isValidSignatureAsync,
|
||||||
@ -34,6 +35,10 @@ export class ZeroEx {
|
|||||||
* this constant for your convenience.
|
* this constant for your convenience.
|
||||||
*/
|
*/
|
||||||
public static NULL_ADDRESS = constants.NULL_ADDRESS;
|
public static NULL_ADDRESS = constants.NULL_ADDRESS;
|
||||||
|
/**
|
||||||
|
* A set of methods to easily decode/encode assetData fields found in 0x orders.
|
||||||
|
*/
|
||||||
|
public static assetData = assetDataUtils;
|
||||||
/**
|
/**
|
||||||
* An instance of the ExchangeWrapper class containing methods for interacting with the 0x Exchange smart contract.
|
* An instance of the ExchangeWrapper class containing methods for interacting with the 0x Exchange smart contract.
|
||||||
*/
|
*/
|
||||||
|
@ -12,6 +12,9 @@ export {
|
|||||||
OrderStateInvalid,
|
OrderStateInvalid,
|
||||||
OrderState,
|
OrderState,
|
||||||
Token,
|
Token,
|
||||||
|
ERC20AssetData,
|
||||||
|
ERC721AssetData,
|
||||||
|
AssetProxyId,
|
||||||
} from '@0xproject/types';
|
} from '@0xproject/types';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@ -59,4 +62,5 @@ export {
|
|||||||
ExchangeCancelEventArgs,
|
ExchangeCancelEventArgs,
|
||||||
ExchangeEventArgs,
|
ExchangeEventArgs,
|
||||||
ContractWrappersConfig,
|
ContractWrappersConfig,
|
||||||
|
OrderInfo,
|
||||||
} from '@0xproject/contract-wrappers';
|
} from '@0xproject/contract-wrappers';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { BlockchainLifecycle, callbackErrorReporter } from '@0xproject/dev-utils';
|
import { BlockchainLifecycle, callbackErrorReporter } from '@0xproject/dev-utils';
|
||||||
import { FillScenarios } from '@0xproject/fill-scenarios';
|
import { FillScenarios } from '@0xproject/fill-scenarios';
|
||||||
import { assetProxyUtils, orderHashUtils } from '@0xproject/order-utils';
|
import { assetDataUtils, orderHashUtils } from '@0xproject/order-utils';
|
||||||
import { DoneCallback, SignedOrder } from '@0xproject/types';
|
import { DoneCallback, SignedOrder } from '@0xproject/types';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
@ -66,8 +66,8 @@ describe('ExchangeWrapper', () => {
|
|||||||
[coinbase, makerAddress, takerAddress, feeRecipient, anotherMakerAddress] = userAddresses;
|
[coinbase, makerAddress, takerAddress, feeRecipient, anotherMakerAddress] = userAddresses;
|
||||||
[makerTokenAddress, takerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses();
|
[makerTokenAddress, takerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses();
|
||||||
[makerAssetData, takerAssetData] = [
|
[makerAssetData, takerAssetData] = [
|
||||||
assetProxyUtils.encodeERC20AssetData(makerTokenAddress),
|
assetDataUtils.encodeERC20AssetData(makerTokenAddress),
|
||||||
assetProxyUtils.encodeERC20AssetData(takerTokenAddress),
|
assetDataUtils.encodeERC20AssetData(takerTokenAddress),
|
||||||
];
|
];
|
||||||
signedOrder = await fillScenarios.createFillableSignedOrderAsync(
|
signedOrder = await fillScenarios.createFillableSignedOrderAsync(
|
||||||
makerAssetData,
|
makerAssetData,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
||||||
import { assetProxyUtils, generatePseudoRandomSalt } from '@0xproject/order-utils';
|
import { assetDataUtils, generatePseudoRandomSalt } from '@0xproject/order-utils';
|
||||||
import { RevertReason } from '@0xproject/types';
|
import { RevertReason } from '@0xproject/types';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
@ -23,6 +23,7 @@ import { constants } from '../utils/constants';
|
|||||||
import { ERC20Wrapper } from '../utils/erc20_wrapper';
|
import { ERC20Wrapper } from '../utils/erc20_wrapper';
|
||||||
import { ERC721Wrapper } from '../utils/erc721_wrapper';
|
import { ERC721Wrapper } from '../utils/erc721_wrapper';
|
||||||
import { LogDecoder } from '../utils/log_decoder';
|
import { LogDecoder } from '../utils/log_decoder';
|
||||||
|
import { typeEncodingUtils } from '../utils/type_encoding_utils';
|
||||||
import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper';
|
import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper';
|
||||||
|
|
||||||
chaiSetup.configure();
|
chaiSetup.configure();
|
||||||
@ -107,7 +108,7 @@ describe('Asset Transfer Proxies', () => {
|
|||||||
describe('transferFrom', () => {
|
describe('transferFrom', () => {
|
||||||
it('should successfully transfer tokens', async () => {
|
it('should successfully transfer tokens', async () => {
|
||||||
// Construct ERC20 asset data
|
// Construct ERC20 asset data
|
||||||
const encodedAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address);
|
const encodedAssetData = assetDataUtils.encodeERC20AssetData(zrxToken.address);
|
||||||
// Perform a transfer from makerAddress to takerAddress
|
// Perform a transfer from makerAddress to takerAddress
|
||||||
const erc20Balances = await erc20Wrapper.getBalancesAsync();
|
const erc20Balances = await erc20Wrapper.getBalancesAsync();
|
||||||
const amount = new BigNumber(10);
|
const amount = new BigNumber(10);
|
||||||
@ -137,7 +138,7 @@ describe('Asset Transfer Proxies', () => {
|
|||||||
|
|
||||||
it('should do nothing if transferring 0 amount of a token', async () => {
|
it('should do nothing if transferring 0 amount of a token', async () => {
|
||||||
// Construct ERC20 asset data
|
// Construct ERC20 asset data
|
||||||
const encodedAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address);
|
const encodedAssetData = assetDataUtils.encodeERC20AssetData(zrxToken.address);
|
||||||
// Perform a transfer from makerAddress to takerAddress
|
// Perform a transfer from makerAddress to takerAddress
|
||||||
const erc20Balances = await erc20Wrapper.getBalancesAsync();
|
const erc20Balances = await erc20Wrapper.getBalancesAsync();
|
||||||
const amount = new BigNumber(0);
|
const amount = new BigNumber(0);
|
||||||
@ -167,7 +168,7 @@ describe('Asset Transfer Proxies', () => {
|
|||||||
|
|
||||||
it('should throw if allowances are too low', async () => {
|
it('should throw if allowances are too low', async () => {
|
||||||
// Construct ERC20 asset data
|
// Construct ERC20 asset data
|
||||||
const encodedAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address);
|
const encodedAssetData = assetDataUtils.encodeERC20AssetData(zrxToken.address);
|
||||||
// Create allowance less than transfer amount. Set allowance on proxy.
|
// Create allowance less than transfer amount. Set allowance on proxy.
|
||||||
const allowance = new BigNumber(0);
|
const allowance = new BigNumber(0);
|
||||||
const amount = new BigNumber(10);
|
const amount = new BigNumber(10);
|
||||||
@ -196,7 +197,7 @@ describe('Asset Transfer Proxies', () => {
|
|||||||
|
|
||||||
it('should throw if requesting address is not authorized', async () => {
|
it('should throw if requesting address is not authorized', async () => {
|
||||||
// Construct ERC20 asset data
|
// Construct ERC20 asset data
|
||||||
const encodedAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address);
|
const encodedAssetData = assetDataUtils.encodeERC20AssetData(zrxToken.address);
|
||||||
// Perform a transfer from makerAddress to takerAddress
|
// Perform a transfer from makerAddress to takerAddress
|
||||||
const amount = new BigNumber(10);
|
const amount = new BigNumber(10);
|
||||||
const data = assetProxyInterface.transferFrom.getABIEncodedTransactionData(
|
const data = assetProxyInterface.transferFrom.getABIEncodedTransactionData(
|
||||||
@ -227,7 +228,7 @@ describe('Asset Transfer Proxies', () => {
|
|||||||
describe('transferFrom', () => {
|
describe('transferFrom', () => {
|
||||||
it('should successfully transfer tokens', async () => {
|
it('should successfully transfer tokens', async () => {
|
||||||
// Construct ERC721 asset data
|
// Construct ERC721 asset data
|
||||||
const encodedAssetData = assetProxyUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId);
|
const encodedAssetData = assetDataUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId);
|
||||||
// Verify pre-condition
|
// Verify pre-condition
|
||||||
const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId);
|
const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId);
|
||||||
expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress);
|
expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress);
|
||||||
@ -254,7 +255,7 @@ describe('Asset Transfer Proxies', () => {
|
|||||||
|
|
||||||
it('should call onERC721Received when transferring to a smart contract without receiver data', async () => {
|
it('should call onERC721Received when transferring to a smart contract without receiver data', async () => {
|
||||||
// Construct ERC721 asset data
|
// Construct ERC721 asset data
|
||||||
const encodedAssetData = assetProxyUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId);
|
const encodedAssetData = assetDataUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId);
|
||||||
// Verify pre-condition
|
// Verify pre-condition
|
||||||
const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId);
|
const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId);
|
||||||
expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress);
|
expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress);
|
||||||
@ -288,8 +289,8 @@ describe('Asset Transfer Proxies', () => {
|
|||||||
|
|
||||||
it('should call onERC721Received when transferring to a smart contract with receiver data', async () => {
|
it('should call onERC721Received when transferring to a smart contract with receiver data', async () => {
|
||||||
// Construct ERC721 asset data
|
// Construct ERC721 asset data
|
||||||
const receiverData = ethUtil.bufferToHex(assetProxyUtils.encodeUint256(generatePseudoRandomSalt()));
|
const receiverData = ethUtil.bufferToHex(typeEncodingUtils.encodeUint256(generatePseudoRandomSalt()));
|
||||||
const encodedAssetData = assetProxyUtils.encodeERC721AssetData(
|
const encodedAssetData = assetDataUtils.encodeERC721AssetData(
|
||||||
erc721Token.address,
|
erc721Token.address,
|
||||||
erc721MakerTokenId,
|
erc721MakerTokenId,
|
||||||
receiverData,
|
receiverData,
|
||||||
@ -327,8 +328,8 @@ describe('Asset Transfer Proxies', () => {
|
|||||||
|
|
||||||
it('should throw if there is receiver data but contract does not have onERC721Received', async () => {
|
it('should throw if there is receiver data but contract does not have onERC721Received', async () => {
|
||||||
// Construct ERC721 asset data
|
// Construct ERC721 asset data
|
||||||
const receiverData = ethUtil.bufferToHex(assetProxyUtils.encodeUint256(generatePseudoRandomSalt()));
|
const receiverData = ethUtil.bufferToHex(typeEncodingUtils.encodeUint256(generatePseudoRandomSalt()));
|
||||||
const encodedAssetData = assetProxyUtils.encodeERC721AssetData(
|
const encodedAssetData = assetDataUtils.encodeERC721AssetData(
|
||||||
erc721Token.address,
|
erc721Token.address,
|
||||||
erc721MakerTokenId,
|
erc721MakerTokenId,
|
||||||
receiverData,
|
receiverData,
|
||||||
@ -357,7 +358,7 @@ describe('Asset Transfer Proxies', () => {
|
|||||||
|
|
||||||
it('should throw if transferring 0 amount of a token', async () => {
|
it('should throw if transferring 0 amount of a token', async () => {
|
||||||
// Construct ERC721 asset data
|
// Construct ERC721 asset data
|
||||||
const encodedAssetData = assetProxyUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId);
|
const encodedAssetData = assetDataUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId);
|
||||||
// Verify pre-condition
|
// Verify pre-condition
|
||||||
const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId);
|
const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId);
|
||||||
expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress);
|
expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress);
|
||||||
@ -381,7 +382,7 @@ describe('Asset Transfer Proxies', () => {
|
|||||||
|
|
||||||
it('should throw if transferring > 1 amount of a token', async () => {
|
it('should throw if transferring > 1 amount of a token', async () => {
|
||||||
// Construct ERC721 asset data
|
// Construct ERC721 asset data
|
||||||
const encodedAssetData = assetProxyUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId);
|
const encodedAssetData = assetDataUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId);
|
||||||
// Verify pre-condition
|
// Verify pre-condition
|
||||||
const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId);
|
const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId);
|
||||||
expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress);
|
expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress);
|
||||||
@ -405,7 +406,7 @@ describe('Asset Transfer Proxies', () => {
|
|||||||
|
|
||||||
it('should throw if allowances are too low', async () => {
|
it('should throw if allowances are too low', async () => {
|
||||||
// Construct ERC721 asset data
|
// Construct ERC721 asset data
|
||||||
const encodedAssetData = assetProxyUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId);
|
const encodedAssetData = assetDataUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId);
|
||||||
// Remove transfer approval for makerAddress.
|
// Remove transfer approval for makerAddress.
|
||||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||||
await erc721Token.approve.sendTransactionAsync(constants.NULL_ADDRESS, erc721MakerTokenId, {
|
await erc721Token.approve.sendTransactionAsync(constants.NULL_ADDRESS, erc721MakerTokenId, {
|
||||||
@ -433,7 +434,7 @@ describe('Asset Transfer Proxies', () => {
|
|||||||
|
|
||||||
it('should throw if requesting address is not authorized', async () => {
|
it('should throw if requesting address is not authorized', async () => {
|
||||||
// Construct ERC721 asset data
|
// Construct ERC721 asset data
|
||||||
const encodedAssetData = assetProxyUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId);
|
const encodedAssetData = assetDataUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId);
|
||||||
// Perform a transfer from makerAddress to takerAddress
|
// Perform a transfer from makerAddress to takerAddress
|
||||||
const amount = new BigNumber(1);
|
const amount = new BigNumber(1);
|
||||||
const data = assetProxyInterface.transferFrom.getABIEncodedTransactionData(
|
const data = assetProxyInterface.transferFrom.getABIEncodedTransactionData(
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
||||||
import { assetProxyUtils, orderHashUtils } from '@0xproject/order-utils';
|
import { assetDataUtils, orderHashUtils } from '@0xproject/order-utils';
|
||||||
import { RevertReason, SignedOrder } from '@0xproject/types';
|
import { RevertReason, SignedOrder } from '@0xproject/types';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||||
@ -88,7 +88,7 @@ describe('Exchange core', () => {
|
|||||||
artifacts.Exchange,
|
artifacts.Exchange,
|
||||||
provider,
|
provider,
|
||||||
txDefaults,
|
txDefaults,
|
||||||
assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
);
|
);
|
||||||
exchangeWrapper = new ExchangeWrapper(exchange, provider);
|
exchangeWrapper = new ExchangeWrapper(exchange, provider);
|
||||||
await exchangeWrapper.registerAssetProxyAsync(erc20Proxy.address, owner);
|
await exchangeWrapper.registerAssetProxyAsync(erc20Proxy.address, owner);
|
||||||
@ -115,8 +115,8 @@ describe('Exchange core', () => {
|
|||||||
exchangeAddress: exchange.address,
|
exchangeAddress: exchange.address,
|
||||||
makerAddress,
|
makerAddress,
|
||||||
feeRecipientAddress,
|
feeRecipientAddress,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultMakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultMakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultTakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultTakerAssetAddress),
|
||||||
};
|
};
|
||||||
const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
|
const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
|
||||||
orderFactory = new OrderFactory(privateKey, defaultOrderParams);
|
orderFactory = new OrderFactory(privateKey, defaultOrderParams);
|
||||||
@ -355,8 +355,8 @@ describe('Exchange core', () => {
|
|||||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetAmount: new BigNumber(1),
|
makerAssetAmount: new BigNumber(1),
|
||||||
takerAssetAmount: new BigNumber(1),
|
takerAssetAmount: new BigNumber(1),
|
||||||
makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
makerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
||||||
takerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, takerAssetId),
|
takerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, takerAssetId),
|
||||||
});
|
});
|
||||||
// Verify pre-conditions
|
// Verify pre-conditions
|
||||||
const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
|
const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
|
||||||
@ -378,8 +378,8 @@ describe('Exchange core', () => {
|
|||||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetAmount: new BigNumber(1),
|
makerAssetAmount: new BigNumber(1),
|
||||||
takerAssetAmount: new BigNumber(1),
|
takerAssetAmount: new BigNumber(1),
|
||||||
makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
makerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
||||||
takerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, takerAssetId),
|
takerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, takerAssetId),
|
||||||
});
|
});
|
||||||
// Verify pre-conditions
|
// Verify pre-conditions
|
||||||
const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
|
const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
|
||||||
@ -401,8 +401,8 @@ describe('Exchange core', () => {
|
|||||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetAmount: new BigNumber(2),
|
makerAssetAmount: new BigNumber(2),
|
||||||
takerAssetAmount: new BigNumber(1),
|
takerAssetAmount: new BigNumber(1),
|
||||||
makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
makerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
||||||
takerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, takerAssetId),
|
takerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, takerAssetId),
|
||||||
});
|
});
|
||||||
// Verify pre-conditions
|
// Verify pre-conditions
|
||||||
const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
|
const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
|
||||||
@ -424,8 +424,8 @@ describe('Exchange core', () => {
|
|||||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetAmount: new BigNumber(1),
|
makerAssetAmount: new BigNumber(1),
|
||||||
takerAssetAmount: new BigNumber(500),
|
takerAssetAmount: new BigNumber(500),
|
||||||
makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
makerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
||||||
takerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, takerAssetId),
|
takerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, takerAssetId),
|
||||||
});
|
});
|
||||||
// Verify pre-conditions
|
// Verify pre-conditions
|
||||||
const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
|
const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
|
||||||
@ -446,8 +446,8 @@ describe('Exchange core', () => {
|
|||||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetAmount: new BigNumber(1),
|
makerAssetAmount: new BigNumber(1),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
|
||||||
makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
makerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultTakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultTakerAssetAddress),
|
||||||
});
|
});
|
||||||
// Call Exchange
|
// Call Exchange
|
||||||
const takerAssetFillAmount = signedOrder.takerAssetAmount.div(2);
|
const takerAssetFillAmount = signedOrder.takerAssetAmount.div(2);
|
||||||
@ -461,14 +461,12 @@ describe('Exchange core', () => {
|
|||||||
// Construct Exchange parameters
|
// Construct Exchange parameters
|
||||||
const makerAssetId = erc721MakerAssetIds[0];
|
const makerAssetId = erc721MakerAssetIds[0];
|
||||||
const takerAssetId = erc721TakerAssetIds[0];
|
const takerAssetId = erc721TakerAssetIds[0];
|
||||||
const makerAssetData = assetProxyUtils
|
const makerAssetData = assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId).slice(0, -2);
|
||||||
.encodeERC721AssetData(erc721Token.address, makerAssetId)
|
|
||||||
.slice(0, -2);
|
|
||||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetAmount: new BigNumber(1),
|
makerAssetAmount: new BigNumber(1),
|
||||||
takerAssetAmount: new BigNumber(1),
|
takerAssetAmount: new BigNumber(1),
|
||||||
makerAssetData,
|
makerAssetData,
|
||||||
takerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, takerAssetId),
|
takerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, takerAssetId),
|
||||||
});
|
});
|
||||||
// Verify pre-conditions
|
// Verify pre-conditions
|
||||||
const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
|
const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
||||||
import { assetProxyUtils } from '@0xproject/order-utils';
|
import { assetDataUtils } from '@0xproject/order-utils';
|
||||||
import { AssetProxyId, RevertReason } from '@0xproject/types';
|
import { AssetProxyId, RevertReason } from '@0xproject/types';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
@ -180,7 +180,7 @@ describe('AssetProxyDispatcher', () => {
|
|||||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||||
);
|
);
|
||||||
// Construct metadata for ERC20 proxy
|
// Construct metadata for ERC20 proxy
|
||||||
const encodedAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address);
|
const encodedAssetData = assetDataUtils.encodeERC20AssetData(zrxToken.address);
|
||||||
|
|
||||||
// Perform a transfer from makerAddress to takerAddress
|
// Perform a transfer from makerAddress to takerAddress
|
||||||
const erc20Balances = await erc20Wrapper.getBalancesAsync();
|
const erc20Balances = await erc20Wrapper.getBalancesAsync();
|
||||||
@ -207,7 +207,7 @@ describe('AssetProxyDispatcher', () => {
|
|||||||
|
|
||||||
it('should throw if dispatching to unregistered proxy', async () => {
|
it('should throw if dispatching to unregistered proxy', async () => {
|
||||||
// Construct metadata for ERC20 proxy
|
// Construct metadata for ERC20 proxy
|
||||||
const encodedAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address);
|
const encodedAssetData = assetDataUtils.encodeERC20AssetData(zrxToken.address);
|
||||||
// Perform a transfer from makerAddress to takerAddress
|
// Perform a transfer from makerAddress to takerAddress
|
||||||
const amount = new BigNumber(10);
|
const amount = new BigNumber(10);
|
||||||
return expectTransactionFailedAsync(
|
return expectTransactionFailedAsync(
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
||||||
import { assetProxyUtils, EIP712Utils, orderHashUtils } from '@0xproject/order-utils';
|
import { assetDataUtils, EIP712Utils, orderHashUtils } from '@0xproject/order-utils';
|
||||||
import { SignedOrder } from '@0xproject/types';
|
import { SignedOrder } from '@0xproject/types';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
@ -38,8 +38,8 @@ describe('Exchange libs', () => {
|
|||||||
exchangeAddress: libs.address,
|
exchangeAddress: libs.address,
|
||||||
makerAddress,
|
makerAddress,
|
||||||
feeRecipientAddress: addressUtils.generatePseudoRandomAddress(),
|
feeRecipientAddress: addressUtils.generatePseudoRandomAddress(),
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(addressUtils.generatePseudoRandomAddress()),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(addressUtils.generatePseudoRandomAddress()),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(addressUtils.generatePseudoRandomAddress()),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(addressUtils.generatePseudoRandomAddress()),
|
||||||
};
|
};
|
||||||
const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
|
const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
|
||||||
orderFactory = new OrderFactory(privateKey, defaultOrderParams);
|
orderFactory = new OrderFactory(privateKey, defaultOrderParams);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
||||||
import { assetProxyUtils } from '@0xproject/order-utils';
|
import { assetDataUtils } from '@0xproject/order-utils';
|
||||||
import { RevertReason } from '@0xproject/types';
|
import { RevertReason } from '@0xproject/types';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||||
@ -100,7 +100,7 @@ describe('matchOrders', () => {
|
|||||||
artifacts.Exchange,
|
artifacts.Exchange,
|
||||||
provider,
|
provider,
|
||||||
txDefaults,
|
txDefaults,
|
||||||
assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
);
|
);
|
||||||
exchangeWrapper = new ExchangeWrapper(exchange, provider);
|
exchangeWrapper = new ExchangeWrapper(exchange, provider);
|
||||||
await exchangeWrapper.registerAssetProxyAsync(erc20Proxy.address, owner);
|
await exchangeWrapper.registerAssetProxyAsync(erc20Proxy.address, owner);
|
||||||
@ -126,8 +126,8 @@ describe('matchOrders', () => {
|
|||||||
const defaultOrderParams = {
|
const defaultOrderParams = {
|
||||||
...constants.STATIC_ORDER_PARAMS,
|
...constants.STATIC_ORDER_PARAMS,
|
||||||
exchangeAddress: exchange.address,
|
exchangeAddress: exchange.address,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||||
};
|
};
|
||||||
const privateKeyLeft = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddressLeft)];
|
const privateKeyLeft = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddressLeft)];
|
||||||
orderFactoryLeft = new OrderFactory(privateKeyLeft, defaultOrderParams);
|
orderFactoryLeft = new OrderFactory(privateKeyLeft, defaultOrderParams);
|
||||||
@ -158,8 +158,8 @@ describe('matchOrders', () => {
|
|||||||
});
|
});
|
||||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||||
makerAddress: makerAddressRight,
|
makerAddress: makerAddressRight,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
||||||
feeRecipientAddress: feeRecipientAddressRight,
|
feeRecipientAddress: feeRecipientAddressRight,
|
||||||
@ -190,8 +190,8 @@ describe('matchOrders', () => {
|
|||||||
});
|
});
|
||||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||||
makerAddress: makerAddressRight,
|
makerAddress: makerAddressRight,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18),
|
||||||
feeRecipientAddress: feeRecipientAddressRight,
|
feeRecipientAddress: feeRecipientAddressRight,
|
||||||
@ -233,8 +233,8 @@ describe('matchOrders', () => {
|
|||||||
});
|
});
|
||||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||||
makerAddress: makerAddressRight,
|
makerAddress: makerAddressRight,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(20), 18),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(20), 18),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(4), 18),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(4), 18),
|
||||||
feeRecipientAddress: feeRecipientAddressRight,
|
feeRecipientAddress: feeRecipientAddressRight,
|
||||||
@ -265,8 +265,8 @@ describe('matchOrders', () => {
|
|||||||
});
|
});
|
||||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||||
makerAddress: makerAddressRight,
|
makerAddress: makerAddressRight,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
||||||
feeRecipientAddress: feeRecipientAddressRight,
|
feeRecipientAddress: feeRecipientAddressRight,
|
||||||
@ -297,8 +297,8 @@ describe('matchOrders', () => {
|
|||||||
});
|
});
|
||||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||||
makerAddress: makerAddressRight,
|
makerAddress: makerAddressRight,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
||||||
feeRecipientAddress: feeRecipientAddressRight,
|
feeRecipientAddress: feeRecipientAddressRight,
|
||||||
@ -328,8 +328,8 @@ describe('matchOrders', () => {
|
|||||||
// branch in the contract twice for this test.
|
// branch in the contract twice for this test.
|
||||||
const signedOrderRight2 = await orderFactoryRight.newSignedOrderAsync({
|
const signedOrderRight2 = await orderFactoryRight.newSignedOrderAsync({
|
||||||
makerAddress: makerAddressRight,
|
makerAddress: makerAddressRight,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18),
|
||||||
feeRecipientAddress: feeRecipientAddressRight,
|
feeRecipientAddress: feeRecipientAddressRight,
|
||||||
@ -365,8 +365,8 @@ describe('matchOrders', () => {
|
|||||||
|
|
||||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||||
makerAddress: makerAddressRight,
|
makerAddress: makerAddressRight,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
|
||||||
feeRecipientAddress: feeRecipientAddressRight,
|
feeRecipientAddress: feeRecipientAddressRight,
|
||||||
@ -433,8 +433,8 @@ describe('matchOrders', () => {
|
|||||||
});
|
});
|
||||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||||
makerAddress: makerAddressRight,
|
makerAddress: makerAddressRight,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
||||||
feeRecipientAddress,
|
feeRecipientAddress,
|
||||||
@ -459,8 +459,8 @@ describe('matchOrders', () => {
|
|||||||
});
|
});
|
||||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||||
makerAddress: makerAddressRight,
|
makerAddress: makerAddressRight,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
||||||
feeRecipientAddress: feeRecipientAddressRight,
|
feeRecipientAddress: feeRecipientAddressRight,
|
||||||
@ -486,8 +486,8 @@ describe('matchOrders', () => {
|
|||||||
});
|
});
|
||||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||||
makerAddress: makerAddressRight,
|
makerAddress: makerAddressRight,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
||||||
feeRecipientAddress: feeRecipientAddressRight,
|
feeRecipientAddress: feeRecipientAddressRight,
|
||||||
@ -513,8 +513,8 @@ describe('matchOrders', () => {
|
|||||||
});
|
});
|
||||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||||
makerAddress: makerAddressRight,
|
makerAddress: makerAddressRight,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
||||||
feeRecipientAddress: feeRecipientAddressRight,
|
feeRecipientAddress: feeRecipientAddressRight,
|
||||||
@ -540,8 +540,8 @@ describe('matchOrders', () => {
|
|||||||
});
|
});
|
||||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||||
makerAddress: makerAddressRight,
|
makerAddress: makerAddressRight,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
||||||
feeRecipientAddress: feeRecipientAddressRight,
|
feeRecipientAddress: feeRecipientAddressRight,
|
||||||
@ -567,8 +567,8 @@ describe('matchOrders', () => {
|
|||||||
});
|
});
|
||||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||||
makerAddress: makerAddressRight,
|
makerAddress: makerAddressRight,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
||||||
feeRecipientAddress: makerAddressRight,
|
feeRecipientAddress: makerAddressRight,
|
||||||
@ -593,8 +593,8 @@ describe('matchOrders', () => {
|
|||||||
});
|
});
|
||||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||||
makerAddress: makerAddressRight,
|
makerAddress: makerAddressRight,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
||||||
feeRecipientAddress: feeRecipientAddressRight,
|
feeRecipientAddress: feeRecipientAddressRight,
|
||||||
@ -618,8 +618,8 @@ describe('matchOrders', () => {
|
|||||||
});
|
});
|
||||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||||
makerAddress: makerAddressRight,
|
makerAddress: makerAddressRight,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
||||||
feeRecipientAddress: feeRecipientAddressRight,
|
feeRecipientAddress: feeRecipientAddressRight,
|
||||||
@ -643,8 +643,8 @@ describe('matchOrders', () => {
|
|||||||
});
|
});
|
||||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||||
makerAddress: makerAddressRight,
|
makerAddress: makerAddressRight,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18),
|
||||||
feeRecipientAddress: feeRecipientAddressRight,
|
feeRecipientAddress: feeRecipientAddressRight,
|
||||||
@ -666,8 +666,8 @@ describe('matchOrders', () => {
|
|||||||
});
|
});
|
||||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||||
makerAddress: makerAddressRight,
|
makerAddress: makerAddressRight,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
||||||
feeRecipientAddress: feeRecipientAddressRight,
|
feeRecipientAddress: feeRecipientAddressRight,
|
||||||
@ -687,16 +687,16 @@ describe('matchOrders', () => {
|
|||||||
// Create orders to match
|
// Create orders to match
|
||||||
const signedOrderLeft = await orderFactoryLeft.newSignedOrderAsync({
|
const signedOrderLeft = await orderFactoryLeft.newSignedOrderAsync({
|
||||||
makerAddress: makerAddressLeft,
|
makerAddress: makerAddressLeft,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
||||||
feeRecipientAddress: feeRecipientAddressLeft,
|
feeRecipientAddress: feeRecipientAddressLeft,
|
||||||
});
|
});
|
||||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||||
makerAddress: makerAddressRight,
|
makerAddress: makerAddressRight,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18),
|
||||||
feeRecipientAddress: feeRecipientAddressRight,
|
feeRecipientAddress: feeRecipientAddressRight,
|
||||||
@ -713,16 +713,16 @@ describe('matchOrders', () => {
|
|||||||
const erc721TokenToTransfer = erc721LeftMakerAssetIds[0];
|
const erc721TokenToTransfer = erc721LeftMakerAssetIds[0];
|
||||||
const signedOrderLeft = await orderFactoryLeft.newSignedOrderAsync({
|
const signedOrderLeft = await orderFactoryLeft.newSignedOrderAsync({
|
||||||
makerAddress: makerAddressLeft,
|
makerAddress: makerAddressLeft,
|
||||||
makerAssetData: assetProxyUtils.encodeERC721AssetData(defaultERC721AssetAddress, erc721TokenToTransfer),
|
makerAssetData: assetDataUtils.encodeERC721AssetData(defaultERC721AssetAddress, erc721TokenToTransfer),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||||
makerAssetAmount: new BigNumber(1),
|
makerAssetAmount: new BigNumber(1),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
||||||
feeRecipientAddress: feeRecipientAddressLeft,
|
feeRecipientAddress: feeRecipientAddressLeft,
|
||||||
});
|
});
|
||||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||||
makerAddress: makerAddressRight,
|
makerAddress: makerAddressRight,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC721AssetData(defaultERC721AssetAddress, erc721TokenToTransfer),
|
takerAssetData: assetDataUtils.encodeERC721AssetData(defaultERC721AssetAddress, erc721TokenToTransfer),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
||||||
takerAssetAmount: new BigNumber(1),
|
takerAssetAmount: new BigNumber(1),
|
||||||
feeRecipientAddress: feeRecipientAddressRight,
|
feeRecipientAddress: feeRecipientAddressRight,
|
||||||
@ -748,16 +748,16 @@ describe('matchOrders', () => {
|
|||||||
const erc721TokenToTransfer = erc721RightMakerAssetIds[0];
|
const erc721TokenToTransfer = erc721RightMakerAssetIds[0];
|
||||||
const signedOrderLeft = await orderFactoryLeft.newSignedOrderAsync({
|
const signedOrderLeft = await orderFactoryLeft.newSignedOrderAsync({
|
||||||
makerAddress: makerAddressLeft,
|
makerAddress: makerAddressLeft,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC721AssetData(defaultERC721AssetAddress, erc721TokenToTransfer),
|
takerAssetData: assetDataUtils.encodeERC721AssetData(defaultERC721AssetAddress, erc721TokenToTransfer),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
||||||
takerAssetAmount: new BigNumber(1),
|
takerAssetAmount: new BigNumber(1),
|
||||||
feeRecipientAddress: feeRecipientAddressLeft,
|
feeRecipientAddress: feeRecipientAddressLeft,
|
||||||
});
|
});
|
||||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||||
makerAddress: makerAddressRight,
|
makerAddress: makerAddressRight,
|
||||||
makerAssetData: assetProxyUtils.encodeERC721AssetData(defaultERC721AssetAddress, erc721TokenToTransfer),
|
makerAssetData: assetDataUtils.encodeERC721AssetData(defaultERC721AssetAddress, erc721TokenToTransfer),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||||
makerAssetAmount: new BigNumber(1),
|
makerAssetAmount: new BigNumber(1),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18),
|
||||||
feeRecipientAddress: feeRecipientAddressRight,
|
feeRecipientAddress: feeRecipientAddressRight,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
||||||
import { addSignedMessagePrefix, assetProxyUtils, MessagePrefixType, orderHashUtils } from '@0xproject/order-utils';
|
import { addSignedMessagePrefix, assetDataUtils, MessagePrefixType, orderHashUtils } from '@0xproject/order-utils';
|
||||||
import { RevertReason, SignatureType, SignedOrder } from '@0xproject/types';
|
import { RevertReason, SignatureType, SignedOrder } from '@0xproject/types';
|
||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
import { LogWithDecodedArgs } from 'ethereum-types';
|
import { LogWithDecodedArgs } from 'ethereum-types';
|
||||||
@ -78,8 +78,8 @@ describe('MixinSignatureValidator', () => {
|
|||||||
exchangeAddress: signatureValidator.address,
|
exchangeAddress: signatureValidator.address,
|
||||||
makerAddress,
|
makerAddress,
|
||||||
feeRecipientAddress: addressUtils.generatePseudoRandomAddress(),
|
feeRecipientAddress: addressUtils.generatePseudoRandomAddress(),
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(addressUtils.generatePseudoRandomAddress()),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(addressUtils.generatePseudoRandomAddress()),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(addressUtils.generatePseudoRandomAddress()),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(addressUtils.generatePseudoRandomAddress()),
|
||||||
};
|
};
|
||||||
signerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
|
signerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
|
||||||
notSignerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(notSignerAddress)];
|
notSignerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(notSignerAddress)];
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
||||||
import { assetProxyUtils, generatePseudoRandomSalt } from '@0xproject/order-utils';
|
import { assetDataUtils, generatePseudoRandomSalt } from '@0xproject/order-utils';
|
||||||
import { OrderWithoutExchangeAddress, RevertReason, SignedOrder } from '@0xproject/types';
|
import { OrderWithoutExchangeAddress, RevertReason, SignedOrder } from '@0xproject/types';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
@ -88,7 +88,7 @@ describe('Exchange transactions', () => {
|
|||||||
artifacts.Exchange,
|
artifacts.Exchange,
|
||||||
provider,
|
provider,
|
||||||
txDefaults,
|
txDefaults,
|
||||||
assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
);
|
);
|
||||||
exchangeWrapper = new ExchangeWrapper(exchange, provider);
|
exchangeWrapper = new ExchangeWrapper(exchange, provider);
|
||||||
await exchangeWrapper.registerAssetProxyAsync(erc20Proxy.address, owner);
|
await exchangeWrapper.registerAssetProxyAsync(erc20Proxy.address, owner);
|
||||||
@ -107,8 +107,8 @@ describe('Exchange transactions', () => {
|
|||||||
exchangeAddress: exchange.address,
|
exchangeAddress: exchange.address,
|
||||||
makerAddress,
|
makerAddress,
|
||||||
feeRecipientAddress,
|
feeRecipientAddress,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultMakerTokenAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultMakerTokenAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultTakerTokenAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultTakerTokenAddress),
|
||||||
};
|
};
|
||||||
makerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
|
makerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
|
||||||
takerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(takerAddress)];
|
takerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(takerAddress)];
|
||||||
@ -349,8 +349,8 @@ describe('Exchange transactions', () => {
|
|||||||
exchangeAddress: exchange.address,
|
exchangeAddress: exchange.address,
|
||||||
makerAddress,
|
makerAddress,
|
||||||
feeRecipientAddress,
|
feeRecipientAddress,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultMakerTokenAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultMakerTokenAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultTakerTokenAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultTakerTokenAddress),
|
||||||
};
|
};
|
||||||
whitelistOrderFactory = new OrderFactory(makerPrivateKey, defaultOrderParams);
|
whitelistOrderFactory = new OrderFactory(makerPrivateKey, defaultOrderParams);
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
||||||
import { assetProxyUtils, orderHashUtils } from '@0xproject/order-utils';
|
import { assetDataUtils, orderHashUtils } from '@0xproject/order-utils';
|
||||||
import { RevertReason, SignedOrder } from '@0xproject/types';
|
import { RevertReason, SignedOrder } from '@0xproject/types';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||||
@ -85,7 +85,7 @@ describe('Exchange wrappers', () => {
|
|||||||
artifacts.Exchange,
|
artifacts.Exchange,
|
||||||
provider,
|
provider,
|
||||||
txDefaults,
|
txDefaults,
|
||||||
assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
);
|
);
|
||||||
exchangeWrapper = new ExchangeWrapper(exchange, provider);
|
exchangeWrapper = new ExchangeWrapper(exchange, provider);
|
||||||
await exchangeWrapper.registerAssetProxyAsync(erc20Proxy.address, owner);
|
await exchangeWrapper.registerAssetProxyAsync(erc20Proxy.address, owner);
|
||||||
@ -112,8 +112,8 @@ describe('Exchange wrappers', () => {
|
|||||||
exchangeAddress: exchange.address,
|
exchangeAddress: exchange.address,
|
||||||
makerAddress,
|
makerAddress,
|
||||||
feeRecipientAddress,
|
feeRecipientAddress,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultMakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultMakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultTakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultTakerAssetAddress),
|
||||||
};
|
};
|
||||||
const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
|
const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
|
||||||
orderFactory = new OrderFactory(privateKey, defaultOrderParams);
|
orderFactory = new OrderFactory(privateKey, defaultOrderParams);
|
||||||
@ -311,7 +311,7 @@ describe('Exchange wrappers', () => {
|
|||||||
const signedOrder = await orderFactory.newSignedOrderAsync({
|
const signedOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetAmount: makerZRXBalance,
|
makerAssetAmount: makerZRXBalance,
|
||||||
makerFee: new BigNumber(1),
|
makerFee: new BigNumber(1),
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
});
|
});
|
||||||
await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress);
|
await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress);
|
||||||
const newBalances = await erc20Wrapper.getBalancesAsync();
|
const newBalances = await erc20Wrapper.getBalancesAsync();
|
||||||
@ -323,7 +323,7 @@ describe('Exchange wrappers', () => {
|
|||||||
const signedOrder = await orderFactory.newSignedOrderAsync({
|
const signedOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetAmount: new BigNumber(makerZRXAllowance),
|
makerAssetAmount: new BigNumber(makerZRXAllowance),
|
||||||
makerFee: new BigNumber(1),
|
makerFee: new BigNumber(1),
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
});
|
});
|
||||||
await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress);
|
await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress);
|
||||||
const newBalances = await erc20Wrapper.getBalancesAsync();
|
const newBalances = await erc20Wrapper.getBalancesAsync();
|
||||||
@ -335,7 +335,7 @@ describe('Exchange wrappers', () => {
|
|||||||
const signedOrder = await orderFactory.newSignedOrderAsync({
|
const signedOrder = await orderFactory.newSignedOrderAsync({
|
||||||
takerAssetAmount: takerZRXBalance,
|
takerAssetAmount: takerZRXBalance,
|
||||||
takerFee: new BigNumber(1),
|
takerFee: new BigNumber(1),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
});
|
});
|
||||||
await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress);
|
await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress);
|
||||||
const newBalances = await erc20Wrapper.getBalancesAsync();
|
const newBalances = await erc20Wrapper.getBalancesAsync();
|
||||||
@ -347,7 +347,7 @@ describe('Exchange wrappers', () => {
|
|||||||
const signedOrder = await orderFactory.newSignedOrderAsync({
|
const signedOrder = await orderFactory.newSignedOrderAsync({
|
||||||
takerAssetAmount: new BigNumber(takerZRXAllowance),
|
takerAssetAmount: new BigNumber(takerZRXAllowance),
|
||||||
takerFee: new BigNumber(1),
|
takerFee: new BigNumber(1),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
});
|
});
|
||||||
await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress);
|
await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress);
|
||||||
const newBalances = await erc20Wrapper.getBalancesAsync();
|
const newBalances = await erc20Wrapper.getBalancesAsync();
|
||||||
@ -361,8 +361,8 @@ describe('Exchange wrappers', () => {
|
|||||||
const signedOrder = await orderFactory.newSignedOrderAsync({
|
const signedOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetAmount: new BigNumber(1),
|
makerAssetAmount: new BigNumber(1),
|
||||||
takerAssetAmount: new BigNumber(1),
|
takerAssetAmount: new BigNumber(1),
|
||||||
makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
makerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
||||||
takerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, takerAssetId),
|
takerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, takerAssetId),
|
||||||
});
|
});
|
||||||
// Verify pre-conditions
|
// Verify pre-conditions
|
||||||
const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
|
const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
|
||||||
@ -700,7 +700,7 @@ describe('Exchange wrappers', () => {
|
|||||||
signedOrders = [
|
signedOrders = [
|
||||||
await orderFactory.newSignedOrderAsync(),
|
await orderFactory.newSignedOrderAsync(),
|
||||||
await orderFactory.newSignedOrderAsync({
|
await orderFactory.newSignedOrderAsync({
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
}),
|
}),
|
||||||
await orderFactory.newSignedOrderAsync(),
|
await orderFactory.newSignedOrderAsync(),
|
||||||
];
|
];
|
||||||
@ -801,7 +801,7 @@ describe('Exchange wrappers', () => {
|
|||||||
await orderFactory.newSignedOrderAsync(),
|
await orderFactory.newSignedOrderAsync(),
|
||||||
await orderFactory.newSignedOrderAsync(),
|
await orderFactory.newSignedOrderAsync(),
|
||||||
await orderFactory.newSignedOrderAsync({
|
await orderFactory.newSignedOrderAsync({
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
const takerAssetFillAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(100000), 18);
|
const takerAssetFillAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(100000), 18);
|
||||||
@ -918,7 +918,7 @@ describe('Exchange wrappers', () => {
|
|||||||
signedOrders = [
|
signedOrders = [
|
||||||
await orderFactory.newSignedOrderAsync(),
|
await orderFactory.newSignedOrderAsync(),
|
||||||
await orderFactory.newSignedOrderAsync({
|
await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
}),
|
}),
|
||||||
await orderFactory.newSignedOrderAsync(),
|
await orderFactory.newSignedOrderAsync(),
|
||||||
];
|
];
|
||||||
@ -1017,7 +1017,7 @@ describe('Exchange wrappers', () => {
|
|||||||
await orderFactory.newSignedOrderAsync(),
|
await orderFactory.newSignedOrderAsync(),
|
||||||
await orderFactory.newSignedOrderAsync(),
|
await orderFactory.newSignedOrderAsync(),
|
||||||
await orderFactory.newSignedOrderAsync({
|
await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
||||||
import { assetProxyUtils } from '@0xproject/order-utils';
|
import { assetDataUtils } from '@0xproject/order-utils';
|
||||||
import { RevertReason, SignedOrder } from '@0xproject/types';
|
import { RevertReason, SignedOrder } from '@0xproject/types';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||||
@ -88,8 +88,8 @@ describe(ContractName.Forwarder, () => {
|
|||||||
weth = new DummyERC20TokenContract(wethContract.abi, wethContract.address, provider);
|
weth = new DummyERC20TokenContract(wethContract.abi, wethContract.address, provider);
|
||||||
erc20Wrapper.addDummyTokenContract(weth);
|
erc20Wrapper.addDummyTokenContract(weth);
|
||||||
|
|
||||||
const wethAssetData = assetProxyUtils.encodeERC20AssetData(wethContract.address);
|
const wethAssetData = assetDataUtils.encodeERC20AssetData(wethContract.address);
|
||||||
const zrxAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address);
|
const zrxAssetData = assetDataUtils.encodeERC20AssetData(zrxToken.address);
|
||||||
const exchangeInstance = await ExchangeContract.deployFrom0xArtifactAsync(
|
const exchangeInstance = await ExchangeContract.deployFrom0xArtifactAsync(
|
||||||
artifacts.Exchange,
|
artifacts.Exchange,
|
||||||
provider,
|
provider,
|
||||||
@ -114,8 +114,8 @@ describe(ContractName.Forwarder, () => {
|
|||||||
exchangeAddress: exchangeInstance.address,
|
exchangeAddress: exchangeInstance.address,
|
||||||
makerAddress,
|
makerAddress,
|
||||||
feeRecipientAddress,
|
feeRecipientAddress,
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultMakerAssetAddress),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultMakerAssetAddress),
|
||||||
takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultTakerAssetAddress),
|
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultTakerAssetAddress),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), DECIMALS_DEFAULT),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), DECIMALS_DEFAULT),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), DECIMALS_DEFAULT),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), DECIMALS_DEFAULT),
|
||||||
makerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), DECIMALS_DEFAULT),
|
makerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), DECIMALS_DEFAULT),
|
||||||
@ -151,7 +151,7 @@ describe(ContractName.Forwarder, () => {
|
|||||||
signedOrder = await orderFactory.newSignedOrderAsync();
|
signedOrder = await orderFactory.newSignedOrderAsync();
|
||||||
signedOrders = [signedOrder];
|
signedOrders = [signedOrder];
|
||||||
feeOrder = await orderFactory.newSignedOrderAsync({
|
feeOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), DECIMALS_DEFAULT),
|
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), DECIMALS_DEFAULT),
|
||||||
});
|
});
|
||||||
feeOrders = [feeOrder];
|
feeOrders = [feeOrder];
|
||||||
@ -239,7 +239,7 @@ describe(ContractName.Forwarder, () => {
|
|||||||
});
|
});
|
||||||
it('should fill the order when token is ZRX with fees', async () => {
|
it('should fill the order when token is ZRX with fees', async () => {
|
||||||
orderWithFee = await orderFactory.newSignedOrderAsync({
|
orderWithFee = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), DECIMALS_DEFAULT),
|
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), DECIMALS_DEFAULT),
|
||||||
});
|
});
|
||||||
signedOrdersWithFee = [orderWithFee];
|
signedOrdersWithFee = [orderWithFee];
|
||||||
@ -261,7 +261,7 @@ describe(ContractName.Forwarder, () => {
|
|||||||
});
|
});
|
||||||
it('should fail if sent an ETH amount too high', async () => {
|
it('should fail if sent an ETH amount too high', async () => {
|
||||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), DECIMALS_DEFAULT),
|
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), DECIMALS_DEFAULT),
|
||||||
});
|
});
|
||||||
const fillAmount = signedOrder.takerAssetAmount.times(2);
|
const fillAmount = signedOrder.takerAssetAmount.times(2);
|
||||||
@ -279,7 +279,7 @@ describe(ContractName.Forwarder, () => {
|
|||||||
});
|
});
|
||||||
signedOrdersWithFee = [orderWithFee];
|
signedOrdersWithFee = [orderWithFee];
|
||||||
feeOrder = await orderFactory.newSignedOrderAsync({
|
feeOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), DECIMALS_DEFAULT),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), DECIMALS_DEFAULT),
|
||||||
});
|
});
|
||||||
feeOrders = [feeOrder];
|
feeOrders = [feeOrder];
|
||||||
@ -296,7 +296,7 @@ describe(ContractName.Forwarder, () => {
|
|||||||
const makerAssetId = erc721MakerAssetIds[0];
|
const makerAssetId = erc721MakerAssetIds[0];
|
||||||
const erc721SignedOrder = await orderFactory.newSignedOrderAsync({
|
const erc721SignedOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetAmount: new BigNumber(1),
|
makerAssetAmount: new BigNumber(1),
|
||||||
makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
makerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
||||||
});
|
});
|
||||||
const erc20SignedOrder = await orderFactory.newSignedOrderAsync();
|
const erc20SignedOrder = await orderFactory.newSignedOrderAsync();
|
||||||
signedOrders = [erc20SignedOrder, erc721SignedOrder];
|
signedOrders = [erc20SignedOrder, erc721SignedOrder];
|
||||||
@ -419,7 +419,7 @@ describe(ContractName.Forwarder, () => {
|
|||||||
});
|
});
|
||||||
it('should buy the exact amount of assets when buying zrx with fee abstraction', async () => {
|
it('should buy the exact amount of assets when buying zrx with fee abstraction', async () => {
|
||||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), DECIMALS_DEFAULT),
|
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), DECIMALS_DEFAULT),
|
||||||
});
|
});
|
||||||
signedOrdersWithFee = [signedOrder];
|
signedOrdersWithFee = [signedOrder];
|
||||||
@ -448,7 +448,7 @@ describe(ContractName.Forwarder, () => {
|
|||||||
});
|
});
|
||||||
it('throws if fees are higher than 5% when buying zrx', async () => {
|
it('throws if fees are higher than 5% when buying zrx', async () => {
|
||||||
const highFeeZRXOrder = await orderFactory.newSignedOrderAsync({
|
const highFeeZRXOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
makerAssetAmount: signedOrder.makerAssetAmount,
|
makerAssetAmount: signedOrder.makerAssetAmount,
|
||||||
takerFee: signedOrder.makerAssetAmount.times(0.06),
|
takerFee: signedOrder.makerAssetAmount.times(0.06),
|
||||||
});
|
});
|
||||||
@ -546,7 +546,7 @@ describe(ContractName.Forwarder, () => {
|
|||||||
const makerAssetId = erc721MakerAssetIds[0];
|
const makerAssetId = erc721MakerAssetIds[0];
|
||||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetAmount: new BigNumber(1),
|
makerAssetAmount: new BigNumber(1),
|
||||||
makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
makerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
||||||
});
|
});
|
||||||
feeOrders = [];
|
feeOrders = [];
|
||||||
signedOrders = [signedOrder];
|
signedOrders = [signedOrder];
|
||||||
@ -569,7 +569,7 @@ describe(ContractName.Forwarder, () => {
|
|||||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetAmount: new BigNumber(1),
|
makerAssetAmount: new BigNumber(1),
|
||||||
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), DECIMALS_DEFAULT),
|
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), DECIMALS_DEFAULT),
|
||||||
makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
makerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
||||||
});
|
});
|
||||||
signedOrders = [signedOrder];
|
signedOrders = [signedOrder];
|
||||||
const makerAssetAmount = new BigNumber(signedOrders.length);
|
const makerAssetAmount = new BigNumber(signedOrders.length);
|
||||||
@ -591,7 +591,7 @@ describe(ContractName.Forwarder, () => {
|
|||||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetAmount: new BigNumber(1),
|
makerAssetAmount: new BigNumber(1),
|
||||||
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), DECIMALS_DEFAULT),
|
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), DECIMALS_DEFAULT),
|
||||||
makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
makerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
||||||
});
|
});
|
||||||
signedOrders = [signedOrder];
|
signedOrders = [signedOrder];
|
||||||
feeProportion = 100;
|
feeProportion = 100;
|
||||||
@ -633,12 +633,12 @@ describe(ContractName.Forwarder, () => {
|
|||||||
const signedOrder1 = await orderFactory.newSignedOrderAsync({
|
const signedOrder1 = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetAmount: new BigNumber(1),
|
makerAssetAmount: new BigNumber(1),
|
||||||
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(3), DECIMALS_DEFAULT),
|
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(3), DECIMALS_DEFAULT),
|
||||||
makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId1),
|
makerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId1),
|
||||||
});
|
});
|
||||||
const signedOrder2 = await orderFactory.newSignedOrderAsync({
|
const signedOrder2 = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetAmount: new BigNumber(1),
|
makerAssetAmount: new BigNumber(1),
|
||||||
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(4), DECIMALS_DEFAULT),
|
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(4), DECIMALS_DEFAULT),
|
||||||
makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId2),
|
makerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId2),
|
||||||
});
|
});
|
||||||
signedOrders = [signedOrder1, signedOrder2];
|
signedOrders = [signedOrder1, signedOrder2];
|
||||||
feeProportion = 10;
|
feeProportion = 10;
|
||||||
@ -669,19 +669,19 @@ describe(ContractName.Forwarder, () => {
|
|||||||
makerAssetAmount: erc721MakerAssetAmount,
|
makerAssetAmount: erc721MakerAssetAmount,
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), DECIMALS_DEFAULT),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), DECIMALS_DEFAULT),
|
||||||
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(6), DECIMALS_DEFAULT),
|
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(6), DECIMALS_DEFAULT),
|
||||||
makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
makerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
||||||
});
|
});
|
||||||
signedOrders = [signedOrder];
|
signedOrders = [signedOrder];
|
||||||
const firstFeeOrder = await orderFactory.newSignedOrderAsync({
|
const firstFeeOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(8), DECIMALS_DEFAULT),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(8), DECIMALS_DEFAULT),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(0.1), DECIMALS_DEFAULT),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(0.1), DECIMALS_DEFAULT),
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(0), DECIMALS_DEFAULT),
|
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(0), DECIMALS_DEFAULT),
|
||||||
});
|
});
|
||||||
const secondFeeOrder = await orderFactory.newSignedOrderAsync({
|
const secondFeeOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(8), DECIMALS_DEFAULT),
|
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(8), DECIMALS_DEFAULT),
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(0.12), DECIMALS_DEFAULT),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(0.12), DECIMALS_DEFAULT),
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(0), DECIMALS_DEFAULT),
|
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(0), DECIMALS_DEFAULT),
|
||||||
});
|
});
|
||||||
feeOrders = [firstFeeOrder, secondFeeOrder];
|
feeOrders = [firstFeeOrder, secondFeeOrder];
|
||||||
@ -733,20 +733,20 @@ describe(ContractName.Forwarder, () => {
|
|||||||
makerAssetAmount: erc721MakerAssetAmount,
|
makerAssetAmount: erc721MakerAssetAmount,
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), DECIMALS_DEFAULT),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), DECIMALS_DEFAULT),
|
||||||
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(6), DECIMALS_DEFAULT),
|
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(6), DECIMALS_DEFAULT),
|
||||||
makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
makerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
||||||
});
|
});
|
||||||
const zrxMakerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(8), DECIMALS_DEFAULT);
|
const zrxMakerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(8), DECIMALS_DEFAULT);
|
||||||
signedOrders = [signedOrder];
|
signedOrders = [signedOrder];
|
||||||
const firstFeeOrder = await orderFactory.newSignedOrderAsync({
|
const firstFeeOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetAmount: zrxMakerAssetAmount,
|
makerAssetAmount: zrxMakerAssetAmount,
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(0.1), DECIMALS_DEFAULT),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(0.1), DECIMALS_DEFAULT),
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(0), DECIMALS_DEFAULT),
|
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(0), DECIMALS_DEFAULT),
|
||||||
});
|
});
|
||||||
const secondFeeOrder = await orderFactory.newSignedOrderAsync({
|
const secondFeeOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetAmount: zrxMakerAssetAmount,
|
makerAssetAmount: zrxMakerAssetAmount,
|
||||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(0.12), DECIMALS_DEFAULT),
|
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(0.12), DECIMALS_DEFAULT),
|
||||||
makerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
makerAssetData: assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(0), DECIMALS_DEFAULT),
|
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(0), DECIMALS_DEFAULT),
|
||||||
});
|
});
|
||||||
feeOrders = [firstFeeOrder, secondFeeOrder];
|
feeOrders = [firstFeeOrder, secondFeeOrder];
|
||||||
@ -780,7 +780,7 @@ describe(ContractName.Forwarder, () => {
|
|||||||
const makerAssetId = erc721MakerAssetIds[0];
|
const makerAssetId = erc721MakerAssetIds[0];
|
||||||
const erc721SignedOrder = await orderFactory.newSignedOrderAsync({
|
const erc721SignedOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetAmount: new BigNumber(1),
|
makerAssetAmount: new BigNumber(1),
|
||||||
makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
makerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
||||||
});
|
});
|
||||||
const erc20SignedOrder = await orderFactory.newSignedOrderAsync();
|
const erc20SignedOrder = await orderFactory.newSignedOrderAsync();
|
||||||
signedOrders = [erc721SignedOrder, erc20SignedOrder];
|
signedOrders = [erc721SignedOrder, erc20SignedOrder];
|
||||||
@ -798,7 +798,7 @@ describe(ContractName.Forwarder, () => {
|
|||||||
const makerAssetId = erc721MakerAssetIds[0];
|
const makerAssetId = erc721MakerAssetIds[0];
|
||||||
const erc721SignedOrder = await orderFactory.newSignedOrderAsync({
|
const erc721SignedOrder = await orderFactory.newSignedOrderAsync({
|
||||||
makerAssetAmount: new BigNumber(1),
|
makerAssetAmount: new BigNumber(1),
|
||||||
makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
makerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
|
||||||
});
|
});
|
||||||
const erc20SignedOrder = await orderFactory.newSignedOrderAsync();
|
const erc20SignedOrder = await orderFactory.newSignedOrderAsync();
|
||||||
signedOrders = [erc20SignedOrder, erc721SignedOrder];
|
signedOrders = [erc20SignedOrder, erc721SignedOrder];
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
||||||
import { assetProxyUtils, generatePseudoRandomSalt } from '@0xproject/order-utils';
|
import { generatePseudoRandomSalt } from '@0xproject/order-utils';
|
||||||
import { RevertReason } from '@0xproject/types';
|
import { RevertReason } from '@0xproject/types';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
import BN = require('bn.js');
|
import BN = require('bn.js');
|
||||||
@ -12,6 +12,7 @@ import { artifacts } from '../utils/artifacts';
|
|||||||
import { expectContractCallFailed } from '../utils/assertions';
|
import { expectContractCallFailed } from '../utils/assertions';
|
||||||
import { chaiSetup } from '../utils/chai_setup';
|
import { chaiSetup } from '../utils/chai_setup';
|
||||||
import { constants } from '../utils/constants';
|
import { constants } from '../utils/constants';
|
||||||
|
import { typeEncodingUtils } from '../utils/type_encoding_utils';
|
||||||
import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper';
|
import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper';
|
||||||
|
|
||||||
chaiSetup.configure();
|
chaiSetup.configure();
|
||||||
@ -74,20 +75,20 @@ describe('LibBytes', () => {
|
|||||||
shortData = '0xffffaa';
|
shortData = '0xffffaa';
|
||||||
const encodedShortData = ethUtil.toBuffer(shortData);
|
const encodedShortData = ethUtil.toBuffer(shortData);
|
||||||
const shortDataLength = new BigNumber(encodedShortData.byteLength);
|
const shortDataLength = new BigNumber(encodedShortData.byteLength);
|
||||||
const encodedShortDataLength = assetProxyUtils.encodeUint256(shortDataLength);
|
const encodedShortDataLength = typeEncodingUtils.encodeUint256(shortDataLength);
|
||||||
shortTestBytesAsBuffer = Buffer.concat([encodedShortDataLength, encodedShortData]);
|
shortTestBytesAsBuffer = Buffer.concat([encodedShortDataLength, encodedShortData]);
|
||||||
shortTestBytes = ethUtil.bufferToHex(shortTestBytesAsBuffer);
|
shortTestBytes = ethUtil.bufferToHex(shortTestBytesAsBuffer);
|
||||||
// Create test bytes one word in length
|
// Create test bytes one word in length
|
||||||
wordOfData = ethUtil.bufferToHex(assetProxyUtils.encodeUint256(generatePseudoRandomSalt()));
|
wordOfData = ethUtil.bufferToHex(typeEncodingUtils.encodeUint256(generatePseudoRandomSalt()));
|
||||||
const encodedWordOfData = ethUtil.toBuffer(wordOfData);
|
const encodedWordOfData = ethUtil.toBuffer(wordOfData);
|
||||||
const wordOfDataLength = new BigNumber(encodedWordOfData.byteLength);
|
const wordOfDataLength = new BigNumber(encodedWordOfData.byteLength);
|
||||||
const encodedWordOfDataLength = assetProxyUtils.encodeUint256(wordOfDataLength);
|
const encodedWordOfDataLength = typeEncodingUtils.encodeUint256(wordOfDataLength);
|
||||||
wordOfTestBytesAsBuffer = Buffer.concat([encodedWordOfDataLength, encodedWordOfData]);
|
wordOfTestBytesAsBuffer = Buffer.concat([encodedWordOfDataLength, encodedWordOfData]);
|
||||||
wordOfTestBytes = ethUtil.bufferToHex(wordOfTestBytesAsBuffer);
|
wordOfTestBytes = ethUtil.bufferToHex(wordOfTestBytesAsBuffer);
|
||||||
// Create long test bytes (combines short test bytes with word of test bytes)
|
// Create long test bytes (combines short test bytes with word of test bytes)
|
||||||
longData = ethUtil.bufferToHex(Buffer.concat([encodedShortData, encodedWordOfData]));
|
longData = ethUtil.bufferToHex(Buffer.concat([encodedShortData, encodedWordOfData]));
|
||||||
const longDataLength = new BigNumber(encodedShortData.byteLength + encodedWordOfData.byteLength);
|
const longDataLength = new BigNumber(encodedShortData.byteLength + encodedWordOfData.byteLength);
|
||||||
const encodedLongDataLength = assetProxyUtils.encodeUint256(longDataLength);
|
const encodedLongDataLength = typeEncodingUtils.encodeUint256(longDataLength);
|
||||||
longTestBytesAsBuffer = Buffer.concat([encodedLongDataLength, encodedShortData, encodedWordOfData]);
|
longTestBytesAsBuffer = Buffer.concat([encodedLongDataLength, encodedShortData, encodedWordOfData]);
|
||||||
longTestBytes = ethUtil.bufferToHex(longTestBytesAsBuffer);
|
longTestBytes = ethUtil.bufferToHex(longTestBytesAsBuffer);
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { assetProxyUtils } from '@0xproject/order-utils';
|
import { assetDataUtils } from '@0xproject/order-utils';
|
||||||
import { AssetProxyId } from '@0xproject/types';
|
import { AssetProxyId } from '@0xproject/types';
|
||||||
import { BigNumber, errorUtils } from '@0xproject/utils';
|
import { BigNumber, errorUtils } from '@0xproject/utils';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
@ -26,7 +26,7 @@ export class AssetWrapper {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
public async getBalanceAsync(userAddress: string, assetData: string): Promise<BigNumber> {
|
public async getBalanceAsync(userAddress: string, assetData: string): Promise<BigNumber> {
|
||||||
const proxyId = assetProxyUtils.decodeAssetDataId(assetData);
|
const proxyId = assetDataUtils.decodeAssetProxyId(assetData);
|
||||||
switch (proxyId) {
|
switch (proxyId) {
|
||||||
case AssetProxyId.ERC20: {
|
case AssetProxyId.ERC20: {
|
||||||
const erc20Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC20Wrapper;
|
const erc20Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC20Wrapper;
|
||||||
@ -35,7 +35,7 @@ export class AssetWrapper {
|
|||||||
}
|
}
|
||||||
case AssetProxyId.ERC721: {
|
case AssetProxyId.ERC721: {
|
||||||
const assetWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
|
const assetWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
|
||||||
const assetProxyData = assetProxyUtils.decodeERC721AssetData(assetData);
|
const assetProxyData = assetDataUtils.decodeERC721AssetData(assetData);
|
||||||
const isOwner = await assetWrapper.isOwnerAsync(
|
const isOwner = await assetWrapper.isOwnerAsync(
|
||||||
userAddress,
|
userAddress,
|
||||||
assetProxyData.tokenAddress,
|
assetProxyData.tokenAddress,
|
||||||
@ -49,7 +49,7 @@ export class AssetWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public async setBalanceAsync(userAddress: string, assetData: string, desiredBalance: BigNumber): Promise<void> {
|
public async setBalanceAsync(userAddress: string, assetData: string, desiredBalance: BigNumber): Promise<void> {
|
||||||
const proxyId = assetProxyUtils.decodeAssetDataId(assetData);
|
const proxyId = assetDataUtils.decodeAssetProxyId(assetData);
|
||||||
switch (proxyId) {
|
switch (proxyId) {
|
||||||
case AssetProxyId.ERC20: {
|
case AssetProxyId.ERC20: {
|
||||||
const erc20Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC20Wrapper;
|
const erc20Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC20Wrapper;
|
||||||
@ -61,7 +61,7 @@ export class AssetWrapper {
|
|||||||
throw new Error(`Balance for ERC721 token can only be set to 0 or 1. Got: ${desiredBalance}`);
|
throw new Error(`Balance for ERC721 token can only be set to 0 or 1. Got: ${desiredBalance}`);
|
||||||
}
|
}
|
||||||
const erc721Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
|
const erc721Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
|
||||||
const assetProxyData = assetProxyUtils.decodeERC721AssetData(assetData);
|
const assetProxyData = assetDataUtils.decodeERC721AssetData(assetData);
|
||||||
const doesTokenExist = erc721Wrapper.doesTokenExistAsync(
|
const doesTokenExist = erc721Wrapper.doesTokenExistAsync(
|
||||||
assetProxyData.tokenAddress,
|
assetProxyData.tokenAddress,
|
||||||
assetProxyData.tokenId,
|
assetProxyData.tokenId,
|
||||||
@ -107,7 +107,7 @@ export class AssetWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public async getProxyAllowanceAsync(userAddress: string, assetData: string): Promise<BigNumber> {
|
public async getProxyAllowanceAsync(userAddress: string, assetData: string): Promise<BigNumber> {
|
||||||
const proxyId = assetProxyUtils.decodeAssetDataId(assetData);
|
const proxyId = assetDataUtils.decodeAssetProxyId(assetData);
|
||||||
switch (proxyId) {
|
switch (proxyId) {
|
||||||
case AssetProxyId.ERC20: {
|
case AssetProxyId.ERC20: {
|
||||||
const erc20Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC20Wrapper;
|
const erc20Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC20Wrapper;
|
||||||
@ -116,7 +116,7 @@ export class AssetWrapper {
|
|||||||
}
|
}
|
||||||
case AssetProxyId.ERC721: {
|
case AssetProxyId.ERC721: {
|
||||||
const assetWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
|
const assetWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
|
||||||
const erc721ProxyData = assetProxyUtils.decodeERC721AssetData(assetData);
|
const erc721ProxyData = assetDataUtils.decodeERC721AssetData(assetData);
|
||||||
const isProxyApprovedForAll = await assetWrapper.isProxyApprovedForAllAsync(
|
const isProxyApprovedForAll = await assetWrapper.isProxyApprovedForAllAsync(
|
||||||
userAddress,
|
userAddress,
|
||||||
erc721ProxyData.tokenAddress,
|
erc721ProxyData.tokenAddress,
|
||||||
@ -141,7 +141,7 @@ export class AssetWrapper {
|
|||||||
assetData: string,
|
assetData: string,
|
||||||
desiredAllowance: BigNumber,
|
desiredAllowance: BigNumber,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const proxyId = assetProxyUtils.decodeAssetDataId(assetData);
|
const proxyId = assetDataUtils.decodeAssetProxyId(assetData);
|
||||||
switch (proxyId) {
|
switch (proxyId) {
|
||||||
case AssetProxyId.ERC20: {
|
case AssetProxyId.ERC20: {
|
||||||
const erc20Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC20Wrapper;
|
const erc20Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC20Wrapper;
|
||||||
@ -159,7 +159,7 @@ export class AssetWrapper {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
const erc721Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
|
const erc721Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
|
||||||
const assetProxyData = assetProxyUtils.decodeERC721AssetData(assetData);
|
const assetProxyData = assetDataUtils.decodeERC721AssetData(assetData);
|
||||||
|
|
||||||
const doesTokenExist = await erc721Wrapper.doesTokenExistAsync(
|
const doesTokenExist = await erc721Wrapper.doesTokenExistAsync(
|
||||||
assetProxyData.tokenAddress,
|
assetProxyData.tokenAddress,
|
||||||
|
@ -17,6 +17,7 @@ const TESTRPC_PRIVATE_KEYS_STRINGS = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
export const constants = {
|
export const constants = {
|
||||||
|
BASE_16: 16,
|
||||||
INVALID_OPCODE: 'invalid opcode',
|
INVALID_OPCODE: 'invalid opcode',
|
||||||
TESTRPC_NETWORK_ID: 50,
|
TESTRPC_NETWORK_ID: 50,
|
||||||
// Note(albrow): In practice V8 and most other engines limit the minimum
|
// Note(albrow): In practice V8 and most other engines limit the minimum
|
||||||
@ -47,4 +48,5 @@ export const constants = {
|
|||||||
makerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18),
|
makerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18),
|
||||||
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18),
|
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18),
|
||||||
},
|
},
|
||||||
|
WORD_LENGTH: 32,
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
assetProxyUtils,
|
assetDataUtils,
|
||||||
BalanceAndProxyAllowanceLazyStore,
|
BalanceAndProxyAllowanceLazyStore,
|
||||||
ExchangeTransferSimulator,
|
ExchangeTransferSimulator,
|
||||||
orderHashUtils,
|
orderHashUtils,
|
||||||
@ -72,7 +72,7 @@ export async function coreCombinatorialUtilsFactoryAsync(
|
|||||||
erc20EighteenDecimalTokenB,
|
erc20EighteenDecimalTokenB,
|
||||||
zrxToken,
|
zrxToken,
|
||||||
] = await erc20Wrapper.deployDummyTokensAsync(erc20EighteenDecimalTokenCount, eighteenDecimals);
|
] = await erc20Wrapper.deployDummyTokensAsync(erc20EighteenDecimalTokenCount, eighteenDecimals);
|
||||||
const zrxAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address);
|
const zrxAssetData = assetDataUtils.encodeERC20AssetData(zrxToken.address);
|
||||||
|
|
||||||
const erc20FiveDecimalTokenCount = 2;
|
const erc20FiveDecimalTokenCount = 2;
|
||||||
const fiveDecimals = new BigNumber(5);
|
const fiveDecimals = new BigNumber(5);
|
||||||
@ -598,8 +598,8 @@ export class CoreCombinatorialUtils {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case TakerAssetFillAmountScenario.LessThanRemainingFillableTakerAssetAmount:
|
case TakerAssetFillAmountScenario.LessThanRemainingFillableTakerAssetAmount:
|
||||||
const takerAssetProxyId = assetProxyUtils.decodeAssetDataId(signedOrder.takerAssetData);
|
const takerAssetProxyId = assetDataUtils.decodeAssetProxyId(signedOrder.takerAssetData);
|
||||||
const makerAssetProxyId = assetProxyUtils.decodeAssetDataId(signedOrder.makerAssetData);
|
const makerAssetProxyId = assetDataUtils.decodeAssetProxyId(signedOrder.makerAssetData);
|
||||||
const isEitherAssetERC721 =
|
const isEitherAssetERC721 =
|
||||||
takerAssetProxyId === AssetProxyId.ERC721 || makerAssetProxyId === AssetProxyId.ERC721;
|
takerAssetProxyId === AssetProxyId.ERC721 || makerAssetProxyId === AssetProxyId.ERC721;
|
||||||
if (isEitherAssetERC721) {
|
if (isEitherAssetERC721) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { assetProxyUtils } from '@0xproject/order-utils';
|
import { assetDataUtils } from '@0xproject/order-utils';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||||
import { Provider } from 'ethereum-types';
|
import { Provider } from 'ethereum-types';
|
||||||
@ -154,7 +154,7 @@ export class ERC20Wrapper {
|
|||||||
return tokenAddresses;
|
return tokenAddresses;
|
||||||
}
|
}
|
||||||
private _getTokenContractFromAssetData(assetData: string): DummyERC20TokenContract {
|
private _getTokenContractFromAssetData(assetData: string): DummyERC20TokenContract {
|
||||||
const erc20ProxyData = assetProxyUtils.decodeERC20AssetData(assetData);
|
const erc20ProxyData = assetDataUtils.decodeERC20AssetData(assetData);
|
||||||
const tokenAddress = erc20ProxyData.tokenAddress;
|
const tokenAddress = erc20ProxyData.tokenAddress;
|
||||||
const tokenContractIfExists = _.find(this._dummyTokenContracts, c => c.address === tokenAddress);
|
const tokenContractIfExists = _.find(this._dummyTokenContracts, c => c.address === tokenAddress);
|
||||||
if (_.isUndefined(tokenContractIfExists)) {
|
if (_.isUndefined(tokenContractIfExists)) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { assetProxyUtils } from '@0xproject/order-utils';
|
import { assetDataUtils } from '@0xproject/order-utils';
|
||||||
import { AssetProxyId, SignedOrder } from '@0xproject/types';
|
import { AssetProxyId, SignedOrder } from '@0xproject/types';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||||
@ -24,7 +24,7 @@ export class ForwarderWrapper {
|
|||||||
private readonly _zrxAddress: string;
|
private readonly _zrxAddress: string;
|
||||||
private static _createOptimizedSellOrders(signedOrders: SignedOrder[]): MarketSellOrders {
|
private static _createOptimizedSellOrders(signedOrders: SignedOrder[]): MarketSellOrders {
|
||||||
const marketSellOrders = formatters.createMarketSellOrders(signedOrders, ZERO_AMOUNT);
|
const marketSellOrders = formatters.createMarketSellOrders(signedOrders, ZERO_AMOUNT);
|
||||||
const assetDataId = assetProxyUtils.decodeAssetDataId(signedOrders[0].makerAssetData);
|
const assetDataId = assetDataUtils.decodeAssetProxyId(signedOrders[0].makerAssetData);
|
||||||
// Contract will fill this in for us as all of the assetData is assumed to be the same
|
// Contract will fill this in for us as all of the assetData is assumed to be the same
|
||||||
for (let i = 0; i < signedOrders.length; i++) {
|
for (let i = 0; i < signedOrders.length; i++) {
|
||||||
if (i !== 0 && assetDataId === AssetProxyId.ERC20) {
|
if (i !== 0 && assetDataId === AssetProxyId.ERC20) {
|
||||||
@ -90,7 +90,7 @@ export class ForwarderWrapper {
|
|||||||
txData: TxDataPayable,
|
txData: TxDataPayable,
|
||||||
opts: { feeProportion?: number; feeRecipient?: string } = {},
|
opts: { feeProportion?: number; feeRecipient?: string } = {},
|
||||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||||
const assetDataId = assetProxyUtils.decodeAssetDataId(orders[0].makerAssetData);
|
const assetDataId = assetDataUtils.decodeAssetProxyId(orders[0].makerAssetData);
|
||||||
if (assetDataId !== AssetProxyId.ERC20) {
|
if (assetDataId !== AssetProxyId.ERC20) {
|
||||||
throw new Error('Asset type not supported by marketSellEthForERC20');
|
throw new Error('Asset type not supported by marketSellEthForERC20');
|
||||||
}
|
}
|
||||||
@ -116,7 +116,7 @@ export class ForwarderWrapper {
|
|||||||
feeProportion: number,
|
feeProportion: number,
|
||||||
makerAssetFillAmount: BigNumber,
|
makerAssetFillAmount: BigNumber,
|
||||||
): Promise<BigNumber> {
|
): Promise<BigNumber> {
|
||||||
const assetProxyId = assetProxyUtils.decodeAssetDataId(orders[0].makerAssetData);
|
const assetProxyId = assetDataUtils.decodeAssetProxyId(orders[0].makerAssetData);
|
||||||
switch (assetProxyId) {
|
switch (assetProxyId) {
|
||||||
case AssetProxyId.ERC20: {
|
case AssetProxyId.ERC20: {
|
||||||
const fillAmountWei = this._calculateMarketBuyERC20FillAmountAsync(
|
const fillAmountWei = this._calculateMarketBuyERC20FillAmountAsync(
|
||||||
@ -145,7 +145,7 @@ export class ForwarderWrapper {
|
|||||||
feeProportion: number,
|
feeProportion: number,
|
||||||
makerAssetFillAmount: BigNumber,
|
makerAssetFillAmount: BigNumber,
|
||||||
): Promise<BigNumber> {
|
): Promise<BigNumber> {
|
||||||
const makerAssetData = assetProxyUtils.decodeAssetData(orders[0].makerAssetData);
|
const makerAssetData = assetDataUtils.decodeAssetData(orders[0].makerAssetData);
|
||||||
const makerAssetToken = makerAssetData.tokenAddress;
|
const makerAssetToken = makerAssetData.tokenAddress;
|
||||||
const params = formatters.createMarketBuyOrders(orders, makerAssetFillAmount);
|
const params = formatters.createMarketBuyOrders(orders, makerAssetFillAmount);
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { assetProxyUtils, orderHashUtils } from '@0xproject/order-utils';
|
import { assetDataUtils, orderHashUtils } from '@0xproject/order-utils';
|
||||||
import { AssetProxyId, SignedOrder } from '@0xproject/types';
|
import { AssetProxyId, SignedOrder } from '@0xproject/types';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
@ -233,10 +233,10 @@ export class MatchOrderTester {
|
|||||||
const expectedNewERC20BalancesByOwner = _.cloneDeep(erc20BalancesByOwner);
|
const expectedNewERC20BalancesByOwner = _.cloneDeep(erc20BalancesByOwner);
|
||||||
const expectedNewERC721TokenIdsByOwner = _.cloneDeep(erc721TokenIdsByOwner);
|
const expectedNewERC721TokenIdsByOwner = _.cloneDeep(erc721TokenIdsByOwner);
|
||||||
// Left Maker Asset (Right Taker Asset)
|
// Left Maker Asset (Right Taker Asset)
|
||||||
const makerAssetProxyIdLeft = assetProxyUtils.decodeAssetDataId(signedOrderLeft.makerAssetData);
|
const makerAssetProxyIdLeft = assetDataUtils.decodeAssetProxyId(signedOrderLeft.makerAssetData);
|
||||||
if (makerAssetProxyIdLeft === AssetProxyId.ERC20) {
|
if (makerAssetProxyIdLeft === AssetProxyId.ERC20) {
|
||||||
// Decode asset data
|
// Decode asset data
|
||||||
const erc20AssetData = assetProxyUtils.decodeERC20AssetData(signedOrderLeft.makerAssetData);
|
const erc20AssetData = assetDataUtils.decodeERC20AssetData(signedOrderLeft.makerAssetData);
|
||||||
const makerAssetAddressLeft = erc20AssetData.tokenAddress;
|
const makerAssetAddressLeft = erc20AssetData.tokenAddress;
|
||||||
const takerAssetAddressRight = makerAssetAddressLeft;
|
const takerAssetAddressRight = makerAssetAddressLeft;
|
||||||
// Left Maker
|
// Left Maker
|
||||||
@ -255,7 +255,7 @@ export class MatchOrderTester {
|
|||||||
][makerAssetAddressLeft].add(expectedTransferAmounts.amountReceivedByTaker);
|
][makerAssetAddressLeft].add(expectedTransferAmounts.amountReceivedByTaker);
|
||||||
} else if (makerAssetProxyIdLeft === AssetProxyId.ERC721) {
|
} else if (makerAssetProxyIdLeft === AssetProxyId.ERC721) {
|
||||||
// Decode asset data
|
// Decode asset data
|
||||||
const erc721AssetData = assetProxyUtils.decodeERC721AssetData(signedOrderLeft.makerAssetData);
|
const erc721AssetData = assetDataUtils.decodeERC721AssetData(signedOrderLeft.makerAssetData);
|
||||||
const makerAssetAddressLeft = erc721AssetData.tokenAddress;
|
const makerAssetAddressLeft = erc721AssetData.tokenAddress;
|
||||||
const makerAssetIdLeft = erc721AssetData.tokenId;
|
const makerAssetIdLeft = erc721AssetData.tokenId;
|
||||||
const takerAssetAddressRight = makerAssetAddressLeft;
|
const takerAssetAddressRight = makerAssetAddressLeft;
|
||||||
@ -268,10 +268,10 @@ export class MatchOrderTester {
|
|||||||
}
|
}
|
||||||
// Left Taker Asset (Right Maker Asset)
|
// Left Taker Asset (Right Maker Asset)
|
||||||
// Note: This exchange is only between the order makers: the Taker does not receive any of the left taker asset.
|
// Note: This exchange is only between the order makers: the Taker does not receive any of the left taker asset.
|
||||||
const takerAssetProxyIdLeft = assetProxyUtils.decodeAssetDataId(signedOrderLeft.takerAssetData);
|
const takerAssetProxyIdLeft = assetDataUtils.decodeAssetProxyId(signedOrderLeft.takerAssetData);
|
||||||
if (takerAssetProxyIdLeft === AssetProxyId.ERC20) {
|
if (takerAssetProxyIdLeft === AssetProxyId.ERC20) {
|
||||||
// Decode asset data
|
// Decode asset data
|
||||||
const erc20AssetData = assetProxyUtils.decodeERC20AssetData(signedOrderLeft.takerAssetData);
|
const erc20AssetData = assetDataUtils.decodeERC20AssetData(signedOrderLeft.takerAssetData);
|
||||||
const takerAssetAddressLeft = erc20AssetData.tokenAddress;
|
const takerAssetAddressLeft = erc20AssetData.tokenAddress;
|
||||||
const makerAssetAddressRight = takerAssetAddressLeft;
|
const makerAssetAddressRight = takerAssetAddressLeft;
|
||||||
// Left Maker
|
// Left Maker
|
||||||
@ -286,7 +286,7 @@ export class MatchOrderTester {
|
|||||||
);
|
);
|
||||||
} else if (takerAssetProxyIdLeft === AssetProxyId.ERC721) {
|
} else if (takerAssetProxyIdLeft === AssetProxyId.ERC721) {
|
||||||
// Decode asset data
|
// Decode asset data
|
||||||
const erc721AssetData = assetProxyUtils.decodeERC721AssetData(signedOrderRight.makerAssetData);
|
const erc721AssetData = assetDataUtils.decodeERC721AssetData(signedOrderRight.makerAssetData);
|
||||||
const makerAssetAddressRight = erc721AssetData.tokenAddress;
|
const makerAssetAddressRight = erc721AssetData.tokenAddress;
|
||||||
const makerAssetIdRight = erc721AssetData.tokenId;
|
const makerAssetIdRight = erc721AssetData.tokenId;
|
||||||
const takerAssetAddressLeft = makerAssetAddressRight;
|
const takerAssetAddressLeft = makerAssetAddressRight;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { assetProxyUtils, generatePseudoRandomSalt } from '@0xproject/order-utils';
|
import { assetDataUtils, generatePseudoRandomSalt } from '@0xproject/order-utils';
|
||||||
import { Order } from '@0xproject/types';
|
import { Order } from '@0xproject/types';
|
||||||
import { BigNumber, errorUtils } from '@0xproject/utils';
|
import { BigNumber, errorUtils } from '@0xproject/utils';
|
||||||
|
|
||||||
@ -75,18 +75,16 @@ export class OrderFactoryFromScenario {
|
|||||||
|
|
||||||
switch (orderScenario.makerAssetDataScenario) {
|
switch (orderScenario.makerAssetDataScenario) {
|
||||||
case AssetDataScenario.ZRXFeeToken:
|
case AssetDataScenario.ZRXFeeToken:
|
||||||
makerAssetData = assetProxyUtils.encodeERC20AssetData(this._zrxAddress);
|
makerAssetData = assetDataUtils.encodeERC20AssetData(this._zrxAddress);
|
||||||
break;
|
break;
|
||||||
case AssetDataScenario.ERC20NonZRXEighteenDecimals:
|
case AssetDataScenario.ERC20NonZRXEighteenDecimals:
|
||||||
makerAssetData = assetProxyUtils.encodeERC20AssetData(
|
makerAssetData = assetDataUtils.encodeERC20AssetData(this._nonZrxERC20EighteenDecimalTokenAddresses[0]);
|
||||||
this._nonZrxERC20EighteenDecimalTokenAddresses[0],
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
case AssetDataScenario.ERC20FiveDecimals:
|
case AssetDataScenario.ERC20FiveDecimals:
|
||||||
makerAssetData = assetProxyUtils.encodeERC20AssetData(this._erc20FiveDecimalTokenAddresses[0]);
|
makerAssetData = assetDataUtils.encodeERC20AssetData(this._erc20FiveDecimalTokenAddresses[0]);
|
||||||
break;
|
break;
|
||||||
case AssetDataScenario.ERC721:
|
case AssetDataScenario.ERC721:
|
||||||
makerAssetData = assetProxyUtils.encodeERC721AssetData(
|
makerAssetData = assetDataUtils.encodeERC721AssetData(
|
||||||
this._erc721Token.address,
|
this._erc721Token.address,
|
||||||
erc721MakerAssetIds[0],
|
erc721MakerAssetIds[0],
|
||||||
);
|
);
|
||||||
@ -97,18 +95,16 @@ export class OrderFactoryFromScenario {
|
|||||||
|
|
||||||
switch (orderScenario.takerAssetDataScenario) {
|
switch (orderScenario.takerAssetDataScenario) {
|
||||||
case AssetDataScenario.ZRXFeeToken:
|
case AssetDataScenario.ZRXFeeToken:
|
||||||
takerAssetData = assetProxyUtils.encodeERC20AssetData(this._zrxAddress);
|
takerAssetData = assetDataUtils.encodeERC20AssetData(this._zrxAddress);
|
||||||
break;
|
break;
|
||||||
case AssetDataScenario.ERC20NonZRXEighteenDecimals:
|
case AssetDataScenario.ERC20NonZRXEighteenDecimals:
|
||||||
takerAssetData = assetProxyUtils.encodeERC20AssetData(
|
takerAssetData = assetDataUtils.encodeERC20AssetData(this._nonZrxERC20EighteenDecimalTokenAddresses[1]);
|
||||||
this._nonZrxERC20EighteenDecimalTokenAddresses[1],
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
case AssetDataScenario.ERC20FiveDecimals:
|
case AssetDataScenario.ERC20FiveDecimals:
|
||||||
takerAssetData = assetProxyUtils.encodeERC20AssetData(this._erc20FiveDecimalTokenAddresses[1]);
|
takerAssetData = assetDataUtils.encodeERC20AssetData(this._erc20FiveDecimalTokenAddresses[1]);
|
||||||
break;
|
break;
|
||||||
case AssetDataScenario.ERC721:
|
case AssetDataScenario.ERC721:
|
||||||
takerAssetData = assetProxyUtils.encodeERC721AssetData(
|
takerAssetData = assetDataUtils.encodeERC721AssetData(
|
||||||
this._erc721Token.address,
|
this._erc721Token.address,
|
||||||
erc721TakerAssetIds[0],
|
erc721TakerAssetIds[0],
|
||||||
);
|
);
|
||||||
|
21
packages/contracts/test/utils/type_encoding_utils.ts
Normal file
21
packages/contracts/test/utils/type_encoding_utils.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { BigNumber } from '@0xproject/utils';
|
||||||
|
import BN = require('bn.js');
|
||||||
|
import ethUtil = require('ethereumjs-util');
|
||||||
|
|
||||||
|
import { constants } from './constants';
|
||||||
|
|
||||||
|
export const typeEncodingUtils = {
|
||||||
|
encodeUint256(value: BigNumber): Buffer {
|
||||||
|
const base = 10;
|
||||||
|
const formattedValue = new BN(value.toString(base));
|
||||||
|
const encodedValue = ethUtil.toBuffer(formattedValue);
|
||||||
|
// tslint:disable-next-line:custom-no-magic-numbers
|
||||||
|
const paddedValue = ethUtil.setLengthLeft(encodedValue, constants.WORD_LENGTH);
|
||||||
|
return paddedValue;
|
||||||
|
},
|
||||||
|
decodeUint256(encodedValue: Buffer): BigNumber {
|
||||||
|
const formattedValue = ethUtil.bufferToHex(encodedValue);
|
||||||
|
const value = new BigNumber(formattedValue, constants.BASE_16);
|
||||||
|
return value;
|
||||||
|
},
|
||||||
|
};
|
@ -1,4 +1,4 @@
|
|||||||
import { assetProxyUtils, orderFactory } from '@0xproject/order-utils';
|
import { assetDataUtils, orderFactory } from '@0xproject/order-utils';
|
||||||
import { OrderWithoutExchangeAddress, SignedOrder } from '@0xproject/types';
|
import { OrderWithoutExchangeAddress, SignedOrder } from '@0xproject/types';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||||
@ -146,9 +146,9 @@ export class FillScenarios {
|
|||||||
feeRecepientAddress: string,
|
feeRecepientAddress: string,
|
||||||
expirationTimeSeconds?: BigNumber,
|
expirationTimeSeconds?: BigNumber,
|
||||||
): Promise<SignedOrder> {
|
): Promise<SignedOrder> {
|
||||||
const makerERC20AssetData = assetProxyUtils.decodeERC20AssetData(makerAssetData);
|
const makerERC20AssetData = assetDataUtils.decodeERC20AssetData(makerAssetData);
|
||||||
const makerTokenAddress = makerERC20AssetData.tokenAddress;
|
const makerTokenAddress = makerERC20AssetData.tokenAddress;
|
||||||
const takerERC20AssetData = assetProxyUtils.decodeERC20AssetData(takerAssetData);
|
const takerERC20AssetData = assetDataUtils.decodeERC20AssetData(takerAssetData);
|
||||||
const takerTokenAddress = takerERC20AssetData.tokenAddress;
|
const takerTokenAddress = takerERC20AssetData.tokenAddress;
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
this._increaseERC20BalanceAndAllowanceAsync(makerTokenAddress, makerAddress, makerFillableAmount),
|
this._increaseERC20BalanceAndAllowanceAsync(makerTokenAddress, makerAddress, makerFillableAmount),
|
||||||
|
8
packages/migrations/src/2.0.0/migration.ts
vendored
8
packages/migrations/src/2.0.0/migration.ts
vendored
@ -1,4 +1,4 @@
|
|||||||
import { assetProxyUtils } from '@0xproject/order-utils';
|
import { assetDataUtils } from '@0xproject/order-utils';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||||
import { Provider, TxData } from 'ethereum-types';
|
import { Provider, TxData } from 'ethereum-types';
|
||||||
@ -53,7 +53,7 @@ export const runV2MigrationsAsync = async (provider: Provider, artifactsDir: str
|
|||||||
artifacts.Exchange,
|
artifacts.Exchange,
|
||||||
provider,
|
provider,
|
||||||
txDefaults,
|
txDefaults,
|
||||||
assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
);
|
);
|
||||||
artifactsWriter.saveArtifact(exchange);
|
artifactsWriter.saveArtifact(exchange);
|
||||||
|
|
||||||
@ -137,8 +137,8 @@ export const runV2MigrationsAsync = async (provider: Provider, artifactsDir: str
|
|||||||
exchange.address,
|
exchange.address,
|
||||||
etherToken.address,
|
etherToken.address,
|
||||||
zrxToken.address,
|
zrxToken.address,
|
||||||
assetProxyUtils.encodeERC20AssetData(zrxToken.address),
|
assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||||
assetProxyUtils.encodeERC20AssetData(etherToken.address),
|
assetDataUtils.encodeERC20AssetData(etherToken.address),
|
||||||
);
|
);
|
||||||
artifactsWriter.saveArtifact(forwarder);
|
artifactsWriter.saveArtifact(forwarder);
|
||||||
};
|
};
|
||||||
|
@ -54,7 +54,6 @@
|
|||||||
"@0xproject/dev-utils": "^0.4.5",
|
"@0xproject/dev-utils": "^0.4.5",
|
||||||
"@0xproject/monorepo-scripts": "^0.2.2",
|
"@0xproject/monorepo-scripts": "^0.2.2",
|
||||||
"@0xproject/tslint-config": "^0.4.21",
|
"@0xproject/tslint-config": "^0.4.21",
|
||||||
"@types/ethereumjs-abi": "^0.6.0",
|
|
||||||
"@types/bn.js": "^4.11.0",
|
"@types/bn.js": "^4.11.0",
|
||||||
"@types/lodash": "4.14.104",
|
"@types/lodash": "4.14.104",
|
||||||
"chai": "^4.0.1",
|
"chai": "^4.0.1",
|
||||||
|
@ -1,64 +1,25 @@
|
|||||||
import { AssetProxyId, ERC20AssetData, ERC721AssetData } from '@0xproject/types';
|
import { AssetProxyId, ERC20AssetData, ERC721AssetData } from '@0xproject/types';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
import BN = require('bn.js');
|
import ethAbi = require('ethereumjs-abi');
|
||||||
import ethUtil = require('ethereumjs-util');
|
import ethUtil = require('ethereumjs-util');
|
||||||
|
|
||||||
import { constants } from './constants';
|
import { constants } from './constants';
|
||||||
|
|
||||||
// TODO: Push upstream to DefinitelyTyped
|
export const assetDataUtils = {
|
||||||
interface EthAbi {
|
/**
|
||||||
simpleEncode(signature: string, ...args: any[]): Buffer;
|
* Encodes an ERC20 token address into a hex encoded assetData string, usable in the makerAssetData or
|
||||||
rawDecode(signature: string[], data: Buffer): any[];
|
* takerAssetData fields in a 0x order.
|
||||||
}
|
* @param tokenAddress The ERC20 token address to encode
|
||||||
// tslint:disable:no-var-requires
|
* @return The hex encoded assetData string
|
||||||
const ethAbi = require('ethereumjs-abi') as EthAbi;
|
*/
|
||||||
|
|
||||||
export const assetProxyUtils = {
|
|
||||||
encodeAssetProxyId(assetProxyId: AssetProxyId): Buffer {
|
|
||||||
return ethUtil.toBuffer(assetProxyId);
|
|
||||||
},
|
|
||||||
decodeAssetProxyId(encodedAssetProxyId: Buffer): AssetProxyId {
|
|
||||||
const hexString = ethUtil.bufferToHex(encodedAssetProxyId);
|
|
||||||
if (hexString === AssetProxyId.ERC20) {
|
|
||||||
return AssetProxyId.ERC20;
|
|
||||||
}
|
|
||||||
if (hexString === AssetProxyId.ERC721) {
|
|
||||||
return AssetProxyId.ERC721;
|
|
||||||
}
|
|
||||||
throw new Error(`Invalid ProxyId: ${hexString}`);
|
|
||||||
},
|
|
||||||
encodeAddress(address: string): Buffer {
|
|
||||||
if (!ethUtil.isValidAddress(address)) {
|
|
||||||
throw new Error(`Invalid Address: ${address}`);
|
|
||||||
}
|
|
||||||
const encodedAddress = ethUtil.toBuffer(address);
|
|
||||||
const padded = ethUtil.setLengthLeft(encodedAddress, constants.WORD_LENGTH);
|
|
||||||
return padded;
|
|
||||||
},
|
|
||||||
decodeAddress(encodedAddress: Buffer): string {
|
|
||||||
const unpadded = ethUtil.setLengthLeft(encodedAddress, constants.ADDRESS_LENGTH);
|
|
||||||
const address = ethUtil.bufferToHex(unpadded);
|
|
||||||
if (!ethUtil.isValidAddress(address)) {
|
|
||||||
throw new Error(`Invalid Address: ${address}`);
|
|
||||||
}
|
|
||||||
return address;
|
|
||||||
},
|
|
||||||
encodeUint256(value: BigNumber): Buffer {
|
|
||||||
const base = 10;
|
|
||||||
const formattedValue = new BN(value.toString(base));
|
|
||||||
const encodedValue = ethUtil.toBuffer(formattedValue);
|
|
||||||
// tslint:disable-next-line:custom-no-magic-numbers
|
|
||||||
const paddedValue = ethUtil.setLengthLeft(encodedValue, constants.WORD_LENGTH);
|
|
||||||
return paddedValue;
|
|
||||||
},
|
|
||||||
decodeUint256(encodedValue: Buffer): BigNumber {
|
|
||||||
const formattedValue = ethUtil.bufferToHex(encodedValue);
|
|
||||||
const value = new BigNumber(formattedValue, constants.BASE_16);
|
|
||||||
return value;
|
|
||||||
},
|
|
||||||
encodeERC20AssetData(tokenAddress: string): string {
|
encodeERC20AssetData(tokenAddress: string): string {
|
||||||
return ethUtil.bufferToHex(ethAbi.simpleEncode('ERC20Token(address)', tokenAddress));
|
return ethUtil.bufferToHex(ethAbi.simpleEncode('ERC20Token(address)', tokenAddress));
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Decodes an ERC20 assetData hex string into it's corresponding ERC20 tokenAddress & assetProxyId
|
||||||
|
* @param assetData Hex encoded assetData string to decode
|
||||||
|
* @return An object containing the decoded tokenAddress & assetProxyId
|
||||||
|
*/
|
||||||
decodeERC20AssetData(assetData: string): ERC20AssetData {
|
decodeERC20AssetData(assetData: string): ERC20AssetData {
|
||||||
const data = ethUtil.toBuffer(assetData);
|
const data = ethUtil.toBuffer(assetData);
|
||||||
if (data.byteLength < constants.ERC20_ASSET_DATA_BYTE_LENGTH) {
|
if (data.byteLength < constants.ERC20_ASSET_DATA_BYTE_LENGTH) {
|
||||||
@ -82,6 +43,13 @@ export const assetProxyUtils = {
|
|||||||
tokenAddress: ethUtil.addHexPrefix(tokenAddress),
|
tokenAddress: ethUtil.addHexPrefix(tokenAddress),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Encodes an ERC721 token address into a hex encoded assetData string, usable in the makerAssetData or
|
||||||
|
* takerAssetData fields in a 0x order.
|
||||||
|
* @param tokenAddress The ERC721 token address to encode
|
||||||
|
* @param tokenId The ERC721 tokenId to encode
|
||||||
|
* @return The hex encoded assetData string
|
||||||
|
*/
|
||||||
encodeERC721AssetData(tokenAddress: string, tokenId: BigNumber, receiverData?: string): string {
|
encodeERC721AssetData(tokenAddress: string, tokenId: BigNumber, receiverData?: string): string {
|
||||||
// TODO: Pass `tokendId` as a BigNumber.
|
// TODO: Pass `tokendId` as a BigNumber.
|
||||||
return ethUtil.bufferToHex(
|
return ethUtil.bufferToHex(
|
||||||
@ -93,6 +61,11 @@ export const assetProxyUtils = {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Decodes an ERC721 assetData hex string into it's corresponding ERC721 tokenAddress, tokenId & assetProxyId
|
||||||
|
* @param assetData Hex encoded assetData string to decode
|
||||||
|
* @return An object containing the decoded tokenAddress, tokenId & assetProxyId
|
||||||
|
*/
|
||||||
decodeERC721AssetData(assetData: string): ERC721AssetData {
|
decodeERC721AssetData(assetData: string): ERC721AssetData {
|
||||||
const data = ethUtil.toBuffer(assetData);
|
const data = ethUtil.toBuffer(assetData);
|
||||||
if (data.byteLength < constants.ERC721_ASSET_DATA_MINIMUM_BYTE_LENGTH) {
|
if (data.byteLength < constants.ERC721_ASSET_DATA_MINIMUM_BYTE_LENGTH) {
|
||||||
@ -121,30 +94,51 @@ export const assetProxyUtils = {
|
|||||||
receiverData: ethUtil.bufferToHex(receiverData),
|
receiverData: ethUtil.bufferToHex(receiverData),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
decodeAssetDataId(assetData: string): AssetProxyId {
|
/**
|
||||||
|
* Decode and return the assetProxyId from the assetData
|
||||||
|
* @param assetData Hex encoded assetData string to decode
|
||||||
|
* @return The assetProxyId
|
||||||
|
*/
|
||||||
|
decodeAssetProxyId(assetData: string): AssetProxyId {
|
||||||
const encodedAssetData = ethUtil.toBuffer(assetData);
|
const encodedAssetData = ethUtil.toBuffer(assetData);
|
||||||
if (encodedAssetData.byteLength < constants.SELECTOR_LENGTH) {
|
if (encodedAssetData.byteLength < constants.SELECTOR_LENGTH) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Could not decode Proxy Data. Expected length of encoded data to be at least 4. Got ${
|
`Could not decode assetData. Expected length of encoded data to be at least 4. Got ${
|
||||||
encodedAssetData.byteLength
|
encodedAssetData.byteLength
|
||||||
}`,
|
}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const encodedAssetProxyId = encodedAssetData.slice(0, constants.SELECTOR_LENGTH);
|
const encodedAssetProxyId = encodedAssetData.slice(0, constants.SELECTOR_LENGTH);
|
||||||
const assetProxyId = assetProxyUtils.decodeAssetProxyId(encodedAssetProxyId);
|
const assetProxyId = decodeAssetProxyId(encodedAssetProxyId);
|
||||||
return assetProxyId;
|
return assetProxyId;
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Decode any assetData into it's corresponding assetData object
|
||||||
|
* @param assetData Hex encoded assetData string to decode
|
||||||
|
* @return Either a ERC20 or ERC721 assetData object
|
||||||
|
*/
|
||||||
decodeAssetData(assetData: string): ERC20AssetData | ERC721AssetData {
|
decodeAssetData(assetData: string): ERC20AssetData | ERC721AssetData {
|
||||||
const assetProxyId = assetProxyUtils.decodeAssetDataId(assetData);
|
const assetProxyId = assetDataUtils.decodeAssetProxyId(assetData);
|
||||||
switch (assetProxyId) {
|
switch (assetProxyId) {
|
||||||
case AssetProxyId.ERC20:
|
case AssetProxyId.ERC20:
|
||||||
const erc20AssetData = assetProxyUtils.decodeERC20AssetData(assetData);
|
const erc20AssetData = assetDataUtils.decodeERC20AssetData(assetData);
|
||||||
return erc20AssetData;
|
return erc20AssetData;
|
||||||
case AssetProxyId.ERC721:
|
case AssetProxyId.ERC721:
|
||||||
const erc721AssetData = assetProxyUtils.decodeERC721AssetData(assetData);
|
const erc721AssetData = assetDataUtils.decodeERC721AssetData(assetData);
|
||||||
return erc721AssetData;
|
return erc721AssetData;
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unrecognized asset proxy id: ${assetProxyId}`);
|
throw new Error(`Unrecognized asset proxy id: ${assetProxyId}`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function decodeAssetProxyId(encodedAssetProxyId: Buffer): AssetProxyId {
|
||||||
|
const hexString = ethUtil.bufferToHex(encodedAssetProxyId);
|
||||||
|
if (hexString === AssetProxyId.ERC20) {
|
||||||
|
return AssetProxyId.ERC20;
|
||||||
|
}
|
||||||
|
if (hexString === AssetProxyId.ERC721) {
|
||||||
|
return AssetProxyId.ERC721;
|
||||||
|
}
|
||||||
|
throw new Error(`Invalid ProxyId: ${hexString}`);
|
||||||
|
}
|
@ -6,7 +6,6 @@ export const constants = {
|
|||||||
UNLIMITED_ALLOWANCE_IN_BASE_UNITS: new BigNumber(2).pow(256).minus(1),
|
UNLIMITED_ALLOWANCE_IN_BASE_UNITS: new BigNumber(2).pow(256).minus(1),
|
||||||
TESTRPC_NETWORK_ID: 50,
|
TESTRPC_NETWORK_ID: 50,
|
||||||
ADDRESS_LENGTH: 20,
|
ADDRESS_LENGTH: 20,
|
||||||
WORD_LENGTH: 32,
|
|
||||||
ERC20_ASSET_DATA_BYTE_LENGTH: 36,
|
ERC20_ASSET_DATA_BYTE_LENGTH: 36,
|
||||||
ERC721_ASSET_DATA_MINIMUM_BYTE_LENGTH: 53,
|
ERC721_ASSET_DATA_MINIMUM_BYTE_LENGTH: 53,
|
||||||
SELECTOR_LENGTH: 4,
|
SELECTOR_LENGTH: 4,
|
||||||
|
@ -19,7 +19,7 @@ export { AbstractOrderFilledCancelledFetcher } from './abstract/abstract_order_f
|
|||||||
export { BalanceAndProxyAllowanceLazyStore } from './store/balance_and_proxy_allowance_lazy_store';
|
export { BalanceAndProxyAllowanceLazyStore } from './store/balance_and_proxy_allowance_lazy_store';
|
||||||
export { RemainingFillableCalculator } from './remaining_fillable_calculator';
|
export { RemainingFillableCalculator } from './remaining_fillable_calculator';
|
||||||
export { OrderStateUtils } from './order_state_utils';
|
export { OrderStateUtils } from './order_state_utils';
|
||||||
export { assetProxyUtils } from './asset_proxy_utils';
|
export { assetDataUtils } from './asset_data_utils';
|
||||||
export { EIP712Utils } from './eip712_utils';
|
export { EIP712Utils } from './eip712_utils';
|
||||||
export { OrderValidationUtils } from './order_validation_utils';
|
export { OrderValidationUtils } from './order_validation_utils';
|
||||||
export { ExchangeTransferSimulator } from './exchange_transfer_simulator';
|
export { ExchangeTransferSimulator } from './exchange_transfer_simulator';
|
||||||
|
@ -4,7 +4,7 @@ import { BigNumber } from '@0xproject/utils';
|
|||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
|
|
||||||
import { artifacts } from '../src/artifacts';
|
import { artifacts } from '../src/artifacts';
|
||||||
import { assetProxyUtils } from '../src/asset_proxy_utils';
|
import { assetDataUtils } from '../src/asset_data_utils';
|
||||||
import { constants } from '../src/constants';
|
import { constants } from '../src/constants';
|
||||||
import { ExchangeTransferSimulator } from '../src/exchange_transfer_simulator';
|
import { ExchangeTransferSimulator } from '../src/exchange_transfer_simulator';
|
||||||
import { DummyERC20TokenContract } from '../src/generated_contract_wrappers/dummy_erc20_token';
|
import { DummyERC20TokenContract } from '../src/generated_contract_wrappers/dummy_erc20_token';
|
||||||
@ -66,7 +66,7 @@ describe('ExchangeTransferSimulator', async () => {
|
|||||||
totalSupply,
|
totalSupply,
|
||||||
);
|
);
|
||||||
|
|
||||||
exampleAssetData = assetProxyUtils.encodeERC20AssetData(dummyERC20Token.address);
|
exampleAssetData = assetDataUtils.encodeERC20AssetData(dummyERC20Token.address);
|
||||||
});
|
});
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await blockchainLifecycle.startAsync();
|
await blockchainLifecycle.startAsync();
|
||||||
|
7
packages/typescript-typings/types/ethereumjs-abi/index.d.ts
vendored
Normal file
7
packages/typescript-typings/types/ethereumjs-abi/index.d.ts
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
declare module 'ethereumjs-abi' {
|
||||||
|
export function soliditySHA3(argTypes: string[], args: any[]): Buffer;
|
||||||
|
export function soliditySHA256(argTypes: string[], args: any[]): Buffer;
|
||||||
|
export function methodID(name: string, types: string[]): Buffer;
|
||||||
|
export function simpleEncode(signature: string, ...args: any[]): Buffer;
|
||||||
|
export function rawDecode(signature: string[], data: Buffer): any[];
|
||||||
|
}
|
@ -181,6 +181,32 @@ const docsInfoConfig: DocsInfoConfig = {
|
|||||||
'JSONRPCErrorCallback',
|
'JSONRPCErrorCallback',
|
||||||
'LogEntryEvent',
|
'LogEntryEvent',
|
||||||
'LogEntry',
|
'LogEntry',
|
||||||
|
'ERC20AssetData',
|
||||||
|
'ERC721AssetData',
|
||||||
|
'AssetProxyId',
|
||||||
|
'WETH9Events',
|
||||||
|
'WETH9WithdrawalEventArgs',
|
||||||
|
'WETH9ApprovalEventArgs',
|
||||||
|
'WETH9EventArgs',
|
||||||
|
'WETH9DepositEventArgs',
|
||||||
|
'WETH9TransferEventArgs',
|
||||||
|
'ERC20TokenTransferEventArgs',
|
||||||
|
'ERC20TokenApprovalEventArgs',
|
||||||
|
'ERC20TokenEvents',
|
||||||
|
'ERC20TokenEventArgs',
|
||||||
|
'ERC721TokenApprovalEventArgs',
|
||||||
|
'ERC721TokenApprovalForAllEventArgs',
|
||||||
|
'ERC721TokenTransferEventArgs',
|
||||||
|
'ERC721TokenEvents',
|
||||||
|
'ExchangeCancelUpToEventArgs',
|
||||||
|
'ExchangeAssetProxyRegisteredEventArgs',
|
||||||
|
'ExchangeFillEventArgs',
|
||||||
|
'ExchangeCancelEventArgs',
|
||||||
|
'ExchangeEventArgs',
|
||||||
|
'ContractWrappersConfig',
|
||||||
|
'MessagePrefixType',
|
||||||
|
'MessagePrefixOpts',
|
||||||
|
'OrderInfo',
|
||||||
],
|
],
|
||||||
typeNameToPrefix: {},
|
typeNameToPrefix: {},
|
||||||
typeNameToExternalLink: {
|
typeNameToExternalLink: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user