aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'packages/contracts/src/utils')
-rw-r--r--packages/contracts/src/utils/artifacts.ts8
-rw-r--r--packages/contracts/src/utils/asset_proxy_utils.ts66
-rw-r--r--packages/contracts/src/utils/balances.ts6
-rw-r--r--packages/contracts/src/utils/exchange_wrapper.ts62
-rw-r--r--packages/contracts/src/utils/formatters.ts16
-rw-r--r--packages/contracts/src/utils/order_utils.ts20
-rw-r--r--packages/contracts/src/utils/types.ts21
7 files changed, 96 insertions, 103 deletions
diff --git a/packages/contracts/src/utils/artifacts.ts b/packages/contracts/src/utils/artifacts.ts
index 87cc73cff..78ba1c142 100644
--- a/packages/contracts/src/utils/artifacts.ts
+++ b/packages/contracts/src/utils/artifacts.ts
@@ -1,9 +1,7 @@
-import * as DummyTokenArtifact from '../artifacts/DummyToken.json';
+import * as DummyERC20TokenArtifact from '../artifacts/DummyERC20Token.json';
import * as ExchangeArtifact from '../artifacts/Exchange.json';
-import * as MaliciousTokenArtifact from '../artifacts/MaliciousToken.json';
import * as MultiSigWalletWithTimeLockArtifact from '../artifacts/MultiSigWalletWithTimeLock.json';
import * as MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressArtifact from '../artifacts/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.json';
-import * as TokenArtifact from '../artifacts/Token.json';
import * as TokenRegistryArtifact from '../artifacts/TokenRegistry.json';
import * as EtherTokenArtifact from '../artifacts/WETH9.json';
import * as ZRXArtifact from '../artifacts/ZRXToken.json';
@@ -12,12 +10,10 @@ import { Artifact } from './types';
export const artifacts = {
ZRXArtifact: (ZRXArtifact as any) as Artifact,
- DummyTokenArtifact: (DummyTokenArtifact as any) as Artifact,
- TokenArtifact: (TokenArtifact as any) as Artifact,
+ DummyERC20TokenArtifact: (DummyERC20TokenArtifact as any) as Artifact,
ExchangeArtifact: (ExchangeArtifact as any) as Artifact,
EtherTokenArtifact: (EtherTokenArtifact as any) as Artifact,
TokenRegistryArtifact: (TokenRegistryArtifact as any) as Artifact,
- MaliciousTokenArtifact: (MaliciousTokenArtifact as any) as Artifact,
MultiSigWalletWithTimeLockArtifact: (MultiSigWalletWithTimeLockArtifact as any) as Artifact,
MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressArtifact: (MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressArtifact as any) as Artifact,
};
diff --git a/packages/contracts/src/utils/asset_proxy_utils.ts b/packages/contracts/src/utils/asset_proxy_utils.ts
index da610cbcc..1a7a312dd 100644
--- a/packages/contracts/src/utils/asset_proxy_utils.ts
+++ b/packages/contracts/src/utils/asset_proxy_utils.ts
@@ -4,37 +4,35 @@ import ethUtil = require('ethereumjs-util');
import { AssetProxyId } from './types';
-export function encodeAssetProxyId(assetProxyId: AssetProxyId): Buffer {
- return ethUtil.toBuffer(assetProxyId);
-}
-
-export function encodeAddress(address: string): Buffer {
- if (!ethUtil.isValidAddress(address)) {
- throw new Error(`Invalid Address: ${address}`);
- }
- const encodedAddress = ethUtil.toBuffer(address);
- return encodedAddress;
-}
-
-export function encodeUint256(value: BigNumber): Buffer {
- const formattedValue = new BN(value.toString(10));
- const encodedValue = ethUtil.toBuffer(formattedValue);
- return encodedValue;
-}
-
-export function encodeERC20ProxyData(tokenAddress: string): string {
- const encodedAssetProxyId = encodeAssetProxyId(AssetProxyId.ERC20);
- const encodedAddress = encodeAddress(tokenAddress);
- const encodedMetadata = Buffer.concat([encodedAssetProxyId, encodedAddress]);
- const encodedMetadataHex = ethUtil.bufferToHex(encodedMetadata);
- return encodedMetadataHex;
-}
-
-export function encodeERC721ProxyData(tokenAddress: string, tokenId: BigNumber): string {
- const encodedAssetProxyId = encodeAssetProxyId(AssetProxyId.ERC721);
- const encodedAddress = encodeAddress(tokenAddress);
- const encodedTokenId = encodeUint256(tokenId);
- const encodedMetadata = Buffer.concat([encodedAssetProxyId, encodedAddress, encodedTokenId]);
- const encodedMetadataHex = ethUtil.bufferToHex(encodedMetadata);
- return encodedMetadataHex;
-}
+export const assetProxyUtils = {
+ encodeAssetProxyId(assetProxyId: AssetProxyId): Buffer {
+ return ethUtil.toBuffer(assetProxyId);
+ },
+ encodeAddress(address: string): Buffer {
+ if (!ethUtil.isValidAddress(address)) {
+ throw new Error(`Invalid Address: ${address}`);
+ }
+ const encodedAddress = ethUtil.toBuffer(address);
+ return encodedAddress;
+ },
+ encodeUint256(value: BigNumber): Buffer {
+ const formattedValue = new BN(value.toString(10));
+ const encodedValue = ethUtil.toBuffer(formattedValue);
+ return encodedValue;
+ },
+ encodeERC20ProxyData(tokenAddress: string): string {
+ const encodedAssetProxyId = assetProxyUtils.encodeAssetProxyId(AssetProxyId.ERC20);
+ const encodedAddress = assetProxyUtils.encodeAddress(tokenAddress);
+ const encodedMetadata = Buffer.concat([encodedAssetProxyId, encodedAddress]);
+ const encodedMetadataHex = ethUtil.bufferToHex(encodedMetadata);
+ return encodedMetadataHex;
+ },
+ encodeERC721ProxyData(tokenAddress: string, tokenId: BigNumber): string {
+ const encodedAssetProxyId = assetProxyUtils.encodeAssetProxyId(AssetProxyId.ERC721);
+ const encodedAddress = assetProxyUtils.encodeAddress(tokenAddress);
+ const encodedTokenId = assetProxyUtils.encodeUint256(tokenId);
+ const encodedMetadata = Buffer.concat([encodedAssetProxyId, encodedAddress, encodedTokenId]);
+ const encodedMetadataHex = ethUtil.bufferToHex(encodedMetadata);
+ return encodedMetadataHex;
+ },
+};
diff --git a/packages/contracts/src/utils/balances.ts b/packages/contracts/src/utils/balances.ts
index 2ebc10313..40a59e815 100644
--- a/packages/contracts/src/utils/balances.ts
+++ b/packages/contracts/src/utils/balances.ts
@@ -2,14 +2,14 @@ import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
import * as Web3 from 'web3';
-import { DummyTokenContract } from '../contract_wrappers/generated/dummy_token';
+import { DummyERC20TokenContract } from '../contract_wrappers/generated/dummy_e_r_c20_token';
import { BalancesByOwner } from './types';
export class Balances {
- private _tokenContractInstances: DummyTokenContract[];
+ private _tokenContractInstances: DummyERC20TokenContract[];
private _ownerAddresses: string[];
- constructor(tokenContractInstances: DummyTokenContract[], ownerAddresses: string[]) {
+ constructor(tokenContractInstances: DummyERC20TokenContract[], ownerAddresses: string[]) {
this._tokenContractInstances = tokenContractInstances;
this._ownerAddresses = ownerAddresses;
}
diff --git a/packages/contracts/src/utils/exchange_wrapper.ts b/packages/contracts/src/utils/exchange_wrapper.ts
index cda012aa9..26ce8b04e 100644
--- a/packages/contracts/src/utils/exchange_wrapper.ts
+++ b/packages/contracts/src/utils/exchange_wrapper.ts
@@ -22,12 +22,12 @@ export class ExchangeWrapper {
public async fillOrderAsync(
signedOrder: SignedOrder,
from: string,
- opts: { takerTokenFillAmount?: BigNumber } = {},
+ opts: { takerAssetFillAmount?: BigNumber } = {},
): Promise<TransactionReceiptWithDecodedLogs> {
- const params = orderUtils.createFill(signedOrder, opts.takerTokenFillAmount);
+ const params = orderUtils.createFill(signedOrder, opts.takerAssetFillAmount);
const txHash = await this._exchange.fillOrder.sendTransactionAsync(
params.order,
- params.takerTokenFillAmount,
+ params.takerAssetFillAmount,
params.signature,
{ from },
);
@@ -43,12 +43,12 @@ export class ExchangeWrapper {
public async fillOrKillOrderAsync(
signedOrder: SignedOrder,
from: string,
- opts: { takerTokenFillAmount?: BigNumber } = {},
+ opts: { takerAssetFillAmount?: BigNumber } = {},
): Promise<TransactionReceiptWithDecodedLogs> {
- const params = orderUtils.createFill(signedOrder, opts.takerTokenFillAmount);
+ const params = orderUtils.createFill(signedOrder, opts.takerAssetFillAmount);
const txHash = await this._exchange.fillOrKillOrder.sendTransactionAsync(
params.order,
- params.takerTokenFillAmount,
+ params.takerAssetFillAmount,
params.signature,
{ from },
);
@@ -58,12 +58,12 @@ export class ExchangeWrapper {
public async fillOrderNoThrowAsync(
signedOrder: SignedOrder,
from: string,
- opts: { takerTokenFillAmount?: BigNumber } = {},
+ opts: { takerAssetFillAmount?: BigNumber } = {},
): Promise<TransactionReceiptWithDecodedLogs> {
- const params = orderUtils.createFill(signedOrder, opts.takerTokenFillAmount);
+ const params = orderUtils.createFill(signedOrder, opts.takerAssetFillAmount);
const txHash = await this._exchange.fillOrderNoThrow.sendTransactionAsync(
params.order,
- params.takerTokenFillAmount,
+ params.takerAssetFillAmount,
params.signature,
{ from },
);
@@ -73,12 +73,12 @@ export class ExchangeWrapper {
public async batchFillOrdersAsync(
orders: SignedOrder[],
from: string,
- opts: { takerTokenFillAmounts?: BigNumber[] } = {},
+ opts: { takerAssetFillAmounts?: BigNumber[] } = {},
): Promise<TransactionReceiptWithDecodedLogs> {
- const params = formatters.createBatchFill(orders, opts.takerTokenFillAmounts);
+ const params = formatters.createBatchFill(orders, opts.takerAssetFillAmounts);
const txHash = await this._exchange.batchFillOrders.sendTransactionAsync(
params.orders,
- params.takerTokenFillAmounts,
+ params.takerAssetFillAmounts,
params.signatures,
{ from },
);
@@ -88,12 +88,12 @@ export class ExchangeWrapper {
public async batchFillOrKillOrdersAsync(
orders: SignedOrder[],
from: string,
- opts: { takerTokenFillAmounts?: BigNumber[] } = {},
+ opts: { takerAssetFillAmounts?: BigNumber[] } = {},
): Promise<TransactionReceiptWithDecodedLogs> {
- const params = formatters.createBatchFill(orders, opts.takerTokenFillAmounts);
+ const params = formatters.createBatchFill(orders, opts.takerAssetFillAmounts);
const txHash = await this._exchange.batchFillOrKillOrders.sendTransactionAsync(
params.orders,
- params.takerTokenFillAmounts,
+ params.takerAssetFillAmounts,
params.signatures,
{ from },
);
@@ -103,12 +103,12 @@ export class ExchangeWrapper {
public async batchFillOrdersNoThrowAsync(
orders: SignedOrder[],
from: string,
- opts: { takerTokenFillAmounts?: BigNumber[] } = {},
+ opts: { takerAssetFillAmounts?: BigNumber[] } = {},
): Promise<TransactionReceiptWithDecodedLogs> {
- const params = formatters.createBatchFill(orders, opts.takerTokenFillAmounts);
+ const params = formatters.createBatchFill(orders, opts.takerAssetFillAmounts);
const txHash = await this._exchange.batchFillOrdersNoThrow.sendTransactionAsync(
params.orders,
- params.takerTokenFillAmounts,
+ params.takerAssetFillAmounts,
params.signatures,
{ from },
);
@@ -118,12 +118,12 @@ export class ExchangeWrapper {
public async marketSellOrdersAsync(
orders: SignedOrder[],
from: string,
- opts: { takerTokenFillAmount: BigNumber },
+ opts: { takerAssetFillAmount: BigNumber },
): Promise<TransactionReceiptWithDecodedLogs> {
- const params = formatters.createMarketSellOrders(orders, opts.takerTokenFillAmount);
+ const params = formatters.createMarketSellOrders(orders, opts.takerAssetFillAmount);
const txHash = await this._exchange.marketSellOrders.sendTransactionAsync(
params.orders,
- params.takerTokenFillAmount,
+ params.takerAssetFillAmount,
params.signatures,
{ from },
);
@@ -133,12 +133,12 @@ export class ExchangeWrapper {
public async marketSellOrdersNoThrowAsync(
orders: SignedOrder[],
from: string,
- opts: { takerTokenFillAmount: BigNumber },
+ opts: { takerAssetFillAmount: BigNumber },
): Promise<TransactionReceiptWithDecodedLogs> {
- const params = formatters.createMarketSellOrders(orders, opts.takerTokenFillAmount);
+ const params = formatters.createMarketSellOrders(orders, opts.takerAssetFillAmount);
const txHash = await this._exchange.marketSellOrdersNoThrow.sendTransactionAsync(
params.orders,
- params.takerTokenFillAmount,
+ params.takerAssetFillAmount,
params.signatures,
{ from },
);
@@ -148,12 +148,12 @@ export class ExchangeWrapper {
public async marketBuyOrdersAsync(
orders: SignedOrder[],
from: string,
- opts: { makerTokenFillAmount: BigNumber },
+ opts: { makerAssetFillAmount: BigNumber },
): Promise<TransactionReceiptWithDecodedLogs> {
- const params = formatters.createMarketBuyOrders(orders, opts.makerTokenFillAmount);
+ const params = formatters.createMarketBuyOrders(orders, opts.makerAssetFillAmount);
const txHash = await this._exchange.marketBuyOrders.sendTransactionAsync(
params.orders,
- params.makerTokenFillAmount,
+ params.makerAssetFillAmount,
params.signatures,
{ from },
);
@@ -163,12 +163,12 @@ export class ExchangeWrapper {
public async marketBuyOrdersNoThrowAsync(
orders: SignedOrder[],
from: string,
- opts: { makerTokenFillAmount: BigNumber },
+ opts: { makerAssetFillAmount: BigNumber },
): Promise<TransactionReceiptWithDecodedLogs> {
- const params = formatters.createMarketBuyOrders(orders, opts.makerTokenFillAmount);
+ const params = formatters.createMarketBuyOrders(orders, opts.makerAssetFillAmount);
const txHash = await this._exchange.marketBuyOrdersNoThrow.sendTransactionAsync(
params.orders,
- params.makerTokenFillAmount,
+ params.makerAssetFillAmount,
params.signatures,
{ from },
);
@@ -221,7 +221,7 @@ export class ExchangeWrapper {
);
return partialAmount;
}
- public async getTakerTokenFilledAmount(orderHashHex: string): Promise<BigNumber> {
+ public async getTakerAssetFilledAmountAsync(orderHashHex: string): Promise<BigNumber> {
const filledAmount = new BigNumber(await this._exchange.filled.callAsync(orderHashHex));
return filledAmount;
}
diff --git a/packages/contracts/src/utils/formatters.ts b/packages/contracts/src/utils/formatters.ts
index fce10c448..e706c15b5 100644
--- a/packages/contracts/src/utils/formatters.ts
+++ b/packages/contracts/src/utils/formatters.ts
@@ -5,27 +5,27 @@ import { orderUtils } from './order_utils';
import { BatchCancelOrders, BatchFillOrders, MarketBuyOrders, MarketSellOrders, SignedOrder } from './types';
export const formatters = {
- createBatchFill(signedOrders: SignedOrder[], takerTokenFillAmounts: BigNumber[] = []) {
+ createBatchFill(signedOrders: SignedOrder[], takerAssetFillAmounts: BigNumber[] = []) {
const batchFill: BatchFillOrders = {
orders: [],
signatures: [],
- takerTokenFillAmounts,
+ takerAssetFillAmounts,
};
_.forEach(signedOrders, signedOrder => {
const orderStruct = orderUtils.getOrderStruct(signedOrder);
batchFill.orders.push(orderStruct);
batchFill.signatures.push(signedOrder.signature);
- if (takerTokenFillAmounts.length < signedOrders.length) {
- batchFill.takerTokenFillAmounts.push(signedOrder.takerTokenAmount);
+ if (takerAssetFillAmounts.length < signedOrders.length) {
+ batchFill.takerAssetFillAmounts.push(signedOrder.takerAssetAmount);
}
});
return batchFill;
},
- createMarketSellOrders(signedOrders: SignedOrder[], takerTokenFillAmount: BigNumber) {
+ createMarketSellOrders(signedOrders: SignedOrder[], takerAssetFillAmount: BigNumber) {
const marketSellOrders: MarketSellOrders = {
orders: [],
signatures: [],
- takerTokenFillAmount,
+ takerAssetFillAmount,
};
_.forEach(signedOrders, signedOrder => {
const orderStruct = orderUtils.getOrderStruct(signedOrder);
@@ -34,11 +34,11 @@ export const formatters = {
});
return marketSellOrders;
},
- createMarketBuyOrders(signedOrders: SignedOrder[], makerTokenFillAmount: BigNumber) {
+ createMarketBuyOrders(signedOrders: SignedOrder[], makerAssetFillAmount: BigNumber) {
const marketBuyOrders: MarketBuyOrders = {
orders: [],
signatures: [],
- makerTokenFillAmount,
+ makerAssetFillAmount,
};
_.forEach(signedOrders, signedOrder => {
const orderStruct = orderUtils.getOrderStruct(signedOrder);
diff --git a/packages/contracts/src/utils/order_utils.ts b/packages/contracts/src/utils/order_utils.ts
index 18892b4d4..52eb44941 100644
--- a/packages/contracts/src/utils/order_utils.ts
+++ b/packages/contracts/src/utils/order_utils.ts
@@ -7,18 +7,18 @@ import { crypto } from './crypto';
import { OrderStruct, SignatureType, SignedOrder, UnsignedOrder } from './types';
export const orderUtils = {
- createFill: (signedOrder: SignedOrder, takerTokenFillAmount?: BigNumber) => {
+ createFill: (signedOrder: SignedOrder, takerAssetFillAmount?: BigNumber) => {
const fill = {
order: orderUtils.getOrderStruct(signedOrder),
- takerTokenFillAmount: takerTokenFillAmount || signedOrder.takerTokenAmount,
+ takerAssetFillAmount: takerAssetFillAmount || signedOrder.takerAssetAmount,
signature: signedOrder.signature,
};
return fill;
},
- createCancel(signedOrder: SignedOrder, takerTokenCancelAmount?: BigNumber) {
+ createCancel(signedOrder: SignedOrder, takerAssetCancelAmount?: BigNumber) {
const cancel = {
order: orderUtils.getOrderStruct(signedOrder),
- takerTokenCancelAmount: takerTokenCancelAmount || signedOrder.takerTokenAmount,
+ takerAssetCancelAmount: takerAssetCancelAmount || signedOrder.takerAssetAmount,
};
return cancel;
},
@@ -27,8 +27,8 @@ export const orderUtils = {
makerAddress: signedOrder.makerAddress,
takerAddress: signedOrder.takerAddress,
feeRecipientAddress: signedOrder.feeRecipientAddress,
- makerTokenAmount: signedOrder.makerTokenAmount,
- takerTokenAmount: signedOrder.takerTokenAmount,
+ makerAssetAmount: signedOrder.makerAssetAmount,
+ takerAssetAmount: signedOrder.takerAssetAmount,
makerFee: signedOrder.makerFee,
takerFee: signedOrder.takerFee,
expirationTimeSeconds: signedOrder.expirationTimeSeconds,
@@ -44,8 +44,8 @@ export const orderUtils = {
'address makerAddress',
'address takerAddress',
'address feeRecipientAddress',
- 'uint256 makerTokenAmount',
- 'uint256 takerTokenAmount',
+ 'uint256 makerAssetAmount',
+ 'uint256 takerAssetAmount',
'uint256 makerFee',
'uint256 takerFee',
'uint256 expirationTimeSeconds',
@@ -58,8 +58,8 @@ export const orderUtils = {
order.makerAddress,
order.takerAddress,
order.feeRecipientAddress,
- order.makerTokenAmount,
- order.takerTokenAmount,
+ order.makerAssetAmount,
+ order.takerAssetAmount,
order.makerFee,
order.takerFee,
order.expirationTimeSeconds,
diff --git a/packages/contracts/src/utils/types.ts b/packages/contracts/src/utils/types.ts
index 7de167f27..8bc9641fc 100644
--- a/packages/contracts/src/utils/types.ts
+++ b/packages/contracts/src/utils/types.ts
@@ -14,19 +14,19 @@ export interface SubmissionContractEventArgs {
export interface BatchFillOrders {
orders: OrderStruct[];
signatures: string[];
- takerTokenFillAmounts: BigNumber[];
+ takerAssetFillAmounts: BigNumber[];
}
export interface MarketSellOrders {
orders: OrderStruct[];
signatures: string[];
- takerTokenFillAmount: BigNumber;
+ takerAssetFillAmount: BigNumber;
}
export interface MarketBuyOrders {
orders: OrderStruct[];
signatures: string[];
- makerTokenFillAmount: BigNumber;
+ makerAssetFillAmount: BigNumber;
}
export interface BatchCancelOrders {
@@ -47,10 +47,10 @@ export interface DefaultOrderParams {
exchangeAddress: string;
makerAddress: string;
feeRecipientAddress: string;
- makerTokenAddress: string;
- takerTokenAddress: string;
- makerTokenAmount: BigNumber;
- takerTokenAmount: BigNumber;
+ makerAssetAddress: string;
+ takerAssetAddress: string;
+ makerAssetAmount: BigNumber;
+ takerAssetAmount: BigNumber;
makerFee: BigNumber;
takerFee: BigNumber;
makerAssetData: string;
@@ -100,10 +100,9 @@ export enum ContractName {
MultiSigWalletWithTimeLock = 'MultiSigWalletWithTimeLock',
Exchange = 'Exchange',
ZRXToken = 'ZRXToken',
- DummyToken = 'DummyToken',
+ DummyERC20Token = 'DummyERC20Token',
EtherToken = 'WETH9',
MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress = 'MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress',
- MaliciousToken = 'MaliciousToken',
AccountLevels = 'AccountLevels',
EtherDelta = 'EtherDelta',
Arbitrage = 'Arbitrage',
@@ -138,8 +137,8 @@ export interface OrderStruct {
makerAddress: string;
takerAddress: string;
feeRecipientAddress: string;
- makerTokenAmount: BigNumber;
- takerTokenAmount: BigNumber;
+ makerAssetAmount: BigNumber;
+ takerAssetAmount: BigNumber;
makerFee: BigNumber;
takerFee: BigNumber;
expirationTimeSeconds: BigNumber;