Change utils
This commit is contained in:
parent
a264c36a48
commit
4cc5bbaf19
@ -2,12 +2,14 @@ import { BigNumber } from '@0xproject/utils';
|
|||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import * as Web3 from 'web3';
|
import * as Web3 from 'web3';
|
||||||
|
|
||||||
|
import { DummyTokenContract } from '../src/contract_wrappers/generated/dummy_token';
|
||||||
|
|
||||||
import { BalancesByOwner } from './types';
|
import { BalancesByOwner } from './types';
|
||||||
|
|
||||||
export class Balances {
|
export class Balances {
|
||||||
private _tokenContractInstances: Web3.ContractInstance[];
|
private _tokenContractInstances: DummyTokenContract[];
|
||||||
private _ownerAddresses: string[];
|
private _ownerAddresses: string[];
|
||||||
constructor(tokenContractInstances: Web3.ContractInstance[], ownerAddresses: string[]) {
|
constructor(tokenContractInstances: DummyTokenContract[], ownerAddresses: string[]) {
|
||||||
this._tokenContractInstances = tokenContractInstances;
|
this._tokenContractInstances = tokenContractInstances;
|
||||||
this._ownerAddresses = ownerAddresses;
|
this._ownerAddresses = ownerAddresses;
|
||||||
}
|
}
|
||||||
|
@ -3,14 +3,16 @@ import { BigNumber } from '@0xproject/utils';
|
|||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import * as Web3 from 'web3';
|
import * as Web3 from 'web3';
|
||||||
|
|
||||||
|
import { ExchangeContract } from '../src/contract_wrappers/generated/exchange';
|
||||||
|
|
||||||
import { formatters } from './formatters';
|
import { formatters } from './formatters';
|
||||||
import { Order } from './order';
|
import { Order } from './order';
|
||||||
|
|
||||||
export class ExchangeWrapper {
|
export class ExchangeWrapper {
|
||||||
private _exchange: Web3.ContractInstance;
|
private _exchange: ExchangeContract;
|
||||||
private _zeroEx: ZeroEx;
|
private _zeroEx: ZeroEx;
|
||||||
constructor(exchangeContractInstance: Web3.ContractInstance, zeroEx: ZeroEx) {
|
constructor(exchangeContract: ExchangeContract, zeroEx: ZeroEx) {
|
||||||
this._exchange = exchangeContractInstance;
|
this._exchange = exchangeContract;
|
||||||
this._zeroEx = zeroEx;
|
this._zeroEx = zeroEx;
|
||||||
}
|
}
|
||||||
public async fillOrderAsync(
|
public async fillOrderAsync(
|
||||||
@ -23,14 +25,14 @@ export class ExchangeWrapper {
|
|||||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||||
const shouldThrowOnInsufficientBalanceOrAllowance = !!opts.shouldThrowOnInsufficientBalanceOrAllowance;
|
const shouldThrowOnInsufficientBalanceOrAllowance = !!opts.shouldThrowOnInsufficientBalanceOrAllowance;
|
||||||
const params = order.createFill(shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmount);
|
const params = order.createFill(shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmount);
|
||||||
const txHash = await this._exchange.fillOrder(
|
const txHash = await this._exchange.fillOrder.sendTransactionAsync(
|
||||||
params.orderAddresses,
|
params.orderAddresses,
|
||||||
params.orderValues,
|
params.orderValues,
|
||||||
params.fillTakerTokenAmount,
|
params.fillTakerTokenAmount,
|
||||||
params.shouldThrowOnInsufficientBalanceOrAllowance,
|
params.shouldThrowOnInsufficientBalanceOrAllowance,
|
||||||
params.v,
|
params.v as number,
|
||||||
params.r,
|
params.r as string,
|
||||||
params.s,
|
params.s as string,
|
||||||
{ from },
|
{ from },
|
||||||
);
|
);
|
||||||
const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
|
const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
|
||||||
@ -44,7 +46,7 @@ export class ExchangeWrapper {
|
|||||||
opts: { cancelTakerTokenAmount?: BigNumber } = {},
|
opts: { cancelTakerTokenAmount?: BigNumber } = {},
|
||||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||||
const params = order.createCancel(opts.cancelTakerTokenAmount);
|
const params = order.createCancel(opts.cancelTakerTokenAmount);
|
||||||
const txHash = await this._exchange.cancelOrder(
|
const txHash = await this._exchange.cancelOrder.sendTransactionAsync(
|
||||||
params.orderAddresses,
|
params.orderAddresses,
|
||||||
params.orderValues,
|
params.orderValues,
|
||||||
params.cancelTakerTokenAmount,
|
params.cancelTakerTokenAmount,
|
||||||
@ -62,13 +64,13 @@ export class ExchangeWrapper {
|
|||||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||||
const shouldThrowOnInsufficientBalanceOrAllowance = true;
|
const shouldThrowOnInsufficientBalanceOrAllowance = true;
|
||||||
const params = order.createFill(shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmount);
|
const params = order.createFill(shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmount);
|
||||||
const txHash = await this._exchange.fillOrKillOrder(
|
const txHash = await this._exchange.fillOrKillOrder.sendTransactionAsync(
|
||||||
params.orderAddresses,
|
params.orderAddresses,
|
||||||
params.orderValues,
|
params.orderValues,
|
||||||
params.fillTakerTokenAmount,
|
params.fillTakerTokenAmount,
|
||||||
params.v,
|
params.v as number,
|
||||||
params.r,
|
params.r as string,
|
||||||
params.s,
|
params.s as string,
|
||||||
{ from },
|
{ from },
|
||||||
);
|
);
|
||||||
const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
|
const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash);
|
||||||
@ -90,7 +92,7 @@ export class ExchangeWrapper {
|
|||||||
shouldThrowOnInsufficientBalanceOrAllowance,
|
shouldThrowOnInsufficientBalanceOrAllowance,
|
||||||
opts.fillTakerTokenAmounts,
|
opts.fillTakerTokenAmounts,
|
||||||
);
|
);
|
||||||
const txHash = await this._exchange.batchFillOrders(
|
const txHash = await this._exchange.batchFillOrders.sendTransactionAsync(
|
||||||
params.orderAddresses,
|
params.orderAddresses,
|
||||||
params.orderValues,
|
params.orderValues,
|
||||||
params.fillTakerTokenAmounts,
|
params.fillTakerTokenAmounts,
|
||||||
@ -116,7 +118,7 @@ export class ExchangeWrapper {
|
|||||||
shouldThrowOnInsufficientBalanceOrAllowance,
|
shouldThrowOnInsufficientBalanceOrAllowance,
|
||||||
opts.fillTakerTokenAmounts,
|
opts.fillTakerTokenAmounts,
|
||||||
);
|
);
|
||||||
const txHash = await this._exchange.batchFillOrKillOrders(
|
const txHash = await this._exchange.batchFillOrKillOrders.sendTransactionAsync(
|
||||||
params.orderAddresses,
|
params.orderAddresses,
|
||||||
params.orderValues,
|
params.orderValues,
|
||||||
params.fillTakerTokenAmounts,
|
params.fillTakerTokenAmounts,
|
||||||
@ -141,7 +143,7 @@ export class ExchangeWrapper {
|
|||||||
shouldThrowOnInsufficientBalanceOrAllowance,
|
shouldThrowOnInsufficientBalanceOrAllowance,
|
||||||
opts.fillTakerTokenAmount,
|
opts.fillTakerTokenAmount,
|
||||||
);
|
);
|
||||||
const txHash = await this._exchange.fillOrdersUpTo(
|
const txHash = await this._exchange.fillOrdersUpTo.sendTransactionAsync(
|
||||||
params.orderAddresses,
|
params.orderAddresses,
|
||||||
params.orderValues,
|
params.orderValues,
|
||||||
params.fillTakerTokenAmount,
|
params.fillTakerTokenAmount,
|
||||||
@ -162,7 +164,7 @@ export class ExchangeWrapper {
|
|||||||
opts: { cancelTakerTokenAmounts?: BigNumber[] } = {},
|
opts: { cancelTakerTokenAmounts?: BigNumber[] } = {},
|
||||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||||
const params = formatters.createBatchCancel(orders, opts.cancelTakerTokenAmounts);
|
const params = formatters.createBatchCancel(orders, opts.cancelTakerTokenAmounts);
|
||||||
const txHash = await this._exchange.batchCancelOrders(
|
const txHash = await this._exchange.batchCancelOrders.sendTransactionAsync(
|
||||||
params.orderAddresses,
|
params.orderAddresses,
|
||||||
params.orderValues,
|
params.orderValues,
|
||||||
params.cancelTakerTokenAmounts,
|
params.cancelTakerTokenAmounts,
|
||||||
@ -182,10 +184,10 @@ export class ExchangeWrapper {
|
|||||||
public async isValidSignatureAsync(order: Order): Promise<boolean> {
|
public async isValidSignatureAsync(order: Order): Promise<boolean> {
|
||||||
const isValidSignature = await this._exchange.isValidSignature(
|
const isValidSignature = await this._exchange.isValidSignature(
|
||||||
order.params.maker,
|
order.params.maker,
|
||||||
order.params.orderHashHex,
|
order.params.orderHashHex as string,
|
||||||
order.params.v,
|
order.params.v as number,
|
||||||
order.params.r,
|
order.params.r as string,
|
||||||
order.params.s,
|
order.params.s as string,
|
||||||
);
|
);
|
||||||
return isValidSignature;
|
return isValidSignature;
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
|
import { BigNumber } from '@0xproject/utils';
|
||||||
import ABI = require('ethereumjs-abi');
|
import ABI = require('ethereumjs-abi');
|
||||||
import ethUtil = require('ethereumjs-util');
|
import ethUtil = require('ethereumjs-util');
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import * as Web3 from 'web3';
|
import * as Web3 from 'web3';
|
||||||
|
|
||||||
|
import { MultiSigWalletContract } from '../src/contract_wrappers/generated/multi_sig_wallet';
|
||||||
|
|
||||||
import { TransactionDataParams } from './types';
|
import { TransactionDataParams } from './types';
|
||||||
|
|
||||||
export class MultiSigWrapper {
|
export class MultiSigWrapper {
|
||||||
private _multiSig: Web3.ContractInstance;
|
private _multiSig: MultiSigWalletContract;
|
||||||
public static encodeFnArgs(name: string, abi: Web3.AbiDefinition[], args: any[]) {
|
public static encodeFnArgs(name: string, abi: Web3.AbiDefinition[], args: any[]) {
|
||||||
const abiEntity = _.find(abi, { name }) as Web3.MethodAbi;
|
const abiEntity = _.find(abi, { name }) as Web3.MethodAbi;
|
||||||
if (_.isUndefined(abiEntity)) {
|
if (_.isUndefined(abiEntity)) {
|
||||||
@ -21,18 +24,18 @@ export class MultiSigWrapper {
|
|||||||
});
|
});
|
||||||
return funcSig + argsData.join('');
|
return funcSig + argsData.join('');
|
||||||
}
|
}
|
||||||
constructor(multiSigContractInstance: Web3.ContractInstance) {
|
constructor(multiSigContract: MultiSigWalletContract) {
|
||||||
this._multiSig = multiSigContractInstance;
|
this._multiSig = multiSigContract;
|
||||||
}
|
}
|
||||||
public async submitTransactionAsync(
|
public async submitTransactionAsync(
|
||||||
destination: string,
|
destination: string,
|
||||||
from: string,
|
from: string,
|
||||||
dataParams: TransactionDataParams,
|
dataParams: TransactionDataParams,
|
||||||
value: number = 0,
|
value: BigNumber = new BigNumber(0),
|
||||||
) {
|
) {
|
||||||
const { name, abi, args = [] } = dataParams;
|
const { name, abi, args = [] } = dataParams;
|
||||||
const encoded = MultiSigWrapper.encodeFnArgs(name, abi, args);
|
const encoded = MultiSigWrapper.encodeFnArgs(name, abi, args);
|
||||||
return this._multiSig.submitTransaction(destination, value, encoded, {
|
return this._multiSig.submitTransaction.sendTransactionAsync(destination, value, encoded, {
|
||||||
from,
|
from,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
import * as Web3 from 'web3';
|
import * as Web3 from 'web3';
|
||||||
|
|
||||||
|
import { TokenRegistryContract } from '../src/contract_wrappers/generated/token_registry';
|
||||||
|
|
||||||
import { Token } from './types';
|
import { Token } from './types';
|
||||||
|
|
||||||
export class TokenRegWrapper {
|
export class TokenRegWrapper {
|
||||||
private _tokenReg: Web3.ContractInstance;
|
private _tokenReg: TokenRegistryContract;
|
||||||
constructor(tokenRegContractInstance: Web3.ContractInstance) {
|
constructor(tokenRegContract: TokenRegistryContract) {
|
||||||
this._tokenReg = tokenRegContractInstance;
|
this._tokenReg = tokenRegContract;
|
||||||
}
|
}
|
||||||
public addTokenAsync(token: Token, from: string) {
|
public addTokenAsync(token: Token, from: string) {
|
||||||
const tx = this._tokenReg.addToken(
|
const tx = this._tokenReg.addToken.sendTransactionAsync(
|
||||||
token.address,
|
token.address as string,
|
||||||
token.name,
|
token.name,
|
||||||
token.symbol,
|
token.symbol,
|
||||||
token.decimals,
|
token.decimals,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user