diff options
author | Leonid <logvinov.leon@gmail.com> | 2018-02-07 18:40:06 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-07 18:40:06 +0800 |
commit | 12d62e1157168ec9e8cd23749523b2bcda8eefe5 (patch) | |
tree | 7061d10b3958647e51644593cd7e0be890048576 /packages/contracts/util | |
parent | 4c9c4c487a034d926443eeb8a0154fd38c97aca3 (diff) | |
parent | 0bad911a16dd2924e5be693710a422383aba4871 (diff) | |
download | dexon-sol-tools-12d62e1157168ec9e8cd23749523b2bcda8eefe5.tar dexon-sol-tools-12d62e1157168ec9e8cd23749523b2bcda8eefe5.tar.gz dexon-sol-tools-12d62e1157168ec9e8cd23749523b2bcda8eefe5.tar.bz2 dexon-sol-tools-12d62e1157168ec9e8cd23749523b2bcda8eefe5.tar.lz dexon-sol-tools-12d62e1157168ec9e8cd23749523b2bcda8eefe5.tar.xz dexon-sol-tools-12d62e1157168ec9e8cd23749523b2bcda8eefe5.tar.zst dexon-sol-tools-12d62e1157168ec9e8cd23749523b2bcda8eefe5.zip |
Merge pull request #368 from 0xProject/feature/abigen/addNetworkId
Add CLI option for networkId, add abi-gen to contracts package
Diffstat (limited to 'packages/contracts/util')
-rw-r--r-- | packages/contracts/util/artifacts.ts | 20 | ||||
-rw-r--r-- | packages/contracts/util/balances.ts | 6 | ||||
-rw-r--r-- | packages/contracts/util/exchange_wrapper.ts | 42 | ||||
-rw-r--r-- | packages/contracts/util/multi_sig_wrapper.ts | 13 | ||||
-rw-r--r-- | packages/contracts/util/token_registry_wrapper.ts | 14 |
5 files changed, 52 insertions, 43 deletions
diff --git a/packages/contracts/util/artifacts.ts b/packages/contracts/util/artifacts.ts index fd9380d1d..7c375c1b7 100644 --- a/packages/contracts/util/artifacts.ts +++ b/packages/contracts/util/artifacts.ts @@ -1,13 +1,13 @@ -import * as DummyTokenArtifact from '../artifacts/DummyToken.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 TokenTransferProxyArtifact from '../artifacts/TokenTransferProxy.json'; -import * as EtherTokenArtifact from '../artifacts/WETH9.json'; -import * as ZRXArtifact from '../artifacts/ZRXToken.json'; +import * as DummyTokenArtifact from '../src/artifacts/DummyToken.json'; +import * as ExchangeArtifact from '../src/artifacts/Exchange.json'; +import * as MaliciousTokenArtifact from '../src/artifacts/MaliciousToken.json'; +import * as MultiSigWalletWithTimeLockArtifact from '../src/artifacts/MultiSigWalletWithTimeLock.json'; +import * as MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressArtifact from '../src/artifacts/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.json'; +import * as TokenArtifact from '../src/artifacts/Token.json'; +import * as TokenRegistryArtifact from '../src/artifacts/TokenRegistry.json'; +import * as TokenTransferProxyArtifact from '../src/artifacts/TokenTransferProxy.json'; +import * as EtherTokenArtifact from '../src/artifacts/WETH9.json'; +import * as ZRXArtifact from '../src/artifacts/ZRXToken.json'; import { Artifact } from './types'; diff --git a/packages/contracts/util/balances.ts b/packages/contracts/util/balances.ts index 5bcb5145f..0abc305d8 100644 --- a/packages/contracts/util/balances.ts +++ b/packages/contracts/util/balances.ts @@ -2,12 +2,14 @@ import { BigNumber } from '@0xproject/utils'; import * as _ from 'lodash'; import * as Web3 from 'web3'; +import { DummyTokenContract } from '../src/contract_wrappers/generated/dummy_token'; + import { BalancesByOwner } from './types'; export class Balances { - private _tokenContractInstances: Web3.ContractInstance[]; + private _tokenContractInstances: DummyTokenContract[]; private _ownerAddresses: string[]; - constructor(tokenContractInstances: Web3.ContractInstance[], ownerAddresses: string[]) { + constructor(tokenContractInstances: DummyTokenContract[], ownerAddresses: string[]) { this._tokenContractInstances = tokenContractInstances; this._ownerAddresses = ownerAddresses; } diff --git a/packages/contracts/util/exchange_wrapper.ts b/packages/contracts/util/exchange_wrapper.ts index 7a07239f5..b749cd72e 100644 --- a/packages/contracts/util/exchange_wrapper.ts +++ b/packages/contracts/util/exchange_wrapper.ts @@ -3,14 +3,16 @@ import { BigNumber } from '@0xproject/utils'; import * as _ from 'lodash'; import * as Web3 from 'web3'; +import { ExchangeContract } from '../src/contract_wrappers/generated/exchange'; + import { formatters } from './formatters'; import { Order } from './order'; export class ExchangeWrapper { - private _exchange: Web3.ContractInstance; + private _exchange: ExchangeContract; private _zeroEx: ZeroEx; - constructor(exchangeContractInstance: Web3.ContractInstance, zeroEx: ZeroEx) { - this._exchange = exchangeContractInstance; + constructor(exchangeContract: ExchangeContract, zeroEx: ZeroEx) { + this._exchange = exchangeContract; this._zeroEx = zeroEx; } public async fillOrderAsync( @@ -23,14 +25,14 @@ export class ExchangeWrapper { ): Promise<TransactionReceiptWithDecodedLogs> { const shouldThrowOnInsufficientBalanceOrAllowance = !!opts.shouldThrowOnInsufficientBalanceOrAllowance; const params = order.createFill(shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmount); - const txHash = await this._exchange.fillOrder( + const txHash = await this._exchange.fillOrder.sendTransactionAsync( params.orderAddresses, params.orderValues, params.fillTakerTokenAmount, params.shouldThrowOnInsufficientBalanceOrAllowance, - params.v, - params.r, - params.s, + params.v as number, + params.r as string, + params.s as string, { from }, ); const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); @@ -44,7 +46,7 @@ export class ExchangeWrapper { opts: { cancelTakerTokenAmount?: BigNumber } = {}, ): Promise<TransactionReceiptWithDecodedLogs> { const params = order.createCancel(opts.cancelTakerTokenAmount); - const txHash = await this._exchange.cancelOrder( + const txHash = await this._exchange.cancelOrder.sendTransactionAsync( params.orderAddresses, params.orderValues, params.cancelTakerTokenAmount, @@ -62,13 +64,13 @@ export class ExchangeWrapper { ): Promise<TransactionReceiptWithDecodedLogs> { const shouldThrowOnInsufficientBalanceOrAllowance = true; const params = order.createFill(shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmount); - const txHash = await this._exchange.fillOrKillOrder( + const txHash = await this._exchange.fillOrKillOrder.sendTransactionAsync( params.orderAddresses, params.orderValues, params.fillTakerTokenAmount, - params.v, - params.r, - params.s, + params.v as number, + params.r as string, + params.s as string, { from }, ); const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); @@ -90,7 +92,7 @@ export class ExchangeWrapper { shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmounts, ); - const txHash = await this._exchange.batchFillOrders( + const txHash = await this._exchange.batchFillOrders.sendTransactionAsync( params.orderAddresses, params.orderValues, params.fillTakerTokenAmounts, @@ -116,7 +118,7 @@ export class ExchangeWrapper { shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmounts, ); - const txHash = await this._exchange.batchFillOrKillOrders( + const txHash = await this._exchange.batchFillOrKillOrders.sendTransactionAsync( params.orderAddresses, params.orderValues, params.fillTakerTokenAmounts, @@ -141,7 +143,7 @@ export class ExchangeWrapper { shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmount, ); - const txHash = await this._exchange.fillOrdersUpTo( + const txHash = await this._exchange.fillOrdersUpTo.sendTransactionAsync( params.orderAddresses, params.orderValues, params.fillTakerTokenAmount, @@ -162,7 +164,7 @@ export class ExchangeWrapper { opts: { cancelTakerTokenAmounts?: BigNumber[] } = {}, ): Promise<TransactionReceiptWithDecodedLogs> { const params = formatters.createBatchCancel(orders, opts.cancelTakerTokenAmounts); - const txHash = await this._exchange.batchCancelOrders( + const txHash = await this._exchange.batchCancelOrders.sendTransactionAsync( params.orderAddresses, params.orderValues, params.cancelTakerTokenAmounts, @@ -182,10 +184,10 @@ export class ExchangeWrapper { public async isValidSignatureAsync(order: Order): Promise<boolean> { const isValidSignature = await this._exchange.isValidSignature( order.params.maker, - order.params.orderHashHex, - order.params.v, - order.params.r, - order.params.s, + order.params.orderHashHex as string, + order.params.v as number, + order.params.r as string, + order.params.s as string, ); return isValidSignature; } diff --git a/packages/contracts/util/multi_sig_wrapper.ts b/packages/contracts/util/multi_sig_wrapper.ts index 0a066df53..3b83ccb7b 100644 --- a/packages/contracts/util/multi_sig_wrapper.ts +++ b/packages/contracts/util/multi_sig_wrapper.ts @@ -1,12 +1,15 @@ +import { BigNumber } from '@0xproject/utils'; import ABI = require('ethereumjs-abi'); import ethUtil = require('ethereumjs-util'); import * as _ from 'lodash'; import * as Web3 from 'web3'; +import { MultiSigWalletContract } from '../src/contract_wrappers/generated/multi_sig_wallet'; + import { TransactionDataParams } from './types'; export class MultiSigWrapper { - private _multiSig: Web3.ContractInstance; + private _multiSig: MultiSigWalletContract; public static encodeFnArgs(name: string, abi: Web3.AbiDefinition[], args: any[]) { const abiEntity = _.find(abi, { name }) as Web3.MethodAbi; if (_.isUndefined(abiEntity)) { @@ -21,18 +24,18 @@ export class MultiSigWrapper { }); return funcSig + argsData.join(''); } - constructor(multiSigContractInstance: Web3.ContractInstance) { - this._multiSig = multiSigContractInstance; + constructor(multiSigContract: MultiSigWalletContract) { + this._multiSig = multiSigContract; } public async submitTransactionAsync( destination: string, from: string, dataParams: TransactionDataParams, - value: number = 0, + value: BigNumber = new BigNumber(0), ) { const { name, abi, args = [] } = dataParams; const encoded = MultiSigWrapper.encodeFnArgs(name, abi, args); - return this._multiSig.submitTransaction(destination, value, encoded, { + return this._multiSig.submitTransaction.sendTransactionAsync(destination, value, encoded, { from, }); } diff --git a/packages/contracts/util/token_registry_wrapper.ts b/packages/contracts/util/token_registry_wrapper.ts index 033b72d10..d0af17103 100644 --- a/packages/contracts/util/token_registry_wrapper.ts +++ b/packages/contracts/util/token_registry_wrapper.ts @@ -1,15 +1,17 @@ import * as Web3 from 'web3'; +import { TokenRegistryContract } from '../src/contract_wrappers/generated/token_registry'; + import { Token } from './types'; export class TokenRegWrapper { - private _tokenReg: Web3.ContractInstance; - constructor(tokenRegContractInstance: Web3.ContractInstance) { - this._tokenReg = tokenRegContractInstance; + private _tokenReg: TokenRegistryContract; + constructor(tokenRegContract: TokenRegistryContract) { + this._tokenReg = tokenRegContract; } - public addTokenAsync(token: Token, from: string) { - const tx = this._tokenReg.addToken( - token.address, + public async addTokenAsync(token: Token, from: string) { + const tx = this._tokenReg.addToken.sendTransactionAsync( + token.address as string, token.name, token.symbol, token.decimals, |