Merge development branch

This commit is contained in:
Fabio Berger 2018-08-22 11:41:42 +01:00
commit 0248add542
125 changed files with 7832 additions and 60377 deletions

4
.gitignore vendored
View File

@ -84,8 +84,12 @@ packages/order-watcher/test/artifacts/
packages/contract-wrappers/test/artifacts/ packages/contract-wrappers/test/artifacts/
packages/contract-wrappers/src/artifacts/ packages/contract-wrappers/src/artifacts/
packages/order-watcher/src/artifacts/ packages/order-watcher/src/artifacts/
packages/0x.js/src/artifacts/
packages/order-utils/src/artifacts/ packages/order-utils/src/artifacts/
# unstable generated contract artifacts:
packages/migrations/artifacts/2.0.0/
# generated contract watcher # generated contract watcher
packages/0x.js/src/generated_contract_wrappers/ packages/0x.js/src/generated_contract_wrappers/
packages/contracts/generated_contract_wrappers/ packages/contracts/generated_contract_wrappers/

8
CODEOWNERS Normal file
View File

@ -0,0 +1,8 @@
# See https://help.github.com/articles/about-codeowners/
# for more info about CODEOWNERS file
# It uses the same pattern rule for gitignore file
# https://git-scm.com/docs/gitignore#_pattern_format
# Website
packages/website/ @BMillman19 @fragosti

View File

@ -33,6 +33,7 @@ If you're developing on 0x now or are interested in using 0x infrastructure in t
| [`@0xproject/monorepo-scripts`](/packages/monorepo-scripts) | [![npm](https://img.shields.io/npm/v/@0xproject/monorepo-scripts.svg)](https://www.npmjs.com/package/@0xproject/monorepo-scripts) | Monorepo scripts | | [`@0xproject/monorepo-scripts`](/packages/monorepo-scripts) | [![npm](https://img.shields.io/npm/v/@0xproject/monorepo-scripts.svg)](https://www.npmjs.com/package/@0xproject/monorepo-scripts) | Monorepo scripts |
| [`@0xproject/react-docs`](/packages/react-docs) | [![npm](https://img.shields.io/npm/v/@0xproject/react-docs.svg)](https://www.npmjs.com/package/@0xproject/react-docs) | React documentation component for rendering TypeDoc & Doxity generated JSON | | [`@0xproject/react-docs`](/packages/react-docs) | [![npm](https://img.shields.io/npm/v/@0xproject/react-docs.svg)](https://www.npmjs.com/package/@0xproject/react-docs) | React documentation component for rendering TypeDoc & Doxity generated JSON |
| [`@0xproject/react-shared`](/packages/react-shared) | [![npm](https://img.shields.io/npm/v/@0xproject/react-shared.svg)](https://www.npmjs.com/package/@0xproject/react-shared) | 0x shared react components | | [`@0xproject/react-shared`](/packages/react-shared) | [![npm](https://img.shields.io/npm/v/@0xproject/react-shared.svg)](https://www.npmjs.com/package/@0xproject/react-shared) | 0x shared react components |
| [`@0xproject/sra-api`](/packages/sra-api) | [![npm](https://img.shields.io/npm/v/@0xproject/sra-api.svg)](https://www.npmjs.com/package/@0xproject/sra-api) | OpenAPI specification for the standard relayer API |
| [`@0xproject/sra-report`](/packages/sra-report) | [![npm](https://img.shields.io/npm/v/@0xproject/sra-report.svg)](https://www.npmjs.com/package/@0xproject/sra-report) | Generate reports for standard relayer API compliance | | [`@0xproject/sra-report`](/packages/sra-report) | [![npm](https://img.shields.io/npm/v/@0xproject/sra-report.svg)](https://www.npmjs.com/package/@0xproject/sra-report) | Generate reports for standard relayer API compliance |
| [`@0xproject/sol-cov`](/packages/sol-cov) | [![npm](https://img.shields.io/npm/v/@0xproject/sol-cov.svg)](https://www.npmjs.com/package/@0xproject/sol-cov) | Solidity test coverage tool | | [`@0xproject/sol-cov`](/packages/sol-cov) | [![npm](https://img.shields.io/npm/v/@0xproject/sol-cov.svg)](https://www.npmjs.com/package/@0xproject/sol-cov) | Solidity test coverage tool |
| [`@0xproject/subproviders`](/packages/subproviders) | [![npm](https://img.shields.io/npm/v/@0xproject/subproviders.svg)](https://www.npmjs.com/package/@0xproject/subproviders) | Useful web3 subproviders (e.g LedgerSubprovider) | | [`@0xproject/subproviders`](/packages/subproviders) | [![npm](https://img.shields.io/npm/v/@0xproject/subproviders.svg)](https://www.npmjs.com/package/@0xproject/subproviders) | Useful web3 subproviders (e.g LedgerSubprovider) |
@ -82,13 +83,7 @@ We strongly recommend that the community help us make improvements and determine
### Install dependencies ### Install dependencies
Make sure you are using Yarn v1.6. To install using brew: Make sure you are using Yarn v1.9.4. To install using brew:
```
brew unlink yarn
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/76215230de5f7f7bee2cfcdd7185cf49d949862d/Formula/yarn.rb
brew switch yarn 1.6.0_1
```
Then install dependencies Then install dependencies

View File

@ -42,7 +42,7 @@
"packagesWithDocPages": "0x.js connect json-schemas subproviders web3-wrapper contract-wrappers order-utils order-watcher sol-compiler sol-cov ethereum-types" "packagesWithDocPages": "0x.js connect json-schemas subproviders web3-wrapper contract-wrappers order-utils order-watcher sol-compiler sol-cov ethereum-types"
}, },
"devDependencies": { "devDependencies": {
"@0x-lerna-fork/lerna": "3.0.0-beta.23", "@0x-lerna-fork/lerna": "3.0.0-beta.25",
"async-child-process": "^1.1.1", "async-child-process": "^1.1.1",
"coveralls": "^3.0.0", "coveralls": "^3.0.0",
"ganache-cli": "6.1.3", "ganache-cli": "6.1.3",

View File

@ -5,6 +5,10 @@
{ {
"note": "Export missing ExchangeSignatureValidatorApprovalEventArgs type", "note": "Export missing ExchangeSignatureValidatorApprovalEventArgs type",
"pr": 924 "pr": 924
},
{
"note": "Added Transaction Encoder for use with 0x Exchange executeTransaction",
"pr": 975
} }
] ]
}, },

View File

@ -29,7 +29,7 @@
"docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_FILES" "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_FILES"
}, },
"config": { "config": {
"contracts_v2_beta": "Exchange ERC20Proxy ERC20Token ERC721Proxy ERC721Token WETH9 ZRXToken Forwarder", "contracts_v2_beta": "AssetProxyOwner Exchange ERC20Proxy ERC20Token ERC721Proxy ERC721Token WETH9 ZRXToken Forwarder OrderValidator",
"contracts_v2": "DummyERC20Token DummyERC721Token", "contracts_v2": "DummyERC20Token DummyERC721Token",
"postpublish": { "postpublish": {
"assets": [], "assets": [],

View File

@ -21,6 +21,7 @@ import {
} from '../types'; } from '../types';
import { assert } from '../utils/assert'; import { assert } from '../utils/assert';
import { decorators } from '../utils/decorators'; import { decorators } from '../utils/decorators';
import { TransactionEncoder } from '../utils/transaction_encoder';
import { ContractWrapper } from './contract_wrapper'; import { ContractWrapper } from './contract_wrapper';
import { ExchangeContract, ExchangeEventArgs, ExchangeEvents } from './generated/exchange'; import { ExchangeContract, ExchangeEventArgs, ExchangeEvents } from './generated/exchange';
@ -1109,6 +1110,16 @@ export class ExchangeWrapper extends ContractWrapper {
const zrxAssetData = assetDataUtils.encodeERC20AssetData(zrxTokenAddress); const zrxAssetData = assetDataUtils.encodeERC20AssetData(zrxTokenAddress);
return zrxAssetData; return zrxAssetData;
} }
/**
* Returns a Transaction Encoder. Transaction messages exist for the purpose of calling methods on the Exchange contract
* in the context of another address.
* @return TransactionEncoder
*/
public async transactionEncoderAsync(): Promise<TransactionEncoder> {
const exchangeInstance = await this._getExchangeContractAsync();
const encoder = new TransactionEncoder(exchangeInstance);
return encoder;
}
// tslint:disable:no-unused-variable // tslint:disable:no-unused-variable
private _invalidateContractInstances(): void { private _invalidateContractInstances(): void {
this.unsubscribeAll(); this.unsubscribeAll();

View File

@ -0,0 +1,293 @@
import { schemas } from '@0xproject/json-schemas';
import { EIP712Schema, EIP712Types, EIP712Utils } from '@0xproject/order-utils';
import { Order, SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import _ = require('lodash');
import { ExchangeContract } from '../contract_wrappers/generated/exchange';
import { assert } from './assert';
const EIP712_ZEROEX_TRANSACTION_SCHEMA: EIP712Schema = {
name: 'ZeroExTransaction',
parameters: [
{ name: 'salt', type: EIP712Types.Uint256 },
{ name: 'signerAddress', type: EIP712Types.Address },
{ name: 'data', type: EIP712Types.Bytes },
],
};
/**
* Transaction Encoder. Transaction messages exist for the purpose of calling methods on the Exchange contract
* in the context of another address. For example, UserA can encode and sign a fillOrder transaction and UserB
* can submit this to the blockchain. The Exchange context executes as if UserA had directly submitted this transaction.
*/
export class TransactionEncoder {
private _exchangeInstance: ExchangeContract;
constructor(exchangeInstance: ExchangeContract) {
this._exchangeInstance = exchangeInstance;
}
/**
* Encodes the transaction data for use with the Exchange contract.
* @param data The ABI Encoded 0x Exchange method. I.e fillOrder
* @param salt A random value to provide uniqueness and prevent replay attacks.
* @param signerAddress The address which will sign this transaction.
* @return An unsigned hex encoded transaction for use in 0x Exchange executeTransaction.
*/
public getTransactionHex(data: string, salt: BigNumber, signerAddress: string): string {
const exchangeAddress = this._getExchangeContract().address;
const executeTransactionData = {
salt,
signerAddress,
data,
};
const executeTransactionHashBuff = EIP712Utils.structHash(
EIP712_ZEROEX_TRANSACTION_SCHEMA,
executeTransactionData,
);
const eip721MessageBuffer = EIP712Utils.createEIP712Message(executeTransactionHashBuff, exchangeAddress);
const messageHex = `0x${eip721MessageBuffer.toString('hex')}`;
return messageHex;
}
/**
* Encodes a fillOrder transaction.
* @param signedOrder An object that conforms to the SignedOrder interface.
* @param takerAssetFillAmount The amount of the order (in taker asset baseUnits) that you wish to fill.
* @return Hex encoded abi of the function call.
*/
public fillOrderTx(signedOrder: SignedOrder, takerAssetFillAmount: BigNumber): string {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
assert.isValidBaseUnitAmount('takerAssetFillAmount', takerAssetFillAmount);
const abiEncodedData = this._getExchangeContract().fillOrder.getABIEncodedTransactionData(
signedOrder,
takerAssetFillAmount,
signedOrder.signature,
);
return abiEncodedData;
}
/**
* Encodes a fillOrderNoThrow transaction.
* @param signedOrder An object that conforms to the SignedOrder interface.
* @param takerAssetFillAmount The amount of the order (in taker asset baseUnits) that you wish to fill.
* @return Hex encoded abi of the function call.
*/
public fillOrderNoThrowTx(signedOrder: SignedOrder, takerAssetFillAmount: BigNumber): string {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
assert.isValidBaseUnitAmount('takerAssetFillAmount', takerAssetFillAmount);
const abiEncodedData = this._getExchangeContract().fillOrderNoThrow.getABIEncodedTransactionData(
signedOrder,
takerAssetFillAmount,
signedOrder.signature,
);
return abiEncodedData;
}
/**
* Encodes a fillOrKillOrder transaction.
* @param signedOrder An object that conforms to the SignedOrder interface.
* @param takerAssetFillAmount The amount of the order (in taker asset baseUnits) that you wish to fill.
* @return Hex encoded abi of the function call.
*/
public fillOrKillOrderTx(signedOrder: SignedOrder, takerAssetFillAmount: BigNumber): string {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
assert.isValidBaseUnitAmount('takerAssetFillAmount', takerAssetFillAmount);
const abiEncodedData = this._getExchangeContract().fillOrKillOrder.getABIEncodedTransactionData(
signedOrder,
takerAssetFillAmount,
signedOrder.signature,
);
return abiEncodedData;
}
/**
* Encodes a batchFillOrders transaction.
* @param signedOrders An array of signed orders to fill.
* @param takerAssetFillAmounts The amounts of the orders (in taker asset baseUnits) that you wish to fill.
* @return Hex encoded abi of the function call.
*/
public batchFillOrdersTx(signedOrders: SignedOrder[], takerAssetFillAmounts: BigNumber[]): string {
assert.doesConformToSchema('signedOrders', signedOrders, schemas.signedOrdersSchema);
_.forEach(takerAssetFillAmounts, takerAssetFillAmount =>
assert.isBigNumber('takerAssetFillAmount', takerAssetFillAmount),
);
const signatures = _.map(signedOrders, signedOrder => signedOrder.signature);
const abiEncodedData = this._getExchangeContract().batchFillOrders.getABIEncodedTransactionData(
signedOrders,
takerAssetFillAmounts,
signatures,
);
return abiEncodedData;
}
/**
* Encodes a batchFillOrKillOrders transaction.
* @param signedOrders An array of signed orders to fill.
* @param takerAssetFillAmounts The amounts of the orders (in taker asset baseUnits) that you wish to fill.
* @return Hex encoded abi of the function call.
*/
public batchFillOrKillOrdersTx(signedOrders: SignedOrder[], takerAssetFillAmounts: BigNumber[]): string {
assert.doesConformToSchema('signedOrders', signedOrders, schemas.signedOrdersSchema);
_.forEach(takerAssetFillAmounts, takerAssetFillAmount =>
assert.isBigNumber('takerAssetFillAmount', takerAssetFillAmount),
);
const signatures = _.map(signedOrders, signedOrder => signedOrder.signature);
const abiEncodedData = this._getExchangeContract().batchFillOrKillOrders.getABIEncodedTransactionData(
signedOrders,
takerAssetFillAmounts,
signatures,
);
return abiEncodedData;
}
/**
* Encodes a batchFillOrdersNoThrow transaction.
* @param signedOrders An array of signed orders to fill.
* @param takerAssetFillAmounts The amounts of the orders (in taker asset baseUnits) that you wish to fill.
* @return Hex encoded abi of the function call.
*/
public batchFillOrdersNoThrowTx(signedOrders: SignedOrder[], takerAssetFillAmounts: BigNumber[]): string {
assert.doesConformToSchema('signedOrders', signedOrders, schemas.signedOrdersSchema);
_.forEach(takerAssetFillAmounts, takerAssetFillAmount =>
assert.isBigNumber('takerAssetFillAmount', takerAssetFillAmount),
);
const signatures = _.map(signedOrders, signedOrder => signedOrder.signature);
const abiEncodedData = this._getExchangeContract().batchFillOrdersNoThrow.getABIEncodedTransactionData(
signedOrders,
takerAssetFillAmounts,
signatures,
);
return abiEncodedData;
}
/**
* Encodes a batchCancelOrders transaction.
* @param signedOrders An array of orders to cancel.
* @return Hex encoded abi of the function call.
*/
public batchCancelOrdersTx(signedOrders: SignedOrder[]): string {
assert.doesConformToSchema('signedOrders', signedOrders, schemas.signedOrdersSchema);
const abiEncodedData = this._getExchangeContract().batchCancelOrders.getABIEncodedTransactionData(signedOrders);
return abiEncodedData;
}
/**
* Encodes a cancelOrdersUpTo transaction.
* @param targetOrderEpoch Target order epoch.
* @return Hex encoded abi of the function call.
*/
public cancelOrdersUpToTx(targetOrderEpoch: BigNumber): string {
assert.isBigNumber('targetOrderEpoch', targetOrderEpoch);
const abiEncodedData = this._getExchangeContract().cancelOrdersUpTo.getABIEncodedTransactionData(
targetOrderEpoch,
);
return abiEncodedData;
}
/**
* Encodes a cancelOrder transaction.
* @param order An object that conforms to the Order or SignedOrder interface. The order you would like to cancel.
* @return Hex encoded abi of the function call.
*/
public cancelOrderTx(order: Order | SignedOrder): string {
assert.doesConformToSchema('order', order, schemas.orderSchema);
const abiEncodedData = this._getExchangeContract().cancelOrder.getABIEncodedTransactionData(order);
return abiEncodedData;
}
/**
* Encodes a marketSellOrders transaction.
* @param signedOrders An array of signed orders to fill.
* @param takerAssetFillAmount Taker asset fill amount.
* @return Hex encoded abi of the function call.
*/
public marketSellOrdersTx(signedOrders: SignedOrder[], takerAssetFillAmount: BigNumber): string {
assert.doesConformToSchema('signedOrders', signedOrders, schemas.signedOrdersSchema);
assert.isBigNumber('takerAssetFillAmount', takerAssetFillAmount);
const signatures = _.map(signedOrders, signedOrder => signedOrder.signature);
const abiEncodedData = this._getExchangeContract().marketSellOrders.getABIEncodedTransactionData(
signedOrders,
takerAssetFillAmount,
signatures,
);
return abiEncodedData;
}
/**
* Encodes a marketSellOrdersNoThrow transaction.
* @param signedOrders An array of signed orders to fill.
* @param takerAssetFillAmount Taker asset fill amount.
* @return Hex encoded abi of the function call.
*/
public marketSellOrdersNoThrowTx(signedOrders: SignedOrder[], takerAssetFillAmount: BigNumber): string {
assert.doesConformToSchema('signedOrders', signedOrders, schemas.signedOrdersSchema);
assert.isBigNumber('takerAssetFillAmount', takerAssetFillAmount);
const signatures = _.map(signedOrders, signedOrder => signedOrder.signature);
const abiEncodedData = this._getExchangeContract().marketSellOrdersNoThrow.getABIEncodedTransactionData(
signedOrders,
takerAssetFillAmount,
signatures,
);
return abiEncodedData;
}
/**
* Encodes a maketBuyOrders transaction.
* @param signedOrders An array of signed orders to fill.
* @param makerAssetFillAmount Maker asset fill amount.
* @return Hex encoded abi of the function call.
*/
public marketBuyOrdersTx(signedOrders: SignedOrder[], makerAssetFillAmount: BigNumber): string {
assert.doesConformToSchema('signedOrders', signedOrders, schemas.signedOrdersSchema);
assert.isBigNumber('makerAssetFillAmount', makerAssetFillAmount);
const signatures = _.map(signedOrders, signedOrder => signedOrder.signature);
const abiEncodedData = this._getExchangeContract().marketBuyOrders.getABIEncodedTransactionData(
signedOrders,
makerAssetFillAmount,
signatures,
);
return abiEncodedData;
}
/**
* Encodes a maketBuyOrdersNoThrow transaction.
* @param signedOrders An array of signed orders to fill.
* @param makerAssetFillAmount Maker asset fill amount.
* @return Hex encoded abi of the function call.
*/
public marketBuyOrdersNoThrowTx(signedOrders: SignedOrder[], makerAssetFillAmount: BigNumber): string {
assert.doesConformToSchema('signedOrders', signedOrders, schemas.signedOrdersSchema);
assert.isBigNumber('makerAssetFillAmount', makerAssetFillAmount);
const signatures = _.map(signedOrders, signedOrder => signedOrder.signature);
const abiEncodedData = this._getExchangeContract().marketBuyOrdersNoThrow.getABIEncodedTransactionData(
signedOrders,
makerAssetFillAmount,
signatures,
);
return abiEncodedData;
}
/**
* Encodes a preSign transaction.
* @param hash Hash to pre-sign
* @param signerAddress Address that should have signed the given hash.
* @param signature Proof that the hash has been signed by signer.
* @return Hex encoded abi of the function call.
*/
public preSignTx(hash: string, signerAddress: string, signature: string): string {
assert.isHexString('hash', hash);
assert.isETHAddressHex('signerAddress', signerAddress);
assert.isHexString('signature', signature);
const abiEncodedData = this._getExchangeContract().preSign.getABIEncodedTransactionData(
hash,
signerAddress,
signature,
);
return abiEncodedData;
}
/**
* Encodes a setSignatureValidatorApproval transaction.
* @param validatorAddress Validator contract address.
* @param isApproved Boolean value to set approval to.
* @return Hex encoded abi of the function call.
*/
public setSignatureValidatorApprovalTx(validatorAddress: string, isApproved: boolean): string {
assert.isETHAddressHex('validatorAddress', validatorAddress);
assert.isBoolean('isApproved', isApproved);
const abiEncodedData = this._getExchangeContract().setSignatureValidatorApproval.getABIEncodedTransactionData(
validatorAddress,
isApproved,
);
return abiEncodedData;
}
private _getExchangeContract(): ExchangeContract {
return this._exchangeInstance;
}
}

View File

@ -12,6 +12,6 @@ before('migrate contracts', async function(): Promise<void> {
gas: devConstants.GAS_LIMIT, gas: devConstants.GAS_LIMIT,
from: devConstants.TESTRPC_FIRST_ADDRESS, from: devConstants.TESTRPC_FIRST_ADDRESS,
}; };
const artifactsDir = `../migrations/artifacts/2.0.0`; const artifactsDir = `src/artifacts`;
await runV2MigrationsAsync(provider, artifactsDir, txDefaults); await runV2MigrationsAsync(provider, artifactsDir, txDefaults);
}); });

View File

@ -0,0 +1,211 @@
import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { FillScenarios } from '@0xproject/fill-scenarios';
import { assetDataUtils, ecSignOrderHashAsync, generatePseudoRandomSalt, orderHashUtils } from '@0xproject/order-utils';
import { SignedOrder, SignerType } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import 'mocha';
import { ContractWrappers } from '../src';
import { TransactionEncoder } from '../src/utils/transaction_encoder';
import { constants } from './utils/constants';
import { tokenUtils } from './utils/token_utils';
import { provider, web3Wrapper } from './utils/web3_wrapper';
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe('TransactionEncoder', () => {
let contractWrappers: ContractWrappers;
let userAddresses: string[];
let fillScenarios: FillScenarios;
let exchangeContractAddress: string;
let makerTokenAddress: string;
let takerTokenAddress: string;
let coinbase: string;
let makerAddress: string;
let senderAddress: string;
let takerAddress: string;
let makerAssetData: string;
let takerAssetData: string;
let txHash: string;
const fillableAmount = new BigNumber(5);
const takerTokenFillAmount = new BigNumber(5);
let signedOrder: SignedOrder;
const config = {
networkId: constants.TESTRPC_NETWORK_ID,
blockPollingIntervalMs: 0,
};
before(async () => {
await blockchainLifecycle.startAsync();
contractWrappers = new ContractWrappers(provider, config);
exchangeContractAddress = contractWrappers.exchange.getContractAddress();
userAddresses = await web3Wrapper.getAvailableAddressesAsync();
const zrxTokenAddress = tokenUtils.getProtocolTokenAddress();
fillScenarios = new FillScenarios(
provider,
userAddresses,
zrxTokenAddress,
exchangeContractAddress,
contractWrappers.erc20Proxy.getContractAddress(),
contractWrappers.erc721Proxy.getContractAddress(),
);
[coinbase, makerAddress, takerAddress, senderAddress] = userAddresses;
[makerTokenAddress, takerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses();
[makerAssetData, takerAssetData] = [
assetDataUtils.encodeERC20AssetData(makerTokenAddress),
assetDataUtils.encodeERC20AssetData(takerTokenAddress),
];
signedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerAssetData,
takerAssetData,
makerAddress,
takerAddress,
fillableAmount,
);
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
});
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('encode and executeTransaction', () => {
const executeTransactionOrThrowAsync = async (
encoder: TransactionEncoder,
data: string,
signerAddress: string = takerAddress,
): Promise<void> => {
const salt = generatePseudoRandomSalt();
const encodedTransaction = encoder.getTransactionHex(data, salt, signerAddress);
const signature = await ecSignOrderHashAsync(
provider,
encodedTransaction,
signerAddress,
SignerType.Default,
);
txHash = await contractWrappers.exchange.executeTransactionAsync(
salt,
signerAddress,
data,
signature,
senderAddress,
);
await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
};
describe('#fillOrderTx', () => {
it('should successfully execute the transaction', async () => {
const encoder = await contractWrappers.exchange.transactionEncoderAsync();
const data = encoder.fillOrderTx(signedOrder, takerTokenFillAmount);
await executeTransactionOrThrowAsync(encoder, data);
});
});
describe('#fillOrderNoThrowTx', () => {
it('should successfully execute the transaction', async () => {
const encoder = await contractWrappers.exchange.transactionEncoderAsync();
const data = encoder.fillOrderNoThrowTx(signedOrder, takerTokenFillAmount);
await executeTransactionOrThrowAsync(encoder, data);
});
});
describe('#fillOrKillOrderTx', () => {
it('should successfully execute the transaction', async () => {
const encoder = await contractWrappers.exchange.transactionEncoderAsync();
const data = encoder.fillOrKillOrderTx(signedOrder, takerTokenFillAmount);
await executeTransactionOrThrowAsync(encoder, data);
});
});
describe('#marketSellOrdersTx', () => {
it('should successfully execute the transaction', async () => {
const encoder = await contractWrappers.exchange.transactionEncoderAsync();
const data = encoder.marketSellOrdersTx([signedOrder], takerTokenFillAmount);
await executeTransactionOrThrowAsync(encoder, data);
});
});
describe('#marketSellOrdersNoThrowTx', () => {
it('should successfully execute the transaction', async () => {
const encoder = await contractWrappers.exchange.transactionEncoderAsync();
const data = encoder.marketSellOrdersNoThrowTx([signedOrder], takerTokenFillAmount);
await executeTransactionOrThrowAsync(encoder, data);
});
});
describe('#marketBuyOrdersTx', () => {
it('should successfully execute the transaction', async () => {
const encoder = await contractWrappers.exchange.transactionEncoderAsync();
const data = encoder.marketBuyOrdersTx([signedOrder], fillableAmount);
await executeTransactionOrThrowAsync(encoder, data);
});
});
describe('#marketBuyOrdersNoThrowTx', () => {
it('should successfully execute the transaction', async () => {
const encoder = await contractWrappers.exchange.transactionEncoderAsync();
const data = encoder.marketBuyOrdersNoThrowTx([signedOrder], fillableAmount);
await executeTransactionOrThrowAsync(encoder, data);
});
});
describe('#preSignTx', () => {
it('should successfully execute the transaction', async () => {
const encoder = await contractWrappers.exchange.transactionEncoderAsync();
const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
const signature = signedOrder.signature;
const data = encoder.preSignTx(orderHash, makerAddress, signature);
await executeTransactionOrThrowAsync(encoder, data);
});
});
describe('#setSignatureValidatorApprovalTx', () => {
it('should successfully execute the transaction', async () => {
const encoder = await contractWrappers.exchange.transactionEncoderAsync();
const isApproved = true;
const data = encoder.setSignatureValidatorApprovalTx(senderAddress, isApproved);
await executeTransactionOrThrowAsync(encoder, data);
});
});
describe('#batchFillOrdersTx', () => {
it('should successfully execute the transaction', async () => {
const encoder = await contractWrappers.exchange.transactionEncoderAsync();
const data = encoder.batchFillOrdersTx([signedOrder], [takerTokenFillAmount]);
await executeTransactionOrThrowAsync(encoder, data);
});
});
describe('#batchFillOrKillOrdersTx', () => {
it('should successfully execute the transaction', async () => {
const encoder = await contractWrappers.exchange.transactionEncoderAsync();
const data = encoder.batchFillOrKillOrdersTx([signedOrder], [takerTokenFillAmount]);
await executeTransactionOrThrowAsync(encoder, data);
});
});
describe('#batchFillOrdersNoThrowTx', () => {
it('should successfully execute the transaction', async () => {
const encoder = await contractWrappers.exchange.transactionEncoderAsync();
const data = encoder.batchFillOrdersNoThrowTx([signedOrder], [takerTokenFillAmount]);
await executeTransactionOrThrowAsync(encoder, data);
});
});
describe('#batchCancelOrdersTx', () => {
it('should successfully execute the transaction', async () => {
const encoder = await contractWrappers.exchange.transactionEncoderAsync();
const data = encoder.batchCancelOrdersTx([signedOrder]);
const signerAddress = makerAddress;
await executeTransactionOrThrowAsync(encoder, data, signerAddress);
});
});
describe('#cancelOrderTx', () => {
it('should successfully execute the transaction', async () => {
const encoder = await contractWrappers.exchange.transactionEncoderAsync();
const data = encoder.cancelOrderTx(signedOrder);
const signerAddress = makerAddress;
await executeTransactionOrThrowAsync(encoder, data, signerAddress);
});
});
describe('#cancelOrdersUpToTx', () => {
it('should successfully execute the transaction', async () => {
const encoder = await contractWrappers.exchange.transactionEncoderAsync();
const targetEpoch = signedOrder.salt;
const data = encoder.cancelOrdersUpToTx(targetEpoch);
const signerAddress = makerAddress;
await executeTransactionOrThrowAsync(encoder, data, signerAddress);
});
});
});
});

View File

@ -1,6 +1,6 @@
{ {
"artifactsDir": "../migrations/artifacts/2.0.0", "artifactsDir": "../migrations/artifacts/2.0.0",
"contractsDir": "src/contracts", "contractsDir": "src/",
"compilerSettings": { "compilerSettings": {
"optimizer": { "optimizer": {
"enabled": true, "enabled": true,
@ -23,6 +23,7 @@
"DummyERC20Token", "DummyERC20Token",
"DummyERC721Receiver", "DummyERC721Receiver",
"DummyERC721Token", "DummyERC721Token",
"DummyNoReturnERC20Token",
"ERC20Proxy", "ERC20Proxy",
"ERC20Token", "ERC20Token",
"ERC721Token", "ERC721Token",
@ -32,11 +33,13 @@
"Forwarder", "Forwarder",
"IAssetData", "IAssetData",
"IAssetProxy", "IAssetProxy",
"InvalidERC721Receiver",
"IValidator", "IValidator",
"IWallet", "IWallet",
"MixinAuthorizable", "MixinAuthorizable",
"MultiSigWallet", "MultiSigWallet",
"MultiSigWalletWithTimeLock", "MultiSigWalletWithTimeLock",
"OrderValidator",
"TestAssetProxyOwner", "TestAssetProxyOwner",
"TestAssetProxyDispatcher", "TestAssetProxyDispatcher",
"TestConstants", "TestConstants",

View File

@ -20,11 +20,14 @@
"test:coverage": "SOLIDITY_COVERAGE=true run-s build run_mocha coverage:report:text coverage:report:lcov", "test:coverage": "SOLIDITY_COVERAGE=true run-s build run_mocha coverage:report:text coverage:report:lcov",
"test:profiler": "SOLIDITY_PROFILER=true run-s build run_mocha profiler:report:html", "test:profiler": "SOLIDITY_PROFILER=true run-s build run_mocha profiler:report:html",
"test:trace": "SOLIDITY_REVERT_TRACE=true run-s build run_mocha", "test:trace": "SOLIDITY_REVERT_TRACE=true run-s build run_mocha",
"run_mocha": "mocha --require source-map-support/register --require make-promises-safe 'lib/test/**/*.js' --timeout 100000 --bail --exit", "run_mocha":
"mocha --require source-map-support/register --require make-promises-safe 'lib/test/**/*.js' --timeout 100000 --bail --exit",
"compile": "sol-compiler --contracts-dir src", "compile": "sol-compiler --contracts-dir src",
"clean": "shx rm -rf lib generated_contract_wrappers", "clean": "shx rm -rf lib generated_contract_wrappers",
"generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output generated_contract_wrappers --backend ethers", "generate_contract_wrappers":
"lint": "tslint --project . --exclude **/src/generated_contract_wrappers/**/* --exclude **/lib/**/* && yarn lint-contracts", "abi-gen --abis ${npm_package_config_abis} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output generated_contract_wrappers --backend ethers",
"lint":
"tslint --project . --exclude **/src/generated_contract_wrappers/**/* --exclude **/lib/**/* && yarn lint-contracts",
"coverage:report:text": "istanbul report text", "coverage:report:text": "istanbul report text",
"coverage:report:html": "istanbul report html && open coverage/index.html", "coverage:report:html": "istanbul report html && open coverage/index.html",
"profiler:report:html": "istanbul report html && open coverage/index.html", "profiler:report:html": "istanbul report html && open coverage/index.html",
@ -33,7 +36,8 @@
"lint-contracts": "solhint src/2.0.0/**/**/**/**/*.sol" "lint-contracts": "solhint src/2.0.0/**/**/**/**/*.sol"
}, },
"config": { "config": {
"abis": "../migrations/artifacts/2.0.0/@(AssetProxyOwner|DummyERC20Token|DummyERC721Receiver|DummyERC721Token|ERC20Proxy|ERC721Proxy|Forwarder|Exchange|ExchangeWrapper|IAssetData|IAssetProxy|MixinAuthorizable|MultiSigWallet|MultiSigWalletWithTimeLock|TestAssetProxyOwner|TestAssetProxyDispatcher|TestConstants|TestExchangeInternals|TestLibBytes|TestLibs|TestSignatureValidator|Validator|Wallet|TokenRegistry|Whitelist|WETH9|ZRXToken).json" "abis":
"../migrations/artifacts/2.0.0/@(AssetProxyOwner|DummyERC20Token|DummyERC721Receiver|DummyERC721Token|DummyNoReturnERC20Token|ERC20Proxy|ERC721Proxy|Forwarder|Exchange|ExchangeWrapper|IAssetData|IAssetProxy|InvalidERC721Receiver|MixinAuthorizable|MultiSigWallet|MultiSigWalletWithTimeLock|OrderValidator|TestAssetProxyOwner|TestAssetProxyDispatcher|TestConstants|TestExchangeInternals|TestLibBytes|TestLibs|TestSignatureValidator|Validator|Wallet|TokenRegistry|Whitelist|WETH9|ZRXToken).json"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -37,16 +37,12 @@ contract Forwarder is
constructor ( constructor (
address _exchange, address _exchange,
address _etherToken,
address _zrxToken,
bytes memory _zrxAssetData, bytes memory _zrxAssetData,
bytes memory _wethAssetData bytes memory _wethAssetData
) )
public public
LibConstants( LibConstants(
_exchange, _exchange,
_etherToken,
_zrxToken,
_zrxAssetData, _zrxAssetData,
_wethAssetData _wethAssetData
) )

View File

@ -18,10 +18,10 @@
pragma solidity 0.4.24; pragma solidity 0.4.24;
import "../utils/LibBytes/LibBytes.sol"; import "../../utils/LibBytes/LibBytes.sol";
import "../utils/Ownable/Ownable.sol"; import "../../utils/Ownable/Ownable.sol";
import "../tokens/ERC20Token/IERC20Token.sol"; import "../../tokens/ERC20Token/IERC20Token.sol";
import "../tokens/ERC721Token/IERC721Token.sol"; import "../../tokens/ERC721Token/IERC721Token.sol";
import "./libs/LibConstants.sol"; import "./libs/LibConstants.sol";
import "./mixins/MAssets.sol"; import "./mixins/MAssets.sol";
@ -67,7 +67,7 @@ contract MixinAssets is
} else if (proxyId == ERC721_DATA_ID) { } else if (proxyId == ERC721_DATA_ID) {
transferERC721Token(assetData, amount); transferERC721Token(assetData, amount);
} else { } else {
revert("UNSUPPORTED_TOKEN_PROXY"); revert("UNSUPPORTED_ASSET_PROXY");
} }
} }

View File

@ -21,10 +21,10 @@ pragma experimental ABIEncoderV2;
import "./libs/LibConstants.sol"; import "./libs/LibConstants.sol";
import "./mixins/MExchangeWrapper.sol"; import "./mixins/MExchangeWrapper.sol";
import "../protocol/Exchange/libs/LibAbiEncoder.sol"; import "../../protocol/Exchange/libs/LibAbiEncoder.sol";
import "../protocol/Exchange/libs/LibOrder.sol"; import "../../protocol/Exchange/libs/LibOrder.sol";
import "../protocol/Exchange/libs/LibFillResults.sol"; import "../../protocol/Exchange/libs/LibFillResults.sol";
import "../protocol/Exchange/libs/LibMath.sol"; import "../../protocol/Exchange/libs/LibMath.sol";
contract MixinExchangeWrapper is contract MixinExchangeWrapper is

View File

@ -24,10 +24,10 @@ import "./mixins/MWeth.sol";
import "./mixins/MAssets.sol"; import "./mixins/MAssets.sol";
import "./mixins/MExchangeWrapper.sol"; import "./mixins/MExchangeWrapper.sol";
import "./interfaces/IForwarderCore.sol"; import "./interfaces/IForwarderCore.sol";
import "../utils/LibBytes/LibBytes.sol"; import "../../utils/LibBytes/LibBytes.sol";
import "../protocol/Exchange/libs/LibOrder.sol"; import "../../protocol/Exchange/libs/LibOrder.sol";
import "../protocol/Exchange/libs/LibFillResults.sol"; import "../../protocol/Exchange/libs/LibFillResults.sol";
import "../protocol/Exchange/libs/LibMath.sol"; import "../../protocol/Exchange/libs/LibMath.sol";
contract MixinForwarderCore is contract MixinForwarderCore is

View File

@ -18,7 +18,7 @@
pragma solidity 0.4.24; pragma solidity 0.4.24;
import "../protocol/Exchange/libs/LibMath.sol"; import "../../protocol/Exchange/libs/LibMath.sol";
import "./libs/LibConstants.sol"; import "./libs/LibConstants.sol";
import "./mixins/MWeth.sol"; import "./mixins/MWeth.sol";

View File

@ -19,8 +19,8 @@
pragma solidity 0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../../protocol/Exchange/libs/LibOrder.sol"; import "../../../protocol/Exchange/libs/LibOrder.sol";
import "../../protocol/Exchange/libs/LibFillResults.sol"; import "../../../protocol/Exchange/libs/LibFillResults.sol";
contract IForwarderCore { contract IForwarderCore {

View File

@ -18,13 +18,16 @@
pragma solidity 0.4.24; pragma solidity 0.4.24;
import "../../protocol/Exchange/interfaces/IExchange.sol"; import "../../../utils/LibBytes/LibBytes.sol";
import "../../tokens/EtherToken/IEtherToken.sol"; import "../../../protocol/Exchange/interfaces/IExchange.sol";
import "../../tokens/ERC20Token/IERC20Token.sol"; import "../../../tokens/EtherToken/IEtherToken.sol";
import "../../../tokens/ERC20Token/IERC20Token.sol";
contract LibConstants { contract LibConstants {
using LibBytes for bytes;
bytes4 constant internal ERC20_DATA_ID = bytes4(keccak256("ERC20Token(address)")); bytes4 constant internal ERC20_DATA_ID = bytes4(keccak256("ERC20Token(address)"));
bytes4 constant internal ERC721_DATA_ID = bytes4(keccak256("ERC721Token(address,uint256)")); bytes4 constant internal ERC721_DATA_ID = bytes4(keccak256("ERC721Token(address,uint256)"));
uint256 constant internal MAX_UINT = 2**256 - 1; uint256 constant internal MAX_UINT = 2**256 - 1;
@ -42,17 +45,18 @@ contract LibConstants {
constructor ( constructor (
address _exchange, address _exchange,
address _etherToken,
address _zrxToken,
bytes memory _zrxAssetData, bytes memory _zrxAssetData,
bytes memory _wethAssetData bytes memory _wethAssetData
) )
public public
{ {
EXCHANGE = IExchange(_exchange); EXCHANGE = IExchange(_exchange);
ETHER_TOKEN = IEtherToken(_etherToken);
ZRX_TOKEN = IERC20Token(_zrxToken);
ZRX_ASSET_DATA = _zrxAssetData; ZRX_ASSET_DATA = _zrxAssetData;
WETH_ASSET_DATA = _wethAssetData; WETH_ASSET_DATA = _wethAssetData;
address etherToken = _wethAssetData.readAddress(16);
address zrxToken = _zrxAssetData.readAddress(16);
ETHER_TOKEN = IEtherToken(etherToken);
ZRX_TOKEN = IERC20Token(zrxToken);
} }
} }

View File

@ -27,7 +27,7 @@ contract LibForwarderErrors {
string constant OVERSOLD_WETH = "OVERSOLD_WETH"; // More WETH sold than provided with current message call. string constant OVERSOLD_WETH = "OVERSOLD_WETH"; // More WETH sold than provided with current message call.
string constant COMPLETE_FILL_FAILED = "COMPLETE_FILL_FAILED"; // Desired purchase amount not completely filled (required for ZRX fees only). string constant COMPLETE_FILL_FAILED = "COMPLETE_FILL_FAILED"; // Desired purchase amount not completely filled (required for ZRX fees only).
string constant TRANSFER_FAILED = "TRANSFER_FAILED"; // Asset transfer failed. string constant TRANSFER_FAILED = "TRANSFER_FAILED"; // Asset transfer failed.
string constant UNSUPPORTED_TOKEN_PROXY = "UNSUPPORTED_TOKEN_PROXY"; // Proxy in assetData not supported. string constant UNSUPPORTED_ASSET_PROXY = "UNSUPPORTED_ASSET_PROXY"; // Proxy in assetData not supported.
string constant DEFAULT_FUNCTION_WETH_CONTRACT_ONLY = "DEFAULT_FUNCTION_WETH_CONTRACT_ONLY"; // Fallback function may only be used for WETH withdrawals. string constant DEFAULT_FUNCTION_WETH_CONTRACT_ONLY = "DEFAULT_FUNCTION_WETH_CONTRACT_ONLY"; // Fallback function may only be used for WETH withdrawals.
string constant INVALID_MSG_VALUE = "INVALID_MSG_VALUE"; // msg.value must be greater than 0. string constant INVALID_MSG_VALUE = "INVALID_MSG_VALUE"; // msg.value must be greater than 0.
string constant INVALID_AMOUNT = "INVALID_AMOUNT"; // Amount must equal 1. string constant INVALID_AMOUNT = "INVALID_AMOUNT"; // Amount must equal 1.

View File

@ -19,8 +19,8 @@
pragma solidity 0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../../protocol/Exchange/libs/LibOrder.sol"; import "../../../protocol/Exchange/libs/LibOrder.sol";
import "../../protocol/Exchange/libs/LibFillResults.sol"; import "../../../protocol/Exchange/libs/LibFillResults.sol";
contract MExchangeWrapper { contract MExchangeWrapper {

View File

@ -0,0 +1,218 @@
/*
Copyright 2018 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../../protocol/Exchange/interfaces/IExchange.sol";
import "../../protocol/Exchange/libs/LibOrder.sol";
import "../../tokens/ERC20Token/IERC20Token.sol";
import "../../tokens/ERC721Token/IERC721Token.sol";
import "../../utils/LibBytes/LibBytes.sol";
contract OrderValidator {
bytes4 constant internal ERC20_DATA_ID = bytes4(keccak256("ERC20Token(address)"));
bytes4 constant internal ERC721_DATA_ID = bytes4(keccak256("ERC721Token(address,uint256)"));
using LibBytes for bytes;
struct TraderInfo {
uint256 makerBalance; // Maker's balance of makerAsset
uint256 makerAllowance; // Maker's allowance to corresponding AssetProxy
uint256 takerBalance; // Taker's balance of takerAsset
uint256 takerAllowance; // Taker's allowance to corresponding AssetProxy
uint256 makerZrxBalance; // Maker's balance of ZRX
uint256 makerZrxAllowance; // Maker's allowance of ZRX to ERC20Proxy
uint256 takerZrxBalance; // Taker's balance of ZRX
uint256 takerZrxAllowance; // Taker's allowance of ZRX to ERC20Proxy
}
// solhint-disable var-name-mixedcase
IExchange internal EXCHANGE;
bytes internal ZRX_ASSET_DATA;
// solhint-enable var-name-mixedcase
constructor (address _exchange, bytes memory _zrxAssetData)
public
{
EXCHANGE = IExchange(_exchange);
ZRX_ASSET_DATA = _zrxAssetData;
}
/// @dev Fetches information for order and maker/taker of order.
/// @param order The order structure.
/// @param takerAddress Address that will be filling the order.
/// @return OrderInfo and TraderInfo instances for given order.
function getOrderAndTraderInfo(LibOrder.Order memory order, address takerAddress)
public
view
returns (LibOrder.OrderInfo memory orderInfo, TraderInfo memory traderInfo)
{
orderInfo = EXCHANGE.getOrderInfo(order);
traderInfo = getTraderInfo(order, takerAddress);
return (orderInfo, traderInfo);
}
/// @dev Fetches information for all passed in orders and the makers/takers of each order.
/// @param orders Array of order specifications.
/// @param takerAddresses Array of taker addresses corresponding to each order.
/// @return Arrays of OrderInfo and TraderInfo instances that correspond to each order.
function getOrdersAndTradersInfo(LibOrder.Order[] memory orders, address[] memory takerAddresses)
public
view
returns (LibOrder.OrderInfo[] memory ordersInfo, TraderInfo[] memory tradersInfo)
{
ordersInfo = EXCHANGE.getOrdersInfo(orders);
tradersInfo = getTradersInfo(orders, takerAddresses);
return (ordersInfo, tradersInfo);
}
/// @dev Fetches balance and allowances for maker and taker of order.
/// @param order The order structure.
/// @param takerAddress Address that will be filling the order.
/// @return Balances and allowances of maker and taker of order.
function getTraderInfo(LibOrder.Order memory order, address takerAddress)
public
view
returns (TraderInfo memory traderInfo)
{
(traderInfo.makerBalance, traderInfo.makerAllowance) = getBalanceAndAllowance(order.makerAddress, order.makerAssetData);
(traderInfo.takerBalance, traderInfo.takerAllowance) = getBalanceAndAllowance(takerAddress, order.takerAssetData);
bytes memory zrxAssetData = ZRX_ASSET_DATA;
(traderInfo.makerZrxBalance, traderInfo.makerZrxAllowance) = getBalanceAndAllowance(order.makerAddress, zrxAssetData);
(traderInfo.takerZrxBalance, traderInfo.takerZrxAllowance) = getBalanceAndAllowance(takerAddress, zrxAssetData);
return traderInfo;
}
/// @dev Fetches balances and allowances of maker and taker for each provided order.
/// @param orders Array of order specifications.
/// @param takerAddresses Array of taker addresses corresponding to each order.
/// @return Array of balances and allowances for maker and taker of each order.
function getTradersInfo(LibOrder.Order[] memory orders, address[] memory takerAddresses)
public
view
returns (TraderInfo[] memory)
{
uint256 ordersLength = orders.length;
TraderInfo[] memory tradersInfo = new TraderInfo[](ordersLength);
for (uint256 i = 0; i != ordersLength; i++) {
tradersInfo[i] = getTraderInfo(orders[i], takerAddresses[i]);
}
return tradersInfo;
}
/// @dev Fetches token balances and allowances of an address to given assetProxy. Supports ERC20 and ERC721.
/// @param target Address to fetch balances and allowances of.
/// @param assetData Encoded data that can be decoded by a specified proxy contract when transferring asset.
/// @return Balance of asset and allowance set to given proxy of asset.
/// For ERC721 tokens, these values will always be 1 or 0.
function getBalanceAndAllowance(address target, bytes memory assetData)
public
view
returns (uint256 balance, uint256 allowance)
{
bytes4 assetProxyId = assetData.readBytes4(0);
address token = assetData.readAddress(16);
address assetProxy = EXCHANGE.getAssetProxy(assetProxyId);
if (assetProxyId == ERC20_DATA_ID) {
// Query balance
balance = IERC20Token(token).balanceOf(target);
// Query allowance
allowance = IERC20Token(token).allowance(target, assetProxy);
} else if (assetProxyId == ERC721_DATA_ID) {
uint256 tokenId = assetData.readUint256(36);
// Query owner of tokenId
address owner = getERC721TokenOwner(token, tokenId);
// Set balance to 1 if tokenId is owned by target
balance = target == owner ? 1 : 0;
// Check if ERC721Proxy is approved to spend tokenId
bool isApproved = IERC721Token(token).isApprovedForAll(target, assetProxy) || IERC721Token(token).getApproved(tokenId) == assetProxy;
// Set alowance to 1 if ERC721Proxy is approved to spend tokenId
allowance = isApproved ? 1 : 0;
} else {
revert("UNSUPPORTED_ASSET_PROXY");
}
return (balance, allowance);
}
/// @dev Fetches token balances and allowances of an address for each given assetProxy. Supports ERC20 and ERC721.
/// @param target Address to fetch balances and allowances of.
/// @param assetData Array of encoded byte arrays that can be decoded by a specified proxy contract when transferring asset.
/// @return Balances and allowances of assets.
/// For ERC721 tokens, these values will always be 1 or 0.
function getBalancesAndAllowances(address target, bytes[] memory assetData)
public
view
returns (uint256[] memory, uint256[] memory)
{
uint256 length = assetData.length;
uint256[] memory balances = new uint256[](length);
uint256[] memory allowances = new uint256[](length);
for (uint256 i = 0; i != length; i++) {
(balances[i], allowances[i]) = getBalanceAndAllowance(target, assetData[i]);
}
return (balances, allowances);
}
/// @dev Calls `token.ownerOf(tokenId)`, but returns a null owner instead of reverting on an unowned token.
/// @param token Address of ERC721 token.
/// @param tokenId The identifier for the specific NFT.
/// @return Owner of tokenId or null address if unowned.
function getERC721TokenOwner(address token, uint256 tokenId)
public
view
returns (address owner)
{
assembly {
// load free memory pointer
let cdStart := mload(64)
// bytes4(keccak256(ownerOf(uint256))) = 0x6352211e
mstore(cdStart, 0x6352211e00000000000000000000000000000000000000000000000000000000)
mstore(add(cdStart, 4), tokenId)
// staticcall `ownerOf(tokenId)`
// `ownerOf` will revert if tokenId is not owned
let success := staticcall(
gas, // forward all gas
token, // call token contract
cdStart, // start of calldata
36, // length of input is 36 bytes
cdStart, // write output over input
32 // size of output is 32 bytes
)
// Success implies that tokenId is owned
// Copy owner from return data if successful
if success {
owner := mload(cdStart)
}
}
// Owner initialized to address(0), no need to modify if call is unsuccessful
return owner;
}
}

View File

@ -18,17 +18,18 @@
pragma solidity 0.4.24; pragma solidity 0.4.24;
import "../Mintable/Mintable.sol";
import "../../utils/Ownable/Ownable.sol"; import "../../utils/Ownable/Ownable.sol";
import "../../tokens/ERC20Token/MintableERC20Token.sol";
contract DummyERC20Token is contract DummyERC20Token is
Mintable, Ownable,
Ownable MintableERC20Token
{ {
string public name; string public name;
string public symbol; string public symbol;
uint256 public decimals; uint256 public decimals;
uint256 public constant MAX_MINT_AMOUNT = 10000000000000000000000;
constructor ( constructor (
string _name, string _name,
@ -41,20 +42,36 @@ contract DummyERC20Token is
name = _name; name = _name;
symbol = _symbol; symbol = _symbol;
decimals = _decimals; decimals = _decimals;
totalSupply = _totalSupply; _totalSupply = _totalSupply;
balances[msg.sender] = _totalSupply; balances[msg.sender] = _totalSupply;
} }
/// @dev Sets the balance of target address
/// @param _target Address or which balance will be updated
/// @param _value New balance of target address
function setBalance(address _target, uint256 _value) function setBalance(address _target, uint256 _value)
public external
onlyOwner onlyOwner
{ {
uint256 currBalance = balanceOf(_target); uint256 currBalance = balances[_target];
if (_value < currBalance) { if (_value < currBalance) {
totalSupply = safeSub(totalSupply, safeSub(currBalance, _value)); _totalSupply = safeSub(_totalSupply, safeSub(currBalance, _value));
} else { } else {
totalSupply = safeAdd(totalSupply, safeSub(_value, currBalance)); _totalSupply = safeAdd(_totalSupply, safeSub(_value, currBalance));
} }
balances[_target] = _value; balances[_target] = _value;
} }
/// @dev Mints new tokens for sender
/// @param _value Amount of tokens to mint
function mint(uint256 _value)
external
{
require(
_value <= MAX_MINT_AMOUNT,
"VALUE_TOO_LARGE"
);
_mint(msg.sender, _value);
}
} }

View File

@ -0,0 +1,116 @@
/*
Copyright 2018 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity 0.4.24;
import "./DummyERC20Token.sol";
// solhint-disable no-empty-blocks
contract DummyNoReturnERC20Token is
DummyERC20Token
{
constructor (
string _name,
string _symbol,
uint256 _decimals,
uint256 _totalSupply
)
public
DummyERC20Token(
_name,
_symbol,
_decimals,
_totalSupply
)
{}
/// @dev send `value` token to `to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
function transfer(address _to, uint256 _value)
external
returns (bool)
{
require(
balances[msg.sender] >= _value,
"ERC20_INSUFFICIENT_BALANCE"
);
require(
balances[_to] + _value >= balances[_to],
"UINT256_OVERFLOW"
);
balances[msg.sender] -= _value;
balances[_to] += _value;
emit Transfer(
msg.sender,
_to,
_value
);
// HACK: This contract will not compile if we remove `returns (bool)`, so we manually return no data
assembly {
return(0, 0)
}
}
/// @dev send `value` token to `to` from `from` on the condition it is approved by `from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
function transferFrom(
address _from,
address _to,
uint256 _value
)
external
returns (bool)
{
require(
balances[_from] >= _value,
"ERC20_INSUFFICIENT_BALANCE"
);
require(
allowed[_from][msg.sender] >= _value,
"ERC20_INSUFFICIENT_ALLOWANCE"
);
require(
balances[_to] + _value >= balances[_to],
"UINT256_OVERFLOW"
);
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;
emit Transfer(
_from,
_to,
_value
);
// HACK: This contract will not compile if we remove `returns (bool)`, so we manually return no data
assembly {
return(0, 0)
}
}
}

View File

@ -1,26 +1,19 @@
/* /*
The MIT License (MIT)
Copyright (c) 2016 Smart Contract Solutions, Inc. Copyright 2018 ZeroEx Intl.
Permission is hereby granted, free of charge, to any person obtaining Licensed under the Apache License, Version 2.0 (the "License");
a copy of this software and associated documentation files (the you may not use this file except in compliance with the License.
"Software"), to deal in the Software without restriction, including You may obtain a copy of the License at
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included http://www.apache.org/licenses/LICENSE-2.0
in all copies or substantial portions of the Software.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
pragma solidity 0.4.24; pragma solidity 0.4.24;
@ -32,33 +25,44 @@ contract DummyERC721Receiver is
IERC721Receiver IERC721Receiver
{ {
// Function selector for ERC721Receiver.onERC721Received
// 0x150b7a02
bytes4 constant internal ERC721_RECEIVED = bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
event TokenReceived( event TokenReceived(
address operator,
address from, address from,
uint256 tokenId, uint256 tokenId,
bytes data bytes data
); );
/** /// @notice Handle the receipt of an NFT
* @notice Handle the receipt of an NFT /// @dev The ERC721 smart contract calls this function on the recipient
* @dev The ERC721 smart contract calls this function on the recipient /// after a `transfer`. This function MAY throw to revert and reject the
* after a `safetransfer`. This function MAY throw to revert and reject the /// transfer. Return of other than the magic value MUST result in the
* transfer. This function MUST use 50,000 gas or less. Return of other /// transaction being reverted.
* than the magic value MUST result in the transaction being reverted. /// Note: the contract address is always the message sender.
* Note: the contract address is always the message sender. /// @param _operator The address which called `safeTransferFrom` function
* @param _from The sending address /// @param _from The address which previously owned the token
* @param _tokenId The NFT identifier which is being transfered /// @param _tokenId The NFT identifier which is being transferred
* @param _data Additional data with no specified format /// @param _data Additional data with no specified format
* @return `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))` /// @return `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
*/ /// unless throwing
function onERC721Received( function onERC721Received(
address _operator,
address _from, address _from,
uint256 _tokenId, uint256 _tokenId,
bytes _data bytes _data
) )
public external
returns (bytes4) returns (bytes4)
{ {
emit TokenReceived(_from, _tokenId, _data); emit TokenReceived(
_operator,
_from,
_tokenId,
_data
);
return ERC721_RECEIVED; return ERC721_RECEIVED;
} }
} }

View File

@ -0,0 +1,66 @@
/*
Copyright 2018 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity 0.4.24;
import "../../tokens/ERC721Token/IERC721Receiver.sol";
contract InvalidERC721Receiver is
IERC721Receiver
{
// Actual function signature is `onERC721Received(address,address,uint256,bytes)`
bytes4 constant internal INVALID_ERC721_RECEIVED = bytes4(keccak256("onERC721Received(address,uint256,bytes)"));
event TokenReceived(
address operator,
address from,
uint256 tokenId,
bytes data
);
/// @notice Handle the receipt of an NFT
/// @dev The ERC721 smart contract calls this function on the recipient
/// after a `transfer`. This function MAY throw to revert and reject the
/// transfer. Return of other than the magic value MUST result in the
/// transaction being reverted.
/// Note: the contract address is always the message sender.
/// @param _operator The address which called `safeTransferFrom` function
/// @param _from The address which previously owned the token
/// @param _tokenId The NFT identifier which is being transferred
/// @param _data Additional data with no specified format
/// @return `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
/// unless throwing
function onERC721Received(
address _operator,
address _from,
uint256 _tokenId,
bytes _data
)
external
returns (bytes4)
{
emit TokenReceived(
_operator,
_from,
_tokenId,
_data
);
return INVALID_ERC721_RECEIVED;
}
}

View File

@ -18,59 +18,46 @@
pragma solidity 0.4.24; pragma solidity 0.4.24;
import "../../tokens/ERC721Token/ERC721Token.sol"; import "../../tokens/ERC721Token/MintableERC721Token.sol";
import "../../utils/Ownable/Ownable.sol"; import "../../utils/Ownable/Ownable.sol";
// solhint-disable no-empty-blocks // solhint-disable no-empty-blocks
contract DummyERC721Token is contract DummyERC721Token is
Ownable, Ownable,
ERC721Token MintableERC721Token
{ {
string public name;
string public symbol;
/**
* @dev Constructor passes its arguments to the base ERC721Token constructor
* @param name of token
* @param symbol of token
*/
constructor ( constructor (
string name, string _name,
string symbol string _symbol
) )
public public
ERC721Token(name, symbol)
{}
/**
* @dev Function to mint a new token
* @dev Reverts if the given token ID already exists
* @param to address the beneficiary that will own the minted token
* @param tokenId uint256 ID of the token to be minted by the msg.sender
*/
function mint(address to, uint256 tokenId)
public
onlyOwner
{ {
require( name = _name;
!exists(tokenId), symbol = _symbol;
"Token with tokenId already exists."
);
_mint(to, tokenId);
} }
/** /// @dev Function to mint a new token
* @dev Function to burn a token /// Reverts if the given token ID already exists
* @dev Reverts if the given token ID doesn't exist /// @param _to Address of the beneficiary that will own the minted token
* @param tokenId uint256 ID of the token to be minted by the msg.sender /// @param _tokenId ID of the token to be minted by the msg.sender
*/ function mint(address _to, uint256 _tokenId)
function burn(address owner, uint256 tokenId) external
public {
_mint(_to, _tokenId);
}
/// @dev Function to burn a token
/// Reverts if the given token ID doesn't exist or not called by contract owner
/// @param _owner Owner of token with given token ID
/// @param _tokenId ID of the token to be burned by the msg.sender
function burn(address _owner, uint256 _tokenId)
external
onlyOwner onlyOwner
{ {
require( _burn(_owner, _tokenId);
exists(tokenId),
"Token with tokenId does not exist."
);
_burn(owner, tokenId);
} }
} }

View File

@ -1,43 +0,0 @@
/*
Copyright 2018 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity 0.4.24;
import "../../tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol";
import "../../utils/SafeMath/SafeMath.sol";
/*
* Mintable
* Base contract that creates a mintable UnlimitedAllowanceToken
*/
contract Mintable is
UnlimitedAllowanceToken,
SafeMath
{
function mint(uint256 _value)
public
{
require(
_value <= 100000000000000000000,
"Minting more than 100000000000000000000 is not allowed."
);
balances[msg.sender] = safeAdd(_value, balances[msg.sender]);
totalSupply = safeAdd(totalSupply, _value);
}
}

View File

@ -21,15 +21,21 @@ pragma solidity 0.4.24;
import "./IERC20Token.sol"; import "./IERC20Token.sol";
contract ERC20Token is IERC20Token { contract ERC20Token is
IERC20Token
{
mapping (address => uint256) internal balances; mapping (address => uint256) internal balances;
mapping (address => mapping (address => uint256)) internal allowed; mapping (address => mapping (address => uint256)) internal allowed;
uint256 public totalSupply; uint256 internal _totalSupply;
/// @dev send `value` token to `to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return True if transfer was successful
function transfer(address _to, uint256 _value) function transfer(address _to, uint256 _value)
public external
returns (bool) returns (bool)
{ {
require( require(
@ -38,16 +44,32 @@ contract ERC20Token is IERC20Token {
); );
require( require(
balances[_to] + _value >= balances[_to], balances[_to] + _value >= balances[_to],
"OVERFLOW" "UINT256_OVERFLOW"
); );
balances[msg.sender] -= _value; balances[msg.sender] -= _value;
balances[_to] += _value; balances[_to] += _value;
emit Transfer(msg.sender, _to, _value);
emit Transfer(
msg.sender,
_to,
_value
);
return true; return true;
} }
function transferFrom(address _from, address _to, uint256 _value) /// @dev send `value` token to `to` from `from` on the condition it is approved by `from`
public /// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return True if transfer was successful
function transferFrom(
address _from,
address _to,
uint256 _value
)
external
returns (bool) returns (bool)
{ {
require( require(
@ -60,34 +82,65 @@ contract ERC20Token is IERC20Token {
); );
require( require(
balances[_to] + _value >= balances[_to], balances[_to] + _value >= balances[_to],
"OVERFLOW" "UINT256_OVERFLOW"
); );
balances[_to] += _value; balances[_to] += _value;
balances[_from] -= _value; balances[_from] -= _value;
allowed[_from][msg.sender] -= _value; allowed[_from][msg.sender] -= _value;
emit Transfer(_from, _to, _value);
emit Transfer(
_from,
_to,
_value
);
return true; return true;
} }
/// @dev `msg.sender` approves `_spender` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Always true if the call has enough gas to complete execution
function approve(address _spender, uint256 _value) function approve(address _spender, uint256 _value)
public external
returns (bool) returns (bool)
{ {
allowed[msg.sender][_spender] = _value; allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value); emit Approval(
msg.sender,
_spender,
_value
);
return true; return true;
} }
/// @dev Query total supply of token
/// @return Total supply of token
function totalSupply()
external
view
returns (uint256)
{
return _totalSupply;
}
/// @dev Query the balance of owner
/// @param _owner The address from which the balance will be retrieved
/// @return Balance of owner
function balanceOf(address _owner) function balanceOf(address _owner)
public external
view view
returns (uint256) returns (uint256)
{ {
return balances[_owner]; return balances[_owner];
} }
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) function allowance(address _owner, address _spender)
public external
view view
returns (uint256) returns (uint256)
{ {

View File

@ -21,45 +21,7 @@ pragma solidity 0.4.24;
contract IERC20Token { contract IERC20Token {
/// @notice send `value` token to `to` from `msg.sender` // solhint-disable no-simple-event-func-name
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value)
public
returns (bool);
/// @notice send `value` token to `to` from `from` on the condition it is approved by `from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value)
public
returns (bool);
/// @notice `msg.sender` approves `_spender` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value)
public
returns (bool);
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner)
public view
returns (uint256);
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender)
public view
returns (uint256);
// solhint-disable-next-line no-simple-event-func-name
event Transfer( event Transfer(
address indexed _from, address indexed _from,
address indexed _to, address indexed _to,
@ -71,4 +33,55 @@ contract IERC20Token {
address indexed _spender, address indexed _spender,
uint256 _value uint256 _value
); );
/// @dev send `value` token to `to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return True if transfer was successful
function transfer(address _to, uint256 _value)
external
returns (bool);
/// @dev send `value` token to `to` from `from` on the condition it is approved by `from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return True if transfer was successful
function transferFrom(
address _from,
address _to,
uint256 _value
)
external
returns (bool);
/// @dev `msg.sender` approves `_spender` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Always true if the call has enough gas to complete execution
function approve(address _spender, uint256 _value)
external
returns (bool);
/// @dev Query total supply of token
/// @return Total supply of token
function totalSupply()
external
view
returns (uint256);
/// @param _owner The address from which the balance will be retrieved
/// @return Balance of owner
function balanceOf(address _owner)
external
view
returns (uint256);
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender)
external
view
returns (uint256);
} }

View File

@ -0,0 +1,61 @@
/*
Copyright 2018 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity 0.4.24;
import "../../utils/SafeMath/SafeMath.sol";
import "./UnlimitedAllowanceERC20Token.sol";
contract MintableERC20Token is
SafeMath,
UnlimitedAllowanceERC20Token
{
/// @dev Mints new tokens
/// @param _to Address of the beneficiary that will own the minted token
/// @param _value Amount of tokens to mint
function _mint(address _to, uint256 _value)
internal
{
balances[_to] = safeAdd(_value, balances[_to]);
_totalSupply = safeAdd(_totalSupply, _value);
emit Transfer(
address(0),
_to,
_value
);
}
/// @dev Mints new tokens
/// @param _owner Owner of tokens that will be burned
/// @param _value Amount of tokens to burn
function _burn(address _owner, uint256 _value)
internal
{
balances[_owner] = safeSub(balances[_owner], _value);
_totalSupply = safeSub(_totalSupply, _value);
emit Transfer(
_owner,
address(0),
_value
);
}
}

View File

@ -21,7 +21,9 @@ pragma solidity 0.4.24;
import "../ERC20Token/ERC20Token.sol"; import "../ERC20Token/ERC20Token.sol";
contract UnlimitedAllowanceToken is ERC20Token { contract UnlimitedAllowanceERC20Token is
ERC20Token
{
uint256 constant internal MAX_UINT = 2**256 - 1; uint256 constant internal MAX_UINT = 2**256 - 1;
@ -30,8 +32,12 @@ contract UnlimitedAllowanceToken is ERC20Token {
/// @param _to Address to transfer to. /// @param _to Address to transfer to.
/// @param _value Amount to transfer. /// @param _value Amount to transfer.
/// @return Success of transfer. /// @return Success of transfer.
function transferFrom(address _from, address _to, uint256 _value) function transferFrom(
public address _from,
address _to,
uint256 _value
)
external
returns (bool) returns (bool)
{ {
uint256 allowance = allowed[_from][msg.sender]; uint256 allowance = allowed[_from][msg.sender];
@ -45,14 +51,21 @@ contract UnlimitedAllowanceToken is ERC20Token {
); );
require( require(
balances[_to] + _value >= balances[_to], balances[_to] + _value >= balances[_to],
"OVERFLOW" "UINT256_OVERFLOW"
); );
balances[_to] += _value; balances[_to] += _value;
balances[_from] -= _value; balances[_from] -= _value;
if (allowance < MAX_UINT) { if (allowance < MAX_UINT) {
allowed[_from][msg.sender] -= _value; allowed[_from][msg.sender] -= _value;
} }
emit Transfer(_from, _to, _value);
emit Transfer(
_from,
_to,
_value
);
return true; return true;
} }
} }

View File

@ -1,26 +1,19 @@
/* /*
The MIT License (MIT)
Copyright (c) 2016 Smart Contract Solutions, Inc. Copyright 2018 ZeroEx Intl.
Permission is hereby granted, free of charge, to any person obtaining Licensed under the Apache License, Version 2.0 (the "License");
a copy of this software and associated documentation files (the you may not use this file except in compliance with the License.
"Software"), to deal in the Software without restriction, including You may obtain a copy of the License at
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included http://www.apache.org/licenses/LICENSE-2.0
in all copies or substantial portions of the Software.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
pragma solidity 0.4.24; pragma solidity 0.4.24;
@ -30,179 +23,250 @@ import "./IERC721Receiver.sol";
import "../../utils/SafeMath/SafeMath.sol"; import "../../utils/SafeMath/SafeMath.sol";
/**
* @title ERC721 Non-Fungible Token Standard basic implementation
* @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
* Modified from https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/token/ERC721/ERC721BasicToken.sol
*/
contract ERC721Token is contract ERC721Token is
IERC721Token, IERC721Token,
SafeMath SafeMath
{ {
// Equals to `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))` // Function selector for ERC721Receiver.onERC721Received
// which can be also obtained as `ERC721Receiver(0).onERC721Received.selector` // 0x150b7a02
bytes4 constant internal ERC721_RECEIVED = 0xf0b9e5ba; bytes4 constant internal ERC721_RECEIVED = bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
// Mapping from token ID to owner // Mapping of tokenId => owner
mapping (uint256 => address) internal tokenOwner; mapping (uint256 => address) internal owners;
// Mapping from token ID to approved address // Mapping of tokenId => approved address
mapping (uint256 => address) internal tokenApprovals; mapping (uint256 => address) internal approvals;
// Mapping from owner to number of owned token // Mapping of owner => number of tokens owned
mapping (address => uint256) internal ownedTokensCount; mapping (address => uint256) internal balances;
// Mapping from owner to operator approvals // Mapping of owner => operator => approved
mapping (address => mapping (address => bool)) internal operatorApprovals; mapping (address => mapping (address => bool)) internal operatorApprovals;
/** /// @notice Transfers the ownership of an NFT from one address to another address
* @dev Guarantees msg.sender is owner of the given token /// @dev Throws unless `msg.sender` is the current owner, an authorized
* @param _tokenId uint256 ID of the token to validate its ownership belongs to msg.sender /// operator, or the approved address for this NFT. Throws if `_from` is
*/ /// not the current owner. Throws if `_to` is the zero address. Throws if
modifier onlyOwnerOf(uint256 _tokenId) { /// `_tokenId` is not a valid NFT. When transfer is complete, this function
require(ownerOf(_tokenId) == msg.sender); /// checks if `_to` is a smart contract (code size > 0). If so, it calls
_; /// `onERC721Received` on `_to` and throws if the return value is not
} /// `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`.
/// @param _from The current owner of the NFT
/** /// @param _to The new owner
* @dev Checks msg.sender can transfer a token, by being owner, approved, or operator /// @param _tokenId The NFT to transfer
* @param _tokenId uint256 ID of the token to validate /// @param _data Additional data with no specified format, sent in call to `_to`
*/ function safeTransferFrom(
modifier canTransfer(uint256 _tokenId) { address _from,
require(isApprovedOrOwner(msg.sender, _tokenId)); address _to,
_; uint256 _tokenId,
} bytes _data
)
constructor ( external
string _name,
string _symbol)
public
{ {
name_ = _name; transferFrom(
symbol_ = _symbol; _from,
_to,
_tokenId
);
uint256 receiverCodeSize;
assembly {
receiverCodeSize := extcodesize(_to)
}
if (receiverCodeSize > 0) {
bytes4 selector = IERC721Receiver(_to).onERC721Received(
msg.sender,
_from,
_tokenId,
_data
);
require(
selector == ERC721_RECEIVED,
"ERC721_INVALID_SELECTOR"
);
}
} }
/** /// @notice Transfers the ownership of an NFT from one address to another address
* @dev Gets the token name /// @dev This works identically to the other function with an extra data parameter,
* @return string representing the token name /// except this function just sets data to "".
*/ /// @param _from The current owner of the NFT
function name() /// @param _to The new owner
public /// @param _tokenId The NFT to transfer
view function safeTransferFrom(
returns (string) address _from,
address _to,
uint256 _tokenId
)
external
{ {
return name_; transferFrom(
_from,
_to,
_tokenId
);
uint256 receiverCodeSize;
assembly {
receiverCodeSize := extcodesize(_to)
}
if (receiverCodeSize > 0) {
bytes4 selector = IERC721Receiver(_to).onERC721Received(
msg.sender,
_from,
_tokenId,
""
);
require(
selector == ERC721_RECEIVED,
"ERC721_INVALID_SELECTOR"
);
}
} }
/** /// @notice Change or reaffirm the approved address for an NFT
* @dev Gets the token symbol /// @dev The zero address indicates there is no approved address.
* @return string representing the token symbol /// Throws unless `msg.sender` is the current NFT owner, or an authorized
*/ /// operator of the current owner.
function symbol() /// @param _approved The new approved NFT controller
public /// @param _tokenId The NFT to approve
view function approve(address _approved, uint256 _tokenId)
returns (string) external
{ {
return symbol_; address owner = ownerOf(_tokenId);
require(
msg.sender == owner || isApprovedForAll(owner, msg.sender),
"ERC721_INVALID_SENDER"
);
approvals[_tokenId] = _approved;
emit Approval(
owner,
_approved,
_tokenId
);
} }
/** /// @notice Enable or disable approval for a third party ("operator") to manage
* @dev Gets the balance of the specified address /// all of `msg.sender`'s assets
* @param _owner address to query the balance of /// @dev Emits the ApprovalForAll event. The contract MUST allow
* @return uint256 representing the amount owned by the passed address /// multiple operators per owner.
*/ /// @param _operator Address to add to the set of authorized operators
/// @param _approved True if the operator is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved)
external
{
operatorApprovals[msg.sender][_operator] = _approved;
emit ApprovalForAll(
msg.sender,
_operator,
_approved
);
}
/// @notice Count all NFTs assigned to an owner
/// @dev NFTs assigned to the zero address are considered invalid, and this
/// function throws for queries about the zero address.
/// @param _owner An address for whom to query the balance
/// @return The number of NFTs owned by `_owner`, possibly zero
function balanceOf(address _owner) function balanceOf(address _owner)
public external
view view
returns (uint256) returns (uint256)
{ {
require(_owner != address(0)); require(
return ownedTokensCount[_owner]; _owner != address(0),
"ERC721_ZERO_OWNER"
);
return balances[_owner];
} }
/** /// @notice Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE
* @dev Gets the owner of the specified token ID /// TO CONFIRM THAT `_to` IS CAPABLE OF RECEIVING NFTS OR ELSE
* @param _tokenId uint256 ID of the token to query the owner of /// THEY MAY BE PERMANENTLY LOST
* @return owner address currently marked as the owner of the given token ID /// @dev Throws unless `msg.sender` is the current owner, an authorized
*/ /// operator, or the approved address for this NFT. Throws if `_from` is
/// not the current owner. Throws if `_to` is the zero address. Throws if
/// `_tokenId` is not a valid NFT.
/// @param _from The current owner of the NFT
/// @param _to The new owner
/// @param _tokenId The NFT to transfer
function transferFrom(
address _from,
address _to,
uint256 _tokenId
)
public
{
require(
_to != address(0),
"ERC721_ZERO_TO_ADDRESS"
);
address owner = ownerOf(_tokenId);
require(
_from == owner,
"ERC721_OWNER_MISMATCH"
);
address spender = msg.sender;
address approvedAddress = getApproved(_tokenId);
require(
spender == owner ||
isApprovedForAll(owner, spender) ||
approvedAddress == spender,
"ERC721_INVALID_SPENDER"
);
if (approvedAddress != address(0)) {
approvals[_tokenId] = address(0);
}
owners[_tokenId] = _to;
balances[_from] = safeSub(balances[_from], 1);
balances[_to] = safeAdd(balances[_to], 1);
emit Transfer(
_from,
_to,
_tokenId
);
}
/// @notice Find the owner of an NFT
/// @dev NFTs assigned to zero address are considered invalid, and queries
/// about them do throw.
/// @param _tokenId The identifier for an NFT
/// @return The address of the owner of the NFT
function ownerOf(uint256 _tokenId) function ownerOf(uint256 _tokenId)
public public
view view
returns (address) returns (address)
{ {
address owner = tokenOwner[_tokenId]; address owner = owners[_tokenId];
require(owner != address(0)); require(
owner != address(0),
"ERC721_ZERO_OWNER"
);
return owner; return owner;
} }
/** /// @notice Get the approved address for a single NFT
* @dev Returns whether the specified token exists /// @dev Throws if `_tokenId` is not a valid NFT.
* @param _tokenId uint256 ID of the token to query the existance of /// @param _tokenId The NFT to find the approved address for
* @return whether the token exists /// @return The approved address for this NFT, or the zero address if there is none
*/
function exists(uint256 _tokenId)
public
view
returns (bool)
{
address owner = tokenOwner[_tokenId];
return owner != address(0);
}
/**
* @dev Approves another address to transfer the given token ID
* @dev The zero address indicates there is no approved address.
* @dev There can only be one approved address per token at a given time.
* @dev Can only be called by the token owner or an approved operator.
* @param _to address to be approved for the given token ID
* @param _tokenId uint256 ID of the token to be approved
*/
function approve(address _to, uint256 _tokenId)
public
{
address owner = ownerOf(_tokenId);
require(_to != owner);
require(msg.sender == owner || isApprovedForAll(owner, msg.sender));
if (getApproved(_tokenId) != address(0) || _to != address(0)) {
tokenApprovals[_tokenId] = _to;
emit Approval(owner, _to, _tokenId);
}
}
/**
* @dev Gets the approved address for a token ID, or zero if no address set
* @param _tokenId uint256 ID of the token to query the approval of
* @return address currently approved for a the given token ID
*/
function getApproved(uint256 _tokenId) function getApproved(uint256 _tokenId)
public public
view view
returns (address) returns (address)
{ {
return tokenApprovals[_tokenId]; return approvals[_tokenId];
} }
/** /// @notice Query if an address is an authorized operator for another address
* @dev Sets or unsets the approval of a given operator /// @param _owner The address that owns the NFTs
* @dev An operator is allowed to transfer all tokens of the sender on their behalf /// @param _operator The address that acts on behalf of the owner
* @param _to operator address to set the approval /// @return True if `_operator` is an approved operator for `_owner`, false otherwise
* @param _approved representing the status of the approval to be set
*/
function setApprovalForAll(address _to, bool _approved)
public
{
require(_to != msg.sender);
operatorApprovals[msg.sender][_to] = _approved;
emit ApprovalForAll(msg.sender, _to, _approved);
}
/**
* @dev Tells whether an operator is approved by a given owner
* @param _owner owner address which you want to query the approval of
* @param _operator operator address which you want to query the approval of
* @return bool whether the given operator is approved by the given owner
*/
function isApprovedForAll(address _owner, address _operator) function isApprovedForAll(address _owner, address _operator)
public public
view view
@ -210,198 +274,4 @@ contract ERC721Token is
{ {
return operatorApprovals[_owner][_operator]; return operatorApprovals[_owner][_operator];
} }
/**
* @dev Transfers the ownership of a given token ID to another address
* @dev Usage of this method is discouraged, use `safeTransferFrom` whenever possible
* @dev Requires the msg sender to be the owner, approved, or operator
* @param _from current owner of the token
* @param _to address to receive the ownership of the given token ID
* @param _tokenId uint256 ID of the token to be transferred
*/
function transferFrom(address _from, address _to, uint256 _tokenId)
public
canTransfer(_tokenId)
{
require(_from != address(0));
require(_to != address(0));
clearApproval(_from, _tokenId);
removeTokenFrom(_from, _tokenId);
addTokenTo(_to, _tokenId);
emit Transfer(_from, _to, _tokenId);
}
/**
* @dev Safely transfers the ownership of a given token ID to another address
* @dev If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`; otherwise,
* the transfer is reverted.
* @dev Requires the msg sender to be the owner, approved, or operator
* @param _from current owner of the token
* @param _to address to receive the ownership of the given token ID
* @param _tokenId uint256 ID of the token to be transferred
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId)
public
canTransfer(_tokenId)
{
// solium-disable-next-line arg-overflow
safeTransferFrom(_from, _to, _tokenId, "");
}
/**
* @dev Safely transfers the ownership of a given token ID to another address
* @dev If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`; otherwise,
* the transfer is reverted.
* @dev Requires the msg sender to be the owner, approved, or operator
* @param _from current owner of the token
* @param _to address to receive the ownership of the given token ID
* @param _tokenId uint256 ID of the token to be transferred
* @param _data bytes data to send along with a safe transfer check
*/
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes _data)
public
canTransfer(_tokenId)
{
transferFrom(_from, _to, _tokenId);
// solium-disable-next-line arg-overflow
require(checkAndCallSafeTransfer(_from, _to, _tokenId, _data));
}
/**
* @dev Returns whether the given spender can transfer a given token ID
* @param _spender address of the spender to query
* @param _tokenId uint256 ID of the token to be transferred
* @return bool whether the msg.sender is approved for the given token ID,
* is an operator of the owner, or is the owner of the token
*/
function isApprovedOrOwner(address _spender, uint256 _tokenId)
internal
view
returns (bool)
{
address owner = ownerOf(_tokenId);
return _spender == owner || getApproved(_tokenId) == _spender || isApprovedForAll(owner, _spender);
}
/**
* @dev Internal function to mint a new token
* @dev Reverts if the given token ID already exists
* @param _to The address that will own the minted token
* @param _tokenId uint256 ID of the token to be minted by the msg.sender
*/
function _mint(address _to, uint256 _tokenId)
internal
{
require(_to != address(0));
addTokenTo(_to, _tokenId);
emit Transfer(address(0), _to, _tokenId);
}
/**
* @dev Internal function to burn a specific token
* @dev Reverts if the token does not exist
* @param _tokenId uint256 ID of the token being burned by the msg.sender
*/
function _burn(address _owner, uint256 _tokenId)
internal
{
clearApproval(_owner, _tokenId);
removeTokenFrom(_owner, _tokenId);
emit Transfer(_owner, address(0), _tokenId);
}
/**
* @dev Internal function to clear current approval of a given token ID
* @dev Reverts if the given address is not indeed the owner of the token
* @param _owner owner of the token
* @param _tokenId uint256 ID of the token to be transferred
*/
function clearApproval(address _owner, uint256 _tokenId)
internal
{
require(ownerOf(_tokenId) == _owner);
if (tokenApprovals[_tokenId] != address(0)) {
tokenApprovals[_tokenId] = address(0);
emit Approval(_owner, address(0), _tokenId);
}
}
/**
* @dev Internal function to add a token ID to the list of a given address
* @param _to address representing the new owner of the given token ID
* @param _tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function addTokenTo(address _to, uint256 _tokenId)
internal
{
require(tokenOwner[_tokenId] == address(0));
tokenOwner[_tokenId] = _to;
ownedTokensCount[_to] = safeAdd(ownedTokensCount[_to], 1);
}
/**
* @dev Internal function to remove a token ID from the list of a given address
* @param _from address representing the previous owner of the given token ID
* @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function removeTokenFrom(address _from, uint256 _tokenId)
internal
{
require(ownerOf(_tokenId) == _from);
ownedTokensCount[_from] = safeSub(ownedTokensCount[_from], 1);
tokenOwner[_tokenId] = address(0);
}
/**
* @dev Internal function to invoke `onERC721Received` on a target address
* @dev The call is not executed if the target address is not a contract
* @param _from address representing the previous owner of the given token ID
* @param _to target address that will receive the tokens
* @param _tokenId uint256 ID of the token to be transferred
* @param _data bytes optional data to send along with the call
* @return whether the call correctly returned the expected magic value
*/
function checkAndCallSafeTransfer(
address _from,
address _to,
uint256 _tokenId,
bytes _data)
internal
returns (bool)
{
if (!isContract(_to)) {
return true;
}
bytes4 retval = IERC721Receiver(_to).onERC721Received(_from, _tokenId, _data);
return (retval == ERC721_RECEIVED);
}
function isContract(address addr)
internal
view
returns (bool)
{
uint256 size;
// XXX Currently there is no better way to check if there is a contract in an address
// than to check the size of the code at that address.
// See https://ethereum.stackexchange.com/a/14016/36603
// for more details about how this works.
// TODO Check this again before the Serenity release, because all addresses will be
// contracts then.
assembly { size := extcodesize(addr) } // solium-disable-line security/no-inline-assembly
return size > 0;
}
} }

View File

@ -1,61 +1,44 @@
/* /*
The MIT License (MIT)
Copyright (c) 2016 Smart Contract Solutions, Inc. Copyright 2018 ZeroEx Intl.
Permission is hereby granted, free of charge, to any person obtaining Licensed under the Apache License, Version 2.0 (the "License");
a copy of this software and associated documentation files (the you may not use this file except in compliance with the License.
"Software"), to deal in the Software without restriction, including You may obtain a copy of the License at
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included http://www.apache.org/licenses/LICENSE-2.0
in all copies or substantial portions of the Software.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
pragma solidity 0.4.24; pragma solidity 0.4.24;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* rom ERC721 asset contracts.
* Modified from https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/token/ERC721/ERC721Receiver.sol
*/
contract IERC721Receiver { contract IERC721Receiver {
/**
* @dev Magic value to be returned upon successful reception of an NFT
* Equals to `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`,
* which can be also obtained as `ERC721Receiver(0).onERC721Received.selector`
*/
bytes4 constant internal ERC721_RECEIVED = 0xf0b9e5ba;
/** /// @notice Handle the receipt of an NFT
* @notice Handle the receipt of an NFT /// @dev The ERC721 smart contract calls this function on the recipient
* @dev The ERC721 smart contract calls this function on the recipient /// after a `transfer`. This function MAY throw to revert and reject the
* after a `safetransfer`. This function MAY throw to revert and reject the /// transfer. Return of other than the magic value MUST result in the
* transfer. This function MUST use 50,000 gas or less. Return of other /// transaction being reverted.
* than the magic value MUST result in the transaction being reverted. /// Note: the contract address is always the message sender.
* Note: the contract address is always the message sender. /// @param _operator The address which called `safeTransferFrom` function
* @param _from The sending address /// @param _from The address which previously owned the token
* @param _tokenId The NFT identifier which is being transfered /// @param _tokenId The NFT identifier which is being transferred
* @param _data Additional data with no specified format /// @param _data Additional data with no specified format
* @return `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))` /// @return `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
*/ /// unless throwing
function onERC721Received( function onERC721Received(
address _operator,
address _from, address _from,
uint256 _tokenId, uint256 _tokenId,
bytes _data) bytes _data
public )
external
returns (bytes4); returns (bytes4);
} }

View File

@ -1,99 +1,126 @@
/* /*
The MIT License (MIT)
Copyright (c) 2016 Smart Contract Solutions, Inc. Copyright 2018 ZeroEx Intl.
Permission is hereby granted, free of charge, to any person obtaining Licensed under the Apache License, Version 2.0 (the "License");
a copy of this software and associated documentation files (the you may not use this file except in compliance with the License.
"Software"), to deal in the Software without restriction, including You may obtain a copy of the License at
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included http://www.apache.org/licenses/LICENSE-2.0
in all copies or substantial portions of the Software.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
pragma solidity 0.4.24; pragma solidity 0.4.24;
/**
* @title ERC721 Non-Fungible Token Standard basic interface
* @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
* Modified from https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/token/ERC721/ERC721Basic.sol
*/
contract IERC721Token { contract IERC721Token {
string internal name_;
string internal symbol_;
/// @dev This emits when ownership of any NFT changes by any mechanism.
/// This event emits when NFTs are created (`from` == 0) and destroyed
/// (`to` == 0). Exception: during contract creation, any number of NFTs
/// may be created and assigned without emitting Transfer. At the time of
/// any transfer, the approved address for that NFT (if any) is reset to none.
event Transfer( event Transfer(
address indexed _from, address indexed _from,
address indexed _to, address indexed _to,
uint256 _tokenId uint256 indexed _tokenId
); );
/// @dev This emits when the approved address for an NFT is changed or
/// reaffirmed. The zero address indicates there is no approved address.
/// When a Transfer event emits, this also indicates that the approved
/// address for that NFT (if any) is reset to none.
event Approval( event Approval(
address indexed _owner, address indexed _owner,
address indexed _approved, address indexed _approved,
uint256 _tokenId uint256 indexed _tokenId
); );
/// @dev This emits when an operator is enabled or disabled for an owner.
/// The operator can manage all NFTs of the owner.
event ApprovalForAll( event ApprovalForAll(
address indexed _owner, address indexed _owner,
address indexed _operator, address indexed _operator,
bool _approved bool _approved
); );
function name() /// @notice Transfers the ownership of an NFT from one address to another address
public /// @dev Throws unless `msg.sender` is the current owner, an authorized
view /// perator, or the approved address for this NFT. Throws if `_from` is
returns (string); /// not the current owner. Throws if `_to` is the zero address. Throws if
/// `_tokenId` is not a valid NFT. When transfer is complete, this function
/// checks if `_to` is a smart contract (code size > 0). If so, it calls
/// `onERC721Received` on `_to` and throws if the return value is not
/// `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`.
/// @param _from The current owner of the NFT
/// @param _to The new owner
/// @param _tokenId The NFT to transfer
/// @param _data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes _data
)
external;
function symbol() /// @notice Transfers the ownership of an NFT from one address to another address
public /// @dev This works identically to the other function with an extra data parameter,
view /// except this function just sets data to "".
returns (string); /// @param _from The current owner of the NFT
/// @param _to The new owner
/// @param _tokenId The NFT to transfer
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
)
external;
function balanceOf(address _owner) /// @notice Change or reaffirm the approved address for an NFT
public /// @dev The zero address indicates there is no approved address.
view /// Throws unless `msg.sender` is the current NFT owner, or an authorized
returns (uint256 _balance); /// operator of the current owner.
/// @param _approved The new approved NFT controller
function ownerOf(uint256 _tokenId) /// @param _tokenId The NFT to approve
public function approve(address _approved, uint256 _tokenId)
view external;
returns (address _owner);
function exists(uint256 _tokenId)
public
view
returns (bool _exists);
function approve(address _to, uint256 _tokenId)
public;
function getApproved(uint256 _tokenId)
public
view
returns (address _operator);
/// @notice Enable or disable approval for a third party ("operator") to manage
/// all of `msg.sender`'s assets
/// @dev Emits the ApprovalForAll event. The contract MUST allow
/// multiple operators per owner.
/// @param _operator Address to add to the set of authorized operators
/// @param _approved True if the operator is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved) function setApprovalForAll(address _operator, bool _approved)
public; external;
function isApprovedForAll(address _owner, address _operator) /// @notice Count all NFTs assigned to an owner
public /// @dev NFTs assigned to the zero address are considered invalid, and this
/// function throws for queries about the zero address.
/// @param _owner An address for whom to query the balance
/// @return The number of NFTs owned by `_owner`, possibly zero
function balanceOf(address _owner)
external
view view
returns (bool); returns (uint256);
/// @notice Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE
/// TO CONFIRM THAT `_to` IS CAPABLE OF RECEIVING NFTS OR ELSE
/// THEY MAY BE PERMANENTLY LOST
/// @dev Throws unless `msg.sender` is the current owner, an authorized
/// operator, or the approved address for this NFT. Throws if `_from` is
/// not the current owner. Throws if `_to` is the zero address. Throws if
/// `_tokenId` is not a valid NFT.
/// @param _from The current owner of the NFT
/// @param _to The new owner
/// @param _tokenId The NFT to transfer
function transferFrom( function transferFrom(
address _from, address _from,
address _to, address _to,
@ -101,18 +128,31 @@ contract IERC721Token {
) )
public; public;
function safeTransferFrom( /// @notice Find the owner of an NFT
address _from, /// @dev NFTs assigned to zero address are considered invalid, and queries
address _to, /// about them do throw.
uint256 _tokenId /// @param _tokenId The identifier for an NFT
) /// @return The address of the owner of the NFT
public; function ownerOf(uint256 _tokenId)
public
view
returns (address);
function safeTransferFrom( /// @notice Get the approved address for a single NFT
address _from, /// @dev Throws if `_tokenId` is not a valid NFT.
address _to, /// @param _tokenId The NFT to find the approved address for
uint256 _tokenId, /// @return The approved address for this NFT, or the zero address if there is none
bytes _data function getApproved(uint256 _tokenId)
) public
public; view
returns (address);
/// @notice Query if an address is an authorized operator for another address
/// @param _owner The address that owns the NFTs
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator)
public
view
returns (bool);
} }

View File

@ -0,0 +1,83 @@
/*
Copyright 2018 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity 0.4.24;
import "./ERC721Token.sol";
contract MintableERC721Token is
ERC721Token
{
/// @dev Function to mint a new token
/// Reverts if the given token ID already exists
/// @param _to Address of the beneficiary that will own the minted token
/// @param _tokenId ID of the token to be minted by the msg.sender
function _mint(address _to, uint256 _tokenId)
internal
{
require(
_to != address(0),
"ERC721_ZERO_TO_ADDRESS"
);
address owner = owners[_tokenId];
require(
owner == address(0),
"ERC721_OWNER_ALREADY_EXISTS"
);
owners[_tokenId] = _to;
balances[_to] = safeAdd(balances[_to], 1);
emit Transfer(
address(0),
_to,
_tokenId
);
}
/// @dev Function to burn a token
/// Reverts if the given token ID doesn't exist
/// @param _owner Owner of token with given token ID
/// @param _tokenId ID of the token to be burned by the msg.sender
function _burn(address _owner, uint256 _tokenId)
internal
{
require(
_owner != address(0),
"ERC721_ZERO_OWNER_ADDRESS"
);
address owner = owners[_tokenId];
require(
owner == _owner,
"ERC721_OWNER_MISMATCH"
);
owners[_tokenId] = address(0);
balances[_owner] = safeSub(balances[_owner], 1);
emit Transfer(
_owner,
address(0),
_tokenId
);
}
}

View File

@ -261,7 +261,7 @@ describe('Asset Transfer Proxies', () => {
erc721Receiver.address, erc721Receiver.address,
amount, amount,
); );
const logDecoder = new LogDecoder(web3Wrapper, erc721Receiver.address); const logDecoder = new LogDecoder(web3Wrapper);
const tx = await logDecoder.getTxWithDecodedLogsAsync( const tx = await logDecoder.getTxWithDecodedLogsAsync(
await web3Wrapper.sendTransactionAsync({ await web3Wrapper.sendTransactionAsync({
to: erc721Proxy.address, to: erc721Proxy.address,
@ -271,7 +271,7 @@ describe('Asset Transfer Proxies', () => {
}), }),
); );
// Verify that no log was emitted by erc721 receiver // Verify that no log was emitted by erc721 receiver
expect(tx.logs.length).to.be.equal(0); expect(tx.logs.length).to.be.equal(1);
// Verify transfer was successful // Verify transfer was successful
const newOwnerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId); const newOwnerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId);
expect(newOwnerMakerAsset).to.be.bignumber.equal(erc721Receiver.address); expect(newOwnerMakerAsset).to.be.bignumber.equal(erc721Receiver.address);

View File

@ -10,6 +10,7 @@ import * as _ from 'lodash';
import { DummyERC20TokenContract } from '../../generated_contract_wrappers/dummy_erc20_token'; import { DummyERC20TokenContract } from '../../generated_contract_wrappers/dummy_erc20_token';
import { DummyERC721TokenContract } from '../../generated_contract_wrappers/dummy_erc721_token'; import { DummyERC721TokenContract } from '../../generated_contract_wrappers/dummy_erc721_token';
import { DummyNoReturnERC20TokenContract } from '../../generated_contract_wrappers/dummy_no_return_erc20_token';
import { ERC20ProxyContract } from '../../generated_contract_wrappers/erc20_proxy'; import { ERC20ProxyContract } from '../../generated_contract_wrappers/erc20_proxy';
import { ERC721ProxyContract } from '../../generated_contract_wrappers/erc721_proxy'; import { ERC721ProxyContract } from '../../generated_contract_wrappers/erc721_proxy';
import { ExchangeCancelEventArgs, ExchangeContract } from '../../generated_contract_wrappers/exchange'; import { ExchangeCancelEventArgs, ExchangeContract } from '../../generated_contract_wrappers/exchange';
@ -39,6 +40,7 @@ describe('Exchange core', () => {
let erc20TokenB: DummyERC20TokenContract; let erc20TokenB: DummyERC20TokenContract;
let zrxToken: DummyERC20TokenContract; let zrxToken: DummyERC20TokenContract;
let erc721Token: DummyERC721TokenContract; let erc721Token: DummyERC721TokenContract;
let noReturnErc20Token: DummyNoReturnERC20TokenContract;
let exchange: ExchangeContract; let exchange: ExchangeContract;
let erc20Proxy: ERC20ProxyContract; let erc20Proxy: ERC20ProxyContract;
let erc721Proxy: ERC721ProxyContract; let erc721Proxy: ERC721ProxyContract;
@ -161,6 +163,137 @@ describe('Exchange core', () => {
}); });
}); });
describe('Testing exchange of ERC20 tokens with no return values', () => {
before(async () => {
noReturnErc20Token = await DummyNoReturnERC20TokenContract.deployFrom0xArtifactAsync(
artifacts.DummyNoReturnERC20Token,
provider,
txDefaults,
constants.DUMMY_TOKEN_NAME,
constants.DUMMY_TOKEN_SYMBOL,
constants.DUMMY_TOKEN_DECIMALS,
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await noReturnErc20Token.setBalance.sendTransactionAsync(makerAddress, constants.INITIAL_ERC20_BALANCE),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await noReturnErc20Token.approve.sendTransactionAsync(
erc20Proxy.address,
constants.INITIAL_ERC20_ALLOWANCE,
{ from: makerAddress },
),
constants.AWAIT_TRANSACTION_MINED_MS,
);
});
it('should transfer the correct amounts when makerAssetAmount === takerAssetAmount', async () => {
signedOrder = await orderFactory.newSignedOrderAsync({
makerAssetData: assetDataUtils.encodeERC20AssetData(noReturnErc20Token.address),
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
});
const initialMakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(makerAddress);
const initialMakerBalanceB = await erc20TokenB.balanceOf.callAsync(makerAddress);
const initialMakerZrxBalance = await zrxToken.balanceOf.callAsync(makerAddress);
const initialTakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(takerAddress);
const initialTakerBalanceB = await erc20TokenB.balanceOf.callAsync(takerAddress);
const initialTakerZrxBalance = await zrxToken.balanceOf.callAsync(takerAddress);
const initialFeeRecipientZrxBalance = await zrxToken.balanceOf.callAsync(feeRecipientAddress);
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress);
const finalMakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(makerAddress);
const finalMakerBalanceB = await erc20TokenB.balanceOf.callAsync(makerAddress);
const finalMakerZrxBalance = await zrxToken.balanceOf.callAsync(makerAddress);
const finalTakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(takerAddress);
const finalTakerBalanceB = await erc20TokenB.balanceOf.callAsync(takerAddress);
const finalTakerZrxBalance = await zrxToken.balanceOf.callAsync(takerAddress);
const finalFeeRecipientZrxBalance = await zrxToken.balanceOf.callAsync(feeRecipientAddress);
expect(finalMakerBalanceA).to.be.bignumber.equal(initialMakerBalanceA.minus(signedOrder.makerAssetAmount));
expect(finalMakerBalanceB).to.be.bignumber.equal(initialMakerBalanceB.plus(signedOrder.takerAssetAmount));
expect(finalTakerBalanceA).to.be.bignumber.equal(initialTakerBalanceA.plus(signedOrder.makerAssetAmount));
expect(finalTakerBalanceB).to.be.bignumber.equal(initialTakerBalanceB.minus(signedOrder.takerAssetAmount));
expect(finalMakerZrxBalance).to.be.bignumber.equal(initialMakerZrxBalance.minus(signedOrder.makerFee));
expect(finalTakerZrxBalance).to.be.bignumber.equal(initialTakerZrxBalance.minus(signedOrder.takerFee));
expect(finalFeeRecipientZrxBalance).to.be.bignumber.equal(
initialFeeRecipientZrxBalance.plus(signedOrder.makerFee.plus(signedOrder.takerFee)),
);
});
it('should transfer the correct amounts when makerAssetAmount > takerAssetAmount', async () => {
signedOrder = await orderFactory.newSignedOrderAsync({
makerAssetData: assetDataUtils.encodeERC20AssetData(noReturnErc20Token.address),
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
});
const initialMakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(makerAddress);
const initialMakerBalanceB = await erc20TokenB.balanceOf.callAsync(makerAddress);
const initialMakerZrxBalance = await zrxToken.balanceOf.callAsync(makerAddress);
const initialTakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(takerAddress);
const initialTakerBalanceB = await erc20TokenB.balanceOf.callAsync(takerAddress);
const initialTakerZrxBalance = await zrxToken.balanceOf.callAsync(takerAddress);
const initialFeeRecipientZrxBalance = await zrxToken.balanceOf.callAsync(feeRecipientAddress);
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress);
const finalMakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(makerAddress);
const finalMakerBalanceB = await erc20TokenB.balanceOf.callAsync(makerAddress);
const finalMakerZrxBalance = await zrxToken.balanceOf.callAsync(makerAddress);
const finalTakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(takerAddress);
const finalTakerBalanceB = await erc20TokenB.balanceOf.callAsync(takerAddress);
const finalTakerZrxBalance = await zrxToken.balanceOf.callAsync(takerAddress);
const finalFeeRecipientZrxBalance = await zrxToken.balanceOf.callAsync(feeRecipientAddress);
expect(finalMakerBalanceA).to.be.bignumber.equal(initialMakerBalanceA.minus(signedOrder.makerAssetAmount));
expect(finalMakerBalanceB).to.be.bignumber.equal(initialMakerBalanceB.plus(signedOrder.takerAssetAmount));
expect(finalTakerBalanceA).to.be.bignumber.equal(initialTakerBalanceA.plus(signedOrder.makerAssetAmount));
expect(finalTakerBalanceB).to.be.bignumber.equal(initialTakerBalanceB.minus(signedOrder.takerAssetAmount));
expect(finalMakerZrxBalance).to.be.bignumber.equal(initialMakerZrxBalance.minus(signedOrder.makerFee));
expect(finalTakerZrxBalance).to.be.bignumber.equal(initialTakerZrxBalance.minus(signedOrder.takerFee));
expect(finalFeeRecipientZrxBalance).to.be.bignumber.equal(
initialFeeRecipientZrxBalance.plus(signedOrder.makerFee.plus(signedOrder.takerFee)),
);
});
it('should transfer the correct amounts when makerAssetAmount < takerAssetAmount', async () => {
signedOrder = await orderFactory.newSignedOrderAsync({
makerAssetData: assetDataUtils.encodeERC20AssetData(noReturnErc20Token.address),
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18),
});
const initialMakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(makerAddress);
const initialMakerBalanceB = await erc20TokenB.balanceOf.callAsync(makerAddress);
const initialMakerZrxBalance = await zrxToken.balanceOf.callAsync(makerAddress);
const initialTakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(takerAddress);
const initialTakerBalanceB = await erc20TokenB.balanceOf.callAsync(takerAddress);
const initialTakerZrxBalance = await zrxToken.balanceOf.callAsync(takerAddress);
const initialFeeRecipientZrxBalance = await zrxToken.balanceOf.callAsync(feeRecipientAddress);
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress);
const finalMakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(makerAddress);
const finalMakerBalanceB = await erc20TokenB.balanceOf.callAsync(makerAddress);
const finalMakerZrxBalance = await zrxToken.balanceOf.callAsync(makerAddress);
const finalTakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(takerAddress);
const finalTakerBalanceB = await erc20TokenB.balanceOf.callAsync(takerAddress);
const finalTakerZrxBalance = await zrxToken.balanceOf.callAsync(takerAddress);
const finalFeeRecipientZrxBalance = await zrxToken.balanceOf.callAsync(feeRecipientAddress);
expect(finalMakerBalanceA).to.be.bignumber.equal(initialMakerBalanceA.minus(signedOrder.makerAssetAmount));
expect(finalMakerBalanceB).to.be.bignumber.equal(initialMakerBalanceB.plus(signedOrder.takerAssetAmount));
expect(finalTakerBalanceA).to.be.bignumber.equal(initialTakerBalanceA.plus(signedOrder.makerAssetAmount));
expect(finalTakerBalanceB).to.be.bignumber.equal(initialTakerBalanceB.minus(signedOrder.takerAssetAmount));
expect(finalMakerZrxBalance).to.be.bignumber.equal(initialMakerZrxBalance.minus(signedOrder.makerFee));
expect(finalTakerZrxBalance).to.be.bignumber.equal(initialTakerZrxBalance.minus(signedOrder.takerFee));
expect(finalFeeRecipientZrxBalance).to.be.bignumber.equal(
initialFeeRecipientZrxBalance.plus(signedOrder.makerFee.plus(signedOrder.takerFee)),
);
});
});
describe('cancelOrder', () => { describe('cancelOrder', () => {
beforeEach(async () => { beforeEach(async () => {
erc20Balances = await erc20Wrapper.getBalancesAsync(); erc20Balances = await erc20Wrapper.getBalancesAsync();

View File

@ -145,7 +145,7 @@ describe('AssetProxyDispatcher', () => {
}); });
it('should log an event with correct arguments when an asset proxy is registered', async () => { it('should log an event with correct arguments when an asset proxy is registered', async () => {
const logDecoder = new LogDecoder(web3Wrapper, assetProxyDispatcher.address); const logDecoder = new LogDecoder(web3Wrapper);
const txReceipt = await logDecoder.getTxWithDecodedLogsAsync( const txReceipt = await logDecoder.getTxWithDecodedLogsAsync(
await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync(erc20Proxy.address, { from: owner }), await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync(erc20Proxy.address, { from: owner }),
); );

View File

@ -231,7 +231,7 @@ describe('FillOrder Tests', () => {
}); });
}); });
describe('Testing Exchange of ERC721 Tokens', () => { describe('Testing exchange of ERC721 Tokens', () => {
it('should successfully exchange a single token between the maker and taker (via fillOrder)', async () => { it('should successfully exchange a single token between the maker and taker (via fillOrder)', async () => {
const fillScenario = { const fillScenario = {
...defaultFillScenario, ...defaultFillScenario,

View File

@ -65,7 +65,7 @@ describe('MixinSignatureValidator', () => {
txDefaults, txDefaults,
signerAddress, signerAddress,
); );
signatureValidatorLogDecoder = new LogDecoder(web3Wrapper, signatureValidator.address); signatureValidatorLogDecoder = new LogDecoder(web3Wrapper);
await web3Wrapper.awaitTransactionSuccessAsync( await web3Wrapper.awaitTransactionSuccessAsync(
await signatureValidator.setSignatureValidatorApproval.sendTransactionAsync(testValidator.address, true, { await signatureValidator.setSignatureValidatorApproval.sendTransactionAsync(testValidator.address, true, {
from: signerAddress, from: signerAddress,

View File

@ -131,8 +131,6 @@ describe(ContractName.Forwarder, () => {
provider, provider,
txDefaults, txDefaults,
exchangeInstance.address, exchangeInstance.address,
wethContract.address,
zrxToken.address,
zrxAssetData, zrxAssetData,
wethAssetData, wethAssetData,
); );

View File

@ -0,0 +1,600 @@
import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { assetDataUtils, orderHashUtils } from '@0xproject/order-utils';
import { SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import * as _ from 'lodash';
import { DummyERC20TokenContract } from '../../generated_contract_wrappers/dummy_erc20_token';
import { DummyERC721TokenContract } from '../../generated_contract_wrappers/dummy_erc721_token';
import { ERC20ProxyContract } from '../../generated_contract_wrappers/erc20_proxy';
import { ERC721ProxyContract } from '../../generated_contract_wrappers/erc721_proxy';
import { ExchangeContract } from '../../generated_contract_wrappers/exchange';
import { OrderValidatorContract } from '../../generated_contract_wrappers/order_validator';
import { artifacts } from '../utils/artifacts';
import { chaiSetup } from '../utils/chai_setup';
import { constants } from '../utils/constants';
import { ERC20Wrapper } from '../utils/erc20_wrapper';
import { ERC721Wrapper } from '../utils/erc721_wrapper';
import { ExchangeWrapper } from '../utils/exchange_wrapper';
import { OrderFactory } from '../utils/order_factory';
import { OrderStatus } from '../utils/types';
import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe('OrderValidator', () => {
let makerAddress: string;
let owner: string;
let takerAddress: string;
let erc20AssetData: string;
let erc721AssetData: string;
let erc20Token: DummyERC20TokenContract;
let zrxToken: DummyERC20TokenContract;
let erc721Token: DummyERC721TokenContract;
let exchange: ExchangeContract;
let orderValidator: OrderValidatorContract;
let erc20Proxy: ERC20ProxyContract;
let erc721Proxy: ERC721ProxyContract;
let signedOrder: SignedOrder;
let signedOrder2: SignedOrder;
let orderFactory: OrderFactory;
const tokenId = new BigNumber(123456789);
const tokenId2 = new BigNumber(987654321);
const ERC721_BALANCE = new BigNumber(1);
const ERC721_ALLOWANCE = new BigNumber(1);
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
const usedAddresses = ([owner, makerAddress, takerAddress] = _.slice(accounts, 0, 3));
const erc20Wrapper = new ERC20Wrapper(provider, usedAddresses, owner);
const erc721Wrapper = new ERC721Wrapper(provider, usedAddresses, owner);
const numDummyErc20ToDeploy = 2;
[erc20Token, zrxToken] = await erc20Wrapper.deployDummyTokensAsync(
numDummyErc20ToDeploy,
constants.DUMMY_TOKEN_DECIMALS,
);
erc20Proxy = await erc20Wrapper.deployProxyAsync();
[erc721Token] = await erc721Wrapper.deployDummyTokensAsync();
erc721Proxy = await erc721Wrapper.deployProxyAsync();
const zrxAssetData = assetDataUtils.encodeERC20AssetData(zrxToken.address);
exchange = await ExchangeContract.deployFrom0xArtifactAsync(
artifacts.Exchange,
provider,
txDefaults,
zrxAssetData,
);
const exchangeWrapper = new ExchangeWrapper(exchange, provider);
await exchangeWrapper.registerAssetProxyAsync(erc20Proxy.address, owner);
await exchangeWrapper.registerAssetProxyAsync(erc721Proxy.address, owner);
orderValidator = await OrderValidatorContract.deployFrom0xArtifactAsync(
artifacts.OrderValidator,
provider,
txDefaults,
exchange.address,
zrxAssetData,
);
erc20AssetData = assetDataUtils.encodeERC20AssetData(erc20Token.address);
erc721AssetData = assetDataUtils.encodeERC721AssetData(erc721Token.address, tokenId);
const defaultOrderParams = {
...constants.STATIC_ORDER_PARAMS,
exchangeAddress: exchange.address,
makerAddress,
feeRecipientAddress: constants.NULL_ADDRESS,
makerAssetData: erc20AssetData,
takerAssetData: erc721AssetData,
};
const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
orderFactory = new OrderFactory(privateKey, defaultOrderParams);
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
});
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('getBalanceAndAllowance', () => {
describe('getERC721TokenOwner', async () => {
it('should return the null address when tokenId is not owned', async () => {
const tokenOwner = await orderValidator.getERC721TokenOwner.callAsync(makerAddress, tokenId);
expect(tokenOwner).to.be.equal(constants.NULL_ADDRESS);
});
it('should return the owner address when tokenId is owned', async () => {
await web3Wrapper.awaitTransactionSuccessAsync(
await erc721Token.mint.sendTransactionAsync(makerAddress, tokenId),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const tokenOwner = await orderValidator.getERC721TokenOwner.callAsync(erc721Token.address, tokenId);
expect(tokenOwner).to.be.equal(makerAddress);
});
});
describe('ERC20 assetData', () => {
it('should return the correct balances and allowances when both values are 0', async () => {
const [newBalance, newAllowance] = await orderValidator.getBalanceAndAllowance.callAsync(
makerAddress,
erc20AssetData,
);
expect(constants.ZERO_AMOUNT).to.be.bignumber.equal(newBalance);
expect(constants.ZERO_AMOUNT).to.be.bignumber.equal(newAllowance);
});
it('should return the correct balance and allowance when both values are non-zero', async () => {
const balance = new BigNumber(123);
const allowance = new BigNumber(456);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc20Token.setBalance.sendTransactionAsync(makerAddress, balance),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc20Token.approve.sendTransactionAsync(erc20Proxy.address, allowance, {
from: makerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const [newBalance, newAllowance] = await orderValidator.getBalanceAndAllowance.callAsync(
makerAddress,
erc20AssetData,
);
expect(balance).to.be.bignumber.equal(newBalance);
expect(allowance).to.be.bignumber.equal(newAllowance);
});
});
describe('ERC721 assetData', () => {
it('should return a balance of 0 when the tokenId is not owned by target', async () => {
const [newBalance] = await orderValidator.getBalanceAndAllowance.callAsync(
makerAddress,
erc721AssetData,
);
expect(newBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
});
it('should return an allowance of 0 when no approval is set', async () => {
const [, newAllowance] = await orderValidator.getBalanceAndAllowance.callAsync(
makerAddress,
erc721AssetData,
);
expect(newAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
});
it('should return a balance of 1 when the tokenId is owned by target', async () => {
await web3Wrapper.awaitTransactionSuccessAsync(
await erc721Token.mint.sendTransactionAsync(makerAddress, tokenId),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const [newBalance] = await orderValidator.getBalanceAndAllowance.callAsync(
makerAddress,
erc721AssetData,
);
expect(newBalance).to.be.bignumber.equal(ERC721_BALANCE);
});
it('should return an allowance of 1 when ERC721Proxy is approved for all', async () => {
const isApproved = true;
await web3Wrapper.awaitTransactionSuccessAsync(
await erc721Token.setApprovalForAll.sendTransactionAsync(erc721Proxy.address, isApproved, {
from: makerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const [, newAllowance] = await orderValidator.getBalanceAndAllowance.callAsync(
makerAddress,
erc721AssetData,
);
expect(newAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
});
it('should return an allowance of 1 when ERC721Proxy is approved for specific tokenId', async () => {
await web3Wrapper.awaitTransactionSuccessAsync(
await erc721Token.mint.sendTransactionAsync(makerAddress, tokenId),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc721Token.approve.sendTransactionAsync(erc721Proxy.address, tokenId, {
from: makerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const [, newAllowance] = await orderValidator.getBalanceAndAllowance.callAsync(
makerAddress,
erc721AssetData,
);
expect(newAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
});
});
});
describe('getBalancesAndAllowances', () => {
it('should return the correct balances and allowances when all values are 0', async () => {
const [
[erc20Balance, erc721Balance],
[erc20Allowance, erc721Allowance],
] = await orderValidator.getBalancesAndAllowances.callAsync(makerAddress, [
erc20AssetData,
erc721AssetData,
]);
expect(erc20Balance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(erc721Balance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(erc20Allowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(erc721Allowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
});
it('should return the correct balances and allowances when balances and allowances are non-zero', async () => {
const balance = new BigNumber(123);
const allowance = new BigNumber(456);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc20Token.setBalance.sendTransactionAsync(makerAddress, balance),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc20Token.approve.sendTransactionAsync(erc20Proxy.address, allowance, {
from: makerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc721Token.mint.sendTransactionAsync(makerAddress, tokenId),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc721Token.approve.sendTransactionAsync(erc721Proxy.address, tokenId, {
from: makerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const [
[erc20Balance, erc721Balance],
[erc20Allowance, erc721Allowance],
] = await orderValidator.getBalancesAndAllowances.callAsync(makerAddress, [
erc20AssetData,
erc721AssetData,
]);
expect(erc20Balance).to.be.bignumber.equal(balance);
expect(erc721Balance).to.be.bignumber.equal(ERC721_BALANCE);
expect(erc20Allowance).to.be.bignumber.equal(allowance);
expect(erc721Allowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
});
});
describe('getTraderInfo', () => {
beforeEach(async () => {
signedOrder = await orderFactory.newSignedOrderAsync();
});
it('should return the correct info when no balances or allowances are set', async () => {
const traderInfo = await orderValidator.getTraderInfo.callAsync(signedOrder, takerAddress);
expect(traderInfo.makerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo.makerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo.takerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo.makerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo.takerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
});
it('should return the correct info when balances and allowances are set', async () => {
const makerBalance = new BigNumber(123);
const makerAllowance = new BigNumber(456);
const makerZrxBalance = new BigNumber(789);
const takerZrxAllowance = new BigNumber(987);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc20Token.setBalance.sendTransactionAsync(makerAddress, makerBalance),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc20Token.approve.sendTransactionAsync(erc20Proxy.address, makerAllowance, {
from: makerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await zrxToken.setBalance.sendTransactionAsync(makerAddress, makerZrxBalance),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await zrxToken.approve.sendTransactionAsync(erc20Proxy.address, takerZrxAllowance, {
from: takerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc721Token.mint.sendTransactionAsync(takerAddress, tokenId),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc721Token.approve.sendTransactionAsync(erc721Proxy.address, tokenId, {
from: takerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const traderInfo = await orderValidator.getTraderInfo.callAsync(signedOrder, takerAddress);
expect(traderInfo.makerBalance).to.be.bignumber.equal(makerBalance);
expect(traderInfo.makerAllowance).to.be.bignumber.equal(makerAllowance);
expect(traderInfo.takerBalance).to.be.bignumber.equal(ERC721_BALANCE);
expect(traderInfo.takerAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
expect(traderInfo.makerZrxBalance).to.be.bignumber.equal(makerZrxBalance);
expect(traderInfo.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo.takerZrxAllowance).to.be.bignumber.equal(takerZrxAllowance);
});
});
describe('getTradersInfo', () => {
beforeEach(async () => {
signedOrder = await orderFactory.newSignedOrderAsync();
signedOrder2 = await orderFactory.newSignedOrderAsync({
takerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, tokenId2),
});
});
it('should return the correct info when no balances or allowances have been set', async () => {
const orders = [signedOrder, signedOrder2];
const takers = [takerAddress, takerAddress];
const [traderInfo1, traderInfo2] = await orderValidator.getTradersInfo.callAsync(orders, takers);
expect(traderInfo1.makerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo1.makerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo1.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo1.takerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo1.makerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo1.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo1.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo1.takerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo2.makerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo2.makerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo2.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo2.takerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo2.makerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo2.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo2.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo2.takerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
});
it('should return the correct info when balances and allowances are set', async () => {
const makerBalance = new BigNumber(123);
const makerAllowance = new BigNumber(456);
const makerZrxBalance = new BigNumber(789);
const takerZrxAllowance = new BigNumber(987);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc20Token.setBalance.sendTransactionAsync(makerAddress, makerBalance),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc20Token.approve.sendTransactionAsync(erc20Proxy.address, makerAllowance, {
from: makerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await zrxToken.setBalance.sendTransactionAsync(makerAddress, makerZrxBalance),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await zrxToken.approve.sendTransactionAsync(erc20Proxy.address, takerZrxAllowance, {
from: takerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const isApproved = true;
await web3Wrapper.awaitTransactionSuccessAsync(
await erc721Token.setApprovalForAll.sendTransactionAsync(erc721Proxy.address, isApproved, {
from: takerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc721Token.mint.sendTransactionAsync(takerAddress, tokenId2),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const orders = [signedOrder, signedOrder2];
const takers = [takerAddress, takerAddress];
const [traderInfo1, traderInfo2] = await orderValidator.getTradersInfo.callAsync(orders, takers);
expect(traderInfo1.makerBalance).to.be.bignumber.equal(makerBalance);
expect(traderInfo1.makerAllowance).to.be.bignumber.equal(makerAllowance);
expect(traderInfo1.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo1.takerAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
expect(traderInfo1.makerZrxBalance).to.be.bignumber.equal(makerZrxBalance);
expect(traderInfo1.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo1.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo1.takerZrxAllowance).to.be.bignumber.equal(takerZrxAllowance);
expect(traderInfo2.makerBalance).to.be.bignumber.equal(makerBalance);
expect(traderInfo2.makerAllowance).to.be.bignumber.equal(makerAllowance);
expect(traderInfo2.takerBalance).to.be.bignumber.equal(ERC721_BALANCE);
expect(traderInfo2.takerAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
expect(traderInfo2.makerZrxBalance).to.be.bignumber.equal(makerZrxBalance);
expect(traderInfo2.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo2.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo2.takerZrxAllowance).to.be.bignumber.equal(takerZrxAllowance);
});
});
describe('getOrderAndTraderInfo', () => {
beforeEach(async () => {
signedOrder = await orderFactory.newSignedOrderAsync();
});
it('should return the correct info when no balances or allowances are set', async () => {
const [orderInfo, traderInfo] = await orderValidator.getOrderAndTraderInfo.callAsync(
signedOrder,
takerAddress,
);
const expectedOrderHash = orderHashUtils.getOrderHashHex(signedOrder);
expect(orderInfo.orderStatus).to.be.equal(OrderStatus.FILLABLE);
expect(orderInfo.orderHash).to.be.equal(expectedOrderHash);
expect(orderInfo.orderTakerAssetFilledAmount).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo.makerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo.makerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo.takerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo.makerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo.takerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
});
it('should return the correct info when balances and allowances are set', async () => {
const makerBalance = new BigNumber(123);
const makerAllowance = new BigNumber(456);
const makerZrxBalance = new BigNumber(789);
const takerZrxAllowance = new BigNumber(987);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc20Token.setBalance.sendTransactionAsync(makerAddress, makerBalance),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc20Token.approve.sendTransactionAsync(erc20Proxy.address, makerAllowance, {
from: makerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await zrxToken.setBalance.sendTransactionAsync(makerAddress, makerZrxBalance),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await zrxToken.approve.sendTransactionAsync(erc20Proxy.address, takerZrxAllowance, {
from: takerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc721Token.mint.sendTransactionAsync(takerAddress, tokenId),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc721Token.approve.sendTransactionAsync(erc721Proxy.address, tokenId, {
from: takerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const [orderInfo, traderInfo] = await orderValidator.getOrderAndTraderInfo.callAsync(
signedOrder,
takerAddress,
);
const expectedOrderHash = orderHashUtils.getOrderHashHex(signedOrder);
expect(orderInfo.orderStatus).to.be.equal(OrderStatus.FILLABLE);
expect(orderInfo.orderHash).to.be.equal(expectedOrderHash);
expect(orderInfo.orderTakerAssetFilledAmount).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo.makerBalance).to.be.bignumber.equal(makerBalance);
expect(traderInfo.makerAllowance).to.be.bignumber.equal(makerAllowance);
expect(traderInfo.takerBalance).to.be.bignumber.equal(ERC721_BALANCE);
expect(traderInfo.takerAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
expect(traderInfo.makerZrxBalance).to.be.bignumber.equal(makerZrxBalance);
expect(traderInfo.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo.takerZrxAllowance).to.be.bignumber.equal(takerZrxAllowance);
});
});
describe('getOrdersAndTradersInfo', () => {
beforeEach(async () => {
signedOrder = await orderFactory.newSignedOrderAsync();
signedOrder2 = await orderFactory.newSignedOrderAsync({
takerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, tokenId2),
});
});
it('should return the correct info when no balances or allowances have been set', async () => {
const orders = [signedOrder, signedOrder2];
const takers = [takerAddress, takerAddress];
const [
[orderInfo1, orderInfo2],
[traderInfo1, traderInfo2],
] = await orderValidator.getOrdersAndTradersInfo.callAsync(orders, takers);
const expectedOrderHash1 = orderHashUtils.getOrderHashHex(signedOrder);
const expectedOrderHash2 = orderHashUtils.getOrderHashHex(signedOrder2);
expect(orderInfo1.orderStatus).to.be.equal(OrderStatus.FILLABLE);
expect(orderInfo1.orderHash).to.be.equal(expectedOrderHash1);
expect(orderInfo1.orderTakerAssetFilledAmount).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(orderInfo2.orderStatus).to.be.equal(OrderStatus.FILLABLE);
expect(orderInfo2.orderHash).to.be.equal(expectedOrderHash2);
expect(orderInfo2.orderTakerAssetFilledAmount).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo1.makerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo1.makerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo1.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo1.takerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo1.makerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo1.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo1.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo1.takerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo2.makerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo2.makerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo2.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo2.takerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo2.makerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo2.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo2.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo2.takerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
});
it('should return the correct info when balances and allowances are set', async () => {
const makerBalance = new BigNumber(123);
const makerAllowance = new BigNumber(456);
const makerZrxBalance = new BigNumber(789);
const takerZrxAllowance = new BigNumber(987);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc20Token.setBalance.sendTransactionAsync(makerAddress, makerBalance),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc20Token.approve.sendTransactionAsync(erc20Proxy.address, makerAllowance, {
from: makerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await zrxToken.setBalance.sendTransactionAsync(makerAddress, makerZrxBalance),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await zrxToken.approve.sendTransactionAsync(erc20Proxy.address, takerZrxAllowance, {
from: takerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const isApproved = true;
await web3Wrapper.awaitTransactionSuccessAsync(
await erc721Token.setApprovalForAll.sendTransactionAsync(erc721Proxy.address, isApproved, {
from: takerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc721Token.mint.sendTransactionAsync(takerAddress, tokenId2),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const orders = [signedOrder, signedOrder2];
const takers = [takerAddress, takerAddress];
const [
[orderInfo1, orderInfo2],
[traderInfo1, traderInfo2],
] = await orderValidator.getOrdersAndTradersInfo.callAsync(orders, takers);
const expectedOrderHash1 = orderHashUtils.getOrderHashHex(signedOrder);
const expectedOrderHash2 = orderHashUtils.getOrderHashHex(signedOrder2);
expect(orderInfo1.orderStatus).to.be.equal(OrderStatus.FILLABLE);
expect(orderInfo1.orderHash).to.be.equal(expectedOrderHash1);
expect(orderInfo1.orderTakerAssetFilledAmount).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(orderInfo2.orderStatus).to.be.equal(OrderStatus.FILLABLE);
expect(orderInfo2.orderHash).to.be.equal(expectedOrderHash2);
expect(orderInfo2.orderTakerAssetFilledAmount).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo1.makerBalance).to.be.bignumber.equal(makerBalance);
expect(traderInfo1.makerAllowance).to.be.bignumber.equal(makerAllowance);
expect(traderInfo1.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo1.takerAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
expect(traderInfo1.makerZrxBalance).to.be.bignumber.equal(makerZrxBalance);
expect(traderInfo1.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo1.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo1.takerZrxAllowance).to.be.bignumber.equal(takerZrxAllowance);
expect(traderInfo2.makerBalance).to.be.bignumber.equal(makerBalance);
expect(traderInfo2.makerAllowance).to.be.bignumber.equal(makerAllowance);
expect(traderInfo2.takerBalance).to.be.bignumber.equal(ERC721_BALANCE);
expect(traderInfo2.takerAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
expect(traderInfo2.makerZrxBalance).to.be.bignumber.equal(makerZrxBalance);
expect(traderInfo2.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo2.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
expect(traderInfo2.takerZrxAllowance).to.be.bignumber.equal(takerZrxAllowance);
});
});
});
// tslint:disable:max-file-line-count

View File

@ -422,7 +422,7 @@ describe('AssetProxyOwner', () => {
await multiSigWrapper.confirmTransactionAsync(txId, owners[1]); await multiSigWrapper.confirmTransactionAsync(txId, owners[1]);
const execRes = await multiSigWrapper.executeRemoveAuthorizedAddressAtIndexAsync(txId, owners[0]); const execRes = await multiSigWrapper.executeRemoveAuthorizedAddressAtIndexAsync(txId, owners[0]);
const execLog = execRes.logs[0] as LogWithDecodedArgs<AssetProxyOwnerExecutionEventArgs>; const execLog = execRes.logs[1] as LogWithDecodedArgs<AssetProxyOwnerExecutionEventArgs>;
expect(execLog.args.transactionId).to.be.bignumber.equal(txId); expect(execLog.args.transactionId).to.be.bignumber.equal(txId);
const tx = await testAssetProxyOwner.transactions.callAsync(txId); const tx = await testAssetProxyOwner.transactions.callAsync(txId);
@ -449,7 +449,7 @@ describe('AssetProxyOwner', () => {
await multiSigWrapper.confirmTransactionAsync(txId, owners[1]); await multiSigWrapper.confirmTransactionAsync(txId, owners[1]);
const execRes = await multiSigWrapper.executeRemoveAuthorizedAddressAtIndexAsync(txId, owners[0]); const execRes = await multiSigWrapper.executeRemoveAuthorizedAddressAtIndexAsync(txId, owners[0]);
const execLog = execRes.logs[0] as LogWithDecodedArgs<AssetProxyOwnerExecutionEventArgs>; const execLog = execRes.logs[1] as LogWithDecodedArgs<AssetProxyOwnerExecutionEventArgs>;
expect(execLog.args.transactionId).to.be.bignumber.equal(txId); expect(execLog.args.transactionId).to.be.bignumber.equal(txId);
const tx = await testAssetProxyOwner.transactions.callAsync(txId); const tx = await testAssetProxyOwner.transactions.callAsync(txId);

View File

@ -0,0 +1,279 @@
import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { RevertReason } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import { LogWithDecodedArgs } from 'ethereum-types';
import {
DummyERC721ReceiverContract,
DummyERC721ReceiverTokenReceivedEventArgs,
} from '../../generated_contract_wrappers/dummy_erc721_receiver';
import {
DummyERC721TokenContract,
DummyERC721TokenTransferEventArgs,
} from '../../generated_contract_wrappers/dummy_erc721_token';
import { InvalidERC721ReceiverContract } from '../../generated_contract_wrappers/invalid_erc721_receiver';
import { artifacts } from '../utils/artifacts';
import { expectTransactionFailedAsync, expectTransactionFailedWithoutReasonAsync } from '../utils/assertions';
import { chaiSetup } from '../utils/chai_setup';
import { constants } from '../utils/constants';
import { LogDecoder } from '../utils/log_decoder';
import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
// tslint:disable:no-unnecessary-type-assertion
describe('ERC721Token', () => {
let owner: string;
let spender: string;
let token: DummyERC721TokenContract;
let erc721Receiver: DummyERC721ReceiverContract;
let logDecoder: LogDecoder;
const tokenId = new BigNumber(1);
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
owner = accounts[0];
spender = accounts[1];
token = await DummyERC721TokenContract.deployFrom0xArtifactAsync(
artifacts.DummyERC721Token,
provider,
txDefaults,
constants.DUMMY_TOKEN_NAME,
constants.DUMMY_TOKEN_SYMBOL,
);
erc721Receiver = await DummyERC721ReceiverContract.deployFrom0xArtifactAsync(
artifacts.DummyERC721Receiver,
provider,
txDefaults,
);
logDecoder = new LogDecoder(web3Wrapper);
await web3Wrapper.awaitTransactionSuccessAsync(
await token.mint.sendTransactionAsync(owner, tokenId, { from: owner }),
constants.AWAIT_TRANSACTION_MINED_MS,
);
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
});
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('transferFrom', () => {
it('should revert if the tokenId is not owner', async () => {
const from = owner;
const to = erc721Receiver.address;
const unownedTokenId = new BigNumber(2);
await expectTransactionFailedAsync(
token.transferFrom.sendTransactionAsync(from, to, unownedTokenId),
RevertReason.Erc721ZeroOwner,
);
});
it('should revert if transferring to a null address', async () => {
const from = owner;
const to = constants.NULL_ADDRESS;
await expectTransactionFailedAsync(
token.transferFrom.sendTransactionAsync(from, to, tokenId),
RevertReason.Erc721ZeroToAddress,
);
});
it('should revert if the from address does not own the token', async () => {
const from = spender;
const to = erc721Receiver.address;
await expectTransactionFailedAsync(
token.transferFrom.sendTransactionAsync(from, to, tokenId),
RevertReason.Erc721OwnerMismatch,
);
});
it('should revert if spender does not own the token, is not approved, and is not approved for all', async () => {
const from = owner;
const to = erc721Receiver.address;
await expectTransactionFailedAsync(
token.transferFrom.sendTransactionAsync(from, to, tokenId, { from: spender }),
RevertReason.Erc721InvalidSpender,
);
});
it('should transfer the token if called by owner', async () => {
const from = owner;
const to = erc721Receiver.address;
const txReceipt = await logDecoder.getTxWithDecodedLogsAsync(
await token.transferFrom.sendTransactionAsync(from, to, tokenId),
);
const newOwner = await token.ownerOf.callAsync(tokenId);
expect(newOwner).to.be.equal(to);
const log = txReceipt.logs[0] as LogWithDecodedArgs<DummyERC721TokenTransferEventArgs>;
expect(log.args._from).to.be.equal(from);
expect(log.args._to).to.be.equal(to);
expect(log.args._tokenId).to.be.bignumber.equal(tokenId);
});
it('should transfer the token if spender is approved for all', async () => {
const isApproved = true;
await web3Wrapper.awaitTransactionSuccessAsync(
await token.setApprovalForAll.sendTransactionAsync(spender, isApproved),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const from = owner;
const to = erc721Receiver.address;
const txReceipt = await logDecoder.getTxWithDecodedLogsAsync(
await token.transferFrom.sendTransactionAsync(from, to, tokenId),
);
const newOwner = await token.ownerOf.callAsync(tokenId);
expect(newOwner).to.be.equal(to);
const log = txReceipt.logs[0] as LogWithDecodedArgs<DummyERC721TokenTransferEventArgs>;
expect(log.args._from).to.be.equal(from);
expect(log.args._to).to.be.equal(to);
expect(log.args._tokenId).to.be.bignumber.equal(tokenId);
});
it('should transfer the token if spender is individually approved', async () => {
await web3Wrapper.awaitTransactionSuccessAsync(
await token.approve.sendTransactionAsync(spender, tokenId),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const from = owner;
const to = erc721Receiver.address;
const txReceipt = await logDecoder.getTxWithDecodedLogsAsync(
await token.transferFrom.sendTransactionAsync(from, to, tokenId),
);
const newOwner = await token.ownerOf.callAsync(tokenId);
expect(newOwner).to.be.equal(to);
const approvedAddress = await token.getApproved.callAsync(tokenId);
expect(approvedAddress).to.be.equal(constants.NULL_ADDRESS);
const log = txReceipt.logs[0] as LogWithDecodedArgs<DummyERC721TokenTransferEventArgs>;
expect(log.args._from).to.be.equal(from);
expect(log.args._to).to.be.equal(to);
expect(log.args._tokenId).to.be.bignumber.equal(tokenId);
});
});
describe('safeTransferFrom without data', () => {
it('should transfer token to a non-contract address if called by owner', async () => {
const from = owner;
const to = spender;
const txReceipt = await logDecoder.getTxWithDecodedLogsAsync(
await token.safeTransferFrom1.sendTransactionAsync(from, to, tokenId),
);
const newOwner = await token.ownerOf.callAsync(tokenId);
expect(newOwner).to.be.equal(to);
const log = txReceipt.logs[0] as LogWithDecodedArgs<DummyERC721TokenTransferEventArgs>;
expect(log.args._from).to.be.equal(from);
expect(log.args._to).to.be.equal(to);
expect(log.args._tokenId).to.be.bignumber.equal(tokenId);
});
it('should revert if transferring to a contract address without onERC721Received', async () => {
const contract = await DummyERC721TokenContract.deployFrom0xArtifactAsync(
artifacts.DummyERC721Token,
provider,
txDefaults,
constants.DUMMY_TOKEN_NAME,
constants.DUMMY_TOKEN_SYMBOL,
);
const from = owner;
const to = contract.address;
await expectTransactionFailedWithoutReasonAsync(
token.safeTransferFrom1.sendTransactionAsync(from, to, tokenId),
);
});
it('should revert if onERC721Received does not return the correct value', async () => {
const invalidErc721Receiver = await InvalidERC721ReceiverContract.deployFrom0xArtifactAsync(
artifacts.InvalidERC721Receiver,
provider,
txDefaults,
);
const from = owner;
const to = invalidErc721Receiver.address;
await expectTransactionFailedAsync(
token.safeTransferFrom1.sendTransactionAsync(from, to, tokenId),
RevertReason.Erc721InvalidSelector,
);
});
it('should transfer to contract and call onERC721Received with correct return value', async () => {
const from = owner;
const to = erc721Receiver.address;
const txReceipt = await logDecoder.getTxWithDecodedLogsAsync(
await token.safeTransferFrom1.sendTransactionAsync(from, to, tokenId),
);
const newOwner = await token.ownerOf.callAsync(tokenId);
expect(newOwner).to.be.equal(to);
const transferLog = txReceipt.logs[0] as LogWithDecodedArgs<DummyERC721TokenTransferEventArgs>;
const receiverLog = txReceipt.logs[1] as LogWithDecodedArgs<DummyERC721ReceiverTokenReceivedEventArgs>;
expect(transferLog.args._from).to.be.equal(from);
expect(transferLog.args._to).to.be.equal(to);
expect(transferLog.args._tokenId).to.be.bignumber.equal(tokenId);
expect(receiverLog.args.operator).to.be.equal(owner);
expect(receiverLog.args.from).to.be.equal(from);
expect(receiverLog.args.tokenId).to.be.bignumber.equal(tokenId);
expect(receiverLog.args.data).to.be.equal(constants.NULL_BYTES);
});
});
describe('safeTransferFrom with data', () => {
const data = '0x0102030405060708090a0b0c0d0e0f';
it('should transfer token to a non-contract address if called by owner', async () => {
const from = owner;
const to = spender;
const txReceipt = await logDecoder.getTxWithDecodedLogsAsync(
await token.safeTransferFrom2.sendTransactionAsync(from, to, tokenId, data),
);
const newOwner = await token.ownerOf.callAsync(tokenId);
expect(newOwner).to.be.equal(to);
const log = txReceipt.logs[0] as LogWithDecodedArgs<DummyERC721TokenTransferEventArgs>;
expect(log.args._from).to.be.equal(from);
expect(log.args._to).to.be.equal(to);
expect(log.args._tokenId).to.be.bignumber.equal(tokenId);
});
it('should revert if transferring to a contract address without onERC721Received', async () => {
const contract = await DummyERC721TokenContract.deployFrom0xArtifactAsync(
artifacts.DummyERC721Token,
provider,
txDefaults,
constants.DUMMY_TOKEN_NAME,
constants.DUMMY_TOKEN_SYMBOL,
);
const from = owner;
const to = contract.address;
await expectTransactionFailedWithoutReasonAsync(
token.safeTransferFrom2.sendTransactionAsync(from, to, tokenId, data),
);
});
it('should revert if onERC721Received does not return the correct value', async () => {
const invalidErc721Receiver = await InvalidERC721ReceiverContract.deployFrom0xArtifactAsync(
artifacts.InvalidERC721Receiver,
provider,
txDefaults,
);
const from = owner;
const to = invalidErc721Receiver.address;
await expectTransactionFailedAsync(
token.safeTransferFrom2.sendTransactionAsync(from, to, tokenId, data),
RevertReason.Erc721InvalidSelector,
);
});
it('should transfer to contract and call onERC721Received with correct return value', async () => {
const from = owner;
const to = erc721Receiver.address;
const txReceipt = await logDecoder.getTxWithDecodedLogsAsync(
await token.safeTransferFrom2.sendTransactionAsync(from, to, tokenId, data),
);
const newOwner = await token.ownerOf.callAsync(tokenId);
expect(newOwner).to.be.equal(to);
const transferLog = txReceipt.logs[0] as LogWithDecodedArgs<DummyERC721TokenTransferEventArgs>;
const receiverLog = txReceipt.logs[1] as LogWithDecodedArgs<DummyERC721ReceiverTokenReceivedEventArgs>;
expect(transferLog.args._from).to.be.equal(from);
expect(transferLog.args._to).to.be.equal(to);
expect(transferLog.args._tokenId).to.be.bignumber.equal(tokenId);
expect(receiverLog.args.operator).to.be.equal(owner);
expect(receiverLog.args.from).to.be.equal(from);
expect(receiverLog.args.tokenId).to.be.bignumber.equal(tokenId);
expect(receiverLog.args.data).to.be.equal(data);
});
});
});
// tslint:enable:no-unnecessary-type-assertion

View File

@ -17,7 +17,7 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe('UnlimitedAllowanceToken', () => { describe('UnlimitedAllowanceToken', () => {
let owner: string; let owner: string;
let spender: string; let spender: string;
const MAX_MINT_VALUE = new BigNumber(100000000000000000000); const MAX_MINT_VALUE = new BigNumber(10000000000000000000000);
let token: DummyERC20TokenContract; let token: DummyERC20TokenContract;
before(async () => { before(async () => {

View File

@ -4,15 +4,18 @@ import * as AssetProxyOwner from '../../artifacts/AssetProxyOwner.json';
import * as DummyERC20Token from '../../artifacts/DummyERC20Token.json'; import * as DummyERC20Token from '../../artifacts/DummyERC20Token.json';
import * as DummyERC721Receiver from '../../artifacts/DummyERC721Receiver.json'; import * as DummyERC721Receiver from '../../artifacts/DummyERC721Receiver.json';
import * as DummyERC721Token from '../../artifacts/DummyERC721Token.json'; import * as DummyERC721Token from '../../artifacts/DummyERC721Token.json';
import * as DummyNoReturnERC20Token from '../../artifacts/DummyNoReturnERC20Token.json';
import * as ERC20Proxy from '../../artifacts/ERC20Proxy.json'; import * as ERC20Proxy from '../../artifacts/ERC20Proxy.json';
import * as ERC721Proxy from '../../artifacts/ERC721Proxy.json'; import * as ERC721Proxy from '../../artifacts/ERC721Proxy.json';
import * as Exchange from '../../artifacts/Exchange.json'; import * as Exchange from '../../artifacts/Exchange.json';
import * as ExchangeWrapper from '../../artifacts/ExchangeWrapper.json'; import * as ExchangeWrapper from '../../artifacts/ExchangeWrapper.json';
import * as Forwarder from '../../artifacts/Forwarder.json'; import * as Forwarder from '../../artifacts/Forwarder.json';
import * as IAssetProxy from '../../artifacts/IAssetProxy.json'; import * as IAssetProxy from '../../artifacts/IAssetProxy.json';
import * as InvalidERC721Receiver from '../../artifacts/InvalidERC721Receiver.json';
import * as MixinAuthorizable from '../../artifacts/MixinAuthorizable.json'; import * as MixinAuthorizable from '../../artifacts/MixinAuthorizable.json';
import * as MultiSigWallet from '../../artifacts/MultiSigWallet.json'; import * as MultiSigWallet from '../../artifacts/MultiSigWallet.json';
import * as MultiSigWalletWithTimeLock from '../../artifacts/MultiSigWalletWithTimeLock.json'; import * as MultiSigWalletWithTimeLock from '../../artifacts/MultiSigWalletWithTimeLock.json';
import * as OrderValidator from '../../artifacts/OrderValidator.json';
import * as TestAssetProxyDispatcher from '../../artifacts/TestAssetProxyDispatcher.json'; import * as TestAssetProxyDispatcher from '../../artifacts/TestAssetProxyDispatcher.json';
import * as TestAssetProxyOwner from '../../artifacts/TestAssetProxyOwner.json'; import * as TestAssetProxyOwner from '../../artifacts/TestAssetProxyOwner.json';
import * as TestConstants from '../../artifacts/TestConstants.json'; import * as TestConstants from '../../artifacts/TestConstants.json';
@ -32,6 +35,7 @@ export const artifacts = {
DummyERC20Token: (DummyERC20Token as any) as ContractArtifact, DummyERC20Token: (DummyERC20Token as any) as ContractArtifact,
DummyERC721Receiver: (DummyERC721Receiver as any) as ContractArtifact, DummyERC721Receiver: (DummyERC721Receiver as any) as ContractArtifact,
DummyERC721Token: (DummyERC721Token as any) as ContractArtifact, DummyERC721Token: (DummyERC721Token as any) as ContractArtifact,
DummyNoReturnERC20Token: (DummyNoReturnERC20Token as any) as ContractArtifact,
ERC20Proxy: (ERC20Proxy as any) as ContractArtifact, ERC20Proxy: (ERC20Proxy as any) as ContractArtifact,
ERC721Proxy: (ERC721Proxy as any) as ContractArtifact, ERC721Proxy: (ERC721Proxy as any) as ContractArtifact,
Exchange: (Exchange as any) as ContractArtifact, Exchange: (Exchange as any) as ContractArtifact,
@ -39,9 +43,11 @@ export const artifacts = {
EtherToken: (EtherToken as any) as ContractArtifact, EtherToken: (EtherToken as any) as ContractArtifact,
Forwarder: (Forwarder as any) as ContractArtifact, Forwarder: (Forwarder as any) as ContractArtifact,
IAssetProxy: (IAssetProxy as any) as ContractArtifact, IAssetProxy: (IAssetProxy as any) as ContractArtifact,
InvalidERC721Receiver: (InvalidERC721Receiver as any) as ContractArtifact,
MixinAuthorizable: (MixinAuthorizable as any) as ContractArtifact, MixinAuthorizable: (MixinAuthorizable as any) as ContractArtifact,
MultiSigWallet: (MultiSigWallet as any) as ContractArtifact, MultiSigWallet: (MultiSigWallet as any) as ContractArtifact,
MultiSigWalletWithTimeLock: (MultiSigWalletWithTimeLock as any) as ContractArtifact, MultiSigWalletWithTimeLock: (MultiSigWalletWithTimeLock as any) as ContractArtifact,
OrderValidator: (OrderValidator as any) as ContractArtifact,
TestAssetProxyOwner: (TestAssetProxyOwner as any) as ContractArtifact, TestAssetProxyOwner: (TestAssetProxyOwner as any) as ContractArtifact,
TestAssetProxyDispatcher: (TestAssetProxyDispatcher as any) as ContractArtifact, TestAssetProxyDispatcher: (TestAssetProxyDispatcher as any) as ContractArtifact,
TestConstants: (TestConstants as any) as ContractArtifact, TestConstants: (TestConstants as any) as ContractArtifact,

View File

@ -81,7 +81,8 @@ export class ERC721Wrapper {
} }
public async doesTokenExistAsync(tokenAddress: string, tokenId: BigNumber): Promise<boolean> { public async doesTokenExistAsync(tokenAddress: string, tokenId: BigNumber): Promise<boolean> {
const tokenContract = this._getTokenContractFromAssetData(tokenAddress); const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
const doesExist = await tokenContract.exists.callAsync(tokenId); const owner = await tokenContract.ownerOf.callAsync(tokenId);
const doesExist = owner !== constants.NULL_ADDRESS;
return doesExist; return doesExist;
} }
public async approveProxyAsync(tokenAddress: string, tokenId: BigNumber): Promise<void> { public async approveProxyAsync(tokenAddress: string, tokenId: BigNumber): Promise<void> {

View File

@ -17,7 +17,7 @@ export class ExchangeWrapper {
constructor(exchangeContract: ExchangeContract, provider: Provider) { constructor(exchangeContract: ExchangeContract, provider: Provider) {
this._exchange = exchangeContract; this._exchange = exchangeContract;
this._web3Wrapper = new Web3Wrapper(provider); this._web3Wrapper = new Web3Wrapper(provider);
this._logDecoder = new LogDecoder(this._web3Wrapper, this._exchange.address); this._logDecoder = new LogDecoder(this._web3Wrapper);
} }
public async fillOrderAsync( public async fillOrderAsync(
signedOrder: SignedOrder, signedOrder: SignedOrder,
@ -266,4 +266,7 @@ export class ExchangeWrapper {
); );
return data; return data;
} }
public getExchangeAddress(): string {
return this._exchange.address;
}
} }

View File

@ -504,7 +504,11 @@ export class FillOrderCombinatorialUtils {
const actFilledTakerAmount = await this.exchangeWrapper.getTakerAssetFilledAmountAsync(orderHash); const actFilledTakerAmount = await this.exchangeWrapper.getTakerAssetFilledAmountAsync(orderHash);
expect(actFilledTakerAmount).to.be.bignumber.equal(expFilledTakerAmount, 'filledTakerAmount'); expect(actFilledTakerAmount).to.be.bignumber.equal(expFilledTakerAmount, 'filledTakerAmount');
expect(txReceipt.logs.length).to.be.equal(1, 'logs length'); const exchangeLogs = _.filter(
txReceipt.logs,
txLog => txLog.address === this.exchangeWrapper.getExchangeAddress(),
);
expect(exchangeLogs.length).to.be.equal(1, 'logs length');
// tslint:disable-next-line:no-unnecessary-type-assertion // tslint:disable-next-line:no-unnecessary-type-assertion
const log = txReceipt.logs[0] as LogWithDecodedArgs<ExchangeFillEventArgs>; const log = txReceipt.logs[0] as LogWithDecodedArgs<ExchangeFillEventArgs>;
expect(log.args.makerAddress).to.be.equal(makerAddress, 'log.args.makerAddress'); expect(log.args.makerAddress).to.be.equal(makerAddress, 'log.args.makerAddress');

View File

@ -58,7 +58,7 @@ export class ForwarderWrapper {
constructor(contractInstance: ForwarderContract, provider: Provider) { constructor(contractInstance: ForwarderContract, provider: Provider) {
this._forwarderContract = contractInstance; this._forwarderContract = contractInstance;
this._web3Wrapper = new Web3Wrapper(provider); this._web3Wrapper = new Web3Wrapper(provider);
this._logDecoder = new LogDecoder(this._web3Wrapper, this._forwarderContract.address); this._logDecoder = new LogDecoder(this._web3Wrapper);
} }
public async marketSellOrdersWithEthAsync( public async marketSellOrdersWithEthAsync(
orders: SignedOrder[], orders: SignedOrder[],

View File

@ -16,7 +16,6 @@ import { constants } from './constants';
export class LogDecoder { export class LogDecoder {
private readonly _web3Wrapper: Web3Wrapper; private readonly _web3Wrapper: Web3Wrapper;
private readonly _contractAddress: string;
private readonly _abiDecoder: AbiDecoder; private readonly _abiDecoder: AbiDecoder;
public static wrapLogBigNumbers(log: any): any { public static wrapLogBigNumbers(log: any): any {
const argNames = _.keys(log.args); const argNames = _.keys(log.args);
@ -27,9 +26,8 @@ export class LogDecoder {
} }
} }
} }
constructor(web3Wrapper: Web3Wrapper, contractAddress: string) { constructor(web3Wrapper: Web3Wrapper) {
this._web3Wrapper = web3Wrapper; this._web3Wrapper = web3Wrapper;
this._contractAddress = contractAddress;
const abiArrays: AbiDefinition[][] = []; const abiArrays: AbiDefinition[][] = [];
_.forEach(artifacts, (artifact: ContractArtifact) => { _.forEach(artifacts, (artifact: ContractArtifact) => {
const compilerOutput = artifact.compilerOutput; const compilerOutput = artifact.compilerOutput;
@ -48,7 +46,6 @@ export class LogDecoder {
} }
public async getTxWithDecodedLogsAsync(txHash: string): Promise<TransactionReceiptWithDecodedLogs> { public async getTxWithDecodedLogsAsync(txHash: string): Promise<TransactionReceiptWithDecodedLogs> {
const tx = await this._web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); const tx = await this._web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
tx.logs = _.filter(tx.logs, log => log.address === this._contractAddress);
tx.logs = _.map(tx.logs, log => this.decodeLogOrThrow(log)); tx.logs = _.map(tx.logs, log => this.decodeLogOrThrow(log));
return tx; return tx;
} }

View File

@ -16,7 +16,7 @@ export class MultiSigWrapper {
constructor(multiSigContract: MultiSigWalletContract, provider: Provider) { constructor(multiSigContract: MultiSigWalletContract, provider: Provider) {
this._multiSig = multiSigContract; this._multiSig = multiSigContract;
this._web3Wrapper = new Web3Wrapper(provider); this._web3Wrapper = new Web3Wrapper(provider);
this._logDecoder = new LogDecoder(this._web3Wrapper, this._multiSig.address); this._logDecoder = new LogDecoder(this._web3Wrapper);
} }
public async submitTransactionAsync( public async submitTransactionAsync(
destination: string, destination: string,

View File

@ -8,7 +8,7 @@
"watch_without_deps": "yarn pre_build && tsc -w", "watch_without_deps": "yarn pre_build && tsc -w",
"build": "yarn pre_build && tsc", "build": "yarn pre_build && tsc",
"pre_build": "run-s update_artifacts generate_contract_wrappers", "pre_build": "run-s update_artifacts generate_contract_wrappers",
"update_artifacts": "for i in ${npm_package_config_contracts}; do copyfiles -u 4 ../migrations/artifacts/2.0.0/$i.json lib/artifacts; done;", "update_artifacts": "for i in ${npm_package_config_contracts}; do copyfiles -u 4 ../migrations/artifacts/2.0.0-beta-testnet/$i.json lib/artifacts; done;",
"generate_contract_wrappers": "abi-gen --abis 'lib/artifacts/@(Exchange|DummyERC20Token|DummyERC721Token).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/generated_contract_wrappers --backend ethers", "generate_contract_wrappers": "abi-gen --abis 'lib/artifacts/@(Exchange|DummyERC20Token|DummyERC721Token).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/generated_contract_wrappers --backend ethers",
"copy_monorepo_scripts": "copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", "copy_monorepo_scripts": "copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts",
"clean": "shx rm -rf lib src/generated_contract_wrappers", "clean": "shx rm -rf lib src/generated_contract_wrappers",

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,115 @@
{
"schemaVersion": "2.0.0",
"contractName": "DummyERC721Receiver",
"compilerOutput": {
"abi": [
{
"constant": false,
"inputs": [
{
"name": "_operator",
"type": "address"
},
{
"name": "_from",
"type": "address"
},
{
"name": "_tokenId",
"type": "uint256"
},
{
"name": "_data",
"type": "bytes"
}
],
"name": "onERC721Received",
"outputs": [
{
"name": "",
"type": "bytes4"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "operator",
"type": "address"
},
{
"indexed": false,
"name": "from",
"type": "address"
},
{
"indexed": false,
"name": "tokenId",
"type": "uint256"
},
{
"indexed": false,
"name": "data",
"type": "bytes"
}
],
"name": "TokenReceived",
"type": "event"
}
],
"evm": {
"bytecode": {
"linkReferences": {},
"object": "0x608060405234801561001057600080fd5b50610210806100206000396000f3006080604052600436106100405763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663150b7a028114610045575b600080fd5b34801561005157600080fd5b5061008b73ffffffffffffffffffffffffffffffffffffffff600480358216916024803590911691604435916064359081019101356100c0565b604080517fffffffff000000000000000000000000000000000000000000000000000000009092168252519081900360200190f35b60007f5343d39c46825e39cfee854256354ed1b3837af99997a3242ae29e831889773c8686868686604051808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200184815260200180602001828103825284848281815260200192508082843760405192018290039850909650505050505050a150604080517f6f6e455243373231526563656976656428616464726573732c6164647265737381527f2c75696e743235362c62797465732900000000000000000000000000000000006020820152905190819003602f019020959450505050505600a165627a7a723058207ca4491714f16a9054a23361cd9c97f51cc5a7f063295d68504143f2074901720029",
"opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH2 0x210 DUP1 PUSH2 0x20 PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN STOP PUSH1 0x80 PUSH1 0x40 MSTORE PUSH1 0x4 CALLDATASIZE LT PUSH2 0x40 JUMPI PUSH4 0xFFFFFFFF PUSH29 0x100000000000000000000000000000000000000000000000000000000 PUSH1 0x0 CALLDATALOAD DIV AND PUSH4 0x150B7A02 DUP2 EQ PUSH2 0x45 JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST CALLVALUE DUP1 ISZERO PUSH2 0x51 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH2 0x8B PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF PUSH1 0x4 DUP1 CALLDATALOAD DUP3 AND SWAP2 PUSH1 0x24 DUP1 CALLDATALOAD SWAP1 SWAP2 AND SWAP2 PUSH1 0x44 CALLDATALOAD SWAP2 PUSH1 0x64 CALLDATALOAD SWAP1 DUP2 ADD SWAP2 ADD CALLDATALOAD PUSH2 0xC0 JUMP JUMPDEST PUSH1 0x40 DUP1 MLOAD PUSH32 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000 SWAP1 SWAP3 AND DUP3 MSTORE MLOAD SWAP1 DUP2 SWAP1 SUB PUSH1 0x20 ADD SWAP1 RETURN JUMPDEST PUSH1 0x0 PUSH32 0x5343D39C46825E39CFEE854256354ED1B3837AF99997A3242AE29E831889773C DUP7 DUP7 DUP7 DUP7 DUP7 PUSH1 0x40 MLOAD DUP1 DUP7 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP2 MSTORE PUSH1 0x20 ADD DUP6 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP2 MSTORE PUSH1 0x20 ADD DUP5 DUP2 MSTORE PUSH1 0x20 ADD DUP1 PUSH1 0x20 ADD DUP3 DUP2 SUB DUP3 MSTORE DUP5 DUP5 DUP3 DUP2 DUP2 MSTORE PUSH1 0x20 ADD SWAP3 POP DUP1 DUP3 DUP5 CALLDATACOPY PUSH1 0x40 MLOAD SWAP3 ADD DUP3 SWAP1 SUB SWAP9 POP SWAP1 SWAP7 POP POP POP POP POP POP POP LOG1 POP PUSH1 0x40 DUP1 MLOAD PUSH32 0x6F6E455243373231526563656976656428616464726573732C61646472657373 DUP2 MSTORE PUSH32 0x2C75696E743235362C6279746573290000000000000000000000000000000000 PUSH1 0x20 DUP3 ADD MSTORE SWAP1 MLOAD SWAP1 DUP2 SWAP1 SUB PUSH1 0x2F ADD SWAP1 KECCAK256 SWAP6 SWAP5 POP POP POP POP POP JUMP STOP LOG1 PUSH6 0x627A7A723058 KECCAK256 PUSH29 0xA4491714F16A9054A23361CD9C97F51CC5A7F063295D68504143F20749 ADD PUSH19 0x290000000000000000000000000000000000 ",
"sourceMap": "662:1506:0:-;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;662:1506:0;;;;;;;"
},
"deployedBytecode": {
"linkReferences": {},
"object": "0x6080604052600436106100405763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663150b7a028114610045575b600080fd5b34801561005157600080fd5b5061008b73ffffffffffffffffffffffffffffffffffffffff600480358216916024803590911691604435916064359081019101356100c0565b604080517fffffffff000000000000000000000000000000000000000000000000000000009092168252519081900360200190f35b60007f5343d39c46825e39cfee854256354ed1b3837af99997a3242ae29e831889773c8686868686604051808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200184815260200180602001828103825284848281815260200192508082843760405192018290039850909650505050505050a150604080517f6f6e455243373231526563656976656428616464726573732c6164647265737381527f2c75696e743235362c62797465732900000000000000000000000000000000006020820152905190819003602f019020959450505050505600a165627a7a723058207ca4491714f16a9054a23361cd9c97f51cc5a7f063295d68504143f2074901720029",
"opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE PUSH1 0x4 CALLDATASIZE LT PUSH2 0x40 JUMPI PUSH4 0xFFFFFFFF PUSH29 0x100000000000000000000000000000000000000000000000000000000 PUSH1 0x0 CALLDATALOAD DIV AND PUSH4 0x150B7A02 DUP2 EQ PUSH2 0x45 JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST CALLVALUE DUP1 ISZERO PUSH2 0x51 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH2 0x8B PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF PUSH1 0x4 DUP1 CALLDATALOAD DUP3 AND SWAP2 PUSH1 0x24 DUP1 CALLDATALOAD SWAP1 SWAP2 AND SWAP2 PUSH1 0x44 CALLDATALOAD SWAP2 PUSH1 0x64 CALLDATALOAD SWAP1 DUP2 ADD SWAP2 ADD CALLDATALOAD PUSH2 0xC0 JUMP JUMPDEST PUSH1 0x40 DUP1 MLOAD PUSH32 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000 SWAP1 SWAP3 AND DUP3 MSTORE MLOAD SWAP1 DUP2 SWAP1 SUB PUSH1 0x20 ADD SWAP1 RETURN JUMPDEST PUSH1 0x0 PUSH32 0x5343D39C46825E39CFEE854256354ED1B3837AF99997A3242AE29E831889773C DUP7 DUP7 DUP7 DUP7 DUP7 PUSH1 0x40 MLOAD DUP1 DUP7 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP2 MSTORE PUSH1 0x20 ADD DUP6 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP2 MSTORE PUSH1 0x20 ADD DUP5 DUP2 MSTORE PUSH1 0x20 ADD DUP1 PUSH1 0x20 ADD DUP3 DUP2 SUB DUP3 MSTORE DUP5 DUP5 DUP3 DUP2 DUP2 MSTORE PUSH1 0x20 ADD SWAP3 POP DUP1 DUP3 DUP5 CALLDATACOPY PUSH1 0x40 MLOAD SWAP3 ADD DUP3 SWAP1 SUB SWAP9 POP SWAP1 SWAP7 POP POP POP POP POP POP POP LOG1 POP PUSH1 0x40 DUP1 MLOAD PUSH32 0x6F6E455243373231526563656976656428616464726573732C61646472657373 DUP2 MSTORE PUSH32 0x2C75696E743235362C6279746573290000000000000000000000000000000000 PUSH1 0x20 DUP3 ADD MSTORE SWAP1 MLOAD SWAP1 DUP2 SWAP1 SUB PUSH1 0x2F ADD SWAP1 KECCAK256 SWAP6 SWAP5 POP POP POP POP POP JUMP STOP LOG1 PUSH6 0x627A7A723058 KECCAK256 PUSH29 0xA4491714F16A9054A23361CD9C97F51CC5A7F063295D68504143F20749 ADD PUSH19 0x290000000000000000000000000000000000 ",
"sourceMap": "662:1506:0:-;;;;;;;;;;;;;;;;;;;;;;;1831:335;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;1831:335:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1994:6;2021:106;2048:9;2071:5;2090:8;2112:5;;2021:106;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;2021:106:0;;-1:-1:-1;;;;;;;2021:106:0;-1:-1:-1;850:60:0;;;;;;;;;;;;;;;;;;;;;1831:335;;;;;;;:::o"
}
}
},
"sources": {
"2.0.0/test/DummyERC721Receiver/DummyERC721Receiver.sol": {
"id": 0
},
"2.0.0/tokens/ERC721Token/IERC721Receiver.sol": {
"id": 1
}
},
"sourceCodes": {
"2.0.0/test/DummyERC721Receiver/DummyERC721Receiver.sol": "/*\n\n Copyright 2018 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity 0.4.24;\n\nimport \"../../tokens/ERC721Token/IERC721Receiver.sol\";\n\n\ncontract DummyERC721Receiver is\n IERC721Receiver\n{\n\n // Function selector for ERC721Receiver.onERC721Received\n // 0x150b7a02\n bytes4 constant internal ERC721_RECEIVED = bytes4(keccak256(\"onERC721Received(address,address,uint256,bytes)\"));\n\n event TokenReceived(\n address operator,\n address from,\n uint256 tokenId,\n bytes data\n );\n\n /// @notice Handle the receipt of an NFT\n /// @dev The ERC721 smart contract calls this function on the recipient\n /// after a `transfer`. This function MAY throw to revert and reject the\n /// transfer. Return of other than the magic value MUST result in the\n /// transaction being reverted.\n /// Note: the contract address is always the message sender.\n /// @param _operator The address which called `safeTransferFrom` function\n /// @param _from The address which previously owned the token\n /// @param _tokenId The NFT identifier which is being transferred\n /// @param _data Additional data with no specified format\n /// @return `bytes4(keccak256(\"onERC721Received(address,address,uint256,bytes)\"))`\n /// unless throwing\n function onERC721Received(\n address _operator,\n address _from,\n uint256 _tokenId,\n bytes _data\n )\n external\n returns (bytes4)\n {\n emit TokenReceived(\n _operator,\n _from,\n _tokenId,\n _data\n );\n return ERC721_RECEIVED;\n }\n}\n",
"2.0.0/tokens/ERC721Token/IERC721Receiver.sol": "/*\n\n Copyright 2018 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity 0.4.24;\n\n\ncontract IERC721Receiver {\n\n /// @notice Handle the receipt of an NFT\n /// @dev The ERC721 smart contract calls this function on the recipient\n /// after a `transfer`. This function MAY throw to revert and reject the\n /// transfer. Return of other than the magic value MUST result in the\n /// transaction being reverted.\n /// Note: the contract address is always the message sender.\n /// @param _operator The address which called `safeTransferFrom` function\n /// @param _from The address which previously owned the token\n /// @param _tokenId The NFT identifier which is being transferred\n /// @param _data Additional data with no specified format\n /// @return `bytes4(keccak256(\"onERC721Received(address,address,uint256,bytes)\"))`\n /// unless throwing\n function onERC721Received(\n address _operator,\n address _from,\n uint256 _tokenId,\n bytes _data\n )\n external\n returns (bytes4);\n}\n"
},
"sourceTreeHashHex": "0x8dcf5c0923a19bf4d5a85f5cf078ea02068ebfc6f8a10da115e3fb43f31ed63a",
"compiler": {
"name": "solc",
"version": "soljson-v0.4.24+commit.e67f0147.js",
"settings": {
"optimizer": {
"enabled": true,
"runs": 1000000
},
"outputSelection": {
"*": {
"*": [
"abi",
"evm.bytecode.object",
"evm.bytecode.sourceMap",
"evm.deployedBytecode.object",
"evm.deployedBytecode.sourceMap"
]
}
}
}
},
"networks": {}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,115 @@
{
"schemaVersion": "2.0.0",
"contractName": "InvalidERC721Receiver",
"compilerOutput": {
"abi": [
{
"constant": false,
"inputs": [
{
"name": "_operator",
"type": "address"
},
{
"name": "_from",
"type": "address"
},
{
"name": "_tokenId",
"type": "uint256"
},
{
"name": "_data",
"type": "bytes"
}
],
"name": "onERC721Received",
"outputs": [
{
"name": "",
"type": "bytes4"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "operator",
"type": "address"
},
{
"indexed": false,
"name": "from",
"type": "address"
},
{
"indexed": false,
"name": "tokenId",
"type": "uint256"
},
{
"indexed": false,
"name": "data",
"type": "bytes"
}
],
"name": "TokenReceived",
"type": "event"
}
],
"evm": {
"bytecode": {
"linkReferences": {},
"object": "0x608060405234801561001057600080fd5b50610210806100206000396000f3006080604052600436106100405763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663150b7a028114610045575b600080fd5b34801561005157600080fd5b5061008b73ffffffffffffffffffffffffffffffffffffffff600480358216916024803590911691604435916064359081019101356100c0565b604080517fffffffff000000000000000000000000000000000000000000000000000000009092168252519081900360200190f35b60007f5343d39c46825e39cfee854256354ed1b3837af99997a3242ae29e831889773c8686868686604051808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200184815260200180602001828103825284848281815260200192508082843760405192018290039850909650505050505050a150604080517f6f6e455243373231526563656976656428616464726573732c75696e7432353681527f2c6279746573290000000000000000000000000000000000000000000000000060208201529051908190036027019020959450505050505600a165627a7a72305820dcb87ae64bea36d7caea00c4565abd3c2e526326d0283600c9629eafd0d223620029",
"opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH2 0x210 DUP1 PUSH2 0x20 PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN STOP PUSH1 0x80 PUSH1 0x40 MSTORE PUSH1 0x4 CALLDATASIZE LT PUSH2 0x40 JUMPI PUSH4 0xFFFFFFFF PUSH29 0x100000000000000000000000000000000000000000000000000000000 PUSH1 0x0 CALLDATALOAD DIV AND PUSH4 0x150B7A02 DUP2 EQ PUSH2 0x45 JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST CALLVALUE DUP1 ISZERO PUSH2 0x51 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH2 0x8B PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF PUSH1 0x4 DUP1 CALLDATALOAD DUP3 AND SWAP2 PUSH1 0x24 DUP1 CALLDATALOAD SWAP1 SWAP2 AND SWAP2 PUSH1 0x44 CALLDATALOAD SWAP2 PUSH1 0x64 CALLDATALOAD SWAP1 DUP2 ADD SWAP2 ADD CALLDATALOAD PUSH2 0xC0 JUMP JUMPDEST PUSH1 0x40 DUP1 MLOAD PUSH32 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000 SWAP1 SWAP3 AND DUP3 MSTORE MLOAD SWAP1 DUP2 SWAP1 SUB PUSH1 0x20 ADD SWAP1 RETURN JUMPDEST PUSH1 0x0 PUSH32 0x5343D39C46825E39CFEE854256354ED1B3837AF99997A3242AE29E831889773C DUP7 DUP7 DUP7 DUP7 DUP7 PUSH1 0x40 MLOAD DUP1 DUP7 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP2 MSTORE PUSH1 0x20 ADD DUP6 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP2 MSTORE PUSH1 0x20 ADD DUP5 DUP2 MSTORE PUSH1 0x20 ADD DUP1 PUSH1 0x20 ADD DUP3 DUP2 SUB DUP3 MSTORE DUP5 DUP5 DUP3 DUP2 DUP2 MSTORE PUSH1 0x20 ADD SWAP3 POP DUP1 DUP3 DUP5 CALLDATACOPY PUSH1 0x40 MLOAD SWAP3 ADD DUP3 SWAP1 SUB SWAP9 POP SWAP1 SWAP7 POP POP POP POP POP POP POP LOG1 POP PUSH1 0x40 DUP1 MLOAD PUSH32 0x6F6E455243373231526563656976656428616464726573732C75696E74323536 DUP2 MSTORE PUSH32 0x2C62797465732900000000000000000000000000000000000000000000000000 PUSH1 0x20 DUP3 ADD MSTORE SWAP1 MLOAD SWAP1 DUP2 SWAP1 SUB PUSH1 0x27 ADD SWAP1 KECCAK256 SWAP6 SWAP5 POP POP POP POP POP JUMP STOP LOG1 PUSH6 0x627A7A723058 KECCAK256 0xdc 0xb8 PUSH27 0xE64BEA36D7CAEA00C4565ABD3C2E526326D0283600C9629EAFD0D2 0x23 PUSH3 0x2900 ",
"sourceMap": "662:1522:0:-;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;662:1522:0;;;;;;;"
},
"deployedBytecode": {
"linkReferences": {},
"object": "0x6080604052600436106100405763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663150b7a028114610045575b600080fd5b34801561005157600080fd5b5061008b73ffffffffffffffffffffffffffffffffffffffff600480358216916024803590911691604435916064359081019101356100c0565b604080517fffffffff000000000000000000000000000000000000000000000000000000009092168252519081900360200190f35b60007f5343d39c46825e39cfee854256354ed1b3837af99997a3242ae29e831889773c8686868686604051808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200184815260200180602001828103825284848281815260200192508082843760405192018290039850909650505050505050a150604080517f6f6e455243373231526563656976656428616464726573732c75696e7432353681527f2c6279746573290000000000000000000000000000000000000000000000000060208201529051908190036027019020959450505050505600a165627a7a72305820dcb87ae64bea36d7caea00c4565abd3c2e526326d0283600c9629eafd0d223620029",
"opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE PUSH1 0x4 CALLDATASIZE LT PUSH2 0x40 JUMPI PUSH4 0xFFFFFFFF PUSH29 0x100000000000000000000000000000000000000000000000000000000 PUSH1 0x0 CALLDATALOAD DIV AND PUSH4 0x150B7A02 DUP2 EQ PUSH2 0x45 JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST CALLVALUE DUP1 ISZERO PUSH2 0x51 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH2 0x8B PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF PUSH1 0x4 DUP1 CALLDATALOAD DUP3 AND SWAP2 PUSH1 0x24 DUP1 CALLDATALOAD SWAP1 SWAP2 AND SWAP2 PUSH1 0x44 CALLDATALOAD SWAP2 PUSH1 0x64 CALLDATALOAD SWAP1 DUP2 ADD SWAP2 ADD CALLDATALOAD PUSH2 0xC0 JUMP JUMPDEST PUSH1 0x40 DUP1 MLOAD PUSH32 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000 SWAP1 SWAP3 AND DUP3 MSTORE MLOAD SWAP1 DUP2 SWAP1 SUB PUSH1 0x20 ADD SWAP1 RETURN JUMPDEST PUSH1 0x0 PUSH32 0x5343D39C46825E39CFEE854256354ED1B3837AF99997A3242AE29E831889773C DUP7 DUP7 DUP7 DUP7 DUP7 PUSH1 0x40 MLOAD DUP1 DUP7 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP2 MSTORE PUSH1 0x20 ADD DUP6 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP2 MSTORE PUSH1 0x20 ADD DUP5 DUP2 MSTORE PUSH1 0x20 ADD DUP1 PUSH1 0x20 ADD DUP3 DUP2 SUB DUP3 MSTORE DUP5 DUP5 DUP3 DUP2 DUP2 MSTORE PUSH1 0x20 ADD SWAP3 POP DUP1 DUP3 DUP5 CALLDATACOPY PUSH1 0x40 MLOAD SWAP3 ADD DUP3 SWAP1 SUB SWAP9 POP SWAP1 SWAP7 POP POP POP POP POP POP POP LOG1 POP PUSH1 0x40 DUP1 MLOAD PUSH32 0x6F6E455243373231526563656976656428616464726573732C75696E74323536 DUP2 MSTORE PUSH32 0x2C62797465732900000000000000000000000000000000000000000000000000 PUSH1 0x20 DUP3 ADD MSTORE SWAP1 MLOAD SWAP1 DUP2 SWAP1 SUB PUSH1 0x27 ADD SWAP1 KECCAK256 SWAP6 SWAP5 POP POP POP POP POP JUMP STOP LOG1 PUSH6 0x627A7A723058 KECCAK256 0xdc 0xb8 PUSH27 0xE64BEA36D7CAEA00C4565ABD3C2E526326D0283600C9629EAFD0D2 0x23 PUSH3 0x2900 ",
"sourceMap": "662:1522:0:-;;;;;;;;;;;;;;;;;;;;;;;1839:343;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;1839:343:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2002:6;2029:106;2056:9;2079:5;2098:8;2120:5;;2029:106;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;2029:106:0;;-1:-1:-1;;;;;;;2029:106:0;-1:-1:-1;866:52:0;;;;;;;;;;;;;;;;;;;;;1839:343;;;;;;;:::o"
}
}
},
"sources": {
"2.0.0/test/DummyERC721Receiver/InvalidERC721Receiver.sol": {
"id": 0
},
"2.0.0/tokens/ERC721Token/IERC721Receiver.sol": {
"id": 1
}
},
"sourceCodes": {
"2.0.0/test/DummyERC721Receiver/InvalidERC721Receiver.sol": "/*\n\n Copyright 2018 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity 0.4.24;\n\nimport \"../../tokens/ERC721Token/IERC721Receiver.sol\";\n\n\ncontract InvalidERC721Receiver is\n IERC721Receiver\n{\n // Actual function signature is `onERC721Received(address,address,uint256,bytes)`\n bytes4 constant internal INVALID_ERC721_RECEIVED = bytes4(keccak256(\"onERC721Received(address,uint256,bytes)\"));\n\n event TokenReceived(\n address operator,\n address from,\n uint256 tokenId,\n bytes data\n );\n\n /// @notice Handle the receipt of an NFT\n /// @dev The ERC721 smart contract calls this function on the recipient\n /// after a `transfer`. This function MAY throw to revert and reject the\n /// transfer. Return of other than the magic value MUST result in the\n /// transaction being reverted.\n /// Note: the contract address is always the message sender.\n /// @param _operator The address which called `safeTransferFrom` function\n /// @param _from The address which previously owned the token\n /// @param _tokenId The NFT identifier which is being transferred\n /// @param _data Additional data with no specified format\n /// @return `bytes4(keccak256(\"onERC721Received(address,address,uint256,bytes)\"))`\n /// unless throwing\n function onERC721Received(\n address _operator,\n address _from,\n uint256 _tokenId,\n bytes _data\n )\n external\n returns (bytes4)\n {\n emit TokenReceived(\n _operator,\n _from,\n _tokenId,\n _data\n );\n return INVALID_ERC721_RECEIVED;\n }\n}\n",
"2.0.0/tokens/ERC721Token/IERC721Receiver.sol": "/*\n\n Copyright 2018 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity 0.4.24;\n\n\ncontract IERC721Receiver {\n\n /// @notice Handle the receipt of an NFT\n /// @dev The ERC721 smart contract calls this function on the recipient\n /// after a `transfer`. This function MAY throw to revert and reject the\n /// transfer. Return of other than the magic value MUST result in the\n /// transaction being reverted.\n /// Note: the contract address is always the message sender.\n /// @param _operator The address which called `safeTransferFrom` function\n /// @param _from The address which previously owned the token\n /// @param _tokenId The NFT identifier which is being transferred\n /// @param _data Additional data with no specified format\n /// @return `bytes4(keccak256(\"onERC721Received(address,address,uint256,bytes)\"))`\n /// unless throwing\n function onERC721Received(\n address _operator,\n address _from,\n uint256 _tokenId,\n bytes _data\n )\n external\n returns (bytes4);\n}\n"
},
"sourceTreeHashHex": "0xa1e9bac07367f1d9394aa63c5e739d5abdde20c17d09a223e4f5635bf45ec2a4",
"compiler": {
"name": "solc",
"version": "soljson-v0.4.24+commit.e67f0147.js",
"settings": {
"optimizer": {
"enabled": true,
"runs": 1000000
},
"outputSelection": {
"*": {
"*": [
"abi",
"evm.bytecode.object",
"evm.bytecode.sourceMap",
"evm.deployedBytecode.object",
"evm.deployedBytecode.sourceMap"
]
}
}
}
},
"networks": {}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,106 +0,0 @@
{
"schemaVersion": "2.0.0",
"contractName": "DummyERC721Receiver",
"compilerOutput": {
"abi": [
{
"constant": false,
"inputs": [
{
"name": "_from",
"type": "address"
},
{
"name": "_tokenId",
"type": "uint256"
},
{
"name": "_data",
"type": "bytes"
}
],
"name": "onERC721Received",
"outputs": [
{
"name": "",
"type": "bytes4"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "from",
"type": "address"
},
{
"indexed": false,
"name": "tokenId",
"type": "uint256"
},
{
"indexed": false,
"name": "data",
"type": "bytes"
}
],
"name": "TokenReceived",
"type": "event"
}
],
"evm": {
"bytecode": {
"linkReferences": {},
"object": "0x608060405234801561001057600080fd5b5061021c806100206000396000f3006080604052600436106100405763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663f0b9e5ba8114610045575b600080fd5b34801561005157600080fd5b50604080516020600460443581810135601f81018490048402850184019095528484526100bb94823573ffffffffffffffffffffffffffffffffffffffff169460248035953695946064949201919081908401838280828437509497506100f09650505050505050565b604080517fffffffff000000000000000000000000000000000000000000000000000000009092168252519081900360200190f35b60007fefe605af9663e0f15f1dd40dad79f119df71e8d2affb3f6857cb9707c6c4b3ea848484604051808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561018b578181015183820152602001610173565b50505050905090810190601f1680156101b85780820380516001836020036101000a031916815260200191505b5094505050505060405180910390a1507ff0b9e5ba0000000000000000000000000000000000000000000000000000000093925050505600a165627a7a72305820b21a4617d1f81829262138f613de82764dda60f47f5027b3b68c016997529b8b0029",
"opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH2 0x21C DUP1 PUSH2 0x20 PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN STOP PUSH1 0x80 PUSH1 0x40 MSTORE PUSH1 0x4 CALLDATASIZE LT PUSH2 0x40 JUMPI PUSH4 0xFFFFFFFF PUSH29 0x100000000000000000000000000000000000000000000000000000000 PUSH1 0x0 CALLDATALOAD DIV AND PUSH4 0xF0B9E5BA DUP2 EQ PUSH2 0x45 JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST CALLVALUE DUP1 ISZERO PUSH2 0x51 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x40 DUP1 MLOAD PUSH1 0x20 PUSH1 0x4 PUSH1 0x44 CALLDATALOAD DUP2 DUP2 ADD CALLDATALOAD PUSH1 0x1F DUP2 ADD DUP5 SWAP1 DIV DUP5 MUL DUP6 ADD DUP5 ADD SWAP1 SWAP6 MSTORE DUP5 DUP5 MSTORE PUSH2 0xBB SWAP5 DUP3 CALLDATALOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND SWAP5 PUSH1 0x24 DUP1 CALLDATALOAD SWAP6 CALLDATASIZE SWAP6 SWAP5 PUSH1 0x64 SWAP5 SWAP3 ADD SWAP2 SWAP1 DUP2 SWAP1 DUP5 ADD DUP4 DUP3 DUP1 DUP3 DUP5 CALLDATACOPY POP SWAP5 SWAP8 POP PUSH2 0xF0 SWAP7 POP POP POP POP POP POP POP JUMP JUMPDEST PUSH1 0x40 DUP1 MLOAD PUSH32 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000 SWAP1 SWAP3 AND DUP3 MSTORE MLOAD SWAP1 DUP2 SWAP1 SUB PUSH1 0x20 ADD SWAP1 RETURN JUMPDEST PUSH1 0x0 PUSH32 0xEFE605AF9663E0F15F1DD40DAD79F119DF71E8D2AFFB3F6857CB9707C6C4B3EA DUP5 DUP5 DUP5 PUSH1 0x40 MLOAD DUP1 DUP5 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP2 MSTORE PUSH1 0x20 ADD DUP4 DUP2 MSTORE PUSH1 0x20 ADD DUP1 PUSH1 0x20 ADD DUP3 DUP2 SUB DUP3 MSTORE DUP4 DUP2 DUP2 MLOAD DUP2 MSTORE PUSH1 0x20 ADD SWAP2 POP DUP1 MLOAD SWAP1 PUSH1 0x20 ADD SWAP1 DUP1 DUP4 DUP4 PUSH1 0x0 JUMPDEST DUP4 DUP2 LT ISZERO PUSH2 0x18B JUMPI DUP2 DUP2 ADD MLOAD DUP4 DUP3 ADD MSTORE PUSH1 0x20 ADD PUSH2 0x173 JUMP JUMPDEST POP POP POP POP SWAP1 POP SWAP1 DUP2 ADD SWAP1 PUSH1 0x1F AND DUP1 ISZERO PUSH2 0x1B8 JUMPI DUP1 DUP3 SUB DUP1 MLOAD PUSH1 0x1 DUP4 PUSH1 0x20 SUB PUSH2 0x100 EXP SUB NOT AND DUP2 MSTORE PUSH1 0x20 ADD SWAP2 POP JUMPDEST POP SWAP5 POP POP POP POP POP PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 LOG1 POP PUSH32 0xF0B9E5BA00000000000000000000000000000000000000000000000000000000 SWAP4 SWAP3 POP POP POP JUMP STOP LOG1 PUSH6 0x627A7A723058 KECCAK256 0xb2 BYTE 0x46 OR 0xd1 0xf8 XOR 0x29 0x26 0x21 CODESIZE 0xf6 SGT 0xde DUP3 PUSH23 0x4DDA60F47F5027B3B68C016997529B8B00290000000000 ",
"sourceMap": "1186:1067:0:-;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;1186:1067:0;;;;;;;"
},
"deployedBytecode": {
"linkReferences": {},
"object": "0x6080604052600436106100405763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663f0b9e5ba8114610045575b600080fd5b34801561005157600080fd5b50604080516020600460443581810135601f81018490048402850184019095528484526100bb94823573ffffffffffffffffffffffffffffffffffffffff169460248035953695946064949201919081908401838280828437509497506100f09650505050505050565b604080517fffffffff000000000000000000000000000000000000000000000000000000009092168252519081900360200190f35b60007fefe605af9663e0f15f1dd40dad79f119df71e8d2affb3f6857cb9707c6c4b3ea848484604051808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561018b578181015183820152602001610173565b50505050905090810190601f1680156101b85780820380516001836020036101000a031916815260200191505b5094505050505060405180910390a1507ff0b9e5ba0000000000000000000000000000000000000000000000000000000093925050505600a165627a7a72305820b21a4617d1f81829262138f613de82764dda60f47f5027b3b68c016997529b8b0029",
"opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE PUSH1 0x4 CALLDATASIZE LT PUSH2 0x40 JUMPI PUSH4 0xFFFFFFFF PUSH29 0x100000000000000000000000000000000000000000000000000000000 PUSH1 0x0 CALLDATALOAD DIV AND PUSH4 0xF0B9E5BA DUP2 EQ PUSH2 0x45 JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST CALLVALUE DUP1 ISZERO PUSH2 0x51 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x40 DUP1 MLOAD PUSH1 0x20 PUSH1 0x4 PUSH1 0x44 CALLDATALOAD DUP2 DUP2 ADD CALLDATALOAD PUSH1 0x1F DUP2 ADD DUP5 SWAP1 DIV DUP5 MUL DUP6 ADD DUP5 ADD SWAP1 SWAP6 MSTORE DUP5 DUP5 MSTORE PUSH2 0xBB SWAP5 DUP3 CALLDATALOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND SWAP5 PUSH1 0x24 DUP1 CALLDATALOAD SWAP6 CALLDATASIZE SWAP6 SWAP5 PUSH1 0x64 SWAP5 SWAP3 ADD SWAP2 SWAP1 DUP2 SWAP1 DUP5 ADD DUP4 DUP3 DUP1 DUP3 DUP5 CALLDATACOPY POP SWAP5 SWAP8 POP PUSH2 0xF0 SWAP7 POP POP POP POP POP POP POP JUMP JUMPDEST PUSH1 0x40 DUP1 MLOAD PUSH32 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000 SWAP1 SWAP3 AND DUP3 MSTORE MLOAD SWAP1 DUP2 SWAP1 SUB PUSH1 0x20 ADD SWAP1 RETURN JUMPDEST PUSH1 0x0 PUSH32 0xEFE605AF9663E0F15F1DD40DAD79F119DF71E8D2AFFB3F6857CB9707C6C4B3EA DUP5 DUP5 DUP5 PUSH1 0x40 MLOAD DUP1 DUP5 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP2 MSTORE PUSH1 0x20 ADD DUP4 DUP2 MSTORE PUSH1 0x20 ADD DUP1 PUSH1 0x20 ADD DUP3 DUP2 SUB DUP3 MSTORE DUP4 DUP2 DUP2 MLOAD DUP2 MSTORE PUSH1 0x20 ADD SWAP2 POP DUP1 MLOAD SWAP1 PUSH1 0x20 ADD SWAP1 DUP1 DUP4 DUP4 PUSH1 0x0 JUMPDEST DUP4 DUP2 LT ISZERO PUSH2 0x18B JUMPI DUP2 DUP2 ADD MLOAD DUP4 DUP3 ADD MSTORE PUSH1 0x20 ADD PUSH2 0x173 JUMP JUMPDEST POP POP POP POP SWAP1 POP SWAP1 DUP2 ADD SWAP1 PUSH1 0x1F AND DUP1 ISZERO PUSH2 0x1B8 JUMPI DUP1 DUP3 SUB DUP1 MLOAD PUSH1 0x1 DUP4 PUSH1 0x20 SUB PUSH2 0x100 EXP SUB NOT AND DUP2 MSTORE PUSH1 0x20 ADD SWAP2 POP JUMPDEST POP SWAP5 POP POP POP POP POP PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 LOG1 POP PUSH32 0xF0B9E5BA00000000000000000000000000000000000000000000000000000000 SWAP4 SWAP3 POP POP POP JUMP STOP LOG1 PUSH6 0x627A7A723058 KECCAK256 0xb2 BYTE 0x46 OR 0xd1 0xf8 XOR 0x29 0x26 0x21 CODESIZE 0xf6 SGT 0xde DUP3 PUSH23 0x4DDA60F47F5027B3B68C016997529B8B00290000000000 ",
"sourceMap": "1186:1067:0:-;;;;;;;;;;;;;;;;;;;;;;;2014:237;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;2014:237:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;2014:237:0;;-1:-1:-1;2014:237:0;;-1:-1:-1;;;;;;;2014:237:0;;;;;;;;;;;;;;;;;;;;;2148:6;2175:37;2189:5;2196:8;2206:5;2175:37;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;23:1:-1;8:100;33:3;30:1;27:10;8:100;;;90:11;;;84:18;71:11;;;64:39;52:2;45:10;8:100;;;12:14;2175:37:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;2229:15:0;2014:237;;;;;:::o"
}
}
},
"sources": {
"2.0.0/test/DummyERC721Receiver/DummyERC721Receiver.sol": {
"id": 0
},
"2.0.0/tokens/ERC721Token/IERC721Receiver.sol": {
"id": 1
}
},
"sourceCodes": {
"2.0.0/test/DummyERC721Receiver/DummyERC721Receiver.sol": "/*\nThe MIT License (MIT)\n\nCopyright (c) 2016 Smart Contract Solutions, Inc.\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be included\nin all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\nOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n*/\n\npragma solidity 0.4.24;\n\nimport \"../../tokens/ERC721Token/IERC721Receiver.sol\";\n\n\ncontract DummyERC721Receiver is\n IERC721Receiver\n{\n\n event TokenReceived(\n address from,\n uint256 tokenId,\n bytes data\n );\n\n /**\n * @notice Handle the receipt of an NFT\n * @dev The ERC721 smart contract calls this function on the recipient\n * after a `safetransfer`. This function MAY throw to revert and reject the\n * transfer. This function MUST use 50,000 gas or less. Return of other\n * than the magic value MUST result in the transaction being reverted.\n * Note: the contract address is always the message sender.\n * @param _from The sending address\n * @param _tokenId The NFT identifier which is being transfered\n * @param _data Additional data with no specified format\n * @return `bytes4(keccak256(\"onERC721Received(address,uint256,bytes)\"))`\n */\n function onERC721Received(\n address _from,\n uint256 _tokenId,\n bytes _data\n )\n public\n returns (bytes4)\n {\n emit TokenReceived(_from, _tokenId, _data);\n return ERC721_RECEIVED;\n }\n}\n",
"2.0.0/tokens/ERC721Token/IERC721Receiver.sol": "/*\nThe MIT License (MIT)\n\nCopyright (c) 2016 Smart Contract Solutions, Inc.\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be included\nin all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\nOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n*/\n\npragma solidity 0.4.24;\n\n\n/**\n * @title ERC721 token receiver interface\n * @dev Interface for any contract that wants to support safeTransfers\n * rom ERC721 asset contracts.\n * Modified from https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/token/ERC721/ERC721Receiver.sol\n */\ncontract IERC721Receiver {\n /**\n * @dev Magic value to be returned upon successful reception of an NFT\n * Equals to `bytes4(keccak256(\"onERC721Received(address,uint256,bytes)\"))`,\n * which can be also obtained as `ERC721Receiver(0).onERC721Received.selector`\n */\n bytes4 constant internal ERC721_RECEIVED = 0xf0b9e5ba;\n\n /**\n * @notice Handle the receipt of an NFT\n * @dev The ERC721 smart contract calls this function on the recipient\n * after a `safetransfer`. This function MAY throw to revert and reject the\n * transfer. This function MUST use 50,000 gas or less. Return of other\n * than the magic value MUST result in the transaction being reverted.\n * Note: the contract address is always the message sender.\n * @param _from The sending address\n * @param _tokenId The NFT identifier which is being transfered\n * @param _data Additional data with no specified format\n * @return `bytes4(keccak256(\"onERC721Received(address,uint256,bytes)\"))`\n */\n function onERC721Received(\n address _from,\n uint256 _tokenId,\n bytes _data)\n public\n returns (bytes4);\n}\n"
},
"sourceTreeHashHex": "0x8eb51bd09ddeb7decac329c3c85f31301af7822aa808b193752eaa94725657bd",
"compiler": {
"name": "solc",
"version": "soljson-v0.4.24+commit.e67f0147.js",
"settings": {
"optimizer": {
"enabled": true,
"runs": 1000000
},
"outputSelection": {
"*": {
"*": [
"abi",
"evm.bytecode.object",
"evm.bytecode.sourceMap",
"evm.deployedBytecode.object",
"evm.deployedBytecode.sourceMap"
]
}
}
}
},
"networks": {}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,80 +0,0 @@
{
"schemaVersion": "2.0.0",
"contractName": "IValidator",
"compilerOutput": {
"abi": [
{
"constant": true,
"inputs": [
{
"name": "hash",
"type": "bytes32"
},
{
"name": "signerAddress",
"type": "address"
},
{
"name": "signature",
"type": "bytes"
}
],
"name": "isValidSignature",
"outputs": [
{
"name": "isValid",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
],
"evm": {
"bytecode": {
"linkReferences": {},
"object": "0x",
"opcodes": "",
"sourceMap": ""
},
"deployedBytecode": {
"linkReferences": {},
"object": "0x",
"opcodes": "",
"sourceMap": ""
}
}
},
"sources": {
"2.0.0/protocol/Exchange/interfaces/IValidator.sol": {
"id": 0
}
},
"sourceCodes": {
"2.0.0/protocol/Exchange/interfaces/IValidator.sol": "/*\n\n Copyright 2018 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity 0.4.24;\n\n\ncontract IValidator {\n\n /// @dev Verifies that a signature is valid.\n /// @param hash Message hash that is signed.\n /// @param signerAddress Address that should have signed the given hash.\n /// @param signature Proof of signing.\n /// @return Validity of order signature.\n function isValidSignature(\n bytes32 hash,\n address signerAddress,\n bytes signature\n )\n external\n view\n returns (bool isValid);\n}\n"
},
"sourceTreeHashHex": "0x560b257f8a4e1420a4586d5ba0c40e74042ef5af0f53aad412951444ea710a7e",
"compiler": {
"name": "solc",
"version": "soljson-v0.4.24+commit.e67f0147.js",
"settings": {
"optimizer": {
"enabled": true,
"runs": 1000000
},
"outputSelection": {
"*": {
"*": [
"abi",
"evm.bytecode.object",
"evm.bytecode.sourceMap",
"evm.deployedBytecode.object",
"evm.deployedBytecode.sourceMap"
]
}
}
}
},
"networks": {}
}

View File

@ -1,76 +0,0 @@
{
"schemaVersion": "2.0.0",
"contractName": "IWallet",
"compilerOutput": {
"abi": [
{
"constant": true,
"inputs": [
{
"name": "hash",
"type": "bytes32"
},
{
"name": "signature",
"type": "bytes"
}
],
"name": "isValidSignature",
"outputs": [
{
"name": "isValid",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
],
"evm": {
"bytecode": {
"linkReferences": {},
"object": "0x",
"opcodes": "",
"sourceMap": ""
},
"deployedBytecode": {
"linkReferences": {},
"object": "0x",
"opcodes": "",
"sourceMap": ""
}
}
},
"sources": {
"2.0.0/protocol/Exchange/interfaces/IWallet.sol": {
"id": 0
}
},
"sourceCodes": {
"2.0.0/protocol/Exchange/interfaces/IWallet.sol": "/*\n\n Copyright 2018 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity 0.4.24;\n\n\ncontract IWallet {\n\n /// @dev Verifies that a signature is valid.\n /// @param hash Message hash that is signed.\n /// @param signature Proof of signing.\n /// @return Validity of order signature.\n function isValidSignature(\n bytes32 hash,\n bytes signature\n )\n external\n view\n returns (bool isValid);\n}\n"
},
"sourceTreeHashHex": "0x70b7d3c15ab87e6b4b1011d194282163232dfd88486038e4120d6bf245d58e44",
"compiler": {
"name": "solc",
"version": "soljson-v0.4.24+commit.e67f0147.js",
"settings": {
"optimizer": {
"enabled": true,
"runs": 1000000
},
"outputSelection": {
"*": {
"*": [
"abi",
"evm.bytecode.object",
"evm.bytecode.sourceMap",
"evm.deployedBytecode.object",
"evm.deployedBytecode.sourceMap"
]
}
}
}
},
"networks": {}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -10,29 +10,27 @@
"scripts": { "scripts": {
"watch_without_deps": "yarn pre_build && tsc -w", "watch_without_deps": "yarn pre_build && tsc -w",
"build": "yarn pre_build && tsc", "build": "yarn pre_build && tsc",
"pre_build": "run-s copy_artifacts generate_contract_wrappers", "pre_build": "run-s compile:v2 copy_artifacts generate_contract_wrappers",
"copy_artifacts": "copyfiles 'artifacts/**/*' ./lib", "copy_artifacts": "copyfiles 'artifacts/**/*' ./lib",
"clean": "shx rm -rf lib src/1.0.0/contract_wrappers src/2.0.0/contract_wrappers src/2.0.0-beta-testnet/contract_wrappers", "clean": "shx rm -rf lib src/1.0.0/contract_wrappers src/2.0.0/contract_wrappers src/2.0.0-beta-testnet/contract_wrappers artifacts/2.0.0",
"lint": "tslint --project . --exclude **/src/v2/contract_wrappers/**/* --exclude **/src/v1/contract_wrappers/**/*", "lint": "tslint --project . --exclude **/src/v2/contract_wrappers/**/* --exclude **/src/v1/contract_wrappers/**/*",
"migrate:v1": "run-s build compile:v1 script:migrate:v1", "migrate:v1": "run-s build compile:v1 script:migrate:v1",
"migrate:v2": "run-s build compile:v2 script:migrate:v2",
"migrate:v2-beta-testnet": "run-s build compile:v2-beta-testnet script:migrate:v2-beta-testnet", "migrate:v2-beta-testnet": "run-s build compile:v2-beta-testnet script:migrate:v2-beta-testnet",
"script:migrate:v1": "node ./lib/migrate.js --contracts-version 1.0.0", "script:migrate:v1": "node ./lib/migrate.js --contracts-version 1.0.0",
"script:migrate:v2": "node ./lib/migrate.js --contracts-version 2.0.0",
"script:migrate:v2-beta-testnet": "node ./lib/migrate.js --contracts-version 2.0.0-beta-testnet", "script:migrate:v2-beta-testnet": "node ./lib/migrate.js --contracts-version 2.0.0-beta-testnet",
"generate_contract_wrappers": "run-p generate_contract_wrappers:*", "generate_contract_wrappers": "run-p generate_contract_wrappers:*",
"generate_contract_wrappers:v1": "abi-gen --abis ${npm_package_config_abis_v1} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/1.0.0/contract_wrappers --backend ethers", "generate_contract_wrappers:v1": "abi-gen --abis ${npm_package_config_abis_v1} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/1.0.0/contract_wrappers --backend ethers",
"generate_contract_wrappers:v2": "abi-gen --abis ${npm_package_config_abis_v2} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/2.0.0/contract_wrappers --backend ethers", "generate_contract_wrappers:v2": "abi-gen --abis ${npm_package_config_abis_v2} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/2.0.0/contract_wrappers --backend ethers",
"generate_contract_wrappers:v2-beta-testnet": "abi-gen --abis ${npm_package_config_abis_v2BetaTestnet} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/2.0.0-beta-testnet/contract_wrappers --backend ethers", "generate_contract_wrappers:v2-beta-testnet": "abi-gen --abis ${npm_package_config_abis_v2BetaTestnet} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/2.0.0-beta-testnet/contract_wrappers --backend ethers",
"compile:v1": "sol-compiler --artifacts-dir artifacts/1.0.0 --contracts Exchange_v1,DummyERC20Token,ZRXToken,WETH9,TokenTransferProxy_v1,MultiSigWallet,MultiSigWalletWithTimeLock,MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,TokenRegistry", "compile:v1": "sol-compiler --artifacts-dir artifacts/1.0.0 --contracts Exchange_v1,DummyERC20Token,ZRXToken,WETH9,TokenTransferProxy_v1,MultiSigWallet,MultiSigWalletWithTimeLock,MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,TokenRegistry",
"compile:v2": "sol-compiler --artifacts-dir artifacts/2.0.0 --contracts ERC20Token,DummyERC20Token,ERC721Token,DummyERC721Token,ERC20Proxy,ERC721Proxy,Exchange,Forwarder,MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,ZRXToken,WETH9,IWallet,IValidator", "compile:v2": "sol-compiler --artifacts-dir artifacts/2.0.0 --contracts AssetProxyOwner,ERC20Token,DummyERC20Token,ERC721Token,DummyERC721Token,ERC20Proxy,ERC721Proxy,Exchange,Forwarder,MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,ZRXToken,WETH9,IWallet,IValidator,OrderValidator",
"compile:v2-beta-testnet": "sol-compiler --artifacts-dir artifacts/2.0.0-beta-testnet --contracts AssetProxyOwner,ERC20Proxy,ERC721Proxy,Exchange,Forwarder,IWallet,IValidator,ERC20Token,ERC721Token" "compile:v2-beta-testnet": "sol-compiler --artifacts-dir artifacts/2.0.0-beta-testnet --contracts AssetProxyOwner,DummyERC20Token,ERC20Proxy,ERC721Proxy,Exchange,Forwarder,IWallet,IValidator,ERC20Token,ERC721Token,OrderValidator"
}, },
"config": { "config": {
"abis": { "abis": {
"v1": "artifacts/1.0.0/@(DummyERC20Token|TokenTransferProxy_v1|Exchange_v1|TokenRegistry|MultiSigWallet|MultiSigWalletWithTimeLock|MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress|TokenRegistry|ZRXToken|WETH9).json", "v1": "artifacts/1.0.0/@(DummyERC20Token|TokenTransferProxy_v1|Exchange_v1|TokenRegistry|MultiSigWallet|MultiSigWalletWithTimeLock|MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress|TokenRegistry|ZRXToken|WETH9).json",
"v2": "artifacts/2.0.0/@(ERC20Token|DummyERC20Token|ERC721Token|DummyERC721Token|ERC20Proxy|ERC721Proxy|Exchange|Forwarder|AssetProxyOwner|ZRXToken|WETH9|IWallet|IValidator).json", "v2": "artifacts/2.0.0/@(ERC20Token|DummyERC20Token|ERC721Token|DummyERC721Token|ERC20Proxy|ERC721Proxy|Exchange|Forwarder|AssetProxyOwner|ZRXToken|WETH9|IWallet|IValidator|OrderValidator).json",
"v2BetaTestnet": "artifacts/2.0.0-beta-testnet/@(ERC20Token|ERC721Token|ERC20Proxy|ERC721Proxy|Exchange|Forwarder|AssetProxyOwner|IWallet|IValidator).json" "v2BetaTestnet": "artifacts/2.0.0-beta-testnet/@(ERC20Token|ERC721Token|ERC20Proxy|ERC721Proxy|Exchange|Forwarder|AssetProxyOwner|IWallet|IValidator|OrderValidator).json"
} }
}, },
"license": "Apache-2.0", "license": "Apache-2.0",

View File

@ -4,10 +4,12 @@ import * as AssetProxyOwner from '../../artifacts/2.0.0-beta-testnet/AssetProxyO
import * as ERC20Proxy from '../../artifacts/2.0.0-beta-testnet/ERC20Proxy.json'; import * as ERC20Proxy from '../../artifacts/2.0.0-beta-testnet/ERC20Proxy.json';
import * as ERC721Proxy from '../../artifacts/2.0.0-beta-testnet/ERC721Proxy.json'; import * as ERC721Proxy from '../../artifacts/2.0.0-beta-testnet/ERC721Proxy.json';
import * as Exchange from '../../artifacts/2.0.0-beta-testnet/Exchange.json'; import * as Exchange from '../../artifacts/2.0.0-beta-testnet/Exchange.json';
import * as OrderValidator from '../../artifacts/2.0.0-beta-testnet/OrderValidator.json';
export const artifacts = { export const artifacts = {
AssetProxyOwner: (AssetProxyOwner as any) as ContractArtifact, AssetProxyOwner: (AssetProxyOwner as any) as ContractArtifact,
Exchange: (Exchange as any) as ContractArtifact, Exchange: (Exchange as any) as ContractArtifact,
ERC20Proxy: (ERC20Proxy as any) as ContractArtifact, ERC20Proxy: (ERC20Proxy as any) as ContractArtifact,
ERC721Proxy: (ERC721Proxy as any) as ContractArtifact, ERC721Proxy: (ERC721Proxy as any) as ContractArtifact,
OrderValidator: (OrderValidator as any) as ContractArtifact,
}; };

View File

@ -12,6 +12,7 @@ import { AssetProxyOwnerContract } from './contract_wrappers/asset_proxy_owner';
import { ERC20ProxyContract } from './contract_wrappers/erc20_proxy'; import { ERC20ProxyContract } from './contract_wrappers/erc20_proxy';
import { ERC721ProxyContract } from './contract_wrappers/erc721_proxy'; import { ERC721ProxyContract } from './contract_wrappers/erc721_proxy';
import { ExchangeContract } from './contract_wrappers/exchange'; import { ExchangeContract } from './contract_wrappers/exchange';
import { OrderValidatorContract } from './contract_wrappers/order_validator';
/** /**
* Custom migrations should be defined in this function. This will be called with the CLI 'migrate:v2-beta-testnet' command. * Custom migrations should be defined in this function. This will be called with the CLI 'migrate:v2-beta-testnet' command.
@ -75,6 +76,16 @@ export const runV2TestnetMigrationsAsync = async (
); );
artifactsWriter.saveArtifact(assetProxyOwner); artifactsWriter.saveArtifact(assetProxyOwner);
// Deploy OrderValidator
const orderValidator = await OrderValidatorContract.deployFrom0xArtifactAsync(
artifacts.OrderValidator,
provider,
txDefaults,
exchange.address,
zrxAssetData,
);
artifactsWriter.saveArtifact(orderValidator);
// Authorize Exchange contracts to call AssetProxies // Authorize Exchange contracts to call AssetProxies
txHash = await erc20proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address); txHash = await erc20proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address);
logUtils.log(`transactionHash: ${txHash}`); logUtils.log(`transactionHash: ${txHash}`);

Some files were not shown because too many files have changed in this diff Show More